Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8802 in orxonox.OLD for trunk/src


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

merged the network branche back to trunk

Location:
trunk/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/math/quaternion.h

    r8731 r8802  
    5050  /** @param q: the Quaternion to compare with this one. @returns true if the Quaternions are the same, false otherwise */
    5151  inline bool operator== (const Quaternion& q) const { return (unlikely(this->v==q.v&&this->w==q.w))?true:false; };
     52  /** @param q: the Quaternion to compare with this one. @returns true if the Quaternions are the same, false otherwise */
     53  inline bool operator!= (const Quaternion& q) const { return (unlikely(this->v!=q.v&&this->w!=q.w))?true:false; };
    5254  /** @param f: a real value @return a Quaternion containing the quotient */
    5355  inline Quaternion operator/ (const float& f) const { return (unlikely(f==0.0)) ? Quaternion() : Quaternion(this->v/f, this->w/f); };
  • trunk/src/lib/network/netdefs.h

    r7954 r8802  
    1919#define MAX_CONNECTIONS 1000
    2020
    21 #define NETWORK_FREQUENCY 33
     21#define NETWORK_FREQUENCY 66
    2222
    2323
  • trunk/src/lib/network/udp_server_socket.cc

    r8623 r8802  
    147147    res.length = packetBuffer[userId].front().length;
    148148    packetBuffer[userId].pop_front();
    149 
    150     if ( res.length == 0 )
    151       res.length = -1;
    152149  }
    153150
     
    173170 * @param ip users host / port
    174171 */
    175 void UdpServerSocket::initUser( int userId, IPaddress ip )
     172void UdpServerSocket::initUser( int userId, IPaddress ip, byte randomByte )
    176173{
    177174  int channel = SDLNet_UDP_Bind( socket, userId, &ip );
     
    192189    userList.resize( userId + 1 );
    193190
    194   userList[ userId ] = ip;
     191  userList[ userId ].addr = ip;
     192  userList[ userId ].randomByte = randomByte;
    195193}
    196194
     
    206204    return;
    207205
    208   userList[userId].host = 0;
    209   userList[userId].port = 0;
     206  userList[userId].addr.host = 0;
     207  userList[userId].addr.port = 0;
    210208
    211209  SDLNet_UDP_Unbind( socket, userId );
     
    234232    return false;
    235233  }
    236 
     234 
    237235  return true;
    238236}
     
    251249    bool isNewConnection = false;
    252250
     251    if ( packet->len <= 0 )
     252      continue;
     253       
    253254    for ( userId =0; userId < (int)userList.size(); userId++ )
    254       if ( userList[userId].host == packet->address.host && userList[userId].port == packet->address.port )
     255      if ( userList[userId].addr.host == packet->address.host && userList[userId].addr.port == packet->address.port && userList[userId].randomByte == ( packet->data[0] & 0xFC ) )
    255256        break;
    256257
    257258    if ( userId >= (int)userList.size() )
    258259    {
    259 
    260260      newConn++;
    261261      isNewConnection = true;
     
    268268
    269269      for ( userId =0; userId < (int)userList.size(); userId++ )
    270         if ( userList[userId].host == 0 && userList[userId].port == 0 )
     270        if ( userList[userId].addr.host == 0 && userList[userId].addr.port == 0 )
    271271          break;
    272272
    273       initUser( userId, packet->address );
    274       UdpSocket * sock = new UdpSocket( this, packet->address, userId );
     273      initUser( userId, packet->address, packet->data[0] & 0xFC );
     274      UdpSocket * sock = new UdpSocket( this, packet->address, userId, packet->data[0] & 0xFC );
    275275      newSocketList.push_back( sock );
    276276      PRINTF(0)("NEW CONNECTION %x\n", packet->address.host );
     
    292292    memcpy( networkPacket.data, packet->data, packet->len );
    293293    packetBuffer[userId].push_back( networkPacket );
    294 
    295294  }
    296295
  • trunk/src/lib/network/udp_server_socket.h

    r7954 r8802  
    3333typedef std::vector<NetworkPacketList> PacketBuffer;
    3434
    35 typedef std::vector<IPaddress> UserList;
     35struct UserInfo
     36{
     37  IPaddress addr;
     38  byte randomByte;
     39};
     40
     41typedef std::vector<UserInfo> UserList;
    3642
    3743typedef std::list<UdpSocket*> UdpSocketList;
     
    5763    bool sendPacket( NetworkPacket networkPacket, int userId );
    5864    int getPacketCount( int childId );
    59     void initUser( int childId, IPaddress ip );
     65    void initUser( int childId, IPaddress ip, byte randomByte );
    6066   
    6167  private:
  • trunk/src/lib/network/udp_socket.cc

    r8362 r8802  
    2525  this->socket = NULL;
    2626  this->packet = NULL;
     27  this->randomByte = 0;
    2728}
    2829
     
    7071 * @param userId userid used by serverSocket
    7172 */
    72 UdpSocket::UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId )
     73UdpSocket::UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId, byte randomByte )
    7374{
    7475  this->init();
    7576  this->serverSocket = serverSocket;
    7677  this->userId = userId;
     78  this->randomByte = randomByte;
    7779}
    7880
     
    104106
    105107  IPaddress ip;
     108 
     109  this->randomByte = generateNewRandomByte();
    106110
    107111  PRINTF(0)("connect to server %s on port %d\n", host.c_str(), port);
     
    137141{
    138142  PRINTF(0)("disconnect\n");
    139   writePacket( NULL, 0 );
     143  byte cmd = this->randomByte | UDPCMD_DISCONNECT;
     144  writeRawPacket( &cmd, 1 );
    140145  SDLNet_UDP_Unbind( socket, -1 );
    141146  SDLNet_UDP_Close( socket );
     
    152157bool UdpSocket::writePacket( byte * data, int length )
    153158{
     159  byte * buf = new byte[length+1];
     160  if ( length > 0 )
     161    memcpy( buf+1, data, length );
     162  buf[0] = this->randomByte;
     163  return writeRawPacket( buf, length+1 );
     164}
     165
     166/**
     167 * recieve one packet from another host
     168 * @param data pointer to buffer to copy data into
     169 * @param maxLength maximal length of buffer
     170 * @return less than 0 on error, number bytes read else
     171 */
     172int UdpSocket::readPacket( byte * data, int maxLength )
     173{
     174  assert( maxLength <= UDP_PACKET_SIZE );
     175
     176  if ( serverSocket )
     177  {
     178    NetworkPacket networkPacket = serverSocket->getPacket( this->userId );
     179
     180    byte udpCmd = 0;
     181   
     182    if ( networkPacket.length > 0 )
     183    {
     184      assert( maxLength > networkPacket.length );
     185
     186      memcpy( data, networkPacket.data+1, networkPacket.length-1 );
     187      udpCmd = networkPacket.data[0];
     188    }
     189    else
     190      return 0;
     191     
     192    if ( !checkRandomByte( networkPacket.data[0] ) )
     193      return 0;
     194
     195    if ( networkPacket.data )
     196    {
     197      free( networkPacket.data );
     198      networkPacket.data = NULL;
     199    }
     200   
     201    if ( !checkUdpCmd( udpCmd ) )
     202      return 0;
     203
     204    return networkPacket.length-1;
     205  }
     206  else
     207  {
     208    int numrecv = SDLNet_UDP_Recv( socket, packet);
     209   
     210    byte udpCmd = 0;
     211
     212    if ( numrecv > 0)
     213    {
     214      assert( packet->len <= maxLength );
     215
     216      if ( packet->len > 0 )
     217        memcpy( data, packet->data+1, packet->len-1 );
     218      else
     219        return 0;
     220           
     221      if ( !checkRandomByte( packet->data[0] ) )
     222        return 0;
     223             
     224      if ( !checkUdpCmd( udpCmd ) )
     225        return 0;
     226
     227      return packet->len-1;
     228    }
     229    else if ( numrecv < 0 )
     230    {
     231      PRINTF(1)("SDLNet_UDP_Recv: %s\n", SDLNet_GetError());
     232      bOk = false;
     233      return -1;
     234    }
     235    else
     236    {
     237      return 0;
     238    }
     239  }
     240
     241  return 0;
     242}
     243
     244bool UdpSocket::writeRawPacket( byte * data, int length )
     245{
    154246  if ( serverSocket )
    155247  {
     
    183275}
    184276
    185 /**
    186  * recieve one packet from another host
    187  * @param data pointer to buffer to copy data into
    188  * @param maxLength maximal length of buffer
    189  * @return less than 0 on error, number bytes read else
    190  */
    191 int UdpSocket::readPacket( byte * data, int maxLength )
    192 {
    193   assert( maxLength <= UDP_PACKET_SIZE );
    194 
    195   if ( serverSocket )
    196   {
    197     NetworkPacket networkPacket = serverSocket->getPacket( this->userId );
    198 
    199     if ( networkPacket.length == -1 )
    200     {
    201       this->disconnectServer();
    202       return 0;
    203     }
    204 
    205     if ( networkPacket.length > 0 )
    206     {
    207       assert( maxLength > networkPacket.length );
    208 
    209       memcpy( data, networkPacket.data, networkPacket.length );
    210     }
    211 
    212     if ( networkPacket.data )
    213     {
    214       free( networkPacket.data );
    215       networkPacket.data = NULL;
    216     }
    217 
    218     return networkPacket.length;
     277bool UdpSocket::checkUdpCmd( byte udpCmd )
     278{
     279  if ( udpCmd & UDPCMD_DISCONNECT )
     280  {
     281    this->disconnectServer();
     282    PRINTF(0)("received disconnect byte\n");
     283    return false;
     284  }
     285 
     286  if ( !this->serverSocket && ( udpCmd & UDPCMD_INVALIDRNDBYTE ) )
     287  {
     288    PRINTF(0)("received invlid random number byte\n");
     289    byte cmd = this->randomByte | UDPCMD_DISCONNECT;
     290    writeRawPacket( &cmd, 1 );
     291    this->randomByte = generateNewRandomByte();
     292    return false;
     293  }
     294 
     295  return true;
     296}
     297
     298byte UdpSocket::generateNewRandomByte( )
     299{
     300  srand( SDL_GetTicks() );
     301  byte res = ( rand() & 0xFC );
     302 
     303  PRINTF(0)("generated random byte: %x\n", res);
     304 
     305  return res;
     306}
     307
     308bool UdpSocket::checkRandomByte( byte rndByte )
     309{
     310  if ( ( rndByte & 0xFC ) == this->randomByte )
     311  {
     312    return true;
    219313  }
    220314  else
    221315  {
    222     int numrecv = SDLNet_UDP_Recv( socket, packet);
    223     if ( numrecv > 0)
    224     {
    225       assert( packet->len <= maxLength );
    226 
    227       if ( packet->len == 0 )
    228       {
    229         this->disconnectServer();
    230         return 0;
    231       }
    232 
    233       memcpy( data, packet->data, packet->len );
    234       return packet->len;
    235     }
    236     else if ( numrecv < 0 )
    237     {
    238       PRINTF(1)("SDLNet_UDP_Recv: %s\n", SDLNet_GetError());
    239       bOk = false;
    240       return -1;
    241     }
    242     else
    243     {
    244       return 0;
    245     }
    246   }
    247 
    248   return 0;
    249 }
    250 
    251 
    252 
     316    PRINTF(2)("wrong random byte: %x\n", ( rndByte & 0xFC ));
     317    return false;
     318  }
     319}
     320
     321
     322
  • trunk/src/lib/network/udp_socket.h

    r7954 r8802  
    1616class UdpServerSocket;
    1717
     18enum
     19{
     20  UDPCMD_DISCONNECT = 1,
     21  UDPCMD_INVALIDRNDBYTE = 2
     22};
     23
    1824class UdpSocket : public NetworkSocket
    1925{
    2026  public:
    2127    UdpSocket();
    22     UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId );
     28    UdpSocket( UdpServerSocket * serverSocket, IPaddress ip, int userId, byte randomByte );
    2329    UdpSocket( std::string host, int port );
    2430    virtual ~UdpSocket();
     
    2834    virtual void disconnectServer();
    2935
    30     virtual bool writePacket(byte * data, int length);
     36    virtual bool writePacket(byte * data, int length );
    3137
    3238    virtual int readPacket(byte * data, int maxLength);
     
    3945    UDPpacket *       packet;
    4046   
     47    byte              randomByte;     //!< contains random bytes & 0xFC
     48   
     49    bool writeRawPacket( byte * data, int length );
     50    bool checkUdpCmd( byte udpCmd );
     51    bool checkRandomByte( byte rndByte );
     52    byte generateNewRandomByte();
     53   
    4154    void init();
    4255
  • 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
  • trunk/src/world_entities/npcs/generic_npc.cc

    r8783 r8802  
    3030#include "generic_npc.h"
    3131
     32#include "animation/animation3d.h"
     33
    3234using namespace std;
    3335
     
    5557 */
    5658GenericNPC::~GenericNPC ()
    57 {}
     59{
     60  if( this->currentAnim != NULL)
     61    delete this->currentAnim;
     62}
    5863
    5964
     
    138143float GenericNPC::walkTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    139144{
    140 
    141   return true;
     145  Vector destCoor = Vector(x, y, z);
     146  Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
     147
     148  // check if this is the current goal
     149  if( this->destCoor != destCoor && this->destDir != destDir)
     150  {
     151    this->destCoor = Vector(x, y, 0.0f);
     152    this->destDir = Quaternion(Vector(qx, qy, qz), qu);
     153
     154    float time = 5.0f;
     155
     156    if( this->currentAnim != NULL)
     157      delete this->currentAnim;
     158
     159    this->currentAnim = new Animation3D(this);
     160    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f);
     161    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time);
     162  }
     163
     164  // calculate the distance
     165  Vector distance = this->getAbsCoor() - this->destCoor;
     166  return distance.len();
     167}
     168
     169
     170
     171/**
     172 * walk to a specific place with direction
     173 *
     174 * @param x: x coordinate to go to
     175 * @param y: y coordinate to go to
     176 * @param qu: angle to rotate
     177 * @param qx: x coordinate of rotation vector
     178 * @param qy: y coordinate of rotation vector
     179 * @param qz: z coordinate of rotation vector
     180 *
     181 */
     182float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz)
     183{
     184  return this->walkTo(x, y, 0.0f, qu, qx, qy, qz);
    142185}
    143186
  • trunk/src/world_entities/npcs/generic_npc.h

    r8796 r8802  
    2222
    2323class TiXmlElement;
     24class Animation3D;
    2425
    2526
     
    7172   Vector                                  destCoor;
    7273   Quaternion                              destDir;
     74
     75   Animation3D*                            currentAnim;
    7376};
    7477
  • trunk/src/world_entities/spawning_point.cc

    r8068 r8802  
    2424#include "compiler.h"
    2525
    26 #include <map>
     26#include "state.h"
     27#include "game_rules.h"
    2728
    2829
     
    5960{
    6061  this->setClassID(CL_SPAWNING_POINT, "SpawningPoint");
     62 
     63  this->teamId = -1;
    6164}
    6265
     
    8184  LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay)
    8285      .describe("sets the delay of the spawning point");
     86     
     87  /* load teamId */
     88  LoadParam(root, "teamId", this, SpawningPoint, setTeamId)
     89      .describe("sets teamId");
    8390
    8491
     
    101108void SpawningPoint::pushEntity(WorldEntity* entity, float delay)
    102109{
    103   this->queue[entity] = this->localTimer + delay;
     110  QueueEntry qe;
     111  qe.entity = entity;
     112  qe.list = entity->getOMListNumber();
     113  qe.respawnTime = this->localTimer + delay;
     114 
     115  queue.push_back( qe );
    104116}
    105117
     
    113125
    114126
    115   //BaseObject* spawningEntity = Factory::fabricate(this->classID);
    116   //   if( likely(this->world != NULL))
    117   //     this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity));
     127  entity->setAbsCoor( this->getAbsCoor() );
     128  entity->setAbsDir( this->getAbsDir() );
     129 
     130  //TODO set camera (not smooth)
    118131}
    119132
     
    129142  this->localTimer += dt;
    130143
    131   std::map<WorldEntity*, float>::iterator it = this->queue.begin();
    132   for( ; it != this->queue.end(); it++)
     144  std::list<QueueEntry>::iterator it = this->queue.begin();
     145  for( ; it != this->queue.end(); )
    133146  {
    134     //
    135     if( it->second <= this->localTimer)
     147   
     148    if( it->respawnTime <= this->localTimer)
    136149    {
    137150      //spawn the player
    138       this->spawn(it->first);
     151      this->spawn(it->entity);
     152     
     153      it->entity->toList( it->list );
     154     
     155      if ( State::getGameRules() )
     156      {
     157        (State::getGameRules())->registerSpawn( it->entity );
     158      }
     159     
     160      std::list<QueueEntry>::iterator delit = it;
     161      it++;
     162     
     163      queue.erase( delit );
     164     
     165      continue;
    139166    }
     167   
     168    it++;
    140169  }
    141170
  • trunk/src/world_entities/spawning_point.h

    r8068 r8802  
    88#define _SPAWNING_POINT
    99
    10 #include "world_entity.h"
     10#include "playable.h"
    1111
    12 #include <map>
     12#include <list>
    1313
    1414class World;
    1515class TiXmlElement;
    1616
     17struct QueueEntry
     18{
     19  float respawnTime;
     20  WorldEntity * entity;
     21  OM_LIST list;
     22};
    1723
    1824//!< used to indicate what type of objects are spawned by this spawning point
     
    5056    /** sets the spawning point mode @param mode: the mode */
    5157    void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; }
     58   
     59    inline int getTeamId(){ return this->teamId; }
     60    inline void setTeamId( int teamId ){ this->teamId = teamId; }
    5261
    5362    void pushEntity(WorldEntity* entity, float delay = 0);
     
    7281    float                           localTimer;                     //!< the local timer
    7382    float                           seed;                           //!< the random seed of the position
     83    int                             teamId;                         //!< only spawn players of this team
    7484    ClassID                         classid;                        //!< the classid of the entity to spawn
    7585    SpawningPointMode               mode;                           //!< the mode of the spawning point
    76     std::map<WorldEntity*, float>   queue;                          //!< queue of waiting WorldEntities to be spawned
     86    std::list<QueueEntry>           queue;                          //!< queue of waiting WorldEntities to be spawned
    7787    bool                            bSpawning;                      //!< flag to indicate if this spawning point is active or not
    7888};
Note: See TracChangeset for help on using the changeset viewer.