Level* WorldBuilder::GetLevelById(int id) { for(int i = 0; i < (int)this->m_levels.size(); i++) { Level* level = this->m_levels.at(i); if(level != NULL && (level->GetId() == id)) { return level; } } return NULL; }
bool PoolCue::Intersects() { Level* pLevel = LevelServer::Instance()->GetCurrentLevel().GetPtr(); // Get end points of cue m_v1 = GetBall()->GetOrientation()->GetVertex(); // Offset this end of the cue to the cue contact pos. // TODO float yr = Engine::Instance()->GetGameState()->GetCurrentPlayerInfo()->m_golfStroke.m_yRot; m_v2 = m_v1; // Get endpoint of cue - use elev and yr. // NB Length is not critical float len = 20.0f; // Get (x, z); m_v2.x -= len * sin(DegToRad(yr)); m_v2.z -= len * cos(DegToRad(yr)); float elev = Engine::Instance()->GetGameState()->GetCurrentPlayerInfo()->m_golfStroke.m_cueElevationDegs; m_v2.y += len * sin(DegToRad(elev)); // Radius of pool cue capsule float radius = 0.2f; // A rough radius of the cue section bool intersectsScene = pLevel->GetScene()->LineIntersects(m_v1, m_v2, radius); if (intersectsScene) { return true; } // Test ball intersection - ignore cue ball int levelId = pLevel->GetId(); int roomId = pLevel->GetRoomId(); GameObjectMap& objs = Engine::Instance()->GetGameObjects(levelId, roomId); // Iterate through map of Game Objects. for (GameObjectMap::iterator it = objs.begin(); it != objs.end(); ++it) { PPoolGameObject pGo = it->second; PoolBall* pBall = dynamic_cast<PoolBall*>(pGo.GetPtr()); if (pBall && !IsCueBall(pBall)) { // Test ball-capsule intersection if (pBall->GetBoundingSphere()->Intersects(m_v1, m_v2, radius)) { #ifdef CUE_DEBUG std::cout << "CUE INTERSECTS BALL: " << pBall->GetId() << "\n"; #endif return true; } } } return false; }
void PoolSnapshot::SetStateToSnapshot() const { // Set the state of all game objects we have stored. for (unsigned int i = 0; i < m_objInfo.size(); i++) { const ObjInfo& info = m_objInfo[i]; #ifdef UNDO_DEBUG if (info.m_pGo->GetId() == 10) { std::cout << "** UNDO: Restoring cue ball: pos is: " << ToString(info.m_or) << "\n"; } else // NB NOT #else { std::cout << "** UNDO: Restoring obj: " << info.m_pGo->GetId() << " (" << info.m_pGo->GetTypeName() << ") or: " << ToString(info.m_or) << "\n"; } #endif info.m_pGo->SetOrientation(info.m_or); info.m_pGo->SetState(info.m_state); } for (unsigned int i = 0; i < m_playerInfo.size(); i++) { Engine::Instance()->GetGameState()->SetPlayerInfo(i, m_playerInfo[i]); } // Set Rules state Level* pLevel = LevelServer::Instance()->GetCurrentLevel().GetPtr(); //Rules* pRules = GetRules(pLevel); //int id = pRules->GetId(); // This was an attempt to assign the object into the one held by the Engine. // This won't work - it just assigns to the local variable! //*pRules = *(m_pRules.GetPtr()); // Replace the Rules object held by the Engine with this new object. Engine::Instance()->HoldGameObject(pLevel->GetId(), pLevel->GetRoomId(), m_pRules.GetPtr()); }
void PoolSnapshot::CreateFromCurrentState() { // Get the state of all game objects in the current room. Level* pLevel = LevelServer::Instance()->GetCurrentLevel().GetPtr(); int levelId = pLevel->GetId(); int roomId = pLevel->GetRoomId(); GameObjectMap& objs = Engine::Instance()->GetGameObjects(levelId, roomId); // Iterate through map of Game Objects. for (GameObjectMap::iterator it = objs.begin(); it != objs.end(); ++it) { PPoolGameObject pGo = it->second; Assert(pGo.GetPtr()); #ifdef UNDO_DEBUG if (gameObjId == 10) std::cout << "** UNDO: Storing cue ball: pos is " << ToString(*(pGo->GetOrientation())) << "\n"; #endif ObjInfo info; info.m_pGo = pGo; if (pGo->GetOrientation()) { info.m_or = *(pGo->GetOrientation()); } info.m_state = pGo->GetState(); m_objInfo.push_back(info); } // No of ball spotted by each player int numPlayers = Engine::Instance()->GetGameState()->GetNumberOfPlayers(); for (int i = 0; i < numPlayers; i++) { m_playerInfo.push_back( *(Engine::Instance()->GetGameState()->GetPlayerInfo(i))); } // Store the state of the Rules - like is this a free ball, can the // ball be placed anywhere, etc. m_pRules = GetRules(pLevel)->Clone(); }