1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Patrick Boenzli |
---|
13 | */ |
---|
14 | |
---|
15 | #define DEBUG_MODULE_GAME_RULES |
---|
16 | |
---|
17 | #include "multiplayer_team_deathmatch.h" |
---|
18 | |
---|
19 | #include "load_param.h" |
---|
20 | #include "factory.h" |
---|
21 | |
---|
22 | #include "render2D/billboard.h" |
---|
23 | #include "state.h" |
---|
24 | #include "class_list.h" |
---|
25 | |
---|
26 | #include "player.h" |
---|
27 | #include "playable.h" |
---|
28 | #include "space_ships/space_ship.h" |
---|
29 | |
---|
30 | #include "shared_network_data.h" |
---|
31 | |
---|
32 | #include <list> |
---|
33 | |
---|
34 | using namespace std; |
---|
35 | |
---|
36 | |
---|
37 | CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH); |
---|
38 | |
---|
39 | |
---|
40 | /** |
---|
41 | * constructor |
---|
42 | */ |
---|
43 | MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root) |
---|
44 | : GameRules(root) |
---|
45 | { |
---|
46 | this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch"); |
---|
47 | |
---|
48 | this->bLocalPlayerDead = false; |
---|
49 | this->deathTimeout = 10.0f; // 5 seconds |
---|
50 | this->timeout = 0.0f; |
---|
51 | |
---|
52 | this->deathScreen = new Billboard(); |
---|
53 | this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0); |
---|
54 | this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f); |
---|
55 | this->deathScreen->setVisibility(false); |
---|
56 | |
---|
57 | this->localPlayer = State::getPlayer(); |
---|
58 | |
---|
59 | if( root != NULL) |
---|
60 | this->loadParams(root); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * decontsructor |
---|
65 | */ |
---|
66 | MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch() |
---|
67 | { |
---|
68 | if( this->deathScreen) |
---|
69 | delete this->deathScreen; |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root) |
---|
75 | { |
---|
76 | GameRules::loadParams(root) ; |
---|
77 | |
---|
78 | LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout) |
---|
79 | .describe("sets the time in seconds a player has to wait for respawn"); |
---|
80 | |
---|
81 | LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills) |
---|
82 | .describe("sets the maximal kills for winning condition"); |
---|
83 | |
---|
84 | LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen) |
---|
85 | .describe("sets the death screen image"); |
---|
86 | |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | void MultiplayerTeamDeathmatch::setDeathScreen(const char* imageName) |
---|
92 | { |
---|
93 | if( this->deathScreen) |
---|
94 | this->deathScreen->setTexture(imageName); |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | /** |
---|
100 | * called when the player enters the game |
---|
101 | * @param player the spawned player |
---|
102 | */ |
---|
103 | void MultiplayerTeamDeathmatch::onPlayerSpawn() |
---|
104 | { |
---|
105 | this->bLocalPlayerDead = false; |
---|
106 | this->deathScreen->setVisibility(false); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | /** |
---|
111 | * when the player is killed |
---|
112 | * @param player the killed player |
---|
113 | */ |
---|
114 | void MultiplayerTeamDeathmatch::onPlayerDeath() |
---|
115 | { |
---|
116 | this->bLocalPlayerDead = true; |
---|
117 | this->deathScreen->setVisibility(true); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | /** |
---|
122 | * time tick |
---|
123 | * @param dt time |
---|
124 | */ |
---|
125 | void MultiplayerTeamDeathmatch::tick(float dt) |
---|
126 | { |
---|
127 | this->checkGameRules(); |
---|
128 | |
---|
129 | // is the local player dead and inactive |
---|
130 | if( unlikely(this->bLocalPlayerDead)) |
---|
131 | { |
---|
132 | this->timeout += dt; |
---|
133 | PRINTF(0)("TICK DEATH: %f of %f\n", this->timeout, this->deathTimeout); |
---|
134 | // long enough dead? |
---|
135 | if( this->timeout >= this->deathTimeout) |
---|
136 | { |
---|
137 | this->timeout = 0.0f; |
---|
138 | // respawn |
---|
139 | PRINTF(0)("RESPAWN\n"); |
---|
140 | (State::getPlayer())->getPlayable()->respawn(); |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | /** |
---|
147 | * draws the stuff |
---|
148 | */ |
---|
149 | void MultiplayerTeamDeathmatch::draw() |
---|
150 | { |
---|
151 | if( unlikely( this->bLocalPlayerDead)) |
---|
152 | { |
---|
153 | |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | /** |
---|
159 | * check the game rules for consistency |
---|
160 | */ |
---|
161 | void MultiplayerTeamDeathmatch::checkGameRules() |
---|
162 | { |
---|
163 | |
---|
164 | Vector big_left(-201, 0, 0); |
---|
165 | float rBig = 176.0f; |
---|
166 | Vector big_right(177, 0, 0); |
---|
167 | Vector small_left(10, 0, 0); |
---|
168 | Vector small_middle(0, 0, 0); |
---|
169 | Vector small_right(-10, 0, 0); |
---|
170 | float rSmall = 90.0f; |
---|
171 | |
---|
172 | |
---|
173 | // check for max killing count |
---|
174 | if( this->teamAKills >= this->maxKills) |
---|
175 | { |
---|
176 | // team A winns |
---|
177 | } |
---|
178 | else if( this->teamBKills >= this->maxKills) |
---|
179 | { |
---|
180 | // team B winns |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | std::list<BaseObject*>::const_iterator it; |
---|
187 | const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE); |
---|
188 | |
---|
189 | if( SharedNetworkData::getInstance()->isGameServer()) |
---|
190 | { |
---|
191 | for(it = list->begin(); it != list->end(); it++) |
---|
192 | { |
---|
193 | float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len(); |
---|
194 | if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig && |
---|
195 | (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig && |
---|
196 | (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall && |
---|
197 | (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall && |
---|
198 | (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall) |
---|
199 | { |
---|
200 | PRINTF(0)("KILLLLLLLL\n"); |
---|
201 | |
---|
202 | if((*it)->isA(CL_SPACE_SHIP)) |
---|
203 | dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(116369220.33434f); |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | |
---|