[8494] | 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 | * Mauro Salomon |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "RaceCheckPoint.h" |
---|
| 30 | |
---|
| 31 | #include "core/CoreIncludes.h" |
---|
| 32 | #include "core/XMLPort.h" |
---|
[8616] | 33 | #include "util/Convert.h" |
---|
[8494] | 34 | |
---|
[8767] | 35 | #include "SpaceRace.h" |
---|
| 36 | |
---|
[8494] | 37 | namespace orxonox |
---|
| 38 | { |
---|
| 39 | CreateFactory(RaceCheckPoint); |
---|
[8767] | 40 | |
---|
[8630] | 41 | RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this)) |
---|
[8494] | 42 | { |
---|
[8630] | 43 | RegisterObject(RaceCheckPoint); |
---|
| 44 | |
---|
| 45 | this->bCheckpointIndex_ = 0; |
---|
| 46 | this->bIsLast_ = false; |
---|
| 47 | this->bTimeLimit_ = 0; |
---|
| 48 | |
---|
| 49 | this->setRadarObjectColour(ColourValue::Blue); |
---|
[8616] | 50 | this->setRadarObjectShape(RadarViewable::Triangle); |
---|
[8494] | 51 | this->setRadarVisibility(false); |
---|
| 52 | } |
---|
[8767] | 53 | |
---|
[8494] | 54 | RaceCheckPoint::~RaceCheckPoint() |
---|
| 55 | { |
---|
| 56 | } |
---|
[8767] | 57 | |
---|
[8494] | 58 | void RaceCheckPoint::tick(float dt) |
---|
| 59 | { |
---|
[8630] | 60 | SUPER(RaceCheckPoint, tick, dt); |
---|
| 61 | |
---|
| 62 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
[8767] | 63 | assert(gametype); |
---|
[8630] | 64 | if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) |
---|
| 65 | this->setRadarVisibility(true); |
---|
| 66 | else |
---|
| 67 | this->setRadarVisibility(false); |
---|
[8494] | 68 | } |
---|
| 69 | |
---|
| 70 | void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 71 | { |
---|
[8630] | 72 | SUPER(RaceCheckPoint, XMLPort, xmlelement, mode); |
---|
| 73 | |
---|
| 74 | XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0); |
---|
| 75 | XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false); |
---|
| 76 | XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); |
---|
[8494] | 77 | } |
---|
[8767] | 78 | |
---|
[8494] | 79 | void RaceCheckPoint::triggered(bool bIsTriggered) |
---|
| 80 | { |
---|
[8630] | 81 | DistanceTrigger::triggered(bIsTriggered); |
---|
| 82 | |
---|
| 83 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
| 84 | if (gametype && this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered) |
---|
| 85 | { |
---|
| 86 | gametype->clock_.capture(); |
---|
| 87 | float time = gametype->clock_.getSecondsPrecise(); |
---|
| 88 | if (this->bTimeLimit_!=0 && time > this->bTimeLimit_) |
---|
| 89 | { |
---|
| 90 | gametype->timeIsUp(); |
---|
| 91 | gametype->end(); |
---|
| 92 | } |
---|
| 93 | else if (this->getLast()) |
---|
| 94 | gametype->end(); |
---|
| 95 | else |
---|
| 96 | { |
---|
| 97 | gametype->newCheckpointReached(); |
---|
| 98 | this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red. |
---|
| 99 | } |
---|
| 100 | } |
---|
[8494] | 101 | } |
---|
[8767] | 102 | |
---|
[8616] | 103 | void RaceCheckPoint::setTimelimit(float timeLimit) |
---|
[8630] | 104 | { |
---|
| 105 | this->bTimeLimit_ = timeLimit; |
---|
| 106 | if (this->bTimeLimit_ != 0) |
---|
| 107 | { |
---|
| 108 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
| 109 | if (gametype) |
---|
| 110 | { |
---|
| 111 | const std::string& message = "You have " + multi_cast<std::string>(this->bTimeLimit_) |
---|
| 112 | + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1) + "\n"; |
---|
| 113 | COUT(3) << message; |
---|
| 114 | const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message); |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | } |
---|
[8767] | 118 | |
---|
[8494] | 119 | } |
---|