| [7034] | 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 |  | 
|---|
| [8068] | 17 | #include <map> | 
|---|
 | 18 |  | 
|---|
| [7034] | 19 | #include "multiplayer_team_deathmatch.h" | 
|---|
 | 20 |  | 
|---|
| [7193] | 21 | #include "util/loading/load_param.h" | 
|---|
 | 22 | #include "util/loading/factory.h" | 
|---|
| [7034] | 23 |  | 
|---|
| [7810] | 24 | #include "render2D/image_plane.h" | 
|---|
| [7039] | 25 | #include "state.h" | 
|---|
| [7101] | 26 | #include "class_list.h" | 
|---|
| [7034] | 27 |  | 
|---|
| [7044] | 28 | #include "player.h" | 
|---|
 | 29 | #include "playable.h" | 
|---|
| [7101] | 30 | #include "space_ships/space_ship.h" | 
|---|
| [7039] | 31 |  | 
|---|
| [7116] | 32 |  | 
|---|
| [7101] | 33 | #include "shared_network_data.h" | 
|---|
| [7116] | 34 | #include "terrain.h" | 
|---|
 | 35 | #include "class_list.h" | 
|---|
 | 36 | #include "space_ships/space_ship.h" | 
|---|
| [7044] | 37 |  | 
|---|
| [8068] | 38 | #include "network_game_manager.h" | 
|---|
| [7101] | 39 |  | 
|---|
| [8147] | 40 | #include "event_handler.h" | 
|---|
| [8068] | 41 |  | 
|---|
| [8147] | 42 | #include "glgui.h" | 
|---|
 | 43 |  | 
|---|
 | 44 | #include "story_entity.h" | 
|---|
 | 45 |  | 
|---|
| [8708] | 46 | #include "shell_command.h" | 
|---|
| [8147] | 47 |  | 
|---|
| [8802] | 48 | #include "spawning_point.h" | 
|---|
| [8708] | 49 |  | 
|---|
| [8802] | 50 |  | 
|---|
| [7034] | 51 |  | 
|---|
 | 52 |  | 
|---|
| [9406] | 53 |  | 
|---|
| [7035] | 54 | CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH); | 
|---|
 | 55 |  | 
|---|
 | 56 |  | 
|---|
| [7034] | 57 | /** | 
|---|
 | 58 |  * constructor | 
|---|
 | 59 |  */ | 
|---|
| [7035] | 60 | MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root) | 
|---|
| [8068] | 61 |   : NetworkGameRules(root) | 
|---|
| [7035] | 62 | { | 
|---|
 | 63 |   this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch"); | 
|---|
| [7034] | 64 |  | 
|---|
| [7037] | 65 |   this->bLocalPlayerDead = false; | 
|---|
 | 66 |   this->deathTimeout = 10.0f;     // 5 seconds | 
|---|
| [7082] | 67 |   this->timeout = 0.0f; | 
|---|
| [8068] | 68 |   this->numTeams = 2; | 
|---|
 | 69 |   this->currentGameState = GAMESTATE_PRE_GAME; | 
|---|
| [9008] | 70 |   this->gameStateTimer = 3.0f; | 
|---|
| [8623] | 71 |   this->bShowTeamChange = false; | 
|---|
| [8717] | 72 |  | 
|---|
| [8147] | 73 |   this->box = NULL; | 
|---|
| [8802] | 74 |   this->table = NULL; | 
|---|
 | 75 |   this->statsBox = NULL; | 
|---|
| [7040] | 76 |  | 
|---|
| [7044] | 77 |   this->localPlayer = State::getPlayer(); | 
|---|
 | 78 |  | 
|---|
| [7035] | 79 |   if( root != NULL) | 
|---|
 | 80 |     this->loadParams(root); | 
|---|
| [8717] | 81 |  | 
|---|
| [8623] | 82 |   subscribeEvent( ES_GAME, SDLK_o ); | 
|---|
| [8708] | 83 |   subscribeEvent( ES_GAME, SDLK_TAB ); | 
|---|
| [8802] | 84 |   subscribeEvent( ES_GAME, SDLK_F1 ); | 
|---|
 | 85 |   subscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 ); | 
|---|
| [9008] | 86 |  | 
|---|
| [8708] | 87 |   this->input = new OrxGui::GLGuiInputLine(); | 
|---|
 | 88 |   this->input->setAbsCoor2D(180, 5); | 
|---|
| [9406] | 89 |   this->input->enterPushed.connect(this, &MultiplayerTeamDeathmatch::onInputEnter); | 
|---|
| [7035] | 90 | } | 
|---|
 | 91 |  | 
|---|
| [7034] | 92 | /** | 
|---|
 | 93 |  * decontsructor | 
|---|
 | 94 |  */ | 
|---|
 | 95 | MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch() | 
|---|
| [7044] | 96 | { | 
|---|
| [8623] | 97 |   unsubscribeEvent( ES_GAME, SDLK_o ); | 
|---|
| [8708] | 98 |   unsubscribeEvent( ES_GAME, SDLK_TAB ); | 
|---|
| [8802] | 99 |   unsubscribeEvent( ES_GAME, SDLK_F1 ); | 
|---|
 | 100 |   unsubscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 ); | 
|---|
| [9008] | 101 |  | 
|---|
| [8708] | 102 |   if ( this->input ) | 
|---|
 | 103 |   { | 
|---|
 | 104 |     delete this->input; | 
|---|
 | 105 |     this->input = NULL; | 
|---|
 | 106 |   } | 
|---|
| [7044] | 107 | } | 
|---|
| [7034] | 108 |  | 
|---|
 | 109 |  | 
|---|
 | 110 |  | 
|---|
 | 111 | void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root) | 
|---|
| [7035] | 112 | { | 
|---|
| [7040] | 113 |   GameRules::loadParams(root) ; | 
|---|
| [7037] | 114 |  | 
|---|
 | 115 |   LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout) | 
|---|
 | 116 |       .describe("sets the time in seconds a player has to wait for respawn"); | 
|---|
 | 117 |  | 
|---|
 | 118 |   LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills) | 
|---|
 | 119 |       .describe("sets the maximal kills for winning condition"); | 
|---|
| [7039] | 120 |  | 
|---|
| [8068] | 121 |   LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams) | 
|---|
 | 122 |       .describe("sets number of teams"); | 
