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 | SpaceRaceManager::~SpaceRaceManager() |
---|
54 | { |
---|
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_) |
---|
71 | { |
---|
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()); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | void SpaceRaceManager::addCheckpoint(RaceCheckPoint* checkpoint) |
---|
84 | { |
---|
85 | this->checkpoints_.push_back(checkpoint); |
---|
86 | } |
---|
87 | |
---|
88 | RaceCheckPoint* SpaceRaceManager::getCheckpoint(unsigned int index) const |
---|
89 | { |
---|
90 | if (index < this->checkpoints_.size()) |
---|
91 | return this->checkpoints_[index]; |
---|
92 | else |
---|
93 | return 0; |
---|
94 | } |
---|
95 | |
---|
96 | int SpaceRaceManager::getIndex(RaceCheckPoint* checkpoint) |
---|
97 | { |
---|
98 | for (size_t i = 0; i < this->checkpoints_.size(); ++i) |
---|
99 | if (this->checkpoints_[i] == checkpoint) |
---|
100 | return i; |
---|
101 | |
---|
102 | return -1; |
---|
103 | } |
---|
104 | |
---|
105 | void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player) |
---|
106 | { |
---|
107 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
108 | assert(gametype); |
---|
109 | |
---|
110 | bool reachedValidCheckpoint = false; |
---|
111 | |
---|
112 | int index = gametype->getCheckpointReached(player); |
---|
113 | if (index > -1) |
---|
114 | { |
---|
115 | Vector3 v = this->getCheckpoint(index)->getNextcheckpoint(); |
---|
116 | |
---|
117 | if (this->getCheckpoint(v.x) == check) |
---|
118 | { |
---|
119 | reachedValidCheckpoint = true; |
---|
120 | } |
---|
121 | if (this->getCheckpoint(v.y) == check) |
---|
122 | { |
---|
123 | reachedValidCheckpoint = true; |
---|
124 | } |
---|
125 | if (this->getCheckpoint(v.z) == check) |
---|
126 | { |
---|
127 | reachedValidCheckpoint = true; |
---|
128 | } |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | reachedValidCheckpoint = (this->getIndex(check) == 0); |
---|
133 | } |
---|
134 | |
---|
135 | if (gametype && reachedValidCheckpoint) |
---|
136 | { |
---|
137 | gametype->getClock().capture(); |
---|
138 | float time = gametype->getClock().getSecondsPrecise(); |
---|
139 | if (check->getTimeLimit() != 0 && time > check->getTimeLimit()) |
---|
140 | { |
---|
141 | gametype->setTimeIsUp(); |
---|
142 | gametype->end(); |
---|
143 | } |
---|
144 | else if (check->isLast()) |
---|
145 | gametype->end(); |
---|
146 | else |
---|
147 | { |
---|
148 | if (index > -1) |
---|
149 | this->setRadVis(player, false); |
---|
150 | else |
---|
151 | this->getCheckpoint(0)->setRadarVisibility(false); |
---|
152 | |
---|
153 | gametype->newCheckpointReached(check, player); |
---|
154 | this->setRadVis(player, true); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | check->resetPlayer(); |
---|
159 | } |
---|
160 | |
---|
161 | void SpaceRaceManager::setRadVis(PlayerInfo* player, bool bVisible) |
---|
162 | { |
---|
163 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
164 | assert(gametype); |
---|
165 | int index = gametype->getCheckpointReached(player); |
---|
166 | Vector3 v = this->getCheckpoint(index)->getNextcheckpoint(); |
---|
167 | |
---|
168 | if (v.x > -1) |
---|
169 | { |
---|
170 | this->getCheckpoint(v.x)->setRadarVisibility(bVisible); |
---|
171 | this->getCheckpoint(v.x)->settingsChanged(); |
---|
172 | } |
---|
173 | if (v.y > -1) |
---|
174 | { |
---|
175 | this->getCheckpoint(v.y)->setRadarVisibility(bVisible); |
---|
176 | this->getCheckpoint(v.y)->settingsChanged(); |
---|
177 | } |
---|
178 | if (v.z > -1) |
---|
179 | { |
---|
180 | this->getCheckpoint(v.z)->setRadarVisibility(bVisible); |
---|
181 | this->getCheckpoint(v.z)->settingsChanged(); |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|