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