00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "initaction.h"
00023 #include "initeffector.h"
00024 #include <zeitgeist/logserver/logserver.h>
00025 #include <oxygen/agentaspect/agentaspect.h>
00026 #include <oxygen/gamecontrolserver/predicate.h>
00027 #include <oxygen/physicsserver/body.h>
00028 #include <soccer/soccerbase/soccerbase.h>
00029 #include <soccer/agentstate/agentstate.h>
00030 #include <soccer/gamestateaspect/gamestateaspect.h>
00031 #include <sstream>
00032
00033 using namespace boost;
00034 using namespace oxygen;
00035 using namespace salt;
00036
00037 InitEffector::InitEffector() : oxygen::Effector()
00038 {
00039 }
00040
00041 InitEffector::~InitEffector()
00042 {
00043 }
00044
00045 bool
00046 InitEffector::Realize(boost::shared_ptr<ActionObject> action)
00047 {
00048 if (
00049 (mGameState.get() == 0) ||
00050 (mAgentAspect.get() == 0)
00051 )
00052 {
00053 return false;
00054 }
00055
00056 shared_ptr<InitAction> initAction =
00057 shared_dynamic_cast<InitAction>(action);
00058
00059 if (initAction.get() == 0)
00060 {
00061 GetLog()->Error()
00062 << "ERROR: (InitEffector) cannot realize an unknown ActionObject\n";
00063 return false;
00064 }
00065
00066
00067 shared_ptr<AgentState> state = shared_static_cast<AgentState>
00068 (mAgentAspect->GetChildOfClass("AgentState",true));
00069
00070 if (state.get() == 0)
00071 {
00072 GetLog()->Error()
00073 << "ERROR: (InitEffector) cannot find AgentState\n";
00074 return false;
00075 }
00076
00077
00078 mGameState->RequestUniform
00079 (state, initAction->GetName(), initAction->GetNumber());
00080
00081
00082 Vector3f pos = mGameState->RequestInitPosition(state->GetTeamIndex());
00083
00084 shared_ptr<Body> body;
00085 if (SoccerBase::GetAgentBody(mAgentAspect,body))
00086 {
00087 body->SetPosition(pos);
00088 body->SetVelocity(Vector3f(0,0,0));
00089 body->SetAngularVelocity(Vector3f(0,0,0));
00090 }
00091
00092 return true;
00093 }
00094
00095 shared_ptr<ActionObject>
00096 InitEffector::GetActionObject(const Predicate& predicate)
00097 {
00098 if (predicate.name != GetPredicate())
00099 {
00100 GetLog()->Error() << "ERROR: (InitEffector) invalid predicate"
00101 << predicate.name << "\n";
00102 return shared_ptr<ActionObject>();
00103 }
00104
00105 std::string name;
00106 predicate.GetValue(predicate.begin(),"teamname",name);
00107
00108 int unum = 0;
00109 predicate.GetValue(predicate.begin(),"unum",unum);
00110
00111 return shared_ptr<ActionObject>(new InitAction(GetPredicate(),name,unum));
00112 }
00113
00114 void InitEffector::OnLink()
00115 {
00116 mGameState = shared_dynamic_cast<GameStateAspect>
00117 (SoccerBase::GetControlAspect(*this,"GameStateAspect"));
00118 mAgentAspect = GetAgentAspect();
00119 if (mAgentAspect.get() == 0)
00120 {
00121 GetLog()->Error()
00122 << "ERROR: (InitEffector) cannot get AgentAspect\n";
00123 }
00124 }
00125
00126 void InitEffector::OnUnlink()
00127 {
00128 mGameState.reset();
00129 mAgentAspect.reset();
00130 }
00131
00132