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 | * Fabian 'x3n' Landau |
---|
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 "objects/Teamcolourable.h" |
---|
35 | #include "objects/worldentities/TeamSpawnPoint.h" |
---|
36 | |
---|
37 | #include "network/Host.h" |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | CreateUnloadableFactory(UnderAttack); |
---|
41 | |
---|
42 | UnderAttack::UnderAttack(BaseObject* creator) : TeamDeathmatch(creator) |
---|
43 | { |
---|
44 | RegisterObject(UnderAttack); |
---|
45 | this->gameTime_ = 30; |
---|
46 | this->teams_ = 2; |
---|
47 | this->destroyer_ = 0; |
---|
48 | this->gameEnded_ = false; |
---|
49 | |
---|
50 | this->setConfigValues(); |
---|
51 | } |
---|
52 | |
---|
53 | void UnderAttack::setConfigValues() |
---|
54 | { |
---|
55 | SetConfigValue(gameTime_, 30); |
---|
56 | } |
---|
57 | |
---|
58 | void UnderAttack::addDestroyer(Destroyer* destroyer) |
---|
59 | { |
---|
60 | this->destroyer_ = destroyer; |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | void UnderAttack::destroyedPawn(Pawn* pawn) |
---|
65 | { |
---|
66 | if (pawn == this->destroyer_) |
---|
67 | { |
---|
68 | this->end(); //end gametype |
---|
69 | std::string message = "Ship destroyed! Team 0 has won!"; |
---|
70 | COUT(0) << message << std::endl; |
---|
71 | Host::Broadcast(message); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | bool UnderAttack::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
76 | { |
---|
77 | if (victim == this->destroyer_) |
---|
78 | { |
---|
79 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
80 | { |
---|
81 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
82 | return true; |
---|
83 | else |
---|
84 | return false; |
---|
85 | } |
---|
86 | |
---|
87 | return false; |
---|
88 | } |
---|
89 | |
---|
90 | return TeamDeathmatch::allowPawnHit(victim, originator); |
---|
91 | } |
---|
92 | |
---|
93 | bool UnderAttack::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
94 | { |
---|
95 | if (victim == this->destroyer_) |
---|
96 | { |
---|
97 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
98 | { |
---|
99 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
100 | return true; |
---|
101 | else |
---|
102 | return false; |
---|
103 | } |
---|
104 | |
---|
105 | return false; |
---|
106 | } |
---|
107 | |
---|
108 | return TeamDeathmatch::allowPawnDamage(victim, originator); |
---|
109 | } |
---|
110 | |
---|
111 | bool UnderAttack::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
112 | { |
---|
113 | if (victim == this->destroyer_) |
---|
114 | { |
---|
115 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
116 | { |
---|
117 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
118 | return true; |
---|
119 | else |
---|
120 | return false; |
---|
121 | } |
---|
122 | |
---|
123 | return false; |
---|
124 | } |
---|
125 | |
---|
126 | return TeamDeathmatch::allowPawnDeath(victim, originator); |
---|
127 | } |
---|
128 | void UnderAttack::tick(float dt) |
---|
129 | { |
---|
130 | SUPER(UnderAttack, tick, dt); |
---|
131 | |
---|
132 | if (this->hasStarted()) |
---|
133 | { |
---|
134 | gameTime_ = gameTime_ - dt; |
---|
135 | if (gameTime_<= 0 && !gameEnded_) |
---|
136 | { |
---|
137 | gameEnded_ = true; |
---|
138 | this->end(); |
---|
139 | std::string message = "Time is up! Team 1 has won!"; |
---|
140 | COUT(0) << message << std::endl; |
---|
141 | Host::Broadcast(message); |
---|
142 | } |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | } |
---|