Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Unit.h
Show All 18 Lines | |||||
#define INCLUDED_UNIT | #define INCLUDED_UNIT | ||||
#include <map> | #include <map> | ||||
#include <set> | #include <set> | ||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#include "simulation2/system/Entity.h" // entity_id_t | #include "simulation2/system/Entity.h" // entity_id_t | ||||
class CActorDef; | |||||
class CModelAbstract; | class CModelAbstract; | ||||
class CObjectEntry; | class CObjectEntry; | ||||
class CObjectManager; | class CObjectManager; | ||||
class CSkeletonAnim; | class CSkeletonAnim; | ||||
class CUnitAnimation; | class CUnitAnimation; | ||||
///////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////// | ||||
// CUnit: simple "actor" definition - defines a sole object within the world | // CUnit: simple "actor" definition - defines a sole object within the world | ||||
class CUnit | class CUnit | ||||
{ | { | ||||
NONCOPYABLE(CUnit); | NONCOPYABLE(CUnit); | ||||
private: | private: | ||||
// Private constructor. Needs complete list of selections for the variation. | // Private constructor. Needs complete list of selections for the variation. | ||||
CUnit(CObjectEntry* object, CObjectManager& objectManager, | CUnit(CObjectManager& objectManager, const CActorDef& actor, uint32_t seed); | ||||
const std::set<CStr>& actorSelections, uint32_t seed); | |||||
public: | public: | ||||
// Attempt to create a unit with the given actor, with a set of | // Attempt to create a unit with the given actor, with a set of | ||||
// suggested selections (with the rest being randomised using the | // suggested selections (with the rest being randomised using the | ||||
// given random seed). | // given random seed). | ||||
// Returns NULL on failure. | // Returns NULL on failure. | ||||
static CUnit* Create(const CStrW& actorName, uint32_t seed, const std::set<CStr>& selections, CObjectManager& objectManager); | static CUnit* Create(const CStrW& actorName, uint32_t seed, const std::set<CStr>& selections, CObjectManager& objectManager); | ||||
// destructor | // destructor | ||||
~CUnit(); | ~CUnit(); | ||||
// get unit's template object | // get unit's template object | ||||
const CObjectEntry& GetObject() const { return *m_Object; } | const CObjectEntry& GetObject() const { return *m_Object; } | ||||
// get unit's model data | // get unit's model data | ||||
CModelAbstract& GetModel() const { return *m_Model; } | CModelAbstract& GetModel() const { return *m_Model; } | ||||
CUnitAnimation* GetAnimation() { return m_Animation; } | CUnitAnimation* GetAnimation() { return m_Animation; } | ||||
/** | /** | ||||
* Update the model's animation. | * Update the model's animation. | ||||
* @param frameTime time in seconds | * @param frameTime time in seconds | ||||
*/ | */ | ||||
void UpdateModel(float frameTime); | void UpdateModel(float frameTime); | ||||
void UpdateLOD(u8 ratio); | |||||
// Sets the entity-selection, and updates the unit to use the new | // Sets the entity-selection, and updates the unit to use the new | ||||
// actor variation. Either set one key at a time, or a complete map. | // actor variation. Either set one key at a time, or a complete map. | ||||
void SetEntitySelection(const CStr& key, const CStr& selection); | void SetEntitySelection(const CStr& key, const CStr& selection); | ||||
void SetEntitySelection(const std::map<CStr, CStr>& selections); | void SetEntitySelection(const std::map<CStr, CStr>& selections); | ||||
// Most units have a hopefully-unique ID number, so they can be referred to | // Most units have a hopefully-unique ID number, so they can be referred to | ||||
// persistently despite saving/loading maps. Default for new units is -1; should | // persistently despite saving/loading maps. Default for new units is -1; should | ||||
// usually be set to CUnitManager::GetNewID() after creation. | // usually be set to CUnitManager::GetNewID() after creation. | ||||
entity_id_t GetID() const { return m_ID; } | entity_id_t GetID() const { return m_ID; } | ||||
void SetID(entity_id_t id); | void SetID(entity_id_t id); | ||||
const std::set<CStr>& GetActorSelections() const { return m_ActorSelections; } | const std::set<CStr>& GetActorSelections() const { return m_ActorSelections; } | ||||
void SetActorSelections(const std::set<CStr>& selections); | void SetActorSelections(const std::set<CStr>& selections); | ||||
private: | private: | ||||
// object from which unit was created; never NULL | // Actor for the unit | ||||
CObjectEntry* m_Object; | const CActorDef& m_Actor; | ||||
// object model representation; never NULL | // object from which unit was created; never NULL once fully created. | ||||
CModelAbstract* m_Model; | CObjectEntry* m_Object = nullptr; | ||||
// object model representation; never NULL once fully created. | |||||
CModelAbstract* m_Model = nullptr; | |||||
CUnitAnimation* m_Animation; | CUnitAnimation* m_Animation = nullptr; | ||||
// unique (per map) ID number for units created in the editor, as a | // unique (per map) ID number for units created in the editor, as a | ||||
// permanent way of referencing them. | // permanent way of referencing them. | ||||
entity_id_t m_ID; | entity_id_t m_ID; | ||||
u8 m_ratio = 0; | |||||
// seed used when creating unit | // seed used when creating unit | ||||
uint32_t m_Seed; | uint32_t m_Seed; | ||||
// actor-level selections for this unit | // actor-level selections for this unit | ||||
std::set<CStr> m_ActorSelections; | std::set<CStr> m_ActorSelections; | ||||
Stan: What's this? | |||||
Done Inline ActionsIt's supposed to be used for atlas to select variants, but it's not actually implemented... since 2006/2010 wraitii: It's supposed to be used for atlas to select variants, but it's not actually implemented... | |||||
Not Done Inline ActionsRight D2042 Stan: Right D2042 | |||||
// entity-level selections for this unit | // entity-level selections for this unit | ||||
std::map<CStr, CStr> m_EntitySelections; | std::map<CStr, CStr> m_EntitySelections; | ||||
// object manager which looks after this unit's objectentry | // object manager which looks after this unit's objectentry | ||||
CObjectManager& m_ObjectManager; | CObjectManager& m_ObjectManager; | ||||
void ReloadObject(); | void ReloadObject(); | ||||
friend class CUnitAnimation; | friend class CUnitAnimation; | ||||
}; | }; | ||||
#endif | #endif |
Wildfire Games · Phabricator
What's this?