Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/multi_player_map/src/util/multiplayer_team_deathmatch.cc @ 8856

Last change on this file since 8856 was 8856, checked in by rennerc, 18 years ago

fixed segfault

File size: 19.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13*/
14
15#define DEBUG_MODULE_GAME_RULES
16
17#include <map>
18
19#include "multiplayer_team_deathmatch.h"
20
21#include "util/loading/load_param.h"
22#include "util/loading/factory.h"
23
24#include "render2D/image_plane.h"
25#include "state.h"
26#include "class_list.h"
27
28#include "player.h"
29#include "playable.h"
30#include "space_ships/space_ship.h"
31
32
33#include "shared_network_data.h"
34#include "terrain.h"
35#include "class_list.h"
36#include "space_ships/space_ship.h"
37
38#include "network_game_manager.h"
39
40#include "event_handler.h"
41
42#include "glgui.h"
43
44#include "story_entity.h"
45
46#include "shell_command.h"
47
48#include "spawning_point.h"
49
50
51using namespace std;
52
53
54CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH);
55
56
57/**
58 * constructor
59 */
60MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root)
61  : NetworkGameRules(root)
62{
63  this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch");
64
65  this->bLocalPlayerDead = false;
66  this->deathTimeout = 10.0f;     // 5 seconds
67  this->timeout = 0.0f;
68  this->numTeams = 2;
69  this->currentGameState = GAMESTATE_PRE_GAME;
70  this->gameStateTimer = 3.0f;
71  this->bShowTeamChange = false;
72
73  this->box = NULL;
74  this->table = NULL;
75  this->statsBox = NULL;
76
77  this->localPlayer = State::getPlayer();
78
79  if( root != NULL)
80    this->loadParams(root);
81
82  subscribeEvent( ES_GAME, SDLK_o );
83  subscribeEvent( ES_GAME, SDLK_TAB );
84  subscribeEvent( ES_GAME, SDLK_F1 );
85  subscribeEvent( ES_MENU, SDLK_F1 );
86  subscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 );
87
88  this->notifier = new OrxGui::GLGuiNotifier();
89  this->notifier->show();
90  this->notifier->setAbsCoor2D(5, 30);
91  this->notifier->setFadeAge( 6.0 );
92  this->notifier->setHideAge( 8.0 );
93  this->input = new OrxGui::GLGuiInputLine();
94  this->input->setAbsCoor2D(180, 5);
95  this->input->connect(SIGNAL(input, enterPushed), this, SLOT(MultiplayerTeamDeathmatch, onInputEnter));
96}
97
98/**
99 * decontsructor
100 */
101MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch()
102{
103  unsubscribeEvent( ES_GAME, SDLK_o );
104  unsubscribeEvent( ES_GAME, SDLK_TAB );
105  unsubscribeEvent( ES_GAME, SDLK_F1 );
106  unsubscribeEvent( ES_MENU, SDLK_F1 );
107  unsubscribeEvent( ES_MENU, KeyMapper::PEV_FIRE1 );
108
109  if ( this->notifier )
110  {
111    delete this->notifier;
112    this->notifier = NULL;
113  }
114
115  if ( this->input )
116  {
117    delete this->input;
118    this->input = NULL;
119  }
120}
121
122
123
124void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root)
125{
126  GameRules::loadParams(root) ;
127
128  LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout)
129      .describe("sets the time in seconds a player has to wait for respawn");
130
131  LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills)
132      .describe("sets the maximal kills for winning condition");
133
134  LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams)
135      .describe("sets number of teams");
136
137}
138
139
140/**
141 * time tick
142 * @param dt time
143 */
144void MultiplayerTeamDeathmatch::tick(float dt)
145{
146  tickStatsTable();
147  //on client side hostId is -1 until hanshake finished
148  if ( SharedNetworkData::getInstance()->getHostID() < 0 )
149    return;
150
151  if ( currentGameState == GAMESTATE_PRE_GAME || currentGameState == GAMESTATE_GAME )
152  {
153    if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
154         && box == NULL
155         &&  (PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM
156         || bShowTeamChange )
157
158       )
159    {
160      EventHandler::getInstance()->pushState( ES_MENU );
161
162      OrxGui::GLGuiHandler::getInstance()->activateCursor();
163
164      box = new OrxGui::GLGuiBox();
165      box->setAbsCoor2D( 300, 100 );
166
167      OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator");
168      box->pack( buttonSpectator );
169      buttonSpectator->connect(SIGNAL(buttonSpectator, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonSpectator));
170
171      OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random");
172      box->pack( buttonRandom );
173      buttonRandom->connect(SIGNAL(buttonRandom, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonRandom));
174
175      OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team");
176      box->pack( buttonTeam0 );
177      buttonTeam0->connect(SIGNAL(buttonTeam0, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam0));
178
179      OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team");
180      box->pack( buttonTeam1 );
181      buttonTeam1->connect(SIGNAL(buttonTeam1, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam1));
182
183      if ( bShowTeamChange )
184      {
185        OrxGui::GLGuiPushButton * buttonCancel = new OrxGui::GLGuiPushButton("Cancel");
186        box->pack( buttonCancel );
187        buttonCancel->connect(SIGNAL(buttonCancel, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonCancel));
188      }
189
190      OrxGui::GLGuiPushButton * buttonExit = new OrxGui::GLGuiPushButton("Exit");
191      box->pack( buttonExit );
192      buttonExit->connect(SIGNAL(buttonExit, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonExit));
193
194      box->showAll();
195    }
196  }
197
198  if ( box != NULL
199       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
200       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM
201       && !bShowTeamChange
202     )
203  {
204    delete box;
205    box = NULL;
206
207    OrxGui::GLGuiHandler::getInstance()->deactivateCursor( true );
208
209    EventHandler::getInstance()->popState();
210  }
211
212  if ( box != NULL )
213  {
214    OrxGui::GLGuiHandler::getInstance()->tick( dt );
215  }
216
217  assignPlayable();
218
219  if ( !SharedNetworkData::getInstance()->isGameServer() )
220    return;
221
222  //handle kills
223  while ( this->killList.begin() != this->killList.end() )
224  {
225    if ( this->killList.begin()->getKiller() != NULL && this->killList.begin()->getVictim() != NULL )
226      onKill( this->killList.begin()->getKiller()->getOwner(), this->killList.begin()->getVictim()->getOwner() );
227    this->killList.erase( this->killList.begin() );
228  }
229 
230
231
232  gameStateTimer -= dt;
233  //PRINTF(0)("TICK %f\n", gameStateTimer);
234
235  if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 )
236    nextGameState();
237
238  this->currentGameState = NetworkGameManager::getInstance()->getGameState();
239
240  if ( currentGameState == GAMESTATE_GAME )
241  {
242    handleTeamChanges();
243  }
244
245  this->calculateTeamScore();
246
247  this->checkGameRules();
248
249  // is the local player dead and inactive
250  if( unlikely(this->bLocalPlayerDead))
251  {
252    this->timeout += dt;
253    PRINTF(0)("TICK DEATH: %f of %f\n", this->timeout, this->deathTimeout);
254    // long enough dead?
255    if( this->timeout >= this->deathTimeout)
256    {
257      this->timeout = 0.0f;
258      // respawn
259      PRINTF(0)("RESPAWN\n");
260      (State::getPlayer())->getPlayable()->respawn();
261    }
262  }
263}
264
265
266/**
267 * draws the stuff
268 */
269void MultiplayerTeamDeathmatch::draw()
270{
271  if( unlikely( this->bLocalPlayerDead))
272  {
273
274  }
275}
276
277
278/**
279 * check the game rules for consistency
280 */
281void MultiplayerTeamDeathmatch::checkGameRules()
282{
283  if ( !SharedNetworkData::getInstance()->isGameServer() )
284    return;
285
286  // check for max killing count
287  for ( int i = 0; i<numTeams; i++ )
288  {
289    if ( teamScore[i] >= maxKills )
290    {
291      nextGameState();
292    }
293  }
294}
295
296/**
297 * find group for new player
298 * @return group id
299 */
300int MultiplayerTeamDeathmatch::getTeamForNewUser()
301{
302  return TEAM_NOTEAM;
303}
304
305ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int userId, int team )
306{
307  if ( team == TEAM_NOTEAM || team == TEAM_SPECTATOR )
308    return CL_SPECTATOR;
309
310  if ( team == 0 || team == 1 )
311    return CL_SPACE_SHIP;
312
313  assert( false );
314}
315
316std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int userId, int team, ClassID classId )
317{
318  if ( team == 0 )
319    return "models/ships/reap_#.obj";
320  else if ( team == 1 )
321    return "models/ships/fighter.obj";
322  else
323    return "";
324}
325
326/**
327 * calculate team score
328 */
329void MultiplayerTeamDeathmatch::calculateTeamScore( )
330{
331  teamScore.clear();
332
333  for ( int i = 0; i<numTeams; i++ )
334    teamScore[i] = 0;
335
336
337  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
338
339  if ( !list )
340    return;
341
342  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
343  {
344    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
345
346    if ( stats.getTeamId() >= 0 )
347    {
348      teamScore[stats.getTeamId()] += stats.getScore();
349    }
350  }
351}
352
353/**
354 * get team for player who choose to join random team
355 * @return smallest team
356 */
357int MultiplayerTeamDeathmatch::getRandomTeam( )
358{
359  std::map<int,int> playersInTeam;
360
361  for ( int i = 0; i<numTeams; i++ )
362    playersInTeam[i] = 0;
363
364  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
365
366  if ( !list )
367    return 0;
368
369  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
370  {
371    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
372
373    if ( stats.getTeamId() >= 0 )
374    {
375      playersInTeam[stats.getTeamId()]++;
376    }
377  }
378
379
380  int minPlayers = 0xFFFF;
381  int minTeam = -1;
382
383  for ( int i = 0; i<numTeams; i++ )
384  {
385    if ( playersInTeam[i] < minPlayers )
386    {
387      minTeam = i;
388      minPlayers = playersInTeam[i];
389    }
390  }
391
392  assert( minTeam != -1 );
393
394  return minTeam;
395}
396
397void MultiplayerTeamDeathmatch::nextGameState( )
398{
399  if ( currentGameState == GAMESTATE_PRE_GAME )
400  {
401    NetworkGameManager::getInstance()->setGameState( GAMESTATE_GAME );
402
403    return;
404  }
405
406  if ( currentGameState == GAMESTATE_GAME )
407  {
408    NetworkGameManager::getInstance()->setGameState( GAMESTATE_POST_GAME );
409
410    return;
411  }
412
413  if ( currentGameState == GAMESTATE_POST_GAME )
414  {
415    State::getCurrentStoryEntity()->stop();
416    this->bShowTeamChange = false;
417
418    return;
419  }
420}
421
422void MultiplayerTeamDeathmatch::handleTeamChanges( )
423{
424  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
425
426  if ( !list )
427    return;
428
429  //first server players with choices
430  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
431  {
432    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
433
434    if ( stats.getTeamId() != stats.getPreferedTeamId() )
435    {
436      if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() >= 0 && stats.getPreferedTeamId() < numTeams ) )
437      {
438        teamChange( stats.getUserId() );
439      }
440    }
441  }
442
443  //now serve player who want join a random team
444  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
445  {
446    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
447
448    if ( stats.getTeamId() != stats.getPreferedTeamId() )
449    {
450      if ( stats.getPreferedTeamId() == TEAM_RANDOM )
451      {
452        stats.setPreferedTeamId( getRandomTeam() );
453        teamChange( stats.getUserId() );
454      }
455    }
456  }
457}
458
459void MultiplayerTeamDeathmatch::teamChange( int userId )
460{
461  assert( PlayerStats::getStats( userId ) );
462  PlayerStats & stats = *(PlayerStats::getStats( userId ));
463
464  stats.setTeamId( stats.getPreferedTeamId() );
465
466  Playable * oldPlayable = stats.getPlayable();
467
468
469  ClassID playableClassId = getPlayableClassId( userId, stats.getPreferedTeamId() );
470  std::string playableModel = getPlayableModelFileName( userId, stats.getPreferedTeamId(), playableClassId );
471
472  BaseObject * bo = Factory::fabricate( playableClassId );
473
474  assert( bo != NULL );
475  assert( bo->isA( CL_PLAYABLE ) );
476
477  Playable & playable = *(dynamic_cast<Playable*>(bo));
478
479  playable.loadModel( playableModel );
480  playable.setOwner( userId );
481  playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
482  playable.setSynchronized( true );
483
484  stats.setTeamId( stats.getPreferedTeamId() );
485  stats.setPlayableClassId( playableClassId );
486  stats.setPlayableUniqueId( playable.getUniqueID() );
487  stats.setModelFileName( playableModel );
488
489  this->respawnPlayable( &playable, stats.getPreferedTeamId(), 0.0f );
490
491  if ( oldPlayable )
492  {
493    //if ( userId == SharedNetworkData::getInstance()->getHostID() )
494    //  State::getPlayer()->setPlayable( NULL );
495    delete oldPlayable;
496  }
497}
498
499void MultiplayerTeamDeathmatch::onButtonExit( )
500{
501  State::getCurrentStoryEntity()->stop();
502  this->bShowTeamChange = false;
503}
504
505void MultiplayerTeamDeathmatch::onButtonRandom( )
506{
507  NetworkGameManager::getInstance()->prefereTeam( TEAM_RANDOM );
508  this->bShowTeamChange = false;
509}
510
511void MultiplayerTeamDeathmatch::onButtonTeam0( )
512{
513  NetworkGameManager::getInstance()->prefereTeam( 0 );
514  this->bShowTeamChange = false;
515}
516
517void MultiplayerTeamDeathmatch::onButtonTeam1( )
518{
519  NetworkGameManager::getInstance()->prefereTeam( 1 );
520  this->bShowTeamChange = false;
521}
522
523void MultiplayerTeamDeathmatch::onButtonSpectator( )
524{
525  NetworkGameManager::getInstance()->prefereTeam( TEAM_SPECTATOR );
526  this->bShowTeamChange = false;
527}
528
529void MultiplayerTeamDeathmatch::assignPlayable( )
530{
531  if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) )
532    PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPlayable();
533}
534
535  /**
536   * function that processes events from the handler
537   * @param event: the event
538   * @todo replace SDLK_o with something from KeyMapper
539   */
540void MultiplayerTeamDeathmatch::process( const Event & event )
541{
542  if ( event.type == SDLK_o )
543  {
544    if ( event.bPressed )
545      this->bShowTeamChange = true;
546  } else if ( event.type == SDLK_F1 )
547  {
548    if ( !this->statsBox && event.bPressed )
549    {
550      PRINTF(0)("show stats\n");
551      this->showStats();
552    }
553    if ( this->statsBox && !this->bLocalPlayerDead && event.bPressed && this->table->rowCount() != 0 && this->table->columnCount() != 0 )
554    {
555      PRINTF(0)("hide stats\n");
556      this->hideStats();
557    }
558  }
559  else if ( event.type == SDLK_TAB )
560  {
561    if ( currentGameState == GAMESTATE_GAME && !event.bPressed && !EventHandler::getInstance()->isPressed( SDLK_RALT ) && !EventHandler::getInstance()->isPressed( SDLK_LALT ) )
562    {
563      EventHandler::getInstance()->pushState( ES_MENU );
564      OrxGui::GLGuiHandler::getInstance()->activateCursor();
565      OrxGui::GLGuiHandler::getInstance()->deactivateCursor();
566      input->show();
567      input->giveMouseFocus();
568      input->setText("say ");
569    }
570  }
571  else if ( this->bLocalPlayerDead && statsBox && event.type == KeyMapper::PEV_FIRE1 )
572  {
573    this->hideStats();
574  }
575}
576
577void MultiplayerTeamDeathmatch::onButtonCancel( )
578{
579  this->bShowTeamChange = false;
580}
581
582
583
584/**
585 * this method is called by NetworkGameManger when he recieved a chat message
586 * @param userId senders user id
587 * @param message message string
588 * @param messageType some int
589 */
590void MultiplayerTeamDeathmatch::handleChatMessage( int userId, const std::string & message, int messageType )
591{
592  std::string name = "unknown";
593
594  if ( PlayerStats::getStats( userId ) )
595  {
596    name = PlayerStats::getStats( userId )->getNickName();
597  }
598
599  PRINTF(0)("CHATMESSAGE %s (%d): %s\n", name.c_str(), userId, message.c_str() );
600  notifier->pushNotifyMessage(name + ": " + message);
601}
602
603void MultiplayerTeamDeathmatch::onInputEnter( const std::string & text )
604{
605  EventHandler::getInstance()->popState();
606  input->breakMouseFocus();
607  input->hide();
608  input->setText("");
609
610  std::string command = text;
611
612  //HACK insert " in say commands so user doesn't have to type them
613  if ( command.length() >= 4 && command[0] == 's' && command[1] == 'a' && command[2] == 'y' && command[3] == ' ' )
614  {
615    command.insert( 4, "\"" );
616    command = command + "\"";
617  }
618
619  OrxShell::ShellCommand::execute( command );
620}
621
622/**
623 * show table with frags
624 */
625void MultiplayerTeamDeathmatch::showStats( )
626{
627  EventHandler::getInstance()->pushState( ES_MENU );
628  statsBox = new OrxGui::GLGuiBox();
629  statsBox->setAbsCoor2D( 300, 100 );
630
631  this->table = new OrxGui::GLGuiTable(0,0);
632
633  statsBox->pack( this->table );
634
635  statsBox->showAll();
636}
637
638/**
639 * hide table with frags
640 */
641void MultiplayerTeamDeathmatch::hideStats( )
642{
643    if ( statsBox )
644    {
645      delete statsBox;
646      statsBox = NULL;
647    }
648
649    EventHandler::getInstance()->popState();
650}
651
652/**
653 * fill stats table with values
654 */
655void MultiplayerTeamDeathmatch::tickStatsTable( )
656{
657  if ( !this->statsBox )
658    return;
659
660  std::vector<std::string> headers;
661  headers.push_back("Red Team");
662  headers.push_back("");
663  headers.push_back("");
664  headers.push_back("Blue Team");
665  headers.push_back("");
666  this->table->setHeader(headers);
667
668  std::map<int,std::string> fragsTeam0;
669  std::map<int,std::string> fragsTeam1;
670
671  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
672
673  if ( !list )
674    return;
675
676  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
677  {
678    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
679
680    if ( stats.getTeamId() == 0 || stats.getTeamId() == 1 )
681    {
682      if ( stats.getTeamId() == 0 )
683        fragsTeam0[stats.getScore()] = stats.getNickName();
684      else
685        fragsTeam1[stats.getScore()] = stats.getNickName();
686    }
687  }
688
689  char st[10];
690  int i = 0;
691
692
693  i = 2;
694  for ( std::map<int,std::string>::const_iterator it = fragsTeam0.begin(); it != fragsTeam0.end(); it++ )
695  {
696    this->table->setEntry( 0, i, it->second );
697    snprintf( st, 10, "%d", it->first );
698    this->table->setEntry( 1, i, st );
699    this->table->setEntry( 2, i, "" );
700    i++;
701  }
702
703  i = 2;
704  for ( std::map<int,std::string>::const_iterator it = fragsTeam1.begin(); it != fragsTeam1.end(); it++ )
705  {
706    this->table->setEntry( 3, i, it->second );
707    snprintf( st, 10, "%d", it->first );
708    this->table->setEntry( 4, i, st );
709    i++;
710  }
711}
712
713/**
714 * this function is called when a player kills another one or himself
715 * @param killedUserId
716 * @param userId
717 */
718void 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 );
725
726  if ( killedUserId != userId )
727    stats.setScore( stats.getScore() + 1 );
728  else
729    stats.setScore( stats.getScore() - 1 );
730
731  if ( killedUserId == SharedNetworkData::getInstance()->getHostID() )
732  {
733    this->bLocalPlayerDead = true;
734    this->showStats();
735  }
736
737  this->respawnPlayable( killedStats.getPlayable(), killedStats.getTeamId(), 3.0f );
738}
739
740/**
741 * this function is called on player respawn
742 * @param userId
743 */
744void MultiplayerTeamDeathmatch::onRespawn( int userId )
745{
746  if ( userId == SharedNetworkData::getInstance()->getHostID() )
747  {
748    this->bLocalPlayerDead = false;
749    this->hideStats();
750  }
751}
752
753/**
754 * this function is called on player respawn
755 * @param we
756 */
757void MultiplayerTeamDeathmatch::registerSpawn( WorldEntity * we )
758{
759  onRespawn( we->getOwner() );
760}
761
762
763void MultiplayerTeamDeathmatch::respawnPlayable( Playable * playable, int teamId, float delay )
764{
765  const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT );
766
767  assert( list );
768
769  std::vector<SpawningPoint*> spList;
770
771  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
772  {
773    SpawningPoint * sp = dynamic_cast<SpawningPoint*>(*it);
774
775    if ( sp->getTeamId() == teamId )
776      spList.push_back( sp );
777  }
778
779  if ( spList.size() == 0 )
780  {
781    for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
782    {
783      SpawningPoint * sp = dynamic_cast<SpawningPoint*>(*it);
784
785      if ( sp->getTeamId() < 0 )
786        spList.push_back( sp );
787    }
788  }
789
790  assert( spList.size() != 0 );
791
792  int n = (int)((float)spList.size() * (float)rand()/(float)RAND_MAX);
793
794  spList[n]->pushEntity( playable, delay );
795}
796
Note: See TracBrowser for help on using the repository browser.