bool SoccerBase::GetActiveScene(const Leaf& base, boost::shared_ptr<Scene>& active_scene) { static boost::shared_ptr<SceneServer> sceneServer; if (sceneServer.get() == 0) { if (! GetSceneServer(base,sceneServer)) { base.GetLog()->Error() << "(SoccerBase) ERROR: " << base.GetName() << ", could not get SceneServer\n"; return false; } } active_scene = sceneServer->GetActiveScene(); if (active_scene.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ", SceneServer reports no active scene\n"; return false; } return true; }
bool SoccerBase::GetGameControlServer(const Leaf& base, boost::shared_ptr<GameControlServer> & game_control_server) { static boost::shared_ptr<GameControlServer> gameControlServer; if (gameControlServer.get() == 0) { gameControlServer = shared_dynamic_cast<GameControlServer> (base.GetCore()->Get("/sys/server/gamecontrol")); if (gameControlServer.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << " found no GameControlServer\n"; return false; } } game_control_server = gameControlServer; return true; }
AABB2 SoccerBase::GetAgentBoundingRect(const Leaf& base) { AABB2 boundingRect; boost::shared_ptr<Space> parent = base.FindParentSupportingClass<Space>().lock(); if (!parent) { base.GetLog()->Error() << "(GetAgentBoundingBox) ERROR: can't get parent node.\n"; return boundingRect; } /* We can't simply use the GetWorldBoundingBox of the space node, becuase * (at least currently) it'll return a wrong answer. Currently, the space * object is always at (0,0,0) which is encapsulated in the result of it's * GetWorldBoundingBox method call. */ Leaf::TLeafList baseNodes; parent->ListChildrenSupportingClass<Collider>(baseNodes,true); if (baseNodes.empty()) { base.GetLog()->Error() << "(GetAgentBoundingBox) ERROR: space object doesn't have any" << " children of type BaseNode.\n"; } for (Leaf::TLeafList::iterator i = baseNodes.begin(); i!= baseNodes.end(); ++i) { boost::shared_ptr<BaseNode> node = shared_static_cast<BaseNode>(*i); const AABB3 &box = node->GetWorldBoundingBox(); boundingRect.Encapsulate(box.minVec.x(), box.minVec.y()); boundingRect.Encapsulate(box.maxVec.x(), box.maxVec.y()); } return boundingRect; }
bool SoccerBase::GetBallBody(const Leaf& base, boost::shared_ptr<RigidBody>& body) { static boost::shared_ptr<Scene> scene; static boost::shared_ptr<RigidBody> bodyRef; if (scene.get() == 0) { if (! GetActiveScene(base,scene)) { base.GetLog()->Error() << "(SoccerBase) ERROR: " << base.GetName() << ", could not get active scene.\n"; return false; } } if (bodyRef.get() == 0) { bodyRef = shared_dynamic_cast<RigidBody> (base.GetCore()->Get(scene->GetFullPath() + "Ball/physics")); if (bodyRef.get() == 0) { base.GetLog()->Error() << "(SoccerBase) ERROR: " << base.GetName() << ", found no ball body node\n"; return false; } } body = bodyRef; return true; }
bool SoccerBase::GetBall(const Leaf& base, boost::shared_ptr<Ball>& ball) { static boost::shared_ptr<Scene> scene; static boost::shared_ptr<Ball> ballRef; if (scene.get() == 0) { if (! GetActiveScene(base,scene)) { base.GetLog()->Error() << "(SoccerBase) ERROR: " << base.GetName() << ", could not get active scene.\n"; return false; } } if (ballRef.get() == 0) { ballRef = shared_dynamic_cast<Ball> (base.GetCore()->Get(scene->GetFullPath() + "Ball")); if (ballRef.get() == 0) { base.GetLog()->Error() << "(SoccerBase) ERROR: " << base.GetName() << ", found no ball node\n"; return false; } } ball = ballRef; return true; }
bool SoccerBase::GetBody(const Leaf& base, boost::shared_ptr<RigidBody>& body) { boost::shared_ptr<Transform> parent; if (! GetTransformParent(base,parent)) { base.GetLog()->Error() << "(SoccerBase) ERROR: no transform parent " << "found in GetBody()\n"; return false; } body = shared_dynamic_cast<RigidBody>(parent->FindChildSupportingClass<RigidBody>()); if (body.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ") parent node has no Body child."; return false; } return true; }
bool SoccerBase::GetTransformParent(const Leaf& base, boost::shared_ptr<Transform>& transform_parent) { transform_parent = shared_dynamic_cast<Transform> ((base.FindParentSupportingClass<Transform>()).lock()); if (transform_parent.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") parent node is not derived from TransformNode\n"; return false; } return true; }
bool SoccerBase::GetSceneServer(const Leaf& base, boost::shared_ptr<SceneServer>& scene_server) { scene_server = shared_static_cast<SceneServer> (base.GetCore()->Get("/sys/server/scene")); if (scene_server.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") scene server not found.\n"; return false; } return true; }
bool SoccerBase::GetGameState(const Leaf& base, boost::shared_ptr<GameStateAspect>& game_state) { game_state = shared_dynamic_cast<GameStateAspect> (base.GetCore()->Get("/sys/server/gamecontrol/GameStateAspect")); if (game_state.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") found no GameStateAspect\n"; return false; } return true; }
bool SoccerBase::GetSoccerRuleAspect(const Leaf& base, boost::shared_ptr<SoccerRuleAspect> & soccer_rule_aspect) { soccer_rule_aspect = shared_dynamic_cast<SoccerRuleAspect> (base.GetCore()->Get("/sys/server/gamecontrol/SoccerRuleAspect")); if (soccer_rule_aspect.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << " found no SoccerRuleAspect\n"; return false; } return true; }
bool SoccerBase::GetAgentState(const Leaf& base, TTeamIndex idx, int unum, boost::shared_ptr<AgentState>& agentState) { static TAgentStateMap mAgentStateMapLeft; static TAgentStateMap mAgentStateMapRight; if (idx == TI_NONE) return false; // do we have a cached reference? if ( idx == TI_LEFT && !mAgentStateMapLeft.empty() ) { TAgentStateMap::iterator iter = mAgentStateMapLeft.find(unum); if (iter != mAgentStateMapLeft.end()) { // is the pointer to the parent (AgentAspect) still valid // (maybe the agent disconnected)? if (!(iter->second)->GetParent().lock().get()) { base.GetLog()->Error() << "(SoccerBase) WARNING: " << "AgentState has invalid parent! " << "The agent probably disconnected, removing from map." << "\n"; mAgentStateMapLeft.erase(iter); } else { agentState = (*iter).second; return true; } } } else if ( idx == TI_RIGHT && !mAgentStateMapRight.empty() ) { TAgentStateMap::iterator iter = mAgentStateMapRight.find(unum); if (iter != mAgentStateMapRight.end()) { // is the pointer to the parent (AgentAspect) still valid // (maybe the agent disconnected)? if ((iter->second)->GetParent().lock().get() == 0) { base.GetLog()->Error() << "(SoccerBase) WARNING: " << "AgentState has invalid parent! " << "The agent probably disconnected, removing from map." << "\n"; mAgentStateMapRight.erase(iter); } else { agentState = (*iter).second; return true; } } } // we have to get all agent states for this team TAgentStateList agentStates; GetAgentStates(base, agentStates, idx); for (TAgentStateList::iterator iter = agentStates.begin(); iter != agentStates.end(); ++iter) { if ((*iter)->GetUniformNumber() == unum) { agentState = *iter; if (idx == TI_LEFT) { mAgentStateMapLeft[unum] = agentState; } else { mAgentStateMapRight[unum] = agentState; } return true; } } return false; }