Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9008 in orxonox.OLD for trunk


Ignore:
Timestamp:
Jul 2, 2006, 2:22:19 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the network bak to the trunk
merged with command:
svn merge -r8804:HEAD https://svn.orxonox.net/orxonox/branches/multi_player_map .

conflicts all resolved in favour of the branche

Location:
trunk/src
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/collision_detection/bounding_volume.h

    r7711 r9008  
    3838    const int*          triangleIndexes;            //!< Array with the triangle indexes in modelInfo
    3939    int                 triangleIndexesLength;      //!< length of the indexes array
     40
     41    float               radius;                     //!< the radius of the box (longest axis)
    4042};
    4143
  • trunk/src/lib/collision_detection/obb_tree_node.cc

    r8776 r9008  
    364364    }
    365365  }
     366  this->bvElement->radius = longestAxis;
    366367  PRINTF(4)("\nLongest Axis is: Nr %i with a half-length of:%11.2f\n", longestAxisIndex, longestAxis);
    367368
     
    454455    return;
    455456
     457  float distanceMax = this->bvElement->radius + ((OBBTreeNode*)treeNode)->bvElement->radius;
     458  float distance = fabs((nodeA->getAbsCoor() - nodeB->getAbsCoor()).len());
     459
     460
     461//   if( distance < distanceMax)
     462//     PRINTF(0)(" %s (%s: group %i) vs %s (%s: group %i): distanceMax: %f, distance: %f\n", nodeA->getClassName(), nodeA->getName(), nodeA->getOMListNumber(), nodeB->getClassName(),  nodeB->getName(), nodeB->getOMListNumber(), distanceMax, distance);
     463
     464
    456465  PRINTF(4)("collideWith\n");
    457466  PRINTF(5)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
     
    482491      if( this->overlapTest(this->nodeLeft->bvElement, treeNode->bvElement, nodeA, nodeB))
    483492      {
     493        bool bAdvance = false;
    484494        if( treeNode->nodeLeft != NULL)
    485495          this->nodeLeft->collideWith(treeNode->nodeLeft, nodeA, nodeB);
     496        else
     497          bAdvance = true;
     498
    486499        if( treeNode->nodeRight != NULL)
    487500          this->nodeLeft->collideWith(treeNode->nodeRight, nodeA, nodeB);
     501        else
     502          bAdvance = true;
     503
     504        if( bAdvance)
     505          this->nodeLeft->collideWith(treeNode, nodeA, nodeB);  // go down the other tree also
    488506      }
    489507    }
     
    494512      if( this->overlapTest(this->nodeRight->bvElement, treeNode->bvElement, nodeA, nodeB))
    495513      {
     514        bool bAdvance = false;
     515
    496516        if( treeNode->nodeLeft != NULL)
    497517          this->nodeRight->collideWith(treeNode->nodeLeft, nodeA, nodeB);
     518        else
     519          bAdvance = true;
     520
    498521        if( treeNode->nodeRight != NULL)
    499522          this->nodeRight->collideWith(treeNode->nodeRight, nodeA, nodeB);
     523        else
     524          bAdvance = true;
     525
     526        if( bAdvance)
     527          this->nodeRight->collideWith(treeNode, nodeA, nodeB);  // go down the other tree also
    500528      }
    501529    }
     
    516544        (treeNode->nodeRight == NULL && treeNode->nodeLeft == NULL)) )
    517545    {
     546//       PRINTF(0)("----------------------------------------------\n\n\n\n\n\n--------------------------------\n\n\n");
    518547      nodeA->registerCollision(nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
    519548    }
  • trunk/src/lib/collision_reaction/cr_object_damage.cc

    r8779 r9008  
    5656  float damage = 0.0f;
    5757
    58   PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n",
     58  PRINTF(0)("Dealing damage - Handling collision: %s vs %s\n",
    5959            collision->getEntityA()->getClassName(),
    6060            collision->getEntityB()->getClassName());
     
    6363  if( collision->isEntityACollide()) {
    6464    damage = collision->getEntityB()->getDamage();
    65     collision->getEntityA()->hit(damage);
     65    collision->getEntityA()->hit(damage, collision->getEntityB());
    6666  }
    6767  PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName());
     
    6969  if( collision->isEntityBCollide()) {
    7070    damage = collision->getEntityA()->getDamage();
    71     collision->getEntityB()->hit(damage);
     71    collision->getEntityB()->hit(damage, collision->getEntityA());
    7272  }
    7373  PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName());
  • trunk/src/lib/network/message_manager.h

    r8708 r9008  
    3232  MSGID_PREFEREDTEAM,
    3333  MSGID_CHANGENICKNAME,
    34   MSGID_CHATMESSAGE
     34  MSGID_CHATMESSAGE,
     35  MSGID_RESPAWN
    3536};
    3637
  • trunk/src/lib/network/network_game_manager.cc

    r8708 r9008  
    3939
    4040#include "network_game_manager.h"
     41
     42#include "multiplayer_team_deathmatch.h"
    4143
    4244
     
    118120  stats->setPlayableUniqueId( playable.getUniqueID() );
    119121  stats->setModelFileName( playableModel );
     122 
     123  if ( rules.isA( CL_MULTIPLAYER_TEAM_DEATHMATCH ) )
     124    dynamic_cast<MultiplayerTeamDeathmatch*>(&rules)->respawnPlayable( &playable, team, 0.0f );
    120125 
    121126  return true;
  • trunk/src/story_entities/multi_player_world.cc

    r8894 r9008  
    9393void MultiPlayerWorld::collisionDetection()
    9494{
     95  //CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), this->dataTank->objectManager->getObjectList(OM_PLAYERS));
     96
     97  PRINTF(5)("\n-----------------------------------------\nchecking OM_PLAYERS vs OM_PLAYERS_PROJ\n\n");
     98  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ),
     99  this->dataTank->objectManager->getObjectList(OM_PLAYERS));
     100  PRINTF(5)("\n-----------------------------------------\nchecking OM_PLAYERS vs OM_GROUP_01_PROJ\n\n");
    95101  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS),
    96     this->dataTank->objectManager->getObjectList(OM_PLAYERS));
     102    this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ));
     103  PRINTF(5)("\n-----------------------------------------\nchecking OM_PLAYERS vs OM_GROUP_01_PROJ\n\n");
    97104  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS),
     105    this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ));
     106  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS),
     107    this->dataTank->objectManager->getObjectList(OM_GROUP_00));
     108  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS),
     109    this->dataTank->objectManager->getObjectList(OM_GROUP_01));
     110
     111
     112
     113  PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_00 vs OM_GROUP_01_PROJ\n\n");
     114  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00),
     115    this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ));
     116  PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_00 vs OM_GROUP_01\n\n");
     117  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00),
     118    this->dataTank->objectManager->getObjectList(OM_GROUP_01));
     119  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00),
    98120    this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ));
    99121
    100   CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS),
    101   this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ));
    102   CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS),
    103   this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ));
    104 
    105   CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00),
    106     this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ));
     122  PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_01 vs OM_GROUP_00_PROJ\n\n");
    107123  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01),
    108124    this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ));
    109   CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00),
    110     this->dataTank->objectManager->getObjectList(OM_GROUP_01));
    111 
    112   CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00),
    113     this->dataTank->objectManager->getObjectList(OM_COMMON));
    114125  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01),
    115     this->dataTank->objectManager->getObjectList(OM_COMMON));
    116 
     126    this->dataTank->objectManager->getObjectList(OM_GROUP_00));
     127  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01),
     128    this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ));
    117129}
    118130
  • trunk/src/story_entities/multi_player_world_data.cc

    r8717 r9008  
    233233  this->tickLists.push_back(OM_ENVIRON);
    234234  this->tickLists.push_back(OM_COMMON);
     235  this->tickLists.push_back(OM_PLAYERS);
     236  this->tickLists.push_back(OM_PLAYERS_PROJ);
    235237  this->tickLists.push_back(OM_GROUP_00);
    236238  this->tickLists.push_back(OM_GROUP_00_PROJ);
     
    241243  this->drawLists.push_back(OM_ENVIRON);
    242244  this->drawLists.push_back(OM_COMMON);
     245  this->drawLists.push_back(OM_PLAYERS);
     246  this->drawLists.push_back(OM_PLAYERS_PROJ);
    243247  this->drawLists.push_back(OM_GROUP_00);
    244248  this->drawLists.push_back(OM_GROUP_00_PROJ);
  • trunk/src/util/game_rules.cc

    r8802 r9008  
    9090  if ( !SharedNetworkData::getInstance()->isGameServer() )
    9191    return;
     92
    9293  PRINTF(0)("Received Event: Kill\n");
    93   this->killList.push_back(kill);
     94
     95  this->killList.push_back( kill );
    9496}
    9597
  • trunk/src/util/game_rules.h

    r8802 r9008  
    99
    1010#include "base_object.h"
     11#include <list>
    1112#include <vector>
    1213
     
    5455    std::vector<MissionGoal*>   missionList;            //!< list of mission goals
    5556
    56     std::vector<Kill>          killList;               //!<  list of kills in the world
     57    std::list<Kill>             killList;               //!<  list of kills in the world
    5758};
    5859
  • trunk/src/util/multiplayer_team_deathmatch.cc

    r8802 r9008  
    6868  this->numTeams = 2;
    6969  this->currentGameState = GAMESTATE_PRE_GAME;
    70   this->gameStateTimer = 10.0f;
     70  this->gameStateTimer = 3.0f;
    7171  this->bShowTeamChange = false;
    7272
     
    8585  subscribeEvent( ES_MENU, SDLK_F1 );
    8686  subscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 );
    87  
     87
    8888  this->notifier = new OrxGui::GLGuiNotifier();
    8989  this->notifier->show();
     
    106106  unsubscribeEvent( ES_MENU, SDLK_F1 );
    107107  unsubscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 );
    108  
     108
    109109  if ( this->notifier )
    110110  {
     
    219219  if ( !SharedNetworkData::getInstance()->isGameServer() )
    220220    return;
    221    
     221
    222222  //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 );
     223  while ( this->killList.begin() != this->killList.end() )
     224  {
     225    onKill( this->killList.begin()->getVictim(), this->killList.begin()->getKiller() );
     226    this->killList.erase( this->killList.begin() );
    231227  }
    232228 
     229
     230
    233231  gameStateTimer -= dt;
    234232  //PRINTF(0)("TICK %f\n", gameStateTimer);
     
    488486  stats.setModelFileName( playableModel );
    489487
     488  this->respawnPlayable( &playable, stats.getPreferedTeamId(), 0.0f );
     489
    490490  if ( oldPlayable )
    491491  {
     
    558558  else if ( event.type == SDLK_TAB )
    559559  {
    560     if ( !event.bPressed )
     560    if ( currentGameState == GAMESTATE_GAME && event.bPressed && !EventHandler::getInstance()->isPressed( SDLK_RALT ) && !EventHandler::getInstance()->isPressed( SDLK_LALT ) )
    561561    {
    562562      EventHandler::getInstance()->pushState( ES_MENU );
     
    627627  statsBox = new OrxGui::GLGuiBox();
    628628  statsBox->setAbsCoor2D( 300, 100 );
    629  
     629
    630630  this->table = new OrxGui::GLGuiTable(0,0);
    631631
     
    645645      statsBox = NULL;
    646646    }
    647      
     647
    648648    EventHandler::getInstance()->popState();
    649649}
     
    664664  headers.push_back("");
    665665  this->table->setHeader(headers);
    666  
     666
    667667  std::map<int,std::string> fragsTeam0;
    668668  std::map<int,std::string> fragsTeam1;
    669  
     669
    670670  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
    671  
     671
    672672  if ( !list )
    673673    return;
    674  
     674
    675675  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    676676  {
    677677    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
    678    
     678
    679679    if ( stats.getTeamId() == 0 || stats.getTeamId() == 1 )
    680680    {
     
    685685    }
    686686  }
    687  
     687
    688688  char st[10];
    689689  int i = 0;
    690  
    691  
     690
     691
    692692  i = 2;
    693693  for ( std::map<int,std::string>::const_iterator it = fragsTeam0.begin(); it != fragsTeam0.end(); it++ )
     
    699699    i++;
    700700  }
    701  
     701
    702702  i = 2;
    703703  for ( std::map<int,std::string>::const_iterator it = fragsTeam1.begin(); it != fragsTeam1.end(); it++ )
     
    712712/**
    713713 * this function is called when a player kills another one or himself
    714  * @param killedUserId
    715  * @param userId
    716  */
    717 void MultiplayerTeamDeathmatch::onKill( int killedUserId, int userId )
    718 {
    719   assert( PlayerStats::getStats( killedUserId ) );
    720   assert( PlayerStats::getStats( userId ) );
     714 * @param killedUserId
     715 * @param userId
     716 */
     717void MultiplayerTeamDeathmatch::onKill( WorldEntity * victim, WorldEntity * killer )
     718{
     719  if ( !victim )
     720    return;
     721  if ( !killer )
     722    return;
    721723 
    722   PlayerStats & killedStats = *PlayerStats::getStats( killedUserId );
    723   PlayerStats & stats = *PlayerStats::getStats( userId );
     724  int killerUserId = killer->getOwner();
     725  int victimUserId = victim->getOwner();
     726
     727  PlayerStats & victimStats = *PlayerStats::getStats( victimUserId );
     728  PlayerStats & killerStats = *PlayerStats::getStats( killerUserId );
    724729 
    725   if ( killedUserId != userId )
    726     stats.setScore( stats.getScore() + 1 );
     730  if ( killerStats.getPlayable() != killer || victimStats.getPlayable() != victim )
     731    return;
     732
     733  //check for suicide
     734  if ( killerUserId != victimUserId )
     735  {
     736    //check for teamkill
     737    if ( victimStats.getTeamId() != killerStats.getTeamId() )
     738    {
     739      killerStats.setScore( killerStats.getScore() + 1 );
     740    }
     741    else
     742    {
     743      killerStats.setScore( killerStats.getScore() - 1 );
     744    }
     745  }
    727746  else
    728     stats.setScore( stats.getScore() - 1 );
    729  
    730   if ( killedUserId == SharedNetworkData::getInstance()->getHostID() )
     747    killerStats.setScore( killerStats.getScore() - 1 );
     748
     749  if ( victimUserId == SharedNetworkData::getInstance()->getHostID() )
    731750  {
    732751    this->bLocalPlayerDead = true;
    733752    this->showStats();
    734753  }
    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 );
     754
     755  this->respawnPlayable( victimStats.getPlayable(), victimStats.getTeamId(), 3.0f );
    753756}
    754757
    755758/**
    756759 * this function is called on player respawn
    757  * @param userId 
     760 * @param userId
    758761 */
    759762void MultiplayerTeamDeathmatch::onRespawn( int userId )
     
    768771/**
    769772 * this function is called on player respawn
    770  * @param we 
     773 * @param we
    771774 */
    772775void MultiplayerTeamDeathmatch::registerSpawn( WorldEntity * we )
     
    775778}
    776779
     780
     781void MultiplayerTeamDeathmatch::respawnPlayable( Playable * playable, int teamId, float delay )
     782{
     783  const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT );
     784
     785  assert( list );
     786
     787  std::vector<SpawningPoint*> spList;
     788
     789  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     790  {
     791    SpawningPoint * sp = dynamic_cast<SpawningPoint*>(*it);
     792
     793    if ( sp->getTeamId() == teamId )
     794      spList.push_back( sp );
     795  }
     796
     797  if ( spList.size() == 0 )
     798  {
     799    for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     800    {
     801      SpawningPoint * sp = dynamic_cast<SpawningPoint*>(*it);
     802
     803      if ( sp->getTeamId() < 0 )
     804        spList.push_back( sp );
     805    }
     806  }
     807
     808  assert( spList.size() != 0 );
     809
     810  int n = (int)((float)spList.size() * (float)rand()/(float)RAND_MAX);
     811
     812  spList[n]->pushEntity( playable, delay );
     813}
     814
  • trunk/src/util/multiplayer_team_deathmatch.h

    r8802 r9008  
    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   
    6161    virtual void handleChatMessage( int userId, const std::string & message, int messageType );
     62   
     63    void respawnPlayable( Playable * playable, int teamId, float delay );
    6264
    6365  protected:
  • trunk/src/util/object_manager.cc

    r8362 r9008  
    212212    "background",
    213213    "common",
     214
     215    "players",
     216    "players-proj",
    214217
    215218    "group00",
  • trunk/src/world_entities/playable.cc

    r8724 r9008  
    6565
    6666  this->bDead = false;
    67  
     67
    6868  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
    6969
     
    392392    State::getGameRules()->onPlayerSpawn();
    393393
    394 
    395   if( this->getOwner() % 2 == 0)
    396   {
    397     //     this->toList(OM_GROUP_00);
    398     this->setAbsCoor(213.37, 57.71, -47.98);
    399     this->setAbsDir(0, 0, 1, 0);
    400   }
    401   else
    402   { // red team
    403     //     this->toList(OM_GROUP_01);
    404     this->setAbsCoor(-314.450, 40.701, 83.554);
    405     this->setAbsDir(1.0, -0.015, -0.012, 0.011);
    406   }
    407394  this->reset();
    408395  this->bDead = false;
  • trunk/src/world_entities/space_ships/space_ship.cc

    r8708 r9008  
    220220  this->burstSystem->setColor(0.5, .5,.5,.8,.8);
    221221  this->burstSystem->setColor(1.0, .8,.8,.8,.0);
    222  
     222
    223223  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity" ) );
    224224  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) );
     
    384384  this->shiftCoor(move);
    385385
     386//   PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber());
    386387
    387388}
     
    504505}
    505506
    506 
    507 
    508 
     507void SpaceShip::destroy( )
     508{
     509  PRINTF(0)("spaceship destroy\n");
     510}
     511
     512void SpaceShip::respawn( )
     513{
     514  toList( OM_PLAYERS );
     515}
     516
     517
     518
     519
  • trunk/src/world_entities/space_ships/space_ship.h

    r7954 r9008  
    3636    virtual void postSpawn();
    3737    virtual void leftWorld();
     38   
     39    virtual void destroy();
     40    virtual void respawn();
    3841
    3942    virtual void collidesWith(WorldEntity* entity, const Vector& location);
  • trunk/src/world_entities/spawning_point.cc

    r8802 r9008  
    2222#include "world_entity.h"
    2323
     24#include "class_list.h"
     25
    2426#include "compiler.h"
    2527
     
    2729#include "game_rules.h"
    2830
     31#include "shared_network_data.h"
     32
     33CREATE_FACTORY( SpawningPoint, CL_SPAWNING_POINT );
    2934
    3035/**
    3136 *  constructor
    3237 */
    33 SpawningPoint::SpawningPoint (ClassID classid, const Vector& position)
    34 {
    35   this->setAbsCoor(position);
    36   this->classid = classid;
    37   this->mode = SPT_ALL_AT_ONCE;
    38   this->delay = 0;
     38SpawningPoint::SpawningPoint( const TiXmlElement * root )
     39{
     40  this->setAbsCoor( 0, 0, 0 );
    3941
    4042  this->init();
    41 }
    42 
    43 
    44 /**
    45  *  standard constructor
    46  */
    47 SpawningPoint::SpawningPoint (const Vector& position, ClassID classid, SpawningPointMode mode, float delay)
    48 {
    49   this->setAbsCoor(position);
    50   this->classid = classid;
    51   this->mode = mode;
    52   this->delay = delay;
    53 
    54   this->init();
    55 }
    56 
    57 
     43 
     44  if (root != NULL)
     45    this->loadParams(root);
     46}
    5847
    5948void SpawningPoint::init()
    6049{
    6150  this->setClassID(CL_SPAWNING_POINT, "SpawningPoint");
     51  PRINTF(0)("Created SpawningPoint\n");
    6252 
    6353  this->teamId = -1;
     54  this->localTimer = 0.0f;
     55 
     56  this->toList( OM_DEAD_TICK );
     57 
     58  MessageManager::getInstance()->registerMessageHandler( MSGID_RESPAWN, respawnMessageHandler, NULL );
    6459}
    6560
     
    8176  WorldEntity::loadParams(root);
    8277
    83   /* now load the frequency */
    84   LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay)
    85       .describe("sets the delay of the spawning point");
    86      
    8778  /* load teamId */
    8879  LoadParam(root, "teamId", this, SpawningPoint, setTeamId)
    8980      .describe("sets teamId");
    90 
    91 
    92   /* now load the seed */
    93 //   LoadParam(root, "entity", this, SpawningPoint, setSpawningEntity)
    94 //       .describe("sets the spawning entity");
    95 
    96   /* now load the seed */
    97 /*  LoadParam(root, "classid", this, SpawningPoint, setSpawningEntity)
    98       .describe("sets the class id of the entity to spawn")
    99       .defaultValues(CL_WORLD_ENTITY);*/
    10081}
    10182
     
    10687 *  @param entity WorldEntity to be added
    10788 */
    108 void SpawningPoint::pushEntity(WorldEntity* entity, float delay)
     89void SpawningPoint::pushEntity(Playable* entity, float delay)
    10990{
    11091  QueueEntry qe;
    11192  qe.entity = entity;
    112   qe.list = entity->getOMListNumber();
    11393  qe.respawnTime = this->localTimer + delay;
    11494 
     
    120100 *  spawn the entity
    121101 */
    122 void SpawningPoint::spawn(WorldEntity* entity)
    123 {
    124   PRINTF(1)("Spawningpoint spawns new Entity (%s)\n", entity->getClassName());
     102void SpawningPoint::spawn(Playable* entity)
     103{
     104  PRINTF(0)("Spawningpoint spawns Entity (%s)\n", entity->getClassName());
    125105
    126106
     
    129109 
    130110  //TODO set camera (not smooth)
     111 
     112  if ( State::getGameRules() )
     113  {
     114    (State::getGameRules())->registerSpawn( entity );
     115  }
     116 
     117  entity->respawn();
    131118}
    132119
     
    141128{
    142129  this->localTimer += dt;
    143 
    144130  std::list<QueueEntry>::iterator it = this->queue.begin();
    145131  for( ; it != this->queue.end(); )
    146132  {
    147    
     133    //PRINTF(0)("%f <= %f\n", it->respawnTime, this->localTimer);
    148134    if( it->respawnTime <= this->localTimer)
    149135    {
     
    151137      this->spawn(it->entity);
    152138     
    153       it->entity->toList( it->list );
    154      
    155       if ( State::getGameRules() )
    156       {
    157         (State::getGameRules())->registerSpawn( it->entity );
    158       }
    159      
     139      if ( SharedNetworkData::getInstance()->isGameServer() )
     140        this->sendRespawnMessage( it->entity->getUniqueID() );
     141
    160142      std::list<QueueEntry>::iterator delit = it;
    161143      it++;
     
    179161 */
    180162void SpawningPoint::draw()
    181 {}
     163{
     164}
     165
     166void SpawningPoint::sendRespawnMessage( int uniqueId )
     167{
     168  byte * buf = new byte[2*INTSIZE];
     169 
     170  assert( Converter::intToByteArray( this->getUniqueID(), buf, INTSIZE ) == INTSIZE );
     171  assert( Converter::intToByteArray( uniqueId, buf + INTSIZE, INTSIZE ) == INTSIZE );
     172 
     173  MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     174}
     175
     176bool SpawningPoint::respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     177{
     178  if ( SharedNetworkData::getInstance()->isGameServer() )
     179  {
     180    PRINTF(2)("server received spawn message!\n");
     181    return true;
     182  }
     183   
     184  int spUniqueId;
     185  int uniqueId;
     186 
     187  if ( dataLength != 2*INTSIZE )
     188  {
     189    PRINTF(2)("spawn message has wrong size: %d\n", dataLength );
     190    return true;
     191  }
     192 
     193  assert( Converter::byteArrayToInt( data, &spUniqueId ) == INTSIZE );
     194  assert( Converter::byteArrayToInt( data+INTSIZE, &uniqueId ) == INTSIZE );
     195 
     196  SpawningPoint * sp = NULL;
     197  Playable      * playable = NULL;
     198 
     199  const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT );
     200 
     201  if ( list )
     202  {
     203    for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     204    {
     205      if ( dynamic_cast<SpawningPoint*>(*it)->getUniqueID() == uniqueId )
     206      {
     207        sp = dynamic_cast<SpawningPoint*>(*it);
     208        break;
     209      }
     210    }
     211  }
     212 
     213  if ( !sp )
     214  {
     215    PRINTF(2)("could not find spawning point\n");
     216    return false;
     217  }
     218 
     219  list = ClassList::getList( CL_PLAYABLE );
     220 
     221  if ( list )
     222  {
     223    for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     224    {
     225      if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
     226      {
     227        playable = dynamic_cast<Playable*>(*it);
     228        break;
     229      }
     230    }
     231  }
     232 
     233  if ( !playable )
     234  {
     235    PRINTF(2)("could not find playable\n");
     236    return false;
     237  }
     238 
     239  sp->spawn( playable );
     240 
     241  return true;
     242}
     243
  • trunk/src/world_entities/spawning_point.h

    r8802 r9008  
    1010#include "playable.h"
    1111
     12#include "message_manager.h"
     13
    1214#include <list>
    1315
     
    1820{
    1921  float respawnTime;
    20   WorldEntity * entity;
    21   OM_LIST list;
     22  Playable * entity;
    2223};
    2324
     
    4344
    4445  public:
    45     SpawningPoint (ClassID classID, const Vector& position = Vector(0.0, 0.0, 0.0));
    46     SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode type, float delay);
     46    SpawningPoint(const TiXmlElement* root = NULL);
    4747    virtual ~SpawningPoint ();
    4848    void init();
     
    5050    virtual void loadParams(const TiXmlElement* root);
    5151
    52     /**  sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */
    53     void SpawningPoint::setSpawningEntity(ClassID classid) { this->classid = classid; }
    54     /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */
    55     void SpawningPoint::setSpawningDelay(float delay) { this->delay = delay; }
    56     /** sets the spawning point mode @param mode: the mode */
    57     void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; }
    58    
    5952    inline int getTeamId(){ return this->teamId; }
    6053    inline void setTeamId( int teamId ){ this->teamId = teamId; }
    6154
    62     void pushEntity(WorldEntity* entity, float delay = 0);
     55    void pushEntity(Playable* entity, float delay = 0);
    6356
    6457    /** activates the spawning point */
     
    7467
    7568  private:
    76     void spawn(WorldEntity* entity);
     69    void spawn(Playable* entity);
     70   
     71    void sendRespawnMessage( int uniqueId );
     72    static bool respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    7773
    7874
    7975  private:
    80     float                           delay;                          //!< the timer that counts down until the next spawn
    8176    float                           localTimer;                     //!< the local timer
    82     float                           seed;                           //!< the random seed of the position
    8377    int                             teamId;                         //!< only spawn players of this team
    84     ClassID                         classid;                        //!< the classid of the entity to spawn
    85     SpawningPointMode               mode;                           //!< the mode of the spawning point
    8678    std::list<QueueEntry>           queue;                          //!< queue of waiting WorldEntities to be spawned
    8779    bool                            bSpawning;                      //!< flag to indicate if this spawning point is active or not
  • trunk/src/world_entities/world_entity.cc

    r9003 r9008  
    8888  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    8989  scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling" ) );
     90  list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list" ) );
    9091}
    9192
     
    733734 *  @param damage damage to be dealt
    734735 */
    735 void WorldEntity::hit(float damage)
     736void WorldEntity::hit(float damage, WorldEntity* killer)
    736737{
    737738  this->decreaseHealth(damage);
     
    748749
    749750    if( State::getGameRules() != NULL)
    750       State::getGameRules()->registerKill(Kill(NULL, this));
     751      State::getGameRules()->registerKill(Kill(killer, this));
    751752  }
    752753}
     
    832833  }
    833834
     835  if ( std::find( id.begin(), id.end(), list_handle ) != id.end() )
     836  {
     837    this->toList( (OM_LIST)list_write );
     838  }
     839
    834840  PNode::varChangeHandler( id );
    835841}
  • trunk/src/world_entities/world_entity.h

    r9003 r9008  
    9999  void setOnGround(bool flag) { this->bOnGround = flag; }
    100100
    101   virtual void hit(float damage);
     101  virtual void hit(float damage, WorldEntity* killer);
     102
    102103  virtual void destroy();
    103104
     
    195196  int                     modelFileName_handle;            //!< handle for syncing var
    196197
     198  int                     list_write;                      //!< entity's list
     199  int                     list_handle;                     //!< handle for list changes
     200
    197201  CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
    198202  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
Note: See TracChangeset for help on using the changeset viewer.