Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 26, 2006, 4:46:25 PM (18 years ago)
Author:
patrick
Message:

merged the network branche back to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/multiplayer_team_deathmatch.cc

    r8717 r8802  
    4545
    4646#include "shell_command.h"
     47
     48#include "spawning_point.h"
    4749
    4850
     
    7072
    7173  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;
    7776
    7877  this->localPlayer = State::getPlayer();
     
    8382  subscribeEvent( ES_GAME, SDLK_o );
    8483  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 
    8688  this->notifier = new OrxGui::GLGuiNotifier();
    8789  this->notifier->show();
     
    99101MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch()
    100102{
    101   if( this->deathScreen)
    102     delete this->deathScreen;
    103 
    104103  unsubscribeEvent( ES_GAME, SDLK_o );
    105104  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 
    107109  if ( this->notifier )
    108110  {
     
    130132      .describe("sets the maximal kills for winning condition");
    131133
    132   LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)
    133       .describe("sets the death screen image");
    134 
    135134  LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams)
    136135      .describe("sets number of teams");
     
    139138
    140139
    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 game
    152  * @param player the spawned player
    153  */
    154 void MultiplayerTeamDeathmatch::onPlayerSpawn()
    155 {
    156   this->bLocalPlayerDead = false;
    157   this->deathScreen->setVisibility(false);
    158 }
    159 
    160 
    161 /**
    162  * when the player is killed
    163  * @param player the killed player
    164  */
    165 void MultiplayerTeamDeathmatch::onPlayerDeath()
    166 {
    167   this->bLocalPlayerDead = true;
    168   this->deathScreen->setVisibility(true);
    169 }
    170 
    171 
    172140/**
    173141 * time tick
     
    176144void MultiplayerTeamDeathmatch::tick(float dt)
    177145{
     146  tickStatsTable();
    178147  //on client side hostId is -1 until hanshake finished
    179148  if ( SharedNetworkData::getInstance()->getHostID() < 0 )
     
    250219  if ( !SharedNetworkData::getInstance()->isGameServer() )
    251220    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 
    253233  gameStateTimer -= dt;
    254234  //PRINTF(0)("TICK %f\n", gameStateTimer);
     
    310290    if ( teamScore[i] >= maxKills )
    311291    {
    312       //team i wins
    313       //TODO
     292      nextGameState();
    314293    }
    315294  }
     
    435414  if ( currentGameState == GAMESTATE_POST_GAME )
    436415  {
    437     //TODO end game
     416    State::getCurrentStoryEntity()->stop();
     417    this->bShowTeamChange = false;
    438418
    439419    return;
     
    563543    if ( event.bPressed )
    564544      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    }
    565557  }
    566558  else if ( event.type == SDLK_TAB )
     
    576568    }
    577569  }
     570  else if ( this->bLocalPlayerDead && statsBox && event.type == KeyMapper::PEV_FIRE1 )
     571  {
     572    this->hideStats();
     573  }
    578574}
    579575
     
    623619}
    624620
    625 
    626 
    627 
     621/**
     622 * show table with frags
     623 */
     624void 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 */
     640void 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 */
     654void 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 */
     717void 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 */
     759void 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 */
     772void MultiplayerTeamDeathmatch::registerSpawn( WorldEntity * we )
     773{
     774  onRespawn( we->getOwner() );
     775}
     776
Note: See TracChangeset for help on using the changeset viewer.