Changeset 9263
- Timestamp:
- Jun 3, 2012, 12:04:35 AM (12 years ago)
- Location:
- code/trunk/src/modules/gametypes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/gametypes/RaceCheckPoint.cc
r9260 r9263 58 58 59 59 this->checkpointIndex_ = 0; 60 this->nextcheckpoints_ = Vector3::ZERO;61 60 this->bIsLast_ = false; 62 61 this->timeLimit_ = 0; … … 76 75 XMLPortParam(RaceCheckPoint, "islast", setLast, isLast, xmlelement, mode).defaultValues(false); 77 76 XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); 78 XMLPortParam Template(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode, const Vector3&).defaultValues(Vector3::ZERO);77 XMLPortParam(RaceCheckPoint, "nextcheckpoints", setNextCheckpointsAsVector3, getNextCheckpointsAsVector3, xmlelement, mode); 79 78 } 80 79 … … 102 101 } 103 102 } 103 104 void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints) 105 { 106 this->nextCheckpoints_.clear(); 107 108 if (checkpoints.x > -1) 109 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); 110 if (checkpoints.y > -1) 111 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5)); 112 if (checkpoints.z > -1) 113 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5)); 114 } 115 116 Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const 117 { 118 Vector3 checkpoints = Vector3(-1, -1, -1); 119 120 size_t count = 0; 121 for (std::set<int>::iterator it = this->nextCheckpoints_.begin(); it != this->nextCheckpoints_.end(); ++it) 122 { 123 switch (count) 124 { 125 case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break; 126 case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break; 127 case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break; 128 } 129 ++count; 130 } 131 132 return checkpoints; 133 } 104 134 } -
code/trunk/src/modules/gametypes/RaceCheckPoint.h
r9262 r9263 54 54 { return this->checkpointIndex_; } 55 55 56 inline void setNextcheckpoint(const Vector3& checkpoints)57 { this->nextcheckpoints_ = checkpoints; }58 inline const Vector3& getNextcheckpoint() const59 { return this->next checkpoints_; }56 void setNextCheckpointsAsVector3(const Vector3& checkpoints); 57 Vector3 getNextCheckpointsAsVector3() const; 58 const std::set<int>& getNextCheckpoints() const 59 { return this->nextCheckpoints_; } 60 60 61 61 inline void setLast(bool isLast) … … 80 80 81 81 private: 82 int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 083 Vector3 nextcheckpoints_; ///< the indexes of the next check points84 bool bIsLast_; ///< True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level.85 float timeLimit_; ///< The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses.86 PlayerInfo* player_; ///< The player that reached the checkpoint82 int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0 83 std::set<int> nextCheckpoints_; ///< the indexes of the next check points 84 bool bIsLast_; ///< True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level. 85 float timeLimit_; ///< The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses. 86 PlayerInfo* player_; ///< The player that reached the checkpoint 87 87 }; 88 88 } -
code/trunk/src/modules/gametypes/SpaceRace.cc
r9262 r9263 104 104 void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player) 105 105 { 106 int index = checkpoint->getCheckpointIndex(); 107 this->checkpointReached_[player] = index; 106 this->checkpointReached_[player] = checkpoint; 108 107 109 108 this->clock_.capture(); … … 111 110 int ms = this->clock_.getMilliseconds() % 1000; 112 111 113 const std::string& message = "Checkpoint " + multi_cast<std::string>( index+ 1)112 const std::string& message = "Checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) 114 113 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds."; 115 114 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 116 115 ChatManager::message(message); 117 }118 119 void SpaceRace::playerEntered(PlayerInfo* player)120 {121 Gametype::playerEntered(player);122 123 this->checkpointReached_[player] = -1;124 116 } 125 117 -
code/trunk/src/modules/gametypes/SpaceRace.h
r9262 r9263 62 62 63 63 void newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player); 64 inline intgetCheckpointReached(PlayerInfo* player)64 inline RaceCheckPoint* getCheckpointReached(PlayerInfo* player) 65 65 { return this->checkpointReached_[player]; } 66 66 … … 74 74 bool allowPawnDeath(Pawn* victim, Pawn* originator); 75 75 76 protected:77 virtual void playerEntered(PlayerInfo* player); ///< Initializes values.78 79 76 private: 80 bool cantMove_; ///< Helper variable, used to stall the engines before the race starts.81 std::map<PlayerInfo*, int> checkpointReached_; ///< The number of the last check point reached by each player.82 bool bTimeIsUp_; ///< True if one of the check points is reached too late.77 bool cantMove_; ///< Helper variable, used to stall the engines before the race starts. 78 std::map<PlayerInfo*, RaceCheckPoint*> checkpointReached_; ///< The number of the last check point reached by each player. 79 bool bTimeIsUp_; ///< True if one of the check points is reached too late. 83 80 84 81 Clock clock_; ///< The clock starts running at the beginning of the game. It is used to give the time at each check point, the give the time at the end of the game, and to stop the game if a check point is reached too late. -
code/trunk/src/modules/gametypes/SpaceRaceManager.cc
r9262 r9263 105 105 } 106 106 107 void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player) 107 bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const 108 { 109 if (oldCheckpoint) 110 { 111 // the player already visited an old checkpoint; see which checkpoints are possible now 112 const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints(); 113 for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it) 114 if (this->findCheckpoint(*it) == newCheckpoint) 115 return true; 116 return false; 117 } 118 else 119 { 120 // the player hasn't visited a checkpoint yet, so he must reach the checkpoint with index 0 (hack?) 121 return (newCheckpoint->getCheckpointIndex() == 0); 122 } 123 } 124 125 void SpaceRaceManager::checkpointReached(RaceCheckPoint* newCheckpoint, PlayerInfo* player) 108 126 { 109 127 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 110 128 assert(gametype); 129 if (!gametype) 130 return; 111 131 112 bool reachedValidCheckpoint = false;132 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); 113 133 114 int index = gametype->getCheckpointReached(player); 115 if (index > -1) 134 if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player)) 116 135 { 117 Vector3 v = this->findCheckpoint(index)->getNextcheckpoint(); 118 119 if (this->findCheckpoint(v.x) == check) 120 { 121 reachedValidCheckpoint = true; 122 } 123 if (this->findCheckpoint(v.y) == check) 124 { 125 reachedValidCheckpoint = true; 126 } 127 if (this->findCheckpoint(v.z) == check) 128 { 129 reachedValidCheckpoint = true; 130 } 131 } 132 else 133 { 134 reachedValidCheckpoint = (check->getCheckpointIndex() == 0); 135 } 136 137 if (gametype && reachedValidCheckpoint) 138 { 136 // the player reached a valid checkpoint 139 137 gametype->getClock().capture(); 140 138 float time = gametype->getClock().getSecondsPrecise(); 141 if ( check->getTimeLimit() != 0 && time > check->getTimeLimit())139 if (newCheckpoint->getTimeLimit() != 0 && time > newCheckpoint->getTimeLimit()) 142 140 { 141 // time's up - the player has lost the game 143 142 gametype->setTimeIsUp(); 144 143 gametype->end(); 145 144 } 146 else if (check->isLast()) 145 else if (newCheckpoint->isLast()) 146 { 147 // the last checkpoint was reached - the player has won the game 147 148 gametype->end(); 149 } 148 150 else 149 151 { 150 if (index > -1) 151 this->setRadarVisibility(player, false); 152 else 153 this->findCheckpoint(0)->setRadarVisibility(false); 154 155 gametype->newCheckpointReached(check, player); 156 this->setRadarVisibility(player, true); 152 // adjust the radarvisibility 153 gametype->newCheckpointReached(newCheckpoint, player); 154 this->updateRadarVisibility(oldCheckpoint, newCheckpoint); 157 155 } 158 156 } 159 157 160 check->resetPlayer();158 newCheckpoint->resetPlayer(); 161 159 } 162 160 163 void SpaceRaceManager:: setRadarVisibility(PlayerInfo* player, bool bVisible)161 void SpaceRaceManager::updateRadarVisibility(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint) const 164 162 { 165 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 166 assert(gametype); 167 int index = gametype->getCheckpointReached(player); 168 Vector3 v = this->findCheckpoint(index)->getNextcheckpoint(); 163 if (oldCheckpoint) 164 { 165 const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints(); 166 for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it) 167 this->findCheckpoint(*it)->setRadarVisibility(false); 168 } 169 169 170 if ( v.x > -1)170 if (newCheckpoint) 171 171 { 172 this->findCheckpoint(v.x)->setRadarVisibility(bVisible); 173 this->findCheckpoint(v.x)->settingsChanged(); 174 } 175 if (v.y > -1) 176 { 177 this->findCheckpoint(v.y)->setRadarVisibility(bVisible); 178 this->findCheckpoint(v.y)->settingsChanged(); 179 } 180 if (v.z > -1) 181 { 182 this->findCheckpoint(v.z)->setRadarVisibility(bVisible); 183 this->findCheckpoint(v.z)->settingsChanged(); 172 newCheckpoint->setRadarVisibility(false); 173 174 const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints(); 175 for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it) 176 this->findCheckpoint(*it)->setRadarVisibility(true); 184 177 } 185 178 } -
code/trunk/src/modules/gametypes/SpaceRaceManager.h
r9262 r9263 65 65 RaceCheckPoint* findCheckpoint(int index) const; 66 66 67 void checkpointReached(RaceCheckPoint* check, PlayerInfo* player);67 void checkpointReached(RaceCheckPoint* newCheckpoint, PlayerInfo* player); 68 68 69 69 void tick(float dt); 70 70 71 71 protected: 72 void setRadarVisibility(PlayerInfo* player, bool bVisible); ///< sets RadarVisibility of the checkpoints the player can reach. 72 bool reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const; 73 void updateRadarVisibility(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint) const; 73 74 74 75 private:
Note: See TracChangeset
for help on using the changeset viewer.