Changeset 9260 for code/trunk/src/modules/gametypes/SpaceRaceManager.cc
- Timestamp:
- Jun 2, 2012, 10:34:48 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/gametypes/SpaceRaceManager.cc
r9016 r9260 21 21 * 22 22 * Author: 23 * Celine Eggenberger23 * Celine Eggenberger 24 24 * Co-authors: 25 25 * ... … … 47 47 { 48 48 RegisterObject(SpaceRaceManager); 49 50 this->firstcheckpointvisible_=false; 51 49 50 this->firstcheckpointvisible_ = false; 52 51 } 53 52 54 53 SpaceRaceManager::~SpaceRaceManager() 55 54 { 56 if (this->isInitialized()) 55 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 56 this->checkpoints_[i]->destroy(); 57 } 58 59 void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode) 60 { 61 SUPER(SpaceRaceManager, XMLPort, xmlelement, mode); 62 63 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode); 64 } 65 66 void SpaceRaceManager::tick(float dt) 67 { 68 SUPER(SpaceRaceManager,tick,dt); 69 70 if (this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_) 57 71 { 58 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 59 this->checkpoints_[i]->destroy(); 72 this->checkpoints_[0]->setRadarVisibility(true); 73 this->firstcheckpointvisible_ = true; 74 } 75 76 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 77 { 78 if (this->checkpoints_[i]->getPlayer() != NULL) 79 this->checkpointReached(this->checkpoints_[i], this->checkpoints_[i]->getPlayer()); 60 80 } 61 81 } 62 82 63 83 void SpaceRaceManager::addCheckpoint(RaceCheckPoint* checkpoint) 64 84 { … … 73 93 return 0; 74 94 } 75 76 int SpaceRaceManager::getIndex(RaceCheckPoint* r)95 96 int SpaceRaceManager::getIndex(RaceCheckPoint* checkpoint) 77 97 { 78 98 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 79 if (this->checkpoints_[i]==r) {return i;} 80 99 if (this->checkpoints_[i] == checkpoint) 100 return i; 101 81 102 return -1; 82 103 } 83 84 void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode)85 {86 SUPER(SpaceRaceManager, XMLPort, xmlelement, mode);87 104 88 89 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode);90 }91 92 void SpaceRaceManager::tick(float dt)93 {94 SUPER(SpaceRaceManager,tick,dt);95 96 if(this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_)97 {98 this->checkpoints_[0]->setRadarVisibility(true);99 this->firstcheckpointvisible_=true;100 }101 102 for (size_t i = 0; i < this->checkpoints_.size(); ++i)103 {104 if(this->checkpoints_[i]->reached_!=NULL)105 this->checkpointReached(this->checkpoints_[i],this->checkpoints_[i]->reached_);106 }107 }108 109 110 105 void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player) 111 106 { 112 107 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 113 108 assert(gametype); 114 115 bool b =false; 116 117 int index=gametype->getCheckpointReached(player); 118 Vector3 v=Vector3 (-1,-1,-1); 119 if (index>-1) 109 110 bool reachedValidCheckpoint = false; 111 112 int index = gametype->getCheckpointReached(player); 113 if (index > -1) 120 114 { 121 RaceCheckPoint* tmp= this->getCheckpoint(index); 122 v= tmp->getNextcheckpoint(); 123 115 Vector3 v = this->getCheckpoint(index)->getNextcheckpoint(); 116 124 117 if (this->getCheckpoint(v.x) == check) 125 118 { 126 b = true; 127 } 128 119 reachedValidCheckpoint = true; 120 } 129 121 if (this->getCheckpoint(v.y) == check) 130 122 { 131 b= true;132 } 123 reachedValidCheckpoint = true; 124 } 133 125 if (this->getCheckpoint(v.z) == check) 134 126 { 135 b= true;136 } 127 reachedValidCheckpoint = true; 128 } 137 129 } 138 130 else 139 131 { 140 b= (this->getIndex(check) == 0);132 reachedValidCheckpoint = (this->getIndex(check) == 0); 141 133 } 142 143 if (gametype && b)134 135 if (gametype && reachedValidCheckpoint) 144 136 { 145 gametype-> clock_.capture();146 float time = gametype-> clock_.getSecondsPrecise();147 if (check->getTimeLimit() !=0 && time > check->getTimeLimit())137 gametype->getClock().capture(); 138 float time = gametype->getClock().getSecondsPrecise(); 139 if (check->getTimeLimit() != 0 && time > check->getTimeLimit()) 148 140 { 149 gametype-> timeIsUp();141 gametype->setTimeIsUp(); 150 142 gametype->end(); 151 143 } 152 else if (check-> getLast())144 else if (check->isLast()) 153 145 gametype->end(); 154 146 else 155 { 156 if (index > -1)this->setRadVis(player,false); 157 else this->getCheckpoint(0)->setRadarVisibility(false); 158 gametype->newCheckpointReached(check,player); 159 160 147 { 148 if (index > -1) 149 this->setRadVis(player, false); 150 else 151 this->getCheckpoint(0)->setRadarVisibility(false); 152 153 gametype->newCheckpointReached(check, player); 161 154 this->setRadVis(player, true); 162 155 } 163 156 } 164 check->reached_=NULL; 157 158 check->resetPlayer(); 165 159 } 166 167 void SpaceRaceManager::setRadVis(PlayerInfo* player, bool b )160 161 void SpaceRaceManager::setRadVis(PlayerInfo* player, bool bVisible) 168 162 { 169 163 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 170 164 assert(gametype); 171 165 int index = gametype->getCheckpointReached(player); 172 Vector3 v = Vector3(-1,-1,-1); 173 RaceCheckPoint* tmp = this->getCheckpoint(index); 174 v = tmp->getNextcheckpoint(); 175 176 if(v.x > -1) 166 Vector3 v = this->getCheckpoint(index)->getNextcheckpoint(); 167 168 if (v.x > -1) 177 169 { 178 this->getCheckpoint(v.x)->setRadarVisibility(b );170 this->getCheckpoint(v.x)->setRadarVisibility(bVisible); 179 171 this->getCheckpoint(v.x)->settingsChanged(); 180 172 } 181 if (v.y > -1)173 if (v.y > -1) 182 174 { 183 this->getCheckpoint(v.y)->setRadarVisibility(b );175 this->getCheckpoint(v.y)->setRadarVisibility(bVisible); 184 176 this->getCheckpoint(v.y)->settingsChanged(); 185 177 } 186 if (v.z > -1)178 if (v.z > -1) 187 179 { 188 this->getCheckpoint(v.z)->setRadarVisibility(b );189 this->getCheckpoint(v.z)->settingsChanged();180 this->getCheckpoint(v.z)->setRadarVisibility(bVisible); 181 this->getCheckpoint(v.z)->settingsChanged(); 190 182 } 191 192 193 183 } 194 195 184 }
Note: See TracChangeset
for help on using the changeset viewer.