SuperTuxKart
Loading...
Searching...
No Matches
linear_world.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2004-2015 SuperTuxKart-Team
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_LINEAR_WORLD_HPP
19#define HEADER_LINEAR_WORLD_HPP
20
21#include "modes/world_with_rank.hpp"
22#include "utils/aligned_array.hpp"
23
24#include <climits>
25#include <vector>
26
27class SFXBase;
28
29/*
30 * A 'linear world' is a subcategory of world used in 'standard' races, i.e.
31 * with a start line and a road that loops. This includes management of drivelines
32 * and lap counting.
33 * \ingroup modes
34 */
36{
37private:
40
43
44 bool m_last_lap_sfx_playing;
45
48
51
52 core::stringw m_fastest_lap_kart_name;
53
62
67
70
71 /* if set then the game will auto end after this time for networking */
72 float m_finish_timeout;
73
79
80 // ------------------------------------------------------------------------
85 {
86 public:
89
92
95
98
102
106
109 // --------------------------------------------------------------------
111 void reset()
112 {
113 m_finished_laps = -1;
115 m_ticks_at_last_lap = INT_MAX;
116 m_estimated_finish = -1.0f;
117 m_overall_distance = 0.0f;
118 m_wrong_way_timer = 0.0f;
119 } // reset
120 // --------------------------------------------------------------------
121 void saveCompleteState(BareNetworkString* bns);
122 // --------------------------------------------------------------------
123 void restoreCompleteState(const BareNetworkString& b);
124 };
125 // ------------------------------------------------------------------------
126
127protected:
128
133 std::vector<KartInfo> m_kart_info;
134
135 virtual void checkForWrongDirection(unsigned int i, float dt);
136 virtual float estimateFinishTimeForKart(AbstractKart* kart) OVERRIDE;
137
138public:
139 LinearWorld();
143 virtual void init() OVERRIDE;
144 virtual ~LinearWorld();
145
146 virtual void update(int ticks) OVERRIDE;
147 virtual void updateGraphics(float dt) OVERRIDE;
148 float getDistanceDownTrackForKart(const int kart_id,
149 bool account_for_checklines) const;
150 void updateTrackSectors();
151 void updateRacePosition();
152 float getDistanceToCenterForKart(const int kart_id) const;
153 float getEstimatedFinishTime(const int kart_id) const;
154 int getLapForKart(const int kart_id) const;
155 int getTicksAtLapForKart(const int kart_id) const;
156 float getLiveTimeDifference() const { return m_live_time_difference; }
157 bool hasValidTimeDifference() const { return m_valid_reference_time; }
158
159 virtual void getKartsDisplayInfo(
160 std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
161
162 virtual unsigned int getNumberOfRescuePositions() const OVERRIDE;
163 virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
164 virtual btTransform getRescueTransform(unsigned int index) const OVERRIDE;
165 virtual void reset(bool restart=false) OVERRIDE;
166 virtual void newLap(unsigned int kart_index) OVERRIDE;
167
168 // ------------------------------------------------------------------------
170 virtual bool raceHasLaps() OVERRIDE { return true; }
171 // ------------------------------------------------------------------------
173 virtual bool haveBonusBoxes() OVERRIDE { return true; }
174 // ------------------------------------------------------------------------
176 virtual bool useChecklineRequirements() const OVERRIDE { return true; }
177 // ------------------------------------------------------------------------
180 int getFinishedLapsOfKart(unsigned int kart_index) const OVERRIDE
181 {
182 assert(kart_index < m_kart_info.size());
183 return m_kart_info[kart_index].m_finished_laps;
184 } // getkartLap
185 // ------------------------------------------------------------------------
186 void setLastTriggeredCheckline(unsigned int kart_index, int index);
187 // ------------------------------------------------------------------------
191 float getOverallDistance(unsigned int kart_index) const
192 {
193 return m_kart_info[kart_index].m_overall_distance;
194 } // getOverallDistance
195 // ------------------------------------------------------------------------
197 float getFastestLap() const
198 {
199 return stk_config->ticks2Time(m_fastest_lap_ticks);
200 }
201 // ------------------------------------------------------------------------
203 stringw getFastestLapKartName() const
204 {
205 return m_fastest_lap_kart_name;
206 }
207 // ------------------------------------------------------------------------
210 {
211 return m_fastest_lap_ticks;
212 }
213 // ------------------------------------------------------------------------
215 void setFastestLapTicks(int ticks)
216 {
217 m_fastest_lap_ticks = ticks;
218 }
219 // ------------------------------------------------------------------------
221 void setFastestKartName(const stringw& name)
222 {
223 m_fastest_lap_kart_name = name;
224 }
225 // ------------------------------------------------------------------------
226 virtual std::pair<uint32_t, uint32_t> getGameStartedProgress() const
227 OVERRIDE;
228 // ------------------------------------------------------------------------
229 virtual void saveCompleteState(BareNetworkString* bns,
230 STKPeer* peer) OVERRIDE;
231 // ------------------------------------------------------------------------
232 virtual void restoreCompleteState(const BareNetworkString& b) OVERRIDE;
233 // ------------------------------------------------------------------------
234 void updateCheckLinesServer(int check_id, int kart_id);
235 // ------------------------------------------------------------------------
236 void updateCheckLinesClient(const BareNetworkString& b);
237 // ------------------------------------------------------------------------
238 void handleServerCheckStructureCount(unsigned count);
239 // ------------------------------------------------------------------------
240 virtual bool showLapsTarget() OVERRIDE { return true; }
241}; // LinearWorld
242
243#endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Some additional info that needs to be kept for each kart in this kind of race.
Definition: linear_world.hpp:85
int m_lap_start_ticks
Time at start of a new lap.
Definition: linear_world.hpp:94
float m_overall_distance
How far the kart has travelled (this is (number-of-laps-1) times track-length plus distance-along-tra...
Definition: linear_world.hpp:101
float m_wrong_way_timer
Accumulates the time a kart has been driving in the wrong direction so that a message can be displaye...
Definition: linear_world.hpp:105
int m_ticks_at_last_lap
Time at finishing last lap.
Definition: linear_world.hpp:91
void reset()
Re-initialises all data.
Definition: linear_world.hpp:111
KartInfo()
Initialises all fields.
Definition: linear_world.hpp:108
int m_finished_laps
Number of finished laps.
Definition: linear_world.hpp:88
float m_estimated_finish
During last lap only: estimated finishing time!
Definition: linear_world.hpp:97
Definition: linear_world.hpp:36
virtual bool useChecklineRequirements() const OVERRIDE
Override settings from base class.
Definition: linear_world.hpp:176
virtual bool haveBonusBoxes() OVERRIDE
Returns if this race mode has bonus items.
Definition: linear_world.hpp:173
float getDistanceToCenterForKart(const int kart_id) const
Gets the distance of the kart from the center of the driveline.
Definition: linear_world.cpp:579
virtual void updateGraphics(float dt) OVERRIDE
This updates all only graphical elements.It is only called once per rendered frame,...
Definition: linear_world.cpp:304
virtual std::pair< uint32_t, uint32_t > getGameStartedProgress() const OVERRIDE
Used by server to get the current started game progress in either or both remaining time or progress ...
Definition: linear_world.cpp:1114
float m_distance_increase
The track length returned by Track::getLength() only covers the distance from start line to finish li...
Definition: linear_world.hpp:61
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE
Determines the rescue position for a kart.
Definition: linear_world.cpp:821
bool m_last_lap_sfx_played
Last lap sfx should only be played once.
Definition: linear_world.hpp:42
virtual void update(int ticks) OVERRIDE
General update function called once per frame.
Definition: linear_world.cpp:174
virtual void reset(bool restart=false) OVERRIDE
Called before a race is started (or restarted).
Definition: linear_world.cpp:107
float getOverallDistance(unsigned int kart_index) const
Returns how far the kart has driven so far (i.e.
Definition: linear_world.hpp:191
float getDistanceDownTrackForKart(const int kart_id, bool account_for_checklines) const
Returns the distance the kart has travelled along the track since crossing the start line.
Definition: linear_world.cpp:569
stringw getFastestLapKartName() const
Returns the kart name that made the fastest lap time.
Definition: linear_world.hpp:203
virtual btTransform getRescueTransform(unsigned int index) const OVERRIDE
Returns the bullet transformation for the specified rescue index.
Definition: linear_world.cpp:843
void setFastestKartName(const stringw &name)
Network use: set fastest kart name.
Definition: linear_world.hpp:221
virtual void checkForWrongDirection(unsigned int i, float dt)
Checks if a kart is going in the wrong direction.
Definition: linear_world.cpp:1046
virtual bool raceHasLaps() OVERRIDE
Returns if this race mode has laps.
Definition: linear_world.hpp:170
SFXBase * m_last_lap_sfx
Sfx for the final lap.
Definition: linear_world.hpp:39
virtual void init() OVERRIDE
call just after instanciating.
Definition: linear_world.cpp:78
int m_fastest_lap_ticks
The fastest lap time, in ticks of physics dt.
Definition: linear_world.hpp:50
bool m_check_structure_compatible
True if clients and server has the same check structure.
Definition: linear_world.hpp:47
bool m_valid_reference_time
True if the live_time_difference is invalid.
Definition: linear_world.hpp:69
void updateLiveDifference()
This calculate the time difference between the second kart in the race (there must be at least two) a...
Definition: linear_world.cpp:337
std::vector< KartInfo > m_kart_info
This vector contains an 'KartInfo' struct for every kart in the race.
Definition: linear_world.hpp:133
virtual unsigned int getNumberOfRescuePositions() const OVERRIDE
Returns the number of rescue positions on a given track, which in linear races is just the number of ...
Definition: linear_world.cpp:815
void updateCheckLinesServer(int check_id, int kart_id)
Called in server whenever a kart cross a check line, it send server current kart lap count,...
Definition: linear_world.cpp:1221
int getFinishedLapsOfKart(unsigned int kart_index) const OVERRIDE
Returns the number of laps a kart has completed.
Definition: linear_world.hpp:180
virtual void getKartsDisplayInfo(std::vector< RaceGUIBase::KartIconDisplayInfo > *info) OVERRIDE
Called by the code that draws the list of karts on the race GUI to know what needs to be drawn in the...
Definition: linear_world.cpp:609
void updateRacePosition()
Find the position (rank) of every kart.
Definition: linear_world.cpp:864
float m_live_time_difference
This stores the live time difference between a ghost kart and a second kart racing against it (normal...
Definition: linear_world.hpp:66
void setFastestLapTicks(int ticks)
Network use: set fastest lap in ticks.
Definition: linear_world.hpp:215
virtual float estimateFinishTimeForKart(AbstractKart *kart) OVERRIDE
Estimate the arrival time of any karts that haven't arrived yet by using their average speed up to no...
Definition: linear_world.cpp:743
LinearWorld()
Constructs the linear world.
Definition: linear_world.cpp:61
int getFastestLapTicks() const
Network use: get fastest lap in ticks.
Definition: linear_world.hpp:209
virtual void newLap(unsigned int kart_index) OVERRIDE
Is called by check structures if a kart starts a new lap.
Definition: linear_world.cpp:376
float getEstimatedFinishTime(const int kart_id) const
Returns the estimated finishing time.
Definition: linear_world.cpp:595
float getFastestLap() const
Returns time for the fastest laps.
Definition: linear_world.hpp:197
virtual bool showLapsTarget() OVERRIDE
If true lap counter shows lap count in format: 4/20 or if false then in format: 4.
Definition: linear_world.hpp:240
The base class for sound effects.
Definition: sfx_base.hpp:43
float ticks2Time(int ticks)
Converts a tick value (in physics time step size) into seconds.
Definition: stk_config.hpp:313
Represents a peer. This class is used to interface the ENetPeer structure.
Definition: stk_peer.hpp:76
A WorldWithRank is a world where the karts are ranked.
Definition: world_with_rank.hpp:39