19 #ifndef HEADER_RACEMANAGER_HPP
20 #define HEADER_RACEMANAGER_HPP
35 #include "race/grand_prix_data.hpp"
36 #include "utils/vec3.hpp"
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" );
95 MAJOR_MODE_GRAND_PRIX = 0,
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)
112 MINOR_MODE_NONE = -1,
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),
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),
123 MINOR_MODE_EASTER_EGG = EASTER_EGG(0),
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)
137 SUPERPOWER_NOLOK_BOSS = 1
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);
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;
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;
211 const std::string &name)
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;
223 return MINOR_MODE_NONE;
232 DIFFICULTY_FIRST = DIFFICULTY_EASY,
236 DIFFICULTY_LAST = DIFFICULTY_BEST,
243 enum KartType { KT_PLAYER, KT_NETWORK_PLAYER, KT_AI, KT_LEADER,
244 KT_GHOST, KT_SPARE_TIRE };
247 bool m_started_from_overworld;
282 KartStatus(
const std::string& ident,
const int& prev_finish_pos,
283 int local_player_id,
int global_player_id,
310 std::vector<std::string> m_tracks;
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;
349 int m_hit_capture_limit;
350 int m_skipped_tracks_in_gp;
359 return (left.m_score < right.m_score) ||
360 (left.m_score == right.m_score &&
364 bool m_have_kart_last_position_on_overworld;
365 Vec3 m_kart_last_position_on_overworld;
369 bool m_is_recording_race;
370 bool m_has_ghost_karts;
371 bool m_watching_replay;
373 bool m_scheduled_benchmark;
379 static void create();
381 static void destroy();
389 void setPlayerKart(
unsigned int player_id,
const std::string &kart_name);
390 void setPlayerKart(
unsigned int player_id,
395 void setKartTeam(
unsigned int player_id, KartTeam team);
404 void setTrack(
const std::string& track);
431 void exitRace(
bool delete_world=
true);
433 bool continue_saved_gp);
435 void startSingleRace(
const std::string &track_ident,
const int num_laps,
436 bool from_overworld);
447 bool hasTimeTarget()
const {
return m_time_target > 0.0f; }
449 void setMaxGoal(
int max_goal)
451 m_time_target = 0.0f;
452 m_goal_target = max_goal;
455 int getMaxGoal(){
return m_goal_target; }
457 void setCoinTarget(
int num) { m_coin_target = num; }
465 void setAIKartOverride(
const std::string& kart)
472 m_ai_superpower = superpower;
475 AISuperPower getAISuperPower()
const {
return m_ai_superpower; }
477 void setNumLaps(
int num)
483 void setReverseTrack(
bool r_t)
496 void setNumKarts(
int num)
500 m_ai_superpower = SUPERPOWER_NONE;
503 void setNumRedAI(
unsigned int num)
508 void setNumBlueAI(
unsigned int num)
513 void setTimeTarget(
float time)
516 m_time_target = time;
524 unsigned int getNumLocalPlayers()
const
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);
546 unsigned int getNumberOfAIKarts()
const
551 unsigned int getNumberOfRedAIKarts()
const {
return m_num_red_ai; }
553 unsigned int getNumberOfBlueAIKarts()
const {
return m_num_blue_ai; }
555 unsigned int getNumNonGhostKarts()
const
556 {
return m_num_karts - m_num_ghost_karts; }
562 std::string getMinorModeName()
const
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 "";
578 unsigned int getNumPlayers()
const
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);
620 const std::string getTrackName()
const
622 if (m_tracks.empty())
624 return m_tracks[m_track_number];
627 const GrandPrixData& getGrandPrix()
const {
return m_grand_prix; }
629 unsigned int getFinishedKarts()
const {
return m_num_finished_karts; }
631 unsigned int getFinishedPlayers()
const {
return m_num_finished_players; }
633 int getKartGPRank(
const int kart_id)
const
638 const std::string& getKartIdent(
int kart)
const
643 int getKartScore(
int krt)
const {
return m_kart_status[krt].m_score; }
645 int getKartPrevScore(
int krt)
const
650 int getKartLocalPlayerId(
int k)
const
656 int getKartGlobalPlayerId(
int k)
const
663 float getOverallTime(
int kart)
const
668 float getKartRaceTime(
int kart)
const
673 KartType getKartType(
int kart)
const
683 bool hasBoostedAI(
int kart)
const
688 void setKartColor(
int kart,
float color)
693 float getKartColor(
int kart)
const
698 int getCoinTarget()
const {
return m_coin_target; }
700 float getTimeTarget()
const {
return m_time_target; }
702 int getTrackNumber()
const {
return m_track_number; }
704 int getNumOfTracks()
const {
return (
int)m_tracks.size(); }
720 if(
id > 999 &&
id < 2000)
return true;
729 const int id = (int)mode;
732 if(
id > 999 &&
id < 2000)
return true;
743 if (
id >= 2000 &&
id <= 2002)
return true;
754 if (
id == 2003)
return true;
759 bool isTutorialMode()
const {
return m_minor_mode == MINOR_MODE_TUTORIAL; }
762 bool isFollowMode()
const {
return m_minor_mode == MINOR_MODE_FOLLOW_LEADER; }
765 bool isCTFMode()
const {
return m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG; }
768 bool isEggHuntMode()
const {
return m_minor_mode == MINOR_MODE_EASTER_EGG; }
771 bool isTimeTrialMode()
const {
return m_minor_mode == MINOR_MODE_TIME_TRIAL; }
773 bool isLapTrialMode()
const {
return m_minor_mode == MINOR_MODE_LAP_TRIAL; }
787 const int answer = (
id-1000)/100;
803 bool raceWasStartedFromOverworld()
const
805 return m_started_from_overworld;
813 bool allPlayerFinished()
const
826 bool haveKartLastPositionOnOverworld()
828 return m_have_kart_last_position_on_overworld;
831 void setKartLastPositionOnOverworld(
const Vec3 &pos)
833 m_have_kart_last_position_on_overworld =
true;
834 m_kart_last_position_on_overworld = pos;
837 void clearKartLastPositionOnOverworld()
839 m_have_kart_last_position_on_overworld =
false;
842 Vec3 getKartLastPositionOnOverworld()
844 return m_kart_last_position_on_overworld;
847 void setRecordRace(
bool record)
849 m_is_recording_race = record;
852 void setRaceGhostKarts(
bool ghost)
854 m_has_ghost_karts = ghost;
857 void setWatchingReplay(
bool watch)
859 m_watching_replay = watch;
862 bool isRecordingRace()
const
864 return m_is_recording_race;
867 bool hasGhostKarts()
const
869 return m_has_ghost_karts;
872 bool isWatchingReplay()
const
874 return m_watching_replay;
877 bool isBenchmarking()
const
879 return m_benchmarking;
882 bool isBenchmarkScheduled()
const
884 return m_scheduled_benchmark;
887 void addSpareTireKart(
const std::string& name)
890 -1, KT_SPARE_TIRE, HANDICAP_NONE));
891 m_num_spare_tire_karts++;
895 void setSpareTireKartNum(
unsigned int i)
897 m_num_spare_tire_karts = i;
900 unsigned int getNumSpareTireKarts()
const
902 return m_num_spare_tire_karts;
907 void clearNetworkGrandPrixResult();
909 void setHitCaptureTime(
int hc,
float time)
911 m_hit_capture_limit = hc;
912 m_time_target = time;
915 int getHitCaptureLimit()
const {
return m_hit_capture_limit; }
917 bool teamEnabled()
const
923 void setFlagReturnTicks(
unsigned ticks) { m_flag_return_ticks = ticks; }
925 unsigned getFlagReturnTicks()
const {
return m_flag_return_ticks; }
927 void setFlagDeactivatedTicks(
unsigned ticks)
928 { m_flag_deactivated_ticks = ticks; }
930 unsigned getFlagDeactivatedTicks()
const
931 {
return m_flag_deactivated_ticks; }
933 int getSkippedTracksInGP()
const {
return m_skipped_tracks_in_gp; }
935 void addSkippedTrackInGP() { m_skipped_tracks_in_gp++; }
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.