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: |
---|
23 | * Celine Eggenberger |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "SpaceRaceManager.h" |
---|
30 | #include "SpaceRace.h" |
---|
31 | #include "infos/PlayerInfo.h" |
---|
32 | |
---|
33 | #include "core/XMLPort.h" |
---|
34 | |
---|
35 | #include "core/CoreIncludes.h" |
---|
36 | |
---|
37 | #include "util/Convert.h" |
---|
38 | #include "util/Math.h" |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | namespace orxonox |
---|
43 | { |
---|
44 | CreateFactory(SpaceRaceManager); |
---|
45 | |
---|
46 | SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : BaseObject(creator) |
---|
47 | { |
---|
48 | RegisterObject(SpaceRaceManager); |
---|
49 | |
---|
50 | this->firstcheckpointvisible_=false; |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | SpaceRaceManager::~SpaceRaceManager() |
---|
55 | { |
---|
56 | if (this->isInitialized()) |
---|
57 | { |
---|
58 | for (size_t i = 0; i < this->checkpoints_.size(); ++i) |
---|
59 | this->checkpoints_[i]->destroy(); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | void SpaceRaceManager::addCheckpoint(RaceCheckPoint* checkpoint) |
---|
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 | |
---|
76 | int SpaceRaceManager::getIndex(RaceCheckPoint* r) |
---|
77 | { |
---|
78 | for (size_t i = 0; i < this->checkpoints_.size(); ++i) |
---|
79 | if (this->checkpoints_[i]==r) {return i;} |
---|
80 | |
---|
81 | return -1; |
---|
82 | } |
---|
83 | |
---|
84 | void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
85 | { |
---|
86 | SUPER(SpaceRaceManager, XMLPort, xmlelement, mode); |
---|
87 | |
---|
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 | void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player) |
---|
111 | { |
---|
112 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
113 | 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) |
---|
120 | { |
---|
121 | RaceCheckPoint* tmp= this->getCheckpoint(index); |
---|
122 | v= tmp->getNextcheckpoint(); |
---|
123 | |
---|
124 | if (this->getCheckpoint(v.x) == check) |
---|
125 | { |
---|
126 | b = true; |
---|
127 | } |
---|
128 | |
---|
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 | |
---|
143 | if (gametype && b) |
---|
144 | { |
---|
145 | gametype->clock_.capture(); |
---|
146 | float time = gametype->clock_.getSecondsPrecise(); |
---|
147 | if (check->getTimeLimit()!=0 && time > check->getTimeLimit()) |
---|
148 | { |
---|
149 | gametype->timeIsUp(); |
---|
150 | gametype->end(); |
---|
151 | } |
---|
152 | else if (check->getLast()) |
---|
153 | gametype->end(); |
---|
154 | else |
---|
155 | { |
---|
156 | if (index > -1)this->setRadVis(player,false); |
---|
157 | else this->getCheckpoint(0)->setRadarVisibility(false); |
---|
158 | gametype->newCheckpointReached(check,player); |
---|
159 | |
---|
160 | |
---|
161 | this->setRadVis(player, true); |
---|
162 | } |
---|
163 | } |
---|
164 | check->reached_=NULL; |
---|
165 | } |
---|
166 | |
---|
167 | void SpaceRaceManager::setRadVis(PlayerInfo* player, bool b) |
---|
168 | { |
---|
169 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
170 | assert(gametype); |
---|
171 | 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) |
---|
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); |
---|
189 | this->getCheckpoint(v.z)->settingsChanged(); |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | } |
---|
194 | |
---|
195 | } |
---|