void TrainerCommandParser::ParseKillCommand(const oxygen::Predicate & predicate)
{
    Predicate::Iterator unumParam(predicate);
    int                 unum;
    bool specified = true;

    boost::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;

    GameControlServer::TAgentAspectList agentAspects;
    mGameControl->GetAgentAspectList(agentAspects);
    GameControlServer::TAgentAspectList::iterator aaiter;
    for (
          aaiter = agentAspects.begin();
          aaiter != agentAspects.end();
          ++aaiter
        )
    {
        // search for the first agent of the left/right side
        boost::shared_ptr<AgentState> agentState =
            shared_dynamic_cast<AgentState>((*aaiter)->GetChild("AgentState", true));

        if ((specified && agentState->GetUniformNumber() == unum && agentState->GetTeamIndex() == idx) ||
            (!specified && agentState->IsSelected()))
        {
            mGameControl->pushDisappearedAgent((*aaiter)->ID());
            break;
        }
    }
}
Esempio n. 2
0
bool
SoccerBase::GetAgentStates(const zeitgeist::Leaf& base,
                           TAgentStateList& agentStates,
                           TTeamIndex idx)
{
    static boost::shared_ptr<GameControlServer> gameCtrl;

    if (gameCtrl.get() == 0)
    {
        GetGameControlServer(base, gameCtrl);

        if (gameCtrl.get() == 0)
        {
            base.GetLog()->Error() << "(SoccerBase) ERROR: can't get "
                                   << "GameControlServer\n";
            return false;
        }
    }

    GameControlServer::TAgentAspectList aspectList;
    gameCtrl->GetAgentAspectList(aspectList);

    GameControlServer::TAgentAspectList::iterator iter;
    boost::shared_ptr<AgentState> agentState;

    for (
         iter = aspectList.begin();
         iter != aspectList.end();
         ++iter
         )
        {
            agentState = shared_dynamic_cast<AgentState>((*iter)->GetChild("AgentState", true));

            if (
                agentState.get() != 0 &&
                (
                 agentState->GetTeamIndex() == idx ||
                 idx == TI_NONE
                 )
                )
                {
                    agentStates.push_back(agentState);
                }
        }

    return true;
}