|---|
| [7039] | 123 |  | 
|---|
| [7035] | 124 | } | 
|---|
 | 125 |  | 
|---|
 | 126 |  | 
|---|
 | 127 | /** | 
|---|
 | 128 |  * time tick | 
|---|
 | 129 |  * @param dt time | 
|---|
 | 130 |  */ | 
|---|
 | 131 | void MultiplayerTeamDeathmatch::tick(float dt) | 
|---|
| [7037] | 132 | { | 
|---|
| [8802] | 133 |   tickStatsTable(); | 
|---|
| [8147] | 134 |   //on client side hostId is -1 until hanshake finished | 
|---|
 | 135 |   if ( SharedNetworkData::getInstance()->getHostID() < 0 ) | 
|---|
 | 136 |     return; | 
|---|
| [8717] | 137 |  | 
|---|
| [8623] | 138 |   if ( currentGameState == GAMESTATE_PRE_GAME || currentGameState == GAMESTATE_GAME ) | 
|---|
| [8147] | 139 |   { | 
|---|
 | 140 |     if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) | 
|---|
 | 141 |          && box == NULL | 
|---|
| [8717] | 142 |          &&  (PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM | 
|---|
| [8623] | 143 |          || bShowTeamChange ) | 
|---|
| [8717] | 144 |  | 
|---|
| [8147] | 145 |        ) | 
|---|
 | 146 |     { | 
|---|
 | 147 |       EventHandler::getInstance()->pushState( ES_MENU ); | 
|---|
| [8717] | 148 |  | 
|---|
| [8147] | 149 |       OrxGui::GLGuiHandler::getInstance()->activateCursor(); | 
|---|
| [8717] | 150 |  | 
|---|
| [8147] | 151 |       box = new OrxGui::GLGuiBox(); | 
|---|
 | 152 |       box->setAbsCoor2D( 300, 100 ); | 
|---|
| [8717] | 153 |  | 
|---|
| [9470] | 154 |       if( SharedNetworkData::getInstance()->isClient() ||  SharedNetworkData::getInstance()->isProxyServerActive()) | 
|---|
| [9416] | 155 |       { | 
|---|
 | 156 |         OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator"); | 
|---|
 | 157 |         box->pack( buttonSpectator ); | 
|---|
 | 158 |         buttonSpectator->released.connect(this, &MultiplayerTeamDeathmatch::onButtonSpectator); | 
|---|
| [8717] | 159 |  | 
|---|
| [9416] | 160 |         OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random"); | 
|---|
 | 161 |         box->pack( buttonRandom ); | 
|---|
 | 162 |         buttonRandom->released.connect(this, &MultiplayerTeamDeathmatch::onButtonRandom); | 
|---|
| [8717] | 163 |  | 
|---|
| [9416] | 164 |         OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team"); | 
|---|
 | 165 |         box->pack( buttonTeam0 ); | 
|---|
 | 166 |         buttonTeam0->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam0); | 
|---|
| [8717] | 167 |  | 
|---|
| [9416] | 168 |         OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team"); | 
|---|
 | 169 |         box->pack( buttonTeam1 ); | 
|---|
 | 170 |         buttonTeam1->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam1); | 
|---|
 | 171 |       } | 
|---|
 | 172 |       else | 
|---|
 | 173 |       { | 
|---|
 | 174 |         OrxGui::GLGuiText* text = new OrxGui::GLGuiText(); | 
|---|
 | 175 |         text->setText("Server Mode: not able to play at this node"); | 
|---|
 | 176 |         box->pack( text); | 
|---|
 | 177 |       } | 
|---|
| [8717] | 178 |  | 
|---|
| [9416] | 179 |  | 
|---|
| [8623] | 180 |       if ( bShowTeamChange ) | 
|---|
 | 181 |       { | 
|---|
 | 182 |         OrxGui::GLGuiPushButton * buttonCancel = new OrxGui::GLGuiPushButton("Cancel"); | 
|---|
 | 183 |         box->pack( buttonCancel ); | 
|---|
| [9406] | 184 |         buttonCancel->released.connect(this, &MultiplayerTeamDeathmatch::onButtonCancel); | 
|---|
| [8623] | 185 |       } | 
|---|
| [8717] | 186 |  | 
|---|
| [8147] | 187 |       OrxGui::GLGuiPushButton * buttonExit = new OrxGui::GLGuiPushButton("Exit"); | 
|---|
 | 188 |       box->pack( buttonExit ); | 
|---|
| [9406] | 189 |       buttonExit->released.connect(this, &MultiplayerTeamDeathmatch::onButtonExit); | 
|---|
| [8717] | 190 |  | 
|---|
| [8147] | 191 |       box->showAll(); | 
|---|
 | 192 |     } | 
|---|
 | 193 |   } | 
|---|
 | 194 |  | 
|---|
 | 195 |   if ( box != NULL | 
|---|
 | 196 |        && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) | 
|---|
| [8717] | 197 |        && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM | 
|---|
| [8623] | 198 |        && !bShowTeamChange | 
|---|
| [8147] | 199 |      ) | 
|---|
 | 200 |   { | 
|---|
 | 201 |     delete box; | 
|---|
 | 202 |     box = NULL; | 
|---|
| [8717] | 203 |  | 
|---|
| [8147] | 204 |     OrxGui::GLGuiHandler::getInstance()->deactivateCursor( true ); | 
|---|
| [8717] | 205 |  | 
|---|
| [8147] | 206 |     EventHandler::getInstance()->popState(); | 
|---|
 | 207 |   } | 
|---|
| [8717] | 208 |  | 
|---|
| [8147] | 209 |   if ( box != NULL ) | 
|---|
 | 210 |   { | 
|---|
 | 211 |     OrxGui::GLGuiHandler::getInstance()->tick( dt ); | 
|---|
 | 212 |   } | 
|---|
| [8717] | 213 |  | 
|---|
| [8147] | 214 |   assignPlayable(); | 
|---|
| [8717] | 215 |  | 
|---|
| [9470] | 216 |   if ( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive()) | 
|---|
| [8068] | 217 |     return; | 
|---|
| [9008] | 218 |  | 
|---|
| [8802] | 219 |   //handle kills | 
|---|
| [9008] | 220 |   while ( this->killList.begin() != this->killList.end() ) | 
|---|
| [8802] | 221 |   { | 
|---|
| [9235] | 222 |     PRINTF(0)("KKKKKKKKIIIIIIIIILLLLLLLLLLLLL\n"); | 
|---|
| [9008] | 223 |     onKill( this->killList.begin()->getVictim(), this->killList.begin()->getKiller() ); | 
|---|
 | 224 |     this->killList.erase( this->killList.begin() ); | 
|---|
| [8802] | 225 |   } | 
|---|
| [9008] | 226 |  | 
|---|
 | 227 |  | 
