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
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.
22 #include <irrString.h>
24 #include "items/flyable.hpp"
25 #include "tracks/track_sector.hpp"
26 #include "utils/cpp2011.hpp"
28 class AbstractKart;
29 class SFXBase;
34 class RubberBall: public Flyable, public TrackSector
35 {
36 private:
39  int m_id;
42  static int m_next_id;
45  static float m_st_interval;
48  static float m_st_squash_duration;
51  static float m_st_squash_slowdown;
55  static float m_st_target_distance;
73  static float m_st_target_max_angle;
83  static int16_t m_st_delete_ticks;
87  static float m_st_min_speed_offset;
91  static float m_st_max_speed_offset;
151  float m_t;
159  float m_interval;
179  int16_t m_delete_ticks;
184  uint8_t m_tunnel_count;
199  bool m_restoring_state;
201  void computeTarget();
202  void updateDistanceToTarget();
203  unsigned int getSuccessorToHitTarget(unsigned int node_index,
204  float *f=NULL);
205  void getNextControlPoint();
206  float updateHeight();
207  void interpolate(Vec3 *next_xyz, int ticks);
208  void moveTowardsTarget(Vec3 *next_xyz, int ticks);
209  void updateWeightedSpeed(int ticks);
210  void initializeControlPoints(const Vec3 &xyz);
211  float getTunnelHeight(const Vec3 &next_xyz,
212  const float vertical_offset) const;
213  bool checkTunneling();
214  void removePingSFX();
216 public:
217  RubberBall (AbstractKart* kart);
218  virtual ~RubberBall();
219  static void init(const XMLNode &node, scene::IMesh *rubberball);
220  virtual bool updateAndDelete(int ticks) OVERRIDE;
221  virtual bool hit(AbstractKart* kart, PhysicalObject* obj=NULL) OVERRIDE;
222  virtual void setAnimation(AbstractKartAnimation *animation) OVERRIDE;
223  // ------------------------------------------------------------------------
226  //virtual HitEffect *getHitEffect() const {return NULL; }
227  // ------------------------------------------------------------------------
228  virtual BareNetworkString* saveState(std::vector<std::string>* ru)
230  // ------------------------------------------------------------------------
231  virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE;
232  // ------------------------------------------------------------------------
233  virtual void onFireFlyable() OVERRIDE;
235 }; // RubberBall
237 #endif
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:73
void moveTowardsTarget(Vec3 *next_xyz, int ticks)
Moves the rubber ball in a straight line towards the target.
Definition: rubber_ball.cpp:505
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:156
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:68
Vec3 m_control_points[4]
Keep the last two, current, and next aiming points for interpolation.
Definition: rubber_ball.hpp:124
void updateDistanceToTarget()
Determines the distance to the target kart.
Definition: rubber_ball.cpp:767
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
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:34
static float m_st_max_offset_distance
The distance to target over which the ball is the fastest.
Definition: rubber_ball.hpp:97
static float m_st_squash_duration
A class variable to store the default squash duration.
Definition: rubber_ball.hpp:48
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:749
This object keeps track of which sector an object is on.
Definition: track_sector.hpp:38
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:78
bool m_fast_ping
This flag is set if the target is within the fast ping distance.
Definition: rubber_ball.hpp:188
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:179
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:83
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:55
const AbstractKart * m_target
A pointer to the target kart.
Definition: rubber_ball.hpp:116
static float m_st_min_offset_distance
The distance to target under which the ball is the slowest.
Definition: rubber_ball.hpp:94
unsigned int getSuccessorToHitTarget(unsigned int node_index, float *f=NULL)
Determines the successor of a graph node.
Definition: rubber_ball.cpp:230
void getNextControlPoint()
Determines the next control points to aim at.
Definition: rubber_ball.cpp:254
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:687
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:91
void computeTarget()
Determines the first kart that is still in the race.
Definition: rubber_ball.cpp:178
virtual bool updateAndDelete(int ticks) OVERRIDE
Updates the rubber ball.
Definition: rubber_ball.cpp:366
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:601
int m_last_aimed_graph_node
The last graph node who's coordinates are stored in m_control_points[3].
Definition: rubber_ball.hpp:120
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:87
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:879
Definition: physical_object.hpp:40
float m_previous_height
To simplify code this stores the previous height above terrain used.
Definition: rubber_ball.hpp:133
static float m_st_squash_slowdown
A class variable to store the default squash slowdown.
Definition: rubber_ball.hpp:51
float m_length_cp_1_2
Estimated length of the spline between the control points 1 and 2.
Definition: rubber_ball.hpp:137
static int m_next_id
A class variable which stores the next id number to use.
Definition: rubber_ball.hpp:42
float m_t
The parameter for the spline, m_t in [0,1].
Definition: rubber_ball.hpp:151
bool checkTunneling()
Checks if the line from the previous ball position to the new position hits something,...
Definition: rubber_ball.cpp:643
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:284
virtual void onFireFlyable() OVERRIDE
Call when the item is (re-)fired (during rewind if needed) by projectile_manager.
Definition: rubber_ball.cpp:78
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:52
Vec3 m_previous_xyz
Saves the previous location of the ball.
Definition: rubber_ball.hpp:129
float m_height_timer
This timer is used to determine the height depending on the time.
Definition: rubber_ball.hpp:169
uint8_t m_tunnel_count
This variable counts how often a ball tunneled (in consecutive frames).
Definition: rubber_ball.hpp:184
float m_distance_to_target
Distance to target.
Definition: rubber_ball.hpp:165
static float m_st_max_height_difference
In somce track, e.g.
Definition: rubber_ball.hpp:62
utility class used to parse XML files
Definition: xml_node.hpp:47
float m_current_max_height
The current maximum height of the ball.
Definition: rubber_ball.hpp:173
The base class for sound effects.
Definition: sfx_base.hpp:42
float m_length_cp_2_3
Estimated length of the spline between the control points 2 and 3.
Definition: rubber_ball.hpp:141
Definition: flyable.hpp:47
float m_interval
How long it takes from one bounce of the ball to the next.
Definition: rubber_ball.hpp:159
The base class for all kart animation, like rescue, explosion, or cannon.
Definition: abstract_kart_animation.hpp:59
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:844
void initializeControlPoints(const Vec3 &xyz)
Sets up the control points for the interpolation.
Definition: rubber_ball.cpp:144
virtual ~RubberBall()
Destructor, removes any playing sfx.
Definition: rubber_ball.cpp:129
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
Definition: rubber_ball.hpp:34
bool m_aiming_at_target
Once the ball is close enough, it will aim for the kart.
Definition: rubber_ball.hpp:194
virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE
Called when a state needs to be replayed.
Definition: rubber_ball.cpp:906
void updateWeightedSpeed(int ticks)
Calculates the current speed of the basket ball.
Definition: rubber_ball.cpp:544
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:113
static float m_st_interval
A class variable to store the default interval size.
Definition: rubber_ball.hpp:45
SFXBase * m_ping_sfx
A 'ping' sound effect to be played when the ball hits the ground.
Definition: rubber_ball.hpp:197