From: Oliver O. <fr...@us...> - 2007-03-07 10:39:40
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/initeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/initeffector Added Files: Tag: projectx initaction.h initeffector.cpp initeffector.h initeffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: initeffector.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: initeffector.cpp,v 1.1.2.1 2007/03/07 10:39:35 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "initaction.h" #include "initeffector.h" #include <zeitgeist/logserver/logserver.h> #include <oxygen/agentaspect/agentaspect.h> #include <oxygen/gamecontrolserver/predicate.h> #include <oxygen/physicsserver/body.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/agentstate/agentstate.h> #include <soccer/gamestateaspect/gamestateaspect.h> #include <sstream> using namespace boost; using namespace oxygen; using namespace salt; InitEffector::InitEffector() : oxygen::Effector() { } InitEffector::~InitEffector() { } bool InitEffector::Realize(boost::shared_ptr<ActionObject> action) { if ( (mGameState.get() == 0) || (mAgentAspect.get() == 0) ) { return false; } shared_ptr<InitAction> initAction = shared_dynamic_cast<InitAction>(action); if (initAction.get() == 0) { GetLog()->Error() << "ERROR: (InitEffector) cannot realize an unknown ActionObject\n"; return false; } // search for the AgentState shared_ptr<AgentState> state = shared_static_cast<AgentState> (mAgentAspect->GetChildOfClass("AgentState",true)); if (state.get() == 0) { GetLog()->Error() << "ERROR: (InitEffector) cannot find AgentState\n"; return false; } // register the uniform number and team index to the GameStateAspect mGameState->RequestUniform (state, initAction->GetName(), initAction->GetNumber()); // request an initial position for the agent and move it there Vector3f pos = mGameState->RequestInitPosition(state->GetTeamIndex()); shared_ptr<Body> body; if (SoccerBase::GetAgentBody(mAgentAspect,body)) { body->SetPosition(pos); body->SetVelocity(Vector3f(0,0,0)); body->SetAngularVelocity(Vector3f(0,0,0)); } return true; } shared_ptr<ActionObject> InitEffector::GetActionObject(const Predicate& predicate) { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (InitEffector) invalid predicate" << predicate.name << "\n"; return shared_ptr<ActionObject>(); } std::string name; predicate.GetValue(predicate.begin(),"teamname",name); int unum = 0; predicate.GetValue(predicate.begin(),"unum",unum); return shared_ptr<ActionObject>(new InitAction(GetPredicate(),name,unum)); } void InitEffector::OnLink() { mGameState = shared_dynamic_cast<GameStateAspect> (SoccerBase::GetControlAspect(*this,"GameStateAspect")); mAgentAspect = GetAgentAspect(); if (mAgentAspect.get() == 0) { GetLog()->Error() << "ERROR: (InitEffector) cannot get AgentAspect\n"; } } void InitEffector::OnUnlink() { mGameState.reset(); mAgentAspect.reset(); } --- NEW FILE: initeffector_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: initeffector_c.cpp,v 1.1.2.1 2007/03/07 10:39:36 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "initeffector.h" using namespace oxygen; void CLASS(InitEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); } --- NEW FILE: initaction.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: initaction.h,v 1.1.2.1 2007/03/07 10:39:35 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef INITACTION_H #define INITACTION_H #include <oxygen/gamecontrolserver/actionobject.h> class InitAction : public oxygen::ActionObject { public: InitAction(const std::string& predicate, const std::string& name, int number) : ActionObject(predicate), mName(name), mNumber(number) {} virtual ~InitAction() {} /** @return the requested team name */ const std::string& GetName() { return mName; } /** @return the requested uniform number */ int GetNumber() { return mNumber; } protected: /** the team name to set */ std::string mName; /** the requested uniform number */ int mNumber; }; #endif // INITACTION_H --- NEW FILE: initeffector.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: initeffector.h,v 1.1.2.1 2007/03/07 10:39:36 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef INITEFFECTOR_H #define INITEFFECTOR_H #include <oxygen/agentaspect/effector.h> class GameStateAspect; class InitEffector : public oxygen::Effector { // // functions // public: InitEffector(); virtual ~InitEffector(); /** realizes the action described by the ActionObject */ virtual bool Realize(boost::shared_ptr<oxygen::ActionObject> action); /** returns the name of the predicate this effector implements. */ virtual std::string GetPredicate() { return "init"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); protected: /** set up the reference GameStateAspect */ virtual void OnLink(); /** reset the reference to the GameStateAspect */ virtual void OnUnlink(); protected: /** reference to the GameStateAspect */ boost::shared_ptr<GameStateAspect> mGameState; /** reference to the AgentAspect */ boost::shared_ptr<oxygen::AgentAspect> mAgentAspect; }; DECLARE_CLASS(InitEffector); #endif // INITEFFECTOR_H |