|---|
| [9406] | 228 |  | 
|---|
| [8068] | 229 |   gameStateTimer -= dt; | 
|---|
| [8147] | 230 |   //PRINTF(0)("TICK %f\n", gameStateTimer); | 
|---|
| [8717] | 231 |  | 
|---|
| [8068] | 232 |   if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 ) | 
|---|
 | 233 |     nextGameState(); | 
|---|
| [8717] | 234 |  | 
|---|
| [8068] | 235 |   this->currentGameState = NetworkGameManager::getInstance()->getGameState(); | 
|---|
| [8717] | 236 |  | 
|---|
| [8068] | 237 |   if ( currentGameState == GAMESTATE_GAME ) | 
|---|
 | 238 |   { | 
|---|
 | 239 |     handleTeamChanges(); | 
|---|
 | 240 |   } | 
|---|
| [8717] | 241 |  | 
|---|
| [8068] | 242 |   this->calculateTeamScore(); | 
|---|
| [8717] | 243 |  | 
|---|
| [7039] | 244 |   this->checkGameRules(); | 
|---|
| [7035] | 245 |  | 
|---|
| [7039] | 246 |   // is the local player dead and inactive | 
|---|
 | 247 |   if( unlikely(this->bLocalPlayerDead)) | 
|---|
 | 248 |   { | 
|---|
 | 249 |     this->timeout += dt; | 
|---|
| [7088] | 250 |     PRINTF(0)("TICK DEATH: %f of %f\n", this->timeout, this->deathTimeout); | 
|---|
| [7039] | 251 |     // long enough dead? | 
|---|
| [7044] | 252 |     if( this->timeout >= this->deathTimeout) | 
|---|
| [7039] | 253 |     { | 
|---|
 | 254 |       this->timeout = 0.0f; | 
|---|
 | 255 |       // respawn | 
|---|
| [7079] | 256 |       PRINTF(0)("RESPAWN\n"); | 
|---|
| [7044] | 257 |       (State::getPlayer())->getPlayable()->respawn(); | 
|---|
| [7039] | 258 |     } | 
|---|
 | 259 |   } | 
|---|
| [7037] | 260 | } | 
|---|
| [7035] | 261 |  | 
|---|
| [7037] | 262 |  | 
|---|
| [7035] | 263 | /** | 
|---|
 | 264 |  * draws the stuff | 
|---|
 | 265 |  */ | 
|---|
 | 266 | void MultiplayerTeamDeathmatch::draw() | 
|---|
| [7039] | 267 | { | 
|---|
 | 268 |   if( unlikely( this->bLocalPlayerDead)) | 
|---|
 | 269 |   { | 
|---|
| [7035] | 270 |  | 
|---|
| [7039] | 271 |   } | 
|---|
 | 272 | } | 
|---|
| [7035] | 273 |  | 
|---|
| [7039] | 274 |  | 
|---|
| [7035] | 275 | /** | 
|---|
 | 276 |  * check the game rules for consistency | 
|---|
 | 277 |  */ | 
|---|
 | 278 | void MultiplayerTeamDeathmatch::checkGameRules() | 
|---|
| [7039] | 279 | { | 
|---|
| [9470] | 280 |   if ( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive()) | 
|---|
| [8068] | 281 |     return; | 
|---|
| [8717] | 282 |  | 
|---|
| [8068] | 283 |   // check for max killing count | 
|---|
 | 284 |   for ( int i = 0; i<numTeams; i++ ) | 
|---|
 | 285 |   { | 
|---|
 | 286 |     if ( teamScore[i] >= maxKills ) | 
|---|
 | 287 |     { | 
|---|
| [8802] | 288 |       nextGameState(); | 
|---|
| [8068] | 289 |     } | 
|---|
 | 290 |   } | 
|---|
 | 291 | } | 
|---|
| [7101] | 292 |  | 
|---|
| [8068] | 293 | /** | 
|---|
 | 294 |  * find group for new player | 
|---|
 | 295 |  * @return group id | 
|---|
 | 296 |  */ | 
|---|
| [8147] | 297 | int MultiplayerTeamDeathmatch::getTeamForNewUser() | 
|---|
| [8068] | 298 | { | 
|---|
 | 299 |   return TEAM_NOTEAM; | 
|---|
 | 300 | } | 
|---|
| [7101] | 301 |  | 
|---|
| [8147] | 302 | ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int userId, int team ) | 
|---|
| [8068] | 303 | { | 
|---|
| [8147] | 304 |   if ( team == TEAM_NOTEAM || team == TEAM_SPECTATOR ) | 
|---|
 | 305 |     return CL_SPECTATOR; | 
|---|
| [8717] | 306 |  | 
|---|
| [8147] | 307 |   if ( team == 0 || team == 1 ) | 
|---|
| [9455] | 308 |     return CL_TURBINE_HOVER; | 
|---|
| [8717] | 309 |  | 
|---|
| [8147] | 310 |   assert( false ); | 
|---|
| [8068] | 311 | } | 
|---|
| [7101] | 312 |  | 
|---|
| [8147] | 313 | std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int userId, int team, ClassID classId ) | 
|---|
| [8068] | 314 | { | 
|---|
| [9455] | 315 |   if (classId == CL_TURBINE_HOVER) | 
|---|
 | 316 |    return "models/ships/hoverglider_mainbody.obj"; | 
|---|
| [8147] | 317 |   if ( team == 0 ) | 
|---|
| [9059] | 318 |     return "models/creatures/doom_guy.md2"; | 
|---|
| [8147] | 319 |   else if ( team == 1 ) | 
|---|
| [9235] | 320 |     return "models/creatures/male.md2"; | 
|---|
| [8147] | 321 |   else | 
|---|
 | 322 |     return ""; | 
|---|
| [8068] | 323 | } | 
|---|
 | 324 |  | 
