Changeset 8970 for code/branches
- Timestamp:
- Dec 13, 2011, 10:50:14 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
r8968 r8970 52 52 this->setBroadcast(false); 53 53 this->setSimultaneousTriggerers(100); 54 55 56 57 58 54 this->bTimeLimit_ = 0; 59 60 55 61 56 this->setRadarObjectColour(ColourValue::Blue); 62 57 this->setRadarObjectShape(RadarViewable::Triangle); 63 64 this->setRadarVisibility(false); 65 this->settingsChanged(); 66 this->reached_=NULL; 67 //this->addTarget("WorldEntity"); 68 69 58 this->setRadarVisibility(false); 59 this->settingsChanged(); 60 this->reached_=NULL; 61 //this->addTarget("WorldEntity"); 70 62 } 71 63 72 64 73 65 RaceCheckPoint::~RaceCheckPoint() 74 66 { 75 67 76 77 78 79 } 68 } 80 69 81 70 void RaceCheckPoint::tick(float dt) … … 85 74 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 86 75 assert(gametype); 87 88 76 } 89 77 … … 91 79 { 92 80 SUPER(RaceCheckPoint, XMLPort, xmlelement, mode); 93 81 Vector3 v= Vector3(0,0,0); 94 82 XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0); 95 83 XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false); … … 98 86 } 99 87 100 88 void RaceCheckPoint::fire(bool bIsTriggered,BaseObject* player) 101 89 { 102 90 DistanceMultiTrigger::fire((bool)bIsTriggered,player); 103 91 104 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());92 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 105 93 assert(gametype); 106 ControllableEntity* entity=(ControllableEntity*) player;94 ControllableEntity* entity = (ControllableEntity*) player; 107 95 108 PlayerInfo* player2=entity->getPlayer();96 PlayerInfo* player2 = entity->getPlayer(); 109 97 110 if(bIsTriggered)this->reached_=player2; 98 if(bIsTriggered) 99 this->reached_=player2; 111 100 } 112 101 -
code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h
r8968 r8970 52 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 53 53 virtual void tick(float dt); 54 54 inline void setCheckpointIndex(int checkpointIndex) 55 55 { this->bCheckpointIndex_ = checkpointIndex; } 56 56 inline int getCheckpointIndex() 57 57 { return this->bCheckpointIndex_; } 58 58 59 60 {this->nextcheckpoints_=checkpoints;}59 inline void setNextcheckpoint(const Vector3& checkpoints) 60 { this->nextcheckpoints_=checkpoints; } 61 61 inline void setNextcheckpoint(float x, float y, float z) 62 62 { this->setNextcheckpoint(Vector3(x, y, z)); } 63 inline const Vector3& getNextcheckpoint() const 64 {return this->nextcheckpoints_;} 65 66 67 inline void setLast(bool isLast) 63 inline const Vector3& getNextcheckpoint() const 64 { return this->nextcheckpoints_; } 65 inline void setLast(bool isLast) 68 66 { this->bIsLast_ = isLast; } 69 67 inline bool getLast() 70 68 { return this->bIsLast_; } 69 71 70 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. 72 71 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. 73 PlayerInfo* reached_; 74 75 inline float getTimeLimit() 76 { return this->bTimeLimit_;} 72 PlayerInfo* reached_; 73 74 inline float getTimeLimit() 75 { return this->bTimeLimit_; } 76 77 77 protected: 78 78 virtual void fire(bool bIsTriggered,BaseObject* player); 79 80 81 82 79 virtual void setTimelimit(float timeLimit); 83 80 … … 88 85 int bCheckpointIndex_; //The index of this check point. This value will be compared with the number of check points reached in the level. The check points must be indexed in ascending order beginning from zero and without any jumps between the indexes. 89 86 90 91 Vector3 nextcheckpoints_; //the indexes of the next check points 92 93 94 95 std::vector<RaceCheckPoint*> next_; 87 Vector3 nextcheckpoints_; //the indexes of the next check points 88 std::vector<RaceCheckPoint*> next_; 96 89 }; 97 90 } -
code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc
r8968 r8970 47 47 RegisterObject(SpaceRace); 48 48 49 50 51 49 this->bTimeIsUp_ = false; 52 50 this->numberOfBots_ = 0; 53 51 this->cantMove_=false; 54 52 55 56 53 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 57 {this->checkpointReached_[it->first]=-1;} 58 54 {this->checkpointReached_[it->first]=-1;} //TODO: should be removed; no functionallity 59 55 60 56 } … … 99 95 void SpaceRace::start() 100 96 { 101 102 this->spawnPlayersIfRequested(); 103 104 Gametype::checkStart(); 105 this->cantMove_=true; 106 107 for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) 108 {if(it->getMaxSpeedFront()>0){this->maxSpeedBack_=it->getMaxSpeedBack(); 109 this->maxSpeedFront_=it->getMaxSpeedFront(); 110 this->maxSpeedLeftRight_=it->getMaxSpeedLeftRight(); 111 this->maxSpeedUpDown_=(it->getMaxSpeedUpDown()); 112 } 113 it->setMaxSpeedBack(0); 114 it->setMaxSpeedFront(0); 115 it->setMaxSpeedLeftRight(0); 116 it->setMaxSpeedUpDown(0); 117 118 119 } 120 121 this->addBots(this->numberOfBots_); 122 123 124 } 125 126 void SpaceRace::tick(float dt){ 127 SUPER(SpaceRace,tick,dt); 128 129 if(!this->isStartCountdownRunning() && this->cantMove_){ 130 131 for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) 132 { 133 it->setMaxSpeedBack(this->maxSpeedBack_); 134 it->setMaxSpeedFront(this->maxSpeedFront_); 135 it->setMaxSpeedLeftRight(this->maxSpeedLeftRight_); 136 it->setMaxSpeedUpDown(this->maxSpeedUpDown_); 137 } 138 this->cantMove_= false; 139 140 std::string message("The match has started! Reach the check points as quickly as possible!"); 141 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 142 ChatManager::message(message); 143 144 } 145 97 98 this->spawnPlayersIfRequested(); 99 Gametype::checkStart(); 100 this->cantMove_=true; 101 //TODO: switch the engine off/on via a short function 102 for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) 103 { 104 if(it->getMaxSpeedFront()>0) 105 { 106 this->maxSpeedBack_=it->getMaxSpeedBack(); 107 this->maxSpeedFront_=it->getMaxSpeedFront(); 108 this->maxSpeedLeftRight_=it->getMaxSpeedLeftRight(); 109 this->maxSpeedUpDown_=(it->getMaxSpeedUpDown()); 110 } 111 it->setMaxSpeedBack(0); 112 it->setMaxSpeedFront(0); 113 it->setMaxSpeedLeftRight(0); 114 it->setMaxSpeedUpDown(0); 115 } 116 this->addBots(this->numberOfBots_); 117 } 118 119 void SpaceRace::tick(float dt) 120 { 121 SUPER(SpaceRace,tick,dt); 122 123 if(!this->isStartCountdownRunning() && this->cantMove_) 124 { 125 for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) 126 { 127 it->setMaxSpeedBack(this->maxSpeedBack_); 128 it->setMaxSpeedFront(this->maxSpeedFront_); 129 it->setMaxSpeedLeftRight(this->maxSpeedLeftRight_); 130 it->setMaxSpeedUpDown(this->maxSpeedUpDown_); 131 } 132 this->cantMove_= false; 133 134 std::string message("The match has started! Reach the check points as quickly as possible!"); 135 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 136 ChatManager::message(message); 137 } 146 138 147 139 } 148 140 149 141 150 142 151 143 void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl) 152 153 144 { 145 this->checkpointReached_[pl]=index; 154 146 this->clock_.capture(); 155 147 int s = this->clock_.getSeconds(); 156 148 int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); 157 158 159 + " seconds."; 149 const std::string& message = "Checkpoint " + multi_cast<std::string>(index) 150 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) 151 + " seconds.";// Message is too long for a normal screen. 160 152 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 161 153 ChatManager::message(message); 162 163 } 154 } 164 155 165 void SpaceRace::newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl) 166 { int index = p->getCheckpointIndex(); 167 this->checkpointReached_[pl]=index; 168 this->clock_.capture(); 169 int s = this->clock_.getSeconds(); 170 int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); 156 void SpaceRace::newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl) 157 { 158 int index = p->getCheckpointIndex(); 159 this->checkpointReached_[pl]=index; 160 this->clock_.capture(); 161 int s = this->clock_.getSeconds(); 162 int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); 171 163 const std::string& message = "Checkpoint " + multi_cast<std::string>(index) 172 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) 173 + " seconds."; 174 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 175 ChatManager::message(message); 176 177 178 } 179 180 181 182 183 void SpaceRace::playerEntered(PlayerInfo* player){ 184 Gametype::playerEntered(player); 185 186 this->checkpointReached_[player]=-1; 187 //this->playersAlive_++; 188 } 189 190 bool SpaceRace::playerLeft(PlayerInfo* player){ 191 return Gametype::playerLeft(player); 192 // bool valid_player = true; 164 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) 165 + " seconds."; 166 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 167 ChatManager::message(message); 168 } 169 170 171 void SpaceRace::playerEntered(PlayerInfo* player) 172 { 173 Gametype::playerEntered(player); 174 175 this->checkpointReached_[player]=-1; 176 //this->playersAlive_++; 177 } 178 179 bool SpaceRace::playerLeft(PlayerInfo* player) 180 { 181 return Gametype::playerLeft(player); 182 // bool valid_player = true; 193 183 //if (valid_player) 194 184 // { … … 197 187 198 188 // return valid_player; 199 200 201 189 } 190 191 bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator) 202 192 { 203 193 return false; -
code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h
r8968 r8970 53 53 { 54 54 friend class RaceCheckPoint; 55 55 //friend class SpaceRaceManager; 56 56 57 57 public: … … 61 61 virtual void start(); 62 62 virtual void end(); 63 63 64 64 virtual void newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl); 65 65 virtual void newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl); 66 66 67 67 inline void setCheckpointReached(int n, PlayerInfo* p) … … 69 69 inline int getCheckpointReached(PlayerInfo* p) 70 70 { return this->checkpointReached_[p]; } 71 71 72 72 inline void timeIsUp() 73 73 { this->bTimeIsUp_ = true;} 74 75 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.74 void tick(float dt); 75 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. 76 76 77 77 78 78 bool allowPawnHit(Pawn* victim, Pawn* originator); 79 79 80 bool allowPawnDamage(Pawn* victim, Pawn* originator);80 bool allowPawnDamage(Pawn* victim, Pawn* originator); 81 81 82 bool allowPawnDeath(Pawn* victim, Pawn* originator);82 bool allowPawnDeath(Pawn* victim, Pawn* originator); 83 83 protected: 84 85 84 virtual void playerEntered(PlayerInfo* player); //!< Initializes values. 85 virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables. 86 86 private: 87 88 87 float maxSpeedBack_; float maxSpeedFront_; float maxSpeedLeftRight_; float maxSpeedUpDown_; 88 bool cantMove_; 89 89 std::map<PlayerInfo*, int>checkpointReached_; //The number of the last check point reached by each player. 90 90 std::set<float> scores_; //The times of the players are saved in a set. 91 91 bool bTimeIsUp_; //True if one of the check points is reached too late. 92 92 93 94 int playersAlive_; 95 96 93 int playersAlive_; 97 94 }; 98 95 } -
code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc
r8968 r8970 52 52 } 53 53 54 SpaceRaceManager::~SpaceRaceManager()54 SpaceRaceManager::~SpaceRaceManager() 55 55 { 56 56 if (this->isInitialized()) … … 60 60 } 61 61 } 62 63 62 63 void SpaceRaceManager::addCheckpoint(RaceCheckPoint* checkpoint) 64 64 { 65 65 this->checkpoints_.push_back(checkpoint); … … 76 76 int SpaceRaceManager::getIndex(RaceCheckPoint* r) 77 77 { 78 79 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 80 if (this->checkpoints_[i]==r){return i;} 78 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 79 if (this->checkpoints_[i]==r) {return i;} 81 80 82 83 84 return -1; 81 return -1; 85 82 } 86 83 87 84 void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode) 88 85 { 89 86 SUPER(SpaceRaceManager, XMLPort, xmlelement, mode); … … 95 92 void SpaceRaceManager::tick(float dt) 96 93 { 97 SUPER(SpaceRaceManager,tick,dt);94 SUPER(SpaceRaceManager,tick,dt); 98 95 99 if(this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_) 100 {this->checkpoints_[0]->setRadarVisibility(true);this->firstcheckpointvisible_=false;} 96 if(this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_) 97 { 98 this->checkpoints_[0]->setRadarVisibility(true); 99 this->firstcheckpointvisible_=false; 100 } 101 101 102 for (size_t i = 0; i < this->checkpoints_.size(); ++i){ 103 if(this->checkpoints_[i]->reached_!=NULL) 102 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 103 { 104 if(this->checkpoints_[i]->reached_!=NULL) 104 105 this->checkpointReached(this->checkpoints_[i],this->checkpoints_[i]->reached_); 105 106 } 106 } 107 107 } 108 108 109 109 110 void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player){ 111 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 110 void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player) 111 { 112 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 112 113 assert(gametype); 113 114 115 bool b =false; 116 117 int index=gametype->getCheckpointReached(player); 118 Vector3 v=Vector3 (-1,-1,-1); 119 if (index>-1) 120 { 121 RaceCheckPoint* tmp= this->getCheckpoint(index); 122 v= tmp->getNextcheckpoint(); 114 123 115 116 bool b =false; 117 118 int index=gametype->getCheckpointReached(player); 119 Vector3 v=Vector3 (-1,-1,-1); 120 if (index>-1){ 121 RaceCheckPoint* tmp= this->getCheckpoint(index); 122 v= tmp->getNextcheckpoint(); 124 if (this->getCheckpoint(v.x) == check) 125 { 126 b = true; 127 } 123 128 124 125 if (this->getCheckpoint(v.x)==check){ 126 b=true; 127 } 128 129 if (this->getCheckpoint(v.y)==check){ 130 b=true; 131 } 132 if (this->getCheckpoint(v.z)==check){ 133 b=true; 134 } } 135 else{b=(this->getIndex(check)==0);} 136 129 if (this->getCheckpoint(v.y) == check) 130 { 131 b = true; 132 } 133 if (this->getCheckpoint(v.z) == check) 134 { 135 b = true; 136 } 137 } 138 else 139 { 140 b = (this->getIndex(check) == 0); 141 } 142 137 143 if (gametype && b) 138 144 { … … 148 154 else 149 155 { 150 156 if (index > -1)this->setRadVis(player,false); 151 157 gametype->newCheckpointReached(check,player); 152 158 check->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red. 153 159 154 155 156 160 this->setRadVis(player, true); 157 158 161 } 159 162 } 160 163 check->reached_=NULL; 161 164 } 162 165 163 void SpaceRaceManager::setRadVis(PlayerInfo* player, bool b){ 164 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 166 void SpaceRaceManager::setRadVis(PlayerInfo* player, bool b) 167 { 168 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 165 169 assert(gametype); 166 int index=gametype->getCheckpointReached(player);167 Vector3 v=Vector3(-1,-1,-1);168 RaceCheckPoint* tmp= this->getCheckpoint(index);169 v= tmp->getNextcheckpoint();170 int index = gametype->getCheckpointReached(player); 171 Vector3 v = Vector3(-1,-1,-1); 172 RaceCheckPoint* tmp = this->getCheckpoint(index); 173 v = tmp->getNextcheckpoint(); 170 174 171 172 if(v.x > -1){this->getCheckpoint(v.x)->setRadarVisibility(b); 173 this->getCheckpoint(v.x)->settingsChanged();} 174 if(v.y > -1){this->getCheckpoint(v.y)->setRadarVisibility(b); 175 this->getCheckpoint(v.y)->settingsChanged();} 176 if(v.z > -1){this->getCheckpoint(v.z)->setRadarVisibility(b); 177 this->getCheckpoint(v.z)->settingsChanged();} 178 175 if(v.x > -1) 176 { 177 this->getCheckpoint(v.x)->setRadarVisibility(b); 178 this->getCheckpoint(v.x)->settingsChanged(); 179 } 180 if(v.y > -1) 181 { 182 this->getCheckpoint(v.y)->setRadarVisibility(b); 183 this->getCheckpoint(v.y)->settingsChanged(); 184 } 185 if(v.z > -1) 186 { 187 this->getCheckpoint(v.z)->setRadarVisibility(b); 188 this->getCheckpoint(v.z)->settingsChanged(); 189 } 179 190 } 180 191 181 182 183 184 } 185 186 187 192 } -
code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h
r8968 r8970 53 53 { 54 54 friend class RaceCheckPoint; 55 56 55 57 56 public: 58 57 SpaceRaceManager(BaseObject* creator); 59 58 virtual ~SpaceRaceManager() ; 60 59 61 void XMLPort(Element& xmlelement, XMLPort::Mode mode);62 60 void XMLPort(Element& xmlelement, XMLPort::Mode mode); 61 int getIndex(RaceCheckPoint* r); 63 62 void addCheckpoint(RaceCheckPoint* checkpoint); 64 63 RaceCheckPoint* getCheckpoint(unsigned int index) const; 65 66 void checkpointReached(RaceCheckPoint* check, PlayerInfo* player); 67 68 69 70 void tick(float dt); 64 65 void checkpointReached(RaceCheckPoint* check, PlayerInfo* player); 66 67 void tick(float dt); 68 71 69 protected: 72 void setRadVis(PlayerInfo* player, bool b); 70 void setRadVis(PlayerInfo* player, bool b); 71 73 72 private: 74 std::vector<RaceCheckPoint*> checkpoints_; 75 bool firstcheckpointvisible_; 76 77 78 }; 73 std::vector<RaceCheckPoint*> checkpoints_; 74 bool firstcheckpointvisible_; 75 76 }; 79 77 } 80 78
Note: See TracChangeset
for help on using the changeset viewer.