openrw/rwengine/include/engine/GameObject.hpp

123 lines
2.2 KiB
C++
Raw Normal View History

2013-09-09 00:18:36 +01:00
#pragma once
#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>
#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
/**
* @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
*/
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
*/
float mHealth;
2014-06-13 21:54:17 +01:00
bool _inWater;
/**
* @brief stores the height of water at the last tick
*/
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),
_inWater(false), _lastHeight(std::numeric_limits<float>::max())
{}
2013-12-12 02:55:31 +00:00
virtual ~GameObject() {}
2013-09-09 00:18:36 +01:00
/**
* @brief Enumeration of possible object types.
*/
2013-09-09 00:18:36 +01:00
enum Type
{
Instance,
Character,
2014-03-01 11:19:33 +00:00
Vehicle,
Pickup,
2014-03-01 11:19:33 +00:00
Unknown
2013-09-09 00:18:36 +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
};
virtual bool takeDamage(const DamageInfo& /*damage*/) { return false; }
2014-03-01 04:12:35 +00:00
virtual bool isAnimationFixed() const { return true; }
2014-06-13 21:54:17 +01:00
virtual bool isInWater() const { return _inWater; }
virtual void tick(float dt) = 0;
2013-09-09 00:18:36 +01:00
};
#endif // __GAMEOBJECTS_HPP__