|---|
| [9235] | 325 | std::string MultiplayerTeamDeathmatch::getPlayableModelTextureFileName( int userId, int team, ClassID classId ) | 
|---|
 | 326 | { | 
|---|
 | 327 |   if ( classId == CL_FPS_PLAYER ) | 
|---|
 | 328 |   { | 
|---|
 | 329 |     if ( team == 0 ) | 
|---|
 | 330 |       return "maps/doom_guy.png"; | 
|---|
 | 331 |     else | 
|---|
 | 332 |       return "maps/male_fiend.pcx"; | 
|---|
 | 333 |   } | 
|---|
| [9406] | 334 |  | 
|---|
| [9235] | 335 |   return ""; | 
|---|
 | 336 | } | 
|---|
 | 337 |  | 
|---|
 | 338 | float MultiplayerTeamDeathmatch::getPlayableScale( int userId, int team, ClassID classId ) | 
|---|
 | 339 | { | 
|---|
 | 340 |   if ( classId == CL_FPS_PLAYER ) | 
|---|
 | 341 |   { | 
|---|
 | 342 |     return 10.0f; | 
|---|
 | 343 |   } | 
|---|
| [9406] | 344 |  | 
|---|
| [9235] | 345 |   return 1.0f; | 
|---|
 | 346 | } | 
|---|
 | 347 |  | 
|---|
| [8068] | 348 | /** | 
|---|
 | 349 |  * calculate team score | 
|---|
 | 350 |  */ | 
|---|
 | 351 | void MultiplayerTeamDeathmatch::calculateTeamScore( ) | 
|---|
 | 352 | { | 
|---|
 | 353 |   teamScore.clear(); | 
|---|
| [8717] | 354 |  | 
|---|
| [8068] | 355 |   for ( int i = 0; i<numTeams; i++ ) | 
|---|
 | 356 |     teamScore[i] = 0; | 
|---|
| [8717] | 357 |  | 
|---|
 | 358 |  | 
|---|
| [8068] | 359 |   const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); | 
|---|
| [8717] | 360 |  | 
|---|
| [8068] | 361 |   if ( !list ) | 
|---|
 | 362 |     return; | 
|---|
| [8717] | 363 |  | 
|---|
| [8068] | 364 |   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) | 
|---|
| [7039] | 365 |   { | 
|---|
| [8068] | 366 |     PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); | 
|---|
 | 367 |  | 
|---|
 | 368 |     if ( stats.getTeamId() >= 0 ) | 
|---|
 | 369 |     { | 
|---|
 | 370 |       teamScore[stats.getTeamId()] += stats.getScore(); | 
|---|
 | 371 |     } | 
|---|
| [7039] | 372 |   } | 
|---|
| [8068] | 373 | } | 
|---|
 | 374 |  | 
|---|
 | 375 | /** | 
|---|
 | 376 |  * get team for player who choose to join random team | 
|---|
 | 377 |  * @return smallest team | 
|---|
 | 378 |  */ | 
|---|
 | 379 | int MultiplayerTeamDeathmatch::getRandomTeam( ) | 
|---|
 | 380 | { | 
|---|
 | 381 |   std::map<int,int> playersInTeam; | 
|---|
| [8717] | 382 |  | 
|---|
| [8068] | 383 |   for ( int i = 0; i<numTeams; i++ ) | 
|---|
 | 384 |     playersInTeam[i] = 0; | 
|---|
| [8717] | 385 |  | 
|---|
| [8068] | 386 |   const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); | 
|---|
| [8717] | 387 |  | 
|---|
| [8068] | 388 |   if ( !list ) | 
|---|
 | 389 |     return 0; | 
|---|
| [8717] | 390 |  | 
|---|
| [8068] | 391 |   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) | 
|---|
| [7039] | 392 |   { | 
|---|
| [8068] | 393 |     PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); | 
|---|
 | 394 |  | 
|---|
 | 395 |     if ( stats.getTeamId() >= 0 ) | 
|---|
 | 396 |     { | 
|---|
 | 397 |       playersInTeam[stats.getTeamId()]++; | 
|---|
 | 398 |     } | 
|---|
| [7039] | 399 |   } | 
|---|
| [8717] | 400 |  | 
|---|
 | 401 |  | 
|---|
| [8068] | 402 |   int minPlayers = 0xFFFF; | 
|---|
 | 403 |   int minTeam = -1; | 
|---|
| [8717] | 404 |  | 
|---|
| [8068] | 405 |   for ( int i = 0; i<numTeams; i++ ) | 
|---|
 | 406 |   { | 
|---|
 | 407 |     if ( playersInTeam[i] < minPlayers ) | 
|---|
 | 408 |     { | 
|---|
 | 409 |       minTeam = i; | 
|---|
 | 410 |       minPlayers = playersInTeam[i]; | 
|---|
 | 411 |     } | 
|---|
 | 412 |   } | 
|---|
| [8717] | 413 |  | 
|---|
| [8068] | 414 |   assert( minTeam != -1 ); | 
|---|
| [8717] | 415 |  | 
|---|
| [8068] | 416 |   return minTeam; | 
|---|
 | 417 | } | 
|---|
| [7101] | 418 |  | 
|---|
| [8068] | 419 | void MultiplayerTeamDeathmatch::nextGameState( ) | 
|---|
 | 420 | { | 
|---|
 | 421 |   if ( currentGameState == GAMESTATE_PRE_GAME ) | 
|---|
 | 422 |   { | 
|---|
 | 423 |     NetworkGameManager::getInstance()->setGameState( GAMESTATE_GAME ); | 
|---|
| [8717] | 424 |  | 
|---|
| [8068] | 425 |     return; | 
|---|
 | 426 |   } | 
|---|
| [8717] | 427 |  | 
|---|
| [8068] | 428 |   if ( currentGameState == GAMESTATE_GAME ) | 
|---|
 | 429 |   { | 
|---|
 | 430 |     NetworkGameManager::getInstance()->setGameState( GAMESTATE_POST_GAME ); | 
|---|
| [8717] | 431 |  | 
|---|
| [8068] | 432 |     return; | 
|---|
 | 433 |   } | 
|---|
| [8717] | 434 |  | 
|---|
| [8068] | 435 |   if ( currentGameState == GAMESTATE_POST_GAME ) | 
|---|
 | 436 |   { | 
|---|
| [9235] | 437 |     //State::getCurrentStoryEntity()->stop(); | 
|---|
| [8802] | 438 |     this->bShowTeamChange = false; | 
|---|
| [8717] | 439 |  | 
|---|
| [8068] | 440 |     return; | 
|---|
 | 441 |   } | 
|---|
 | 442 | } | 
