1
0
forked from 0ad/0ad
0ad/source/simulation/EntityTemplate.h

177 lines
4.2 KiB
C
Raw Normal View History

// EntityTemplate.h
//
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
//
// Entity Templates
//
// Usage: These templates are used as the default values for entity properties.
// Due to Pyrogenesis' data-inheritance model for these properties,
// templates specify a base-template, then override only those properties
// in that template that need to change.
// Similarly, entities need only specify properties they possess that are
// different to the ones in their respective templates. Of course,
// properties such as position, current HP, etc. cannot be inherited from
// a template in this way.
//
#ifndef BASE_ENTITY_INCLUDED
#define BASE_ENTITY_INCLUDED
#include "ps/CStr.h"
#include "graphics/ObjectEntry.h"
#include "scripting/ScriptableComplex.h"
# Added tool for viewing models and animations outside the game. Atlas: Added ActorViewer. Moved GL canvas into separate class for shared use. Disabled message-handling callback while blocked on the game, and stopped creating dialog boxes inside the game thread in order to avoid deadlocks (hopefully). Support multiple Views (for independent sets of camera/update/render code). Recalculate territory boundaries when necessary. Changed default list of animations to match those currently used by actors. # Tidied up more code. Moved some more #includes out of .h files, to minimise unnecessary compilation. MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2 (use PI/2), MAX3, ABS (use abs)). ObjectManager: Removed some ScEd-specific things. Unit: Moved creation out of UnitManager, so units can be created without adding to the manager. Changed CStr8 to the more conventional CStr. app_hooks: Removed warning for setting multiple times. win: Restored SEH catcher. GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do what it says it does ("force renderer to load everything") since we're loading-on-demand most stuff and it doesn't seem especially useful since we'd prefer to minimise loading times (but feel free to correct me if I'm wrong). (And because it crashes when things need to be initialised in a different order, so it's easier to remove than to understand and fix it.) PatchRData, Renderer: Work sensibly when there's no game (hence no LOS manager, water, etc). LOSManager: Use entity position instead of actor position when possible. TerritoryManager: Allow delayed recalculations (so Atlas can issue lots of move+recalculate commands per frame). Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to be deleted manually. This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
#include "scripting/DOMEvent.h"
#include "BoundingObjects.h"
#include "EntitySupport.h"
#include "ScriptObject.h"
class CPlayer;
# Added tool for viewing models and animations outside the game. Atlas: Added ActorViewer. Moved GL canvas into separate class for shared use. Disabled message-handling callback while blocked on the game, and stopped creating dialog boxes inside the game thread in order to avoid deadlocks (hopefully). Support multiple Views (for independent sets of camera/update/render code). Recalculate territory boundaries when necessary. Changed default list of animations to match those currently used by actors. # Tidied up more code. Moved some more #includes out of .h files, to minimise unnecessary compilation. MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2 (use PI/2), MAX3, ABS (use abs)). ObjectManager: Removed some ScEd-specific things. Unit: Moved creation out of UnitManager, so units can be created without adding to the manager. Changed CStr8 to the more conventional CStr. app_hooks: Removed warning for setting multiple times. win: Restored SEH catcher. GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do what it says it does ("force renderer to load everything") since we're loading-on-demand most stuff and it doesn't seem especially useful since we'd prefer to minimise loading times (but feel free to correct me if I'm wrong). (And because it crashes when things need to be initialised in a different order, so it's easier to remove than to understand and fix it.) PatchRData, Renderer: Work sensibly when there's no game (hence no LOS manager, water, etc). LOSManager: Use entity position instead of actor position when possible. TerritoryManager: Allow delayed recalculations (so Atlas can issue lots of move+recalculate commands per frame). Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to be deleted manually. This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
class CXeromyces;
class XMBElement;
class CEntityTemplate : public CJSComplex<CEntityTemplate>, public IEventTarget
{
public:
CPlayer* m_player; // Which player this template is for, or null for the no-player template
// used to read unmodified values for upgrades and such.
CEntityTemplate( CPlayer* player );
~CEntityTemplate();
// Load from XML
bool loadXML( const CStr& filename );
// Load a tree of properties from an XML (XMB) node.
void XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, const CStrW& BasePropertyName );
// Base stats
CEntityTemplate* m_base;
//bool m_extant;
// The unmodified, no-player version of this template
CEntityTemplate* m_unmodified;
// The class types this entity has
CClassSet m_classes;
CStrW m_Base_Name; // <- We don't guarantee the order XML files will be loaded in, so we'll store the name of the
// parent entity referenced, then, after all files are loaded, attempt to match names to objects.
CStrW m_actorName;
CStrW m_Tag;
CBoundingCircle* m_bound_circle;
CBoundingBox* m_bound_box;
CBoundingObject::EBoundingType m_bound_type;
//SP properties
float m_staminaMax;
// HP properties
float m_healthMax;
float m_healthRegenRate;
float m_healthRegenStart;
float m_healthDecayRate;
// Display properties
bool m_barsEnabled;
float m_barOffset;
float m_barHeight;
float m_barWidth;
float m_barBorderSize;
CStr m_barBorder;
float m_staminaBarHeight;
int m_staminaBarSize;
float m_staminaBarWidth;
int m_staminaBorderWidth;
int m_staminaBorderHeight;
CStr m_staminaBorderName;
2005-09-14 21:43:16 +02:00
float m_healthBarHeight;
int m_healthBarSize;
float m_healthBarWidth;
int m_healthBorderWidth;
int m_healthBorderHeight;
CStr m_healthBorderName;
float m_rankWidth;
float m_rankHeight;
// Stance name
CStr m_stanceName;
//Rank properties
CStr m_rankName;
//Rally name
CStr m_rallyName;
float m_rallyWidth;
float m_rallyHeight;
2005-09-14 21:43:16 +02:00
// Minimap properties
CStrW m_minimapType;
int m_minimapR;
int m_minimapG;
int m_minimapB;
// Y anchor
CStrW m_anchorType;
// LOS
int m_los;
bool m_visionPermanent;
// Is this object a territory centre? (e.g. Settlements in 0AD)
bool m_isTerritoryCentre;
// Foundation entity, or "" for none
CStrW m_foundation;
// Socket entity that we can be built on, or "" for free placement
CStrW m_socket;
// Can be "allied" to allow placement only in allied territories, or "" or "all" for all territories
CStrW m_territoryRestriction;
float m_speed;
float m_runSpeed;
float m_runRegenRate;
float m_runDecayRate;
bool m_passThroughAllies;
float m_runMaxRange;
float m_runMinRange;
int m_sectorDivs;
int m_pitchDivs;
float m_pitchValue;
float m_anchorConformX;
float m_anchorConformZ;
float m_turningRadius;
CScriptObject m_EventHandlers[EVENT_LAST];
void loadBase();
jsval getClassSet();
void setClassSet( jsval value );
void rebuildClassSet();
// Script-bound functions
// Get script execution contexts - always run in the context of the entity that fired it.
JSObject* GetScriptExecContext( IEventTarget* target );
jsval ToString( JSContext* cx, uintN argc, jsval* argv );
static void ScriptingInit();
private:
static STL_HASH_SET<CStr, CStr_hash_compare> scriptsLoaded;
NO_COPY_CTOR(CEntityTemplate);
};
#endif