SuperTuxKart
race_manager.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2006-2015 SuperTuxKart-Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_RACEMANAGER_HPP
20 #define HEADER_RACEMANAGER_HPP
21 
29 #include <vector>
30 #include <algorithm>
31 #include <string>
32 
34 #include "race/grand_prix_data.hpp"
35 #include "utils/vec3.hpp"
36 
37 class AbstractKart;
38 class NetworkString;
39 class SavedGrandPrix;
40 class Track;
41 
42 static const std::string IDENT_STD ("STANDARD" );
43 static const std::string IDENT_TTRIAL ("STD_TIMETRIAL" );
44 static const std::string IDENT_FTL ("FOLLOW_LEADER" );
45 static const std::string IDENT_STRIKES ("BATTLE_3_STRIKES");
46 static const std::string IDENT_FFA ("BATTLE_FFA" );
47 static const std::string IDENT_CTF ("BATTLE_CTF" );
48 static const std::string IDENT_EASTER ("EASTER_EGG_HUNT" );
49 static const std::string IDENT_SOCCER ("SOCCER" );
50 static const std::string IDENT_GHOST ("GHOST" );
51 static const std::string IDENT_OVERWORLD("OVERWORLD" );
52 static const std::string IDENT_CUTSCENE ("CUTSCENE" );
53 static const std::string IDENT_LAP_TRIAL("LAP_TRIAL" );
54 
87 {
88 public:
92  {
93  MAJOR_MODE_GRAND_PRIX = 0,
94  MAJOR_MODE_SINGLE
95  };
96 
97  // quick method to tell the difference between battle modes and race modes
98  // think of it like a bitmask, but done in decimal to avoid endianness
99  // issues
100 #define LINEAR_RACE(ID, COUNT_LAPSES) (1000+ID+100*COUNT_LAPSES)
101 #define BATTLE_ARENA(ID) (2000+ID)
102 #define EASTER_EGG(ID) (3000+ID)
103 #define MISC(ID) (4000+ID)
104 
105  // ----------------------------------------------------------------------------------------
109  {
110  MINOR_MODE_NONE = -1,
111 
112  MINOR_MODE_NORMAL_RACE = LINEAR_RACE(0, true),
113  MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1, true),
114  MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false),
115 
116  MINOR_MODE_3_STRIKES = BATTLE_ARENA(0),
117  MINOR_MODE_FREE_FOR_ALL = BATTLE_ARENA(1),
118  MINOR_MODE_CAPTURE_THE_FLAG = BATTLE_ARENA(2),
119  MINOR_MODE_SOCCER = BATTLE_ARENA(3),
120 
121  MINOR_MODE_EASTER_EGG = EASTER_EGG(0),
122 
123  MINOR_MODE_OVERWORLD = MISC(0),
124  MINOR_MODE_TUTORIAL = MISC(1),
125  MINOR_MODE_CUTSCENE = MISC(2),
126  MINOR_MODE_LAP_TRIAL = MISC(3)
127  };
128 
129  // ----------------------------------------------------------------------------------------
133  {
134  SUPERPOWER_NONE = 0,
135  SUPERPOWER_NOLOK_BOSS = 1
136  };
137 
138  // ----------------------------------------------------------------------------------------
142  static const std::string& getIdentOf(const MinorRaceModeType mode)
143  {
144  switch (mode)
145  {
146  case MINOR_MODE_NORMAL_RACE: return IDENT_STD;
147  case MINOR_MODE_TIME_TRIAL: return IDENT_TTRIAL;
148  case MINOR_MODE_FOLLOW_LEADER: return IDENT_FTL;
149  case MINOR_MODE_LAP_TRIAL: return IDENT_LAP_TRIAL;
150  case MINOR_MODE_3_STRIKES: return IDENT_STRIKES;
151  case MINOR_MODE_FREE_FOR_ALL: return IDENT_FFA;
152  case MINOR_MODE_CAPTURE_THE_FLAG: return IDENT_CTF;
153  case MINOR_MODE_EASTER_EGG: return IDENT_EASTER;
154  case MINOR_MODE_SOCCER: return IDENT_SOCCER;
155  default: assert(false);
156  return IDENT_STD; // stop compiler warning
157  }
158  } // getIdentOf
159 
160  // ----------------------------------------------------------------------------------------
164  static const char* getIconOf(const MinorRaceModeType mode)
165  {
166  switch (mode)
167  {
168  case MINOR_MODE_NORMAL_RACE: return "/gui/icons/mode_normal.png";
169  case MINOR_MODE_TIME_TRIAL: return "/gui/icons/mode_tt.png";
170  case MINOR_MODE_FOLLOW_LEADER: return "/gui/icons/mode_ftl.png";
171  case MINOR_MODE_LAP_TRIAL: return "/gui/icons/mode_normal.png"; // TODO: Add lap trial icon
172  case MINOR_MODE_3_STRIKES: return "/gui/icons/mode_3strikes.png";
173  case MINOR_MODE_FREE_FOR_ALL: return "/gui/icons/mode_weapons.png";
174  case MINOR_MODE_CAPTURE_THE_FLAG: return "/gui/icons/mode_weapons.png";
175  case MINOR_MODE_EASTER_EGG: return "/gui/icons/mode_easter.png";
176  case MINOR_MODE_SOCCER: return "/gui/icons/mode_soccer.png";
177  default: assert(false); return NULL;
178  }
179  } // getIconOf
180 
181  // ----------------------------------------------------------------------------------------
182  static const core::stringw getNameOf(const MinorRaceModeType mode);
183  // ----------------------------------------------------------------------------------------
185  bool hasAI()
186  {
187  switch (m_minor_mode)
188  {
189  case MINOR_MODE_NORMAL_RACE: return true;
190  case MINOR_MODE_TIME_TRIAL: return true;
191  case MINOR_MODE_FOLLOW_LEADER: return true;
192  case MINOR_MODE_LAP_TRIAL: return true;
193  case MINOR_MODE_3_STRIKES: return true;
194  case MINOR_MODE_FREE_FOR_ALL: return false;
195  case MINOR_MODE_CAPTURE_THE_FLAG: return false;
196  case MINOR_MODE_EASTER_EGG: return false;
197  case MINOR_MODE_SOCCER: return true;
198  default: assert(false); return false;
199  }
200  } // hasAI
201 
202 
203  // ----------------------------------------------------------------------------------------
209  const std::string &name)
210  {
211  if (name==IDENT_STD ) return MINOR_MODE_NORMAL_RACE;
212  else if (name==IDENT_TTRIAL ) return MINOR_MODE_TIME_TRIAL;
213  else if (name==IDENT_FTL ) return MINOR_MODE_FOLLOW_LEADER;
214  else if (name==IDENT_STRIKES) return MINOR_MODE_3_STRIKES;
215  else if (name==IDENT_FFA) return MINOR_MODE_FREE_FOR_ALL;
216  else if (name==IDENT_CTF) return MINOR_MODE_CAPTURE_THE_FLAG;
217  else if (name==IDENT_EASTER ) return MINOR_MODE_EASTER_EGG;
218  else if (name==IDENT_SOCCER) return MINOR_MODE_SOCCER;
219 
220  assert(0);
221  return MINOR_MODE_NONE;
222  }
223 
224 #undef LINEAR_RACE
225 #undef BATTLE_ARENA
226 #undef MISC
227 
229  enum Difficulty { DIFFICULTY_EASY = 0,
230  DIFFICULTY_FIRST = DIFFICULTY_EASY,
231  DIFFICULTY_MEDIUM,
232  DIFFICULTY_HARD,
233  DIFFICULTY_BEST,
234  DIFFICULTY_LAST = DIFFICULTY_BEST,
235  DIFFICULTY_COUNT,
236  DIFFICULTY_NONE};
237 
241  enum KartType { KT_PLAYER, KT_NETWORK_PLAYER, KT_AI, KT_LEADER,
242  KT_GHOST, KT_SPARE_TIRE };
243 private:
244 
245  bool m_started_from_overworld;
246 
247 public:
248 
251  struct KartStatus
252  {
254  std::string m_ident;
256  std::string m_player_name;
257  // Score for this kart. */
258  int m_score;
264  float m_last_time;
279  float m_color;
280  KartStatus(const std::string& ident, const int& prev_finish_pos,
281  int local_player_id, int global_player_id,
282  int init_gp_rank, KartType kt,
283  HandicapLevel handicap) :
284  m_ident(ident), m_score(0), m_last_score(0),
285  m_overall_time(0.0f), m_last_time(0.0f),
286  m_kart_type(kt),
287  m_local_player_id(local_player_id),
288  m_global_player_id(global_player_id),
289  m_gp_rank(init_gp_rank), m_handicap(handicap)
290  { m_boosted_ai = false; m_color = 0.0f; }
291 
292  }; // KartStatus
293 private:
294 
296  std::vector<KartStatus> m_kart_status;
297 
300 
303 
307  std::vector<RemoteKartInfo> m_player_karts;
308  std::vector<std::string> m_tracks;
309 
311  unsigned int m_num_local_players;
312 
315  std::vector<int> m_num_laps;
316 
318  std::vector<bool> m_reverse_track;
319 
321  std::vector<std::string> m_default_ai_list;
322 
324  std::string m_ai_kart_override;
325 
326  AISuperPower m_ai_superpower;
327 
330  std::vector<std::string> m_ai_kart_list;
331  int m_track_number;
332  GrandPrixData m_grand_prix;
333  SavedGrandPrix* m_saved_gp;
334  int m_num_karts;
335  unsigned int m_num_red_ai;
336  unsigned int m_num_blue_ai;
337  unsigned int m_num_ghost_karts;
338  unsigned int m_num_spare_tire_karts;
339  unsigned int m_num_finished_karts;
340  unsigned int m_num_finished_players;
341  unsigned m_flag_return_ticks;
342  unsigned m_flag_deactivated_ticks;
343  int m_coin_target;
344  float m_time_target;
345  int m_goal_target;
346  int m_hit_capture_limit;
347  int m_skipped_tracks_in_gp;
352  void startNextRace(); // start a next race
353 
354  friend bool operator< (const KartStatus& left, const KartStatus& right)
355  {
356  return (left.m_score < right.m_score) ||
357  (left.m_score == right.m_score &&
358  left.m_overall_time > right.m_overall_time);
359  }
360 
361  bool m_have_kart_last_position_on_overworld;
362  Vec3 m_kart_last_position_on_overworld;
363 
366 
367  bool m_is_recording_race;
368 
369  bool m_has_ghost_karts;
370 
371  bool m_watching_replay;
372 public:
373  // ----------------------------------------------------------------------------------------
374  static RaceManager* get();
375  // ----------------------------------------------------------------------------------------
376  static void create();
377  // ----------------------------------------------------------------------------------------
378  static void destroy();
379  // ----------------------------------------------------------------------------------------
380  static void clear();
381  // ----------------------------------------------------------------------------------------
382  RaceManager();
383  ~RaceManager();
384 
385  void reset();
386  void setPlayerKart(unsigned int player_id, const std::string &kart_name);
387  void setPlayerKart(unsigned int player_id,
388  const RemoteKartInfo& ki);
389 
392  void setKartTeam(unsigned int player_id, KartTeam team);
393 
396  void setPlayerHandicap(unsigned int player_id, HandicapLevel handicap);
397 
401  void setTrack(const std::string& track);
402 
407  const AbstractKart* getKartWithGPRank(unsigned int n);
408 
411  int getLocalPlayerGPRank(const int playerID) const;
412 
413 
418  void computeGPRanks();
419 
423  void setDifficulty(Difficulty diff);
424  static Difficulty convertDifficulty(const std::string &difficulty);
425  void startNew(bool from_overworld);
426  void next();
427  void rerunRace();
428  void exitRace(bool delete_world=true);
429  void startGP(const GrandPrixData &gp, bool from_overworld,
430  bool continue_saved_gp);
431  void saveGP();
432  void startSingleRace(const std::string &track_ident, const int num_laps,
433  bool from_overworld);
434  void startWatchingReplay(const std::string &track_ident, const int num_laps);
435  void setupPlayerKartInfo();
436  void kartFinishedRace(const AbstractKart* kart, float time);
437  void setNumPlayers(int players, int local_players=-1);
438  void setDefaultAIKartList(const std::vector<std::string> &ai_list);
439  void computeRandomKartList();
440 
441  // ----------------------------------------------------------------------------------------
442  bool hasTimeTarget() const { return m_time_target > 0.0f; }
443  // ----------------------------------------------------------------------------------------
444  void setMaxGoal(int max_goal)
445  {
446  m_time_target = 0.0f;
447  m_goal_target = max_goal;
448  } // setMaxGoal
449  // ----------------------------------------------------------------------------------------
450  int getMaxGoal(){ return m_goal_target; }
451  // ----------------------------------------------------------------------------------------
452  void setCoinTarget(int num) { m_coin_target = num; }
453  // ----------------------------------------------------------------------------------------
454  void setGrandPrix(const GrandPrixData &gp)
455  {
456  m_grand_prix = gp;
457  setCoinTarget(0);
458  } // setGrandPrix
459  // ----------------------------------------------------------------------------------------
460  void setAIKartOverride(const std::string& kart)
461  {
462  m_ai_kart_override = kart;
463  } // setAIKartOverride
464  // ----------------------------------------------------------------------------------------
465  void setAISuperPower(AISuperPower superpower)
466  {
467  m_ai_superpower = superpower;
468  } // setAISuperPower
469  // ----------------------------------------------------------------------------------------
470  AISuperPower getAISuperPower() const { return m_ai_superpower; }
471  // ----------------------------------------------------------------------------------------
472  void setNumLaps(int num)
473  {
474  m_num_laps.clear();
475  m_num_laps.push_back(num);
476  } // setNumLaps
477  // ----------------------------------------------------------------------------------------
478  void setReverseTrack(bool r_t)
479  {
480  m_reverse_track.clear();
481  m_reverse_track.push_back(r_t);
482  } // setReverseTrack
483  // ----------------------------------------------------------------------------------------
484  void setMajorMode(MajorRaceModeType mode) { m_major_mode = mode; }
485  // ----------------------------------------------------------------------------------------
486  void setMinorMode(MinorRaceModeType mode)
487  {
488  m_minor_mode = mode;
489  } // setMinorMode
490  // ----------------------------------------------------------------------------------------
491  void setNumKarts(int num)
492  {
493  m_num_karts = num;
494  m_ai_kart_override = "";
495  m_ai_superpower = SUPERPOWER_NONE;
496  } // setNumKarts
497  // ----------------------------------------------------------------------------------------
498  void setNumRedAI(unsigned int num)
499  {
500  m_num_red_ai = num;
501  } // setNumRedAI
502  // ----------------------------------------------------------------------------------------
503  void setNumBlueAI(unsigned int num)
504  {
505  m_num_blue_ai = num;
506  } // setNumBlueAI
507  // ----------------------------------------------------------------------------------------
508  void setTimeTarget(float time)
509  {
510  m_goal_target = 0;
511  m_time_target = time;
512  } // setTimeTarget
513  // ----------------------------------------------------------------------------------------
514  RemoteKartInfo& getKartInfo(unsigned int n)
515  {
516  return m_player_karts[n];
517  } // getKartInfo
518  // ----------------------------------------------------------------------------------------
519  unsigned int getNumLocalPlayers() const
520  {
521  return m_num_local_players;
522  } // getNumLocalPlayers
523 
524  // ----------------------------------------------------------------------------------------
529  {
530  const float sqrt_num_players = sqrtf((float)getNumLocalPlayers());
531  const int rows = (int)ceil(sqrt_num_players);
532  const int cols = (int)round(sqrt_num_players);
533  const int total_spaces = rows * cols;
534  return (total_spaces - getNumLocalPlayers() > 0);
535  } // getIfEmptyScreenSpaceExists
536  // ----------------------------------------------------------------------------------------
539  unsigned int getNumberOfKarts() const { return m_num_karts; }
540  // ----------------------------------------------------------------------------------------
541  unsigned int getNumberOfAIKarts() const
542  {
543  return (unsigned int)m_ai_kart_list.size();
544  } // getNumberOfAIKarts
545  // ----------------------------------------------------------------------------------------
546  unsigned int getNumberOfRedAIKarts() const { return m_num_red_ai; }
547  // ----------------------------------------------------------------------------------------
548  unsigned int getNumberOfBlueAIKarts() const { return m_num_blue_ai; }
549  // ----------------------------------------------------------------------------------------
550  unsigned int getNumNonGhostKarts() const
551  { return m_num_karts - m_num_ghost_karts; }
552  // ----------------------------------------------------------------------------------------
553  MajorRaceModeType getMajorMode() const { return m_major_mode; }
554  // ----------------------------------------------------------------------------------------
555  MinorRaceModeType getMinorMode() const { return m_minor_mode; }
556  // ----------------------------------------------------------------------------------------
557  std::string getMinorModeName() const
558  {
559  switch (m_minor_mode)
560  {
561  case MINOR_MODE_NORMAL_RACE: return "normal";
562  case MINOR_MODE_TIME_TRIAL: return "time-trial";
563  case MINOR_MODE_FOLLOW_LEADER: return "follow-the-leader";
564  case MINOR_MODE_3_STRIKES: return "battle";
565  case MINOR_MODE_FREE_FOR_ALL: return "ffa";
566  case MINOR_MODE_CAPTURE_THE_FLAG: return "ctf";
567  case MINOR_MODE_EASTER_EGG: return "egg-hunt";
568  case MINOR_MODE_SOCCER: return "soccer";
569  default: assert(false); return "";
570  }
571  }
572  // ----------------------------------------------------------------------------------------
573  unsigned int getNumPlayers() const
574  {
575  return (unsigned int) m_player_karts.size();
576  } // getNumPlayers
577  // ----------------------------------------------------------------------------------------
584  int getNumLaps() const
585  {
586  if(modeHasLaps())
587  return m_num_laps[m_track_number];
588  // else
589  return 9999;
590  } // getNumLaps
591  // ----------------------------------------------------------------------------------------
593  bool getReverseTrack() const { return m_reverse_track[m_track_number]; }
594  // ----------------------------------------------------------------------------------------
597  // ----------------------------------------------------------------------------------------
599  std::string getDifficultyAsString(Difficulty diff) const
600  {
601  switch(diff)
602  {
603  case RaceManager::DIFFICULTY_EASY: return "easy"; break;
604  case RaceManager::DIFFICULTY_MEDIUM: return "medium"; break;
605  case RaceManager::DIFFICULTY_HARD: return "hard"; break;
606  case RaceManager::DIFFICULTY_BEST: return "best"; break;
607  default: assert(false);
608  }
609  return "";
610  } // getDifficultyAsString
611 
612  // ----------------------------------------------------------------------------------------
613  core::stringw getDifficultyName(Difficulty diff) const;
614  // ----------------------------------------------------------------------------------------
615  const std::string getTrackName() const
616  {
617  if (m_tracks.empty())
618  return "";
619  return m_tracks[m_track_number];
620  }
621  // ----------------------------------------------------------------------------------------
622  const GrandPrixData& getGrandPrix() const { return m_grand_prix; }
623  // ----------------------------------------------------------------------------------------
624  unsigned int getFinishedKarts() const { return m_num_finished_karts; }
625  // ----------------------------------------------------------------------------------------
626  unsigned int getFinishedPlayers() const { return m_num_finished_players; }
627  // ----------------------------------------------------------------------------------------
628  int getKartGPRank(const int kart_id)const
629  {
630  return m_kart_status[kart_id].m_gp_rank;
631  } // getKartGPRank
632  // ----------------------------------------------------------------------------------------
633  const std::string& getKartIdent(int kart) const
634  {
635  return m_kart_status[kart].m_ident;
636  } // getKartIdent
637  // ----------------------------------------------------------------------------------------
638  int getKartScore(int krt) const { return m_kart_status[krt].m_score; }
639  // ----------------------------------------------------------------------------------------
640  int getKartPrevScore(int krt) const
641  {
642  return m_kart_status[krt].m_last_score;
643  } // getKartPrevScore
644  // ----------------------------------------------------------------------------------------
645  int getKartLocalPlayerId(int k) const
646  {
647  return m_kart_status[k].m_local_player_id;
648  } // getKartLocalPlayerId
649  // ----------------------------------------------------------------------------------------
650  int getKartGlobalPlayerId(int k) const
651  {
652  return m_kart_status[k].m_global_player_id;
653  } // getKartGlobalPlayerId
654  // ----------------------------------------------------------------------------------------
655  float getOverallTime(int kart) const
656  {
657  return m_kart_status[kart].m_overall_time;
658  } // getOverallTime
659  // ----------------------------------------------------------------------------------------
660  float getKartRaceTime(int kart) const
661  {
662  return m_kart_status[kart].m_last_time;
663  } // getKartRaceTime
664  // ----------------------------------------------------------------------------------------
665  KartType getKartType(int kart) const
666  {
667  return m_kart_status[kart].m_kart_type;
668  } // getKartType
669  // ----------------------------------------------------------------------------------------
670  HandicapLevel getPlayerHandicap(int kart) const
671  {
672  return m_kart_status[kart].m_handicap;
673  } // getPlayerHandicap
674  // ----------------------------------------------------------------------------------------
675  bool hasBoostedAI(int kart) const
676  {
677  return m_kart_status[kart].m_boosted_ai;
678  } // getKartRaceTime
679  // ----------------------------------------------------------------------------------------
680  void setKartColor(int kart, float color)
681  {
682  m_kart_status[kart].m_color = color;
683  } // setKartColor
684  // ----------------------------------------------------------------------------------------
685  float getKartColor(int kart) const
686  {
687  return m_kart_status[kart].m_color;
688  } // getKartColor
689  // ----------------------------------------------------------------------------------------
690  int getCoinTarget() const { return m_coin_target; }
691  // ----------------------------------------------------------------------------------------
692  float getTimeTarget() const { return m_time_target; }
693  // ----------------------------------------------------------------------------------------
694  int getTrackNumber() const { return m_track_number; }
695  // ----------------------------------------------------------------------------------------
696  int getNumOfTracks() const { return (int)m_tracks.size(); }
697  // ----------------------------------------------------------------------------------------
700  const std::vector<std::string>& getAIKartList() const
701  {
702  return m_ai_kart_list;
703  } // getAIKartList
704  // ----------------------------------------------------------------------------------------
707  bool isLinearRaceMode() const
708  {
709  const int id = (int)m_minor_mode;
710  // info is stored in its ID for conveniance, see the macros LINEAR_RACE
711  // and BATTLE_ARENA above for exact meaning.
712  if(id > 999 && id < 2000) return true;
713  else return false;
714  } // isLinearRaceMode
715 
716  // ----------------------------------------------------------------------------------------
719  bool isLinearRaceMode(const MinorRaceModeType mode) const
720  {
721  const int id = (int)mode;
722  // info is stored in its ID for conveniance, see the macros LINEAR_RACE
723  // and BATTLE_ARENA above for exact meaning.
724  if(id > 999 && id < 2000) return true;
725  else return false;
726  } // isLinearRaceMode
727 
728  // ----------------------------------------------------------------------------------------
730  bool isBattleMode() const
731  {
732  const int id = (int)m_minor_mode;
733  // This uses the numerical id of the mode, see the macros
734  // LINEAR_RACE and BATTLE_ARENA above for exact meaning.
735  if (id >= 2000 && id <= 2002) return true;
736  else return false;
737  } // isBattleMode
738 
739  // ----------------------------------------------------------------------------------------
741  bool isSoccerMode() const
742  {
743  const int id = (int)m_minor_mode;
744  // This uses the numerical id of the mode, see the macros
745  // LINEAR_RACE and BATTLE_ARENA above for exact meaning.
746  if (id == 2003) return true;
747  else return false;
748  } // isSoccerMode
749 
750  // ----------------------------------------------------------------------------------------
751  bool isTutorialMode() const { return m_minor_mode == MINOR_MODE_TUTORIAL; }
752 
753  // ----------------------------------------------------------------------------------------
754  bool isFollowMode() const { return m_minor_mode == MINOR_MODE_FOLLOW_LEADER; }
755 
756  // ----------------------------------------------------------------------------------------
757  bool isCTFMode() const { return m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG; }
758 
759  // ----------------------------------------------------------------------------------------
760  bool isEggHuntMode() const { return m_minor_mode == MINOR_MODE_EASTER_EGG; }
761 
762  // ----------------------------------------------------------------------------------------
763  bool isTimeTrialMode() const { return m_minor_mode == MINOR_MODE_TIME_TRIAL; }
764  // ----------------------------------------------------------------------------------------
765  bool isLapTrialMode() const { return m_minor_mode == MINOR_MODE_LAP_TRIAL; }
766  // ----------------------------------------------------------------------------------------
769  {
770  return 3; // display milliseconds
771  } // currentModeTimePrecision
772  // ----------------------------------------------------------------------------------------
774  bool modeHasLaps() const
775  {
776  if (!isLinearRaceMode()) return false;
777  const int id = (int)m_minor_mode;
778  // See meaning of IDs above
779  const int answer = (id-1000)/100;
780  return answer!=0;
781  } // modeHasLaps
782  // ----------------------------------------------------------------------------------------
785  {
786  //FIXME: this information is duplicated. RaceManager knows about it,
787  // and each World may set m_use_highscores to true or false.
788  // The reason for this duplication is that we might want to know
789  // whether to display highscores without creating a World.
790  return !isBattleMode() &&
791  !isSoccerMode() &&
792  m_minor_mode != MINOR_MODE_FOLLOW_LEADER;
793  } // modeHasHighscore
794  // ----------------------------------------------------------------------------------------
795  bool raceWasStartedFromOverworld() const
796  {
797  return m_started_from_overworld;
798  } // raceWasStartedFromOverworld
799 
800  // ----------------------------------------------------------------------------------------
805  bool allPlayerFinished() const
806  {
807  return m_num_finished_players == m_player_karts.size();
808  } // allPlayerFinished
809  // ----------------------------------------------------------------------------------------
813  void setAIKartList(const std::vector<std::string>& rkl)
814  {
815  m_ai_kart_list = rkl;
816  } // setAIKartList
817  // ----------------------------------------------------------------------------------------
818  bool haveKartLastPositionOnOverworld()
819  {
820  return m_have_kart_last_position_on_overworld;
821  } // haveKartLastPositionOnOverworld
822  // ----------------------------------------------------------------------------------------
823  void setKartLastPositionOnOverworld(const Vec3 &pos)
824  {
825  m_have_kart_last_position_on_overworld = true;
826  m_kart_last_position_on_overworld = pos;
827  } // setKartLastPositionOnOverworld
828  // ----------------------------------------------------------------------------------------
829  void clearKartLastPositionOnOverworld()
830  {
831  m_have_kart_last_position_on_overworld = false;
832  } // clearKartLastPositionOnOverworld
833  // ----------------------------------------------------------------------------------------
834  Vec3 getKartLastPositionOnOverworld()
835  {
836  return m_kart_last_position_on_overworld;
837  } // getKartLastPositionOnOverworld
838  // ----------------------------------------------------------------------------------------
839  void setRecordRace(bool record)
840  {
841  m_is_recording_race = record;
842  } // setRecordRace
843  // ----------------------------------------------------------------------------------------
844  void setRaceGhostKarts(bool ghost)
845  {
846  m_has_ghost_karts = ghost;
847  } // setRaceGhostKarts
848  // ----------------------------------------------------------------------------------------
849  void setWatchingReplay(bool watch)
850  {
851  m_watching_replay = watch;
852  } // setWatchingReplay
853  // ----------------------------------------------------------------------------------------
854  bool isRecordingRace() const
855  {
856  return m_is_recording_race;
857  } // isRecordingRace
858  // ----------------------------------------------------------------------------------------
859  bool hasGhostKarts() const
860  {
861  return m_has_ghost_karts;
862  } // hasGhostKarts
863  // ----------------------------------------------------------------------------------------
864  bool isWatchingReplay() const
865  {
866  return m_watching_replay;
867  } // isWatchingReplay
868  // ----------------------------------------------------------------------------------------
869  void addSpareTireKart(const std::string& name)
870  {
871  m_kart_status.push_back(KartStatus(name, 0, -1, -1,
872  -1, KT_SPARE_TIRE, HANDICAP_NONE));
873  m_num_spare_tire_karts++;
874  m_num_karts++;
875  } // addSpareTireKart
876  // ----------------------------------------------------------------------------------------
877  void setSpareTireKartNum(unsigned int i)
878  {
879  m_num_spare_tire_karts = i;
880  } // setSpareTireKartNum
881  // ----------------------------------------------------------------------------------------
882  unsigned int getNumSpareTireKarts() const
883  {
884  return m_num_spare_tire_karts;
885  } // getNumSpareTireKarts
886  // ----------------------------------------------------------------------------------------
887  void configGrandPrixResultFromNetwork(NetworkString& ns);
888  // ----------------------------------------------------------------------------------------
889  void clearNetworkGrandPrixResult();
890  // ----------------------------------------------------------------------------------------
891  void setHitCaptureTime(int hc, float time)
892  {
893  m_hit_capture_limit = hc;
894  m_time_target = time;
895  }
896  // ----------------------------------------------------------------------------------------
897  int getHitCaptureLimit() const { return m_hit_capture_limit; }
898  // ----------------------------------------------------------------------------------------
899  bool teamEnabled() const
900  {
901  return m_minor_mode == MINOR_MODE_SOCCER ||
902  m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG;
903  }
904  // ----------------------------------------------------------------------------------------
905  void setFlagReturnTicks(unsigned ticks) { m_flag_return_ticks = ticks; }
906  // ----------------------------------------------------------------------------------------
907  unsigned getFlagReturnTicks() const { return m_flag_return_ticks; }
908  // ----------------------------------------------------------------------------------------
909  void setFlagDeactivatedTicks(unsigned ticks)
910  { m_flag_deactivated_ticks = ticks; }
911  // ----------------------------------------------------------------------------------------
912  unsigned getFlagDeactivatedTicks() const
913  { return m_flag_deactivated_ticks; }
914  // ----------------------------------------------------------------------------------------
915  int getSkippedTracksInGP() const { return m_skipped_tracks_in_gp; }
916  // ----------------------------------------------------------------------------------------
917  void addSkippedTrackInGP() { m_skipped_tracks_in_gp++; }
918  // ----------------------------------------------------------------------------------------
919  void setGPTimeTarget(float time_target) { m_gp_time_target = time_target; }
920  // ----------------------------------------------------------------------------------------
921  int getGPTotalLaps() const { return m_gp_total_laps; }
922  // ----------------------------------------------------------------------------------------
923  void addGPTotalLaps(int laps) { m_gp_total_laps += laps; }
924  // ----------------------------------------------------------------------------------------
927  bool supportsLiveJoining() const
928  {
929  return m_minor_mode == MINOR_MODE_SOCCER ||
930  m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG ||
931  m_minor_mode == MINOR_MODE_FREE_FOR_ALL;
932  }
933 }; // RaceManager
934 
935 #endif
936 
937 /* EOF */
int getLocalPlayerGPRank(const int playerID) const
Returns the GP rank (between 1 and number of karts) of a local player.
Definition: race_manager.cpp:255
static const core::stringw getNameOf(const MinorRaceModeType mode)
Returns a (translated) name of a minor race mode.
Definition: race_manager.cpp:1258
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:39
static const std::string & getIdentOf(const MinorRaceModeType mode)
Returns a string identifier for each minor race mode.
Definition: race_manager.hpp:142
Difficulty
Game difficulty.
Definition: race_manager.hpp:229
void saveGP()
Saves the current GP to the config.
Definition: race_manager.cpp:765
void setTrack(const std::string &track)
In case of non GP mode set the track to use.
Definition: race_manager.cpp:319
A wrapper around bullets btVector3 to include conventient conversion functions (e.g.
Definition: vec3.hpp:34
void kartFinishedRace(const AbstractKart *kart, float time)
A kart has finished the race at the specified time (which can be different from World::getWorld()->ge...
Definition: race_manager.cpp:1033
static const char * getIconOf(const MinorRaceModeType mode)
Returns the icon for a minor race mode.
Definition: race_manager.hpp:164
std::vector< bool > m_reverse_track
Whether a track should be reversed.
Definition: race_manager.hpp:318
float m_color
Kart color of player (used in gp win / lose screen).
Definition: race_manager.hpp:279
void computeRandomKartList()
Computes the list of random karts to be used for the AI.
Definition: race_manager.cpp:331
int getNumLaps() const
Returns the number lf laps.
Definition: race_manager.hpp:584
void next()
Start the next race or go back to the start screen If there are more races to do, starts the next rac...
Definition: race_manager.cpp:738
bool getIfEmptyScreenSpaceExists() const
Returns true if the split screen display leaves an empty space that can be used to display the minima...
Definition: race_manager.hpp:528
const AbstractKart * getKartWithGPRank(unsigned int n)
Returns the kart with a given GP rank (or NULL if no such kart exists).
Definition: race_manager.cpp:243
void exitRace(bool delete_world=true)
Exit a race (and don&#39;t start the next one)
Definition: race_manager.cpp:909
Definition: remote_kart_info.hpp:48
void startNew(bool from_overworld)
Starts a new race or GP (or other mode).
Definition: race_manager.cpp:382
void startSingleRace(const std::string &track_ident, const int num_laps, bool from_overworld)
Higher-level method to start a GP without having to care about the exact startup sequence.
Definition: race_manager.cpp:1102
int m_global_player_id
Global ID of player.
Definition: race_manager.hpp:270
std::vector< int > m_num_laps
The number of laps for each track of a GP (only one element is used if only a single track is used...
Definition: race_manager.hpp:315
KartType
Different kart types: A local player, a player connected via network, an AI kart, the leader kart (cu...
Definition: race_manager.hpp:241
void reset()
Resets the race manager in preparation for a new race.
Definition: race_manager.cpp:163
Difficulty m_difficulty
The selected difficulty.
Definition: race_manager.hpp:299
bool m_continue_saved_gp
Determines if saved GP should be continued or not.
Definition: race_manager.hpp:365
Difficulty getDifficulty() const
Returns the difficulty.
Definition: race_manager.hpp:596
bool isBattleMode() const
Returns true if the current mode is a battle mode.
Definition: race_manager.hpp:730
core::stringw getDifficultyName(Difficulty diff) const
Returns the specified difficulty as a string.
Definition: race_manager.cpp:1286
void setKartTeam(unsigned int player_id, KartTeam team)
Sets additional information for a player to indicate which team it belong to.
Definition: race_manager.cpp:222
void setNumPlayers(int players, int local_players=-1)
Sets the number of players and optional the number of local players.
Definition: race_manager.cpp:273
float m_gp_time_target
Time target for GP, used in Lap Trial mode.
Definition: race_manager.hpp:349
This data structure accumulates kart data and race result data from each race.
Definition: race_manager.hpp:251
static Difficulty convertDifficulty(const std::string &difficulty)
Converst the difficulty given as a string into a Difficult enum.
Definition: race_manager.cpp:292
The race manager has two functions: 1) it stores information about the race the user selected (e...
Definition: race_manager.hpp:86
void rerunRace()
Rerun the same race again This is called after a race is finished, and it will adjust the number of p...
Definition: race_manager.cpp:1066
bool modeHasLaps() const
Returns true if the current mode has laps.
Definition: race_manager.hpp:774
MinorRaceModeType m_minor_mode
The minor mode (race, time trial, ftl, battle mode).
Definition: race_manager.hpp:305
bool supportsLiveJoining() const
Whether the current game mode allow live joining even the current game
Definition: race_manager.hpp:927
bool m_boosted_ai
Boosted status (AI only).
Definition: race_manager.hpp:275
bool getReverseTrack() const
Definition: race_manager.hpp:593
void setDefaultAIKartList(const std::vector< std::string > &ai_list)
Sets the default list of AI karts to use.
Definition: race_manager.cpp:173
MajorRaceModeType m_major_mode
The major mode (single race, GP).
Definition: race_manager.hpp:302
int m_gp_rank
In GPs, at the end, will hold the overall rank of this kart (0<=m_gp_rank < num_karts-1).
Definition: race_manager.hpp:273
std::string m_ident
The kart identifier.
Definition: race_manager.hpp:254
bool hasAI()
Returns if the currently set minor game mode can be used by the AI.
Definition: race_manager.hpp:185
void setPlayerHandicap(unsigned int player_id, HandicapLevel handicap)
Sets the handicap for a player.
Definition: race_manager.cpp:232
void computeGPRanks()
Sort karts and update the m_gp_rank KartStatus member, in preparation for future calls to RaceManager...
Definition: race_manager.cpp:847
int currentModeTimePrecision() const
Returns the number of second&#39;s decimals to display.
Definition: race_manager.hpp:768
std::string m_player_name
For networked karts.
Definition: race_manager.hpp:256
float m_last_time
Needed for restart.
Definition: race_manager.hpp:264
std::vector< std::string > m_default_ai_list
The list of default AI karts to use.
Definition: race_manager.hpp:321
MajorRaceModeType
The major types or races supported in STK.
Definition: race_manager.hpp:91
std::vector< std::string > m_ai_kart_list
The list of AI karts to use.
Definition: race_manager.hpp:330
int m_last_score
Needed for restart race, and for race results GUI.
Definition: race_manager.hpp:260
int m_local_player_id
Player controling the kart, for AI: -1.
Definition: race_manager.hpp:268
std::string m_ai_kart_override
If set, specifies which kart to use for AI(s)
Definition: race_manager.hpp:324
std::vector< KartStatus > m_kart_status
The kart status data for each kart.
Definition: race_manager.hpp:296
Definition: script_track.cpp:52
void startNextRace()
Starts the next (or first) race.
Definition: race_manager.cpp:540
void startWatchingReplay(const std::string &track_ident, const int num_laps)
Function to start the race with only ghost kart(s) and watch.
Definition: race_manager.cpp:1157
bool isSoccerMode() const
Returns true if the current mode is a soccer mode.
Definition: race_manager.hpp:741
AISuperPower
True if the AI should have additional abbilities, e.g.
Definition: race_manager.hpp:132
float m_overall_time
Sum of times of all races.
Definition: race_manager.hpp:262
bool isLinearRaceMode(const MinorRaceModeType mode) const
get information about given mode (returns true if &#39;mode&#39; is of linear races type) ...
Definition: race_manager.hpp:719
const std::vector< std::string > & getAIKartList() const
Returns the list of AI karts to use.
Definition: race_manager.hpp:700
std::string getDifficultyAsString(Difficulty diff) const
Returns the specified difficulty as a string.
Definition: race_manager.hpp:599
std::vector< RemoteKartInfo > m_player_karts
Stores remote kart information about all player karts.
Definition: race_manager.hpp:307
int m_gp_total_laps
Total laps from every track, used in Lap Trial mode.
Definition: race_manager.hpp:351
RaceManager()
Constructs the race manager.
Definition: race_manager.cpp:118
MinorRaceModeType
Minor variants to the major types of race.
Definition: race_manager.hpp:108
unsigned int getNumberOfKarts() const
Returns the selected number of karts (selected number of players and AI karts.
Definition: race_manager.hpp:539
void startGP(const GrandPrixData &gp, bool from_overworld, bool continue_saved_gp)
Higher-level method to start a GP without having to care about the exact startup sequence.
Definition: race_manager.cpp:1081
bool modeHasHighscores()
Returns true if the currently selected minor mode has highscores.
Definition: race_manager.hpp:784
~RaceManager()
Destructor for the race manager.
Definition: race_manager.cpp:154
HandicapLevel m_handicap
The handicap for this player.
Definition: race_manager.hpp:277
bool isLinearRaceMode() const
get information about current mode (returns true if &#39;mode&#39; is of linear races type) ...
Definition: race_manager.hpp:707
void setAIKartList(const std::vector< std::string > &rkl)
Sets the AI to use.
Definition: race_manager.hpp:813
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message...
Definition: network_string.hpp:421
static const MinorRaceModeType getModeIDFromInternalName(const std::string &name)
Returns the minor mode id from a string identifier.
Definition: race_manager.hpp:208
KartType m_kart_type
Kart type: AI, player, network player etc.
Definition: race_manager.hpp:266
unsigned int m_num_local_players
Number of local players.
Definition: race_manager.hpp:311
Class for managing saved Grand-Prix&#39;s A list of all possible resumable GP&#39;s is stored in the user con...
Definition: saved_grand_prix.hpp:38
void setDifficulty(Difficulty diff)
Sets the difficulty.
Definition: race_manager.cpp:310
void setupPlayerKartInfo()
Fills up the remaining kart slots with AI karts.
Definition: race_manager.cpp:1146
Simple class that hold the data relevant to a &#39;grand_prix&#39;, aka.
Definition: grand_prix_data.hpp:35