[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 | |
---|
[11720] | 82 | this->botclass_ = Class(SpaceRaceBot); |
---|
[9260] | 83 | this->cantMove_ = false; |
---|
[8630] | 84 | this->bTimeIsUp_ = false; |
---|
[11358] | 85 | |
---|
| 86 | this->numberOfBots_ = 5; // quick fix: don't allow default-bots to enter the race |
---|
| 87 | //we fixed the number of bots in order to have the same starting position all the time ! |
---|
[8182] | 88 | } |
---|
[8767] | 89 | |
---|
[11358] | 90 | void SpaceRace::start() |
---|
| 91 | { |
---|
[11720] | 92 | // define spawn positions of the 5 bots |
---|
[11358] | 93 | |
---|
[11721] | 94 | float startpos[15]; |
---|
[11358] | 95 | |
---|
| 96 | startpos[0] =100; |
---|
| 97 | startpos[1] =-40; |
---|
| 98 | startpos[2] =0; |
---|
| 99 | |
---|
| 100 | startpos[3] =100; |
---|
| 101 | startpos[4] =-40; |
---|
| 102 | startpos[5] =100; |
---|
| 103 | |
---|
| 104 | startpos[6] =100; |
---|
| 105 | startpos[7] =-40; |
---|
| 106 | startpos[8] =-100; |
---|
| 107 | |
---|
| 108 | startpos[9] =0; |
---|
| 109 | startpos[10] =-40; |
---|
| 110 | startpos[11] =-80; |
---|
| 111 | |
---|
| 112 | startpos[12] =0; |
---|
| 113 | startpos[13] =-40; |
---|
| 114 | startpos[14] =80; |
---|
| 115 | |
---|
[11720] | 116 | Gametype::start(); |
---|
[11358] | 117 | |
---|
[11720] | 118 | this->spawnPlayersIfRequested(); |
---|
| 119 | this->cantMove_ = true; |
---|
| 120 | //players are unable to move while countdown is running |
---|
| 121 | for (Engine* engine : ObjectList<Engine>()) |
---|
[11358] | 122 | { |
---|
[11720] | 123 | engine->setActive(false); |
---|
| 124 | } |
---|
[11358] | 125 | |
---|
[11720] | 126 | //append spawn positions to bots |
---|
| 127 | int a,b,c; |
---|
| 128 | a=0; |
---|
| 129 | b=1; |
---|
| 130 | c=2; |
---|
[11358] | 131 | |
---|
[11720] | 132 | for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>()) |
---|
| 133 | { |
---|
| 134 | bot->getControllableEntity()->setPosition(startpos[a], startpos[b], startpos[c]); |
---|
| 135 | a += 3; |
---|
| 136 | b += 3; |
---|
| 137 | c += 3; |
---|
[11358] | 138 | } |
---|
| 139 | |
---|
| 140 | std::string message("Use headphones to hear the countdown!"); |
---|
| 141 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
| 142 | ChatManager::message(message); |
---|
| 143 | |
---|
[11720] | 144 | //after 11 seconds , countdownFinished function is called to activate bots` engines |
---|
| 145 | Timer* countdownTimer = new Timer(); |
---|
[11358] | 146 | countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this))); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|
[8428] | 152 | void SpaceRace::end() |
---|
| 153 | { |
---|
[9260] | 154 | this->clock_.capture(); |
---|
| 155 | int s = this->clock_.getSeconds(); |
---|
| 156 | int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s); |
---|
| 157 | std::string message; |
---|
| 158 | |
---|
[8630] | 159 | if (this->bTimeIsUp_) |
---|
| 160 | { |
---|
[9260] | 161 | message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" |
---|
[11358] | 162 | + "You lose!"; |
---|
[8630] | 163 | } |
---|
| 164 | else |
---|
| 165 | { |
---|
[11358] | 166 | message = "You win!! Final check point reached after "+ multi_cast<std::string>(s) |
---|
[8630] | 167 | + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
[9260] | 168 | } |
---|
[9804] | 169 | if (!this->hasEnded()) |
---|
| 170 | { |
---|
| 171 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
| 172 | ChatManager::message(message); |
---|
| 173 | } |
---|
| 174 | this->Gametype::end(); |
---|
[8428] | 175 | } |
---|
[8182] | 176 | |
---|
[9260] | 177 | void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player) |
---|
[8428] | 178 | { |
---|
[9263] | 179 | this->checkpointReached_[player] = checkpoint; |
---|
[9262] | 180 | |
---|
[8630] | 181 | this->clock_.capture(); |
---|
| 182 | int s = this->clock_.getSeconds(); |
---|
[9260] | 183 | int ms = this->clock_.getMilliseconds() % 1000; |
---|
[9262] | 184 | |
---|
[11358] | 185 | |
---|
| 186 | |
---|
| 187 | const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) |
---|
| 188 | + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
[11720] | 189 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
[11358] | 190 | ChatManager::message(message); |
---|
| 191 | |
---|
| 192 | } |
---|
| 193 | |
---|
[11720] | 194 | void SpaceRace::countdownFinished()//activates the engines of all players |
---|
[11358] | 195 | { |
---|
| 196 | |
---|
| 197 | std::string message("RACE STARTED "); |
---|
[9348] | 198 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
[8858] | 199 | ChatManager::message(message); |
---|
[11358] | 200 | |
---|
| 201 | |
---|
[11720] | 202 | for (Engine* engine : ObjectList<Engine>()) |
---|
| 203 | engine->setActive(true); |
---|
| 204 | } |
---|
[11358] | 205 | |
---|
[11720] | 206 | void SpaceRace::playerEntered(PlayerInfo* player) |
---|
[11358] | 207 | { |
---|
| 208 | Gametype::playerEntered(player); |
---|
| 209 | |
---|
| 210 | const std::string& message = player->getName() + " entered the game"; |
---|
| 211 | ChatManager::message(message); |
---|
[8428] | 212 | } |
---|
[9260] | 213 | |
---|
[11358] | 214 | |
---|
[11720] | 215 | void SpaceRace::addBots(unsigned int amount) //function that add the bots to the game |
---|
[11358] | 216 | { |
---|
| 217 | for (unsigned int i = 1; i <= amount; ++i){ |
---|
| 218 | this->botclass_.fabricate(this->getContext()); |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
[11720] | 223 | //set bot configurations |
---|
[9016] | 224 | bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
| 225 | { |
---|
[11358] | 226 | return true; |
---|
[9016] | 227 | } |
---|
| 228 | |
---|
| 229 | bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
| 230 | { |
---|
[11358] | 231 | return true; |
---|
[9016] | 232 | } |
---|
| 233 | |
---|
[11720] | 234 | bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)// false because the bots can not recognize the objects and die to earlyif they can |
---|
[9016] | 235 | { |
---|
| 236 | return false; |
---|
| 237 | } |
---|
[8858] | 238 | } |
---|