[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: |
---|
[9348] | 25 | * Celine Egger |
---|
[8182] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "SpaceRace.h" |
---|
| 30 | |
---|
[9016] | 31 | #include "items/Engine.h" |
---|
| 32 | |
---|
[8182] | 33 | #include "core/CoreIncludes.h" |
---|
[8858] | 34 | #include "chat/ChatManager.h" |
---|
[8428] | 35 | #include "util/Convert.h" |
---|
[8767] | 36 | #include "util/Math.h" |
---|
[9526] | 37 | #include "SpaceRaceBot.h" |
---|
[9016] | 38 | #include "items/Engine.h" |
---|
| 39 | |
---|
[8250] | 40 | namespace orxonox |
---|
| 41 | { |
---|
[9667] | 42 | RegisterUnloadableClass(SpaceRace); |
---|
[8767] | 43 | |
---|
[9667] | 44 | SpaceRace::SpaceRace(Context* context) : Gametype(context) |
---|
[8182] | 45 | { |
---|
[8630] | 46 | RegisterObject(SpaceRace); |
---|
[9260] | 47 | |
---|
[9526] | 48 | this->botclass_ = Class(SpaceRaceBot);//ClassByString("") |
---|
[9260] | 49 | this->cantMove_ = false; |
---|
[8630] | 50 | this->bTimeIsUp_ = false; |
---|
[9348] | 51 | this->numberOfBots_ = 0; // quick fix: don't allow default-bots to enter the race |
---|
| 52 | // remove this line, if a raceBot has been created. |
---|
[8182] | 53 | } |
---|
[8767] | 54 | |
---|
[8428] | 55 | void SpaceRace::end() |
---|
| 56 | { |
---|
[9260] | 57 | this->clock_.capture(); |
---|
| 58 | int s = this->clock_.getSeconds(); |
---|
| 59 | int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s); |
---|
| 60 | std::string message; |
---|
| 61 | |
---|
[8630] | 62 | if (this->bTimeIsUp_) |
---|
| 63 | { |
---|
[9260] | 64 | message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" |
---|
[9016] | 65 | + "You didn't reach the check point before the time limit. You lose!"; |
---|
[8630] | 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
[9260] | 69 | message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s) |
---|
[8630] | 70 | + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
[9260] | 71 | } |
---|
[9804] | 72 | if (!this->hasEnded()) |
---|
| 73 | { |
---|
| 74 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
| 75 | ChatManager::message(message); |
---|
| 76 | } |
---|
| 77 | this->Gametype::end(); |
---|
[8428] | 78 | } |
---|
[8182] | 79 | |
---|
[9261] | 80 | void SpaceRace::tick(float dt) |
---|
[8428] | 81 | { |
---|
[9261] | 82 | SUPER(SpaceRace,tick,dt); |
---|
[8630] | 83 | |
---|
[9262] | 84 | // spawn the players already when the countdown starts, but deactivate their engines |
---|
[9261] | 85 | if (this->isStartCountdownRunning() && !this->cantMove_) |
---|
| 86 | { |
---|
| 87 | this->spawnPlayersIfRequested(); |
---|
| 88 | this->cantMove_ = true; |
---|
[9260] | 89 | |
---|
[9261] | 90 | for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) |
---|
| 91 | it->setActive(false); |
---|
| 92 | } |
---|
[9260] | 93 | |
---|
[9262] | 94 | // activate the engines again if the countdown ends |
---|
[9260] | 95 | if (!this->isStartCountdownRunning() && this->cantMove_) |
---|
[9016] | 96 | { |
---|
[9260] | 97 | for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) |
---|
[9016] | 98 | it->setActive(true); |
---|
[9260] | 99 | |
---|
[9016] | 100 | this->cantMove_= false; |
---|
[9260] | 101 | |
---|
| 102 | std::string message = "The match has started! Reach the check points as quickly as possible!"; |
---|
[9348] | 103 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
[9260] | 104 | ChatManager::message(message); |
---|
[9016] | 105 | } |
---|
| 106 | } |
---|
[8767] | 107 | |
---|
[9260] | 108 | void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player) |
---|
[8428] | 109 | { |
---|
[9263] | 110 | this->checkpointReached_[player] = checkpoint; |
---|
[9262] | 111 | |
---|
[8630] | 112 | this->clock_.capture(); |
---|
| 113 | int s = this->clock_.getSeconds(); |
---|
[9260] | 114 | int ms = this->clock_.getMilliseconds() % 1000; |
---|
[9262] | 115 | |
---|
[9263] | 116 | const std::string& message = "Checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) |
---|
[9260] | 117 | + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
[9348] | 118 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
[8858] | 119 | ChatManager::message(message); |
---|
[8428] | 120 | } |
---|
[9260] | 121 | |
---|
[9016] | 122 | bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
| 123 | { |
---|
| 124 | return false; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
| 128 | { |
---|
| 129 | return false; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
| 133 | { |
---|
| 134 | return false; |
---|
| 135 | } |
---|
[8858] | 136 | } |
---|