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 | * Matthias Mock |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "UnderAttack.h" |
---|
31 | |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | #include "core/ConfigValueIncludes.h" |
---|
34 | #include "util/Convert.h" |
---|
35 | #include "network/Host.h" |
---|
36 | |
---|
37 | #include "objects/worldentities/pawns/Destroyer.h" |
---|
38 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | CreateUnloadableFactory(UnderAttack); |
---|
42 | |
---|
43 | UnderAttack::UnderAttack(BaseObject* creator) : TeamDeathmatch(creator) |
---|
44 | { |
---|
45 | RegisterObject(UnderAttack); |
---|
46 | this->gameTime_ = 90; |
---|
47 | this->teams_ = 2; |
---|
48 | this->destroyer_ = 0; |
---|
49 | this->gameEnded_ = false; |
---|
50 | |
---|
51 | this->setConfigValues(); |
---|
52 | this->timesequence_ = (int) this->gameTime_; |
---|
53 | } |
---|
54 | |
---|
55 | void UnderAttack::setConfigValues() |
---|
56 | { |
---|
57 | SetConfigValue(gameTime_, 30); |
---|
58 | } |
---|
59 | |
---|
60 | void UnderAttack::addDestroyer(Destroyer* destroyer) |
---|
61 | { |
---|
62 | this->destroyer_ = destroyer; |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | void UnderAttack::destroyedPawn(Pawn* pawn) |
---|
67 | { |
---|
68 | if (pawn == this->destroyer_) |
---|
69 | { |
---|
70 | this->end(); //end gametype |
---|
71 | std::string message = "Ship destroyed! Team 0 has won!"; |
---|
72 | COUT(0) << message << std::endl; |
---|
73 | Host::Broadcast(message); |
---|
74 | this->gameEnded_ = true; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | bool UnderAttack::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
79 | { |
---|
80 | if (victim == this->destroyer_) |
---|
81 | { |
---|
82 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
83 | { |
---|
84 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
85 | return true; |
---|
86 | else |
---|
87 | return false; |
---|
88 | } |
---|
89 | |
---|
90 | return false; |
---|
91 | } |
---|
92 | |
---|
93 | return TeamDeathmatch::allowPawnHit(victim, originator); |
---|
94 | } |
---|
95 | |
---|
96 | bool UnderAttack::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
97 | { |
---|
98 | if (victim == this->destroyer_) |
---|
99 | { |
---|
100 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
101 | { |
---|
102 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
103 | return true; |
---|
104 | else |
---|
105 | return false; |
---|
106 | } |
---|
107 | |
---|
108 | return false; |
---|
109 | } |
---|
110 | |
---|
111 | return TeamDeathmatch::allowPawnDamage(victim, originator); |
---|
112 | } |
---|
113 | |
---|
114 | bool UnderAttack::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
115 | { |
---|
116 | if (victim == this->destroyer_) |
---|
117 | { |
---|
118 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
119 | { |
---|
120 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
121 | return true; |
---|
122 | else |
---|
123 | return false; |
---|
124 | } |
---|
125 | |
---|
126 | return false; |
---|
127 | } |
---|
128 | |
---|
129 | return TeamDeathmatch::allowPawnDeath(victim, originator); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | void UnderAttack::tick(float dt) |
---|
134 | { |
---|
135 | SUPER(UnderAttack, tick, dt); |
---|
136 | |
---|
137 | if (this->hasStarted() && !gameEnded_) |
---|
138 | { |
---|
139 | gameTime_ = gameTime_ - dt; |
---|
140 | if (gameTime_<= 0) |
---|
141 | { |
---|
142 | this->gameEnded_ = true; |
---|
143 | this->end(); |
---|
144 | std::string message = "Time is up! Team 1 has won!"; |
---|
145 | COUT(0) << message << std::endl; |
---|
146 | Host::Broadcast(message); |
---|
147 | } |
---|
148 | |
---|
149 | //prints gametime |
---|
150 | if ( gameTime_ <= timesequence_) |
---|
151 | { |
---|
152 | std::string message = convertToString(timesequence_) + " sec left!"; |
---|
153 | COUT(0) << message << std::endl; |
---|
154 | Host::Broadcast(message); |
---|
155 | if (timesequence_ >= 30 && timesequence_ <= 60) |
---|
156 | { |
---|
157 | timesequence_ = timesequence_ - 10; |
---|
158 | } |
---|
159 | else if (timesequence_ <= 30) |
---|
160 | { |
---|
161 | timesequence_ = timesequence_ - 5; |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | timesequence_ = timesequence_ - 30; |
---|
166 | } |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|