SuperTuxKart
three_strikes_battle.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2004-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 THREE_STRIKES_BATTLE_HPP
20 #define THREE_STRIKES_BATTLE_HPP
21 
22 
23 #include "modes/world_with_rank.hpp"
24 #include "tracks/track_object.hpp"
25 #include "states_screens/race_gui_base.hpp"
26 
27 #include <string>
28 
29 class PhysicalObject;
30 
37 {
38 private:
39 
40  // This struct is used to sort karts by time/lives
41  struct KartValues
42  {
43  int id;
44  int time;
45  int lives;
46 
47  bool operator < (const KartValues& k) const
48  {
49  return (time == k.time) ? (lives < k.lives) : (time < k.time);
50  } // operator <
51  }; // KartValues
52 
53  struct BattleInfo
54  {
55  int m_lives;
56  };
57 
60  std::vector<BattleInfo> m_kart_info;
61 
63  irr::scene::IMesh* m_tire;
64 
68 
70  core::vector3df m_tire_position;
71 
73  core::vector3df m_tire_offsets[4];
74 
76  float m_tire_radius[4];
77 
79  std::string m_tire_dir;
80 
83 
85 
88  int m_frame_count;
89  int m_start_time;
90  int m_total_hit;
91 
92  std::vector<AbstractKart*> m_spare_tire_karts;
93  int m_next_sta_spawn_ticks;
94 
95 public:
97  struct BattleEvent
98  {
99  float m_time;
100  std::vector<BattleInfo> m_kart_info;
101  };
102  // ------------------------------------------------------------------------
103  std::vector<BattleEvent> m_battle_events;
104  // ------------------------------------------------------------------------
106  // ------------------------------------------------------------------------
107  virtual ~ThreeStrikesBattle();
108  // ------------------------------------------------------------------------
109  virtual void init() OVERRIDE;
110  // ------------------------------------------------------------------------
111  // clock events
112  virtual bool isRaceOver() OVERRIDE;
113  // ------------------------------------------------------------------------
114  virtual void terminateRace() OVERRIDE;
115  // ------------------------------------------------------------------------
116  // overriding World methods
117  virtual void reset(bool restart=false) OVERRIDE;
118  // ------------------------------------------------------------------------
119  virtual void getKartsDisplayInfo(
120  std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
121  // ------------------------------------------------------------------------
122  virtual bool raceHasLaps() OVERRIDE { return false; }
123  // ------------------------------------------------------------------------
124  virtual bool shouldDrawSpeedometerDigit() const OVERRIDE { return true; }
125  // ------------------------------------------------------------------------
126  virtual std::pair<int, video::SColor>
127  getSpeedometerDigit(const AbstractKart *kart) const OVERRIDE;
128  // ------------------------------------------------------------------------
129  virtual const std::string& getIdent() const OVERRIDE;
130  // ------------------------------------------------------------------------
131  virtual bool kartHit(int kart_id, int hitter = -1) OVERRIDE;
132  // ------------------------------------------------------------------------
133  virtual void update(int ticks) OVERRIDE;
134  // ------------------------------------------------------------------------
135  virtual void kartAdded(AbstractKart* kart, scene::ISceneNode* node)
136  OVERRIDE;
137  // ------------------------------------------------------------------------
138  virtual void enterRaceOverState() OVERRIDE;
139  // ------------------------------------------------------------------------
140  virtual void loadCustomModels() OVERRIDE;
141  // ------------------------------------------------------------------------
142  void updateKartRanks();
143  // ------------------------------------------------------------------------
144  void increaseRescueCount() { m_total_rescue++; }
145  // ------------------------------------------------------------------------
146  void addKartLife(unsigned int id);
147  // ------------------------------------------------------------------------
148  int getKartLife(unsigned int id) const { return m_kart_info[id].m_lives; }
149  // ------------------------------------------------------------------------
150  bool spareTireKartsSpawned() const;
151  // ------------------------------------------------------------------------
152  void spawnSpareTireKarts();
153 
154 }; // ThreeStrikesBattles
155 
156 
157 #endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Definition: physical_object.hpp:40
An abstract base class for the two race guis (race_gui and race_result gui)
Definition: race_gui_base.hpp:50
An implementation of WorldWithRank, to provide the 3 strikes battle game mode.
Definition: three_strikes_battle.hpp:37
virtual bool kartHit(int kart_id, int hitter=-1) OVERRIDE
Called when a kart is hit.
Definition: three_strikes_battle.cpp:216
virtual void terminateRace() OVERRIDE
Called when the race finishes, i.e.
Definition: three_strikes_battle.cpp:498
float m_tire_radius[4]
The radius of the karts original tires.
Definition: three_strikes_battle.hpp:76
virtual bool shouldDrawSpeedometerDigit() const OVERRIDE
Definition: three_strikes_battle.hpp:124
virtual std::pair< int, video::SColor > getSpeedometerDigit(const AbstractKart *kart) const OVERRIDE
Definition: three_strikes_battle.cpp:542
virtual void kartAdded(AbstractKart *kart, scene::ISceneNode *node) OVERRIDE
Adds two tires to each of the kart.
Definition: three_strikes_battle.cpp:178
virtual void reset(bool restart=false) OVERRIDE
Called when a battle is restarted.
Definition: three_strikes_battle.cpp:98
int m_total_rescue
Profiling usage.
Definition: three_strikes_battle.hpp:87
virtual bool raceHasLaps() OVERRIDE
Called when it is needed to know whether this kind of race involves counting laps.
Definition: three_strikes_battle.hpp:122
virtual void enterRaceOverState() OVERRIDE
Called when the race is finished, but it still leaves some time for an end of race animation,...
Definition: three_strikes_battle.cpp:566
int m_insert_tire
Indicates the number of tires that should be inserted into the track.
Definition: three_strikes_battle.hpp:67
virtual bool isRaceOver() OVERRIDE
The battle is over if only one kart is left, or no player kart.
Definition: three_strikes_battle.cpp:477
virtual void getKartsDisplayInfo(std::vector< RaceGUIBase::KartIconDisplayInfo > *info) OVERRIDE
Returns the data to display in the race gui.
Definition: three_strikes_battle.cpp:507
std::string m_tire_dir
The directory of the original kart tires.
Definition: three_strikes_battle.hpp:79
core::vector3df m_tire_position
For tires that are blown away.
Definition: three_strikes_battle.hpp:70
std::vector< BattleInfo > m_kart_info
This vector contains an 'BattleInfo' struct for every kart in the race.
Definition: three_strikes_battle.hpp:60
float m_tire_rotation
A rotation to apply to the tires when inserting them.
Definition: three_strikes_battle.hpp:82
virtual void update(int ticks) OVERRIDE
Update the world and the track.
Definition: three_strikes_battle.cpp:357
ThreeStrikesBattle()
Constructor.
Definition: three_strikes_battle.cpp:51
virtual void init() OVERRIDE
Initialises the three strikes battle.
Definition: three_strikes_battle.cpp:72
virtual ~ThreeStrikesBattle()
Destructor.
Definition: three_strikes_battle.cpp:83
core::vector3df m_tire_offsets[4]
The original locations of the tires of a kart.
Definition: three_strikes_battle.hpp:73
irr::scene::IMesh * m_tire
The mesh of the tire which is displayed when a kart loses a life.
Definition: three_strikes_battle.hpp:63
void updateKartRanks()
Updates the ranking of the karts.
Definition: three_strikes_battle.cpp:445
virtual const std::string & getIdent() const OVERRIDE
Returns the internal identifier for this race.
Definition: three_strikes_battle.cpp:348
A WorldWithRank is a world where the karts are ranked.
Definition: world_with_rank.hpp:39
Used to show a nice graph when battle is over.
Definition: three_strikes_battle.hpp:98
Definition: three_strikes_battle.hpp:54
Definition: three_strikes_battle.hpp:42