19#ifndef HEADER_RACEMANAGER_HPP
20#define HEADER_RACEMANAGER_HPP
35#include "race/grand_prix_data.hpp"
36#include "utils/vec3.hpp"
43static const std::string IDENT_STD (
"STANDARD" );
44static const std::string IDENT_TTRIAL (
"STD_TIMETRIAL" );
45static const std::string IDENT_FTL (
"FOLLOW_LEADER" );
46static const std::string IDENT_STRIKES (
"BATTLE_3_STRIKES");
47static const std::string IDENT_FFA (
"BATTLE_FFA" );
48static const std::string IDENT_CTF (
"BATTLE_CTF" );
49static const std::string IDENT_EASTER (
"EASTER_EGG_HUNT" );
50static const std::string IDENT_SOCCER (
"SOCCER" );
51static const std::string IDENT_GHOST (
"GHOST" );
52static const std::string IDENT_OVERWORLD(
"OVERWORLD" );
53static const std::string IDENT_CUTSCENE (
"CUTSCENE" );
54static const std::string IDENT_LAP_TRIAL(
"LAP_TRIAL" );
94 MAJOR_MODE_GRAND_PRIX = 0,
101#define LINEAR_RACE(ID, COUNT_LAPSES) (1000+ID+100*COUNT_LAPSES)
102#define BATTLE_ARENA(ID) (2000+ID)
103#define EASTER_EGG(ID) (3000+ID)
104#define MISC(ID) (4000+ID)
111 MINOR_MODE_NONE = -1,
113 MINOR_MODE_NORMAL_RACE = LINEAR_RACE(0,
true),
114 MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1,
true),
115 MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2,
false),
117 MINOR_MODE_3_STRIKES = BATTLE_ARENA(0),
118 MINOR_MODE_FREE_FOR_ALL = BATTLE_ARENA(1),
119 MINOR_MODE_CAPTURE_THE_FLAG = BATTLE_ARENA(2),
120 MINOR_MODE_SOCCER = BATTLE_ARENA(3),
122 MINOR_MODE_EASTER_EGG = EASTER_EGG(0),
124 MINOR_MODE_OVERWORLD = MISC(0),
125 MINOR_MODE_TUTORIAL = MISC(1),
126 MINOR_MODE_CUTSCENE = MISC(2),
127 MINOR_MODE_LAP_TRIAL = MISC(3)
136 SUPERPOWER_NOLOK_BOSS = 1
147 case MINOR_MODE_NORMAL_RACE:
return IDENT_STD;
148 case MINOR_MODE_TIME_TRIAL:
return IDENT_TTRIAL;
149 case MINOR_MODE_FOLLOW_LEADER:
return IDENT_FTL;
150 case MINOR_MODE_LAP_TRIAL:
return IDENT_LAP_TRIAL;
151 case MINOR_MODE_3_STRIKES:
return IDENT_STRIKES;
152 case MINOR_MODE_FREE_FOR_ALL:
return IDENT_FFA;
153 case MINOR_MODE_CAPTURE_THE_FLAG:
return IDENT_CTF;
154 case MINOR_MODE_EASTER_EGG:
return IDENT_EASTER;
155 case MINOR_MODE_SOCCER:
return IDENT_SOCCER;
156 default: assert(
false);
169 case MINOR_MODE_NORMAL_RACE:
return "/gui/icons/mode_normal.png";
170 case MINOR_MODE_TIME_TRIAL:
return "/gui/icons/mode_tt.png";
171 case MINOR_MODE_FOLLOW_LEADER:
return "/gui/icons/mode_ftl.png";
172 case MINOR_MODE_LAP_TRIAL:
return "/gui/icons/mode_laptrial.png";
173 case MINOR_MODE_3_STRIKES:
return "/gui/icons/mode_3strikes.png";
174 case MINOR_MODE_FREE_FOR_ALL:
return "/gui/icons/mode_weapons.png";
175 case MINOR_MODE_CAPTURE_THE_FLAG:
return "/gui/icons/mode_weapons.png";
176 case MINOR_MODE_EASTER_EGG:
return "/gui/icons/mode_easter.png";
177 case MINOR_MODE_SOCCER:
return "/gui/icons/mode_soccer.png";
178 default: assert(
false);
return NULL;
190 case MINOR_MODE_NORMAL_RACE:
return true;
191 case MINOR_MODE_TIME_TRIAL:
return true;
192 case MINOR_MODE_FOLLOW_LEADER:
return true;
193 case MINOR_MODE_LAP_TRIAL:
return true;
194 case MINOR_MODE_3_STRIKES:
return true;
195 case MINOR_MODE_FREE_FOR_ALL:
return false;
196 case MINOR_MODE_CAPTURE_THE_FLAG:
return false;
197 case MINOR_MODE_EASTER_EGG:
return false;
198 case MINOR_MODE_SOCCER:
return true;
199 default: assert(
false);
return false;
210 const std::string &name)
212 if (name==IDENT_STD )
return MINOR_MODE_NORMAL_RACE;
213 else if (name==IDENT_TTRIAL )
return MINOR_MODE_TIME_TRIAL;
214 else if (name==IDENT_FTL )
return MINOR_MODE_FOLLOW_LEADER;
215 else if (name==IDENT_STRIKES)
return MINOR_MODE_3_STRIKES;
216 else if (name==IDENT_FFA)
return MINOR_MODE_FREE_FOR_ALL;
217 else if (name==IDENT_CTF)
return MINOR_MODE_CAPTURE_THE_FLAG;
218 else if (name==IDENT_EASTER )
return MINOR_MODE_EASTER_EGG;
219 else if (name==IDENT_SOCCER)
return MINOR_MODE_SOCCER;
222 return MINOR_MODE_NONE;
231 DIFFICULTY_FIRST = DIFFICULTY_EASY,
235 DIFFICULTY_LAST = DIFFICULTY_BEST,
242 enum KartType { KT_PLAYER, KT_NETWORK_PLAYER, KT_AI, KT_LEADER,
243 KT_GHOST, KT_SPARE_TIRE };
246 bool m_started_from_overworld;
281 KartStatus(
const std::string& ident,
const int& prev_finish_pos,
282 int local_player_id,
int global_player_id,
309 std::vector<std::string> m_tracks;
336 unsigned int m_num_red_ai;
337 unsigned int m_num_blue_ai;
338 unsigned int m_num_ghost_karts;
339 unsigned int m_num_spare_tire_karts;
340 unsigned int m_num_finished_karts;
341 unsigned int m_num_finished_players;
342 unsigned m_flag_return_ticks;
343 unsigned m_flag_deactivated_ticks;
347 int m_hit_capture_limit;
348 int m_skipped_tracks_in_gp;
357 return (left.m_score < right.m_score) ||
358 (left.m_score == right.m_score &&
362 bool m_have_kart_last_position_on_overworld;
363 Vec3 m_kart_last_position_on_overworld;
368 bool m_is_recording_race;
370 bool m_has_ghost_karts;
372 bool m_watching_replay;
377 static void create();
379 static void destroy();
387 void setPlayerKart(
unsigned int player_id,
const std::string &kart_name);
388 void setPlayerKart(
unsigned int player_id,
393 void setKartTeam(
unsigned int player_id, KartTeam team);
402 void setTrack(
const std::string& track);
429 void exitRace(
bool delete_world=
true);
431 bool continue_saved_gp);
433 void startSingleRace(
const std::string &track_ident,
const int num_laps,
434 bool from_overworld);
443 bool hasTimeTarget()
const {
return m_time_target > 0.0f; }
445 void setMaxGoal(
int max_goal)
447 m_time_target = 0.0f;
448 m_goal_target = max_goal;
451 int getMaxGoal(){
return m_goal_target; }
453 void setCoinTarget(
int num) { m_coin_target = num; }
461 void setAIKartOverride(
const std::string& kart)
468 m_ai_superpower = superpower;
471 AISuperPower getAISuperPower()
const {
return m_ai_superpower; }
473 void setNumLaps(
int num)
479 void setReverseTrack(
bool r_t)
492 void setNumKarts(
int num)
496 m_ai_superpower = SUPERPOWER_NONE;
499 void setNumRedAI(
unsigned int num)
504 void setNumBlueAI(
unsigned int num)
509 void setTimeTarget(
float time)
512 m_time_target = time;
520 unsigned int getNumLocalPlayers()
const
531 const float sqrt_num_players = sqrtf((
float)getNumLocalPlayers());
532 const int rows = (int)ceil(sqrt_num_players);
533 const int cols = (int)round(sqrt_num_players);
534 const int total_spaces = rows * cols;
535 return (total_spaces - getNumLocalPlayers() > 0);
542 unsigned int getNumberOfAIKarts()
const
547 unsigned int getNumberOfRedAIKarts()
const {
return m_num_red_ai; }
549 unsigned int getNumberOfBlueAIKarts()
const {
return m_num_blue_ai; }
551 unsigned int getNumNonGhostKarts()
const
552 {
return m_num_karts - m_num_ghost_karts; }
558 std::string getMinorModeName()
const
562 case MINOR_MODE_NORMAL_RACE:
return "normal";
563 case MINOR_MODE_TIME_TRIAL:
return "time-trial";
564 case MINOR_MODE_FOLLOW_LEADER:
return "follow-the-leader";
565 case MINOR_MODE_3_STRIKES:
return "battle";
566 case MINOR_MODE_FREE_FOR_ALL:
return "ffa";
567 case MINOR_MODE_CAPTURE_THE_FLAG:
return "ctf";
568 case MINOR_MODE_EASTER_EGG:
return "egg-hunt";
569 case MINOR_MODE_SOCCER:
return "soccer";
570 default: assert(
false);
return "";
574 unsigned int getNumPlayers()
const
604 case RaceManager::DIFFICULTY_EASY:
return "easy";
break;
605 case RaceManager::DIFFICULTY_MEDIUM:
return "medium";
break;
606 case RaceManager::DIFFICULTY_HARD:
return "hard";
break;
607 case RaceManager::DIFFICULTY_BEST:
return "best";
break;
608 default: assert(
false);
616 const std::string getTrackName()
const
618 if (m_tracks.empty())
620 return m_tracks[m_track_number];
623 const GrandPrixData& getGrandPrix()
const {
return m_grand_prix; }
625 unsigned int getFinishedKarts()
const {
return m_num_finished_karts; }
627 unsigned int getFinishedPlayers()
const {
return m_num_finished_players; }
629 int getKartGPRank(
const int kart_id)
const
634 const std::string& getKartIdent(
int kart)
const
639 int getKartScore(
int krt)
const {
return m_kart_status[krt].m_score; }
641 int getKartPrevScore(
int krt)
const
646 int getKartLocalPlayerId(
int k)
const
652 int getKartGlobalPlayerId(
int k)
const
659 float getOverallTime(
int kart)
const
664 float getKartRaceTime(
int kart)
const
669 KartType getKartType(
int kart)
const
679 bool hasBoostedAI(
int kart)
const
684 void setKartColor(
int kart,
float color)
689 float getKartColor(
int kart)
const
694 int getCoinTarget()
const {
return m_coin_target; }
696 float getTimeTarget()
const {
return m_time_target; }
698 int getTrackNumber()
const {
return m_track_number; }
700 int getNumOfTracks()
const {
return (
int)m_tracks.size(); }
716 if(
id > 999 &&
id < 2000)
return true;
725 const int id = (int)mode;
728 if(
id > 999 &&
id < 2000)
return true;
739 if (
id >= 2000 &&
id <= 2002)
return true;
750 if (
id == 2003)
return true;
755 bool isTutorialMode()
const {
return m_minor_mode == MINOR_MODE_TUTORIAL; }
758 bool isFollowMode()
const {
return m_minor_mode == MINOR_MODE_FOLLOW_LEADER; }
761 bool isCTFMode()
const {
return m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG; }
764 bool isEggHuntMode()
const {
return m_minor_mode == MINOR_MODE_EASTER_EGG; }
767 bool isTimeTrialMode()
const {
return m_minor_mode == MINOR_MODE_TIME_TRIAL; }
769 bool isLapTrialMode()
const {
return m_minor_mode == MINOR_MODE_LAP_TRIAL; }
783 const int answer = (
id-1000)/100;
799 bool raceWasStartedFromOverworld()
const
801 return m_started_from_overworld;
809 bool allPlayerFinished()
const
822 bool haveKartLastPositionOnOverworld()
824 return m_have_kart_last_position_on_overworld;
827 void setKartLastPositionOnOverworld(
const Vec3 &pos)
829 m_have_kart_last_position_on_overworld =
true;
830 m_kart_last_position_on_overworld = pos;
833 void clearKartLastPositionOnOverworld()
835 m_have_kart_last_position_on_overworld =
false;
838 Vec3 getKartLastPositionOnOverworld()
840 return m_kart_last_position_on_overworld;
843 void setRecordRace(
bool record)
845 m_is_recording_race = record;
848 void setRaceGhostKarts(
bool ghost)
850 m_has_ghost_karts = ghost;
853 void setWatchingReplay(
bool watch)
855 m_watching_replay = watch;
858 bool isRecordingRace()
const
860 return m_is_recording_race;
863 bool hasGhostKarts()
const
865 return m_has_ghost_karts;
868 bool isWatchingReplay()
const
870 return m_watching_replay;
873 void addSpareTireKart(
const std::string& name)
876 -1, KT_SPARE_TIRE, HANDICAP_NONE));
877 m_num_spare_tire_karts++;
881 void setSpareTireKartNum(
unsigned int i)
883 m_num_spare_tire_karts = i;
886 unsigned int getNumSpareTireKarts()
const
888 return m_num_spare_tire_karts;
893 void clearNetworkGrandPrixResult();
895 void setHitCaptureTime(
int hc,
float time)
897 m_hit_capture_limit = hc;
898 m_time_target = time;
901 int getHitCaptureLimit()
const {
return m_hit_capture_limit; }
903 bool teamEnabled()
const
909 void setFlagReturnTicks(
unsigned ticks) { m_flag_return_ticks = ticks; }
911 unsigned getFlagReturnTicks()
const {
return m_flag_return_ticks; }
913 void setFlagDeactivatedTicks(
unsigned ticks)
914 { m_flag_deactivated_ticks = ticks; }
916 unsigned getFlagDeactivatedTicks()
const
917 {
return m_flag_deactivated_ticks; }
919 int getSkippedTracksInGP()
const {
return m_skipped_tracks_in_gp; }
921 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:36
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:88
std::vector< RemoteKartInfo > m_player_karts
Stores remote kart information about all player karts.
Definition: race_manager.hpp:308
static const std::string & getIdentOf(const MinorRaceModeType mode)
Returns a string identifier for each minor race mode.
Definition: race_manager.hpp:143
std::vector< KartStatus > m_kart_status
The kart status data for each kart.
Definition: race_manager.hpp:297
float m_gp_time_target
Time target for GP, used in Lap Trial mode.
Definition: race_manager.hpp:350
std::vector< std::string > m_ai_kart_list
The list of AI karts to use.
Definition: race_manager.hpp:331
void setDefaultAIKartList(const std::vector< std::string > &ai_list)
Sets the default list of AI karts to use.
Definition: race_manager.cpp:175
void setTrack(const std::string &track)
In case of non GP mode set the track to use.
Definition: race_manager.cpp:321
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:1176
void setupPlayerKartInfo()
Fills up the remaining kart slots with AI karts.
Definition: race_manager.cpp:1165
Difficulty getDifficulty() const
Returns the difficulty.
Definition: race_manager.hpp:597
KartType
Different kart types: A local player, a player connected via network, an AI kart, the leader kart (cu...
Definition: race_manager.hpp:242
void setNumPlayers(int players, int local_players=-1)
Sets the number of players and optional the number of local players.
Definition: race_manager.cpp:275
std::vector< bool > m_reverse_track
Whether a track should be reversed.
Definition: race_manager.hpp:319
int currentModeTimePrecision() const
Returns the number of second's decimals to display.
Definition: race_manager.hpp:772
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:165
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:224
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:1085
bool hasAI()
Returns if the currently set minor game mode can be used by the AI.
Definition: race_manager.hpp:186
static const core::stringw getNameOf(const MinorRaceModeType mode)
Returns a (translated) name of a minor race mode.
Definition: race_manager.cpp:1277
std::string getDifficultyAsString(Difficulty diff) const
Returns the specified difficulty as a string.
Definition: race_manager.hpp:600
void startNextRace()
Starts the next (or first) race.
Definition: race_manager.cpp:548
void setDifficulty(Difficulty diff)
Sets the difficulty.
Definition: race_manager.cpp:312
bool supportsLiveJoining() const
Whether the current game mode allow live joining even the current game
Definition: race_manager.hpp:931
~RaceManager()
Destructor for the race manager.
Definition: race_manager.cpp:156
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:257
int m_gp_total_laps
Total laps from every track, used in Lap Trial mode.
Definition: race_manager.hpp:352
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:1100
void setAIKartList(const std::vector< std::string > &rkl)
Sets the AI to use.
Definition: race_manager.hpp:817
MinorRaceModeType
Minor variants to the major types of race.
Definition: race_manager.hpp:110
bool modeHasHighscores()
Returns true if the currently selected minor mode has highscores.
Definition: race_manager.hpp:788
void startNew(bool from_overworld)
Starts a new race or GP (or other mode).
Definition: race_manager.cpp:384
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:245
bool m_continue_saved_gp
Determines if saved GP should be continued or not.
Definition: race_manager.hpp:366
static const char * getIconOf(const MinorRaceModeType mode)
Returns the icon for a minor race mode.
Definition: race_manager.hpp:165
MajorRaceModeType
The major types or races supported in STK.
Definition: race_manager.hpp:93
const std::vector< std::string > & getAIKartList() const
Returns the list of AI karts to use.
Definition: race_manager.hpp:704
AISuperPower
True if the AI should have additional abbilities, e.g.
Definition: race_manager.hpp:134
void saveGP()
Saves the current GP to the config.
Definition: race_manager.cpp:774
bool isLinearRaceMode(const MinorRaceModeType mode) const
get information about given mode (returns true if 'mode' is of linear races type)
Definition: race_manager.hpp:723
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:1121
unsigned int getNumberOfKarts() const
Returns the selected number of karts (selected number of players and AI karts.
Definition: race_manager.hpp:540
bool isSoccerMode() const
Returns true if the current mode is a soccer mode.
Definition: race_manager.hpp:745
static const MinorRaceModeType getModeIDFromInternalName(const std::string &name)
Returns the minor mode id from a string identifier.
Definition: race_manager.hpp:209
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:316
RaceManager()
Constructs the race manager.
Definition: race_manager.cpp:120
std::string m_ai_kart_override
If set, specifies which kart to use for AI(s)
Definition: race_manager.hpp:325
int getNumLaps() const
Returns the number lf laps.
Definition: race_manager.hpp:585
static Difficulty convertDifficulty(const std::string &difficulty)
Converst the difficulty given as a string into a Difficult enum.
Definition: race_manager.cpp:294
bool isBattleMode() const
Returns true if the current mode is a battle mode.
Definition: race_manager.hpp:734
Difficulty
Game difficulty.
Definition: race_manager.hpp:230
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:529
MajorRaceModeType m_major_mode
The major mode (single race, GP).
Definition: race_manager.hpp:303
MinorRaceModeType m_minor_mode
The minor mode (race, time trial, ftl, battle mode).
Definition: race_manager.hpp:306
bool modeHasLaps() const
Returns true if the current mode has laps.
Definition: race_manager.hpp:778
unsigned int m_num_local_players
Number of local players.
Definition: race_manager.hpp:312
void setPlayerHandicap(unsigned int player_id, HandicapLevel handicap)
Sets the handicap for a player.
Definition: race_manager.cpp:234
Difficulty m_difficulty
The selected difficulty.
Definition: race_manager.hpp:300
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:711
void computeRandomKartList()
Computes the list of random karts to be used for the AI.
Definition: race_manager.cpp:333
std::vector< std::string > m_default_ai_list
The list of default AI karts to use.
Definition: race_manager.hpp:322
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:1052
core::stringw getDifficultyName(Difficulty diff) const
Returns the specified difficulty as a string.
Definition: race_manager.cpp:1305
bool getReverseTrack() const
Definition: race_manager.hpp:594
Definition: remote_kart_info.hpp:51
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:114
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:42
This data structure accumulates kart data and race result data from each race.
Definition: race_manager.hpp:253
HandicapLevel m_handicap
The handicap for this player.
Definition: race_manager.hpp:278
std::string m_ident
The kart identifier.
Definition: race_manager.hpp:255
float m_color
Kart color of player (used in gp win / lose screen).
Definition: race_manager.hpp:280
int m_local_player_id
Player controling the kart, for AI: -1.
Definition: race_manager.hpp:269
float m_last_time
Needed for restart.
Definition: race_manager.hpp:265
std::string m_player_name
For networked karts.
Definition: race_manager.hpp:257
int m_global_player_id
Global ID of player.
Definition: race_manager.hpp:271
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:274
float m_overall_time
Sum of times of all races.
Definition: race_manager.hpp:263
KartType m_kart_type
Kart type: AI, player, network player etc.
Definition: race_manager.hpp:267
int m_last_score
Needed for restart race, and for race results GUI.
Definition: race_manager.hpp:261
bool m_boosted_ai
Boosted status (AI only).
Definition: race_manager.hpp:276