2011-01-20 20:54:38 -05:00
|
|
|
// $Id$
|
2007-12-08 08:22:05 -05:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2007 Joerg Henrichs
|
|
|
|
//
|
2009-07-17 20:02:16 -04:00
|
|
|
// Linear item-kart intersection function written by
|
|
|
|
// by David Mikos. Copyright (C) 2009.
|
|
|
|
//
|
2007-12-08 08:22:05 -05:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2008-06-12 20:53:52 -04:00
|
|
|
// as published by the Free Software Foundation; either version 3
|
2007-12-08 08:22:05 -05:00
|
|
|
// 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.
|
|
|
|
|
2009-01-22 07:02:40 -05:00
|
|
|
#ifndef HEADER_FLYABLE_HPP
|
|
|
|
#define HEADER_FLYABLE_HPP
|
2007-12-08 08:22:05 -05:00
|
|
|
|
2009-03-11 20:57:00 -04:00
|
|
|
#include "irrlicht.h"
|
|
|
|
using namespace irr;
|
2009-03-26 19:31:00 -04:00
|
|
|
|
2008-12-04 00:09:51 -05:00
|
|
|
#include "audio/sfx_manager.hpp"
|
|
|
|
#include "items/powerup_manager.hpp"
|
2008-11-06 23:34:01 -05:00
|
|
|
#include "karts/moveable.hpp"
|
2009-01-23 00:23:22 -05:00
|
|
|
#include "tracks/terrain_info.hpp"
|
2007-12-08 08:22:05 -05:00
|
|
|
|
2008-09-07 10:45:43 -04:00
|
|
|
class FlyableInfo;
|
2008-12-04 00:09:51 -05:00
|
|
|
class Kart;
|
2009-03-31 21:30:10 -04:00
|
|
|
class PhysicalObject;
|
2010-02-06 21:05:21 -05:00
|
|
|
class XMLNode;
|
2008-09-07 10:45:43 -04:00
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \ingroup items
|
|
|
|
*/
|
2010-09-09 02:05:16 -04:00
|
|
|
class Flyable : public Moveable, public TerrainInfo
|
2007-12-08 08:22:05 -05:00
|
|
|
{
|
2008-09-07 10:42:37 -04:00
|
|
|
public:
|
|
|
|
private:
|
2007-12-08 08:22:05 -05:00
|
|
|
bool m_has_hit_something;
|
2008-09-07 10:55:05 -04:00
|
|
|
/** This flag is used to avoid that a rocket explodes mode than once.
|
|
|
|
* It can happen that more than one collision between a rocket and
|
2009-08-13 08:12:22 -04:00
|
|
|
* a track or kart is reported by the physics. */
|
2007-12-08 08:22:05 -05:00
|
|
|
bool m_exploded;
|
2010-03-04 07:35:58 -05:00
|
|
|
/** If this flag is set, the up velocity of the kart will not be
|
2009-08-13 08:12:22 -04:00
|
|
|
* adjusted in case that the objects is too high or too low above the
|
2008-09-19 02:50:55 -04:00
|
|
|
* terrain. Otherwise gravity will not work correctly on this object. */
|
2010-03-04 07:35:58 -05:00
|
|
|
bool m_adjust_up_velocity;
|
2009-08-13 08:12:22 -04:00
|
|
|
|
2007-12-08 08:22:05 -05:00
|
|
|
protected:
|
2010-04-28 09:17:02 -04:00
|
|
|
/** Kart which shot this flyable. */
|
|
|
|
Kart* m_owner;
|
|
|
|
|
|
|
|
/** Type of the powerup. */
|
|
|
|
PowerupManager::PowerupType
|
|
|
|
m_type;
|
|
|
|
|
|
|
|
/** Collision shape of this Flyable. */
|
2007-12-08 08:22:05 -05:00
|
|
|
btCollisionShape *m_shape;
|
2010-04-28 09:17:02 -04:00
|
|
|
|
|
|
|
/** Maximum height above terrain. */
|
2007-12-08 08:22:05 -05:00
|
|
|
float m_max_height;
|
2010-04-28 09:17:02 -04:00
|
|
|
|
|
|
|
/** Minimum height above terrain. */
|
2007-12-08 08:22:05 -05:00
|
|
|
float m_min_height;
|
2010-04-28 09:17:02 -04:00
|
|
|
|
|
|
|
/** Average of average of m_{min,ax}_height. */
|
|
|
|
float m_average_height;
|
|
|
|
|
|
|
|
/** Force pushing the Flyable up. */
|
2007-12-08 08:22:05 -05:00
|
|
|
float m_force_updown;
|
2010-04-28 09:17:02 -04:00
|
|
|
|
|
|
|
/** Speed of this Flyable. */
|
2007-12-08 08:22:05 -05:00
|
|
|
float m_speed;
|
2010-04-28 09:17:02 -04:00
|
|
|
|
|
|
|
/** Mass of this Flyable. */
|
2007-12-08 08:22:05 -05:00
|
|
|
float m_mass;
|
2010-04-28 09:17:02 -04:00
|
|
|
|
|
|
|
/** Size of this flyable. */
|
2010-03-04 07:35:58 -05:00
|
|
|
Vec3 m_extend;
|
2010-04-28 09:17:02 -04:00
|
|
|
|
2009-08-13 08:12:22 -04:00
|
|
|
// The flyable class stores the values for each flyable type, e.g.
|
2007-12-08 08:22:05 -05:00
|
|
|
// speed, min_height, max_height. These variables must be static,
|
|
|
|
// so we need arrays of these variables to have different values
|
2008-07-27 20:34:45 -04:00
|
|
|
// for bowling balls, missiles, ...
|
2010-04-28 09:17:02 -04:00
|
|
|
|
|
|
|
/** Speed of the projectile. */
|
|
|
|
static float m_st_speed[PowerupManager::POWERUP_MAX];
|
|
|
|
|
|
|
|
/** The mesh of this Flyable. */
|
|
|
|
static scene::IMesh *m_st_model[PowerupManager::POWERUP_MAX];
|
|
|
|
|
|
|
|
/** Minimum height above track. */
|
|
|
|
static float m_st_min_height[PowerupManager::POWERUP_MAX];
|
|
|
|
|
|
|
|
/**Max height above track. */
|
|
|
|
static float m_st_max_height[PowerupManager::POWERUP_MAX];
|
|
|
|
|
|
|
|
/** Force pushing up/down. */
|
|
|
|
static float m_st_force_updown[PowerupManager::POWERUP_MAX];
|
|
|
|
|
|
|
|
/** Size of the model. */
|
|
|
|
static Vec3 m_st_extend[PowerupManager::POWERUP_MAX];
|
2007-12-08 08:22:05 -05:00
|
|
|
|
2009-12-17 19:36:35 -05:00
|
|
|
/** time since thrown. used so a kart can't hit himself when trying something,
|
|
|
|
and also to put some time limit to some collectibles */
|
|
|
|
float m_time_since_thrown;
|
2009-08-13 08:12:22 -04:00
|
|
|
|
2009-12-17 19:36:35 -05:00
|
|
|
/** set to something > -1 if this flyable should auto-destrcut after a while */
|
|
|
|
float m_max_lifespan;
|
2009-08-13 08:12:22 -04:00
|
|
|
|
2009-12-17 19:36:35 -05:00
|
|
|
/** if set to true, the kart that throwns this flyable can't collide with it
|
|
|
|
for a short time */
|
|
|
|
bool m_owner_has_temporary_immunity;
|
2009-08-13 08:12:22 -04:00
|
|
|
|
|
|
|
void getClosestKart(const Kart **minKart, float *minDistSquared,
|
2010-03-04 07:35:58 -05:00
|
|
|
Vec3 *minDelta, const Kart* inFrontOf=NULL,
|
2008-12-26 16:11:08 -05:00
|
|
|
const bool backwards=false) const;
|
2009-07-17 20:02:16 -04:00
|
|
|
|
2010-03-04 07:35:58 -05:00
|
|
|
void getLinearKartItemIntersection(const Vec3 &origin,
|
|
|
|
const Kart *target_kart,
|
|
|
|
float item_XY_velocity, float gravity,
|
|
|
|
float forw_offset,
|
|
|
|
float *fire_angle, float *up_velocity);
|
2009-07-17 20:02:16 -04:00
|
|
|
|
|
|
|
|
2008-11-06 20:18:04 -05:00
|
|
|
/** init bullet for moving objects like projectiles */
|
2009-08-13 08:12:22 -04:00
|
|
|
void createPhysics(float y_offset,
|
2010-03-04 07:35:58 -05:00
|
|
|
const Vec3 &velocity,
|
2008-12-03 11:38:09 -05:00
|
|
|
btCollisionShape *shape, const float gravity=0.0f,
|
2009-08-13 08:12:22 -04:00
|
|
|
const bool rotates=false, const bool turn_around=false,
|
2008-11-17 20:29:22 -05:00
|
|
|
const btTransform* customDirection=NULL);
|
2007-12-08 08:22:05 -05:00
|
|
|
public:
|
|
|
|
|
2010-04-28 09:17:02 -04:00
|
|
|
Flyable (Kart* kart, PowerupManager::PowerupType type,
|
|
|
|
float mass=1.0f);
|
2007-12-08 08:22:05 -05:00
|
|
|
virtual ~Flyable ();
|
2009-08-13 08:12:22 -04:00
|
|
|
/** Enables/disables adjusting ov velocity depending on height above
|
2008-09-19 02:50:55 -04:00
|
|
|
* terrain. Missiles can 'follow the terrain' with this adjustment,
|
|
|
|
* but gravity will basically be disabled. */
|
2010-03-04 07:35:58 -05:00
|
|
|
void setAdjustUpVelocity(bool f) { m_adjust_up_velocity = f; }
|
2010-02-06 21:05:21 -05:00
|
|
|
static void init (const XMLNode &node, scene::IMesh *model,
|
2010-04-28 09:17:02 -04:00
|
|
|
PowerupManager::PowerupType type);
|
2007-12-08 08:22:05 -05:00
|
|
|
virtual void update (float);
|
2008-09-07 10:55:05 -04:00
|
|
|
void updateFromServer(const FlyableInfo &f, float dt);
|
2007-12-08 08:22:05 -05:00
|
|
|
|
|
|
|
virtual void hitTrack () {};
|
2009-03-31 21:30:10 -04:00
|
|
|
virtual void hit (Kart* kart, PhysicalObject* obj=NULL);
|
2008-12-03 00:49:16 -05:00
|
|
|
bool hasHit () { return m_has_hit_something; }
|
2009-08-13 08:12:22 -04:00
|
|
|
/** Indicates that something was hit and that this object must
|
2008-12-04 00:09:51 -05:00
|
|
|
* be removed. */
|
|
|
|
void setHasHit () { m_has_hit_something = true; }
|
|
|
|
void reset () { Moveable::reset(); }
|
2009-12-17 19:36:35 -05:00
|
|
|
bool isOwnerImmunity(const Kart *kart_hit) const;
|
2011-01-17 16:21:47 -05:00
|
|
|
/** Returns the type of flyable. */
|
|
|
|
PowerupManager::PowerupType
|
|
|
|
getType() const {return m_type;}
|
2010-02-15 14:17:35 -05:00
|
|
|
virtual const char* getExplosionSound() const { return "explosion"; }
|
2009-08-13 08:12:22 -04:00
|
|
|
/** Indicates if an explosion needs to be added if this flyable
|
2008-12-04 00:09:51 -05:00
|
|
|
* is removed. */
|
|
|
|
virtual bool needsExplosion() const {return true;}
|
2007-12-08 08:22:05 -05:00
|
|
|
}; // Flyable
|
|
|
|
|
|
|
|
#endif
|