Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8860 in orxonox.OLD for branches/multi_player_map/src/util


Ignore:
Timestamp:
Jun 28, 2006, 3:09:54 PM (18 years ago)
Author:
rennerc
Message:

removed segfault when killing npc

Location:
branches/multi_player_map/src/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/multi_player_map/src/util/multiplayer_team_deathmatch.cc

    r8857 r8860  
    223223  while ( this->killList.begin() != this->killList.end() )
    224224  {
    225     if ( this->killList.begin()->getKiller() != NULL && this->killList.begin()->getVictim() != NULL )
    226       onKill( this->killList.begin()->getKiller()->getOwner(), this->killList.begin()->getVictim()->getOwner() );
     225    onKill( this->killList.begin()->getVictim(), this->killList.begin()->getKiller() );
    227226    this->killList.erase( this->killList.begin() );
    228227  }
     
    559558  else if ( event.type == SDLK_TAB )
    560559  {
    561     if ( currentGameState == GAMESTATE_GAME && !event.bPressed && !EventHandler::getInstance()->isPressed( SDLK_RALT ) && !EventHandler::getInstance()->isPressed( SDLK_LALT ) )
     560    if ( currentGameState == GAMESTATE_GAME && event.bPressed && !EventHandler::getInstance()->isPressed( SDLK_RALT ) && !EventHandler::getInstance()->isPressed( SDLK_LALT ) )
    562561    {
    563562      EventHandler::getInstance()->pushState( ES_MENU );
     
    716715 * @param userId
    717716 */
    718 void MultiplayerTeamDeathmatch::onKill( int killedUserId, int userId )
    719 {
    720   assert( PlayerStats::getStats( killedUserId ) );
    721   assert( PlayerStats::getStats( userId ) );
    722 
    723   PlayerStats & killedStats = *PlayerStats::getStats( killedUserId );
    724   PlayerStats & stats = *PlayerStats::getStats( userId );
     717void MultiplayerTeamDeathmatch::onKill( WorldEntity * victim, WorldEntity * killer )
     718{
     719  if ( !victim )
     720    return;
     721  if ( !killer )
     722    return;
     723 
     724  int killerUserId = killer->getOwner();
     725  int victimUserId = victim->getOwner();
     726
     727  PlayerStats & victimStats = *PlayerStats::getStats( victimUserId );
     728  PlayerStats & killerStats = *PlayerStats::getStats( killerUserId );
     729 
     730  if ( killerStats.getPlayable() != killer || victimStats.getPlayable() != victim )
     731    return;
    725732
    726733  //check for suicide
    727   if ( killedUserId != userId )
     734  if ( killerUserId != victimUserId )
    728735  {
    729736    //check for teamkill
    730     if ( stats.getTeamId() != killedStats.getTeamId() )
    731     {
    732       stats.setScore( stats.getScore() + 1 );
     737    if ( victimStats.getTeamId() != killerStats.getTeamId() )
     738    {
     739      killerStats.setScore( killerStats.getScore() + 1 );
    733740    }
    734741    else
    735742    {
    736       stats.setScore( stats.getScore() - 1 );
     743      killerStats.setScore( killerStats.getScore() - 1 );
    737744    }
    738745  }
    739746  else
    740     stats.setScore( stats.getScore() - 1 );
    741 
    742   if ( killedUserId == SharedNetworkData::getInstance()->getHostID() )
     747    killerStats.setScore( killerStats.getScore() - 1 );
     748
     749  if ( victimUserId == SharedNetworkData::getInstance()->getHostID() )
    743750  {
    744751    this->bLocalPlayerDead = true;
     
    746753  }
    747754
    748   this->respawnPlayable( killedStats.getPlayable(), killedStats.getTeamId(), 3.0f );
     755  this->respawnPlayable( victimStats.getPlayable(), victimStats.getTeamId(), 3.0f );
    749756}
    750757
  • branches/multi_player_map/src/util/multiplayer_team_deathmatch.h

    r8827 r8860  
    5656    virtual void process(const Event &event);
    5757   
    58     void onKill( int killedUserId, int userId );
     58    void onKill( WorldEntity * victim, WorldEntity * killer );
    5959    void onRespawn( int userId );
    6060   
Note: See TracChangeset for help on using the changeset viewer.