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 <cassert>
32 #include <string>
33 
35 #include "race/grand_prix_data.hpp"
36 #include "utils/vec3.hpp"
37 #include "utils/types.hpp"
38 
39 class AbstractKart;
40 class NetworkString;
41 class SavedGrandPrix;
42 class Track;
43 
44 static const std::string IDENT_STD ("STANDARD" );
45 static const std::string IDENT_TTRIAL ("STD_TIMETRIAL" );
46 static const std::string IDENT_FTL ("FOLLOW_LEADER" );
47 static const std::string IDENT_STRIKES ("BATTLE_3_STRIKES");
48 static const std::string IDENT_FFA ("BATTLE_FFA" );
49 static const std::string IDENT_CTF ("BATTLE_CTF" );
50 static const std::string IDENT_EASTER ("EASTER_EGG_HUNT" );
51 static const std::string IDENT_SOCCER ("SOCCER" );
52 static const std::string IDENT_GHOST ("GHOST" );
53 static const std::string IDENT_OVERWORLD("OVERWORLD" );
54 static const std::string IDENT_CUTSCENE ("CUTSCENE" );
55 static const std::string IDENT_LAP_TRIAL("LAP_TRIAL" );
56 
89 {
90 public:
94  {
95  MAJOR_MODE_GRAND_PRIX = 0,
96  MAJOR_MODE_SINGLE
97  };
98 
99  // quick method to tell the difference between battle modes and race modes
100  // think of it like a bitmask, but done in decimal to avoid endianness
101  // issues
102 #define LINEAR_RACE(ID, COUNT_LAPSES) (1000+ID+100*COUNT_LAPSES)
103 #define BATTLE_ARENA(ID) (2000+ID)
104 #define EASTER_EGG(ID) (3000+ID)
105 #define MISC(ID) (4000+ID)
106 
107  // ----------------------------------------------------------------------------------------
111  {
112  MINOR_MODE_NONE = -1,
113 
114  MINOR_MODE_NORMAL_RACE = LINEAR_RACE(0, true),
115  MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1, true),
116  MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false),
117 
118  MINOR_MODE_3_STRIKES = BATTLE_ARENA(0),
119  MINOR_MODE_FREE_FOR_ALL = BATTLE_ARENA(1),
120  MINOR_MODE_CAPTURE_THE_FLAG = BATTLE_ARENA(2),
121  MINOR_MODE_SOCCER = BATTLE_ARENA(3),
122 
123  MINOR_MODE_EASTER_EGG = EASTER_EGG(0),
124 
125  MINOR_MODE_OVERWORLD = MISC(0),
126  MINOR_MODE_TUTORIAL = MISC(1),
127  MINOR_MODE_CUTSCENE = MISC(2),
128  MINOR_MODE_LAP_TRIAL = MISC(3)
129  };
130 
131  // ----------------------------------------------------------------------------------------
135  {
136  SUPERPOWER_NONE = 0,
137  SUPERPOWER_NOLOK_BOSS = 1
138  };
139 
140  // ----------------------------------------------------------------------------------------
144  static const std::string& getIdentOf(const MinorRaceModeType mode)
145  {
146  switch (mode)
147  {
148  case MINOR_MODE_NORMAL_RACE: return IDENT_STD;
149  case MINOR_MODE_TIME_TRIAL: return IDENT_TTRIAL;
150  case MINOR_MODE_FOLLOW_LEADER: return IDENT_FTL;
151  case MINOR_MODE_LAP_TRIAL: return IDENT_LAP_TRIAL;
152  case MINOR_MODE_3_STRIKES: return IDENT_STRIKES;
153  case MINOR_MODE_FREE_FOR_ALL: return IDENT_FFA;
154  case MINOR_MODE_CAPTURE_THE_FLAG: return IDENT_CTF;
155  case MINOR_MODE_EASTER_EGG: return IDENT_EASTER;
156  case MINOR_MODE_SOCCER: return IDENT_SOCCER;
157  default: assert(false);
158  return IDENT_STD; // stop compiler warning
159  }
160  } // getIdentOf
161 
162  // ----------------------------------------------------------------------------------------
166  static const char* getIconOf(const MinorRaceModeType mode)
167  {
168  switch (mode)
169  {
170  case MINOR_MODE_NORMAL_RACE: return "/gui/icons/mode_normal.png";
171  case MINOR_MODE_TIME_TRIAL: return "/gui/icons/mode_tt.png";
172  case MINOR_MODE_FOLLOW_LEADER: return "/gui/icons/mode_ftl.png";
173  case MINOR_MODE_LAP_TRIAL: return "/gui/icons/mode_laptrial.png";
174  case MINOR_MODE_3_STRIKES: return "/gui/icons/mode_3strikes.png";
175  case MINOR_MODE_FREE_FOR_ALL: return "/gui/icons/mode_weapons.png";
176  case MINOR_MODE_CAPTURE_THE_FLAG: return "/gui/icons/mode_weapons.png";
177  case MINOR_MODE_EASTER_EGG: return "/gui/icons/mode_easter.png";
178  case MINOR_MODE_SOCCER: return "/gui/icons/mode_soccer.png";
179  default: assert(false); return NULL;
180  }
181  } // getIconOf
182 
183  // ----------------------------------------------------------------------------------------
184  static const core::stringw getNameOf(const MinorRaceModeType mode);
185  // ----------------------------------------------------------------------------------------
187  bool hasAI()
188  {
189  switch (m_minor_mode)
190  {
191  case MINOR_MODE_NORMAL_RACE: return true;
192  case MINOR_MODE_TIME_TRIAL: return true;
193  case MINOR_MODE_FOLLOW_LEADER: return true;
194  case MINOR_MODE_LAP_TRIAL: return true;
195  case MINOR_MODE_3_STRIKES: return true;
196  case MINOR_MODE_FREE_FOR_ALL: return false;
197  case MINOR_MODE_CAPTURE_THE_FLAG: return false;
198  case MINOR_MODE_EASTER_EGG: return false;
199  case MINOR_MODE_SOCCER: return true;
200  default: assert(false); return false;
201  }
202  } // hasAI
203 
204 
205  // ----------------------------------------------------------------------------------------
211  const std::string &name)
212  {
213  if (name==IDENT_STD ) return MINOR_MODE_NORMAL_RACE;
214  else if (name==IDENT_TTRIAL ) return MINOR_MODE_TIME_TRIAL;
215  else if (name==IDENT_FTL ) return MINOR_MODE_FOLLOW_LEADER;
216  else if (name==IDENT_STRIKES) return MINOR_MODE_3_STRIKES;
217  else if (name==IDENT_FFA) return MINOR_MODE_FREE_FOR_ALL;
218  else if (name==IDENT_CTF) return MINOR_MODE_CAPTURE_THE_FLAG;
219  else if (name==IDENT_EASTER ) return MINOR_MODE_EASTER_EGG;
220  else if (name==IDENT_SOCCER) return MINOR_MODE_SOCCER;
221 
222  assert(0);
223  return MINOR_MODE_NONE;
224  }
225 
226 #undef LINEAR_RACE
227 #undef BATTLE_ARENA
228 #undef MISC
229 
231  enum Difficulty { DIFFICULTY_EASY = 0,
232  DIFFICULTY_FIRST = DIFFICULTY_EASY,
233  DIFFICULTY_MEDIUM,
234  DIFFICULTY_HARD,
235  DIFFICULTY_BEST,
236  DIFFICULTY_LAST = DIFFICULTY_BEST,
237  DIFFICULTY_COUNT,
238  DIFFICULTY_NONE};
239 
243  enum KartType { KT_PLAYER, KT_NETWORK_PLAYER, KT_AI, KT_LEADER,
244  KT_GHOST, KT_SPARE_TIRE };
245 private:
246 
247  bool m_started_from_overworld;
248 
249 public:
250 
253  struct KartStatus
254  {
256  std::string m_ident;
258  std::string m_player_name;
259  // Score for this kart. */
260  int m_score;
266  float m_last_time;
281  float m_color;
282  KartStatus(const std::string& ident, const int& prev_finish_pos,
283  int local_player_id, int global_player_id,
284  int init_gp_rank, KartType kt,
285  HandicapLevel handicap) :
286  m_ident(ident), m_score(0), m_last_score(0),
287  m_overall_time(0.0f), m_last_time(0.0f),
288  m_kart_type(kt),
289  m_local_player_id(local_player_id),
290  m_global_player_id(global_player_id),
291  m_gp_rank(init_gp_rank), m_handicap(handicap)
292  { m_boosted_ai = false; m_color = 0.0f; }
293 
294  }; // KartStatus
295 private:
296 
298  std::vector<KartStatus> m_kart_status;
299 
302 
305 
309  std::vector<RemoteKartInfo> m_player_karts;
310  std::vector<std::string> m_tracks;
311 
313  unsigned int m_num_local_players;
314 
317  std::vector<int> m_num_laps;
318 
320  // This is uint8_t instead of bool because of GitHub issue #5053
321  std::vector<uint8_t> m_reverse_track;
322 
324  std::vector<std::string> m_default_ai_list;
325 
327  std::string m_ai_kart_override;
328 
329  AISuperPower m_ai_superpower;
330 
333  std::vector<std::string> m_ai_kart_list;
334  int m_track_number;
335  GrandPrixData m_grand_prix;
336  SavedGrandPrix* m_saved_gp;
337  int m_num_karts;
338  unsigned int m_num_red_ai;
339  unsigned int m_num_blue_ai;
340  unsigned int m_num_ghost_karts;
341  unsigned int m_num_spare_tire_karts;
342  unsigned int m_num_finished_karts;
343  unsigned int m_num_finished_players;
344  unsigned m_flag_return_ticks;
345  unsigned m_flag_deactivated_ticks;
346  int m_coin_target;
347  float m_time_target;
348  int m_goal_target;
349  int m_hit_capture_limit;
350  int m_skipped_tracks_in_gp;
355  void startNextRace(); // start a next race
356 
357  friend bool operator< (const KartStatus& left, const KartStatus& right)
358  {
359  return (left.m_score < right.m_score) ||
360  (left.m_score == right.m_score &&
361  left.m_overall_time > right.m_overall_time);
362  }
363 
364  bool m_have_kart_last_position_on_overworld;
365  Vec3 m_kart_last_position_on_overworld;
366 
369  bool m_is_recording_race;
370  bool m_has_ghost_karts;
371  bool m_watching_replay;
372  bool m_benchmarking;
373  bool m_scheduled_benchmark;
374 
375 public:
376  // ----------------------------------------------------------------------------------------
377  static RaceManager* get();
378  // ----------------------------------------------------------------------------------------
379  static void create();
380  // ----------------------------------------------------------------------------------------
381  static void destroy();
382  // ----------------------------------------------------------------------------------------
383  static void clear();
384  // ----------------------------------------------------------------------------------------
385  RaceManager();
386  ~RaceManager();
387 
388  void reset();
389  void setPlayerKart(unsigned int player_id, const std::string &kart_name);
390  void setPlayerKart(unsigned int player_id,
391  const RemoteKartInfo& ki);
392 
395  void setKartTeam(unsigned int player_id, KartTeam team);
396 
399  void setPlayerHandicap(unsigned int player_id, HandicapLevel handicap);
400 
404  void setTrack(const std::string& track);
405 
410  const AbstractKart* getKartWithGPRank(unsigned int n);
411 
414  int getLocalPlayerGPRank(const int playerID) const;
415 
416 
421  void computeGPRanks();
422 
426  void setDifficulty(Difficulty diff);
427  static Difficulty convertDifficulty(const std::string &difficulty);
428  void startNew(bool from_overworld);
429  void next();
430  void rerunRace();
431  void exitRace(bool delete_world=true);
432  void startGP(const GrandPrixData &gp, bool from_overworld,
433  bool continue_saved_gp);
434  void saveGP();
435  void startSingleRace(const std::string &track_ident, const int num_laps,
436  bool from_overworld);
437  void startWatchingReplay(const std::string &track_ident, const int num_laps);
438  void setupPlayerKartInfo();
439  void kartFinishedRace(const AbstractKart* kart, float time);
440  void setNumPlayers(int players, int local_players=-1);
441  void setDefaultAIKartList(const std::vector<std::string> &ai_list);
442  void computeRandomKartList();
443  void setBenchmarking(bool benchmark);
444  void scheduleBenchmark();
445 
446  // ----------------------------------------------------------------------------------------
447  bool hasTimeTarget() const { return m_time_target > 0.0f; }
448  // ----------------------------------------------------------------------------------------
449  void setMaxGoal(int max_goal)
450  {
451  m_time_target = 0.0f;
452  m_goal_target = max_goal;
453  } // setMaxGoal
454  // ----------------------------------------------------------------------------------------
455  int getMaxGoal(){ return m_goal_target; }
456  // ----------------------------------------------------------------------------------------
457  void setCoinTarget(int num) { m_coin_target = num; }
458  // ----------------------------------------------------------------------------------------
459  void setGrandPrix(const GrandPrixData &gp)
460  {
461  m_grand_prix = gp;
462  setCoinTarget(0);
463  } // setGrandPrix
464  // ----------------------------------------------------------------------------------------
465  void setAIKartOverride(const std::string& kart)
466  {
467  m_ai_kart_override = kart;
468  } // setAIKartOverride
469  // ----------------------------------------------------------------------------------------
470  void setAISuperPower(AISuperPower superpower)
471  {
472  m_ai_superpower = superpower;
473  } // setAISuperPower
474  // ----------------------------------------------------------------------------------------
475  AISuperPower getAISuperPower() const { return m_ai_superpower; }
476  // ----------------------------------------------------------------------------------------
477  void setNumLaps(int num)
478  {
479  m_num_laps.clear();
480  m_num_laps.push_back(num);
481  } // setNumLaps
482  // ----------------------------------------------------------------------------------------
483  void setReverseTrack(bool r_t)
484  {
485  m_reverse_track.clear();
486  m_reverse_track.push_back(r_t);
487  } // setReverseTrack
488  // ----------------------------------------------------------------------------------------
489  void setMajorMode(MajorRaceModeType mode) { m_major_mode = mode; }
490  // ----------------------------------------------------------------------------------------
491  void setMinorMode(MinorRaceModeType mode)
492  {
493  m_minor_mode = mode;
494  } // setMinorMode
495  // ----------------------------------------------------------------------------------------
496  void setNumKarts(int num)
497  {
498  m_num_karts = num;
499  m_ai_kart_override = "";
500  m_ai_superpower = SUPERPOWER_NONE;
501  } // setNumKarts
502  // ----------------------------------------------------------------------------------------
503  void setNumRedAI(unsigned int num)
504  {
505  m_num_red_ai = num;
506  } // setNumRedAI
507  // ----------------------------------------------------------------------------------------
508  void setNumBlueAI(unsigned int num)
509  {
510  m_num_blue_ai = num;
511  } // setNumBlueAI
512  // ----------------------------------------------------------------------------------------
513  void setTimeTarget(float time)
514  {
515  m_goal_target = 0;
516  m_time_target = time;
517  } // setTimeTarget
518  // ----------------------------------------------------------------------------------------
519  RemoteKartInfo& getKartInfo(unsigned int n)
520  {
521  return m_player_karts[n];
522  } // getKartInfo
523  // ----------------------------------------------------------------------------------------
524  unsigned int getNumLocalPlayers() const
525  {
526  return m_num_local_players;
527  } // getNumLocalPlayers
528 
529  // ----------------------------------------------------------------------------------------
534  {
535  const float sqrt_num_players = sqrtf((float)getNumLocalPlayers());
536  const int rows = (int)ceil(sqrt_num_players);
537  const int cols = (int)round(sqrt_num_players);
538  const int total_spaces = rows * cols;
539  return (total_spaces - getNumLocalPlayers() > 0);
540  } // getIfEmptyScreenSpaceExists
541  // ----------------------------------------------------------------------------------------
544  unsigned int getNumberOfKarts() const { return m_num_karts; }
545  // ----------------------------------------------------------------------------------------
546  unsigned int getNumberOfAIKarts() const
547  {
548  return (unsigned int)m_ai_kart_list.size();
549  } // getNumberOfAIKarts
550  // ----------------------------------------------------------------------------------------
551  unsigned int getNumberOfRedAIKarts() const { return m_num_red_ai; }
552  // ----------------------------------------------------------------------------------------
553  unsigned int getNumberOfBlueAIKarts() const { return m_num_blue_ai; }
554  // ----------------------------------------------------------------------------------------
555  unsigned int getNumNonGhostKarts() const
556  { return m_num_karts - m_num_ghost_karts; }
557  // ----------------------------------------------------------------------------------------
558  MajorRaceModeType getMajorMode() const { return m_major_mode; }
559  // ----------------------------------------------------------------------------------------
560  MinorRaceModeType getMinorMode() const { return m_minor_mode; }
561  // ----------------------------------------------------------------------------------------
562  std::string getMinorModeName() const
563  {
564  switch (m_minor_mode)
565  {
566  case MINOR_MODE_NORMAL_RACE: return "normal";
567  case MINOR_MODE_TIME_TRIAL: return "time-trial";
568  case MINOR_MODE_FOLLOW_LEADER: return "follow-the-leader";
569  case MINOR_MODE_3_STRIKES: return "battle";
570  case MINOR_MODE_FREE_FOR_ALL: return "ffa";
571  case MINOR_MODE_CAPTURE_THE_FLAG: return "ctf";
572  case MINOR_MODE_EASTER_EGG: return "egg-hunt";
573  case MINOR_MODE_SOCCER: return "soccer";
574  default: assert(false); return "";
575  }
576  }
577  // ----------------------------------------------------------------------------------------
578  unsigned int getNumPlayers() const
579  {
580  return (unsigned int) m_player_karts.size();
581  } // getNumPlayers
582  // ----------------------------------------------------------------------------------------
589  int getNumLaps() const
590  {
591  if(modeHasLaps())
592  return m_num_laps[m_track_number];
593  // else
594  return 9999;
595  } // getNumLaps
596  // ----------------------------------------------------------------------------------------
598  bool getReverseTrack() const { return m_reverse_track[m_track_number]; }
599  // ----------------------------------------------------------------------------------------
602  // ----------------------------------------------------------------------------------------
604  static std::string getDifficultyAsString(Difficulty diff)
605  {
606  switch(diff)
607  {
608  case RaceManager::DIFFICULTY_EASY: return "easy"; break;
609  case RaceManager::DIFFICULTY_MEDIUM: return "medium"; break;
610  case RaceManager::DIFFICULTY_HARD: return "hard"; break;
611  case RaceManager::DIFFICULTY_BEST: return "best"; break;
612  default: assert(false);
613  }
614  return "";
615  } // getDifficultyAsString
616 
617  // ----------------------------------------------------------------------------------------
618  core::stringw getDifficultyName(Difficulty diff) const;
619  // ----------------------------------------------------------------------------------------
620  const std::string getTrackName() const
621  {
622  if (m_tracks.empty())
623  return "";
624  return m_tracks[m_track_number];
625  }
626  // ----------------------------------------------------------------------------------------
627  const GrandPrixData& getGrandPrix() const { return m_grand_prix; }
628  // ----------------------------------------------------------------------------------------
629  unsigned int getFinishedKarts() const { return m_num_finished_karts; }
630  // ----------------------------------------------------------------------------------------
631  unsigned int getFinishedPlayers() const { return m_num_finished_players; }
632  // ----------------------------------------------------------------------------------------
633  int getKartGPRank(const int kart_id)const
634  {
635  return m_kart_status[kart_id].m_gp_rank;
636  } // getKartGPRank
637  // ----------------------------------------------------------------------------------------
638  const std::string& getKartIdent(int kart) const
639  {
640  return m_kart_status[kart].m_ident;
641  } // getKartIdent
642  // ----------------------------------------------------------------------------------------
643  int getKartScore(int krt) const { return m_kart_status[krt].m_score; }
644  // ----------------------------------------------------------------------------------------
645  int getKartPrevScore(int krt) const
646  {
647  return m_kart_status[krt].m_last_score;
648  } // getKartPrevScore
649  // ----------------------------------------------------------------------------------------
650  int getKartLocalPlayerId(int k) const
651  {
652  assert(k < (int)m_kart_status.size());
653  return m_kart_status[k].m_local_player_id;
654  } // getKartLocalPlayerId
655  // ----------------------------------------------------------------------------------------
656  int getKartGlobalPlayerId(int k) const
657  {
658  if (k >= (int)m_kart_status.size())
659  return -1;
660  return m_kart_status[k].m_global_player_id;
661  } // getKartGlobalPlayerId
662  // ----------------------------------------------------------------------------------------
663  float getOverallTime(int kart) const
664  {
665  return m_kart_status[kart].m_overall_time;
666  } // getOverallTime
667  // ----------------------------------------------------------------------------------------
668  float getKartRaceTime(int kart) const
669  {
670  return m_kart_status[kart].m_last_time;
671  } // getKartRaceTime
672  // ----------------------------------------------------------------------------------------
673  KartType getKartType(int kart) const
674  {
675  return m_kart_status[kart].m_kart_type;
676  } // getKartType
677  // ----------------------------------------------------------------------------------------
678  HandicapLevel getPlayerHandicap(int kart) const
679  {
680  return m_kart_status[kart].m_handicap;
681  } // getPlayerHandicap
682  // ----------------------------------------------------------------------------------------
683  bool hasBoostedAI(int kart) const
684  {
685  return m_kart_status[kart].m_boosted_ai;
686  } // getKartRaceTime
687  // ----------------------------------------------------------------------------------------
688  void setKartColor(int kart, float color)
689  {
690  m_kart_status[kart].m_color = color;
691  } // setKartColor
692  // ----------------------------------------------------------------------------------------
693  float getKartColor(int kart) const
694  {
695  return m_kart_status[kart].m_color;
696  } // getKartColor
697  // ----------------------------------------------------------------------------------------
698  int getCoinTarget() const { return m_coin_target; }
699  // ----------------------------------------------------------------------------------------
700  float getTimeTarget() const { return m_time_target; }
701  // ----------------------------------------------------------------------------------------
702  int getTrackNumber() const { return m_track_number; }
703  // ----------------------------------------------------------------------------------------
704  int getNumOfTracks() const { return (int)m_tracks.size(); }
705  // ----------------------------------------------------------------------------------------
708  const std::vector<std::string>& getAIKartList() const
709  {
710  return m_ai_kart_list;
711  } // getAIKartList
712  // ----------------------------------------------------------------------------------------
715  bool isLinearRaceMode() const
716  {
717  const int id = (int)m_minor_mode;
718  // info is stored in its ID for conveniance, see the macros LINEAR_RACE
719  // and BATTLE_ARENA above for exact meaning.
720  if(id > 999 && id < 2000) return true;
721  else return false;
722  } // isLinearRaceMode
723 
724  // ----------------------------------------------------------------------------------------
727  bool isLinearRaceMode(const MinorRaceModeType mode) const
728  {
729  const int id = (int)mode;
730  // info is stored in its ID for conveniance, see the macros LINEAR_RACE
731  // and BATTLE_ARENA above for exact meaning.
732  if(id > 999 && id < 2000) return true;
733  else return false;
734  } // isLinearRaceMode
735 
736  // ----------------------------------------------------------------------------------------
738  bool isBattleMode() const
739  {
740  const int id = (int)m_minor_mode;
741  // This uses the numerical id of the mode, see the macros
742  // LINEAR_RACE and BATTLE_ARENA above for exact meaning.
743  if (id >= 2000 && id <= 2002) return true;
744  else return false;
745  } // isBattleMode
746 
747  // ----------------------------------------------------------------------------------------
749  bool isSoccerMode() const
750  {
751  const int id = (int)m_minor_mode;
752  // This uses the numerical id of the mode, see the macros
753  // LINEAR_RACE and BATTLE_ARENA above for exact meaning.
754  if (id == 2003) return true;
755  else return false;
756  } // isSoccerMode
757 
758  // ----------------------------------------------------------------------------------------
759  bool isTutorialMode() const { return m_minor_mode == MINOR_MODE_TUTORIAL; }
760 
761  // ----------------------------------------------------------------------------------------
762  bool isFollowMode() const { return m_minor_mode == MINOR_MODE_FOLLOW_LEADER; }
763 
764  // ----------------------------------------------------------------------------------------
765  bool isCTFMode() const { return m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG; }
766 
767  // ----------------------------------------------------------------------------------------
768  bool isEggHuntMode() const { return m_minor_mode == MINOR_MODE_EASTER_EGG; }
769 
770  // ----------------------------------------------------------------------------------------
771  bool isTimeTrialMode() const { return m_minor_mode == MINOR_MODE_TIME_TRIAL; }
772  // ----------------------------------------------------------------------------------------
773  bool isLapTrialMode() const { return m_minor_mode == MINOR_MODE_LAP_TRIAL; }
774  // ----------------------------------------------------------------------------------------
777  {
778  return 3; // display milliseconds
779  } // currentModeTimePrecision
780  // ----------------------------------------------------------------------------------------
782  bool modeHasLaps() const
783  {
784  if (!isLinearRaceMode()) return false;
785  const int id = (int)m_minor_mode;
786  // See meaning of IDs above
787  const int answer = (id-1000)/100;
788  return answer!=0;
789  } // modeHasLaps
790  // ----------------------------------------------------------------------------------------
793  {
794  //FIXME: this information is duplicated. RaceManager knows about it,
795  // and each World may set m_use_highscores to true or false.
796  // The reason for this duplication is that we might want to know
797  // whether to display highscores without creating a World.
798  return !isBattleMode() &&
799  !isSoccerMode() &&
800  m_minor_mode != MINOR_MODE_FOLLOW_LEADER;
801  } // modeHasHighscore
802  // ----------------------------------------------------------------------------------------
803  bool raceWasStartedFromOverworld() const
804  {
805  return m_started_from_overworld;
806  } // raceWasStartedFromOverworld
807 
808  // ----------------------------------------------------------------------------------------
813  bool allPlayerFinished() const
814  {
815  return m_num_finished_players == m_player_karts.size();
816  } // allPlayerFinished
817  // ----------------------------------------------------------------------------------------
821  void setAIKartList(const std::vector<std::string>& rkl)
822  {
823  m_ai_kart_list = rkl;
824  } // setAIKartList
825  // ----------------------------------------------------------------------------------------
826  bool haveKartLastPositionOnOverworld()
827  {
828  return m_have_kart_last_position_on_overworld;
829  } // haveKartLastPositionOnOverworld
830  // ----------------------------------------------------------------------------------------
831  void setKartLastPositionOnOverworld(const Vec3 &pos)
832  {
833  m_have_kart_last_position_on_overworld = true;
834  m_kart_last_position_on_overworld = pos;
835  } // setKartLastPositionOnOverworld
836  // ----------------------------------------------------------------------------------------
837  void clearKartLastPositionOnOverworld()
838  {
839  m_have_kart_last_position_on_overworld = false;
840  } // clearKartLastPositionOnOverworld
841  // ----------------------------------------------------------------------------------------
842  Vec3 getKartLastPositionOnOverworld()
843  {
844  return m_kart_last_position_on_overworld;
845  } // getKartLastPositionOnOverworld
846  // ----------------------------------------------------------------------------------------
847  void setRecordRace(bool record)
848  {
849  m_is_recording_race = record;
850  } // setRecordRace
851  // ----------------------------------------------------------------------------------------
852  void setRaceGhostKarts(bool ghost)
853  {
854  m_has_ghost_karts = ghost;
855  } // setRaceGhostKarts
856  // ----------------------------------------------------------------------------------------
857  void setWatchingReplay(bool watch)
858  {
859  m_watching_replay = watch;
860  } // setWatchingReplay
861  // ----------------------------------------------------------------------------------------
862  bool isRecordingRace() const
863  {
864  return m_is_recording_race;
865  } // isRecordingRace
866  // ----------------------------------------------------------------------------------------
867  bool hasGhostKarts() const
868  {
869  return m_has_ghost_karts;
870  } // hasGhostKarts
871  // ----------------------------------------------------------------------------------------
872  bool isWatchingReplay() const
873  {
874  return m_watching_replay;
875  } // isWatchingReplay
876  // ----------------------------------------------------------------------------------------
877  bool isBenchmarking() const
878  {
879  return m_benchmarking;
880  } // isBenchmarking
881  // ----------------------------------------------------------------------------------------
882  bool isBenchmarkScheduled() const
883  {
884  return m_scheduled_benchmark;
885  } // isBenchmarkSchedule
886  // ----------------------------------------------------------------------------------------
887  void addSpareTireKart(const std::string& name)
888  {
889  m_kart_status.push_back(KartStatus(name, 0, -1, -1,
890  -1, KT_SPARE_TIRE, HANDICAP_NONE));
891  m_num_spare_tire_karts++;
892  m_num_karts++;
893  } // addSpareTireKart
894  // ----------------------------------------------------------------------------------------
895  void setSpareTireKartNum(unsigned int i)
896  {
897  m_num_spare_tire_karts = i;
898  } // setSpareTireKartNum
899  // ----------------------------------------------------------------------------------------
900  unsigned int getNumSpareTireKarts() const
901  {
902  return m_num_spare_tire_karts;
903  } // getNumSpareTireKarts
904  // ----------------------------------------------------------------------------------------
905  void configGrandPrixResultFromNetwork(NetworkString& ns);
906  // ----------------------------------------------------------------------------------------
907  void clearNetworkGrandPrixResult();
908  // ----------------------------------------------------------------------------------------
909  void setHitCaptureTime(int hc, float time)
910  {
911  m_hit_capture_limit = hc;
912  m_time_target = time;
913  }
914  // ----------------------------------------------------------------------------------------
915  int getHitCaptureLimit() const { return m_hit_capture_limit; }
916  // ----------------------------------------------------------------------------------------
917  bool teamEnabled() const
918  {
919  return m_minor_mode == MINOR_MODE_SOCCER ||
920  m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG;
921  }
922  // ----------------------------------------------------------------------------------------
923  void setFlagReturnTicks(unsigned ticks) { m_flag_return_ticks = ticks; }
924  // ----------------------------------------------------------------------------------------
925  unsigned getFlagReturnTicks() const { return m_flag_return_ticks; }
926  // ----------------------------------------------------------------------------------------
927  void setFlagDeactivatedTicks(unsigned ticks)
928  { m_flag_deactivated_ticks = ticks; }
929  // ----------------------------------------------------------------------------------------
930  unsigned getFlagDeactivatedTicks() const
931  { return m_flag_deactivated_ticks; }
932  // ----------------------------------------------------------------------------------------
933  int getSkippedTracksInGP() const { return m_skipped_tracks_in_gp; }
934  // ----------------------------------------------------------------------------------------
935  void addSkippedTrackInGP() { m_skipped_tracks_in_gp++; }
936  // ----------------------------------------------------------------------------------------
937  void setGPTimeTarget(float time_target) { m_gp_time_target = time_target; }
938  // ----------------------------------------------------------------------------------------
941  bool supportsLiveJoining() const
942  {
943  return m_minor_mode == MINOR_MODE_SOCCER ||
944  m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG ||
945  m_minor_mode == MINOR_MODE_FREE_FOR_ALL;
946  }
947 }; // RaceManager
948 
949 #endif
950 
951 /* EOF */
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Simple class that hold the data relevant to a 'grand_prix', aka.
Definition: grand_prix_data.hpp:37
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message,...
Definition: network_string.hpp:422
The race manager has two functions: 1) it stores information about the race the user selected (e....
Definition: race_manager.hpp:89
void scheduleBenchmark()
Schedule a benchmark.
Definition: race_manager.cpp:1344
std::vector< RemoteKartInfo > m_player_karts
Stores remote kart information about all player karts.
Definition: race_manager.hpp:309
std::vector< KartStatus > m_kart_status
The kart status data for each kart.
Definition: race_manager.hpp:298
static std::string getDifficultyAsString(Difficulty diff)
Returns the specified difficulty as a string.
Definition: race_manager.hpp:604
float m_gp_time_target
Time target for GP, used in Lap Trial mode.
Definition: race_manager.hpp:352
std::vector< std::string > m_ai_kart_list
The list of AI karts to use.
Definition: race_manager.hpp:333
void setDefaultAIKartList(const std::vector< std::string > &ai_list)
Sets the default list of AI karts to use.
Definition: race_manager.cpp:177
static const std::string & getIdentOf(const MinorRaceModeType mode)
Returns a string identifier for each minor race mode.
Definition: race_manager.hpp:144
void setTrack(const std::string &track)
In case of non GP mode set the track to use.
Definition: race_manager.cpp:323
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:1180
void setupPlayerKartInfo()
Fills up the remaining kart slots with AI karts.
Definition: race_manager.cpp:1169
Difficulty getDifficulty() const
Returns the difficulty.
Definition: race_manager.hpp:601
KartType
Different kart types: A local player, a player connected via network, an AI kart, the leader kart (cu...
Definition: race_manager.hpp:243
void setNumPlayers(int players, int local_players=-1)
Sets the number of players and optional the number of local players.
Definition: race_manager.cpp:277
int currentModeTimePrecision() const
Returns the number of second's decimals to display.
Definition: race_manager.hpp:776
void computeGPRanks()
Sort karts and update the m_gp_rank KartStatus member, in preparation for future calls to RaceManager...
Definition: race_manager.cpp:856
void reset()
Resets the race manager in preparation for a new race.
Definition: race_manager.cpp:167
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:226
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:1088
bool hasAI()
Returns if the currently set minor game mode can be used by the AI.
Definition: race_manager.hpp:187
static const core::stringw getNameOf(const MinorRaceModeType mode)
Returns a (translated) name of a minor race mode.
Definition: race_manager.cpp:1281
void startNextRace()
Total laps from every track, used in Lap Trial mode int m_gp_total_laps;.
Definition: race_manager.cpp:547
void setDifficulty(Difficulty diff)
Sets the difficulty.
Definition: race_manager.cpp:314
bool supportsLiveJoining() const
Whether the current game mode allow live joining even the current game
Definition: race_manager.hpp:941
~RaceManager()
Destructor for the race manager.
Definition: race_manager.cpp:158
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:747
int getLocalPlayerGPRank(const int playerID) const
Returns the GP rank (between 1 and number of karts) of a local player.
Definition: race_manager.cpp:259
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:1103
void setAIKartList(const std::vector< std::string > &rkl)
Sets the AI to use.
Definition: race_manager.hpp:821
MinorRaceModeType
Minor variants to the major types of race.
Definition: race_manager.hpp:111
bool modeHasHighscores()
Returns true if the currently selected minor mode has highscores.
Definition: race_manager.hpp:792
void startNew(bool from_overworld)
Starts a new race or GP (or other mode).
Definition: race_manager.cpp:386
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:247
bool m_continue_saved_gp
Determines if saved GP should be continued or not.
Definition: race_manager.hpp:368
MajorRaceModeType
The major types or races supported in STK.
Definition: race_manager.hpp:94
AISuperPower
True if the AI should have additional abbilities, e.g.
Definition: race_manager.hpp:135
void saveGP()
Saves the current GP to the config.
Definition: race_manager.cpp:774
std::vector< uint8_t > m_reverse_track
Whether a track should be reversed.
Definition: race_manager.hpp:321
bool isLinearRaceMode(const MinorRaceModeType mode) const
get information about given mode (returns true if 'mode' is of linear races type)
Definition: race_manager.hpp:727
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:1125
unsigned int getNumberOfKarts() const
Returns the selected number of karts (selected number of players and AI karts.
Definition: race_manager.hpp:544
bool isSoccerMode() const
Returns true if the current mode is a soccer mode.
Definition: race_manager.hpp:749
static const MinorRaceModeType getModeIDFromInternalName(const std::string &name)
Returns the minor mode id from a string identifier.
Definition: race_manager.hpp:210
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:317
RaceManager()
Constructs the race manager.
Definition: race_manager.cpp:121
std::string m_ai_kart_override
If set, specifies which kart to use for AI(s)
Definition: race_manager.hpp:327
int getNumLaps() const
Returns the number lf laps.
Definition: race_manager.hpp:589
static Difficulty convertDifficulty(const std::string &difficulty)
Converst the difficulty given as a string into a Difficult enum.
Definition: race_manager.cpp:296
static const char * getIconOf(const MinorRaceModeType mode)
Returns the icon for a minor race mode.
Definition: race_manager.hpp:166
bool isBattleMode() const
Returns true if the current mode is a battle mode.
Definition: race_manager.hpp:738
Difficulty
Game difficulty.
Definition: race_manager.hpp:231
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:533
MajorRaceModeType m_major_mode
The major mode (single race, GP).
Definition: race_manager.hpp:304
MinorRaceModeType m_minor_mode
The minor mode (race, time trial, ftl, battle mode).
Definition: race_manager.hpp:307
bool modeHasLaps() const
Returns true if the current mode has laps.
Definition: race_manager.hpp:782
unsigned int m_num_local_players
Number of local players.
Definition: race_manager.hpp:313
void setPlayerHandicap(unsigned int player_id, HandicapLevel handicap)
Sets the handicap for a player.
Definition: race_manager.cpp:236
Difficulty m_difficulty
The selected difficulty.
Definition: race_manager.hpp:301
void exitRace(bool delete_world=true)
Exit a race (and don't start the next one)
Definition: race_manager.cpp:918
bool isLinearRaceMode() const
get information about current mode (returns true if 'mode' is of linear races type)
Definition: race_manager.hpp:715
const std::vector< std::string > & getAIKartList() const
Returns the list of AI karts to use.
Definition: race_manager.hpp:708
void computeRandomKartList()
Computes the list of random karts to be used for the AI.
Definition: race_manager.cpp:335
std::vector< std::string > m_default_ai_list
The list of default AI karts to use.
Definition: race_manager.hpp:324
void setBenchmarking(bool benchmark)
Set the benchmarking mode as requested, and turn off the profiler if needed.
Definition: race_manager.cpp:1327
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:1055
core::stringw getDifficultyName(Difficulty diff) const
Returns the specified difficulty as a string.
Definition: race_manager.cpp:1309
bool getReverseTrack() const
Definition: race_manager.hpp:598
Definition: remote_kart_info.hpp:52
Class for managing saved Grand-Prix's A list of all possible resumable GP's is stored in the user con...
Definition: saved_grand_prix.hpp:39
Definition: track.hpp:115
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:43
This data structure accumulates kart data and race result data from each race.
Definition: race_manager.hpp:254
HandicapLevel m_handicap
The handicap for this player.
Definition: race_manager.hpp:279
std::string m_ident
The kart identifier.
Definition: race_manager.hpp:256
float m_color
Kart color of player (used in gp win / lose screen).
Definition: race_manager.hpp:281
int m_local_player_id
Player controling the kart, for AI: -1.
Definition: race_manager.hpp:270
float m_last_time
Needed for restart.
Definition: race_manager.hpp:266
std::string m_player_name
For networked karts.
Definition: race_manager.hpp:258
int m_global_player_id
Global ID of player.
Definition: race_manager.hpp:272
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:275
float m_overall_time
Sum of times of all races.
Definition: race_manager.hpp:264
KartType m_kart_type
Kart type: AI, player, network player etc.
Definition: race_manager.hpp:268
int m_last_score
Needed for restart race, and for race results GUI.
Definition: race_manager.hpp:262
bool m_boosted_ai
Boosted status (AI only).
Definition: race_manager.hpp:277
Declares the general types that are used by the network.