SuperTuxKart
world_with_rank.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2010-2015 Joerg Henrichs
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 #ifndef HEADER_WORLD_WITH_RANK_HPP
19 #define HEADER_WORLD_WITH_RANK_HPP
20 
21 #include <vector>
22 
23 #include "modes/world.hpp"
24 
25 class AbstractKart;
26 class TrackSector;
27 
38 class WorldWithRank : public World
39 {
40 protected:
42  std::vector<int> m_position_index;
43 
46 
49  std::vector<int> m_score_for_position;
50 
51 #ifdef DEBUG
52 
54  std::vector<bool> m_position_used;
55 
59  bool m_position_setting_initialised;
60 #endif
61 
62  unsigned int getClosestStartPoint(AbstractKart *kart);
63 
65  std::vector<TrackSector*> m_kart_track_sector;
66 
67  // ------------------------------------------------------------------------
68  void updateSectorForKarts();
69 
70 public:
71  WorldWithRank() : World() {}
72  virtual ~WorldWithRank();
76  virtual void init() OVERRIDE;
77  virtual void reset(bool restart=false) OVERRIDE;
78 
79  bool displayRank() const { return m_display_rank; }
80 
81  void beginSetKartPositions();
82  bool setKartPosition(unsigned int kart_id,
83  unsigned int position);
84  void endSetKartPositions();
85  AbstractKart* getKartAtPosition(unsigned int p) const;
88  virtual AbstractKart* getKartAtDrawingPosition(unsigned int p) const
89  { return getKartAtPosition(p); }
90  virtual int getScoreForPosition(int p);
91  virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
92  // ------------------------------------------------------------------------
95  TrackSector* getTrackSector(unsigned int kart_index) const
96  {
97  assert(kart_index < m_kart_track_sector.size());
98  return m_kart_track_sector[kart_index];
99  } // getTrackSector
100  // ------------------------------------------------------------------------
101  bool isOnRoad(unsigned int kart_index) const;
102  // ------------------------------------------------------------------------
103  int getSectorForKart(const AbstractKart *kart) const;
104 
105 }; // WorldWithRank
106 
107 #endif
virtual void init() OVERRIDE
call just after instanciating.
Definition: world_with_rank.cpp:42
std::vector< int > m_position_index
This contains a mapping from race position to kart index.
Definition: world_with_rank.hpp:42
TrackSector * getTrackSector(unsigned int kart_index) const
Returns the track_sector object for the specified kart.
Definition: world_with_rank.hpp:95
int getSectorForKart(const AbstractKart *kart) const
Gets the sector a kart is on.
Definition: world_with_rank.cpp:239
void beginSetKartPositions()
This function must be called before starting to set all kart positions again.
Definition: world_with_rank.cpp:93
This object keeps track of which sector an object is on.
Definition: track_sector.hpp:38
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE
Determines the rescue position for a kart.
Definition: world_with_rank.cpp:169
base class for all game modes This class is responsible for running the actual race.
Definition: world.hpp:87
void updateSectorForKarts()
Localize each kart on the graph using its center xyz.
Definition: world_with_rank.cpp:249
bool m_display_rank
Whether to display the rank in the race GUI.
Definition: world_with_rank.hpp:45
A WorldWithRank is a world where the karts are ranked.
Definition: world_with_rank.hpp:38
virtual void reset(bool restart=false) OVERRIDE
This function is called before a race is started (i.e.
Definition: world_with_rank.cpp:66
bool isOnRoad(unsigned int kart_index) const
Returns true if the kart is on a valid graph quad.
Definition: world_with_rank.cpp:225
void endSetKartPositions()
Called once the last position was set.
Definition: world_with_rank.cpp:151
virtual AbstractKart * getKartAtDrawingPosition(unsigned int p) const
Returns the kart at which position (start from 1) to draw race icon.
Definition: world_with_rank.hpp:88
std::vector< TrackSector * > m_kart_track_sector
Stores the current graph node and track coordinates for each kart.
Definition: world_with_rank.hpp:65
AbstractKart * getKartAtPosition(unsigned int p) const
Returns the kart with a given position.
Definition: world_with_rank.cpp:80
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
bool setKartPosition(unsigned int kart_id, unsigned int position)
Sets the position of a kart.
Definition: world_with_rank.cpp:114
virtual int getScoreForPosition(int p)
Returns the number of points for a kart at a specified position.
Definition: world_with_rank.cpp:214
std::vector< int > m_score_for_position
The points given to a kart on a given position (index is 0 based, so using race-position - 1...
Definition: world_with_rank.hpp:49