?? handlemessage.cc
字號:
#include "gamemodel.hh"using namespace bats;using namespace std;void GameModel::handleMessage(rPredicate const &pred){ // std::cerr << "handleMessage(" << *pred << "). Empty: " << (pred->isEmpty() ? "yes" : "no") << std::endl; for (Predicate::iterator p = pred->begin(); p != pred->end(); ++p) { //std::cerr << "- " << (*p)->getStr() << std::endl; if ((*p)->getStr() == "Init") { std::cerr << "handleMessage(" << *pred << "). Empty: " << (pred->isEmpty() ? "yes" : "no") << std::endl; static Path pathFieldLength("/FieldLength/"); rPredicate predFieldLength = (*p)->select(pathFieldLength); if (predFieldLength) setVar(FieldLength,*predFieldLength); static Path pathFieldWidth("/FieldWidth/"); rPredicate predFieldWidth = (*p)->select(pathFieldWidth); if (predFieldWidth) setVar(FieldWidth,*predFieldWidth); static Path pathFieldHeight("/FieldHeight/"); rPredicate predFieldHeight = (*p)->select(pathFieldHeight); if (predFieldHeight) setVar(FieldHeight,*predFieldHeight); static Path pathGoalWidth("/GoalWidth/"); rPredicate predGoalWidth = (*p)->select(pathGoalWidth); if (predGoalWidth) setVar(GoalWidth,*predGoalWidth); static Path pathGoalDepth("/GoalDepth/"); rPredicate predGoalDepth = (*p)->select(pathGoalDepth); if (predGoalDepth) setVar(GoalDepth,*predGoalDepth); static Path pathGoalHeight("/GoalHeight/"); rPredicate predGoalHeight = (*p)->select(pathGoalHeight); if (predGoalHeight) setVar(GoalHeight,*predGoalHeight); static Path pathBorderSize("/BorderSize/"); rPredicate predBorderSize = (*p)->select(pathBorderSize); if (predBorderSize) setVar(BorderSize,*predBorderSize); static Path pathFreeKickDistance("/FreeKickDistance/"); rPredicate predFreeKickDistance = (*p)->select(pathFreeKickDistance); if (predFreeKickDistance) setVar(FreeKickDistance,*predFreeKickDistance); static Path pathWaitBeforeKickOff("/WaitBeforeKickOff/"); rPredicate predWaitBeforeKickOff = (*p)->select(pathWaitBeforeKickOff); if (predWaitBeforeKickOff) setVar(WaitBeforeKickOff,*predWaitBeforeKickOff); static Path pathAgentMass("/AgentMass/"); rPredicate predAgentMass = (*p)->select(pathAgentMass); if (predAgentMass) setVar(AgentMass,*predAgentMass); static Path pathAgentRadius("/AgentRadius/"); rPredicate predAgentRadius = (*p)->select(pathAgentRadius); if (predAgentRadius) setVar(AgentRadius,*predAgentRadius); static Path pathAgentMaxSpeed("/AgentMaxSpeed/"); rPredicate predAgentMaxSpeed = (*p)->select(pathAgentMaxSpeed); if (predAgentMaxSpeed) setVar(AgentMaxSpeed,*predAgentMaxSpeed); static Path pathBallRadius("/BallRadius/"); rPredicate predBallRadius = (*p)->select(pathBallRadius); if (predBallRadius) setVar(BallRadius,*predBallRadius); static Path pathBallMass("/BallMass/"); rPredicate predBallMass = (*p)->select(pathBallMass); if (predBallMass) setVar(BallMass,*predBallMass); static Path pathRuleGoalPauseTime("/RuleGoalPauseTime/"); rPredicate predRuleGoalPauseTime = (*p)->select(pathRuleGoalPauseTime); if (predRuleGoalPauseTime) setVar(RuleGoalPauseTime,*predRuleGoalPauseTime); static Path pathRuleKickInPauseTime("/RuleKickInPauseTime/"); rPredicate predRuleKickInPauseTime = (*p)->select(pathRuleKickInPauseTime); if (predRuleKickInPauseTime) setVar(RuleKickInPauseTime,*predRuleKickInPauseTime); static Path pathRuleHalfTime("/RuleHalfTime/"); rPredicate predRuleHalfTime = (*p)->select(pathRuleHalfTime); if (predRuleHalfTime) setVar(RuleHalfTime,*predRuleHalfTime); static Path pathPlayModes("/play_modes"); rPredicate predPlayModes = (*p)->select(pathPlayModes); cerr << "Play modes?...?" << endl; if (predPlayModes) { d_playModes.clear(); // just in case, first clear the playModes list. for (Predicate::iterator i = predPlayModes->begin(); i != predPlayModes->end(); ++i) d_playModes.push_back(**i); } } else if ((*p)->getStr() == "Info") { vector <rPredicate> players; vector <rPredicate> flags; vector <rPredicate> goalPosts; static Path timePath("time/"); static Path playerPath("P"); static Path flagPath("F"); static Path goalPath("G"); static Path ballPath("B"); static Path sidePath("s/"); static Path idPath("id/"); static Path posPath("pos/"); static Path sayPath("say/"); static Path teamLeftPath("team_left/"); static Path teamRightPath("team_right/"); static Path playModePath("play_mode/"); rPredicate teamLeft = pred->select(teamLeftPath); if (teamLeft) setVar(TeamLeft, teamLeft->getStr()); rPredicate teamRight = pred->select(teamRightPath); if (teamRight) setVar(TeamRight, teamRight->getStr()); vector<rPredicate> pos; Vector3D coords; // Time rPredicate time = pred->select(timePath); if (time) setVar(Time, time->getStr()); rPredicate playMode = pred->select(playModePath); if (playMode) setVar(PlayMode, playMode->getStr()); // Ball rPredicate ball = pred->select(ballPath); pos.clear(); ball->selectAll(pos, posPath); coords[0] = pos[0]->getDouble(); coords[1] = pos[1]->getDouble(); coords[2] = pos[2]->getDouble(); setVar(Ball, coords); // Players pred->selectAll(players, playerPath); for (unsigned i = 0; i < players.size(); ++i) { int side = *players[i]->select(sidePath); // Side 0 = uninitialized player if (side != 0) { int id = *players[i]->select(idPath); pos.clear(); players[i]->selectAll(pos, posPath); coords[0] = pos[0]->getDouble(); coords[1] = pos[1]->getDouble(); coords[2] = pos[2]->getDouble(); getPlayerInfo(side - 1, id - 1).pos = coords; rPredicate sayPred = players[i]->select(sayPath); if (sayPred) getPlayerInfo(side - 1, id - 1).say = string(*sayPred); else getPlayerInfo(side - 1, id - 1).say = ""; } } // Flags pred->selectAll(flags, flagPath); for (unsigned i = 0; i < flags.size(); ++i) { string id = *flags[i]->select(idPath); pos.clear(); flags[i]->selectAll(pos, posPath); coords[0] = pos[0]->getDouble(); coords[1] = pos[1]->getDouble(); coords[2] = pos[2]->getDouble(); GameVar flagId; if (id == "1_l") flagId = Flag1L; if (id == "1_r") flagId = Flag1R; if (id == "2_l") flagId = Flag2L; if (id == "2_r") flagId = Flag2R; setVar(flagId, coords); } // GoalPosts pred->selectAll(goalPosts, goalPath); //cout << "Nr of Goal Posts: " << goalPosts.size() << endl; for (unsigned i = 0; i < goalPosts.size(); ++i) { string id = *goalPosts[i]->select(idPath); pos.clear(); goalPosts[i]->selectAll(pos, posPath); coords[0] = pos[0]->getDouble(); coords[1] = pos[1]->getDouble(); coords[2] = pos[2]->getDouble(); GameVar goalId; if (id == "1_l") goalId = Goal1L; if (id == "1_r") goalId = Goal1R; if (id == "2_l") goalId = Goal2L; if (id == "2_r") goalId = Goal2R; setVar(goalId, coords); } // Test: updateAgentCommands(); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -