From: <sgv...@us...> - 2010-06-01 11:03:43
|
Revision: 206 http://simspark.svn.sourceforge.net/simspark/?rev=206&view=rev Author: sgvandijk Date: 2010-06-01 11:03:37 +0000 (Tue, 01 Jun 2010) Log Message: ----------- - Monitor command to position agent out of field Modified Paths: -------------- branches/agentselection/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.cpp branches/agentselection/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.h branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerinput.cpp branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerinput.h branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerrender.cpp branches/agentselection/rcssserver3d/rcssmonitor3d/soccerbindings.rb Modified: branches/agentselection/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.cpp =================================================================== --- branches/agentselection/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.cpp 2010-06-01 10:07:38 UTC (rev 205) +++ branches/agentselection/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.cpp 2010-06-01 11:03:37 UTC (rev 206) @@ -34,6 +34,7 @@ using namespace std; using namespace boost; +using namespace salt; using namespace zeitgeist; using namespace oxygen; @@ -48,6 +49,7 @@ mCommandMap["getAck"] = CT_ACK; mCommandMap["select"] = CT_SELECT; mCommandMap["kill"] = CT_KILL; + mCommandMap["repos"] = CT_REPOS; // setup team index map // Originally team sides were "L","R" and "N" @@ -157,6 +159,8 @@ bool TrainerCommandParser::ParsePredicate(const oxygen::Predicate & predicate) { + cerr << "repos 1" << endl; + SoccerBase::GetGameState(*this,mGameState); SoccerBase::GetSoccerRuleAspect(*this,mSoccerRule); @@ -207,6 +211,9 @@ case CT_KILL: ParseKillCommand(predicate); break; + case CT_REPOS: + ParseReposCommand(predicate); + break; default: return false; } @@ -630,4 +637,67 @@ } } +void TrainerCommandParser::ParseReposCommand(const oxygen::Predicate & predicate) +{ + cerr << "repos 2" << endl; + + Predicate::Iterator unumParam(predicate); + int unum; + bool specified = true; + shared_ptr<SoccerRuleAspect> soccerRuleAspect; + if (!SoccerBase::GetSoccerRuleAspect(*this, soccerRuleAspect)) + { + GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get soccer rule aspect\n"; + return; + } + + // extract unum + if (predicate.FindParameter(unumParam, "unum")) + { + if (! predicate.GetValue(unumParam, unum)) + specified = false; + } + else + specified = false; + + string team; + TTeamIndex idx; + Predicate::Iterator teamParam(predicate); + + // extract side + if (predicate.FindParameter(teamParam, "team")) + { + if (! predicate.GetValue(teamParam, team)) + specified = false; + else + idx = mTeamIndexMap[team]; + } + else + specified = false; + + SoccerBase::TAgentStateList agentStates; + SoccerBase::GetAgentStates(*this, agentStates, TI_NONE); + SoccerBase::TAgentStateList::iterator iter = agentStates.begin(); + boost::shared_ptr<oxygen::Transform> agent_aspect; + for (;iter != agentStates.end(); ++iter) + { + if ((specified && (*iter)->GetUniformNumber() == unum && (*iter)->GetTeamIndex() == idx) || + (!specified && (*iter)->IsSelected())) + { + Vector3f ballPos(0,0,0); + boost::shared_ptr<RigidBody> ballBody; + + if (SoccerBase::GetBallBody(*this, ballBody)) + ballPos = ballBody->GetPosition(); + + SoccerBase::GetTransformParent(**iter, agent_aspect); + cerr << "repos 3" << endl; + Vector3f new_pos = mSoccerRule->RepositionOutsidePos(ballPos, (*iter)->GetUniformNumber(), (*iter)->GetTeamIndex()); + SoccerBase::MoveAgent(agent_aspect, new_pos); + + break; + } + } +} + Modified: branches/agentselection/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.h =================================================================== --- branches/agentselection/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.h 2010-06-01 10:07:38 UTC (rev 205) +++ branches/agentselection/rcssserver3d/plugin/soccer/trainercommandparser/trainercommandparser.h 2010-06-01 11:03:37 UTC (rev 206) @@ -51,7 +51,8 @@ CT_KICK_OFF, CT_ACK, CT_SELECT, - CT_KILL + CT_KILL, + CT_REPOS }; typedef std::map<std::string, ECommandType> TCommandMap; @@ -117,6 +118,11 @@ predicate */ void ParseKillCommand(const oxygen::Predicate & predicate); + + /** parses and executes the reposition command contained in the given + predicate + */ + void ParseReposCommand(const oxygen::Predicate & predicate); protected: TCommandMap mCommandMap; Modified: branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerinput.cpp =================================================================== --- branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerinput.cpp 2010-06-01 10:07:38 UTC (rev 205) +++ branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerinput.cpp 2010-06-01 11:03:37 UTC (rev 206) @@ -74,6 +74,7 @@ scriptServer->CreateVariable("Command.SelectNextAgent", CmdSelectNextAgent); scriptServer->CreateVariable("Command.ResetSelection", CmdResetSelection); scriptServer->CreateVariable("Command.KillSelection", CmdKillSelection); + scriptServer->CreateVariable("Command.ReposSelection", CmdReposSelection); mMonitorClient = shared_dynamic_cast<NetClient> (GetCore()->Get("/sys/server/simulation/SparkMonitorClient")); @@ -157,6 +158,13 @@ } break; + case CmdReposSelection: + if (input.GetKeyPress()) + { + SendCommand("(repos)"); + } + break; + case CmdKickOff: if (input.GetKeyPress()) { Modified: branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerinput.h =================================================================== --- branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerinput.h 2010-06-01 10:07:38 UTC (rev 205) +++ branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerinput.h 2010-06-01 11:03:37 UTC (rev 206) @@ -68,7 +68,8 @@ CmdPlayerSelectMode = CmdRight + 1, CmdSelectNextAgent = CmdPlayerSelectMode + 1, CmdResetSelection = CmdSelectNextAgent + 1, - CmdKillSelection = CmdResetSelection + 1 + CmdKillSelection = CmdResetSelection + 1, + CmdReposSelection = CmdKillSelection + 1 }; enum ECmdMode Modified: branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerrender.cpp =================================================================== --- branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerrender.cpp 2010-06-01 10:07:38 UTC (rev 205) +++ branches/agentselection/rcssserver3d/plugin/soccermonitor/soccerrender.cpp 2010-06-01 11:03:37 UTC (rev 206) @@ -149,8 +149,8 @@ xPos = int((1024-(mFont->GetStringWidth(ss_c.str().c_str())))/2); mFont->DrawString(xPos, 0, ss_c.str().c_str()); - ss_m << mInput->GetCmdMode(); - mFont->DrawString(10, 30, ss_m.str().c_str()); + //ss_m << mInput->GetCmdMode(); + //mFont->DrawString(10, 30, ss_m.str().c_str()); mFontServer->End(); } Modified: branches/agentselection/rcssserver3d/rcssmonitor3d/soccerbindings.rb =================================================================== --- branches/agentselection/rcssserver3d/rcssmonitor3d/soccerbindings.rb 2010-06-01 10:07:38 UTC (rev 205) +++ branches/agentselection/rcssserver3d/rcssmonitor3d/soccerbindings.rb 2010-06-01 11:03:37 UTC (rev 206) @@ -55,5 +55,6 @@ inputServer.bindCommand('n', Command.SelectNextAgent); inputServer.bindCommand('e', Command.ResetSelection); inputServer.bindCommand('x', Command.KillSelection); + inputServer.bindCommand('p', Command.ReposSelection); end end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |