Changeset 8802 in orxonox.OLD for trunk/src/util
- Timestamp:
- Jun 26, 2006, 4:46:25 PM (19 years ago)
- Location:
- trunk/src/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/game_rules.cc
r8362 r8802 21 21 22 22 #include "util/mission_goal.h" 23 24 #include "shared_network_data.h" 23 25 24 26 #include "debug.h" … … 86 88 void GameRules::registerKill(const Kill& kill) 87 89 { 90 if ( !SharedNetworkData::getInstance()->isGameServer() ) 91 return; 88 92 PRINTF(0)("Received Event: Kill\n"); 89 93 this->killList.push_back(kill); -
trunk/src/util/game_rules.h
r8623 r8802 35 35 /** adding a kill event to the kill list @param kill the kill object containing all infos */ 36 36 void registerKill(const Kill& kill); 37 virtual void registerSpawn( WorldEntity * we ){} 37 38 38 39 virtual void onPlayerSpawn() {} 39 40 virtual void onPlayerDeath() {} 40 41 41 42 42 virtual void tick(float dt) = 0; -
trunk/src/util/multiplayer_team_deathmatch.cc
r8717 r8802 45 45 46 46 #include "shell_command.h" 47 48 #include "spawning_point.h" 47 49 48 50 … … 70 72 71 73 this->box = NULL; 72 73 this->deathScreen = new ImagePlane(); 74 this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0); 75 this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f); 76 this->deathScreen->setVisibility(false); 74 this->table = NULL; 75 this->statsBox = NULL; 77 76 78 77 this->localPlayer = State::getPlayer(); … … 83 82 subscribeEvent( ES_GAME, SDLK_o ); 84 83 subscribeEvent( ES_GAME, SDLK_TAB ); 85 84 subscribeEvent( ES_GAME, SDLK_F1 ); 85 subscribeEvent( ES_MENU, SDLK_F1 ); 86 subscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 ); 87 86 88 this->notifier = new OrxGui::GLGuiNotifier(); 87 89 this->notifier->show(); … … 99 101 MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch() 100 102 { 101 if( this->deathScreen)102 delete this->deathScreen;103 104 103 unsubscribeEvent( ES_GAME, SDLK_o ); 105 104 unsubscribeEvent( ES_GAME, SDLK_TAB ); 106 105 unsubscribeEvent( ES_GAME, SDLK_F1 ); 106 unsubscribeEvent( ES_MENU, SDLK_F1 ); 107 unsubscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 ); 108 107 109 if ( this->notifier ) 108 110 { … … 130 132 .describe("sets the maximal kills for winning condition"); 131 133 132 LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)133 .describe("sets the death screen image");134 135 134 LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams) 136 135 .describe("sets number of teams"); … … 139 138 140 139 141 142 void MultiplayerTeamDeathmatch::setDeathScreen(const std::string& imageName)143 {144 if( this->deathScreen)145 this->deathScreen->setTexture(imageName);146 }147 148 149 150 /**151 * called when the player enters the game152 * @param player the spawned player153 */154 void MultiplayerTeamDeathmatch::onPlayerSpawn()155 {156 this->bLocalPlayerDead = false;157 this->deathScreen->setVisibility(false);158 }159 160 161 /**162 * when the player is killed163 * @param player the killed player164 */165 void MultiplayerTeamDeathmatch::onPlayerDeath()166 {167 this->bLocalPlayerDead = true;168 this->deathScreen->setVisibility(true);169 }170 171 172 140 /** 173 141 * time tick … … 176 144 void MultiplayerTeamDeathmatch::tick(float dt) 177 145 { 146 tickStatsTable(); 178 147 //on client side hostId is -1 until hanshake finished 179 148 if ( SharedNetworkData::getInstance()->getHostID() < 0 ) … … 250 219 if ( !SharedNetworkData::getInstance()->isGameServer() ) 251 220 return; 252 221 222 //handle kills 223 for ( std::vector<Kill>::iterator it = this->killList.begin(); it != this->killList.end(); ) 224 { 225 std::vector<Kill>::iterator delit = it; 226 227 onKill( it->getKiller()->getOwner(), it->getVictim()->getOwner() ); 228 229 it++; 230 killList.erase( delit ); 231 } 232 253 233 gameStateTimer -= dt; 254 234 //PRINTF(0)("TICK %f\n", gameStateTimer); … … 310 290 if ( teamScore[i] >= maxKills ) 311 291 { 312 //team i wins 313 //TODO 292 nextGameState(); 314 293 } 315 294 } … … 435 414 if ( currentGameState == GAMESTATE_POST_GAME ) 436 415 { 437 //TODO end game 416 State::getCurrentStoryEntity()->stop(); 417 this->bShowTeamChange = false; 438 418 439 419 return; … … 563 543 if ( event.bPressed ) 564 544 this->bShowTeamChange = true; 545 } else if ( event.type == SDLK_F1 ) 546 { 547 if ( !this->statsBox && event.bPressed ) 548 { 549 PRINTF(0)("show stats\n"); 550 this->showStats(); 551 } 552 if ( this->statsBox && !this->bLocalPlayerDead && event.bPressed && this->table->rowCount() != 0 && this->table->columnCount() != 0 ) 553 { 554 PRINTF(0)("hide stats\n"); 555 this->hideStats(); 556 } 565 557 } 566 558 else if ( event.type == SDLK_TAB ) … … 576 568 } 577 569 } 570 else if ( this->bLocalPlayerDead && statsBox && event.type == KeyMapper::PEV_FIRE1 ) 571 { 572 this->hideStats(); 573 } 578 574 } 579 575 … … 623 619 } 624 620 625 626 627 621 /** 622 * show table with frags 623 */ 624 void MultiplayerTeamDeathmatch::showStats( ) 625 { 626 EventHandler::getInstance()->pushState( ES_MENU ); 627 statsBox = new OrxGui::GLGuiBox(); 628 statsBox->setAbsCoor2D( 300, 100 ); 629 630 this->table = new OrxGui::GLGuiTable(0,0); 631 632 statsBox->pack( this->table ); 633 634 statsBox->showAll(); 635 } 636 637 /** 638 * hide table with frags 639 */ 640 void MultiplayerTeamDeathmatch::hideStats( ) 641 { 642 if ( statsBox ) 643 { 644 delete statsBox; 645 statsBox = NULL; 646 } 647 648 EventHandler::getInstance()->popState(); 649 } 650 651 /** 652 * fill stats table with values 653 */ 654 void MultiplayerTeamDeathmatch::tickStatsTable( ) 655 { 656 if ( !this->statsBox ) 657 return; 658 659 std::vector<std::string> headers; 660 headers.push_back("Red Team"); 661 headers.push_back(""); 662 headers.push_back(""); 663 headers.push_back("Blue Team"); 664 headers.push_back(""); 665 this->table->setHeader(headers); 666 667 std::map<int,std::string> fragsTeam0; 668 std::map<int,std::string> fragsTeam1; 669 670 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 671 672 if ( !list ) 673 return; 674 675 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 676 { 677 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 678 679 if ( stats.getTeamId() == 0 || stats.getTeamId() == 1 ) 680 { 681 if ( stats.getTeamId() == 0 ) 682 fragsTeam0[stats.getScore()] = stats.getNickName(); 683 else 684 fragsTeam1[stats.getScore()] = stats.getNickName(); 685 } 686 } 687 688 char st[10]; 689 int i = 0; 690 691 692 i = 2; 693 for ( std::map<int,std::string>::const_iterator it = fragsTeam0.begin(); it != fragsTeam0.end(); it++ ) 694 { 695 this->table->setEntry( 0, i, it->second ); 696 snprintf( st, 10, "%d", it->first ); 697 this->table->setEntry( 1, i, st ); 698 this->table->setEntry( 2, i, "" ); 699 i++; 700 } 701 702 i = 2; 703 for ( std::map<int,std::string>::const_iterator it = fragsTeam1.begin(); it != fragsTeam1.end(); it++ ) 704 { 705 this->table->setEntry( 3, i, it->second ); 706 snprintf( st, 10, "%d", it->first ); 707 this->table->setEntry( 4, i, st ); 708 i++; 709 } 710 } 711 712 /** 713 * this function is called when a player kills another one or himself 714 * @param killedUserId 715 * @param userId 716 */ 717 void MultiplayerTeamDeathmatch::onKill( int killedUserId, int userId ) 718 { 719 assert( PlayerStats::getStats( killedUserId ) ); 720 assert( PlayerStats::getStats( userId ) ); 721 722 PlayerStats & killedStats = *PlayerStats::getStats( killedUserId ); 723 PlayerStats & stats = *PlayerStats::getStats( userId ); 724 725 if ( killedUserId != userId ) 726 stats.setScore( stats.getScore() + 1 ); 727 else 728 stats.setScore( stats.getScore() - 1 ); 729 730 if ( killedUserId == SharedNetworkData::getInstance()->getHostID() ) 731 { 732 this->bLocalPlayerDead = true; 733 this->showStats(); 734 } 735 736 const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT ); 737 738 assert( list ); 739 740 std::vector<SpawningPoint*> spList; 741 742 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 743 { 744 SpawningPoint * sp = dynamic_cast<SpawningPoint*>(*it); 745 746 if ( sp->getTeamId() < 0 || sp->getTeamId() == killedStats.getTeamId() ) 747 spList.push_back( sp ); 748 } 749 750 int n = spList.size()*rand(); 751 752 spList[n]->pushEntity( killedStats.getPlayable(), 3 ); 753 } 754 755 /** 756 * this function is called on player respawn 757 * @param userId 758 */ 759 void MultiplayerTeamDeathmatch::onRespawn( int userId ) 760 { 761 if ( userId == SharedNetworkData::getInstance()->getHostID() ) 762 { 763 this->bLocalPlayerDead = false; 764 this->hideStats(); 765 } 766 } 767 768 /** 769 * this function is called on player respawn 770 * @param we 771 */ 772 void MultiplayerTeamDeathmatch::registerSpawn( WorldEntity * we ) 773 { 774 onRespawn( we->getOwner() ); 775 } 776 -
trunk/src/util/multiplayer_team_deathmatch.h
r8708 r8802 41 41 virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId ); 42 42 43 virtual void onPlayerSpawn(); 44 virtual void onPlayerDeath(); 45 43 virtual void registerSpawn( WorldEntity * we ); 46 44 47 45 virtual void tick(float dt); … … 50 48 inline void setDeathPenaltyTimeout(float time) { this->deathTimeout = time; } 51 49 inline void setMaxKills(int kills) { this->maxKills = kills; } 52 void setDeathScreen(const std::string& imageName);53 50 54 51 inline void setNumTeams( int numTeams ){ this->numTeams = numTeams; } … … 58 55 59 56 virtual void process(const Event &event); 57 58 void onKill( int killedUserId, int userId ); 59 void onRespawn( int userId ); 60 60 61 61 virtual void handleChatMessage( int userId, const std::string & message, int messageType ); … … 73 73 74 74 std::map<int,int> teamScore; //!< team score 75 76 ImagePlane* deathScreen; //!< the death screen77 75 78 76 int currentGameState; //!< game state … … 100 98 101 99 void onInputEnter( const std::string & text ); 100 101 OrxGui::GLGuiBox* statsBox; 102 OrxGui::GLGuiTable* table; 103 void tickStatsTable(); 104 105 void showStats(); 106 void hideStats(); 102 107 }; 103 108
Note: See TracChangeset
for help on using the changeset viewer.