|---|
| [7118] | 443 |  | 
|---|
| [8068] | 444 | void MultiplayerTeamDeathmatch::handleTeamChanges( ) | 
|---|
 | 445 | { | 
|---|
 | 446 |   const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); | 
|---|
| [8717] | 447 |  | 
|---|
| [8068] | 448 |   if ( !list ) | 
|---|
 | 449 |     return; | 
|---|
| [8717] | 450 |  | 
|---|
| [8068] | 451 |   //first server players with choices | 
|---|
 | 452 |   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) | 
|---|
| [7116] | 453 |   { | 
|---|
| [8068] | 454 |     PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); | 
|---|
| [7118] | 455 |  | 
|---|
| [8068] | 456 |     if ( stats.getTeamId() != stats.getPreferedTeamId() ) | 
|---|
| [7116] | 457 |     { | 
|---|
| [8147] | 458 |       if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() >= 0 && stats.getPreferedTeamId() < numTeams ) ) | 
|---|
| [7116] | 459 |       { | 
|---|
| [8068] | 460 |         teamChange( stats.getUserId() ); | 
|---|
| [7116] | 461 |       } | 
|---|
 | 462 |     } | 
|---|
 | 463 |   } | 
|---|
| [8717] | 464 |  | 
|---|
| [8068] | 465 |   //now serve player who want join a random team | 
|---|
 | 466 |   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) | 
|---|
 | 467 |   { | 
|---|
 | 468 |     PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); | 
|---|
| [7101] | 469 |  | 
|---|
| [8068] | 470 |     if ( stats.getTeamId() != stats.getPreferedTeamId() ) | 
|---|
| [7101] | 471 |     { | 
|---|
| [8068] | 472 |       if ( stats.getPreferedTeamId() == TEAM_RANDOM ) | 
|---|
| [7101] | 473 |       { | 
|---|
| [8147] | 474 |         stats.setPreferedTeamId( getRandomTeam() ); | 
|---|
| [8068] | 475 |         teamChange( stats.getUserId() ); | 
|---|
| [7101] | 476 |       } | 
|---|
 | 477 |     } | 
|---|
 | 478 |   } | 
|---|
| [8068] | 479 | } | 
|---|
| [7101] | 480 |  | 
|---|
| [8068] | 481 | void MultiplayerTeamDeathmatch::teamChange( int userId ) | 
|---|
 | 482 | { | 
|---|
 | 483 |   assert( PlayerStats::getStats( userId ) ); | 
|---|
 | 484 |   PlayerStats & stats = *(PlayerStats::getStats( userId )); | 
|---|
| [8717] | 485 |  | 
|---|
| [8147] | 486 |   stats.setTeamId( stats.getPreferedTeamId() ); | 
|---|
| [8717] | 487 |  | 
|---|
| [8147] | 488 |   Playable * oldPlayable = stats.getPlayable(); | 
|---|
| [8717] | 489 |  | 
|---|
 | 490 |  | 
|---|
| [8147] | 491 |   ClassID playableClassId = getPlayableClassId( userId, stats.getPreferedTeamId() ); | 
|---|
 | 492 |   std::string playableModel = getPlayableModelFileName( userId, stats.getPreferedTeamId(), playableClassId ); | 
|---|
| [9110] | 493 |   std::string playableTexture = getPlayableModelTextureFileName( userId, stats.getPreferedTeamId(), playableClassId ); | 
|---|
| [9235] | 494 |   float       playableScale = getPlayableScale( userId, stats.getPreferedTeamId(), playableClassId ); | 
|---|
| [8717] | 495 |  | 
|---|
| [8147] | 496 |   BaseObject * bo = Factory::fabricate( playableClassId ); | 
|---|
| [8717] | 497 |  | 
|---|
| [8147] | 498 |   assert( bo != NULL ); | 
|---|
 | 499 |   assert( bo->isA( CL_PLAYABLE ) ); | 
|---|
| [8717] | 500 |  | 
|---|
| [8147] | 501 |   Playable & playable = *(dynamic_cast<Playable*>(bo)); | 
|---|
| [8717] | 502 |  | 
|---|
| [9235] | 503 |   playable.loadMD2Texture( playableTexture ); | 
|---|
 | 504 |   playable.loadModel( playableModel, playableScale ); | 
|---|
| [8147] | 505 |   playable.setOwner( userId ); | 
|---|
 | 506 |   playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); | 
|---|
 | 507 |   playable.setSynchronized( true ); | 
|---|
| [8717] | 508 |  | 
|---|
| [8147] | 509 |   stats.setTeamId( stats.getPreferedTeamId() ); | 
|---|
 | 510 |   stats.setPlayableClassId( playableClassId ); | 
|---|
 | 511 |   stats.setPlayableUniqueId( playable.getUniqueID() ); | 
|---|
 | 512 |   stats.setModelFileName( playableModel ); | 
|---|
| [8717] | 513 |  | 
|---|
| [9008] | 514 |   this->respawnPlayable( &playable, stats.getPreferedTeamId(), 0.0f ); | 
|---|
 | 515 |  | 
|---|
| [8147] | 516 |   if ( oldPlayable ) | 
|---|
 | 517 |   { | 
|---|
 | 518 |     //if ( userId == SharedNetworkData::getInstance()->getHostID() ) | 
|---|
 | 519 |     //  State::getPlayer()->setPlayable( NULL ); | 
|---|
 | 520 |     delete oldPlayable; | 
|---|
 | 521 |   } | 
