Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8067 in orxonox.OLD


Ignore:
Timestamp:
Jun 1, 2006, 2:06:53 PM (18 years ago)
Author:
rennerc
Message:

implemented gamestates for multiplayerTeamDeathmatch

Location:
branches/network/src
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/defs/class_id.h

    r7984 r8067  
    190190  CL_HOVER                      =    0x0000035e,
    191191  CL_TURBINE_HOVER              =    0x0000035f,
     192  CL_SPECTATOR                  =    0x00000360,
    192193
    193194  // Powerups
  • branches/network/src/lib/network/message_manager.cc

    r7954 r8067  
    309309  {
    310310    if (
    311          recieverType == RT_ALL ||
     311         recieverType == RT_ALL_ME ||
     312         recieverType == RT_ALL_NOT_ME ||
    312313         recieverType == RT_USER && it->first == reciever ||
    313314         recieverType == RT_NOT_USER && it->first != reciever
     
    324325     
    325326      it->second.messages.push_back( msg );
    326     }
    327   }
    328 }
    329 
    330 
     327     
     328      if ( recieverType == RT_ALL_ME )
     329        incomingMessabeBuffer.push_back( msg );
     330    }
     331  }
     332}
     333
     334
  • branches/network/src/lib/network/message_manager.h

    r8024 r8067  
    3636enum RecieverType
    3737{
    38   RT_ALL = 1,   //!< message is sent to all users
    39   RT_USER,      //!< message is only sent to reciever
    40   RT_NOT_USER   //!< message is sent to all but reciever
     38  RT_ALL_NOT_ME = 1,   //!< message is sent to all users
     39  RT_ALL_ME,           //!< message is sent to all users
     40  RT_USER,             //!< message is only sent to reciever
     41  RT_NOT_USER          //!< message is sent to all but reciever
    4142};
    4243
  • branches/network/src/lib/network/network_game_manager.cc

    r8024 r8067  
    5959 
    6060  MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL );
     61 
     62  this->gameState = 0;
     63  registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) );
    6164}
    6265
     
    118121bool NetworkGameManager::signalLeftPlayer(int userID)
    119122{
     123  delete PlayerStats::getStats( userID )->getPlayable();
     124  delete PlayerStats::getStats( userID );
    120125}
    121126
     
    166171void NetworkGameManager::removeSynchronizeable( int uniqueId )
    167172{
     173  byte buf[INTSIZE];
     174 
     175  assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE );
     176 
     177  MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
    168178}
    169179
     
    172182
    173183
     184
  • branches/network/src/lib/network/network_game_manager.h

    r8024 r8067  
    4747  public:
    4848    virtual ~NetworkGameManager();
    49 
     49   
    5050    static NetworkGameManager* NetworkGameManager::getInstance()
    5151    { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; }
     
    5757    void removeSynchronizeable( int uniqueId );
    5858
     59    inline void setGameState( int gameState ){ this->gameState = gameState; }
     60    inline int getGameState(){ return this->gameState; }
    5961
    6062  private:
     
    6466
    6567    static NetworkGameManager*    singletonRef;
     68   
     69    int                           gameState;
    6670};
    6771
  • branches/network/src/lib/network/player_stats.cc

    r8014 r8067  
    4848
    4949  this->userId = 0;
    50   this->teamId = 0;
     50  this->teamId = TEAM_NOTEAM;
     51  this->preferedTeamId = TEAM_NOTEAM;
    5152  this->score = 0;
    5253  this->playableClassId = 0;
     
    5455 
    5556  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
    56   groupId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
     57  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
     58  preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );
    5759  score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
    5860  playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
  • branches/network/src/lib/network/player_stats.h

    r8014 r8067  
    1212#include <string>
    1313#include <list>
     14
     15enum
     16{
     17  TEAM_NOTEAM = -3,
     18  TEAM_RANDOM = -2,
     19  TEAM_SPECTATOR = -1
     20};
    1421
    1522//! A class for storing player information
     
    3138    inline void setTeamId( int teamId ){ this->teamId = teamId; }
    3239   
     40    inline int getPreferedTeamId(){ return preferedTeamId; }
     41    inline void setPreferedTeamId( int preferedTeamId ){ this->preferedTeamId = preferedTeamId; }
     42   
    3343    inline int getScore(){ return score; }
    3444    inline void setScore( int score ){ this->score = score; }
     
    4858    int userId;                //!< userId
    4959    int teamId;                //!< teamId
     60    int preferedTeamId;        //!< preferedTeamId
    5061
    5162    int score;                 //!< users score points
     
    5869    // handles for SynchronizeableVars
    5970    int userId_handle;
    60     int groupId_handle;
     71    int teamId_handle;
     72    int preferedTeamId_handle;
    6173    int score_handle;
    6274    int playableClassId_handle;
  • branches/network/src/lib/network/synchronizeable.cc

    r8014 r8067  
    2121#include "netdefs.h"
    2222#include "network_log.h"
     23#include "network_game_manager.h"
    2324
    2425#include "state.h"
     
    6869  if ( this->networkStream )
    6970    this->networkStream->disconnectSynchronizeable(*this);
     71 
     72  if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 )
     73    NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
    7074}
    7175
  • branches/network/src/util/multiplayer_team_deathmatch.cc

    r7984 r8067  
    1515#define DEBUG_MODULE_GAME_RULES
    1616
     17#include <map>
     18
    1719#include "multiplayer_team_deathmatch.h"
    1820
     
    3436#include "space_ships/space_ship.h"
    3537
     38#include "network_game_manager.h"
     39
    3640
    3741using namespace std;
     
    5256  this->deathTimeout = 10.0f;     // 5 seconds
    5357  this->timeout = 0.0f;
     58  this->numTeams = 2;
     59  this->currentGameState = GAMESTATE_PRE_GAME;
     60  this->gameStateTimer = 10.0f;
    5461
    5562  this->deathScreen = new ImagePlane();
     
    8794  LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen)
    8895      .describe("sets the death screen image");
     96 
     97  LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams)
     98      .describe("sets number of teams");
    8999
    90100}
     
    128138void MultiplayerTeamDeathmatch::tick(float dt)
    129139{
     140  if ( !SharedNetworkData::getInstance()->isGameServer() )
     141    return;
     142 
     143  gameStateTimer -= dt;
     144  PRINTF(0)("TICK %f\n", gameStateTimer);
     145 
     146  if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 )
     147    nextGameState();
     148 
     149  this->currentGameState = NetworkGameManager::getInstance()->getGameState();
     150 
     151  if ( currentGameState == GAMESTATE_GAME )
     152  {
     153    handleTeamChanges();
     154  }
     155 
     156  this->calculateTeamScore();
     157 
    130158  this->checkGameRules();
    131159
     
    164192void MultiplayerTeamDeathmatch::checkGameRules()
    165193{
    166 
    167   Vector big_left(-201, 0, 0);
    168   float rBig = 176.0f;
    169   Vector big_right(177, 0, 0);
    170   Vector small_left(10, 0, 0);
    171   Vector small_middle(0, 0, 0);
    172   Vector small_right(-10, 0, 0);
    173   float rSmall = 90.0f;
    174 
    175 
     194  if ( !SharedNetworkData::getInstance()->isGameServer() )
     195    return;
     196 
    176197  // check for max killing count
    177   if( this->teamAKills >= this->maxKills)
    178   {
    179     // team A winns
    180   }
    181   else if( this->teamBKills >= this->maxKills)
    182   {
    183     // team B winns
    184   }
    185 
    186 
    187   if ( SharedNetworkData::getInstance()->isGameServer() )
    188   {
    189     float offsetx = 500.0f;
    190     float offsety = 323.0f;
    191     float offsetz = 200.0f;
    192 
    193     offsetz += 10;
    194 
    195     Terrain * terrain = dynamic_cast<Terrain*>(*(ClassList::getList( CL_TERRAIN )->begin()));
    196     const std::list<BaseObject*> * list = ClassList::getList( CL_SPACE_SHIP );
    197     for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++)
    198     {
    199       SpaceShip * ss = dynamic_cast<SpaceShip*>(*it);
    200       float terrx = ss->getAbsCoor().x + offsetx;
    201       float terry = ss->getAbsCoor().z + offsetz;
    202       float terrz = ss->getAbsCoor().y + offsety;
    203       if ( terrz < terrain->getHeight( terrx, terry ) && ss->getAbsCoor().x > -1000 )
     198  for ( int i = 0; i<numTeams; i++ )
     199  {
     200    if ( teamScore[i] >= maxKills )
     201    {
     202      //team i wins
     203      //TODO
     204    }
     205  }
     206}
     207
     208/**
     209 * find group for new player
     210 * @return group id
     211 */
     212int MultiplayerTeamDeathmatch::getTeamForNewUser( )
     213{
     214  return TEAM_NOTEAM;
     215}
     216
     217ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int team )
     218{
     219  return CL_SPECTATOR;
     220}
     221
     222std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int team, ClassID classId )
     223{
     224  return "";
     225}
     226
     227/**
     228 * calculate team score
     229 */
     230void MultiplayerTeamDeathmatch::calculateTeamScore( )
     231{
     232  teamScore.clear();
     233 
     234  for ( int i = 0; i<numTeams; i++ )
     235    teamScore[i] = 0;
     236 
     237   
     238  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
     239 
     240  if ( !list )
     241    return;
     242 
     243  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     244  {
     245    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
     246
     247    if ( stats.getTeamId() >= 0 )
     248    {
     249      teamScore[stats.getTeamId()] += stats.getScore();
     250    }
     251  }
     252}
     253
     254/**
     255 * get team for player who choose to join random team
     256 * @return smallest team
     257 */
     258int MultiplayerTeamDeathmatch::getRandomTeam( )
     259{
     260  std::map<int,int> playersInTeam;
     261 
     262  for ( int i = 0; i<numTeams; i++ )
     263    playersInTeam[i] = 0;
     264 
     265  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
     266 
     267  if ( !list )
     268    return 0;
     269 
     270  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     271  {
     272    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
     273
     274    if ( stats.getTeamId() >= 0 )
     275    {
     276      playersInTeam[stats.getTeamId()]++;
     277    }
     278  }
     279 
     280 
     281  int minPlayers = 0xFFFF;
     282  int minTeam = -1;
     283 
     284  for ( int i = 0; i<numTeams; i++ )
     285  {
     286    if ( playersInTeam[i] < minPlayers )
     287    {
     288      minTeam = i;
     289      minPlayers = playersInTeam[i];
     290    }
     291  }
     292 
     293  assert( minTeam != -1 );
     294 
     295  return minTeam;
     296}
     297
     298void MultiplayerTeamDeathmatch::nextGameState( )
     299{
     300  if ( currentGameState == GAMESTATE_PRE_GAME )
     301  {
     302    NetworkGameManager::getInstance()->setGameState( GAMESTATE_GAME );
     303   
     304    return;
     305  }
     306 
     307  if ( currentGameState == GAMESTATE_GAME )
     308  {
     309    NetworkGameManager::getInstance()->setGameState( GAMESTATE_POST_GAME );
     310   
     311    return;
     312  }
     313 
     314  if ( currentGameState == GAMESTATE_POST_GAME )
     315  {
     316    //TODO end game
     317   
     318    return;
     319  }
     320}
     321
     322void MultiplayerTeamDeathmatch::handleTeamChanges( )
     323{
     324  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
     325 
     326  if ( !list )
     327    return;
     328 
     329  //first server players with choices
     330  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     331  {
     332    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
     333
     334    if ( stats.getTeamId() != stats.getPreferedTeamId() )
     335    {
     336      if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() <= 0 && stats.getPreferedTeamId() < numTeams ) )
    204337      {
    205         //TODO handle this
     338        teamChange( stats.getUserId() );
    206339      }
    207 
    208 
    209       float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len();
    210       if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig &&
    211            (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig &&
    212            (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall &&
    213            (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall &&
    214            (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall
    215            && ss->getAbsCoor().x > -1000)
     340    }
     341  }
     342 
     343  //now serve player who want join a random team
     344  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     345  {
     346    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
     347
     348    if ( stats.getTeamId() != stats.getPreferedTeamId() )
     349    {
     350      if ( stats.getPreferedTeamId() == TEAM_RANDOM )
    216351      {
    217         PRINTF(0)("KILLLLLLLL\n");
    218 
    219         if((*it)->isA(CL_SPACE_SHIP))
    220         {
    221           //TODO handle this
    222         }
     352        stats.setPreferedTeamId( getTeamForNewUser() );
     353        teamChange( stats.getUserId() );
    223354      }
    224355    }
    225356  }
    226 
    227 
    228 #if 0
    229   std::list<BaseObject*>::const_iterator it;
    230   const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
    231 
    232   if( SharedNetworkData::getInstance()->isGameServer())
    233   {
    234     for(it = list->begin(); it != list->end(); it++)
    235     {
    236       float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len();
    237       if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig &&
    238            (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig &&
    239            (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall &&
    240            (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall &&
    241            (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall)
    242       {
    243         PRINTF(0)("KILLLLLLLL\n");
    244 
    245         if((*it)->isA(CL_SPACE_SHIP))
    246           dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(116369220.33434f);
    247       }
    248     }
    249   }
    250 #endif
    251 
    252 }
    253 
    254 
    255 
    256 
    257 
    258 
     357}
     358
     359void MultiplayerTeamDeathmatch::teamChange( int userId )
     360{
     361  assert( PlayerStats::getStats( userId ) );
     362  PlayerStats & stats = *(PlayerStats::getStats( userId ));
     363 
     364  assert(false);
     365}
     366
     367
     368
     369
     370
     371
  • branches/network/src/util/multiplayer_team_deathmatch.h

    r7984 r8067  
    1818class ImagePlane;
    1919
     20enum
     21{
     22  GAMESTATE_PRE_GAME = 0,
     23  GAMESTATE_GAME,
     24  GAMESTATE_POST_GAME
     25};
     26
    2027
    2128class MultiplayerTeamDeathmatch : public NetworkGameRules
     
    2835    virtual void loadParams(const TiXmlElement* root);
    2936
     37    virtual int getTeamForNewUser();
     38    virtual ClassID getPlayableClassId( int team );
     39    virtual std::string getPlayableModelFileName( int team, ClassID classId );
    3040
    3141    virtual void onPlayerSpawn();
     
    3949    inline void setMaxKills(int kills) { this->maxKills = kills; }
    4050    void setDeathScreen(const std::string& imageName);
     51   
     52    inline void setNumTeams( int numTeams ){ this->numTeams = numTeams; }
     53    inline int getNumTeams(){ return this->numTeams; }
     54   
     55    int getRandomTeam();
    4156
    4257  protected:
     
    4964    int                maxKills;                   //!< max kills for winning condition
    5065
    51     int                teamAKills;                 //!< kills of team A
    52     int                teamBKills;                 //!< kills of team B
     66    int                numTeams;                   //!< number of teams
    5367
    54     ImagePlane*         deathScreen;                //!< the death screen
     68    std::map<int,int>  teamScore;                  //!< team score
     69
     70    ImagePlane*        deathScreen;                //!< the death screen
     71
     72    int                currentGameState;           //!< game state
     73    float              gameStateTimer;             //!< if less than 0 -> change game state
     74
     75    void calculateTeamScore();
     76    void nextGameState();
     77    void handleTeamChanges();
     78    void teamChange( int userId );
    5579};
    5680
  • branches/network/src/util/network_game_rules.h

    r8024 r8067  
    2020    virtual ~NetworkGameRules();
    2121   
    22     int getTeamForNewUser();
    23     ClassID getPlayableClassId( int team );
    24     std::string getPlayableModelFileName( int team, ClassID classId );
     22    virtual int getTeamForNewUser();
     23    virtual ClassID getPlayableClassId( int team );
     24    virtual std::string getPlayableModelFileName( int team, ClassID classId );
    2525   
    26     PlayerStats * getNewPlayerStats( int userId ){ return new PlayerStats( userId ); }
     26    virtual PlayerStats * getNewPlayerStats( int userId ){ return new PlayerStats( userId ); }
    2727
    2828
  • branches/network/src/util/signal_handler.cc

    r8024 r8067  
    105105    {
    106106      dup2( fd[0], STDIN_FILENO );
    107       snprintf( command, 255, "gdb -p %d %s 1>" GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() );
     107      snprintf( command, 255, "gdb -p %d %s 1>>" GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() );
    108108    }
    109109    else
  • branches/network/src/world_entities/WorldEntities.am

    r7785 r8067  
    3939                world_entities/space_ships/turbine_hover.cc \
    4040                world_entities/creatures/md2_creature.cc \
     41                world_entities/spectator.cc \
    4142                \
    4243                \
     
    9091                space_ships/turbine_hover.h \
    9192                creatures/md2_creature.h \
     93                spectator.h \
    9294                \
    9395                environments/water.h \
Note: See TracChangeset for help on using the changeset viewer.