SuperTuxKart
Loading...
Searching...
No Matches
rubber_ball.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2011-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_RUBBER_BALL_HPP
20#define HEADER_RUBBER_BALL_HPP
21
22#include <irrString.h>
23
24#include "items/flyable.hpp"
25#include "tracks/track_sector.hpp"
26#include "utils/cpp2011.hpp"
27
28class AbstractKart;
29class SFXBase;
30
34class RubberBall: public Flyable, public TrackSector
35{
36private:
39 int m_id;
40
42 static float m_st_interval;
43
46
49
53
60
66
71
76
80 static int16_t m_st_delete_ticks;
81
85
89
92
95
111
114
118
122
127
131
135
139
148 float m_t;
149
154
157
163
167
171
177
182
186
192
195
196 bool m_restoring_state;
197
198 void computeTarget();
200 unsigned int getSuccessorToHitTarget(unsigned int node_index,
201 float *f=NULL);
202 void getNextControlPoint();
203 float updateHeight();
204 void interpolate(Vec3 *next_xyz, int ticks);
205 void moveTowardsTarget(Vec3 *next_xyz, int ticks);
206 void updateWeightedSpeed(int ticks);
207 void initializeControlPoints(const Vec3 &xyz);
208 float getTunnelHeight(const Vec3 &next_xyz,
209 const float vertical_offset) const;
210 bool checkTunneling();
211 void removePingSFX();
212
213public:
214 RubberBall (AbstractKart* kart);
215 virtual ~RubberBall();
216 static void init(const XMLNode &node, scene::IMesh *rubberball);
217 virtual bool updateAndDelete(int ticks) OVERRIDE;
218 virtual bool hit(AbstractKart* kart, PhysicalObject* obj=NULL) OVERRIDE;
219 virtual void setAnimation(AbstractKartAnimation *animation) OVERRIDE;
220 // ------------------------------------------------------------------------
223 //virtual HitEffect *getHitEffect() const {return NULL; }
224 // ------------------------------------------------------------------------
225 virtual BareNetworkString* saveState(std::vector<std::string>* ru)
226 OVERRIDE;
227 // ------------------------------------------------------------------------
228 virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE;
229 // ------------------------------------------------------------------------
230 virtual void onFireFlyable() OVERRIDE;
231
232}; // RubberBall
233
234#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
Definition: physical_object.hpp:40
Definition: rubber_ball.hpp:35
Vec3 m_control_points[4]
Keep the last two, current, and next aiming points for interpolation.
Definition: rubber_ball.hpp:121
static int16_t m_st_delete_ticks
If the ball overtakes its target or starts to aim at the kart which originally shot the rubber ball,...
Definition: rubber_ball.hpp:80
bool m_fast_ping
This flag is set if the target is within the fast ping distance.
Definition: rubber_ball.hpp:185
void interpolate(Vec3 *next_xyz, int ticks)
Uses Hermite splines (Catmull-Rom) to interpolate the position of the ball between the control points...
Definition: rubber_ball.cpp:609
float m_current_max_height
The current maximum height of the ball.
Definition: rubber_ball.hpp:170
void moveTowardsTarget(Vec3 *next_xyz, int ticks)
Moves the rubber ball in a straight line towards the target.
Definition: rubber_ball.cpp:513
static float m_st_fast_ping_distance
Distance between ball and target at which the ball will start to bounce faster (which makes more 'pin...
Definition: rubber_ball.hpp:65
float m_previous_height
To simplify code this stores the previous height above terrain used.
Definition: rubber_ball.hpp:130
static float m_st_min_interpolation_distance
Each control point chosen must be at least this far away from the previous one.
Definition: rubber_ball.hpp:75
void getNextControlPoint()
Determines the next control points to aim at.
Definition: rubber_ball.cpp:262
static float m_st_target_distance
If the ball is closer than this distance to the target, it will start to aim directly at the target (...
Definition: rubber_ball.hpp:52
float m_height_timer
This timer is used to determine the height depending on the time.
Definition: rubber_ball.hpp:166
static float m_st_max_height_difference
In somce track, e.g.
Definition: rubber_ball.hpp:59
static float m_st_max_speed_offset
If the ball is farther to its target than max_offset_distance, the speed in addition to the difficult...
Definition: rubber_ball.hpp:88
float m_length_cp_2_3
Estimated length of the spline between the control points 2 and 3.
Definition: rubber_ball.hpp:138
float updateHeight()
Updates the height of the rubber ball, and if necessary also adjusts the maximum height of the ball d...
Definition: rubber_ball.cpp:695
SFXBase * m_ping_sfx
A 'ping' sound effect to be played when the ball hits the ground.
Definition: rubber_ball.hpp:194
static float m_st_target_max_angle
The maximum angle the ball can change per second when being close to the taregt.
Definition: rubber_ball.hpp:70
static float m_st_max_offset_distance
The distance to target over which the ball is the fastest.
Definition: rubber_ball.hpp:94
float getTunnelHeight(const Vec3 &next_xyz, const float vertical_offset) const
When the ball is in a tunnel, this will return the tunnel height.
Definition: rubber_ball.cpp:757
float m_t
The parameter for the spline, m_t in [0,1].
Definition: rubber_ball.hpp:148
float m_distance_to_target
Distance to target.
Definition: rubber_ball.hpp:162
static float m_st_min_speed_offset
If the ball is closer to its target than min_offset_distance, the speed in addition to the difficulty...
Definition: rubber_ball.hpp:84
static float m_st_squash_duration
A class variable to store the default squash duration.
Definition: rubber_ball.hpp:45
bool checkTunneling()
Checks if the line from the previous ball position to the new position hits something,...
Definition: rubber_ball.cpp:651
virtual bool updateAndDelete(int ticks) OVERRIDE
Updates the rubber ball.
Definition: rubber_ball.cpp:374
static float m_st_early_target_factor
This factor is used to influence how much the rubber ball should aim at its target early.
Definition: rubber_ball.hpp:110
void updateDistanceToTarget()
Determines the distance to the target kart.
Definition: rubber_ball.cpp:775
virtual void onFireFlyable() OVERRIDE
Call when the item is (re-)fired (during rewind if needed) by projectile_manager.
Definition: rubber_ball.cpp:80
static void init(const XMLNode &node, scene::IMesh *rubberball)
Initialises this object with data from the power.xml file (this is a static function).
Definition: rubber_ball.cpp:292
float m_interval
How long it takes from one bounce of the ball to the next.
Definition: rubber_ball.hpp:156
float m_t_increase
How much m_t must increase per second in order to maintain a constant speed, i.e.
Definition: rubber_ball.hpp:153
uint8_t m_tunnel_count
This variable counts how often a ball tunneled (in consecutive frames).
Definition: rubber_ball.hpp:181
virtual ~RubberBall()
Destructor, removes any playing sfx.
Definition: rubber_ball.cpp:137
void updateWeightedSpeed(int ticks)
Calculates the current speed of the basket ball.
Definition: rubber_ball.cpp:552
float m_length_cp_1_2
Estimated length of the spline between the control points 1 and 2.
Definition: rubber_ball.hpp:134
int m_last_aimed_graph_node
The last graph node who's coordinates are stored in m_control_points[3].
Definition: rubber_ball.hpp:117
static float m_st_squash_slowdown
A class variable to store the default squash slowdown.
Definition: rubber_ball.hpp:48
unsigned int getSuccessorToHitTarget(unsigned int node_index, float *f=NULL)
Determines the successor of a graph node.
Definition: rubber_ball.cpp:238
virtual BareNetworkString * saveState(std::vector< std::string > *ru) OVERRIDE
This object does not create an explosion, all affects on karts are handled by this hit() function.
Definition: rubber_ball.cpp:887
virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE
Called when a state needs to be replayed.
Definition: rubber_ball.cpp:914
void computeTarget()
Determines the first kart that is still in the race.
Definition: rubber_ball.cpp:186
Vec3 m_previous_xyz
Saves the previous location of the ball.
Definition: rubber_ball.hpp:126
int m_id
Used in case of flyable debugging so that each output line gets a unique number for each ball.
Definition: rubber_ball.hpp:39
int16_t m_delete_ticks
If the ball overtakes its target or starts to aim at the kart which originally shot the rubber ball,...
Definition: rubber_ball.hpp:176
const AbstractKart * m_target
A pointer to the target kart.
Definition: rubber_ball.hpp:113
void initializeControlPoints(const Vec3 &xyz)
Sets up the control points for the interpolation.
Definition: rubber_ball.cpp:152
virtual bool hit(AbstractKart *kart, PhysicalObject *obj=NULL) OVERRIDE
Callback from the physics in case that a kart or object is hit.
Definition: rubber_ball.cpp:852
bool m_aiming_at_target
Once the ball is close enough, it will aim for the kart.
Definition: rubber_ball.hpp:191
static float m_st_interval
A class variable to store the default interval size.
Definition: rubber_ball.hpp:42
static float m_st_min_offset_distance
The distance to target under which the ball is the slowest.
Definition: rubber_ball.hpp:91
The base class for sound effects.
Definition: sfx_base.hpp:43
This object keeps track of which sector an object is on.
Definition: track_sector.hpp:39
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