SuperTuxKart
Loading...
Searching...
No Matches
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
38class AbstractKart;
39class NetworkString;
40class SavedGrandPrix;
41class Track;
42
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" );
55
88{
89public:
93 {
94 MAJOR_MODE_GRAND_PRIX = 0,
95 MAJOR_MODE_SINGLE
96 };
97
98 // quick method to tell the difference between battle modes and race modes
99 // think of it like a bitmask, but done in decimal to avoid endianness
100 // issues
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)
105
106 // ----------------------------------------------------------------------------------------
110 {
111 MINOR_MODE_NONE = -1,
112
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),
116
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),
121
122 MINOR_MODE_EASTER_EGG = EASTER_EGG(0),
123
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)
128 };
129
130 // ----------------------------------------------------------------------------------------
134 {
135 SUPERPOWER_NONE = 0,
136 SUPERPOWER_NOLOK_BOSS = 1
137 };
138
139 // ----------------------------------------------------------------------------------------
143 static const std::string& getIdentOf(const MinorRaceModeType mode)
144 {
145 switch (mode)
146 {
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);
157 return IDENT_STD; // stop compiler warning
158 }
159 } // getIdentOf
160
161 // ----------------------------------------------------------------------------------------
165 static const char* getIconOf(const MinorRaceModeType mode)
166 {
167 switch (mode)
168 {
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;
179 }
180 } // getIconOf
181
182 // ----------------------------------------------------------------------------------------
183 static const core::stringw getNameOf(const MinorRaceModeType mode);
184 // ----------------------------------------------------------------------------------------
186 bool hasAI()
187 {
188 switch (m_minor_mode)
189 {
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;
200 }
201 } // hasAI
202
203
204 // ----------------------------------------------------------------------------------------
210 const std::string &name)
211 {
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;
220
221 assert(0);
222 return MINOR_MODE_NONE;
223 }
224
225#undef LINEAR_RACE
226#undef BATTLE_ARENA
227#undef MISC
228
230 enum Difficulty { DIFFICULTY_EASY = 0,
231 DIFFICULTY_FIRST = DIFFICULTY_EASY,
232 DIFFICULTY_MEDIUM,
233 DIFFICULTY_HARD,
234 DIFFICULTY_BEST,
235 DIFFICULTY_LAST = DIFFICULTY_BEST,
236 DIFFICULTY_COUNT,
237 DIFFICULTY_NONE};
238
242 enum KartType { KT_PLAYER, KT_NETWORK_PLAYER, KT_AI, KT_LEADER,
243 KT_GHOST, KT_SPARE_TIRE };
244private:
245
246 bool m_started_from_overworld;
247
248public:
249
253 {
255 std::string m_ident;
257 std::string m_player_name;
258 // Score for this kart. */
259 int m_score;
280 float m_color;
281 KartStatus(const std::string& ident, const int& prev_finish_pos,
282 int local_player_id, int global_player_id,
283 int init_gp_rank, KartType kt,
284 HandicapLevel handicap) :
285 m_ident(ident), m_score(0), m_last_score(0),
286 m_overall_time(0.0f), m_last_time(0.0f),
287 m_kart_type(kt),
288 m_local_player_id(local_player_id),
289 m_global_player_id(global_player_id),
290 m_gp_rank(init_gp_rank), m_handicap(handicap)
291 { m_boosted_ai = false; m_color = 0.0f; }
292
293 }; // KartStatus
294private:
295
297 std::vector<KartStatus> m_kart_status;
298
301
304
308 std::vector<RemoteKartInfo> m_player_karts;
309 std::vector<std::string> m_tracks;
310
313
316 std::vector<int> m_num_laps;
317
319 std::vector<bool> m_reverse_track;
320
322 std::vector<std::string> m_default_ai_list;
323
326
327 AISuperPower m_ai_superpower;
328
331 std::vector<std::string> m_ai_kart_list;
332 int m_track_number;
333 GrandPrixData m_grand_prix;
334 SavedGrandPrix* m_saved_gp;
335 int m_num_karts;
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;
344 int m_coin_target;
345 float m_time_target;
346 int m_goal_target;
347 int m_hit_capture_limit;
348 int m_skipped_tracks_in_gp;
353 void startNextRace(); // start a next race
354
355 friend bool operator< (const KartStatus& left, const KartStatus& right)
356 {
357 return (left.m_score < right.m_score) ||
358 (left.m_score == right.m_score &&
359 left.m_overall_time > right.m_overall_time);
360 }
361
362 bool m_have_kart_last_position_on_overworld;
363 Vec3 m_kart_last_position_on_overworld;
364
367
368 bool m_is_recording_race;
369
370 bool m_has_ghost_karts;
371
372 bool m_watching_replay;
373public:
374 // ----------------------------------------------------------------------------------------
375 static RaceManager* get();
376 // ----------------------------------------------------------------------------------------
377 static void create();
378 // ----------------------------------------------------------------------------------------
379 static void destroy();
380 // ----------------------------------------------------------------------------------------
381 static void clear();
382 // ----------------------------------------------------------------------------------------
383 RaceManager();
384 ~RaceManager();
385
386 void reset();
387 void setPlayerKart(unsigned int player_id, const std::string &kart_name);
388 void setPlayerKart(unsigned int player_id,
389 const RemoteKartInfo& ki);
390
393 void setKartTeam(unsigned int player_id, KartTeam team);
394
397 void setPlayerHandicap(unsigned int player_id, HandicapLevel handicap);
398
402 void setTrack(const std::string& track);
403
408 const AbstractKart* getKartWithGPRank(unsigned int n);
409
412 int getLocalPlayerGPRank(const int playerID) const;
413
414
419 void computeGPRanks();
420
424 void setDifficulty(Difficulty diff);
425 static Difficulty convertDifficulty(const std::string &difficulty);
426 void startNew(bool from_overworld);
427 void next();
428 void rerunRace();
429 void exitRace(bool delete_world=true);
430 void startGP(const GrandPrixData &gp, bool from_overworld,
431 bool continue_saved_gp);
432 void saveGP();
433 void startSingleRace(const std::string &track_ident, const int num_laps,
434 bool from_overworld);
435 void startWatchingReplay(const std::string &track_ident, const int num_laps);
436 void setupPlayerKartInfo();
437 void kartFinishedRace(const AbstractKart* kart, float time);
438 void setNumPlayers(int players, int local_players=-1);
439 void setDefaultAIKartList(const std::vector<std::string> &ai_list);
441
442 // ----------------------------------------------------------------------------------------
443 bool hasTimeTarget() const { return m_time_target > 0.0f; }
444 // ----------------------------------------------------------------------------------------
445 void setMaxGoal(int max_goal)
446 {
447 m_time_target = 0.0f;
448 m_goal_target = max_goal;
449 } // setMaxGoal
450 // ----------------------------------------------------------------------------------------
451 int getMaxGoal(){ return m_goal_target; }
452 // ----------------------------------------------------------------------------------------
453 void setCoinTarget(int num) { m_coin_target = num; }
454 // ----------------------------------------------------------------------------------------
455 void setGrandPrix(const GrandPrixData &gp)
456 {
457 m_grand_prix = gp;
458 setCoinTarget(0);
459 } // setGrandPrix
460 // ----------------------------------------------------------------------------------------
461 void setAIKartOverride(const std::string& kart)
462 {
463 m_ai_kart_override = kart;
464 } // setAIKartOverride
465 // ----------------------------------------------------------------------------------------
466 void setAISuperPower(AISuperPower superpower)
467 {
468 m_ai_superpower = superpower;
469 } // setAISuperPower
470 // ----------------------------------------------------------------------------------------
471 AISuperPower getAISuperPower() const { return m_ai_superpower; }
472 // ----------------------------------------------------------------------------------------
473 void setNumLaps(int num)
474 {
475 m_num_laps.clear();
476 m_num_laps.push_back(num);
477 } // setNumLaps
478 // ----------------------------------------------------------------------------------------
479 void setReverseTrack(bool r_t)
480 {
481 m_reverse_track.clear();
482 m_reverse_track.push_back(r_t);
483 } // setReverseTrack
484 // ----------------------------------------------------------------------------------------
485 void setMajorMode(MajorRaceModeType mode) { m_major_mode = mode; }
486 // ----------------------------------------------------------------------------------------
487 void setMinorMode(MinorRaceModeType mode)
488 {
489 m_minor_mode = mode;
490 } // setMinorMode
491 // ----------------------------------------------------------------------------------------
492 void setNumKarts(int num)
493 {
494 m_num_karts = num;
496 m_ai_superpower = SUPERPOWER_NONE;
497 } // setNumKarts
498 // ----------------------------------------------------------------------------------------
499 void setNumRedAI(unsigned int num)
500 {
501 m_num_red_ai = num;
502 } // setNumRedAI
503 // ----------------------------------------------------------------------------------------
504 void setNumBlueAI(unsigned int num)
505 {
506 m_num_blue_ai = num;
507 } // setNumBlueAI
508 // ----------------------------------------------------------------------------------------
509 void setTimeTarget(float time)
510 {
511 m_goal_target = 0;
512 m_time_target = time;
513 } // setTimeTarget
514 // ----------------------------------------------------------------------------------------
515 RemoteKartInfo& getKartInfo(unsigned int n)
516 {
517 return m_player_karts[n];
518 } // getKartInfo
519 // ----------------------------------------------------------------------------------------
520 unsigned int getNumLocalPlayers() const
521 {
522 return m_num_local_players;
523 } // getNumLocalPlayers
524
525 // ----------------------------------------------------------------------------------------
530 {
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);
536 } // getIfEmptyScreenSpaceExists
537 // ----------------------------------------------------------------------------------------
540 unsigned int getNumberOfKarts() const { return m_num_karts; }
541 // ----------------------------------------------------------------------------------------
542 unsigned int getNumberOfAIKarts() const
543 {
544 return (unsigned int)m_ai_kart_list.size();
545 } // getNumberOfAIKarts
546 // ----------------------------------------------------------------------------------------
547 unsigned int getNumberOfRedAIKarts() const { return m_num_red_ai; }
548 // ----------------------------------------------------------------------------------------
549 unsigned int getNumberOfBlueAIKarts() const { return m_num_blue_ai; }
550 // ----------------------------------------------------------------------------------------
551 unsigned int getNumNonGhostKarts() const
552 { return m_num_karts - m_num_ghost_karts; }
553 // ----------------------------------------------------------------------------------------
554 MajorRaceModeType getMajorMode() const { return m_major_mode; }
555 // ----------------------------------------------------------------------------------------
556 MinorRaceModeType getMinorMode() const { return m_minor_mode; }
557 // ----------------------------------------------------------------------------------------
558 std::string getMinorModeName() const
559 {
560 switch (m_minor_mode)
561 {
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 "";
571 }
572 }
573 // ----------------------------------------------------------------------------------------
574 unsigned int getNumPlayers() const
575 {
576 return (unsigned int) m_player_karts.size();
577 } // getNumPlayers
578 // ----------------------------------------------------------------------------------------
585 int getNumLaps() const
586 {
587 if(modeHasLaps())
588 return m_num_laps[m_track_number];
589 // else
590 return 9999;
591 } // getNumLaps
592 // ----------------------------------------------------------------------------------------
594 bool getReverseTrack() const { return m_reverse_track[m_track_number]; }
595 // ----------------------------------------------------------------------------------------
598 // ----------------------------------------------------------------------------------------
600 std::string getDifficultyAsString(Difficulty diff) const
601 {
602 switch(diff)
603 {
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);
609 }
610 return "";
611 } // getDifficultyAsString
612
613 // ----------------------------------------------------------------------------------------
614 core::stringw getDifficultyName(Difficulty diff) const;
615 // ----------------------------------------------------------------------------------------
616 const std::string getTrackName() const
617 {
618 if (m_tracks.empty())
619 return "";
620 return m_tracks[m_track_number];
621 }
622 // ----------------------------------------------------------------------------------------
623 const GrandPrixData& getGrandPrix() const { return m_grand_prix; }
624 // ----------------------------------------------------------------------------------------
625 unsigned int getFinishedKarts() const { return m_num_finished_karts; }
626 // ----------------------------------------------------------------------------------------
627 unsigned int getFinishedPlayers() const { return m_num_finished_players; }
628 // ----------------------------------------------------------------------------------------
629 int getKartGPRank(const int kart_id)const
630 {
631 return m_kart_status[kart_id].m_gp_rank;
632 } // getKartGPRank
633 // ----------------------------------------------------------------------------------------
634 const std::string& getKartIdent(int kart) const
635 {
636 return m_kart_status[kart].m_ident;
637 } // getKartIdent
638 // ----------------------------------------------------------------------------------------
639 int getKartScore(int krt) const { return m_kart_status[krt].m_score; }
640 // ----------------------------------------------------------------------------------------
641 int getKartPrevScore(int krt) const
642 {
643 return m_kart_status[krt].m_last_score;
644 } // getKartPrevScore
645 // ----------------------------------------------------------------------------------------
646 int getKartLocalPlayerId(int k) const
647 {
648 assert(k < (int)m_kart_status.size());
649 return m_kart_status[k].m_local_player_id;
650 } // getKartLocalPlayerId
651 // ----------------------------------------------------------------------------------------
652 int getKartGlobalPlayerId(int k) const
653 {
654 if (k >= (int)m_kart_status.size())
655 return -1;
656 return m_kart_status[k].m_global_player_id;
657 } // getKartGlobalPlayerId
658 // ----------------------------------------------------------------------------------------
659 float getOverallTime(int kart) const
660 {
661 return m_kart_status[kart].m_overall_time;
662 } // getOverallTime
663 // ----------------------------------------------------------------------------------------
664 float getKartRaceTime(int kart) const
665 {
666 return m_kart_status[kart].m_last_time;
667 } // getKartRaceTime
668 // ----------------------------------------------------------------------------------------
669 KartType getKartType(int kart) const
670 {
671 return m_kart_status[kart].m_kart_type;
672 } // getKartType
673 // ----------------------------------------------------------------------------------------
674 HandicapLevel getPlayerHandicap(int kart) const
675 {
676 return m_kart_status[kart].m_handicap;
677 } // getPlayerHandicap
678 // ----------------------------------------------------------------------------------------
679 bool hasBoostedAI(int kart) const
680 {
681 return m_kart_status[kart].m_boosted_ai;
682 } // getKartRaceTime
683 // ----------------------------------------------------------------------------------------
684 void setKartColor(int kart, float color)
685 {
686 m_kart_status[kart].m_color = color;
687 } // setKartColor
688 // ----------------------------------------------------------------------------------------
689 float getKartColor(int kart) const
690 {
691 return m_kart_status[kart].m_color;
692 } // getKartColor
693 // ----------------------------------------------------------------------------------------
694 int getCoinTarget() const { return m_coin_target; }
695 // ----------------------------------------------------------------------------------------
696 float getTimeTarget() const { return m_time_target; }
697 // ----------------------------------------------------------------------------------------
698 int getTrackNumber() const { return m_track_number; }
699 // ----------------------------------------------------------------------------------------
700 int getNumOfTracks() const { return (int)m_tracks.size(); }
701 // ----------------------------------------------------------------------------------------
704 const std::vector<std::string>& getAIKartList() const
705 {
706 return m_ai_kart_list;
707 } // getAIKartList
708 // ----------------------------------------------------------------------------------------
711 bool isLinearRaceMode() const
712 {
713 const int id = (int)m_minor_mode;
714 // info is stored in its ID for conveniance, see the macros LINEAR_RACE
715 // and BATTLE_ARENA above for exact meaning.
716 if(id > 999 && id < 2000) return true;
717 else return false;
718 } // isLinearRaceMode
719
720 // ----------------------------------------------------------------------------------------
723 bool isLinearRaceMode(const MinorRaceModeType mode) const
724 {
725 const int id = (int)mode;
726 // info is stored in its ID for conveniance, see the macros LINEAR_RACE
727 // and BATTLE_ARENA above for exact meaning.
728 if(id > 999 && id < 2000) return true;
729 else return false;
730 } // isLinearRaceMode
731
732 // ----------------------------------------------------------------------------------------
734 bool isBattleMode() const
735 {
736 const int id = (int)m_minor_mode;
737 // This uses the numerical id of the mode, see the macros
738 // LINEAR_RACE and BATTLE_ARENA above for exact meaning.
739 if (id >= 2000 && id <= 2002) return true;
740 else return false;
741 } // isBattleMode
742
743 // ----------------------------------------------------------------------------------------
745 bool isSoccerMode() const
746 {
747 const int id = (int)m_minor_mode;
748 // This uses the numerical id of the mode, see the macros
749 // LINEAR_RACE and BATTLE_ARENA above for exact meaning.
750 if (id == 2003) return true;
751 else return false;
752 } // isSoccerMode
753
754 // ----------------------------------------------------------------------------------------
755 bool isTutorialMode() const { return m_minor_mode == MINOR_MODE_TUTORIAL; }
756
757 // ----------------------------------------------------------------------------------------
758 bool isFollowMode() const { return m_minor_mode == MINOR_MODE_FOLLOW_LEADER; }
759
760 // ----------------------------------------------------------------------------------------
761 bool isCTFMode() const { return m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG; }
762
763 // ----------------------------------------------------------------------------------------
764 bool isEggHuntMode() const { return m_minor_mode == MINOR_MODE_EASTER_EGG; }
765
766 // ----------------------------------------------------------------------------------------
767 bool isTimeTrialMode() const { return m_minor_mode == MINOR_MODE_TIME_TRIAL; }
768 // ----------------------------------------------------------------------------------------
769 bool isLapTrialMode() const { return m_minor_mode == MINOR_MODE_LAP_TRIAL; }
770 // ----------------------------------------------------------------------------------------
773 {
774 return 3; // display milliseconds
775 } // currentModeTimePrecision
776 // ----------------------------------------------------------------------------------------
778 bool modeHasLaps() const
779 {
780 if (!isLinearRaceMode()) return false;
781 const int id = (int)m_minor_mode;
782 // See meaning of IDs above
783 const int answer = (id-1000)/100;
784 return answer!=0;
785 } // modeHasLaps
786 // ----------------------------------------------------------------------------------------
789 {
790 //FIXME: this information is duplicated. RaceManager knows about it,
791 // and each World may set m_use_highscores to true or false.
792 // The reason for this duplication is that we might want to know
793 // whether to display highscores without creating a World.
794 return !isBattleMode() &&
795 !isSoccerMode() &&
796 m_minor_mode != MINOR_MODE_FOLLOW_LEADER;
797 } // modeHasHighscore
798 // ----------------------------------------------------------------------------------------
799 bool raceWasStartedFromOverworld() const
800 {
801 return m_started_from_overworld;
802 } // raceWasStartedFromOverworld
803
804 // ----------------------------------------------------------------------------------------
809 bool allPlayerFinished() const
810 {
811 return m_num_finished_players == m_player_karts.size();
812 } // allPlayerFinished
813 // ----------------------------------------------------------------------------------------
817 void setAIKartList(const std::vector<std::string>& rkl)
818 {
819 m_ai_kart_list = rkl;
820 } // setAIKartList
821 // ----------------------------------------------------------------------------------------
822 bool haveKartLastPositionOnOverworld()
823 {
824 return m_have_kart_last_position_on_overworld;
825 } // haveKartLastPositionOnOverworld
826 // ----------------------------------------------------------------------------------------
827 void setKartLastPositionOnOverworld(const Vec3 &pos)
828 {
829 m_have_kart_last_position_on_overworld = true;
830 m_kart_last_position_on_overworld = pos;
831 } // setKartLastPositionOnOverworld
832 // ----------------------------------------------------------------------------------------
833 void clearKartLastPositionOnOverworld()
834 {
835 m_have_kart_last_position_on_overworld = false;
836 } // clearKartLastPositionOnOverworld
837 // ----------------------------------------------------------------------------------------
838 Vec3 getKartLastPositionOnOverworld()
839 {
840 return m_kart_last_position_on_overworld;
841 } // getKartLastPositionOnOverworld
842 // ----------------------------------------------------------------------------------------
843 void setRecordRace(bool record)
844 {
845 m_is_recording_race = record;
846 } // setRecordRace
847 // ----------------------------------------------------------------------------------------
848 void setRaceGhostKarts(bool ghost)
849 {
850 m_has_ghost_karts = ghost;
851 } // setRaceGhostKarts
852 // ----------------------------------------------------------------------------------------
853 void setWatchingReplay(bool watch)
854 {
855 m_watching_replay = watch;
856 } // setWatchingReplay
857 // ----------------------------------------------------------------------------------------
858 bool isRecordingRace() const
859 {
860 return m_is_recording_race;
861 } // isRecordingRace
862 // ----------------------------------------------------------------------------------------
863 bool hasGhostKarts() const
864 {
865 return m_has_ghost_karts;
866 } // hasGhostKarts
867 // ----------------------------------------------------------------------------------------
868 bool isWatchingReplay() const
869 {
870 return m_watching_replay;
871 } // isWatchingReplay
872 // ----------------------------------------------------------------------------------------
873 void addSpareTireKart(const std::string& name)
874 {
875 m_kart_status.push_back(KartStatus(name, 0, -1, -1,
876 -1, KT_SPARE_TIRE, HANDICAP_NONE));
877 m_num_spare_tire_karts++;
878 m_num_karts++;
879 } // addSpareTireKart
880 // ----------------------------------------------------------------------------------------
881 void setSpareTireKartNum(unsigned int i)
882 {
883 m_num_spare_tire_karts = i;
884 } // setSpareTireKartNum
885 // ----------------------------------------------------------------------------------------
886 unsigned int getNumSpareTireKarts() const
887 {
888 return m_num_spare_tire_karts;
889 } // getNumSpareTireKarts
890 // ----------------------------------------------------------------------------------------
891 void configGrandPrixResultFromNetwork(NetworkString& ns);
892 // ----------------------------------------------------------------------------------------
893 void clearNetworkGrandPrixResult();
894 // ----------------------------------------------------------------------------------------
895 void setHitCaptureTime(int hc, float time)
896 {
897 m_hit_capture_limit = hc;
898 m_time_target = time;
899 }
900 // ----------------------------------------------------------------------------------------
901 int getHitCaptureLimit() const { return m_hit_capture_limit; }
902 // ----------------------------------------------------------------------------------------
903 bool teamEnabled() const
904 {
905 return m_minor_mode == MINOR_MODE_SOCCER ||
906 m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG;
907 }
908 // ----------------------------------------------------------------------------------------
909 void setFlagReturnTicks(unsigned ticks) { m_flag_return_ticks = ticks; }
910 // ----------------------------------------------------------------------------------------
911 unsigned getFlagReturnTicks() const { return m_flag_return_ticks; }
912 // ----------------------------------------------------------------------------------------
913 void setFlagDeactivatedTicks(unsigned ticks)
914 { m_flag_deactivated_ticks = ticks; }
915 // ----------------------------------------------------------------------------------------
916 unsigned getFlagDeactivatedTicks() const
917 { return m_flag_deactivated_ticks; }
918 // ----------------------------------------------------------------------------------------
919 int getSkippedTracksInGP() const { return m_skipped_tracks_in_gp; }
920 // ----------------------------------------------------------------------------------------
921 void addSkippedTrackInGP() { m_skipped_tracks_in_gp++; }
922 // ----------------------------------------------------------------------------------------
923 void setGPTimeTarget(float time_target) { m_gp_time_target = time_target; }
924 // ----------------------------------------------------------------------------------------
925 int getGPTotalLaps() const { return m_gp_total_laps; }
926 // ----------------------------------------------------------------------------------------
927 void addGPTotalLaps(int laps) { m_gp_total_laps += laps; }
928 // ----------------------------------------------------------------------------------------
932 {
933 return m_minor_mode == MINOR_MODE_SOCCER ||
934 m_minor_mode == MINOR_MODE_CAPTURE_THE_FLAG ||
935 m_minor_mode == MINOR_MODE_FREE_FOR_ALL;
936 }
937}; // RaceManager
938
939#endif
940
941/* 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: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