Changeset 8096 in orxonox.OLD for branches/network/src/util
- Timestamp:
- Jun 1, 2006, 6:36:55 PM (18 years ago)
- Location:
- branches/network/src/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/util/multiplayer_team_deathmatch.cc
r8068 r8096 37 37 38 38 #include "network_game_manager.h" 39 40 #include "event_handler.h" 41 42 #include "glgui.h" 43 44 #include "story_entity.h" 39 45 40 46 … … 59 65 this->currentGameState = GAMESTATE_PRE_GAME; 60 66 this->gameStateTimer = 10.0f; 67 68 this->box = NULL; 61 69 62 70 this->deathScreen = new ImagePlane(); … … 138 146 void MultiplayerTeamDeathmatch::tick(float dt) 139 147 { 148 //on client side hostId is -1 until hanshake finished 149 if ( SharedNetworkData::getInstance()->getHostID() < 0 ) 150 return; 151 152 if ( currentGameState == GAMESTATE_PRE_GAME ) 153 { 154 if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) 155 && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM 156 && box == NULL 157 ) 158 { 159 EventHandler::getInstance()->pushState( ES_MENU ); 160 161 OrxGui::GLGuiHandler::getInstance()->activateCursor(); 162 163 box = new OrxGui::GLGuiBox(); 164 box->setAbsCoor2D( 300, 100 ); 165 166 OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator"); 167 box->pack( buttonSpectator ); 168 buttonSpectator->connect(SIGNAL(buttonSpectator, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonSpectator)); 169 170 OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random"); 171 box->pack( buttonRandom ); 172 buttonRandom->connect(SIGNAL(buttonRandom, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonRandom)); 173 174 OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team"); 175 box->pack( buttonTeam0 ); 176 buttonTeam0->connect(SIGNAL(buttonTeam0, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam0)); 177 178 OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team"); 179 box->pack( buttonTeam1 ); 180 buttonTeam1->connect(SIGNAL(buttonTeam1, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam1)); 181 182 OrxGui::GLGuiPushButton * buttonExit = new OrxGui::GLGuiPushButton("Exit"); 183 box->pack( buttonExit ); 184 buttonExit->connect(SIGNAL(buttonExit, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonExit)); 185 186 box->showAll(); 187 } 188 } 189 190 if ( box != NULL 191 && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) 192 && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM 193 ) 194 { 195 delete box; 196 box = NULL; 197 198 OrxGui::GLGuiHandler::getInstance()->deactivateCursor( true ); 199 200 EventHandler::getInstance()->popState(); 201 } 202 203 if ( box != NULL ) 204 { 205 OrxGui::GLGuiHandler::getInstance()->tick( dt ); 206 } 207 208 assignPlayable(); 209 140 210 if ( !SharedNetworkData::getInstance()->isGameServer() ) 141 211 return; 142 212 143 213 gameStateTimer -= dt; 144 PRINTF(0)("TICK %f\n", gameStateTimer);214 //PRINTF(0)("TICK %f\n", gameStateTimer); 145 215 146 216 if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 ) … … 210 280 * @return group id 211 281 */ 212 int MultiplayerTeamDeathmatch::getTeamForNewUser( 282 int MultiplayerTeamDeathmatch::getTeamForNewUser() 213 283 { 214 284 return TEAM_NOTEAM; 215 285 } 216 286 217 ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int team ) 218 { 219 return CL_SPECTATOR; 220 } 221 222 std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int team, ClassID classId ) 223 { 224 return ""; 287 ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int userId, int team ) 288 { 289 if ( team == TEAM_NOTEAM || team == TEAM_SPECTATOR ) 290 return CL_SPECTATOR; 291 292 if ( team == 0 || team == 1 ) 293 return CL_SPACE_SHIP; 294 295 assert( false ); 296 } 297 298 std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int userId, int team, ClassID classId ) 299 { 300 if ( team == 0 ) 301 return "models/ships/reap_#.obj"; 302 else if ( team == 1 ) 303 return "models/ships/fighter.obj"; 304 else 305 return ""; 225 306 } 226 307 … … 334 415 if ( stats.getTeamId() != stats.getPreferedTeamId() ) 335 416 { 336 if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() <= 0 && stats.getPreferedTeamId() < numTeams ) )417 if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() >= 0 && stats.getPreferedTeamId() < numTeams ) ) 337 418 { 338 419 teamChange( stats.getUserId() ); … … 362 443 PlayerStats & stats = *(PlayerStats::getStats( userId )); 363 444 364 assert(false); 365 } 366 367 368 369 370 371 445 stats.setTeamId( stats.getPreferedTeamId() ); 446 447 Playable * oldPlayable = stats.getPlayable(); 448 449 450 ClassID playableClassId = getPlayableClassId( userId, stats.getPreferedTeamId() ); 451 std::string playableModel = getPlayableModelFileName( userId, stats.getPreferedTeamId(), playableClassId ); 452 453 BaseObject * bo = Factory::fabricate( playableClassId ); 454 455 assert( bo != NULL ); 456 assert( bo->isA( CL_PLAYABLE ) ); 457 458 Playable & playable = *(dynamic_cast<Playable*>(bo)); 459 460 playable.loadModel( playableModel ); 461 playable.setOwner( userId ); 462 playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 463 playable.setSynchronized( true ); 464 465 stats.setTeamId( stats.getPreferedTeamId() ); 466 stats.setPlayableClassId( playableClassId ); 467 stats.setPlayableUniqueId( playable.getUniqueID() ); 468 stats.setModelFileName( playableModel ); 469 470 if ( oldPlayable ) 471 { 472 //if ( userId == SharedNetworkData::getInstance()->getHostID() ) 473 // State::getPlayer()->setPlayable( NULL ); 474 delete oldPlayable; 475 } 476 } 477 478 void MultiplayerTeamDeathmatch::onButtonExit( ) 479 { 480 State::getCurrentStoryEntity()->stop(); 481 } 482 483 void MultiplayerTeamDeathmatch::onButtonRandom( ) 484 { 485 NetworkGameManager::getInstance()->prefereTeam( TEAM_RANDOM ); 486 } 487 488 void MultiplayerTeamDeathmatch::onButtonTeam0( ) 489 { 490 NetworkGameManager::getInstance()->prefereTeam( 0 ); 491 } 492 493 void MultiplayerTeamDeathmatch::onButtonTeam1( ) 494 { 495 NetworkGameManager::getInstance()->prefereTeam( 1 ); 496 } 497 498 void MultiplayerTeamDeathmatch::onButtonSpectator( ) 499 { 500 NetworkGameManager::getInstance()->prefereTeam( TEAM_SPECTATOR ); 501 } 502 503 void MultiplayerTeamDeathmatch::assignPlayable( ) 504 { 505 if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) ) 506 PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPlayable(); 507 } 508 509 510 511 512 513 -
branches/network/src/util/multiplayer_team_deathmatch.h
r8068 r8096 12 12 #include "network_game_rules.h" 13 13 14 #include "glgui_box.h" 14 15 15 16 class TiXmlElement; … … 36 37 37 38 virtual int getTeamForNewUser(); 38 virtual ClassID getPlayableClassId( int team );39 virtual std::string getPlayableModelFileName( int team, ClassID classId );39 virtual ClassID getPlayableClassId( int userId, int team ); 40 virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId ); 40 41 41 42 virtual void onPlayerSpawn(); … … 73 74 float gameStateTimer; //!< if less than 0 -> change game state 74 75 76 OrxGui::GLGuiBox* box; 77 78 75 79 void calculateTeamScore(); 76 80 void nextGameState(); 77 81 void handleTeamChanges(); 78 82 void teamChange( int userId ); 83 void assignPlayable(); 84 85 void onButtonSpectator(); 86 void onButtonRandom(); 87 void onButtonTeam0(); 88 void onButtonTeam1(); 89 void onButtonExit(); 79 90 }; 80 91 -
branches/network/src/util/network_game_rules.cc
r8068 r8096 38 38 } 39 39 40 std::string NetworkGameRules::getPlayableModelFileName( int team, ClassID classId )40 std::string NetworkGameRules::getPlayableModelFileName( int uesrId, int team, ClassID classId ) 41 41 { 42 42 return "models/ships/reap_#.obj"; 43 43 } 44 44 45 ClassID NetworkGameRules::getPlayableClassId( int team )45 ClassID NetworkGameRules::getPlayableClassId( int userId, int team ) 46 46 { 47 47 return CL_SPACE_SHIP; -
branches/network/src/util/network_game_rules.h
r8068 r8096 21 21 22 22 virtual int getTeamForNewUser(); 23 virtual ClassID getPlayableClassId( int team );24 virtual std::string getPlayableModelFileName( int team, ClassID classId );23 virtual ClassID getPlayableClassId( int userId, int team ); 24 virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId ); 25 25 26 26 virtual PlayerStats * getNewPlayerStats( int userId ){ return new PlayerStats( userId ); }
Note: See TracChangeset
for help on using the changeset viewer.