2011-07-19 20:39:32 -04:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2015-03-29 20:31:42 -04:00
|
|
|
// Copyright (C) 2011-2015 Joerg Henrichs
|
2011-07-19 20:39:32 -04:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#ifndef HEADER_RUBBER_BALL_HPP
|
|
|
|
#define HEADER_RUBBER_BALL_HPP
|
|
|
|
|
2011-08-25 18:02:29 -04:00
|
|
|
#include <irrString.h>
|
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
#include "items/flyable.hpp"
|
2011-08-04 19:33:41 -04:00
|
|
|
#include "tracks/track_sector.hpp"
|
2011-07-19 20:39:32 -04:00
|
|
|
|
2012-03-19 16:21:11 -04:00
|
|
|
class AbstractKart;
|
2011-08-21 17:56:49 -04:00
|
|
|
class SFXBase;
|
2011-07-19 20:39:32 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \ingroup items
|
|
|
|
*/
|
2011-08-04 19:33:41 -04:00
|
|
|
class RubberBall: public Flyable, public TrackSector
|
2011-07-19 20:39:32 -04:00
|
|
|
{
|
|
|
|
private:
|
2011-09-05 19:20:23 -04:00
|
|
|
/** Used in case of flyable debugging so that each output line gets
|
|
|
|
* a unique number for each ball. */
|
|
|
|
int m_id;
|
|
|
|
|
|
|
|
/** A class variable which stores the next id number to use. */
|
|
|
|
static int m_next_id;
|
2011-09-05 22:54:15 -04:00
|
|
|
|
2011-08-03 02:56:49 -04:00
|
|
|
/** A class variable to store the default interval size. */
|
|
|
|
static float m_st_interval;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2011-08-03 02:56:49 -04:00
|
|
|
/** A class variable to store the default squash duration. */
|
|
|
|
static float m_st_squash_duration;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2011-08-14 20:25:30 -04:00
|
|
|
/** A class variable to store the default squash slowdown. */
|
|
|
|
static float m_st_squash_slowdown;
|
|
|
|
|
2011-08-17 23:31:52 -04:00
|
|
|
/** If the ball is closer than this distance to the target, it will
|
|
|
|
* start to aim directly at the target (and not interpolate anymore). */
|
|
|
|
static float m_st_target_distance;
|
|
|
|
|
2011-10-16 08:17:56 -04:00
|
|
|
/** In somce track, e.g. subsea track, it is possible that the karts
|
|
|
|
* are on different parts of the track (different shortcuts), but
|
|
|
|
* still close to each other - because one of the parts is just
|
|
|
|
* on top of the other part. Therefore use the height as additional
|
|
|
|
* criteria to determine if a ball is close to its target. */
|
|
|
|
static float m_st_max_height_difference;
|
|
|
|
|
|
|
|
/** Distance between ball and target at which the ball will start to
|
2013-05-30 15:47:39 -04:00
|
|
|
* bounce faster (which makes more 'ping' sfx for the driver to
|
2011-10-16 08:17:56 -04:00
|
|
|
* hear it coming closer, but also higher probability to hit the
|
|
|
|
* target and not fly over it). */
|
2011-10-16 17:18:45 -04:00
|
|
|
static float m_st_fast_ping_distance;
|
2011-10-16 08:17:56 -04:00
|
|
|
|
2011-09-29 23:56:25 -04:00
|
|
|
/** The maximum angle the ball can change per second when being close
|
|
|
|
* to the taregt. If the target angle is small, it makes it much harder
|
|
|
|
* to hit the target, giving it some chances to escape. */
|
|
|
|
static float m_st_target_max_angle;
|
|
|
|
|
2011-08-17 23:31:52 -04:00
|
|
|
/** Each control point chosen must be at least this far away from
|
|
|
|
* the previous one. This gives smooth 'overall' interpolation
|
|
|
|
* even if the quads should be close to each other. */
|
|
|
|
static float m_st_min_interpolation_distance;
|
|
|
|
|
2011-10-05 17:27:21 -04:00
|
|
|
/** If the ball overtakes its target or starts to aim at the kart which
|
|
|
|
* originally shot the rubber ball, after this amount of time the
|
|
|
|
* ball will be deleted. */
|
|
|
|
static float m_st_delete_time;
|
|
|
|
|
2013-05-03 02:48:47 -04:00
|
|
|
/** Timer before another rubber ball can be picked up. This is to ensure
|
|
|
|
* that there are not too many rubber balls on the track in races with many
|
|
|
|
* karts. */
|
|
|
|
static float m_time_between_balls;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2011-10-18 16:14:03 -04:00
|
|
|
/** This factor is used to influence how much the rubber ball should aim
|
|
|
|
* at its target early. It used the 'distance to center of track' of its
|
2013-05-30 15:47:39 -04:00
|
|
|
* target, and adjusts the interpolation control points to be more or
|
2011-10-18 16:14:03 -04:00
|
|
|
* less at the same (relative) distance from center. If the factor is
|
|
|
|
* 1, the rubber ball will aim to be at the same relative distance,
|
|
|
|
* if the factor is 0, the rubber ball will aim directly at the
|
|
|
|
* driveline points. A factor of 1 usually means that by the time
|
|
|
|
* the ball starts aiming directly at the target it is (nearly) on the
|
|
|
|
* same 'line', meaning it only has to go straight. On the other hand
|
|
|
|
* in a tunnel this might result in the ball being too far to the
|
|
|
|
* side, increasing the likelihood of the ball tunneling through
|
|
|
|
* (which can happen when the ball switches to aim-at-target mode,
|
|
|
|
* in a tight curve, so that the direct line to the target goes through
|
|
|
|
* a wall. */
|
|
|
|
static float m_st_early_target_factor;
|
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
/** A pointer to the target kart. */
|
2012-03-19 16:21:11 -04:00
|
|
|
const AbstractKart *m_target;
|
2011-07-19 20:39:32 -04:00
|
|
|
|
2011-08-14 20:25:30 -04:00
|
|
|
/** The last graph node who's coordinates are stored in
|
|
|
|
* m_control_points[3]. */
|
|
|
|
int m_last_aimed_graph_node;
|
2011-07-20 18:21:44 -04:00
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
/** Keep the last two, current, and next aiming points
|
2011-08-17 19:06:48 -04:00
|
|
|
* for interpolation. */
|
2011-08-14 20:25:30 -04:00
|
|
|
Vec3 m_control_points[4];
|
|
|
|
|
2011-08-17 19:06:48 -04:00
|
|
|
/** Saves the previous location of the ball. This is needed if a ball
|
|
|
|
* should lose it target, and has to reinitialise the control points
|
|
|
|
* for the interpolation. */
|
|
|
|
Vec3 m_previous_xyz;
|
|
|
|
|
2011-10-25 16:48:36 -04:00
|
|
|
/** To simplify code this stores the previous height above terrain
|
|
|
|
* used. */
|
|
|
|
float m_previous_height;
|
|
|
|
|
2011-08-14 20:25:30 -04:00
|
|
|
/** Estimated length of the spline between the control points
|
|
|
|
* 1 and 2. */
|
|
|
|
float m_length_cp_1_2;
|
|
|
|
|
|
|
|
/** Estimated length of the spline between the control points
|
|
|
|
* 2 and 3. */
|
|
|
|
float m_length_cp_2_3;
|
|
|
|
|
|
|
|
/** The parameter for the spline, m_t in [0,1]. This is not directly
|
2013-05-30 15:47:39 -04:00
|
|
|
* related to the time, since depending on the distance between
|
|
|
|
* the two control points different increments must be used for m_t.
|
2011-08-14 20:25:30 -04:00
|
|
|
* For example, if the distance is 10 m, and assuming a speed of
|
|
|
|
* 10 m/s for the ball, then each second must add '1' to m_t. If
|
|
|
|
* the distance on the other hand is 200 m, then 10/200 = 1/20 per
|
|
|
|
* second must be added (so that it takes 20 seconds to move from 0
|
|
|
|
* to 1). */
|
2011-08-03 02:56:49 -04:00
|
|
|
float m_t;
|
|
|
|
|
2011-09-05 19:20:23 -04:00
|
|
|
/** How much m_t must increase per second in order to maintain a
|
2011-08-14 20:25:30 -04:00
|
|
|
* constant speed, i.e. the speed of the ball divided by the
|
|
|
|
* distance between the control points. See m_t for more details. */
|
2011-08-03 02:56:49 -04:00
|
|
|
float m_t_increase;
|
|
|
|
|
2011-07-21 18:07:09 -04:00
|
|
|
/** How long it takes from one bounce of the ball to the next. */
|
|
|
|
float m_interval;
|
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
/** This flag is set if the target is within the fast ping distance. It
|
2011-10-16 17:18:45 -04:00
|
|
|
* will cause the rubber ball to decrese the jump height and intervall. */
|
|
|
|
bool m_fast_ping;
|
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
/** Distance to target. This is measured in terms of 'distance along
|
|
|
|
* track', but also takes the 3d distance and height difference into
|
|
|
|
* account (in case that the target is on a different part of the
|
2011-10-16 17:18:45 -04:00
|
|
|
* track) */
|
|
|
|
float m_distance_to_target;
|
|
|
|
|
2011-07-21 18:07:09 -04:00
|
|
|
/** This timer is used to determine the height depending on the time.
|
|
|
|
* It is always between 0 and m_interval. */
|
2011-10-05 17:27:21 -04:00
|
|
|
float m_height_timer;
|
|
|
|
|
|
|
|
/** If the ball overtakes its target or starts to aim at the kart which
|
|
|
|
* originally shot the rubber ball, after a certain amount of time the
|
|
|
|
* ball will be deleted. This timer tracks this time. If it is < 0
|
|
|
|
* it indicates that the ball is targeting another kart atm. */
|
|
|
|
float m_delete_timer;
|
2011-07-21 02:58:28 -04:00
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
/** The current maximum height of the ball. This value will be
|
2011-08-14 20:25:30 -04:00
|
|
|
* reduced if the ball gets closer to the target. */
|
|
|
|
float m_current_max_height;
|
2011-07-22 02:26:28 -04:00
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
/** Once the ball is close enough, it will aim for the kart. If the
|
|
|
|
* kart should be able to then increase the distance to the ball,
|
|
|
|
* the ball will be removed and the kart escapes. This boolean is
|
|
|
|
* used to keep track of the state of this ball. */
|
|
|
|
bool m_aiming_at_target;
|
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
/** This variable counts how often a ball tunneled (in consecutive
|
2011-10-25 16:48:36 -04:00
|
|
|
* frames). If a ball tunnels a certain number of times, it is
|
|
|
|
* considered stuck and will be removed. */
|
|
|
|
unsigned int m_tunnel_count;
|
|
|
|
|
2011-08-21 17:56:49 -04:00
|
|
|
/** A 'ping' sound effect to be played when the ball hits the ground. */
|
|
|
|
SFXBase *m_ping_sfx;
|
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
void computeTarget();
|
2011-10-17 02:07:44 -04:00
|
|
|
void updateDistanceToTarget();
|
2013-05-30 15:47:39 -04:00
|
|
|
unsigned int getSuccessorToHitTarget(unsigned int node_index,
|
2011-08-14 20:25:30 -04:00
|
|
|
float *f=NULL);
|
|
|
|
void getNextControlPoint();
|
|
|
|
float updateHeight();
|
2011-08-17 19:06:48 -04:00
|
|
|
void interpolate(Vec3 *next_xyz, float dt);
|
2011-10-05 17:27:21 -04:00
|
|
|
void moveTowardsTarget(Vec3 *next_xyz, float dt);
|
2011-08-17 19:06:48 -04:00
|
|
|
void initializeControlPoints(const Vec3 &xyz);
|
2014-07-23 10:30:15 -04:00
|
|
|
float getTunnelHeight(const Vec3 &next_xyz,
|
|
|
|
const float vertical_offset) const;
|
2011-10-25 16:48:36 -04:00
|
|
|
bool checkTunneling();
|
2011-07-19 20:39:32 -04:00
|
|
|
public:
|
2012-03-19 16:21:11 -04:00
|
|
|
RubberBall (AbstractKart* kart);
|
2011-08-21 17:56:49 -04:00
|
|
|
virtual ~RubberBall();
|
2013-05-03 02:48:47 -04:00
|
|
|
static void init(const XMLNode &node, scene::IMesh *rubberball);
|
2011-08-24 20:06:33 -04:00
|
|
|
virtual bool updateAndDelete(float dt);
|
2012-03-19 16:21:11 -04:00
|
|
|
virtual bool hit(AbstractKart* kart, PhysicalObject* obj=NULL);
|
2013-05-03 02:48:47 -04:00
|
|
|
static float getTimeBetweenRubberBalls() {return m_time_between_balls;}
|
2011-08-24 20:06:33 -04:00
|
|
|
// ------------------------------------------------------------------------
|
2011-08-03 02:56:49 -04:00
|
|
|
/** This object does not create an explosion, all affects on
|
|
|
|
* karts are handled by this hit() function. */
|
2011-10-17 02:07:44 -04:00
|
|
|
//virtual HitEffect *getHitEffect() const {return NULL; }
|
2011-07-26 02:58:11 -04:00
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
}; // RubberBall
|
|
|
|
|
|
|
|
#endif
|