[8182] | 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: |
---|
[8250] | 23 | * Mauro Salomon |
---|
[8182] | 24 | * Co-authors: |
---|
[11358] | 25 | * Celine Egger*/ |
---|
| 26 | |
---|
[8182] | 27 | |
---|
[11358] | 28 | |
---|
| 29 | |
---|
| 30 | /* |
---|
| 31 | Edited, Renewed and Revised by |
---|
| 32 | Berkay Berabi |
---|
| 33 | Louis Meile |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | To-do- list by Louis Meile and Berkay Berabi for future projects : |
---|
| 37 | - improve AI (SpaceRaceController): |
---|
| 38 | i) so far bots arent able to evade obstacles. fix that! |
---|
| 39 | ii) bots should be able to use pickups |
---|
| 40 | - game crashes when bot wins the game(this is a huge problem you should work with the log file to find out what the errors are ) |
---|
| 41 | - bots rotate while waiting for the countdown to end. make it stop! |
---|
| 42 | - add elements to level file to make it even more fun to play. be creative! |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | |
---|
[8182] | 46 | #include "SpaceRace.h" |
---|
| 47 | |
---|
[11358] | 48 | #include "core/CoreIncludes.h" |
---|
| 49 | #include "chat/ChatManager.h" |
---|
| 50 | #include "util/Convert.h" |
---|
| 51 | #include "util/Math.h" |
---|
| 52 | #include "infos/Bot.h" |
---|
[9016] | 53 | #include "items/Engine.h" |
---|
[11358] | 54 | #include "controllers/HumanController.h" |
---|
[9016] | 55 | |
---|
[8182] | 56 | #include "core/CoreIncludes.h" |
---|
[8858] | 57 | #include "chat/ChatManager.h" |
---|
[11358] | 58 | #include "infos/PlayerInfo.h" |
---|
| 59 | #include "worldentities/pawns/Pawn.h" |
---|
| 60 | #include "core/config/ConfigValueIncludes.h" |
---|
| 61 | #include "infos/Bot.h" |
---|
| 62 | #include "SpaceRaceBot.h" |
---|
| 63 | #include "items/Engine.h" |
---|
| 64 | |
---|
| 65 | #include "core/CoreIncludes.h" |
---|
| 66 | #include "chat/ChatManager.h" |
---|
[8428] | 67 | #include "util/Convert.h" |
---|
[8767] | 68 | #include "util/Math.h" |
---|
[9526] | 69 | #include "SpaceRaceBot.h" |
---|
[9016] | 70 | #include "items/Engine.h" |
---|
[11358] | 71 | #include <vector> |
---|
[9016] | 72 | |
---|
[11358] | 73 | |
---|
[8250] | 74 | namespace orxonox |
---|
| 75 | { |
---|
[9667] | 76 | RegisterUnloadableClass(SpaceRace); |
---|
[8767] | 77 | |
---|
[9667] | 78 | SpaceRace::SpaceRace(Context* context) : Gametype(context) |
---|
[8182] | 79 | { |
---|
[8630] | 80 | RegisterObject(SpaceRace); |
---|
[9260] | 81 | |
---|
[11358] | 82 | this->botclass_ = Class(SpaceRaceBot); //ClassByString("") |
---|
[9260] | 83 | this->cantMove_ = false; |
---|
[8630] | 84 | this->bTimeIsUp_ = false; |
---|
[11358] | 85 | this->setConfigValues(); |
---|
| 86 | |
---|
| 87 | this->numberOfBots_ = 5; // quick fix: don't allow default-bots to enter the race |
---|
| 88 | //we fixed the number of bots in order to have the same starting position all the time ! |
---|
[8182] | 89 | } |
---|
[8767] | 90 | |
---|
[11358] | 91 | void SpaceRace::setConfigValues() |
---|
| 92 | { |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | void SpaceRace::start() |
---|
| 98 | { |
---|
| 99 | // define spawn positions of the 5 bots |
---|
| 100 | |
---|
| 101 | int startpos[15]; |
---|
| 102 | |
---|
| 103 | startpos[0] =100; |
---|
| 104 | startpos[1] =-40; |
---|
| 105 | startpos[2] =0; |
---|
| 106 | |
---|
| 107 | startpos[3] =100; |
---|
| 108 | startpos[4] =-40; |
---|
| 109 | startpos[5] =100; |
---|
| 110 | |
---|
| 111 | startpos[6] =100; |
---|
| 112 | startpos[7] =-40; |
---|
| 113 | startpos[8] =-100; |
---|
| 114 | |
---|
| 115 | startpos[9] =0; |
---|
| 116 | startpos[10] =-40; |
---|
| 117 | startpos[11] =-80; |
---|
| 118 | |
---|
| 119 | startpos[12] =0; |
---|
| 120 | startpos[13] =-40; |
---|
| 121 | startpos[14] =80; |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | Gametype::start(); |
---|
| 127 | if (true) |
---|
| 128 | { |
---|
| 129 | this->spawnPlayersIfRequested(); |
---|
| 130 | this->cantMove_ = true; |
---|
| 131 | //players are unable to move while countdown is running |
---|
| 132 | for (Engine* engine : ObjectList<Engine>()){ |
---|
| 133 | engine->setActive(false); |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | } |
---|
| 137 | //append spawn positions to bots |
---|
| 138 | int a,b,c; |
---|
| 139 | a=0; |
---|
| 140 | b=1; |
---|
| 141 | c=2; |
---|
| 142 | for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>()){ |
---|
| 143 | bot->getControllableEntity()->setPosition(startpos[a],startpos[b],startpos[c]); |
---|
| 144 | a= a+3; |
---|
| 145 | b = b+3; |
---|
| 146 | c+= 3; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | std::string message("Use headphones to hear the countdown!"); |
---|
| 155 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
| 156 | ChatManager::message(message); |
---|
| 157 | |
---|
| 158 | //after 11 seconds , countdownFinished function is called to activate bots` engines |
---|
| 159 | Timer* countdownTimer = new Timer(); |
---|
| 160 | countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this))); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | |
---|
[8428] | 166 | void SpaceRace::end() |
---|
| 167 | { |
---|
[9260] | 168 | this->clock_.capture(); |
---|
| 169 | int s = this->clock_.getSeconds(); |
---|
| 170 | int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s); |
---|
| 171 | std::string message; |
---|
| 172 | |
---|
[8630] | 173 | if (this->bTimeIsUp_) |
---|
| 174 | { |
---|
[9260] | 175 | message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" |
---|
[11358] | 176 | + "You lose!"; |
---|
[8630] | 177 | } |
---|
| 178 | else |
---|
| 179 | { |
---|
[11358] | 180 | message = "You win!! Final check point reached after "+ multi_cast<std::string>(s) |
---|
[8630] | 181 | + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
[9260] | 182 | } |
---|
[9804] | 183 | if (!this->hasEnded()) |
---|
| 184 | { |
---|
| 185 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
| 186 | ChatManager::message(message); |
---|
| 187 | } |
---|
| 188 | this->Gametype::end(); |
---|
[8428] | 189 | } |
---|
[8182] | 190 | |
---|
[11358] | 191 | |
---|
| 192 | void SpaceRace::tick(float dt) |
---|
[8428] | 193 | { |
---|
[9261] | 194 | SUPER(SpaceRace,tick,dt); |
---|
[11358] | 195 | } |
---|
[8630] | 196 | |
---|
[9260] | 197 | void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player) |
---|
[8428] | 198 | { |
---|
[9263] | 199 | this->checkpointReached_[player] = checkpoint; |
---|
[9262] | 200 | |
---|
[8630] | 201 | this->clock_.capture(); |
---|
| 202 | int s = this->clock_.getSeconds(); |
---|
[9260] | 203 | int ms = this->clock_.getMilliseconds() % 1000; |
---|
[9262] | 204 | |
---|
[11358] | 205 | |
---|
| 206 | |
---|
| 207 | const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) |
---|
| 208 | + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
| 209 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
| 210 | ChatManager::message(message); |
---|
| 211 | |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | void SpaceRace::countdownFinished()//activates the engines of all players |
---|
| 215 | { |
---|
| 216 | |
---|
| 217 | std::string message("RACE STARTED "); |
---|
[9348] | 218 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
[8858] | 219 | ChatManager::message(message); |
---|
[11358] | 220 | |
---|
| 221 | |
---|
| 222 | for (Engine* engine : ObjectList<Engine>()) |
---|
| 223 | engine->setActive(true); |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | void SpaceRace::playerEntered(PlayerInfo* player) |
---|
| 230 | { |
---|
| 231 | Gametype::playerEntered(player); |
---|
| 232 | |
---|
| 233 | const std::string& message = player->getName() + " entered the game"; |
---|
| 234 | ChatManager::message(message); |
---|
[8428] | 235 | } |
---|
[9260] | 236 | |
---|
[11358] | 237 | |
---|
| 238 | void SpaceRace::addBots(unsigned int amount) //function that add the bots to the game |
---|
| 239 | { |
---|
| 240 | for (unsigned int i = 1; i <= amount; ++i){ |
---|
| 241 | this->botclass_.fabricate(this->getContext()); |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | //set bot configurations |
---|
[9016] | 247 | bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
| 248 | { |
---|
[11358] | 249 | return true; |
---|
[9016] | 250 | } |
---|
| 251 | |
---|
| 252 | bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
| 253 | { |
---|
[11358] | 254 | return true; |
---|
[9016] | 255 | } |
---|
| 256 | |
---|
[11358] | 257 | bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)// false because the bots can not recognize the objects and die to early |
---|
| 258 | //if they can |
---|
[9016] | 259 | { |
---|
| 260 | return false; |
---|
| 261 | } |
---|
[8858] | 262 | } |
---|