[8911] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[8968] | 23 | * Celine Eggenberger |
---|
[8911] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "SpaceRaceManager.h" |
---|
[8934] | 30 | #include "SpaceRace.h" |
---|
[8940] | 31 | #include "infos/PlayerInfo.h" |
---|
[8911] | 32 | |
---|
| 33 | #include "core/XMLPort.h" |
---|
| 34 | |
---|
| 35 | #include "core/CoreIncludes.h" |
---|
| 36 | |
---|
| 37 | #include "util/Convert.h" |
---|
| 38 | #include "util/Math.h" |
---|
| 39 | |
---|
[8968] | 40 | |
---|
| 41 | |
---|
[8911] | 42 | namespace orxonox |
---|
| 43 | { |
---|
[8940] | 44 | CreateFactory(SpaceRaceManager); |
---|
[8911] | 45 | |
---|
| 46 | SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : BaseObject(creator) |
---|
| 47 | { |
---|
| 48 | RegisterObject(SpaceRaceManager); |
---|
[8944] | 49 | |
---|
[8968] | 50 | this->firstcheckpointvisible_=false; |
---|
| 51 | |
---|
[8911] | 52 | } |
---|
| 53 | |
---|
[8970] | 54 | SpaceRaceManager::~SpaceRaceManager() |
---|
[8915] | 55 | { |
---|
| 56 | if (this->isInitialized()) |
---|
| 57 | { |
---|
| 58 | for (size_t i = 0; i < this->checkpoints_.size(); ++i) |
---|
| 59 | this->checkpoints_[i]->destroy(); |
---|
| 60 | } |
---|
| 61 | } |
---|
[8970] | 62 | |
---|
| 63 | void SpaceRaceManager::addCheckpoint(RaceCheckPoint* checkpoint) |
---|
[8915] | 64 | { |
---|
| 65 | this->checkpoints_.push_back(checkpoint); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | RaceCheckPoint* SpaceRaceManager::getCheckpoint(unsigned int index) const |
---|
| 69 | { |
---|
| 70 | if (index < this->checkpoints_.size()) |
---|
| 71 | return this->checkpoints_[index]; |
---|
| 72 | else |
---|
| 73 | return 0; |
---|
| 74 | } |
---|
| 75 | |
---|
[8959] | 76 | int SpaceRaceManager::getIndex(RaceCheckPoint* r) |
---|
| 77 | { |
---|
[8970] | 78 | for (size_t i = 0; i < this->checkpoints_.size(); ++i) |
---|
| 79 | if (this->checkpoints_[i]==r) {return i;} |
---|
[8959] | 80 | |
---|
[8970] | 81 | return -1; |
---|
[8959] | 82 | } |
---|
| 83 | |
---|
[8970] | 84 | void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[8911] | 85 | { |
---|
| 86 | SUPER(SpaceRaceManager, XMLPort, xmlelement, mode); |
---|
| 87 | |
---|
[8979] | 88 | |
---|
[8940] | 89 | XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode); |
---|
[8911] | 90 | } |
---|
| 91 | |
---|
| 92 | void SpaceRaceManager::tick(float dt) |
---|
| 93 | { |
---|
[8970] | 94 | SUPER(SpaceRaceManager,tick,dt); |
---|
[8968] | 95 | |
---|
[8970] | 96 | if(this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_) |
---|
| 97 | { |
---|
| 98 | this->checkpoints_[0]->setRadarVisibility(true); |
---|
[8983] | 99 | this->firstcheckpointvisible_=true; |
---|
[8970] | 100 | } |
---|
[8940] | 101 | |
---|
[8970] | 102 | for (size_t i = 0; i < this->checkpoints_.size(); ++i) |
---|
| 103 | { |
---|
| 104 | if(this->checkpoints_[i]->reached_!=NULL) |
---|
[8959] | 105 | this->checkpointReached(this->checkpoints_[i],this->checkpoints_[i]->reached_); |
---|
[8970] | 106 | } |
---|
[8959] | 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
[8970] | 110 | void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player) |
---|
| 111 | { |
---|
| 112 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
[8959] | 113 | assert(gametype); |
---|
| 114 | |
---|
[8970] | 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(); |
---|
[8968] | 123 | |
---|
[8970] | 124 | if (this->getCheckpoint(v.x) == check) |
---|
| 125 | { |
---|
| 126 | b = true; |
---|
| 127 | } |
---|
[8959] | 128 | |
---|
[8970] | 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 | |
---|
[8959] | 143 | if (gametype && b) |
---|
| 144 | { |
---|
| 145 | gametype->clock_.capture(); |
---|
| 146 | float time = gametype->clock_.getSecondsPrecise(); |
---|
[8968] | 147 | if (check->getTimeLimit()!=0 && time > check->getTimeLimit()) |
---|
[8959] | 148 | { |
---|
| 149 | gametype->timeIsUp(); |
---|
| 150 | gametype->end(); |
---|
| 151 | } |
---|
| 152 | else if (check->getLast()) |
---|
| 153 | gametype->end(); |
---|
| 154 | else |
---|
[8983] | 155 | { |
---|
[8970] | 156 | if (index > -1)this->setRadVis(player,false); |
---|
[8979] | 157 | else this->getCheckpoint(0)->setRadarVisibility(false); |
---|
[8959] | 158 | gametype->newCheckpointReached(check,player); |
---|
[8983] | 159 | |
---|
[8968] | 160 | |
---|
| 161 | this->setRadVis(player, true); |
---|
[8959] | 162 | } |
---|
| 163 | } |
---|
[8970] | 164 | check->reached_=NULL; |
---|
[8959] | 165 | } |
---|
| 166 | |
---|
[8970] | 167 | void SpaceRaceManager::setRadVis(PlayerInfo* player, bool b) |
---|
| 168 | { |
---|
| 169 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
[8968] | 170 | assert(gametype); |
---|
[8970] | 171 | int index = gametype->getCheckpointReached(player); |
---|
| 172 | Vector3 v = Vector3(-1,-1,-1); |
---|
| 173 | RaceCheckPoint* tmp = this->getCheckpoint(index); |
---|
| 174 | v = tmp->getNextcheckpoint(); |
---|
[8959] | 175 | |
---|
[8970] | 176 | if(v.x > -1) |
---|
| 177 | { |
---|
| 178 | this->getCheckpoint(v.x)->setRadarVisibility(b); |
---|
| 179 | this->getCheckpoint(v.x)->settingsChanged(); |
---|
| 180 | } |
---|
| 181 | if(v.y > -1) |
---|
| 182 | { |
---|
| 183 | this->getCheckpoint(v.y)->setRadarVisibility(b); |
---|
| 184 | this->getCheckpoint(v.y)->settingsChanged(); |
---|
| 185 | } |
---|
| 186 | if(v.z > -1) |
---|
| 187 | { |
---|
| 188 | this->getCheckpoint(v.z)->setRadarVisibility(b); |
---|
[8983] | 189 | this->getCheckpoint(v.z)->settingsChanged(); |
---|
[8970] | 190 | } |
---|
[8983] | 191 | |
---|
| 192 | |
---|
[8968] | 193 | } |
---|
[8959] | 194 | |
---|
[8970] | 195 | } |
---|