SuperTuxKart
ghost_kart.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2012-2015 Joerg Henrichs
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 HEADER_GHOST_KART_HPP
20 #define HEADER_GHOST_KART_HPP
21 
22 #include "karts/kart.hpp"
23 #include "replay/replay_play.hpp"
24 #include "utils/cpp2011.hpp"
25 
26 #include "LinearMath/btTransform.h"
27 
28 #include <vector>
29 
37 class GhostKart : public Kart
38 {
39 private:
41  std::vector<btTransform> m_all_transform;
42 
43  std::vector<ReplayBase::PhysicInfo> m_all_physic_info;
44 
45  std::vector<ReplayBase::BonusInfo> m_all_bonus_info;
46 
47  std::vector<ReplayBase::KartReplayEvent> m_all_replay_events;
48 
49  ReplayPlay::ReplayData m_replay_data;
50 
51  unsigned int m_last_egg_idx;
52 
53  bool m_finish_computed;
54 
55  // ----------------------------------------------------------------------------
57  void computeFinishTime();
58  // ----------------------------------------------------------------------------
60  void updateSound(float dt);
61 
62 public:
63  GhostKart(const std::string& ident, unsigned int world_kart_id,
64  int position, float color_hue,
65  const ReplayPlay::ReplayData& rd);
66  virtual void update(int ticks) OVERRIDE;
67  virtual void updateGraphics(float dt) OVERRIDE;
68  virtual void reset() OVERRIDE;
69  // ------------------------------------------------------------------------
71  virtual void applyEngineForce (float force) OVERRIDE {};
72  // ------------------------------------------------------------------------
73  // Not needed to create any physics for a ghost kart.
74  virtual void createPhysics() OVERRIDE {};
75  // ------------------------------------------------------------------------
76  const float getSuspensionLength(int index, int wheel) const
77  { return m_all_physic_info[index].m_suspension_length[wheel]; }
78  // ------------------------------------------------------------------------
79  void addReplayEvent(float time,
80  const btTransform &trans,
81  const ReplayBase::PhysicInfo &pi,
82  const ReplayBase::BonusInfo &bi,
83  const ReplayBase::KartReplayEvent &kre);
84  // ------------------------------------------------------------------------
86  virtual bool isGhostKart() const OVERRIDE { return true; }
87  // ------------------------------------------------------------------------
89  virtual bool isInvulnerable() const OVERRIDE { return true; }
90  // ------------------------------------------------------------------------
92  virtual bool isOnGround() const OVERRIDE { return !m_flying; }
93  // ------------------------------------------------------------------------
95  virtual float getSpeed() const OVERRIDE;
96  // ------------------------------------------------------------------------
98  float getGhostFinishTime();
99  // ------------------------------------------------------------------------
102  virtual float getTimeForDistance(float distance) OVERRIDE;
103 
104  // ----------------------------------------------------------------------------
107  float getTimeForEggs(int egg_number);
108 
109  // ------------------------------------------------------------------------
110  virtual void kartIsInRestNow() OVERRIDE {}
111  // ------------------------------------------------------------------------
112  virtual void makeKartRest() OVERRIDE {}
113  // ------------------------------------------------------------------------
114  const ReplayPlay::ReplayData& getReplayData() const
115  { return m_replay_data; }
116 }; // GhostKart
117 #endif
118 
A ghost kart.
Definition: ghost_kart.hpp:38
virtual bool isGhostKart() const OVERRIDE
Returns whether this kart is a ghost (replay) kart.
Definition: ghost_kart.hpp:86
float getGhostFinishTime()
Returns the finished time for a ghost kart.
Definition: ghost_kart.cpp:329
std::vector< btTransform > m_all_transform
The transforms to assume at the corresponding time in m_all_times.
Definition: ghost_kart.hpp:41
virtual bool isOnGround() const OVERRIDE
Ghost are not on the ground if flying.
Definition: ghost_kart.hpp:92
virtual void createPhysics() OVERRIDE
Creates the physical representation of this kart.
Definition: ghost_kart.hpp:74
virtual float getTimeForDistance(float distance) OVERRIDE
Returns the time at which the kart was at a given distance.
Definition: ghost_kart.cpp:340
virtual void applyEngineForce(float force) OVERRIDE
No physics for ghost kart.
Definition: ghost_kart.hpp:71
virtual bool isInvulnerable() const OVERRIDE
Ghost can't be hunted.
Definition: ghost_kart.hpp:89
float getTimeForEggs(int egg_number)
Returns the smallest time at which the kart had the required number of eggs Returns -1....
Definition: ghost_kart.cpp:418
virtual void reset() OVERRIDE
Reset before a new race.
Definition: ghost_kart.cpp:52
virtual void kartIsInRestNow() OVERRIDE
Computes the transform of the graphical kart chasses with regards to the physical chassis.
Definition: ghost_kart.hpp:110
virtual void update(int ticks) OVERRIDE
Updates the current event of the ghost kart using interpolation.
Definition: ghost_kart.cpp:113
void computeFinishTime()
Compute the time at which the ghost finished the race.
Definition: ghost_kart.cpp:308
virtual void makeKartRest() OVERRIDE
Called before go phase to make sure all karts start at the same position in case there is a slope.
Definition: ghost_kart.hpp:112
virtual void updateGraphics(float dt) OVERRIDE
Called once per rendered frame.
Definition: ghost_kart.cpp:94
virtual float getSpeed() const OVERRIDE
Returns the speed of the kart in meters/second.
Definition: ghost_kart.cpp:283
void updateSound(float dt)
Update sound effect upon ghost replay data.
Definition: ghost_kart.cpp:251
The main kart class.
Definition: kart.hpp:72
bool m_flying
True if kart is flying (for debug purposes only).
Definition: kart.hpp:180
Definition: replay_play.hpp:57
Definition: replay_base.hpp:63
Records all other events.
Definition: replay_base.hpp:85
Definition: replay_base.hpp:50