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 "util/Convert.h" |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | #include "core/XMLPort.h" |
---|
34 | #include "chat/ChatManager.h" |
---|
35 | |
---|
36 | #include "SpaceRace.h" |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | CreateFactory(RaceCheckPoint); |
---|
41 | |
---|
42 | RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this)) |
---|
43 | { |
---|
44 | RegisterObject(RaceCheckPoint); |
---|
45 | |
---|
46 | this->bCheckpointIndex_ = 0; |
---|
47 | //this->bIsLast_ = false; |
---|
48 | this->bTimeLimit_ = 0; |
---|
49 | this->isVisible_=false; |
---|
50 | |
---|
51 | this->setRadarObjectColour(ColourValue::Blue); |
---|
52 | this->setRadarObjectShape(RadarViewable::Triangle); |
---|
53 | this->setRadarVisibility(false); |
---|
54 | } |
---|
55 | |
---|
56 | RaceCheckPoint::~RaceCheckPoint() |
---|
57 | { |
---|
58 | //if (this->isInitialized()) |
---|
59 | { |
---|
60 | //for (size_t i = 0; i < this->nextcheckpoints_.size(); ++i) |
---|
61 | // this->nextcheckpoints_[i]->destroy(); |
---|
62 | } |
---|
63 | //nextcheckpoints_.destroy; |
---|
64 | } |
---|
65 | |
---|
66 | void RaceCheckPoint::tick(float dt) |
---|
67 | { |
---|
68 | SUPER(RaceCheckPoint, tick, dt); |
---|
69 | |
---|
70 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
71 | assert(gametype); |
---|
72 | if(this->isVisible_){this->setRadarVisibility(true);} |
---|
73 | else{this->setRadarVisibility(false);} |
---|
74 | /*this->setRadarVisibility(false); |
---|
75 | Vector3 v =Vector3(0,0,0); |
---|
76 | int j=0; |
---|
77 | for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it) |
---|
78 | { |
---|
79 | j=gametype->getCheckpointReached(it->first); |
---|
80 | RaceCheckPoint* r=SpaceRaceManager::getCheckpoint(j); |
---|
81 | v=r->getNextcheckpoint(); |
---|
82 | for(int i=1;i<4;i++){ |
---|
83 | if (this->getCheckpointIndex() == v[i]) |
---|
84 | this->setRadarVisibility(true); |
---|
85 | }*/ |
---|
86 | //} |
---|
87 | } |
---|
88 | |
---|
89 | void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
90 | { |
---|
91 | SUPER(RaceCheckPoint, XMLPort, xmlelement, mode); |
---|
92 | Vector3 v= Vector3(0,0,0); |
---|
93 | XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0); |
---|
94 | XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false); |
---|
95 | XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); |
---|
96 | XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&).defaultValues(v); |
---|
97 | } |
---|
98 | |
---|
99 | void RaceCheckPoint::triggered(bool bIsTriggered, PlayerInfo* player) |
---|
100 | { |
---|
101 | DistanceTrigger::triggered(bIsTriggered); |
---|
102 | |
---|
103 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
104 | assert(gametype); |
---|
105 | if (gametype && this->getCheckpointIndex() == gametype->getCheckpointReached(player) && bIsTriggered) |
---|
106 | { |
---|
107 | gametype->clock_.capture(); |
---|
108 | float time = gametype->clock_.getSecondsPrecise(); |
---|
109 | if (this->bTimeLimit_!=0 && time > this->bTimeLimit_) |
---|
110 | { |
---|
111 | gametype->timeIsUp(); |
---|
112 | gametype->end(); |
---|
113 | } |
---|
114 | else if (this->getLast()) |
---|
115 | gametype->end(); |
---|
116 | else |
---|
117 | { |
---|
118 | gametype->newCheckpointReached(this,player); |
---|
119 | this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red. |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | void RaceCheckPoint::setTimelimit(float timeLimit) |
---|
125 | { |
---|
126 | this->bTimeLimit_ = timeLimit; |
---|
127 | if (this->bTimeLimit_ != 0) |
---|
128 | { |
---|
129 | SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); |
---|
130 | assert(gametype); |
---|
131 | if (gametype) |
---|
132 | { |
---|
133 | const std::string& message = "You have " + multi_cast<std::string>(this->bTimeLimit_) |
---|
134 | + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1); |
---|
135 | const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message); |
---|
136 | ChatManager::message(message); |
---|
137 | } |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|