Changeset 8928 for code/branches
- Timestamp:
- Nov 9, 2011, 4:11:12 PM (13 years ago)
- Location:
- code/branches/spaceraceTwo/src/modules/gametypes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc
r8921 r8928 36 36 #include "SpaceRace.h" 37 37 38 38 39 namespace orxonox 39 40 { … … 60 61 // this->nextcheckpoints_[i]->destroy(); 61 62 } 62 nextcheckpoints_.clear();63 //nextcheckpoints_.destroy; 63 64 } 64 65 … … 69 70 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 70 71 assert(gametype); 71 if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) 72 this->setRadarVisibility(true); 73 else 74 this->setRadarVisibility(false); 72 this->setRadarVisibility(false); 73 Vector3 v =Vector3(0,0,0); 74 int j=0; 75 for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it) 76 { 77 j=gametype->getCheckpointReached(it->first); 78 RaceCheckPoint* r=SpaceRaceManager::getCheckpoint(j); 79 v=r->getNextcheckpoint(); 80 for(int i=1;i<4;i++){ 81 if (this->getCheckpointIndex() == v[i]) 82 this->setRadarVisibility(true); 83 } 84 } 75 85 } 76 86 … … 82 92 XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false); 83 93 XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); 84 //XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const std::vector<int>&);94 XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&); 85 95 } 86 96 87 void RaceCheckPoint::triggered(bool bIsTriggered) 97 98 99 void RaceCheckPoint::triggered(bool bIsTriggered, PlayerInfo* player) 88 100 { 89 101 DistanceTrigger::triggered(bIsTriggered); 90 102 91 103 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 92 if (gametype && this->getCheckpointIndex() == gametype->getCheckpoint sReached() && bIsTriggered)104 if (gametype && this->getCheckpointIndex() == gametype->getCheckpointReached(player) && bIsTriggered) 93 105 { 94 106 gametype->clock_.capture(); … … 103 115 else 104 116 { 105 gametype->newCheckpointReached( );117 gametype->newCheckpointReached(this); 106 118 this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red. 107 119 } -
code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h
r8915 r8928 50 50 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 51 51 virtual void tick(float dt); 52 inline void setCheckpointIndex(int checkpointIndex) 53 { this->bCheckpointIndex_ = checkpointIndex; } 54 inline int getCheckpointIndex() 55 { return this->bCheckpointIndex_; } 52 56 53 protected: 54 virtual void triggered(bool bIsTriggered); 57 inline void setNextcheckpoint(const Vector3& checkpoints) 58 {this->nextcheckpoints_=checkpoints;} 59 inline void setNextcheckpoint(float x, float y, float z) 60 { this->setNextcheckpoint(Vector3(x, y, z)); } 61 inline const Vector3& getNextcheckpoint() const 62 {return this->nextcheckpoints_;} 63 protected: 64 virtual void triggered(bool bIsTriggered, PlayerInfo* player); 55 65 inline void setLast(bool isLast) 56 66 { this->bIsLast_ = isLast; } … … 58 68 { return this->bIsLast_; } 59 69 60 inline void setCheckpointIndex(int checkpointIndex) 61 { this->bCheckpointIndex_ = checkpointIndex; } 62 inline int getCheckpointIndex() 63 { return this->bCheckpointIndex_; } 70 71 64 72 65 inline void setNextcheckpoint(std::vector<int> checkpoints)66 { this->nextcheckpoints_ = checkpoints; }67 inline std::vector<int> getNextcheckpoint()68 { return this->nextcheckpoints_; }69 73 virtual void setTimelimit(float timeLimit); 70 74 inline float getTimeLimit() … … 78 82 float bTimeLimit_; //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. 79 83 80 std::vector<int> nextcheckpoints_; //the indexes of the next check points 84 85 Vector3 nextcheckpoints_; //the indexes of the next check points 81 86 82 87 }; -
code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc
r8915 r8928 45 45 { 46 46 RegisterObject(SpaceRace); 47 this->checkpointsReached_ = 0;47 //this->checkpointsReached_ = 0; 48 48 this->bTimeIsUp_ = false; 49 49 this->numberOfBots_ = 0; 50 50 this->cantMove_=false; 51 52 51 53 } 52 54 … … 65 67 int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); 66 68 const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" 67 + "You didn't reach the check point " + multi_cast<std::string>(this->checkpointsReached_+1) 68 + " before the time limit. You lose!"; 69 + "You didn't reach the check point before the time limit. You lose!"; 69 70 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 70 71 ChatManager::message(message); … … 138 139 139 140 140 void SpaceRace::newCheckpointReached( )141 void SpaceRace::newCheckpointReached(RaceCheckPoint* p) 141 142 { 142 this->checkpoint sReached_++;143 this->checkpointReached_=p->getCheckpointIndex(); 143 144 this->clock_.capture(); 144 145 int s = this->clock_.getSeconds(); 145 146 int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); 146 const std::string& message = "Checkpoint " + multi_cast<std::string>( this->getCheckpointsReached())147 const std::string& message = "Checkpoint " + multi_cast<std::string>(p) 147 148 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) 148 149 + " seconds."; 149 150 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 150 151 ChatManager::message(message); 152 153 151 154 } 155 156 int SpaceRace::getCheckpointReached(PlayerInfo* player){ 157 return this->currentCheckpoint_[player]; 158 } 152 159 160 void SpaceRace::playerEntered(PlayerInfo* player){ 161 this->currentCheckpoint_[player]=1; 162 this->playersAlive_++; 163 } 164 165 bool SpaceRace::playerLeft(PlayerInfo* player){ 166 bool valid_player = true; 167 if (valid_player) 168 { 169 this->playersAlive_--; 170 } 171 172 return valid_player; 173 } 153 174 } -
code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h
r8911 r8928 59 59 virtual void end(); 60 60 61 virtual void newCheckpointReached( );61 virtual void newCheckpointReached(RaceCheckPoint* p); 62 62 63 inline void setCheckpointsReached(int n) 64 { this->checkpointsReached_ = n;} 65 inline int getCheckpointsReached() 66 { return this->checkpointsReached_; } 63 inline void setCheckpointReached(int n) 64 { this->checkpointReached_ = n;} 65 inline int getCheckpointReached() 66 { return this->checkpointReached_; } 67 67 68 inline void timeIsUp() 68 69 { this->bTimeIsUp_ = true;} 69 70 void tick(float dt); 71 72 int getCheckpointReached(PlayerInfo* player); 73 74 70 75 protected: 71 76 virtual void playerEntered(PlayerInfo* player); //!< Initializes values. 77 virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables. 72 78 private: 73 79 float maxSpeedBack_; float maxSpeedFront_; float maxSpeedLeftRight_; float maxSpeedUpDown_; 74 80 bool cantMove_; 75 int checkpoint sReached_; //The current number of check points reached by theplayer.81 int checkpointReached_; //The number of the last check point reached by each player. 76 82 std::set<float> scores_; //The times of the players are saved in a set. 77 83 bool bTimeIsUp_; //True if one of the check points is reached too late. 78 84 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. 85 86 std::map<PlayerInfo*, int> currentCheckpoint_; 87 int playersAlive_; 88 89 79 90 }; 80 91 } -
code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc
r8915 r8928 85 85 86 86 87 88 89 90 } 87 91 88 89 92 90 } -
code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h
r8915 r8928 61 61 void addCheckpoint(RaceCheckPoint* checkpoint); 62 62 RaceCheckPoint* getCheckpoint(unsigned int index) const; 63 64 63 65 64 66 void tick(float dt); … … 66 68 67 69 private: 68 std::vector<RaceCheckPoint*> checkpoints_; 70 std::vector<RaceCheckPoint*> checkpoints_; 71 72 73 69 74 }; 70 75 }
Note: See TracChangeset
for help on using the changeset viewer.