2004-05-22 02:57:54 +02:00
|
|
|
// Entity.h
|
|
|
|
//
|
2004-07-20 21:30:35 +02:00
|
|
|
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
|
2004-05-22 02:57:54 +02:00
|
|
|
//
|
|
|
|
// Entity class.
|
|
|
|
//
|
|
|
|
// Usage: Do not attempt to instantiate this class directly. (See EntityManager.h)
|
|
|
|
// Most of the members are trivially obvious; some highlights are:
|
|
|
|
//
|
|
|
|
// HEntity me: is a reference to this entity. Use instead of the address-of operator for
|
|
|
|
// non-temporary references. See EntityHandles.h
|
2004-05-29 05:32:33 +02:00
|
|
|
//
|
|
|
|
// Destroying entities: An entity is destroyed when all references to it expire.
|
|
|
|
// It is somewhat unfunny if this happens while a method from this
|
|
|
|
// class is still executing. If you need to kill an entity,
|
2004-07-20 21:30:35 +02:00
|
|
|
// use CEntity::kill(). If kill() releases the final handle,
|
2004-05-29 05:32:33 +02:00
|
|
|
// the entity is placed in the reaper queue and is deleted immediately
|
|
|
|
// prior to its next update cycle.
|
|
|
|
//
|
2004-05-22 02:57:54 +02:00
|
|
|
// CUnit* m_actor: is the visible representation of this entity.
|
|
|
|
// std::hash_map m_properties: isn't yet used, is capable of storing properties defined by script.
|
|
|
|
//
|
|
|
|
// snapToGround(): Called every frame, this will ensure the entity never takes flight.
|
|
|
|
// updateActorTransforms(): Must be called every time the position of this entity changes.
|
2004-05-26 22:57:25 +02:00
|
|
|
// Also remember to update the collision object if you alter the position directly.
|
2004-05-22 02:57:54 +02:00
|
|
|
//
|
|
|
|
// Some notes: update() and dispatch() /can/ be called directly without ill effects,
|
|
|
|
// but it's preferable to go through the Entity manager and the Scheduler, respectively.
|
|
|
|
//
|
2004-05-22 01:46:16 +02:00
|
|
|
|
|
|
|
#ifndef ENTITY_INCLUDED
|
|
|
|
#define ENTITY_INCLUDED
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include "EntityProperties.h"
|
|
|
|
|
|
|
|
#include "BaseEntity.h"
|
2004-05-26 22:57:25 +02:00
|
|
|
#include "Vector2D.h"
|
|
|
|
#include "BoundingObjects.h"
|
2004-05-22 01:46:16 +02:00
|
|
|
#include "Vector3D.h"
|
|
|
|
#include "Unit.h"
|
|
|
|
#include "UnitManager.h"
|
|
|
|
#include "EntityOrders.h"
|
|
|
|
#include "EntityHandles.h"
|
|
|
|
#include "EntityMessage.h"
|
|
|
|
|
|
|
|
class CEntityManager;
|
|
|
|
|
2004-06-11 00:24:03 +02:00
|
|
|
class CEntity : public IPropertyOwner
|
2004-05-22 01:46:16 +02:00
|
|
|
{
|
2004-06-02 18:11:32 +02:00
|
|
|
friend class CEntityManager;
|
2004-05-22 01:46:16 +02:00
|
|
|
public:
|
2004-06-11 00:24:03 +02:00
|
|
|
// Intrinsic properties
|
|
|
|
CProperty_CStr m_name;
|
|
|
|
CProperty_float m_speed;
|
|
|
|
CProperty_float m_turningRadius;
|
2004-07-20 21:30:35 +02:00
|
|
|
CProperty_bool m_selected;
|
|
|
|
|
|
|
|
bool m_extant; // Don't want JS to have direct write-access to these. (Things that should be done might not be)
|
|
|
|
CProperty_bool m_extant_mirror; // plus this way limits the number of nasty semantics to work around.
|
|
|
|
u8 m_grouped;
|
|
|
|
CProperty_i32 m_grouped_mirror;
|
|
|
|
|
|
|
|
//-- Interpolated property
|
|
|
|
CVector3D m_position;
|
|
|
|
CVector3D m_position_previous;
|
|
|
|
CProperty_CVector3D m_graphics_position;
|
|
|
|
|
2004-07-23 12:56:52 +02:00
|
|
|
CVector2D m_graphicsOffset;
|
|
|
|
|
2004-05-26 22:57:25 +02:00
|
|
|
CBoundingObject* m_bounds;
|
2004-05-22 01:46:16 +02:00
|
|
|
float m_targetorientation;
|
2004-05-26 22:57:25 +02:00
|
|
|
CVector2D m_ahead;
|
2004-07-20 21:30:35 +02:00
|
|
|
|
|
|
|
//-- Interpolated property
|
|
|
|
float m_orientation;
|
|
|
|
float m_orientation_previous;
|
|
|
|
CProperty_float m_graphics_orientation;
|
|
|
|
|
2004-05-22 01:46:16 +02:00
|
|
|
CUnit* m_actor;
|
|
|
|
|
|
|
|
std::deque<CEntityOrder> m_orderQueue;
|
|
|
|
|
2004-05-22 02:57:54 +02:00
|
|
|
private:
|
2004-05-22 01:46:16 +02:00
|
|
|
CEntity( CBaseEntity* base, CVector3D position, float orientation );
|
2004-05-28 04:57:50 +02:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
bool processGotoNoPathing( CEntityOrder* current, size_t timestep_milli );
|
|
|
|
bool processGoto( CEntityOrder* current, size_t timestep_milli );
|
|
|
|
bool processPatrol( CEntityOrder* current, size_t timestep_milli );
|
2004-05-28 04:57:50 +02:00
|
|
|
|
2004-05-22 01:46:16 +02:00
|
|
|
public:
|
2004-05-29 05:32:33 +02:00
|
|
|
~CEntity();
|
2004-05-22 01:46:16 +02:00
|
|
|
|
|
|
|
// Handle-to-self.
|
|
|
|
HEntity me;
|
2004-07-20 21:30:35 +02:00
|
|
|
|
|
|
|
void dispatch( const CMessage* msg );
|
2004-07-27 23:00:53 +02:00
|
|
|
void update( size_t timestep_millis );
|
2004-07-20 21:30:35 +02:00
|
|
|
void kill();
|
|
|
|
|
|
|
|
void interpolate( float relativeoffset );
|
2004-05-22 01:46:16 +02:00
|
|
|
void snapToGround();
|
2004-07-20 21:30:35 +02:00
|
|
|
void updateActorTransforms();
|
|
|
|
void render();
|
|
|
|
void renderSelectionOutline( float alpha = 1.0f );
|
|
|
|
|
2004-06-11 00:24:03 +02:00
|
|
|
void repath();
|
|
|
|
|
|
|
|
void loadBase();
|
2004-07-20 21:30:35 +02:00
|
|
|
|
|
|
|
void reorient(); // Orientation
|
2004-06-11 00:24:03 +02:00
|
|
|
void teleport(); // Fixes things if the position is changed by something externally.
|
2004-07-20 21:30:35 +02:00
|
|
|
void checkSelection(); // In case anyone tries to select/deselect this through JavaScript. You'd think they'd have something better to do.
|
|
|
|
void checkGroup(); // Groups
|
|
|
|
void checkExtant(); // Existance
|
|
|
|
|
|
|
|
bool acceptsOrder( int orderType, CEntity* orderTarget );
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
void clearOrders();
|
2004-05-22 01:46:16 +02:00
|
|
|
void pushOrder( CEntityOrder& order );
|
|
|
|
};
|
|
|
|
|
2004-07-22 18:18:12 +02:00
|
|
|
// General entity globals
|
|
|
|
|
|
|
|
|
|
|
|
// In it's current incarnation, inefficient but pretty
|
|
|
|
#define SELECTION_TERRAIN_CONFORMANCE
|
|
|
|
|
|
|
|
extern int SELECTION_CIRCLE_POINTS;
|
|
|
|
extern int SELECTION_BOX_POINTS;
|
|
|
|
extern int SELECTION_SMOOTHNESS_UNIFIED;
|
|
|
|
|
|
|
|
|
2004-06-02 18:11:32 +02:00
|
|
|
#endif
|