|---|
| [7039] | 522 | } | 
|---|
| [7035] | 523 |  | 
|---|
| [8147] | 524 | void MultiplayerTeamDeathmatch::onButtonExit( ) | 
|---|
 | 525 | { | 
|---|
 | 526 |   State::getCurrentStoryEntity()->stop(); | 
|---|
| [8623] | 527 |   this->bShowTeamChange = false; | 
|---|
| [8147] | 528 | } | 
|---|
| [7035] | 529 |  | 
|---|
| [8147] | 530 | void MultiplayerTeamDeathmatch::onButtonRandom( ) | 
|---|
 | 531 | { | 
|---|
 | 532 |   NetworkGameManager::getInstance()->prefereTeam( TEAM_RANDOM ); | 
|---|
| [8623] | 533 |   this->bShowTeamChange = false; | 
|---|
| [8147] | 534 | } | 
|---|
| [7035] | 535 |  | 
|---|
| [8147] | 536 | void MultiplayerTeamDeathmatch::onButtonTeam0( ) | 
|---|
 | 537 | { | 
|---|
 | 538 |   NetworkGameManager::getInstance()->prefereTeam( 0 ); | 
|---|
| [8623] | 539 |   this->bShowTeamChange = false; | 
|---|
| [8147] | 540 | } | 
|---|
| [7035] | 541 |  | 
|---|
| [8147] | 542 | void MultiplayerTeamDeathmatch::onButtonTeam1( ) | 
|---|
 | 543 | { | 
|---|
 | 544 |   NetworkGameManager::getInstance()->prefereTeam( 1 ); | 
|---|
| [8623] | 545 |   this->bShowTeamChange = false; | 
|---|
| [8147] | 546 | } | 
|---|
| [7035] | 547 |  | 
|---|
| [8147] | 548 | void MultiplayerTeamDeathmatch::onButtonSpectator( ) | 
|---|
 | 549 | { | 
|---|
 | 550 |   NetworkGameManager::getInstance()->prefereTeam( TEAM_SPECTATOR ); | 
|---|
| [8623] | 551 |   this->bShowTeamChange = false; | 
|---|
| [8147] | 552 | } | 
|---|
| [7035] | 553 |  | 
|---|
| [8147] | 554 | void MultiplayerTeamDeathmatch::assignPlayable( ) | 
|---|
 | 555 | { | 
|---|
 | 556 |   if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) ) | 
|---|
 | 557 |     PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPlayable(); | 
|---|
 | 558 | } | 
|---|
 | 559 |  | 
|---|
| [8623] | 560 |   /** | 
|---|
 | 561 |    * function that processes events from the handler | 
|---|
 | 562 |    * @param event: the event | 
|---|
 | 563 |    * @todo replace SDLK_o with something from KeyMapper | 
|---|
 | 564 |    */ | 
|---|
 | 565 | void MultiplayerTeamDeathmatch::process( const Event & event ) | 
|---|
 | 566 | { | 
|---|
 | 567 |   if ( event.type == SDLK_o ) | 
|---|
 | 568 |   { | 
|---|
 | 569 |     if ( event.bPressed ) | 
|---|
 | 570 |       this->bShowTeamChange = true; | 
|---|
| [8802] | 571 |   } else if ( event.type == SDLK_F1 ) | 
|---|
 | 572 |   { | 
|---|
| [9059] | 573 |     if ( this->statsBox && !this->bLocalPlayerDead && event.bPressed ) | 
|---|
 | 574 |     { | 
|---|
 | 575 |       PRINTF(0)("hide stats\n"); | 
|---|
 | 576 |       this->hideStats(); | 
|---|
 | 577 |     } | 
|---|
| [9110] | 578 |     else if ( !this->statsBox && event.bPressed ) | 
|---|
| [8802] | 579 |     { | 
|---|
 | 580 |       PRINTF(0)("show stats\n"); | 
|---|
 | 581 |       this->showStats(); | 
|---|
 | 582 |     } | 
|---|
| [8623] | 583 |   } | 
|---|
| [8708] | 584 |   else if ( event.type == SDLK_TAB ) | 
|---|
 | 585 |   { | 
|---|
| [9008] | 586 |     if ( currentGameState == GAMESTATE_GAME && event.bPressed && !EventHandler::getInstance()->isPressed( SDLK_RALT ) && !EventHandler::getInstance()->isPressed( SDLK_LALT ) ) | 
|---|
| [8708] | 587 |     { | 
|---|
 | 588 |       EventHandler::getInstance()->pushState( ES_MENU ); | 
|---|
 | 589 |       OrxGui::GLGuiHandler::getInstance()->activateCursor(); | 
|---|
 | 590 |       OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); | 
|---|
 | 591 |       input->show(); | 
|---|
| [8717] | 592 |       input->giveMouseFocus(); | 
|---|
| [8708] | 593 |       input->setText("say "); | 
|---|
 | 594 |     } | 
|---|
 | 595 |   } | 
|---|
| [8802] | 596 |   else if ( this->bLocalPlayerDead && statsBox && event.type == KeyMapper::PEV_FIRE1 ) | 
|---|
 | 597 |   { | 
|---|
 | 598 |     this->hideStats(); | 
|---|
 | 599 |   } | 
|---|
| [8623] | 600 | } | 
|---|
| [8147] | 601 |  | 
|---|
| [8623] | 602 | void MultiplayerTeamDeathmatch::onButtonCancel( ) | 
|---|
 | 603 | { | 
|---|
 | 604 |   this->bShowTeamChange = false; | 
|---|
 | 605 | } | 
|---|
| [8147] | 606 |  | 
|---|
 | 607 |  | 
|---|
 | 608 |  | 
|---|
| [8623] | 609 | /** | 
|---|
 | 610 |  * this method is called by NetworkGameManger when he recieved a chat message | 
|---|
 | 611 |  * @param userId senders user id | 
|---|
 | 612 |  * @param message message string | 
|---|
 | 613 |  * @param messageType some int | 
|---|
 | 614 |  */ | 
|---|
 | 615 | void MultiplayerTeamDeathmatch::handleChatMessage( int userId, const std::string & message, int messageType ) | 
