SuperTuxKart
free_for_all.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2018 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 FREE_FOR_ALL_HPP
19 #define FREE_FOR_ALL_HPP
20 
21 #include "modes/world_with_rank.hpp"
22 #include "states_screens/race_gui_base.hpp"
23 
24 #include <vector>
25 
26 class NetworkString;
27 
28 class FreeForAll : public WorldWithRank
29 {
30 protected:
31  bool m_count_down_reached_zero;
32 
33  std::vector<int> m_scores;
34  // ------------------------------------------------------------------------
35  void handleScoreInServer(int kart_id, int hitter);
36 
37 private:
38  // ------------------------------------------------------------------------
39  virtual video::SColor getColor(unsigned int kart_id) const;
40 
41 public:
42  // ------------------------------------------------------------------------
43  FreeForAll();
44  // ------------------------------------------------------------------------
45  virtual ~FreeForAll();
46  // ------------------------------------------------------------------------
47  virtual void init() OVERRIDE;
48  // ------------------------------------------------------------------------
49  virtual bool isRaceOver() OVERRIDE;
50  // ------------------------------------------------------------------------
51  virtual void reset(bool restart=false) OVERRIDE;
52  // ------------------------------------------------------------------------
53  virtual void getKartsDisplayInfo(
54  std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
55  // ------------------------------------------------------------------------
56  virtual bool raceHasLaps() OVERRIDE { return false; }
57  // ------------------------------------------------------------------------
58  virtual bool shouldDrawSpeedometerDigit() const OVERRIDE { return true; }
59  // ------------------------------------------------------------------------
60  virtual std::pair<int, video::SColor>
61  getSpeedometerDigit(const AbstractKart *kart) const OVERRIDE;
62  // ------------------------------------------------------------------------
63  virtual const std::string& getIdent() const OVERRIDE;
64  // ------------------------------------------------------------------------
65  virtual bool kartHit(int kart_id, int hitter = -1) OVERRIDE;
66  // ------------------------------------------------------------------------
67  virtual void update(int ticks) OVERRIDE;
68  // ------------------------------------------------------------------------
69  virtual void countdownReachedZero() OVERRIDE;
70  // ------------------------------------------------------------------------
71  virtual void terminateRace() OVERRIDE;
72  // ------------------------------------------------------------------------
73  void setKartScoreFromServer(NetworkString& ns);
74  // ------------------------------------------------------------------------
75  int getKartScore(int kart_id) const { return m_scores.at(kart_id); }
76  // ------------------------------------------------------------------------
77  bool getKartFFAResult(int kart_id) const;
78  // ------------------------------------------------------------------------
79  virtual std::pair<uint32_t, uint32_t> getGameStartedProgress() const
80  OVERRIDE;
81  // ------------------------------------------------------------------------
82  virtual void addReservedKart(int kart_id) OVERRIDE
83  {
84  WorldWithRank::addReservedKart(kart_id);
85  m_scores.at(kart_id) = 0;
86  }
87  // ------------------------------------------------------------------------
88  virtual void saveCompleteState(BareNetworkString* bns,
89  STKPeer* peer) OVERRIDE;
90  // ------------------------------------------------------------------------
91  virtual void restoreCompleteState(const BareNetworkString& b) OVERRIDE;
92 }; // FreeForAll
93 
94 
95 #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
Definition: free_for_all.hpp:29
void handleScoreInServer(int kart_id, int hitter)
Called when the score of kart needs updated.
Definition: free_for_all.cpp:115
virtual bool kartHit(int kart_id, int hitter=-1) OVERRIDE
Called when a kart is hit.
Definition: free_for_all.cpp:97
virtual void update(int ticks) OVERRIDE
Updates the physics, all karts, the track, and projectile manager.
Definition: free_for_all.cpp:154
virtual void reset(bool restart=false) OVERRIDE
Called when a battle is restarted.
Definition: free_for_all.cpp:64
virtual const std::string & getIdent() const OVERRIDE
Returns the internal identifier for this race.
Definition: free_for_all.cpp:148
virtual bool raceHasLaps() OVERRIDE
Called when it is needed to know whether this kind of race involves counting laps.
Definition: free_for_all.hpp:56
virtual void getKartsDisplayInfo(std::vector< RaceGUIBase::KartIconDisplayInfo > *info) OVERRIDE
Returns the data to display in the race gui.
Definition: free_for_all.cpp:203
virtual bool isRaceOver() OVERRIDE
The battle is over if only one kart is left, or no player kart.
Definition: free_for_all.cpp:184
virtual void terminateRace() OVERRIDE
Called at the end of a race.
Definition: free_for_all.cpp:270
virtual void countdownReachedZero() OVERRIDE
Called when the match time ends.
Definition: free_for_all.cpp:84
virtual void init() OVERRIDE
call just after instanciating.
Definition: free_for_all.cpp:53
virtual std::pair< int, video::SColor > getSpeedometerDigit(const AbstractKart *kart) const OVERRIDE
Definition: free_for_all.cpp:230
FreeForAll()
Constructor.
Definition: free_for_all.cpp:34
virtual bool shouldDrawSpeedometerDigit() const OVERRIDE
Definition: free_for_all.hpp:58
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: free_for_all.cpp:312
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message,...
Definition: network_string.hpp:422
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