Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8802 in orxonox.OLD for trunk/src/util


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

merged the network branche back to trunk

Location:
trunk/src/util
Files:
4 edited

Legend:

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

    r8362 r8802  
    2121
    2222#include "util/mission_goal.h"
     23
     24#include "shared_network_data.h"
    2325
    2426#include "debug.h"
     
    8688void GameRules::registerKill(const Kill& kill)
    8789{
     90  if ( !SharedNetworkData::getInstance()->isGameServer() )
     91    return;
    8892  PRINTF(0)("Received Event: Kill\n");
    8993  this->killList.push_back(kill);
  • trunk/src/util/game_rules.h

    r8623 r8802  
    3535    /** adding a kill event to the kill list @param kill the kill object containing all infos */
    3636    void registerKill(const Kill& kill);
     37    virtual void registerSpawn( WorldEntity * we ){}
    3738
    3839    virtual void onPlayerSpawn() {}
    3940    virtual void onPlayerDeath() {}
    40 
    4141
    4242    virtual void tick(float dt) = 0;
  • 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
  • trunk/src/util/multiplayer_team_deathmatch.h

    r8708 r8802  
    4141    virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId );
    4242
    43     virtual void onPlayerSpawn();
    44     virtual void onPlayerDeath();
    45 
     43    virtual void registerSpawn( WorldEntity * we );
    4644
    4745    virtual void tick(float dt);
     
    5048    inline void setDeathPenaltyTimeout(float time) { this->deathTimeout = time; }
    5149    inline void setMaxKills(int kills) { this->maxKills = kills; }
    52     void setDeathScreen(const std::string& imageName);
    5350   
    5451    inline void setNumTeams( int numTeams ){ this->numTeams = numTeams; }
     
    5855   
    5956    virtual void process(const Event &event);
     57   
     58    void onKill( int killedUserId, int userId );
     59    void onRespawn( int userId );
    6060   
    6161    virtual void handleChatMessage( int userId, const std::string & message, int messageType );
     
    7373
    7474    std::map<int,int>  teamScore;                  //!< team score
    75 
    76     ImagePlane*        deathScreen;                //!< the death screen
    7775
    7876    int                currentGameState;           //!< game state
     
    10098   
    10199    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();
    102107};
    103108
Note: See TracChangeset for help on using the changeset viewer.