|---|
 | 616 | { | 
|---|
 | 617 |   std::string name = "unknown"; | 
|---|
| [8717] | 618 |  | 
|---|
| [8623] | 619 |   if ( PlayerStats::getStats( userId ) ) | 
|---|
 | 620 |   { | 
|---|
 | 621 |     name = PlayerStats::getStats( userId )->getNickName(); | 
|---|
 | 622 |   } | 
|---|
| [8717] | 623 |  | 
|---|
| [8708] | 624 |   PRINTF(0)("CHATMESSAGE %s (%d): %s\n", name.c_str(), userId, message.c_str() ); | 
|---|
| [9059] | 625 |   State::getPlayer()->hud().notifyUser(name + ": " + message); | 
|---|
| [8623] | 626 | } | 
|---|
| [8147] | 627 |  | 
|---|
| [8708] | 628 | void MultiplayerTeamDeathmatch::onInputEnter( const std::string & text ) | 
|---|
 | 629 | { | 
|---|
 | 630 |   EventHandler::getInstance()->popState(); | 
|---|
| [8717] | 631 |   input->breakMouseFocus(); | 
|---|
| [8708] | 632 |   input->hide(); | 
|---|
 | 633 |   input->setText(""); | 
|---|
| [8623] | 634 |  | 
|---|
| [8708] | 635 |   std::string command = text; | 
|---|
| [8717] | 636 |  | 
|---|
| [8708] | 637 |   //HACK insert " in say commands so user doesn't have to type them | 
|---|
 | 638 |   if ( command.length() >= 4 && command[0] == 's' && command[1] == 'a' && command[2] == 'y' && command[3] == ' ' ) | 
|---|
 | 639 |   { | 
|---|
 | 640 |     command.insert( 4, "\"" ); | 
|---|
 | 641 |     command = command + "\""; | 
|---|
 | 642 |   } | 
|---|
| [8623] | 643 |  | 
|---|
| [8708] | 644 |   OrxShell::ShellCommand::execute( command ); | 
|---|
 | 645 | } | 
|---|
| [8623] | 646 |  | 
|---|
| [8802] | 647 | /** | 
|---|
 | 648 |  * show table with frags | 
|---|
 | 649 |  */ | 
|---|
 | 650 | void MultiplayerTeamDeathmatch::showStats( ) | 
|---|
 | 651 | { | 
|---|
 | 652 |   statsBox = new OrxGui::GLGuiBox(); | 
|---|
| [9110] | 653 |   statsBox->setAbsCoor2D( 100, 100 ); | 
|---|
| [9008] | 654 |  | 
|---|
| [9110] | 655 |   this->table = new OrxGui::GLGuiTable(10,5); | 
|---|
| [8708] | 656 |  | 
|---|
| [8802] | 657 |   statsBox->pack( this->table ); | 
|---|
| [8708] | 658 |  | 
|---|
| [8802] | 659 |   statsBox->showAll(); | 
|---|
 | 660 | } | 
|---|
| [8708] | 661 |  | 
|---|
| [8802] | 662 | /** | 
|---|
 | 663 |  * hide table with frags | 
|---|
 | 664 |  */ | 
|---|
 | 665 | void MultiplayerTeamDeathmatch::hideStats( ) | 
|---|
 | 666 | { | 
|---|
 | 667 |     if ( statsBox ) | 
|---|
 | 668 |     { | 
|---|
 | 669 |       delete statsBox; | 
|---|
 | 670 |       statsBox = NULL; | 
|---|
 | 671 |     } | 
|---|
 | 672 | } | 
|---|
 | 673 |  | 
|---|
 | 674 | /** | 
|---|
 | 675 |  * fill stats table with values | 
|---|
 | 676 |  */ | 
|---|
 | 677 | void MultiplayerTeamDeathmatch::tickStatsTable( ) | 
|---|
 | 678 | { | 
|---|
 | 679 |   if ( !this->statsBox ) | 
|---|
 | 680 |     return; | 
|---|
 | 681 |  | 
|---|
 | 682 |   std::vector<std::string> headers; | 
|---|
| [9110] | 683 |   headers.push_back("Blue Team"); | 
|---|
| [8802] | 684 |   headers.push_back(""); | 
|---|
 | 685 |   headers.push_back(""); | 
|---|
| [9110] | 686 |   headers.push_back("Red Team"); | 
|---|
| [8802] | 687 |   headers.push_back(""); | 
|---|
 | 688 |   this->table->setHeader(headers); | 
|---|
| [9008] | 689 |  | 
|---|
| [9110] | 690 |   ScoreList scoreList = PlayerStats::getScoreList(); | 
|---|
| [9008] | 691 |  | 
|---|
| [8802] | 692 |   char st[10]; | 
|---|
 | 693 |   int i = 0; | 
|---|
| [9406] | 694 |  | 
|---|
| [8802] | 695 |   i = 2; | 
|---|
| [9110] | 696 |   for ( TeamScoreList::const_iterator it = scoreList[0].begin(); it != scoreList[0].end(); it++ ) | 
|---|
| [8802] | 697 |   { | 
|---|
| [9110] | 698 |     this->table->setEntry( i, 0, it->name ); | 
|---|
 | 699 |     snprintf( st, 10, "%d", it->score ); | 
|---|
 | 700 |     this->table->setEntry( i, 1, st ); | 
|---|
 | 701 |     this->table->setEntry( i, 2, "" ); | 
|---|
| [8802] | 702 |     i++; | 
|---|
 | 703 |   } | 
|---|
| [9008] | 704 |  | 
|---|
| [8802] | 705 |   i = 2; | 
|---|
| [9110] | 706 |   for ( TeamScoreList::const_iterator it = scoreList[1].begin(); it != scoreList[1].end(); it++ ) | 
|---|
| [8802] | 707 |   { | 
|---|
| [9110] | 708 |     this->table->setEntry( i, 3, it->name ); | 
|---|
 | 709 |     snprintf( st, 10, "%d", it->score ); | 
|---|
 | 710 |     this->table->setEntry( i, 4, st ); | 
|---|
| [8802] | 711 |     i++; | 
|---|
 | 712 |   } | 
|---|
| [9110] | 713 |  | 
|---|
| [8802] | 714 | } | 
|---|
 | 715 |  | 
