Changeset 8717 in orxonox.OLD for trunk/src/util
- Timestamp:
- Jun 22, 2006, 2:04:28 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/multiplayer_team_deathmatch.cc
r8708 r8717 68 68 this->gameStateTimer = 10.0f; 69 69 this->bShowTeamChange = false; 70 70 71 71 this->box = NULL; 72 72 … … 80 80 if( root != NULL) 81 81 this->loadParams(root); 82 82 83 83 subscribeEvent( ES_GAME, SDLK_o ); 84 84 subscribeEvent( ES_GAME, SDLK_TAB ); 85 85 86 86 this->notifier = new OrxGui::GLGuiNotifier(); 87 87 this->notifier->show(); … … 101 101 if( this->deathScreen) 102 102 delete this->deathScreen; 103 103 104 104 unsubscribeEvent( ES_GAME, SDLK_o ); 105 105 unsubscribeEvent( ES_GAME, SDLK_TAB ); 106 106 107 107 if ( this->notifier ) 108 108 { … … 110 110 this->notifier = NULL; 111 111 } 112 112 113 113 if ( this->input ) 114 114 { … … 132 132 LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen) 133 133 .describe("sets the death screen image"); 134 134 135 135 LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams) 136 136 .describe("sets number of teams"); … … 179 179 if ( SharedNetworkData::getInstance()->getHostID() < 0 ) 180 180 return; 181 181 182 182 if ( currentGameState == GAMESTATE_PRE_GAME || currentGameState == GAMESTATE_GAME ) 183 183 { 184 184 if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) 185 185 && box == NULL 186 && (PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM 186 && (PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM 187 187 || bShowTeamChange ) 188 188 189 189 ) 190 190 { 191 191 EventHandler::getInstance()->pushState( ES_MENU ); 192 192 193 193 OrxGui::GLGuiHandler::getInstance()->activateCursor(); 194 194 195 195 box = new OrxGui::GLGuiBox(); 196 196 box->setAbsCoor2D( 300, 100 ); 197 197 198 198 OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator"); 199 199 box->pack( buttonSpectator ); 200 200 buttonSpectator->connect(SIGNAL(buttonSpectator, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonSpectator)); 201 201 202 202 OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random"); 203 203 box->pack( buttonRandom ); 204 204 buttonRandom->connect(SIGNAL(buttonRandom, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonRandom)); 205 205 206 206 OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team"); 207 207 box->pack( buttonTeam0 ); 208 208 buttonTeam0->connect(SIGNAL(buttonTeam0, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam0)); 209 209 210 210 OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team"); 211 211 box->pack( buttonTeam1 ); 212 212 buttonTeam1->connect(SIGNAL(buttonTeam1, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam1)); 213 213 214 214 if ( bShowTeamChange ) 215 215 { … … 218 218 buttonCancel->connect(SIGNAL(buttonCancel, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonCancel)); 219 219 } 220 220 221 221 OrxGui::GLGuiPushButton * buttonExit = new OrxGui::GLGuiPushButton("Exit"); 222 222 box->pack( buttonExit ); 223 223 buttonExit->connect(SIGNAL(buttonExit, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonExit)); 224 224 225 225 box->showAll(); 226 226 } … … 229 229 if ( box != NULL 230 230 && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) 231 && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM 231 && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM 232 232 && !bShowTeamChange 233 233 ) … … 235 235 delete box; 236 236 box = NULL; 237 237 238 238 OrxGui::GLGuiHandler::getInstance()->deactivateCursor( true ); 239 239 240 240 EventHandler::getInstance()->popState(); 241 241 } 242 242 243 243 if ( box != NULL ) 244 244 { 245 245 OrxGui::GLGuiHandler::getInstance()->tick( dt ); 246 246 } 247 247 248 248 assignPlayable(); 249 249 250 250 if ( !SharedNetworkData::getInstance()->isGameServer() ) 251 251 return; 252 252 253 253 gameStateTimer -= dt; 254 254 //PRINTF(0)("TICK %f\n", gameStateTimer); 255 255 256 256 if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 ) 257 257 nextGameState(); 258 258 259 259 this->currentGameState = NetworkGameManager::getInstance()->getGameState(); 260 260 261 261 if ( currentGameState == GAMESTATE_GAME ) 262 262 { 263 263 handleTeamChanges(); 264 264 } 265 265 266 266 this->calculateTeamScore(); 267 267 268 268 this->checkGameRules(); 269 269 … … 304 304 if ( !SharedNetworkData::getInstance()->isGameServer() ) 305 305 return; 306 306 307 307 // check for max killing count 308 308 for ( int i = 0; i<numTeams; i++ ) … … 329 329 if ( team == TEAM_NOTEAM || team == TEAM_SPECTATOR ) 330 330 return CL_SPECTATOR; 331 331 332 332 if ( team == 0 || team == 1 ) 333 333 return CL_SPACE_SHIP; 334 334 335 335 assert( false ); 336 336 } … … 352 352 { 353 353 teamScore.clear(); 354 354 355 355 for ( int i = 0; i<numTeams; i++ ) 356 356 teamScore[i] = 0; 357 358 357 358 359 359 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 360 360 361 361 if ( !list ) 362 362 return; 363 363 364 364 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 365 365 { … … 380 380 { 381 381 std::map<int,int> playersInTeam; 382 382 383 383 for ( int i = 0; i<numTeams; i++ ) 384 384 playersInTeam[i] = 0; 385 385 386 386 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 387 387 388 388 if ( !list ) 389 389 return 0; 390 390 391 391 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 392 392 { … … 398 398 } 399 399 } 400 401 400 401 402 402 int minPlayers = 0xFFFF; 403 403 int minTeam = -1; 404 404 405 405 for ( int i = 0; i<numTeams; i++ ) 406 406 { … … 411 411 } 412 412 } 413 413 414 414 assert( minTeam != -1 ); 415 415 416 416 return minTeam; 417 417 } … … 422 422 { 423 423 NetworkGameManager::getInstance()->setGameState( GAMESTATE_GAME ); 424 425 return; 426 } 427 424 425 return; 426 } 427 428 428 if ( currentGameState == GAMESTATE_GAME ) 429 429 { 430 430 NetworkGameManager::getInstance()->setGameState( GAMESTATE_POST_GAME ); 431 432 return; 433 } 434 431 432 return; 433 } 434 435 435 if ( currentGameState == GAMESTATE_POST_GAME ) 436 436 { 437 437 //TODO end game 438 438 439 439 return; 440 440 } … … 444 444 { 445 445 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 446 446 447 447 if ( !list ) 448 448 return; 449 449 450 450 //first server players with choices 451 451 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 461 461 } 462 462 } 463 463 464 464 //now serve player who want join a random team 465 465 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 482 482 assert( PlayerStats::getStats( userId ) ); 483 483 PlayerStats & stats = *(PlayerStats::getStats( userId )); 484 484 485 485 stats.setTeamId( stats.getPreferedTeamId() ); 486 486 487 487 Playable * oldPlayable = stats.getPlayable(); 488 489 488 489 490 490 ClassID playableClassId = getPlayableClassId( userId, stats.getPreferedTeamId() ); 491 491 std::string playableModel = getPlayableModelFileName( userId, stats.getPreferedTeamId(), playableClassId ); 492 492 493 493 BaseObject * bo = Factory::fabricate( playableClassId ); 494 494 495 495 assert( bo != NULL ); 496 496 assert( bo->isA( CL_PLAYABLE ) ); 497 497 498 498 Playable & playable = *(dynamic_cast<Playable*>(bo)); 499 499 500 500 playable.loadModel( playableModel ); 501 501 playable.setOwner( userId ); 502 502 playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 503 503 playable.setSynchronized( true ); 504 504 505 505 stats.setTeamId( stats.getPreferedTeamId() ); 506 506 stats.setPlayableClassId( playableClassId ); 507 507 stats.setPlayableUniqueId( playable.getUniqueID() ); 508 508 stats.setModelFileName( playableModel ); 509 509 510 510 if ( oldPlayable ) 511 511 { … … 572 572 OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); 573 573 input->show(); 574 input->give Focus();574 input->giveMouseFocus(); 575 575 input->setText("say "); 576 576 } … … 594 594 { 595 595 std::string name = "unknown"; 596 596 597 597 if ( PlayerStats::getStats( userId ) ) 598 598 { 599 599 name = PlayerStats::getStats( userId )->getNickName(); 600 600 } 601 601 602 602 PRINTF(0)("CHATMESSAGE %s (%d): %s\n", name.c_str(), userId, message.c_str() ); 603 603 notifier->pushNotifyMessage(name + ": " + message); … … 607 607 { 608 608 EventHandler::getInstance()->popState(); 609 input->break Focus();609 input->breakMouseFocus(); 610 610 input->hide(); 611 611 input->setText(""); 612 612 613 613 std::string command = text; 614 614 615 615 //HACK insert " in say commands so user doesn't have to type them 616 616 if ( command.length() >= 4 && command[0] == 's' && command[1] == 'a' && command[2] == 'y' && command[3] == ' ' )
Note: See TracChangeset
for help on using the changeset viewer.