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 float m_st_interval;
45  static float m_st_squash_duration;
48  static float m_st_squash_slowdown;
52  static float m_st_target_distance;
70  static float m_st_target_max_angle;
80  static int16_t m_st_delete_ticks;
84  static float m_st_min_speed_offset;
88  static float m_st_max_speed_offset;
148  float m_t;
156  float m_interval;
176  int16_t m_delete_ticks;
181  uint8_t m_tunnel_count;
196  bool m_restoring_state;
198  void computeTarget();
199  void updateDistanceToTarget();
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();
213 public:
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)
227  // ------------------------------------------------------------------------
228  virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE;
229  // ------------------------------------------------------------------------
230  virtual void onFireFlyable() OVERRIDE;
232 }; // RubberBall
234 #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:70
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:153
static float m_st_fast_ping_distance
Distance between ball and target at which the ball will start to bounce faster (which makes more &#39;pin...
Definition: rubber_ball.hpp:65
Vec3 m_control_points[4]
Keep the last two, current, and next aiming points for interpolation.
Definition: rubber_ball.hpp:121
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.g.
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:94
static float m_st_squash_duration
A class variable to store the default squash duration.
Definition: rubber_ball.hpp:45
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:75
bool m_fast_ping
This flag is set if the target is within the fast ping distance.
Definition: rubber_ball.hpp:185
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
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
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
const AbstractKart * m_target
A pointer to the target kart.
Definition: rubber_ball.hpp:113
static float m_st_min_offset_distance
The distance to target under which the ball is the slowest.
Definition: rubber_ball.hpp:91
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:88
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&#39;s coordinates are stored in m_control_points[3].
Definition: rubber_ball.hpp:117
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
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:38
float m_previous_height
To simplify code this stores the previous height above terrain used.
Definition: rubber_ball.hpp:130
static float m_st_squash_slowdown
A class variable to store the default squash slowdown.
Definition: rubber_ball.hpp:48
float m_length_cp_1_2
Estimated length of the spline between the control points 1 and 2.
Definition: rubber_ball.hpp:134
float m_t
The parameter for the spline, m_t in [0,1].
Definition: rubber_ball.hpp:148
bool checkTunneling()
Checks if the line from the previous ball position to the new position hits something, which indicates that the ball is tunneling through.
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:126
float m_height_timer
This timer is used to determine the height depending on the time.
Definition: rubber_ball.hpp:166
uint8_t m_tunnel_count
This variable counts how often a ball tunneled (in consecutive frames).
Definition: rubber_ball.hpp:181
float m_distance_to_target
Distance to target.
Definition: rubber_ball.hpp:162
static float m_st_max_height_difference
In somce track, e.g.
Definition: rubber_ball.hpp:59
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:170
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:138
Definition: flyable.hpp:48
float m_interval
How long it takes from one bounce of the ball to the next.
Definition: rubber_ball.hpp:156
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:191
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:110
static float m_st_interval
A class variable to store the default interval size.
Definition: rubber_ball.hpp:42
SFXBase * m_ping_sfx
A &#39;ping&#39; sound effect to be played when the ball hits the ground.
Definition: rubber_ball.hpp:194