SuperTuxKart
Loading...
Searching...
No Matches
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
37class GhostKart : public Kart
38{
39private:
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 // ----------------------------------------------------------------------------
55 void computeFinishTime();
56public:
57 GhostKart(const std::string& ident, unsigned int world_kart_id,
58 int position, float color_hue,
59 const ReplayPlay::ReplayData& rd);
60 virtual void update(int ticks) OVERRIDE;
61 virtual void updateGraphics(float dt) OVERRIDE;
62 virtual void reset() OVERRIDE;
63 // ------------------------------------------------------------------------
65 virtual void applyEngineForce (float force) OVERRIDE {};
66 // ------------------------------------------------------------------------
67 // Not needed to create any physics for a ghost kart.
68 virtual void createPhysics() OVERRIDE {};
69 // ------------------------------------------------------------------------
70 const float getSuspensionLength(int index, int wheel) const
71 { return m_all_physic_info[index].m_suspension_length[wheel]; }
72 // ------------------------------------------------------------------------
73 void addReplayEvent(float time,
74 const btTransform &trans,
75 const ReplayBase::PhysicInfo &pi,
76 const ReplayBase::BonusInfo &bi,
78 // ------------------------------------------------------------------------
80 virtual bool isGhostKart() const OVERRIDE { return true; }
81 // ------------------------------------------------------------------------
83 virtual bool isInvulnerable() const OVERRIDE { return true; }
84 // ------------------------------------------------------------------------
86 virtual float getSpeed() const OVERRIDE;
87
88 // ------------------------------------------------------------------------
90 float getGhostFinishTime() { computeFinishTime(); return m_finish_time; }
91
92 // ------------------------------------------------------------------------
95 virtual float getTimeForDistance(float distance) OVERRIDE;
96
97 // ----------------------------------------------------------------------------
100 float getTimeForEggs(int egg_number);
101
102 // ------------------------------------------------------------------------
103 virtual void kartIsInRestNow() OVERRIDE {}
104 // ------------------------------------------------------------------------
105 virtual void makeKartRest() OVERRIDE {}
106 // ------------------------------------------------------------------------
107 const ReplayPlay::ReplayData& getReplayData() const
108 { return m_replay_data; }
109}; // GhostKart
110#endif
111
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:80
float getGhostFinishTime()
Returns the finished time for a ghost kart.
Definition: ghost_kart.hpp:90
std::vector< btTransform > m_all_transform
The transforms to assume at the corresponding time in m_all_times.
Definition: ghost_kart.hpp:41
virtual void createPhysics() OVERRIDE
Creates the physical representation of this kart.
Definition: ghost_kart.hpp:68
virtual float getTimeForDistance(float distance) OVERRIDE
Returns the time at which the kart was at a given distance.
Definition: ghost_kart.cpp:279
virtual void applyEngineForce(float force) OVERRIDE
No physics for ghost kart.
Definition: ghost_kart.hpp:65
virtual bool isInvulnerable() const OVERRIDE
Ghost can't be hunted.
Definition: ghost_kart.hpp:83
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:357
virtual void reset() OVERRIDE
Reset before a new race.
Definition: ghost_kart.cpp:48
virtual void kartIsInRestNow() OVERRIDE
Computes the transform of the graphical kart chasses with regards to the physical chassis.
Definition: ghost_kart.hpp:103
virtual void update(int ticks) OVERRIDE
Updates the current event of the ghost kart using interpolation.
Definition: ghost_kart.cpp:107
void computeFinishTime()
Compute the time at which the ghost finished the race.
Definition: ghost_kart.cpp:258
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:105
virtual void updateGraphics(float dt) OVERRIDE
Called once per rendered frame.
Definition: ghost_kart.cpp:90
virtual float getSpeed() const OVERRIDE
Returns the speed of the kart in meters/second.
Definition: ghost_kart.cpp:239
The main kart class.
Definition: kart.hpp:69
Definition: replay_play.hpp:57
Definition: replay_base.hpp:63
Records all other events.
Definition: replay_base.hpp:85
Definition: replay_base.hpp:50