You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(153) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(48) |
Feb
(46) |
Mar
(12) |
Apr
(4) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
(263) |
Mar
(235) |
Apr
(66) |
May
(42) |
Jun
(270) |
Jul
(65) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:37
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/gamestateaspect Added Files: Tag: projectx gamestateaspect.cpp gamestateaspect.h gamestateaspect_c.cpp gamestateitem.cpp gamestateitem.h gamestateitem_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: gamestateitem.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: gamestateitem.cpp,v 1.1.2.1 2007/03/07 10:39:32 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 "gamestateitem.h" #include "gamestateaspect.h" #include <soccer/soccerbase/soccerbase.h> using namespace oxygen; using namespace std; GameStateItem::GameStateItem() : MonitorItem() { ResetSentFlags(); } GameStateItem::~GameStateItem() { } void GameStateItem::ResetSentFlags() { mSentLeftTeamname = false; mSentRightTeamname = false; mLastHalf = GH_NONE; mLastLeftScore = -1; mLastRightScore = -1; mLastPlayMode = PM_NONE; mSentFlags = false; } void GameStateItem::PutFloatParam(const string& name, PredicateList& pList) { float value; if (! SoccerBase::GetSoccerVar(*this,name,value)) { return; } Predicate& pred = pList.AddPredicate(); pred.name = name; pred.parameter.AddValue(value); } void GameStateItem::GetInitialPredicates(PredicateList& pList) { ResetSentFlags(); // field geometry parameter PutFloatParam("FieldLength",pList); PutFloatParam("FieldWidth",pList); PutFloatParam("FieldHeight",pList); PutFloatParam("GoalWidth",pList); PutFloatParam("GoalDepth",pList); PutFloatParam("GoalHeight",pList); PutFloatParam("BorderSize",pList); PutFloatParam("FreeKickDistance",pList); PutFloatParam("WaitBeforeKickOff",pList); // agent parameter PutFloatParam("AgentMass",pList); PutFloatParam("AgentRadius",pList); PutFloatParam("AgentMaxSpeed",pList); // ball parameter PutFloatParam("BallRadius",pList); PutFloatParam("BallMass",pList); // soccer rule parameters PutFloatParam("RuleGoalPauseTime",pList); PutFloatParam("RuleKickInPauseTime",pList); PutFloatParam("RuleHalfTime",pList); // play modes Predicate& pred = pList.AddPredicate(); pred.name = "play_modes"; for (int i=0; i<PM_NONE; ++i) { pred.parameter.AddValue (SoccerBase::PlayMode2Str(static_cast<TPlayMode>(i))); } } void GameStateItem::GetPredicates(PredicateList& pList) { if (mGameState.get() == 0) { return; } Predicate& timePred = pList.AddPredicate(); timePred.name = "time"; timePred.parameter.AddValue(mGameState->GetTime()); if (! mSentLeftTeamname) { // team names string name = mGameState->GetTeamName(TI_LEFT); if (! name.empty()) { Predicate& teamPredLeft = pList.AddPredicate(); teamPredLeft.name = "team_left"; teamPredLeft.parameter.AddValue(name); mSentLeftTeamname = true; } } if (! mSentRightTeamname) { // team names string name = mGameState->GetTeamName(TI_RIGHT); if (! name.empty()) { Predicate& teamPredRight = pList.AddPredicate(); teamPredRight.name = "team_right"; teamPredRight.parameter.AddValue(name); mSentRightTeamname = true; } } // game half TGameHalf half = mGameState->GetGameHalf(); if (half != mLastHalf) { mLastHalf = half; Predicate& halfPred = pList.AddPredicate(); halfPred.name = "half"; halfPred.parameter.AddValue(static_cast<int>(half)); } // scores int left_score = mGameState->GetScore(TI_LEFT); if (left_score != mLastLeftScore) { mLastLeftScore = left_score; Predicate& scoreLeftPred = pList.AddPredicate(); scoreLeftPred.name = "score_left"; scoreLeftPred.parameter.AddValue(left_score); } int right_score = mGameState->GetScore(TI_RIGHT); if (right_score != mLastRightScore) { mLastRightScore = right_score; Predicate& scoreRightPred = pList.AddPredicate(); scoreRightPred.name = "score_right"; scoreRightPred.parameter.AddValue(right_score); } // gamestate TPlayMode play_mode = mGameState->GetPlayMode(); if (play_mode != mLastPlayMode) { mLastPlayMode = play_mode; Predicate& modePred = pList.AddPredicate(); modePred.name = "play_mode"; modePred.parameter.AddValue(static_cast<int>(play_mode)); } } void GameStateItem::OnLink() { SoccerBase::GetGameState(*this,mGameState); } void GameStateItem::OnUnlink() { mGameState.reset(); } --- NEW FILE: gamestateitem_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: gamestateitem_c.cpp,v 1.1.2.1 2007/03/07 10:39:33 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 "gamestateitem.h" using namespace oxygen; void CLASS(GameStateItem)::DefineClass() { DEFINE_BASECLASS(MonitorItem); } --- NEW FILE: gamestateaspect_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: gamestateaspect_c.cpp,v 1.1.2.1 2007/03/07 10:39:32 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 "gamestateaspect.h" using namespace oxygen; FUNCTION(GameStateAspect,kickOff) { obj->KickOff(); return true; } void CLASS(GameStateAspect)::DefineClass() { DEFINE_BASECLASS(SoccerControlAspect); DEFINE_FUNCTION(kickOff); } --- NEW FILE: gamestateitem.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: gamestateitem.h,v 1.1.2.1 2007/03/07 10:39:32 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 GAMESTATEITEM_H #define GAMESTATEITEM_H #include <oxygen/monitorserver/monitoritem.h> #include <soccer/soccerbase/soccerbase.h> class GameStateAspect; class GameStateItem : public oxygen::MonitorItem { public: GameStateItem(); virtual ~GameStateItem(); /** This function is called once for every MonitorSystem each time * a new client connects. It should append predicates to a list * that is sent using the active monitor */ virtual void GetInitialPredicates(oxygen::PredicateList& pList); /** This function will be called periodically to append predicates to a list that is sent using the active monitor */ virtual void GetPredicates(oxygen::PredicateList& pList); /** sets the reference to the GameStateAspect */ virtual void OnLink(); /** resets the reference to the GameStateAspect */ virtual void OnUnlink(); protected: void ResetSentFlags(); /** helper method that queries the ScriptServer for the float variable name and appends a predicate describing it to pList */ void PutFloatParam(const std::string& name, oxygen::PredicateList& pList); protected: boost::shared_ptr<GameStateAspect> mGameState; // flags for sent information //! flag if we already sent the left teamname bool mSentLeftTeamname; //! flag if we already sent the left teamname bool mSentRightTeamname; //! the last half sent out to monitors TGameHalf mLastHalf; //! the last left score sent out to monitors int mLastLeftScore; //! the last right score sent out to monitors int mLastRightScore; //! the last playmode sent out to monitors TPlayMode mLastPlayMode; //! flag if the monitors received field flags information bool mSentFlags; }; DECLARE_CLASS(GameStateItem) #endif // GAMESTATEITEM_H --- NEW FILE: gamestateaspect.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: gamestateaspect.cpp,v 1.1.2.1 2007/03/07 10:39:31 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 "gamestateaspect.h" #include <zeitgeist/logserver/logserver.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/agentstate/agentstate.h> #include <salt/random.h> using namespace oxygen; using namespace boost; using namespace std; using namespace salt; GameStateAspect::GameStateAspect() : SoccerControlAspect() { mPlayMode = PM_BeforeKickOff; mTime = 0; mLeadTime = 0; mFupTime = 0; mLastModeChange = 0; mGameHalf = GH_FIRST; mScore[0] = 0; mScore[1] = 0; mMaxUnum[0] = 0; mMaxUnum[1] = 0; mLastKickOff = TI_NONE; //mSecondHalfKickOff = TI_NONE; mLeftInit = Vector3f(0,0,0); mRightInit = Vector3f(0,0,0); mFinished = false; } GameStateAspect::~GameStateAspect() { } void GameStateAspect::UpdateTime(float deltaTime) { switch (mPlayMode) { case PM_BeforeKickOff: mLeadTime += deltaTime; break; case PM_GameOver: mFupTime += deltaTime; break; default: mTime += deltaTime; } } void GameStateAspect::Update(float deltaTime) { UpdateTime(deltaTime); } TPlayMode GameStateAspect::GetPlayMode() const { return mPlayMode; } void GameStateAspect::SetPlayMode(TPlayMode mode) { if (mode == mPlayMode) { return; } GetLog()->Normal() << "(GameStateAspect) playmode changed to " << SoccerBase::PlayMode2Str(mode) << " at t=" << mTime << "\n"; mPlayMode = mode; mLastModeChange = mTime; mLeadTime = 0.0; mFupTime = 0.0; } // let the monitor handle who kicks off in 2nd half. void GameStateAspect::KickOff(TTeamIndex ti) { // throw a coin to determine which team kicks off if (ti == TI_NONE) { ti = (salt::UniformRNG<>(0,1)() <= 0.5) ? TI_LEFT : TI_RIGHT; } SetPlayMode((ti == TI_LEFT) ? PM_KickOff_Left : PM_KickOff_Right); if (mLastKickOff == TI_NONE) mLastKickOff = ti; } // void // GameStateAspect::KickOff(TTeamIndex ti) // { // if (mGameHalf == GH_FIRST) // { // // throw a coin to determine which team kicks off // if (ti == TI_NONE) // { // ti = (salt::UniformRNG<>(0,1)() <= 0.5) ? TI_LEFT : TI_RIGHT; // } // SetPlayMode((ti == TI_LEFT) ? PM_KickOff_Left : PM_KickOff_Right); // if (mLastKickOff == TI_NONE) // mLastKickOff = ti; // } // else // { // // in the second half, let the opposite team kick off // SetPlayMode((mLastKickOff == TI_LEFT) ? PM_KickOff_Right : PM_KickOff_Left); // } // } //--------------------------------------------- // void // GameStateAspect::KickOff(TTeamIndex ti) // { // if (mGameHalf == GH_FIRST) // { // // throw a coin to determine which team kicks off // if (ti == TI_NONE) // { // ti = (salt::UniformRNG<>(0,1)() <= 0.5) ? TI_LEFT : TI_RIGHT; // } // SetPlayMode((ti == TI_LEFT) ? PM_KickOff_Left : PM_KickOff_Right); // mLastKickOff = ti; // if (mSecondHalfKickOff == TI_NONE) // { // //clog << "setting mSecondHalfKickOff\n"; // mSecondHalfKickOff = // (mLastKickOff == TI_LEFT) ? TI_RIGHT : TI_LEFT; // } // } // else // { // // in the second half, let the opposite team kick off // SetPlayMode((mSecondHalfKickOff == TI_LEFT) ? PM_KickOff_Left : PM_KickOff_Right); // } // } //--------------------------------------------- TTime GameStateAspect::GetTime() const { return mTime; } TTime GameStateAspect::GetModeTime() const { switch (mPlayMode) { case PM_BeforeKickOff: return mLeadTime; case PM_GameOver: return mFupTime; default: return mTime - mLastModeChange; } } TTime GameStateAspect::GetLastModeChange() const { return mLastModeChange; } void GameStateAspect::SetTeamName(TTeamIndex idx, const std::string& name) { switch (idx) { case TI_LEFT: mTeamName[0] = name; break; case TI_RIGHT: mTeamName[1] = name; break; } return; } std::string GameStateAspect::GetTeamName(TTeamIndex idx) const { switch (idx) { case TI_LEFT: return mTeamName[0]; case TI_RIGHT: return mTeamName[1]; default: return ""; } } TTeamIndex GameStateAspect::GetTeamIndex(const std::string& teamName) { for (int i=0; i<=1; ++i) { if (mTeamName[i].empty()) { mTeamName[i] = teamName; return static_cast<TTeamIndex>(i + TI_LEFT); } if (mTeamName[i] == teamName) { return static_cast<TTeamIndex>(i + TI_LEFT); } } return TI_NONE; } bool GameStateAspect::InsertUnum(TTeamIndex idx, int unum) { int i; switch (idx) { case TI_LEFT: i = 0; break; case TI_RIGHT: i = 1; break; default: return false; } TUnumSet& set = mUnumSet[i]; if ( (set.size() >= 11) || (set.find(unum) != set.end()) ) { return false; } set.insert(unum); mMaxUnum[i] = std::max<int>(unum, mMaxUnum[i]); return true; } bool GameStateAspect::RequestUniform(shared_ptr<AgentState> agentState, std::string teamName, unsigned int unum) { if (agentState.get() == 0) { return false; } TTeamIndex idx = GetTeamIndex(teamName); if (idx == TI_NONE) { GetLog()->Error() << "ERROR: (GameStateAspect::RequestUniform) invalid teamname " << teamName << "\n"; return false; } if (unum == 0) { unum = RequestUniformNumber(idx); } if (! InsertUnum(idx,unum)) { GetLog()->Error() << "ERROR: (GameStateAspect::RequestUniform) cannot insert uniform" " number " << unum << " to team " << teamName << "\n"; return false; } agentState->SetUniformNumber(unum); agentState->SetTeamIndex(idx); //agentState->SetPerceptName(teamName, ObjectState::PT_Default); agentState->SetPerceptName(teamName, ObjectState::PT_Default, ObjectState::PT_Player ); agentState->SetPerceptName("player", ObjectState::PT_TooFar); GetLog()->Normal() << "(GameStateAspect) handed out uniform number " << unum << " for team " << teamName << "\n"; return true; } void GameStateAspect::SetGameHalf(TGameHalf half) { if ( (half != GH_FIRST) && (half != GH_SECOND) ) { return; } mGameHalf = half; } TGameHalf GameStateAspect::GetGameHalf() const { return mGameHalf; } void GameStateAspect::ScoreTeam(TTeamIndex idx) { switch (idx) { case TI_LEFT: ++mScore[0]; break; case TI_RIGHT: ++mScore[1]; break; } return; } int GameStateAspect::GetScore(TTeamIndex idx) const { switch (idx) { case TI_LEFT: return mScore[0]; case TI_RIGHT: return mScore[1]; default: return 0; } } Vector3f GameStateAspect::RequestInitPosition(const TTeamIndex ti) { if (ti == TI_NONE) { GetLog()->Debug() << "(GameStateAspect) RequestInitPosition called with " << "ti=TI_NONE\n"; return Vector3f(0,0,10); } salt::Vector3f& init = (ti ==TI_LEFT) ? mLeftInit : mRightInit; Vector3f pos = init; init[1] -= mAgentRadius * 3; return pos; } void GameStateAspect::OnLink() { // setup the initial starting positions for the agents float fieldWidth = 64.0; SoccerBase::GetSoccerVar(*this,"FieldWidth",fieldWidth); float fieldLength = 100.0; SoccerBase::GetSoccerVar(*this,"FieldLength",fieldLength); mAgentRadius = 0.22; SoccerBase::GetSoccerVar(*this,"AgentRadius",mAgentRadius); mLeftInit = Vector3f ( -fieldLength/2.0 + mAgentRadius*2, fieldWidth/2 - mAgentRadius*2, mAgentRadius ); mRightInit = Vector3f ( +fieldLength/2.0 - mAgentRadius*2, fieldWidth/2 - mAgentRadius*2, mAgentRadius ); } int GameStateAspect::RequestUniformNumber(TTeamIndex ti) const { switch (ti) { case TI_LEFT: return mMaxUnum[0] + 1; case TI_RIGHT: return mMaxUnum[1] + 1; default: return 0; } } --- NEW FILE: gamestateaspect.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: gamestateaspect.h,v 1.1.2.1 2007/03/07 10:39:31 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 GAMESTATEASPECT_H #define GAMESTATEASPECT_H #include <soccer/soccercontrolaspect/soccercontrolaspect.h> #include <set> class AgentState; class GameStateAspect : public SoccerControlAspect { protected: typedef std::set<int> TUnumSet; public: GameStateAspect(); virtual ~GameStateAspect(); /** called during the update of the GameControlServer to allow the ControlAspect to perform any necessary checks. */ virtual void Update(float deltaTime); /** Used by the SexpMonitor to check if the terminating message should be sent. \return true if the match is over */ bool IsFinished() const { return mFinished; } /** finish the simulation */ void Finish() { mFinished = true; } /** returns the current play mode */ TPlayMode GetPlayMode() const; /** sets the current play mode */ void SetPlayMode(TPlayMode mode); /** set the current play mode randomly to PM_KickOff_Left or PM_KickOff_Right. \param ti Team which should do the kick off (if TI_NONE, then do a coin toss) */ void KickOff(TTeamIndex ti = TI_NONE); /** returns the current game time */ TTime GetTime() const; /** returns the time passed since the last playmode change */ TTime GetModeTime() const; /** returns the time of the last playmode change */ TTime GetLastModeChange() const; /** sets the current game half */ void SetGameHalf(TGameHalf half); /** returns the current game half */ TGameHalf GetGameHalf() const; /** sets the name of a team */ void SetTeamName(TTeamIndex idx, const std::string& name); /** returns the name of a team */ std::string GetTeamName(TTeamIndex idx) const; /** called from the InitEffector to request a uniformn number and teamname */ bool RequestUniform(boost::shared_ptr<AgentState> agentState, std::string teamName, unsigned int unum); /** returns the next uniform number not taken for the given team */ int RequestUniformNumber(TTeamIndex ti) const; /** called from the InitEffector to request an initial position for an agent */ salt::Vector3f RequestInitPosition(const TTeamIndex ti); /** increments the score of a team */ void ScoreTeam(TTeamIndex idx); /** returns the score of a team */ int GetScore(TTeamIndex idx) const; protected: /** setup the init positions for the agents */ virtual void OnLink(); /** advances the game time */ void UpdateTime(float deltaTime); /** checks if the set of uniform numbers of given team already contains a uniform number unum and inserts it. */ bool InsertUnum(TTeamIndex idx, int unum); /** returns the team index corresponding to the given teamName. If the teamname does not exist and less than two teams are registered, the given team name is registered. */ TTeamIndex GetTeamIndex(const std::string& teamName); protected: /** the current play mode */ TPlayMode mPlayMode; /** the last time the play mode changed */ TTime mLastModeChange; /** the current game time */ TTime mTime; /** the current time before the match started */ TTime mLeadTime; /** the time in game state Game Over */ TTime mFupTime; /** the current half of the game */ TGameHalf mGameHalf; /** the team that had the last KickOff */ TTeamIndex mLastKickOff; // /** the team that has to start the second half */ // TTeamIndex mSecondHalfKickOff; /** the names of the two teams */ std::string mTeamName[2]; /** the set of uniform number for each team */ TUnumSet mUnumSet[2]; /** the maximal uniform number handed out for each team */ int mMaxUnum[2]; /** the scores of two teams */ int mScore[2]; /** the position where the last left player was put initially */ salt::Vector3f mLeftInit; /** the position where the last right player was put initially */ salt::Vector3f mRightInit; /** the radius of an agent */ float mAgentRadius; /** flag if the simulation should be stopped */ bool mFinished; }; DECLARE_CLASS(GameStateAspect); #endif // GAMESTATEASPECT_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:34
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/fieldflag In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/fieldflag Added Files: Tag: projectx fieldflag.h fieldflag_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: fieldflag.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: fieldflag.h,v 1.1.2.1 2007/03/07 10:39:30 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 FIELDFLAG_H #define FIELDFLAG_H #include <oxygen/sceneserver/transform.h> /** \class FieldFlag represents a flag that marks a position on the playing field. It is used to mark a position in the scene. */ class FieldFlag : public oxygen::Transform { public: FieldFlag() : Transform() {}; virtual ~FieldFlag() {}; }; DECLARE_CLASS(FieldFlag); #endif // FIELDFLAG_H --- NEW FILE: fieldflag_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: fieldflag_c.cpp,v 1.1.2.1 2007/03/07 10:39:30 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 "fieldflag.h" using namespace oxygen; void CLASS(FieldFlag)::DefineClass() { DEFINE_BASECLASS(oxygen/Transform); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:34
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/driveeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/driveeffector Added Files: Tag: projectx driveaction.h driveeffector.cpp driveeffector.h driveeffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: driveeffector.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: driveeffector.cpp,v 1.1.2.1 2007/03/07 10:39:28 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 "driveaction.h" #include "driveeffector.h" #include <salt/gmath.h> #include <zeitgeist/logserver/logserver.h> #include <oxygen/physicsserver/spherecollider.h> #include <soccer/soccerbase/soccerbase.h> using namespace boost; using namespace oxygen; using namespace salt; DriveEffector::DriveEffector() : oxygen::Effector(), mForceFactor(60.0), mMaxPower(100.0), mConsumption(1.0/18000.0) { } DriveEffector::~DriveEffector() { } bool DriveEffector::Realize(boost::shared_ptr<ActionObject> action) { if (mBody.get() == 0) { return false; } shared_ptr<BaseNode> parent = shared_dynamic_cast<BaseNode>(make_shared(GetParent())); if (parent.get() == 0) { GetLog()->Error() << "ERROR: (DriveEffector) parent node is not derived from BaseNode\n"; return false; } shared_ptr<DriveAction> driveAction = shared_dynamic_cast<DriveAction>(action); if (driveAction.get() == 0) { GetLog()->Error() << "ERROR: (DriveEffector) cannot realize an unknown ActionObject\n"; return false; } mForce = driveAction->GetForce(); // cut down the drive power vector to maximum length if (mForce.SquareLength() > mMaxPower * mMaxPower) { mForce.Normalize(); mForce *= mMaxPower; } if (mForceErrorRNG.get() != 0) { mForce[0] = mForce[0] * (*(mForceErrorRNG.get()))() * mForceFactor; mForce[1] = mForce[1] * (*(mForceErrorRNG.get()))() * mForceFactor; mForce[2] = mForce[2] * (*(mForceErrorRNG.get()))() * mForceFactor; } else { mForce = mForce * mForceFactor; } return true; } shared_ptr<ActionObject> DriveEffector::GetActionObject(const Predicate& predicate) { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (DriveEffector) invalid predicate" << predicate.name << "\n"; return shared_ptr<ActionObject>(); } Vector3f force; if (! predicate.GetValue(predicate.begin(), force)) { GetLog()->Error() << "ERROR: (DriveEffector) Vector3f parameter expected\n"; return shared_ptr<ActionObject>(new ActionObject(GetPredicate())); } return shared_ptr<ActionObject>(new DriveAction(GetPredicate(),force)); } void DriveEffector::OnLink() { SoccerBase::GetTransformParent(*this,mTransformParent); SoccerBase::GetBody(*this,mBody); SoccerBase::GetAgentState(*this,mAgentState); shared_ptr<SphereCollider> geom = shared_dynamic_cast<SphereCollider>(mTransformParent->GetChild("geometry")); mMaxDistance = 0.001; if (geom.get() == 0) { GetLog()->Error() << "ERROR: (DriveEffector) parent node has " << "no 'geometry' sphere child\n"; } else { mMaxDistance += geom->GetRadius(); } } void DriveEffector::OnUnlink() { mForceErrorRNG.reset(); mTransformParent.reset(); mBody.reset(); } void DriveEffector::SetForceFactor(float force_factor) { mForceFactor = salt::gAbs(force_factor); } void DriveEffector::SetSigma(float sigma) { NormalRngPtr rng(new salt::NormalRNG<>(1.0,sigma)); mForceErrorRNG = rng; } void DriveEffector::SetMaxPower(float max_power) { mMaxPower = max_power; } void DriveEffector::PrePhysicsUpdateInternal(float deltaTime) { Effector::PrePhysicsUpdateInternal(deltaTime); if (mBody.get() == 0 || mForce.Length() <= std::numeric_limits<float>::epsilon()) { return; } Vector3f vec = mTransformParent->GetWorldTransform().Pos(); if (vec.z() > mMaxDistance) return; if (mAgentState->ReduceBattery(mForce.Length() * mConsumption)) { mBody->AddForce(SoccerBase::FlipView(mForce,mAgentState->GetTeamIndex())); } } void DriveEffector::SetConsumption(float consume_time) { mConsumption = 1.0 / consume_time; } --- NEW FILE: driveaction.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: driveaction.h,v 1.1.2.1 2007/03/07 10:39:28 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 DRIVEACTION_H #define DRIVEACTION_H #include <oxygen/gamecontrolserver/actionobject.h> #include <salt/vector.h> class DriveAction : public oxygen::ActionObject { public: DriveAction(const std::string& predicate, salt::Vector3f force) : ActionObject(predicate), mForce(force) {} virtual ~DriveAction() {} /** returns the stored force vector */ const salt::Vector3f& GetForce() { return mForce; } protected: /** the force to be applied by the DriveEffector */ salt::Vector3f mForce; }; #endif // DRIVEACTION_H --- NEW FILE: driveeffector_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: driveeffector_c.cpp,v 1.1.2.1 2007/03/07 10:39:29 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 "driveeffector.h" using namespace oxygen; FUNCTION(DriveEffector,setForceFactor) { float inForceFactor; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inForceFactor)) ) { return false; } obj->SetForceFactor(inForceFactor); return true; } FUNCTION(DriveEffector,setSigma) { float inSigma; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inSigma)) ) { return false; } obj->SetSigma(inSigma); return true; } FUNCTION(DriveEffector,setMaxPower) { float inMaxPower; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inMaxPower)) ) { return false; } obj->SetMaxPower(inMaxPower); return true; } FUNCTION(DriveEffector,setConsumption) { float inConsumption; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inConsumption)) ) { return false; } obj->SetConsumption(inConsumption); return true; } void CLASS(DriveEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); DEFINE_FUNCTION(setForceFactor); DEFINE_FUNCTION(setSigma); DEFINE_FUNCTION(setMaxPower); DEFINE_FUNCTION(setConsumption); } --- NEW FILE: driveeffector.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: driveeffector.h,v 1.1.2.1 2007/03/07 10:39:28 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 DRIVEEFFECTOR_H #define DRIVEEFFECTOR_H #include <salt/random.h> #include <oxygen/agentaspect/effector.h> #include <oxygen/physicsserver/body.h> #include <soccer/agentstate/agentstate.h> class DriveEffector : public oxygen::Effector { public: DriveEffector(); virtual ~DriveEffector(); /** 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 "drive"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); /** Set the force factor. * * The drive power vector is multiplied by this factor divided by the maximum length * of the drive power vector. */ void SetForceFactor(float force_factor); /** Set the error distribution for calculating the applied force. * * The force applied to a sphere is the drive power vector multiplied by * the force factor divided by (maximum length of the drive power vector + Error). * The error is normaly distributed around zero with a given sigma. If sigma is <= 0, * no error will be applied. */ void SetSigma(float sigma); /** Set the maximum length of the drive power vector. */ void SetMaxPower(float max_power); /** Set the battery consumption. * How long can you be driving full speed with a fully charged battery? * \param consume_time time (in milliseconds) the battery works * driving full speed */ void SetConsumption(float consume_time); protected: virtual void PrePhysicsUpdateInternal(float deltaTime); /** setup the reference to the agents body node */ virtual void OnLink(); /** remove the reference to the agents body node */ virtual void OnUnlink(); protected: typedef boost::shared_ptr<salt::NormalRNG<> > NormalRngPtr; /** the reference to the parent transform node */ boost::shared_ptr<oxygen::Transform> mTransformParent; /** the reference to the parents body node */ boost::shared_ptr<oxygen::Body> mBody; //! a reference to the agent state boost::shared_ptr<AgentState> mAgentState; /** the force that should be applied to the agent body */ salt::Vector3f mForce; /** the maximum distance from the plane */ float mMaxDistance; /** The force factor is the force applied to the body if the length of the drive power vector is greater or equal to mMaxDrivePower */ float mForceFactor; /** random number generator for the error distribution of the applied force */ NormalRngPtr mForceErrorRNG; /** The maximum length of the drive power vector. */ float mMaxPower; /** The battery consumption for driving one second with full speed */ double mConsumption; }; DECLARE_CLASS(DriveEffector); #endif // DRIVEEFFECTOR_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:33
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/createeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/createeffector Added Files: Tag: projectx createaction.h createeffector.cpp createeffector.h createeffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: createeffector.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: createeffector.cpp,v 1.1.2.1 2007/03/07 10:39:27 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 "createeffector.h" #include "createaction.h" #include <oxygen/agentaspect/agentaspect.h> #include <oxygen/gamecontrolserver/actionobject.h> #include <zeitgeist/logserver/logserver.h> #include <zeitgeist/scriptserver/scriptserver.h> using namespace oxygen; using namespace boost; using namespace zeitgeist; using namespace std; CreateEffector::CreateEffector() : Effector() { } bool CreateEffector::Realize(shared_ptr<ActionObject> action) { shared_ptr<CreateAction> createAction = shared_dynamic_cast<CreateAction>(action); if (createAction.get() == 0) { GetLog()->Error() << "ERROR: (CreateEffector) cannot realize an unknown ActionObject\n"; return false; } shared_ptr<AgentAspect> aspect = GetAgentAspect(); if (aspect.get() == 0) { GetLog()->Error() << "ERROR: (CreateEffector) cannot find the AgentAspect\n"; return false; } // call the ruby addAgent function that has to be defined in the // simulator init script with the AgentAspect path as the // argument. This function is then responsible to construct the // remaining agent nodes string cmd = "addAgent('" + aspect->GetFullPath() + "')"; GetCore()->GetScriptServer()->Eval(cmd); return true; } shared_ptr<ActionObject> CreateEffector::GetActionObject(const Predicate& predicate) { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (CreateEffector) invalid predicate" << predicate.name << "\n"; return shared_ptr<ActionObject>(); } // // don't care for the supplied parameters for now; the desired agent // type should be passed later on and stored in the CreateAction object // return shared_ptr<CreateAction>(new CreateAction(GetPredicate())); } --- NEW FILE: createaction.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: createaction.h,v 1.1.2.1 2007/03/07 10:39:27 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 CREATEACTION_H #define CREATEACTION_H #include <oxygen/gamecontrolserver/actionobject.h> namespace oxygen { class CreateAction : public oxygen::ActionObject { public: CreateAction(const std::string& predicate) : ActionObject(predicate) {} virtual ~CreateAction() {} }; }; // namespace oxygen #endif // CREATEACTION_H --- NEW FILE: createeffector.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: createeffector.h,v 1.1.2.1 2007/03/07 10:39:27 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 CREATEEFFECTOR_H #define CREATEEFFECTOR_H #include <oxygen/agentaspect/effector.h> class CreateEffector : public oxygen::Effector { public: CreateEffector(); virtual ~CreateEffector() {}; /** 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 "create"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); }; DECLARE_CLASS(CreateEffector); #endif // CREATEEFFECTOR_H --- NEW FILE: createeffector_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: createeffector_c.cpp,v 1.1.2.1 2007/03/07 10:39:27 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 <zeitgeist/class.h> #include "createeffector.h" using namespace oxygen; void CLASS(CreateEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:33
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/catcheffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/catcheffector Added Files: Tag: projectx catchaction.h catcheffector.cpp catcheffector.h catcheffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: catchaction.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 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 CATCHACTION_H #define CATCHACTION_H #include <oxygen/gamecontrolserver/actionobject.h> #include <salt/vector.h> class CatchAction : public oxygen::ActionObject { public: CatchAction(const std::string& predicate) : ActionObject(predicate){} virtual ~CatchAction() {} }; #endif // CATCHACTION_H --- NEW FILE: catcheffector.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 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 "catchaction.h" #include "catcheffector.h" #include <salt/random.h> #include <zeitgeist/logserver/logserver.h> #include <oxygen/sceneserver/transform.h> #include <oxygen/physicsserver/spherecollider.h> #include <oxygen/agentaspect/agentaspect.h> #include <oxygen/physicsserver/body.h> #include <oxygen/gamecontrolserver/gamecontrolserver.h> #include <soccer/ballstateaspect/ballstateaspect.h> #include <soccer/agentstate/agentstate.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/soccercontrolaspect/soccercontrolaspect.h> #include <soccer/soccerruleaspect/soccerruleaspect.h> using namespace boost; using namespace oxygen; using namespace salt; using namespace std; CatchEffector::CatchEffector() : oxygen::Effector(), mCatchMargin(1.00),mPlayerRadius(0.0),mBallRadius(0.0) { } CatchEffector::~CatchEffector() { } void CatchEffector::MoveBall(const Vector3f& pos) { mBallBody->SetPosition(pos); mBallBody->SetVelocity(Vector3f(0,0,0)); mBallBody->SetAngularVelocity(Vector3f(0,0,0)); } bool CatchEffector::Realize(boost::shared_ptr<ActionObject> action) { // this should also include the case when there is no ball // (because then there will be no body, neither). if (mBallBody.get() == 0) { return false; } if (mAgent.get() == 0) { GetLog()->Error() << "ERROR: (CatchEffector) parent node is not derived " << "from BaseNode\n"; return false; } if (mAgentState.get() == 0) { GetLog()->Error() << "ERROR: (CatchEffector) parent node is not derived " << "from BaseNode\n"; return false; } shared_ptr<CatchAction> catchAction = shared_dynamic_cast<CatchAction>(action); if (catchAction.get() == 0) { GetLog()->Error() << "ERROR: (CatchEffector) cannot realize an unknown " << "ActionObject\n"; return false; } if (mAgentState->GetUniformNumber() != 1) { return true; } Vector3f pos = mBallBody->GetWorldTransform().Pos(); if ( mAgentState->GetTeamIndex() == TI_LEFT ) { if (! mLeftPenaltyArea.Contains(Vector2f(pos[0], pos[1]))) { return true; } } else { if (! mRightPenaltyArea.Contains(Vector2f(pos[0], pos[1]))) { return true; } } Vector3f ballVec = mBallBody->GetWorldTransform().Pos() - mAgent->GetWorldTransform().Pos(); // the ball can be catched if the distance is // less then Ball-Radius + Player-Radius + CatchMargin AND // the player is close to the ground if (mAgent->GetWorldTransform().Pos().z() > mPlayerRadius + 0.01 || ballVec.Length() > mPlayerRadius + mBallRadius + mCatchMargin) { // ball is out of reach, or player is in the air: // catch has no effect return true; } Vector3f ballPos = mAgent->GetWorldTransform().Pos(); ballPos[2]= mBallRadius; if (mAgentState->GetTeamIndex() == TI_LEFT) { ballPos[0] += mBallRadius + mPlayerRadius + 0.07; } else { ballPos[0] -= mBallRadius + mPlayerRadius + 0.07; } mSoccerRule->ClearPlayersWithException(ballPos, 2.0, 5.0, TI_LEFT, mAgentState); mSoccerRule->ClearPlayersWithException(ballPos, 2.0, 5.0, TI_RIGHT, mAgentState); MoveBall(ballPos); return true; } shared_ptr<ActionObject> CatchEffector::GetActionObject(const Predicate& predicate) { do { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (CatchEffector) invalid predicate" << predicate.name << "\n"; break; } // construct the CatchAction object return shared_ptr<CatchAction>(new CatchAction(GetPredicate())); } while (0); // some error happened return shared_ptr<ActionObject>(); } void CatchEffector::OnLink() { SoccerBase::GetBallBody(*this,mBallBody); SoccerBase::GetAgentState(*this,mAgentState); SoccerBase::GetSoccerRuleAspect(*this,mSoccerRule); mAgent = shared_dynamic_cast<AgentAspect>(make_shared(GetParent())); if (mAgent.get() == 0) { GetLog()->Error() << "ERROR: (CatchEffector) parent node is not derived " << "from AgentAspect\n"; return; } shared_ptr<SphereCollider> geom = shared_dynamic_cast<SphereCollider>(mAgent->GetChild("geometry")); if (geom.get() == 0) { GetLog()->Error() << "ERROR: (CatchEffector) parent node has no SphereCollider " << "child\n"; } else { mPlayerRadius = geom->GetRadius(); } if (! SoccerBase::GetBallCollider(*this,geom)) { GetLog()->Error() << "ERROR: (CatchEffector) ball node has no SphereCollider " << "child\n"; } else { mBallRadius = geom->GetRadius(); } SoccerBase::GetSoccerVar(*this,"FieldLength",mFieldLength); SoccerBase::GetSoccerVar(*this,"GoalWidth",mGoalWidth); // the penalty areas (exact sizes) mRightPenaltyArea = salt::AABB2( Vector2f(mFieldLength/2.0 - 16.5, -16.5 - mGoalWidth/2.0), Vector2f(mFieldLength/2.0 , 16.5 + mGoalWidth/2.0)); mLeftPenaltyArea = salt::AABB2( Vector2f(-mFieldLength/2.0 + 16.5, -16.5 - mGoalWidth/2.0), Vector2f(-mFieldLength/2.0, 16.5 + mGoalWidth/2.0)); } void CatchEffector::OnUnlink() { mSoccerRule.reset(); mBallBody.reset(); mAgent.reset(); mAgentState.reset(); } void CatchEffector::SetCatchMargin(float margin) { mCatchMargin = margin; } --- NEW FILE: catcheffector.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 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 CATCHEFFECTOR_H #define CATCHEFFECTOR_H #include <oxygen/agentaspect/effector.h> #include <oxygen/physicsserver/body.h> #include <soccer/ball/ball.h> #include <soccer/ballstateaspect/ballstateaspect.h> namespace salt { class AABB2; } namespace oxygen { class Body; class AgentAspect; } class AgentState; class SoccerRuleAspect; class CatchEffector : public oxygen::Effector { public: CatchEffector(); virtual ~CatchEffector(); /** 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 "catch"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); /** setup the reference to the ball body node */ virtual void OnLink(); /** remove the reference to the ball body node */ virtual void OnUnlink(); /** set the catch margin (the area within objects are catchable) */ void SetCatchMargin(float margin); protected: /** moves the ball to pos setting its linear and angular velocity to 0 */ void MoveBall(const salt::Vector3f& pos); /** reference to the soccer rule aspect */ boost::shared_ptr<SoccerRuleAspect> mSoccerRule; protected: /** reference to the body node of the ball */ boost::shared_ptr<oxygen::Body> mBallBody; /** reference to the agent aspect */ boost::shared_ptr<oxygen::AgentAspect> mAgent; /** reference to the agentstate */ boost::shared_ptr<AgentState> mAgentState; /** bounding box for the right penalty area */ salt::AABB2 mRightPenaltyArea; /** bounding box for the left penalty area */ salt::AABB2 mLeftPenaltyArea; /** the field length (in meters) */ float mFieldLength; /** the goal width (in meters) */ float mGoalWidth; private: /** the margin where objects can be catched */ float mCatchMargin; /** radius of the player */ float mPlayerRadius; /** radius of the ball */ float mBallRadius; }; DECLARE_CLASS(CatchEffector); #endif // CATCHEFFECTOR_H --- NEW FILE: catcheffector_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 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 "catcheffector.h" using namespace oxygen; FUNCTION(CatchEffector,setCatchMargin) { float inMargin; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inMargin)) ) { return false; } obj->SetCatchMargin(inMargin); return true; } void CLASS(CatchEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); DEFINE_FUNCTION(setCatchMargin); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:33
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/ballstateaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/ballstateaspect Added Files: Tag: projectx ballstateaspect.cpp ballstateaspect.h ballstateaspect_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: ballstateaspect.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: ballstateaspect.cpp,v 1.1.2.1 2007/03/07 10:39:20 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 "ballstateaspect.h" #include <zeitgeist/logserver/logserver.h> #include <oxygen/sceneserver/sceneserver.h> #include <oxygen/sceneserver/scene.h> #include <oxygen/agentaspect/agentaspect.h> #include <oxygen/physicsserver/recorderhandler.h> #include <soccer/gamestateaspect/gamestateaspect.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/ball/ball.h> using namespace oxygen; using namespace boost; using namespace std; using namespace salt; BallStateAspect::BallStateAspect() : SoccerControlAspect() { mBallOnField = false; mLastValidBallPos = Vector3f(0,0,0); mGoalState = TI_NONE; mLastAgentCollisionTime = 0; } BallStateAspect::~BallStateAspect() { } bool BallStateAspect::GetLastCollidingAgent(shared_ptr<AgentAspect>& agent, TTime& time) { agent = mLastCollidingAgent; time = mLastAgentCollisionTime; return (agent.get() != 0); } bool BallStateAspect::GetLastKickingAgent(shared_ptr<AgentAspect>& agent, TTime& time) { agent = mLastKickingAgent; time = mLastAgentKickTime; return (agent.get() != 0); } void BallStateAspect::UpdateLastCollidingAgent() { // get a list of agents that collided with the ball since the last // update of the recorder and remember the first returned node as // the last agent that collided with the ball. RecorderHandler::TParentList agents; mBallRecorder->GetParentsSupportingClass("AgentAspect",agents); if (agents.size() > 0) { mLastCollidingAgent = shared_static_cast<AgentAspect> (make_shared(agents.front())); mLastAgentCollisionTime = mGameState->GetTime(); } // empty the recorder buffer mBallRecorder->Clear(); } void BallStateAspect::UpdateLastCollidingAgent(boost::shared_ptr<AgentAspect> agent) { mLastCollidingAgent = agent; mLastAgentCollisionTime = mGameState->GetTime(); } void BallStateAspect::UpdateLastKickingAgent(boost::shared_ptr<AgentAspect> agent) { mLastKickingAgent = agent; mLastAgentKickTime = mGameState->GetTime(); } void BallStateAspect::UpdateBallOnField() { // get a list of Ball nodes that collided with the field RecorderHandler::TParentList ball; mFieldRecorder->GetParentsSupportingClass("Ball",ball); // the ball is on or above the playing field iff it collided with // the box collider around the playing field mBallOnField = (ball.size() > 0); // empty the recorder buffer mFieldRecorder->Clear(); } void BallStateAspect::UpdateLastValidBallPos() { if (! mBallOnField) { return; } mLastValidBallPos = mBall->GetWorldTransform().Pos(); } void BallStateAspect::UpdateGoalState() { // check both goal box collider RecorderHandler::TParentList ball; mLeftGoalRecorder->GetParentsSupportingClass("Ball",ball); if (! ball.empty()) { mGoalState = TI_LEFT; } else { mRightGoalRecorder->GetParentsSupportingClass("Ball",ball); if (! ball.empty()) { mGoalState = TI_RIGHT; } else { mGoalState = TI_NONE; } } mLeftGoalRecorder->Clear(); mRightGoalRecorder->Clear(); } TTeamIndex BallStateAspect::GetGoalState() { return mGoalState; } void BallStateAspect::Update(float deltaTime) { if ( (mFieldRecorder.get() == 0) || (mBall.get() == 0) || (mBallRecorder.get() == 0) || (mLeftGoalRecorder.get() == 0) || (mRightGoalRecorder.get() == 0) ) { return; } UpdateLastCollidingAgent(); UpdateBallOnField(); UpdateLastValidBallPos(); UpdateGoalState(); } void BallStateAspect::OnLink() { SoccerControlAspect::OnLink(); mFieldRecorder = GetFieldRecorder(); SoccerBase::GetBall(*this,mBall); mBallRecorder = GetBallRecorder(); mLeftGoalRecorder = GetLeftGoalRecorder(); mRightGoalRecorder = GetRightGoalRecorder(); mGameState = shared_dynamic_cast<GameStateAspect> (GetControlAspect("GameStateAspect")); } void BallStateAspect::OnUnlink() { SoccerControlAspect::OnUnlink(); mBallRecorder.reset(); mFieldRecorder.reset(); mLastCollidingAgent.reset(); mLeftGoalRecorder.reset(); mRightGoalRecorder.reset(); mGameState.reset(); } bool BallStateAspect::GetBallOnField() { return mBallOnField; } salt::Vector3f BallStateAspect::GetLastValidBallPosition() { return mLastValidBallPos; } --- NEW FILE: ballstateaspect.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: ballstateaspect.h,v 1.1.2.1 2007/03/07 10:39:20 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 BALLLSTATEASPECT_H #define BALLLSTATEASPECT_H #include <soccer/soccercontrolaspect/soccercontrolaspect.h> /** BallStateAspect is a ControlAspect that holds information about the current state of the ball in the simulation. */ class Ball; namespace oxygen { class RecorderHandler; class AgentAspect; } class BallStateAspect : public SoccerControlAspect { public: BallStateAspect(); virtual ~BallStateAspect(); /** called during the update of the GameControlServer to allow the ControlAspect to perform any necessary checks. */ virtual void Update(float deltaTime); /** returns the last agent that collided with the ball and the time when this happened*/ bool GetLastCollidingAgent (boost::shared_ptr<oxygen::AgentAspect>& agent, TTime& time); /** returns the last agent that kicked the ball and the time when this happened*/ bool GetLastKickingAgent (boost::shared_ptr<oxygen::AgentAspect>& agent, TTime& time); /** returns true if the ball over the playing field */ bool GetBallOnField(); /** returns the last valid position of the ball over the playing field */ salt::Vector3f GetLastValidBallPosition(); /** returns the goal in which the balls position is or TI_NONE otherwise */ TTeamIndex GetGoalState(); /** updates the reference to the last agent that collided with the ball */ void UpdateLastCollidingAgent(boost::shared_ptr<oxygen::AgentAspect> agent); /** updates the reference to the last agent that kicked the ball */ void UpdateLastKickingAgent(boost::shared_ptr<oxygen::AgentAspect> agent); protected: /** set up the reference to the ball and field collider */ virtual void OnLink(); /** reset the reference to the ball and field recorder */ virtual void OnUnlink(); /** updates the reference to the last agent that collided with the ball */ void UpdateLastCollidingAgent(); /** checks if the ball is on the playing field an updates the mBallOnField flag */ void UpdateBallOnField(); /** checks if the ball is in one of the goals and updates the mGoalState member*/ void UpdateGoalState(); /** if the ball has a valid position, i.e. is on the field, remember it */ void UpdateLastValidBallPos(); protected: /** reference to the Ball node */ boost::shared_ptr<Ball> mBall; /** reference to the Ball collision recorder */ boost::shared_ptr<oxygen::RecorderHandler> mBallRecorder; /** reference to the field collider */ boost::shared_ptr<oxygen::RecorderHandler> mFieldRecorder; /** reference to the left goal recorder */ boost::shared_ptr<oxygen::RecorderHandler> mLeftGoalRecorder; /** reference to the right goal recorder */ boost::shared_ptr<oxygen::RecorderHandler> mRightGoalRecorder; /** holds a reference to the last agent that collided with the ball */ boost::shared_ptr<oxygen::AgentAspect> mLastCollidingAgent; /** holds a reference to the last agent that kicked the ball */ boost::shared_ptr<oxygen::AgentAspect> mLastKickingAgent; /** holds a reference to the GameStateAspect */ boost::shared_ptr<GameStateAspect> mGameState; /** then time when the last agent collided with the ball */ TTime mLastAgentCollisionTime; /** then time when the last agent kicked the ball */ TTime mLastAgentKickTime; /** true if the ball on the soccer field, i.e. not on the border surrounding the soccer field */ bool mBallOnField; /** holds the last valid ball position */ salt::Vector3f mLastValidBallPos; /** indicates in which goal the ball is, TI_NONE otherwise */ TTeamIndex mGoalState; }; DECLARE_CLASS(BallStateAspect); #endif // BALLLSTATEASPECT_H --- NEW FILE: ballstateaspect_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: ballstateaspect_c.cpp,v 1.1.2.1 2007/03/07 10:39:21 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 "ballstateaspect.h" using namespace oxygen; void CLASS(BallStateAspect)::DefineClass() { DEFINE_BASECLASS(SoccerControlAspect); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:32
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/beameffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/beameffector Added Files: Tag: projectx beamaction.h beameffector.cpp beameffector.h beameffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: beameffector.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: beameffector.cpp,v 1.1.2.1 2007/03/07 10:39:22 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 "beamaction.h" #include "beameffector.h" #include <soccer/soccerbase/soccerbase.h> #include <soccer/agentstate/agentstate.h> #include <cmath> using namespace boost; using namespace oxygen; using namespace salt; using namespace std; BeamEffector::BeamEffector() : oxygen::Effector() { } BeamEffector::~BeamEffector() { } #ifdef __APPLE_CC__ bool isfinite( float f ) { return f == f && f != f * 0.5f; } #endif bool BeamEffector::Realize(boost::shared_ptr<ActionObject> action) { if ( (mBody.get() == 0) || (mGameState.get() == 0) || (mAgentState.get() == 0) ) { return false; } shared_ptr<BeamAction> beamAction = shared_dynamic_cast<BeamAction>(action); if (beamAction.get() == 0) { GetLog()->Error() << "ERROR: (BeamEffector) cannot realize an unknown ActionObject\n"; return false; } // the beam effector only has an effect in PM_BeforeKickOff if (mGameState->GetPlayMode() == PM_BeforeKickOff) { Vector3f pos = beamAction->GetPosition(); // reject nan or infinite numbers in the beam position if ( (! isfinite(pos[0])) || (! isfinite(pos[1])) || (! isfinite(pos[2])) ) { return false; } // an agent can only beam within it's own field half float minX = -mFieldLength/2 + mAgentRadius; pos[0] = std::max<float>(pos[0],minX); pos[0] = std::min<float>(pos[0],0.0f); float minY = -mFieldWidth/2 + mAgentRadius; float maxY = mFieldWidth/2 - mAgentRadius; pos[1] = std::max<float>(minY,pos[1]); pos[1] = std::min<float>(maxY,pos[1]); pos[2] = mAgentRadius; // swap x and y coordinates accordingly for the current // team; after the flip pos is global and not independent // on the team pos = SoccerBase::FlipView ( pos, mAgentState->GetTeamIndex() ); mBody->SetPosition(pos); mBody->SetVelocity(Vector3f(0,0,0)); mBody->SetAngularVelocity(Vector3f(0,0,0)); } return true; } shared_ptr<ActionObject> BeamEffector::GetActionObject(const Predicate& predicate) { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (BeamEffector) invalid predicate" << predicate.name << "\n"; return shared_ptr<ActionObject>(); } Vector3f pos; if (! predicate.GetValue(predicate.begin(), pos)) { GetLog()->Error() << "ERROR: (BeamEffector) Vector3f parameter expected\n"; return shared_ptr<ActionObject>(new ActionObject(GetPredicate())); } return shared_ptr<ActionObject>(new BeamAction(GetPredicate(),pos)); } void BeamEffector::OnLink() { SoccerBase::GetBody(*this,mBody); SoccerBase::GetGameState(*this, mGameState); SoccerBase::GetAgentState(*this,mAgentState); mFieldWidth = 64.0; SoccerBase::GetSoccerVar(*this,"FieldWidth",mFieldWidth); mFieldLength = 100.0; SoccerBase::GetSoccerVar(*this,"FieldLength",mFieldLength); mAgentRadius = 0.22; SoccerBase::GetSoccerVar(*this,"AgentRadius",mAgentRadius); } void BeamEffector::OnUnlink() { mBody.reset(); mGameState.reset(); mAgentState.reset(); } --- NEW FILE: beameffector_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: beameffector_c.cpp,v 1.1.2.1 2007/03/07 10:39:22 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 "beameffector.h" using namespace oxygen; void CLASS(BeamEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); } --- NEW FILE: beameffector.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: beameffector.h,v 1.1.2.1 2007/03/07 10:39:22 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 BEAMEFFECTOR_H #define BEAMEFFECTOR_H #include <oxygen/agentaspect/effector.h> #include <oxygen/physicsserver/body.h> #include <soccer/gamestateaspect/gamestateaspect.h> class BeamEffector : public oxygen::Effector { public: BeamEffector(); virtual ~BeamEffector(); /** 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 "beam"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); protected: /** setup the reference to the agents body node */ virtual void OnLink(); /** remove the reference to the agents body node */ virtual void OnUnlink(); protected: /** the reference to the parents body node */ boost::shared_ptr<oxygen::Body> mBody; /** the reference to the GameState */ boost::shared_ptr<GameStateAspect> mGameState; /** a reference to the agent state */ boost::shared_ptr<AgentState> mAgentState; /** the cached field length */ float mFieldLength; /** the cached field width */ float mFieldWidth; /** thec cached agent radius */ float mAgentRadius; }; DECLARE_CLASS(BeamEffector); #endif // BEAMEFFECTOR_H --- NEW FILE: beamaction.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: beamaction.h,v 1.1.2.1 2007/03/07 10:39:21 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 BEAMACTION_H #define BEAMACTION_H #include <oxygen/gamecontrolserver/actionobject.h> #include <salt/vector.h> class BeamAction : public oxygen::ActionObject { public: BeamAction(const std::string& predicate, salt::Vector3f pos) : ActionObject(predicate), mPos(pos) {} virtual ~BeamAction() {} /** returns the stored positin */ const salt::Vector3f& GetPosition() { return mPos; } protected: /** the position to beam the agent to */ salt::Vector3f mPos; }; #endif // BEAMACTION_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:27
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718 Added Files: Tag: projectx .cvsignore Makefile.am export.cpp soccertypes.h Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- .deps .libs Makefile Makefile.in *.la *.lo --- NEW FILE: export.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: export.cpp,v 1.1.2.1 2007/03/07 10:39:17 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 <zeitgeist/zeitgeist.h> #include "beameffector/beameffector.h" #include "catcheffector/catcheffector.h" #include "createeffector/createeffector.h" #include "driveeffector/driveeffector.h" #include "initeffector/initeffector.h" #include "kickeffector/kickeffector.h" #include "pantilteffector/pantilteffector.h" #include "sayeffector/sayeffector.h" #include "soccercontrolaspect/soccercontrolaspect.h" #include "gamestateaspect/gamestateaspect.h" #include "gamestateaspect/gamestateitem.h" #include "ballstateaspect/ballstateaspect.h" #include "soccerruleaspect/soccerruleaspect.h" #include "agentstate/agentstate.h" #include "sexpmonitor/sexpmonitor.h" #include "trainercommandparser/trainercommandparser.h" #include "fieldflag/fieldflag.h" #include "ball/ball.h" #include "visionperceptor/visionperceptor.h" #include "restrictedvisionperceptor/restrictedvisionperceptor.h" #include "gamestateperceptor/gamestateperceptor.h" #include "agentstateperceptor/agentstateperceptor.h" #include "hearperceptor/hearperceptor.h" ZEITGEIST_EXPORT_BEGIN() ZEITGEIST_EXPORT(SoccerControlAspect); ZEITGEIST_EXPORT(GameStateAspect); ZEITGEIST_EXPORT(GameStateItem); ZEITGEIST_EXPORT(BallStateAspect); ZEITGEIST_EXPORT(SoccerRuleAspect); ZEITGEIST_EXPORT(BeamEffector); ZEITGEIST_EXPORT(CatchEffector); ZEITGEIST_EXPORT(CreateEffector); ZEITGEIST_EXPORT(DriveEffector); ZEITGEIST_EXPORT(InitEffector); ZEITGEIST_EXPORT(KickEffector); ZEITGEIST_EXPORT(PanTiltEffector); ZEITGEIST_EXPORT(SayEffector); ZEITGEIST_EXPORT(ObjectState); ZEITGEIST_EXPORT(AgentState); ZEITGEIST_EXPORT(TrainerCommandParser); ZEITGEIST_EXPORT(SexpMonitor); ZEITGEIST_EXPORT(FieldFlag); ZEITGEIST_EXPORT(Ball); ZEITGEIST_EXPORT(AgentStatePerceptor); ZEITGEIST_EXPORT(GameStatePerceptor); ZEITGEIST_EXPORT(HearPerceptor); ZEITGEIST_EXPORT(RestrictedVisionPerceptor); ZEITGEIST_EXPORT(VisionPerceptor); ZEITGEIST_EXPORT_END() --- NEW FILE: soccertypes.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: soccertypes.h,v 1.1.2.1 2007/03/07 10:39:17 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 SOCCERTYPES_H #define SOCCERTYPES_H /** this file contains types common to all plugins in the soccer simulation */ #include <string> enum TPlayMode { // the order of the first 3 play modes should not be changed. PM_BeforeKickOff = 0, /*!< before_kick_off: before the match */ PM_KickOff_Left = 1, /*!< kick_off_left: kick off for the left team */ PM_KickOff_Right = 2, /*!< kick_off_right: kick off for the right team */ PM_PlayOn, /*!< play_on: regular game play */ PM_KickIn_Left, PM_KickIn_Right, PM_CORNER_KICK_LEFT, /*!< corner_kick_l: corner kick left team */ PM_CORNER_KICK_RIGHT, /*!< corner_kick_r: corner kick right team */ PM_GOAL_KICK_LEFT, /*!< goal_kick_l: goal kick for left team */ PM_GOAL_KICK_RIGHT, /*!< goal_kick_r: goal kick for right team*/ PM_OFFSIDE_LEFT, /*!< offside_l: offside for left team */ PM_OFFSIDE_RIGHT, /*!< offside_r: offside for right team */ PM_GameOver, PM_Goal_Left, PM_Goal_Right, PM_FREE_KICK_LEFT, /*!< free_kick_l: free kick for left team */ PM_FREE_KICK_RIGHT, /*!< free_kick_r: free kick for right team*/ PM_NONE /*!< no play mode, this must be the last entry */ }; /** mapping from TPlayMode to string constants */ #define STR_PM_BeforeKickOff "BeforeKickOff" #define STR_PM_KickOff_Left "KickOff_Left" #define STR_PM_KickOff_Right "KickOff_Right" #define STR_PM_PlayOn "PlayOn" #define STR_PM_KickIn_Left "KickIn_Left" #define STR_PM_KickIn_Right "KickIn_Right" #define STR_PM_CORNER_KICK_LEFT "corner_kick_left" #define STR_PM_CORNER_KICK_RIGHT "corner_kick_right" #define STR_PM_GOAL_KICK_LEFT "goal_kick_left" #define STR_PM_GOAL_KICK_RIGHT "goal_kick_right" #define STR_PM_OFFSIDE_LEFT "offside_left" #define STR_PM_OFFSIDE_RIGHT "offside_right" #define STR_PM_GameOver "GameOver" #define STR_PM_Goal_Left "Goal_Left" #define STR_PM_Goal_Right "Goal_Right" #define STR_PM_FREE_KICK_LEFT "free_kick_left" #define STR_PM_FREE_KICK_RIGHT "free_kick_right" #define STR_PM_Unknown "unknown" enum TTeamIndex { TI_NONE = 0, TI_LEFT = 1, TI_RIGHT = 2 }; typedef float TTime; enum TGameHalf { GH_NONE = 0, GH_FIRST = 1, GH_SECOND = 2 }; #endif // SOCCERTYPES_H --- NEW FILE: Makefile.am --- pkglib_LTLIBRARIES = soccer.la soccer_la_SOURCES = export.cpp \ agentstate/agentstate.cpp \ agentstate/agentstate_c.cpp \ agentstateperceptor/agentstateperceptor.cpp \ agentstateperceptor/agentstateperceptor_c.cpp \ ball/ball.cpp ball/ball_c.cpp \ ballstateaspect/ballstateaspect.cpp \ ballstateaspect/ballstateaspect_c.cpp \ beameffector/beameffector.cpp \ beameffector/beameffector_c.cpp \ catcheffector/catcheffector.cpp \ catcheffector/catcheffector_c.cpp \ createeffector/createeffector.cpp \ createeffector/createeffector_c.cpp \ driveeffector/driveeffector.cpp \ driveeffector/driveeffector_c.cpp \ fieldflag/fieldflag_c.cpp \ gamestateaspect/gamestateaspect.cpp \ gamestateaspect/gamestateaspect_c.cpp \ gamestateaspect/gamestateitem.cpp \ gamestateaspect/gamestateitem_c.cpp \ gamestateperceptor/gamestateperceptor.cpp \ gamestateperceptor/gamestateperceptor_c.cpp \ hearperceptor/hearperceptor.cpp \ hearperceptor/hearperceptor_c.cpp \ initeffector/initeffector.cpp \ initeffector/initeffector_c.cpp \ kickeffector/kickeffector.cpp \ kickeffector/kickeffector_c.cpp \ objectstate/objectstate.cpp \ objectstate/objectstate_c.cpp \ pantilteffector/pantilteffector.cpp \ pantilteffector/pantilteffector_c.cpp \ restrictedvisionperceptor/restrictedvisionperceptor.cpp \ restrictedvisionperceptor/restrictedvisionperceptor_c.cpp \ sayeffector/sayeffector.cpp \ sayeffector/sayeffector_c.cpp \ sexpmonitor/sexpmonitor.cpp \ sexpmonitor/sexpmonitor_c.cpp \ soccerbase/soccerbase.cpp \ soccercontrolaspect/soccercontrolaspect.cpp \ soccercontrolaspect/soccercontrolaspect_c.cpp \ soccerruleaspect/soccerruleaspect.cpp \ soccerruleaspect/soccerruleaspect_c.cpp \ trainercommandparser/trainercommandparser.cpp \ trainercommandparser/trainercommandparser_c.cpp \ visionperceptor/visionperceptor.cpp \ visionperceptor/visionperceptor_c.cpp nobase_libpkginclude_HEADERS = \ soccertypes.h \ agentstate/agentstate.h \ agentstateperceptor/agentstateperceptor.h \ ball/ball.h \ ballstateaspect/ballstateaspect.h \ beameffector/beamaction.h \ beameffector/beameffector.h \ catcheffector/catchaction.h \ catcheffector/catcheffector.h \ createeffector/createaction.h \ createeffector/createeffector.h \ driveeffector/driveaction.h \ driveeffector/driveeffector.h \ fieldflag/fieldflag.h \ gamestateaspect/gamestateaspect.h \ gamestateaspect/gamestateitem.h \ gamestateperceptor/gamestateperceptor.h \ hearperceptor/hearperceptor.h \ initeffector/initaction.h \ initeffector/initeffector.h \ kickeffector/kickaction.h \ kickeffector/kickeffector.h \ objectstate/objectstate.h \ pantilteffector/pantiltaction.h \ pantilteffector/pantilteffector.h \ restrictedvisionperceptor/restrictedvisionperceptor.h \ sayeffector/sayaction.h \ sayeffector/sayeffector.h \ sexpmonitor/sexpmonitor.h \ soccerbase/soccerbase.h \ soccercontrolaspect/soccercontrolaspect.h \ soccerruleaspect/soccerruleaspect.h \ trainercommandparser/trainercommandparser.h \ visionperceptor/visionperceptor.h ## define include directory local to the pkgincludedir libpkgincludedir = $(includedir)/@PACKAGE@/soccer # -module tells automake we're not building a library but a loadable module # so we don't need the "lib" prefix in the module name soccer_la_LDFLAGS = -module -version-info 1:0:0 AM_CPPFLAGS = -I${top_srcdir}/lib @RUBY_CPPFLAGS@ -I${top_srcdir}/plugin |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:24
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/ball In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/ball Added Files: Tag: projectx ball.cpp ball.h ball_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: ball_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: ball_c.cpp,v 1.1.2.1 2007/03/07 10:39:20 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 "ball.h" using namespace oxygen; void CLASS(Ball)::DefineClass() { DEFINE_BASECLASS(oxygen/Transform); } --- NEW FILE: ball.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: ball.cpp,v 1.1.2.1 2007/03/07 10:39:19 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 <oxygen/agentaspect/agentaspect.h> #include <oxygen/physicsserver/body.h> #include <soccer/ballstateaspect/ballstateaspect.h> #include "ball.h" using namespace boost; using namespace oxygen; Ball::Ball() : Transform(), mForceTTL(0) { } void Ball::SetAcceleration(int steps, const salt::Vector3f& force, const salt::Vector3f& torque, boost::shared_ptr<oxygen::AgentAspect> agent) { if (mForceTTL > 0 && mKickedLast == agent) return; mForceTTL = steps; mForce = force; mTorque = torque; mKickedLast = agent; if (mBody.get() == 0) { mBody = shared_dynamic_cast<Body>(GetChildOfClass("Body")); } } void Ball::PrePhysicsUpdateInternal(float deltaTime) { Transform::PrePhysicsUpdateInternal(deltaTime); if (mBody.get() == 0 || mForceTTL <= 0) return; // the BallStateAspect is created after the ball, so we cannot set // mBallStateAspect during OnLink if (mBallStateAspect.get() == 0) { mBallStateAspect = shared_dynamic_cast<BallStateAspect> (GetCore()->Get("/sys/server/gamecontrol/BallStateAspect")); if (mBallStateAspect.get() == 0) return; } mBody->AddForce(mForce); mBody->AddTorque(mTorque); mBallStateAspect->UpdateLastCollidingAgent(mKickedLast); --mForceTTL; } --- NEW FILE: ball.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: ball.h,v 1.1.2.1 2007/03/07 10:39:19 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 BALL_H #define BALL_H #include <oxygen/sceneserver/transform.h> #include <oxygen/physicsserver/body.h> #include <salt/vector.h> class BallStateAspect; namespace oxygen { class AgentAspect; } /** \class Ball represents the ball on the soccer field ;) */ class Ball : public oxygen::Transform { public: Ball(); virtual ~Ball() {}; /** Set the acceleration of the ball. * * This method can be used to accelerate the ball over a number * of simulation steps. The ball acceleration will be applied over the number * of steps using a constant force and torque. * * \param steps number of steps the acceleration should be applied. * \param force the maximum force to add to the ball * \param torque the maximum torque to add to the ball * \param agent the agent kicking the ball */ void SetAcceleration(int steps, const salt::Vector3f& force, const salt::Vector3f& torque, boost::shared_ptr<oxygen::AgentAspect> agent); /** This method is used to add forces and torques to the ball before each simulation * step, if necessary. */ virtual void PrePhysicsUpdateInternal(float deltaTime); private: int mForceTTL; salt::Vector3f mForce; salt::Vector3f mTorque; boost::shared_ptr<oxygen::Body> mBody; boost::shared_ptr<oxygen::AgentAspect> mKickedLast; boost::shared_ptr<BallStateAspect> mBallStateAspect; }; DECLARE_CLASS(Ball); #endif // BALL_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:23
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/agentstateperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/agentstateperceptor Added Files: Tag: projectx agentstateperceptor.cpp agentstateperceptor.h agentstateperceptor_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: agentstateperceptor_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) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: agentstateperceptor_c.cpp,v 1.1.2.1 2007/03/07 10:39:19 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 "agentstateperceptor.h" using namespace boost; using namespace oxygen; void CLASS(AgentStatePerceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/Perceptor); } --- NEW FILE: agentstateperceptor.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) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: agentstateperceptor.h,v 1.1.2.1 2007/03/07 10:39:19 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 AGENTSTATEPERCEPTOR_H #define AGENTSTATEPERCEPTOR_H #include <oxygen/agentaspect/perceptor.h> #include <soccer/soccertypes.h> class AgentState; namespace oxygen { class Predicate; } class AgentStatePerceptor : public oxygen::Perceptor { public: AgentStatePerceptor(); virtual ~AgentStatePerceptor(); //! \return true, if valid data is available and false otherwise. virtual bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); protected: /** sets up the reference to the AgentState */ virtual void OnLink(); /** resets the reference to the AgentState */ virtual void OnUnlink(); protected: //! a reference to the agentstate boost::shared_ptr<AgentState> mAgentState; //! the percept percept rate is the rate SenseIntervals divided by number of percepts int mPerceptRate; //! sense interval counter for subsequent percepts int mSenses; }; DECLARE_CLASS(AgentStatePerceptor); #endif // AGENTSTATEPERCEPTOR_H --- NEW FILE: agentstateperceptor.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: agentstateperceptor.cpp,v 1.1.2.1 2007/03/07 10:39:18 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 "agentstateperceptor.h" #include <soccer/agentstate/agentstate.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/restrictedvisionperceptor/restrictedvisionperceptor.h> using namespace oxygen; using namespace zeitgeist; using namespace boost; AgentStatePerceptor::AgentStatePerceptor() : oxygen::Perceptor() { mPerceptRate = 10; mSenses = 0; } AgentStatePerceptor::~AgentStatePerceptor() { } bool AgentStatePerceptor::Percept(boost::shared_ptr<PredicateList> predList) { if (mAgentState.get() == 0) { return false; } --mSenses; if (mSenses > 0) { return false; } mSenses = mPerceptRate; Predicate& predicate = predList->AddPredicate(); predicate.name = "AgentState"; predicate.parameter.Clear(); shared_ptr<BaseNode> parent = shared_dynamic_cast<BaseNode>(make_shared(GetParent())); if (parent.get() == 0) { GetLog()->Warning() << "WARNING: (AgentStatePerceptor) " << "parent node is not derived from BaseNode\n"; } else { shared_ptr<RestrictedVisionPerceptor> rvp = parent->FindChildSupportingClass<RestrictedVisionPerceptor>(false); if (rvp.get() == 0) { GetLog()->Warning() << "WARNING: (AgentStatePerceptor) " << "cannot find RestrictedVisionPerceptor instance\n"; } else { // pan tilt information ParameterList& pantiltElement = predicate.parameter.AddList(); pantiltElement.AddValue(std::string("pan_tilt")); pantiltElement.AddValue(static_cast<int>(roundf(rvp->GetPan()))); pantiltElement.AddValue(static_cast<int>(roundf(rvp->GetTilt()))); } } // battery ParameterList& batteryElement = predicate.parameter.AddList(); batteryElement.AddValue(std::string("battery")); batteryElement.AddValue(mAgentState->GetBattery()); // temperature ParameterList& tempElement = predicate.parameter.AddList(); tempElement.AddValue(std::string("temp")); tempElement.AddValue(mAgentState->GetTemperature()); return true; } void AgentStatePerceptor::OnLink() { SoccerBase::GetAgentState(*this,mAgentState); } void AgentStatePerceptor::OnUnlink() { mAgentState.reset(); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:22
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/agentstate In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/agentstate Added Files: Tag: projectx agentstate.cpp agentstate.h agentstate_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: agentstate.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: agentstate.h,v 1.1.2.1 2007/03/07 10:39:18 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 AGENTSTATE_H #define AGENTSTATE_H #include <soccer/objectstate/objectstate.h> #include <soccer/soccertypes.h> namespace oxygen { class Body; } class AgentState : public ObjectState { // // functions // public: AgentState(); virtual ~AgentState(); /** set the team index */ void SetTeamIndex(TTeamIndex idx); /** returns the team index */ TTeamIndex GetTeamIndex() const; /** Set the uniform number. * * This sets both the uniform number as well as the object id * (only the representation is different). */ void SetUniformNumber(int number); /** returns the uniform number as integer */ int GetUniformNumber() const; /** Set the object id for perceptors. * * This method is the same as SetUniformNumber for AgentState. * If id is not an integer, the object ID will not be changed. * * \param id a new ID, an integer represented as std::string. * \param pt the percept type for which the ID is set */ virtual void SetID(const std::string& id, TPerceptType pt = PT_Default); /** Get the battery state */ float GetBattery() const; /** Set the battery state */ void SetBattery(float battery); /** Get the motor temperature */ float GetTemperature() const; /** Set the temperature */ void SetTemperature(float temperature); /** reduce battery by the given amout. * \param consumption the amount by which the battery is reduced if possible * \return true if the battery if good enough for the given consumption */ bool ReduceBattery(double consumption); /** Add a new message to the list */ void AddMessage(const std::string& msg, float direction, bool teamMate); void AddSelfMessage(const std::string& msg); /** Get the first message from the list */ bool GetMessage(std::string& msg, float& direction, bool teamMate); bool GetSelfMessage(std::string& msg); protected: /** team index */ TTeamIndex mTeamIndex; /** uniform number */ int mUniformNumber; /** motor temperature */ float mTemperature; /** battery state */ double mBattery; /** self message */ std::string mSelfMsg; /** team-mate's message */ std::string mMateMsg; float mMateMsgDir; /** opponent's message */ std::string mOppMsg; float mOppMsgDir; /** max hear capacity units */ int mHearMax; /** hear capacity increase units when it's silent */ int mHearInc; /** hear capacity decrease units when player hears a message */ int mHearDecay; /** hear capacity for his team */ int mHearMateCap; /** hear capacity for opponent team */ int mHearOppCap; /** is there any message from myself */ bool mIfSelfMsg; /** is there any message from teammate */ bool mIfMateMsg; /** is there any message from oponnent */ bool mIfOppMsg; }; DECLARE_CLASS(AgentState); #endif // AGENTSTATE_H --- NEW FILE: agentstate.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: agentstate.cpp,v 1.1.2.1 2007/03/07 10:39:18 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 "agentstate.h" #include <soccer/soccerbase/soccerbase.h> #include <oxygen/physicsserver/body.h> #include <sstream> using namespace oxygen; using namespace std; AgentState::AgentState() : ObjectState(), mTeamIndex(TI_NONE), mTemperature(20.0), mBattery(100.0), mHearMax(2), mHearInc(1), mHearDecay(2), mHearMateCap(2), mHearOppCap(2), mIfSelfMsg(false), mIfMateMsg(false), mIfOppMsg(false) { // set mID and mUniformNumber into a joint state SetUniformNumber(0); } AgentState::~AgentState() { } void AgentState::SetTeamIndex(TTeamIndex idx) { mTeamIndex = idx; } TTeamIndex AgentState::GetTeamIndex() const { return mTeamIndex; } void AgentState::SetUniformNumber(int number) { mUniformNumber = number; std::ostringstream ss; ss << number; ObjectState::SetID(ss.str()); } int AgentState::GetUniformNumber() const { return mUniformNumber; } void AgentState::SetID(const std::string& id, TPerceptType pt) { std::istringstream iss(id); iss >> mUniformNumber; if (!iss) { // conversion failed. mUniformNumber is not changed. return; } ObjectState::SetID(id,pt); } float AgentState::GetBattery() const { return mBattery; } void AgentState::SetBattery(float battery) { mBattery = battery; } float AgentState::GetTemperature() const { return 23.0; } void AgentState::SetTemperature(float temperature) { mTemperature = temperature; } bool AgentState::ReduceBattery(double consumption) { if (mBattery - consumption >= 0.0) { mBattery -= consumption; return true; } return false; } void AgentState::AddMessage(const string& msg, float direction, bool teamMate) { if (teamMate) { if (mHearMateCap < mHearDecay) { return; } mHearMateCap -= mHearDecay; mMateMsg = msg; mMateMsgDir = direction; mIfMateMsg = true; } else { if (mHearOppCap < mHearDecay) { return; } mHearOppCap -= mHearDecay; mOppMsg = msg; mOppMsgDir = direction; mIfOppMsg = true; } } void AgentState::AddSelfMessage(const string& msg) { mSelfMsg = msg; mIfSelfMsg = true; } bool AgentState::GetMessage(string& msg, float& direction, bool teamMate) { if (teamMate) { if (mHearMateCap < mHearMax) { mHearMateCap += mHearInc; } if (! mIfMateMsg) { return false; } msg = mMateMsg; direction = mMateMsgDir; mIfMateMsg = false; return true; } else { if (mHearOppCap < mHearMax) { mHearOppCap += mHearInc; } if (! mIfOppMsg) { return false; } msg = mOppMsg; direction = mOppMsgDir; mIfOppMsg = false; return true; } } bool AgentState::GetSelfMessage(string& msg) { if (! mIfSelfMsg) { return false; } msg = mSelfMsg; mIfSelfMsg = false; return true; } --- NEW FILE: agentstate_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: agentstate_c.cpp,v 1.1.2.1 2007/03/07 10:39:18 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 "agentstate.h" using namespace boost; using namespace oxygen; void CLASS(AgentState)::DefineClass() { DEFINE_BASECLASS(ObjectState); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:22:12
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/sexpmonitor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv16892/sexpmonitor Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/sexpmonitor added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:24
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/trainercommandparser In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/trainercommandparser Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/trainercommandparser added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:24
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/sayeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/sayeffector Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/sayeffector added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:24
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/initeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/initeffector Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/initeffector added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:23
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/gamestateaspect Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateaspect added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:23
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/visionperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/visionperceptor Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/visionperceptor added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:22
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/soccercontrolaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/soccercontrolaspect Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/soccercontrolaspect added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:22
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/soccerruleaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/soccerruleaspect Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/soccerruleaspect added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:22
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/objectstate In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/objectstate Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/objectstate added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:22
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/gamestateperceptor Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateperceptor added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:21
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/driveeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/driveeffector Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/driveeffector added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:21
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/fieldflag In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/fieldflag Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/fieldflag added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:20
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/kickeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/kickeffector Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/kickeffector added to the repository --> Using per-directory sticky tag `projectx' |
From: Oliver O. <fr...@us...> - 2007-03-07 10:18:20
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/hearperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15875/hearperceptor Log Message: Directory /cvsroot/simspark/simspark/simulations/soccer/plugin/hearperceptor added to the repository --> Using per-directory sticky tag `projectx' |