Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

initeffector.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: initeffector.cpp,v 1.5 2004/03/23 09:37:13 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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     // search for the AgentState
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     // register the uniform number and team index to the GameStateAspect
00078     mGameState->RequestUniform
00079         (state, initAction->GetName(), initAction->GetNumber());
00080 
00081     // request an initial position for the agent and move it there
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 

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4