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
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  virtual bool shouldDrawSpeedometerDigit() const OVERRIDE
80  { return m_display_rank; }
81  virtual std::pair<int, video::SColor>
82  getSpeedometerDigit(const AbstractKart *kart) const OVERRIDE;
83 
84  void beginSetKartPositions();
85  bool setKartPosition(unsigned int kart_id,
86  unsigned int position);
87  void endSetKartPositions();
88  AbstractKart* getKartAtPosition(unsigned int p) const;
91  virtual AbstractKart* getKartAtDrawingPosition(unsigned int p) const
92  { return getKartAtPosition(p); }
93  virtual int getScoreForPosition(int p);
94  virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
95  // ------------------------------------------------------------------------
98  TrackSector* getTrackSector(unsigned int kart_index) const
99  {
100  assert(kart_index < m_kart_track_sector.size());
101  return m_kart_track_sector[kart_index];
102  } // getTrackSector
103  // ------------------------------------------------------------------------
104  bool isOnRoad(unsigned int kart_index) const;
105  // ------------------------------------------------------------------------
106  int getSectorForKart(const AbstractKart *kart) const;
107 
108 }; // WorldWithRank
109 
110 #endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
This object keeps track of which sector an object is on.
Definition: track_sector.hpp:39
A WorldWithRank is a world where the karts are ranked.
Definition: world_with_rank.hpp:39
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE
Determines the rescue position for a kart.
Definition: world_with_rank.cpp:175
void beginSetKartPositions()
This function must be called before starting to set all kart positions again.
Definition: world_with_rank.cpp:99
void endSetKartPositions()
Called once the last position was set.
Definition: world_with_rank.cpp:157
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
bool isOnRoad(unsigned int kart_index) const
Returns true if the kart is on a valid graph quad.
Definition: world_with_rank.cpp:231
void updateSectorForKarts()
Localize each kart on the graph using its center xyz.
Definition: world_with_rank.cpp:255
bool setKartPosition(unsigned int kart_id, unsigned int position)
Sets the position of a kart.
Definition: world_with_rank.cpp:120
bool m_display_rank
Whether to display the rank in the race GUI.
Definition: world_with_rank.hpp:45
virtual int getScoreForPosition(int p)
Returns the number of points for a kart at a specified position.
Definition: world_with_rank.cpp:220
virtual bool shouldDrawSpeedometerDigit() const OVERRIDE
Definition: world_with_rank.hpp:79
std::vector< TrackSector * > m_kart_track_sector
Stores the current graph node and track coordinates for each kart.
Definition: world_with_rank.hpp:65
virtual void reset(bool restart=false) OVERRIDE
This function is called before a race is started (i.e.
Definition: world_with_rank.cpp:66
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
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:91
int getSectorForKart(const AbstractKart *kart) const
Gets the sector a kart is on.
Definition: world_with_rank.cpp:245
TrackSector * getTrackSector(unsigned int kart_index) const
Returns the track_sector object for the specified kart.
Definition: world_with_rank.hpp:98
AbstractKart * getKartAtPosition(unsigned int p) const
Returns the kart with a given position.
Definition: world_with_rank.cpp:80
virtual std::pair< int, video::SColor > getSpeedometerDigit(const AbstractKart *kart) const OVERRIDE
Definition: world_with_rank.cpp:89
base class for all game modes This class is responsible for running the actual race.
Definition: world.hpp:88