SuperTuxKart
Loading...
Searching...
No Matches
flyable.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2007-2015 Joerg Henrichs
4//
5// Linear item-kart intersection function written by
6// Copyright (C) 2009-2015 David Mikos.
7//
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License
10// as published by the Free Software Foundation; either version 3
11// of the License, or (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22#ifndef HEADER_FLYABLE_HPP
23#define HEADER_FLYABLE_HPP
24
25#include "items/powerup_manager.hpp"
26#include "karts/moveable.hpp"
27#include "network/rewinder.hpp"
28#include "tracks/terrain_info.hpp"
29#include "utils/cpp2011.hpp"
30
31#include <irrString.h>
32namespace irr
33{
34 namespace scene { class IMesh; }
35}
36using namespace irr;
37
38class AbstractKart;
40class HitEffect;
41class PhysicalObject;
42class SFXBase;
43class XMLNode;
44
48class Flyable : public Moveable, public TerrainInfo,
49 public Rewinder
50{
51private:
52 bool m_has_hit_something;
53
58
64
71
72 /* Used in network to restore previous gravity in compressed form. */
73 uint32_t m_compressed_gravity_vector;
74
78
79protected:
82
84 PowerupManager::PowerupType
86
88 btCollisionShape *m_shape;
89
92
95
98
101
103 float m_speed;
104
106 const float m_mass;
107
110
114
115 /* True if this flyable exists in server, and will trigger a rewind.
116 * For each local state it will reset it to false and call moveToInfinity,
117 * and for each restoreState it will set it to true. Also when re-fire the
118 * flyable during rewind it will set to true too. */
119 bool m_has_server_state;
120
124
125 /* Set to true once when onDeleteFlyable, this is used to create HitEffect
126 * only once. */
127 bool m_deleted_once;
128
129 /* Save the locally detected deleted ticks, if the confirmed state world
130 * ticks in computeError > this, the flyable can be deleted in client. */
131 int m_last_deleted_ticks;
132
133 // The flyable class stores the values for each flyable type, e.g.
134 // speed, min_height, max_height. These variables must be static,
135 // so we need arrays of these variables to have different values
136 // for bowling balls, missiles, ...
137
139 static float m_st_speed[PowerupManager::POWERUP_MAX];
140
142 static scene::IMesh *m_st_model[PowerupManager::POWERUP_MAX];
143
145 static float m_st_min_height[PowerupManager::POWERUP_MAX];
146
148 static float m_st_max_height[PowerupManager::POWERUP_MAX];
149
151 static float m_st_force_updown[PowerupManager::POWERUP_MAX];
152
154 static Vec3 m_st_extend[PowerupManager::POWERUP_MAX];
155
159
160 /* For debugging purpose */
161 int m_created_ticks;
162
163 void getClosestKart(const AbstractKart **minKart,
164 float *minDistSquared,
165 Vec3 *minDelta,
166 const AbstractKart* inFrontOf=NULL,
167 const bool backwards=false) const;
168
169 void getLinearKartItemIntersection(const Vec3 &origin,
170 const AbstractKart *target_kart,
171 float item_XY_velocity, float gravity,
172 float forw_offset,
173 float *fire_angle, float *up_velocity);
174
175
177 void createPhysics(float y_offset,
178 const Vec3 &velocity,
179 btCollisionShape *shape,
180 float restitution,
181 const btVector3& gravity=btVector3(0.0f,0.0f,0.0f),
182 const bool rotates=false,
183 const bool turn_around=false,
184 const btTransform* customDirection=NULL);
185
186 void moveToInfinity(bool set_moveable_trans = true);
187 void removePhysics();
188 void fixSFXSplitscreen(SFXBase* sfx);
189public:
190
191 Flyable (AbstractKart* kart,
192 PowerupManager::PowerupType type,
193 float mass=1.0f);
194 virtual ~Flyable ();
195 static void init (const XMLNode &node, scene::IMesh *model,
196 PowerupManager::PowerupType type);
197 void updateGraphics(float dt) OVERRIDE;
198 virtual bool updateAndDelete(int ticks);
199 virtual void setAnimation(AbstractKartAnimation *animation);
200 virtual HitEffect* getHitEffect() const;
201 bool isOwnerImmunity(const AbstractKart *kart_hit) const;
202 virtual bool hit(AbstractKart* kart, PhysicalObject* obj=NULL);
203 void explode(AbstractKart* kart, PhysicalObject* obj=NULL,
204 bool secondary_hits=true);
205 unsigned int getOwnerId();
206 // ------------------------------------------------------------------------
208 bool hasAnimation() const { return m_animation != NULL; }
209 // ------------------------------------------------------------------------
214 // ------------------------------------------------------------------------
219 // ------------------------------------------------------------------------
221 virtual void hitTrack () {};
222 // ------------------------------------------------------------------------
226 bool hasHit () { return m_has_hit_something; }
227 // ------------------------------------------------------------------------
230 void setHasHit () { m_has_hit_something = true; }
231 // ------------------------------------------------------------------------
233 void reset() OVERRIDE { Moveable::reset(); }
234 // ------------------------------------------------------------------------
236 PowerupManager::PowerupType getType() const {return m_type;}
237
238 // ------------------------------------------------------------------------
240 AbstractKart *getOwner() const { return m_owner;}
241 // ------------------------------------------------------------------------
246 // ------------------------------------------------------------------------
248 const Vec3 &getExtend() const { return m_extend; }
249 // ------------------------------------------------------------------------
250 void addForRewind(const std::string& uid);
251 // ------------------------------------------------------------------------
252 virtual void undoEvent(BareNetworkString *buffer) OVERRIDE {}
253 // ------------------------------------------------------------------------
254 virtual void rewindToEvent(BareNetworkString *buffer) OVERRIDE {}
255 // ------------------------------------------------------------------------
256 virtual void undoState(BareNetworkString *buffer) OVERRIDE {}
257 // ------------------------------------------------------------------------
258 virtual void saveTransform() OVERRIDE;
259 // ------------------------------------------------------------------------
260 virtual void computeError() OVERRIDE;
261 // ------------------------------------------------------------------------
262 virtual BareNetworkString* saveState(std::vector<std::string>* ru)
263 OVERRIDE;
264 // ------------------------------------------------------------------------
265 virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE;
266 // ------------------------------------------------------------------------
267 /* Return true if still in game state, or otherwise can be deleted. */
268 bool hasServerState() const { return m_has_server_state; }
269 // ------------------------------------------------------------------------
272 virtual void onFireFlyable();
273 // ------------------------------------------------------------------------
274 virtual void onDeleteFlyable();
275 // ------------------------------------------------------------------------
276 void setCreatedTicks(int ticks) { m_created_ticks = ticks; }
277}; // Flyable
278
279#endif
The base class for all kart animation, like rescue, explosion, or cannon.
Definition: abstract_kart_animation.hpp:60
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: flyable.hpp:50
static float m_st_speed[PowerupManager::POWERUP_MAX]
Speed of the projectile.
Definition: flyable.hpp:139
virtual void undoState(BareNetworkString *buffer) OVERRIDE
Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo).
Definition: flyable.hpp:256
virtual void saveTransform() OVERRIDE
Called before a rewind.
Definition: flyable.cpp:745
void setPositionOffset(const Vec3 &o)
Sets the offset to be used when determining the terrain under the flyable.
Definition: flyable.hpp:218
PowerupManager::PowerupType getType() const
Returns the type of flyable.
Definition: flyable.hpp:236
virtual BareNetworkString * saveState(std::vector< std::string > *ru) OVERRIDE
Provides a copy of the state of the object in one memory buffer.
Definition: flyable.cpp:667
AbstractKart * getOwner() const
Returns the owner's kart.
Definition: flyable.hpp:240
bool m_owner_has_temporary_immunity
If set to true, the kart that throwns this flyable can't collide with it for a short time.
Definition: flyable.hpp:123
virtual void onFireFlyable()
Call when the item is (re-)fired (during rewind if needed) by projectile_manager.
Definition: flyable.cpp:777
float m_min_height
Minimum height above terrain.
Definition: flyable.hpp:94
float m_average_height
Average of average of m_{min,ax}_height.
Definition: flyable.hpp:97
void explode(AbstractKart *kart, PhysicalObject *obj=NULL, bool secondary_hits=true)
Creates the explosion physical effect, i.e.
Definition: flyable.cpp:571
float m_speed
Speed of this Flyable.
Definition: flyable.hpp:103
static float m_st_force_updown[PowerupManager::POWERUP_MAX]
Force pushing up/down.
Definition: flyable.hpp:151
void moveToInfinity(bool set_moveable_trans=true)
It's called when undoing the creation or destruction of flyables, so that it will not affected the cu...
Definition: flyable.cpp:653
virtual bool hit(AbstractKart *kart, PhysicalObject *obj=NULL)
Callback from the physics in case that a kart or physical object is hit.
Definition: flyable.cpp:551
static float m_st_max_height[PowerupManager::POWERUP_MAX]
Max height above track.
Definition: flyable.hpp:148
const Vec3 & getExtend() const
Returns the size (extend) of the mesh.
Definition: flyable.hpp:248
bool isOwnerImmunity(const AbstractKart *kart_hit) const
Returns true if the item hit the kart who shot it (to avoid that an item that's too close to the shoo...
Definition: flyable.cpp:537
int m_max_lifespan
Set to something > -1 if this flyable should auto-destrcut after that may ticks.
Definition: flyable.hpp:158
bool m_adjust_up_velocity
If this flag is set, the up velocity of the kart will not be adjusted in case that the objects is too...
Definition: flyable.hpp:57
void setHasHit()
Indicates that something was hit and that this object must be removed.
Definition: flyable.hpp:230
PowerupManager::PowerupType m_type
Type of the powerup.
Definition: flyable.hpp:85
uint16_t m_ticks_since_thrown
Time since thrown.
Definition: flyable.hpp:113
static scene::IMesh * m_st_model[PowerupManager::POWERUP_MAX]
The mesh of this Flyable.
Definition: flyable.hpp:142
void createPhysics(float y_offset, const Vec3 &velocity, btCollisionShape *shape, float restitution, const btVector3 &gravity=btVector3(0.0f, 0.0f, 0.0f), const bool rotates=false, const bool turn_around=false, const btTransform *customDirection=NULL)
init bullet for moving objects like projectiles
Definition: flyable.cpp:126
bool m_do_terrain_info
If this variable is set to true (which is the default) flyable will update the height of terrain when...
Definition: flyable.hpp:70
AbstractKart * m_owner
Kart which shot this flyable.
Definition: flyable.hpp:81
float m_max_height
Maximum height above terrain.
Definition: flyable.hpp:91
static Vec3 m_st_extend[PowerupManager::POWERUP_MAX]
Size of the model.
Definition: flyable.hpp:154
void setAdjustUpVelocity(bool f)
If true the up velocity of the flyable will be adjust so that the flyable stays at a height close to ...
Definition: flyable.hpp:213
Vec3 m_position_offset
An offset that is added when doing the raycast for terrain.
Definition: flyable.hpp:63
const float m_mass
Mass of this Flyable.
Definition: flyable.hpp:106
Vec3 m_extend
Size of this flyable.
Definition: flyable.hpp:109
bool hasHit()
Enables/disables adjusting ov velocity depending on height above terrain.
Definition: flyable.hpp:226
void setDoTerrainInfo(bool d)
Sets wether Flyable should update TerrainInfo as part of its update call, or if the inheriting object...
Definition: flyable.hpp:245
btCollisionShape * m_shape
Collision shape of this Flyable.
Definition: flyable.hpp:88
virtual void undoEvent(BareNetworkString *buffer) OVERRIDE
Called when an event needs to be undone.
Definition: flyable.hpp:252
AbstractKartAnimation * m_animation
If the flyable is in a cannon, this is the pointer to the cannon animation.
Definition: flyable.hpp:77
void getLinearKartItemIntersection(const Vec3 &origin, const AbstractKart *target_kart, float item_XY_velocity, float gravity, float forw_offset, float *fire_angle, float *up_velocity)
Returns information on the parameters needed to hit a target kart moving at constant velocity and dir...
Definition: flyable.cpp:330
void updateGraphics(float dt) OVERRIDE
Called once per rendered frame.
Definition: flyable.cpp:415
virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE
Called when a state needs to be replayed.
Definition: flyable.cpp:692
void reset() OVERRIDE
Resets this flyable.
Definition: flyable.hpp:233
virtual void hitTrack()
Called when this flyable hits the track.
Definition: flyable.hpp:221
float m_force_updown
Force pushing the Flyable up.
Definition: flyable.hpp:100
static float m_st_min_height[PowerupManager::POWERUP_MAX]
Minimum height above track.
Definition: flyable.hpp:145
virtual void computeError() OVERRIDE
Called when a rewind is finished, and is used to compute the error caused by the rewind (which is the...
Definition: flyable.cpp:756
virtual HitEffect * getHitEffect() const
Returns the hit effect object to use when this objects hits something.
Definition: flyable.cpp:631
static void init(const XMLNode &node, scene::IMesh *model, PowerupManager::PowerupType type)
Initialises the static members of this class for a certain type with default values and with settings...
Definition: flyable.cpp:198
bool hasAnimation() const
Returns if this flyable has an animation playing (e.g.
Definition: flyable.hpp:208
virtual void rewindToEvent(BareNetworkString *buffer) OVERRIDE
Called when an event needs to be replayed.
Definition: flyable.hpp:254
void getClosestKart(const AbstractKart **minKart, float *minDistSquared, Vec3 *minDelta, const AbstractKart *inFrontOf=NULL, const bool backwards=false) const
Returns information on what is the closest kart and at what distance it is.
Definition: flyable.cpp:251
virtual bool updateAndDelete(int ticks)
Updates this flyable.
Definition: flyable.cpp:427
A small interface for effects to be used when a kart is hit.
Definition: hit_effect.hpp:33
Definition: moveable.hpp:46
virtual void reset()
The reset position must be set before calling reset.
Definition: moveable.cpp:104
Definition: physical_object.hpp:40
Definition: rewinder.hpp:44
The base class for sound effects.
Definition: sfx_base.hpp:43
This class stores information about the triangle that's under an object, i.e.: the normal,...
Definition: terrain_info.hpp:32
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48