|---|
 | 716 | /** | 
|---|
 | 717 |  * this function is called when a player kills another one or himself | 
|---|
| [9008] | 718 |  * @param killedUserId | 
|---|
 | 719 |  * @param userId | 
|---|
| [8802] | 720 |  */ | 
|---|
| [9008] | 721 | void MultiplayerTeamDeathmatch::onKill( WorldEntity * victim, WorldEntity * killer ) | 
|---|
| [8802] | 722 | { | 
|---|
| [9008] | 723 |   if ( !victim ) | 
|---|
| [9235] | 724 |   { | 
|---|
 | 725 |     PRINTF(0)("victim == NULL\n"); | 
|---|
| [9008] | 726 |     return; | 
|---|
| [9235] | 727 |   } | 
|---|
| [9008] | 728 |   if ( !killer ) | 
|---|
| [9235] | 729 |   { | 
|---|
 | 730 |     PRINTF(0)("killer == NULL\n"); | 
|---|
| [9008] | 731 |     return; | 
|---|
| [9235] | 732 |   } | 
|---|
| [9406] | 733 |  | 
|---|
| [9008] | 734 |   int killerUserId = killer->getOwner(); | 
|---|
 | 735 |   int victimUserId = victim->getOwner(); | 
|---|
 | 736 |  | 
|---|
| [9406] | 737 |   PRINTF(0)("%d %d %x %x %s %s\n", killerUserId, victimUserId, killer, victim, killer->getClassCName(), victim->getClassCName()); | 
|---|
 | 738 |  | 
|---|
| [9008] | 739 |   PlayerStats & victimStats = *PlayerStats::getStats( victimUserId ); | 
|---|
 | 740 |   PlayerStats & killerStats = *PlayerStats::getStats( killerUserId ); | 
|---|
| [9406] | 741 |  | 
|---|
| [9008] | 742 |   if ( killerStats.getPlayable() != killer || victimStats.getPlayable() != victim ) | 
|---|
| [9235] | 743 |   { | 
|---|
 | 744 |     PRINTF(0)("killerStats.getPlayable() != killer || victimStats.getPlayable() != victim\n"); | 
|---|
 | 745 |     PRINTF(0)("%x %x %x %x\n", killerStats.getPlayable(), killer, victimStats.getPlayable(), victim ); | 
|---|
 | 746 |     PRINTF(0)("%d %d %d %d\n", killerStats.getPlayable()->getUniqueID(), killer->getUniqueID(), victimStats.getPlayable()->getUniqueID(), victim->getUniqueID() ); | 
|---|
| [9008] | 747 |     return; | 
|---|
| [9235] | 748 |   } | 
|---|
| [9008] | 749 |  | 
|---|
 | 750 |   //check for suicide | 
|---|
 | 751 |   if ( killerUserId != victimUserId ) | 
|---|
 | 752 |   { | 
|---|
 | 753 |     //check for teamkill | 
|---|
 | 754 |     if ( victimStats.getTeamId() != killerStats.getTeamId() ) | 
|---|
 | 755 |     { | 
|---|
 | 756 |       killerStats.setScore( killerStats.getScore() + 1 ); | 
|---|
 | 757 |     } | 
|---|
 | 758 |     else | 
|---|
 | 759 |     { | 
|---|
 | 760 |       killerStats.setScore( killerStats.getScore() - 1 ); | 
|---|
 | 761 |     } | 
|---|
 | 762 |   } | 
|---|
| [8802] | 763 |   else | 
|---|
| [9008] | 764 |     killerStats.setScore( killerStats.getScore() - 1 ); | 
|---|
 | 765 |  | 
|---|
 | 766 |   if ( victimUserId == SharedNetworkData::getInstance()->getHostID() ) | 
|---|
| [8802] | 767 |   { | 
|---|
 | 768 |     this->bLocalPlayerDead = true; | 
|---|
 | 769 |     this->showStats(); | 
|---|
 | 770 |   } | 
|---|
| [9008] | 771 |  | 
|---|
 | 772 |   this->respawnPlayable( victimStats.getPlayable(), victimStats.getTeamId(), 3.0f ); | 
|---|
| [8802] | 773 | } | 
|---|
 | 774 |  | 
|---|
 | 775 | /** | 
|---|
 | 776 |  * this function is called on player respawn | 
|---|
| [9008] | 777 |  * @param userId | 
|---|
| [8802] | 778 |  */ | 
|---|
 | 779 | void MultiplayerTeamDeathmatch::onRespawn( int userId ) | 
|---|
 | 780 | { | 
|---|
 | 781 |   if ( userId == SharedNetworkData::getInstance()->getHostID() ) | 
|---|
 | 782 |   { | 
|---|
 | 783 |     this->bLocalPlayerDead = false; | 
|---|
 | 784 |     this->hideStats(); | 
|---|
 | 785 |   } | 
|---|
 | 786 | } | 
|---|
 | 787 |  | 
|---|
 | 788 | /** | 
|---|
 | 789 |  * this function is called on player respawn | 
|---|
| [9008] | 790 |  * @param we | 
|---|
| [8802] | 791 |  */ | 
|---|
 | 792 | void MultiplayerTeamDeathmatch::registerSpawn( WorldEntity * we ) | 
|---|
 | 793 | { | 
|---|
 | 794 |   onRespawn( we->getOwner() ); | 
|---|
 | 795 | } | 
|---|
 | 796 |  | 
|---|
| [9008] | 797 |  | 
|---|
 | 798 | void MultiplayerTeamDeathmatch::respawnPlayable( Playable * playable, int teamId, float delay ) | 
|---|
 | 799 | { | 
|---|
 | 800 |   const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT ); | 
|---|
 | 801 |  | 
|---|
 | 802 |   assert( list ); | 
|---|
 | 803 |  | 
|---|
 | 804 |   std::vector<SpawningPoint*> spList; | 
|---|
 | 805 |  | 
|---|
 | 806 |   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) | 
|---|
 | 807 |   { | 
|---|
 | 808 |     SpawningPoint * sp = dynamic_cast<SpawningPoint*>(*it); | 
|---|
 | 809 |  | 
|---|
 | 810 |     if ( sp->getTeamId() == teamId ) | 
|---|
 | 811 |       spList.push_back( sp ); | 
|---|
 | 812 |   } | 
|---|
 | 813 |  | 
|---|
 | 814 |   if ( spList.size() == 0 ) | 
|---|
 | 815 |   { | 
|---|
 | 816 |     for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) | 
|---|
 | 817 |     { | 
|---|
 | 818 |       SpawningPoint * sp = dynamic_cast<SpawningPoint*>(*it); | 
|---|
 | 819 |  | 
|---|
 | 820 |       if ( sp->getTeamId() < 0 ) | 
|---|
 | 821 |         spList.push_back( sp ); | 
|---|
 | 822 |     } | 
|---|
 | 823 |   } | 
|---|
 | 824 |  | 
|---|
 | 825 |   assert( spList.size() != 0 ); | 
|---|
 | 826 |  | 
|---|
 | 827 |   int n = (int)((float)spList.size() * (float)rand()/(float)RAND_MAX); | 
|---|
 | 828 |  | 
|---|
 | 829 |   spList[n]->pushEntity( playable, delay ); | 
|---|
 | 830 | } | 
|---|
 | 831 |  | 
|---|
| [9110] | 832 |  | 
|---|