2013-09-09 00:18:36 +01:00
|
|
|
#pragma once
|
2014-02-28 11:23:51 +00:00
|
|
|
#ifndef _GAMEOBJECT_HPP_
|
|
|
|
#define _GAMEOBJECT_HPP_
|
2013-09-09 00:18:36 +01:00
|
|
|
|
2014-06-06 17:04:00 +01:00
|
|
|
#include <engine/RWTypes.hpp>
|
2013-12-20 14:03:32 +00:00
|
|
|
#include <loaders/LoaderIDE.hpp>
|
|
|
|
#include <loaders/LoaderIPL.hpp>
|
2013-09-09 00:18:36 +01:00
|
|
|
#include <glm/gtc/quaternion.hpp>
|
|
|
|
#include <memory>
|
|
|
|
|
2014-06-06 17:04:00 +01:00
|
|
|
class CharacterController;
|
2014-03-01 04:12:35 +00:00
|
|
|
class ModelFrame;
|
2013-09-11 00:26:13 +01:00
|
|
|
class Animator;
|
2013-09-09 00:18:36 +01:00
|
|
|
|
2013-12-20 16:02:46 +00:00
|
|
|
class GameWorld;
|
2013-09-09 00:18:36 +01:00
|
|
|
|
|
|
|
/**
|
2014-07-09 05:04:48 +01:00
|
|
|
* @brief Base data and interface for all world "objects" like vehicles, peds.
|
|
|
|
*
|
|
|
|
* Contains handle to the world, and other useful properties like water level
|
|
|
|
* tracking used to make tunnels work.
|
2013-09-09 00:18:36 +01:00
|
|
|
*/
|
2014-02-28 11:23:51 +00:00
|
|
|
struct GameObject
|
2013-09-09 00:18:36 +01:00
|
|
|
{
|
|
|
|
glm::vec3 position;
|
|
|
|
glm::quat rotation;
|
|
|
|
|
2014-06-06 12:18:32 +01:00
|
|
|
ModelHandle* model; /// Cached pointer to Object's Model.
|
2013-09-09 00:18:36 +01:00
|
|
|
|
2013-12-20 16:02:46 +00:00
|
|
|
GameWorld* engine;
|
2013-09-09 00:18:36 +01:00
|
|
|
|
2013-09-11 00:26:13 +01:00
|
|
|
Animator* animator; /// Object's animator.
|
2014-06-13 21:54:17 +01:00
|
|
|
|
2013-12-06 21:25:34 +00:00
|
|
|
/**
|
|
|
|
* Health value
|
|
|
|
*/
|
2014-06-02 00:08:48 +01:00
|
|
|
float mHealth;
|
|
|
|
|
2014-06-13 21:54:17 +01:00
|
|
|
bool _inWater;
|
|
|
|
|
2014-07-09 05:04:48 +01:00
|
|
|
/**
|
|
|
|
* @brief stores the height of water at the last tick
|
|
|
|
*/
|
2014-06-15 01:34:13 +01:00
|
|
|
float _lastHeight;
|
|
|
|
|
2014-06-06 12:18:32 +01:00
|
|
|
GameObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, ModelHandle* model)
|
2014-06-13 21:54:17 +01:00
|
|
|
: position(pos), rotation(rot), model(model), engine(engine), animator(nullptr), mHealth(0.f),
|
2014-06-17 00:48:19 +01:00
|
|
|
_inWater(false), _lastHeight(std::numeric_limits<float>::max())
|
2014-06-02 00:08:48 +01:00
|
|
|
{}
|
2013-12-12 02:55:31 +00:00
|
|
|
|
2014-06-02 00:08:48 +01:00
|
|
|
virtual ~GameObject() {}
|
2013-09-09 00:18:36 +01:00
|
|
|
|
2014-07-09 05:04:48 +01:00
|
|
|
/**
|
|
|
|
* @brief Enumeration of possible object types.
|
|
|
|
*/
|
2013-09-09 00:18:36 +01:00
|
|
|
enum Type
|
|
|
|
{
|
2014-07-04 21:06:56 +01:00
|
|
|
Instance,
|
|
|
|
Character,
|
2014-03-01 11:19:33 +00:00
|
|
|
Vehicle,
|
2014-07-04 21:06:56 +01:00
|
|
|
Pickup,
|
2014-03-01 11:19:33 +00:00
|
|
|
Unknown
|
2013-09-09 00:18:36 +01:00
|
|
|
};
|
|
|
|
|
2014-07-09 05:04:48 +01:00
|
|
|
/**
|
|
|
|
* @brief determines what type of object this is.
|
|
|
|
* @return one of Type
|
|
|
|
*/
|
2014-03-01 11:19:33 +00:00
|
|
|
virtual Type type() { return Unknown; }
|
2013-09-09 00:18:36 +01:00
|
|
|
|
|
|
|
virtual void setPosition(const glm::vec3& pos);
|
|
|
|
|
|
|
|
virtual glm::vec3 getPosition() const;
|
2013-09-09 04:04:21 +01:00
|
|
|
|
|
|
|
virtual glm::quat getRotation() const;
|
2013-12-06 21:25:34 +00:00
|
|
|
|
|
|
|
struct DamageInfo
|
|
|
|
{
|
|
|
|
enum DamageType
|
|
|
|
{
|
|
|
|
Explosion,
|
|
|
|
Burning,
|
|
|
|
Bullet,
|
|
|
|
Physics
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* World position of damage
|
|
|
|
*/
|
|
|
|
glm::vec3 damageLocation;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* World position of the source (used for direction)
|
|
|
|
*/
|
|
|
|
glm::vec3 damageSource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Magnitude of destruction
|
|
|
|
*/
|
|
|
|
float hitpoints;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of the damage
|
|
|
|
*/
|
|
|
|
DamageType type;
|
2014-06-11 21:00:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Physics impulse.
|
|
|
|
*/
|
|
|
|
float impulse;
|
2013-12-06 21:25:34 +00:00
|
|
|
};
|
|
|
|
|
2014-07-09 05:04:48 +01:00
|
|
|
virtual bool takeDamage(const DamageInfo& /*damage*/) { return false; }
|
2014-03-01 04:12:35 +00:00
|
|
|
|
2014-06-02 04:58:41 +01:00
|
|
|
virtual bool isAnimationFixed() const { return true; }
|
2014-06-13 21:54:17 +01:00
|
|
|
|
|
|
|
virtual bool isInWater() const { return _inWater; }
|
2014-07-01 23:04:23 +01:00
|
|
|
|
|
|
|
virtual void tick(float dt) = 0;
|
2013-09-09 00:18:36 +01:00
|
|
|
};
|
|
|
|
|
2014-02-28 11:23:51 +00:00
|
|
|
#endif // __GAMEOBJECTS_HPP__
|