Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/util/multiplayer_team_deathmatch.cc @ 9153

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

new model for team 1

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