Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Unit.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_UNIT
19 #define INCLUDED_UNIT
20 
21 #include <set>
22 
23 #include "ps/CStr.h"
24 #include "simulation2/system/Entity.h" // entity_id_t
25 
26 class CModelAbstract;
27 class CObjectEntry;
28 class CObjectManager;
29 class CSkeletonAnim;
30 class CUnitAnimation;
31 
32 
33 /////////////////////////////////////////////////////////////////////////////////////////////
34 // CUnit: simple "actor" definition - defines a sole object within the world
35 class CUnit
36 {
38 private:
39  // Private constructor. Needs complete list of selections for the variation.
40  CUnit(CObjectEntry* object, CObjectManager& objectManager,
41  const std::set<CStr>& actorSelections, uint32_t seed);
42 
43 public:
44  // Attempt to create a unit with the given actor, with a set of
45  // suggested selections (with the rest being randomised using the
46  // given random seed).
47  // Returns NULL on failure.
48  static CUnit* Create(const CStrW& actorName, uint32_t seed, const std::set<CStr>& selections, CObjectManager& objectManager);
49 
50  // destructor
51  ~CUnit();
52 
53  // get unit's template object
54  const CObjectEntry& GetObject() const { return *m_Object; }
55  // get unit's model data
56  CModelAbstract& GetModel() const { return *m_Model; }
57 
59 
60  /**
61  * Update the model's animation.
62  * @param frameTime time in seconds
63  */
64  void UpdateModel(float frameTime);
65 
66  // Sets the entity-selection, and updates the unit to use the new
67  // actor variation.
68  void SetEntitySelection(const CStr& selection);
69 
70  // Most units have a hopefully-unique ID number, so they can be referred to
71  // persistently despite saving/loading maps. Default for new units is -1; should
72  // usually be set to CUnitManager::GetNewID() after creation.
73  entity_id_t GetID() const { return m_ID; }
74  void SetID(entity_id_t id);
75 
76  const std::set<CStr>& GetActorSelections() const { return m_ActorSelections; }
77 
78  void SetActorSelections(const std::set<CStr>& selections);
79 
80 private:
81  // object from which unit was created; never NULL
83  // object model representation; never NULL
85 
87 
88  // unique (per map) ID number for units created in the editor, as a
89  // permanent way of referencing them.
91 
92  // seed used when creating unit
94 
95  // actor-level selections for this unit
96  std::set<CStr> m_ActorSelections;
97  // entity-level selections for this unit
98  std::set<CStr> m_EntitySelections;
99 
100  // object manager which looks after this unit's objectentry
102 
103  void ReloadObject();
104 
105  friend class CUnitAnimation;
106 };
107 
108 #endif
~CUnit()
Definition: Unit.cpp:41
void SetEntitySelection(const CStr &selection)
Definition: Unit.cpp:80
std::set< CStr > m_ActorSelections
Definition: Unit.h:96
void ReloadObject()
Definition: Unit.cpp:101
Definition: Unit.h:35
CModelAbstract & GetModel() const
Definition: Unit.h:56
uint32_t m_Seed
Definition: Unit.h:93
CUnit(CObjectEntry *object, CObjectManager &objectManager, const std::set< CStr > &actorSelections, uint32_t seed)
Definition: Unit.cpp:29
NONCOPYABLE(CUnit)
entity_id_t m_ID
Definition: Unit.h:90
CObjectManager & m_ObjectManager
Definition: Unit.h:101
void SetActorSelections(const std::set< CStr > &selections)
Definition: Unit.cpp:95
entity_id_t GetID() const
Definition: Unit.h:73
std::set< CStr > m_EntitySelections
Definition: Unit.h:98
static CUnit * Create(const CStrW &actorName, uint32_t seed, const std::set< CStr > &selections, CObjectManager &objectManager)
Definition: Unit.cpp:47
CModelAbstract * m_Model
Definition: Unit.h:84
const CObjectEntry & GetObject() const
Definition: Unit.h:54
CObjectEntry * m_Object
Definition: Unit.h:82
Abstract base class for graphical objects that are used by units, or as props attached to other CMode...
Definition: ModelAbstract.h:36
unsigned int uint32_t
Definition: wposix_types.h:53
Deals with synchronisation issues between raw animation data (CModel, CSkeletonAnim) and the simulati...
Definition: UnitAnimation.h:35
CUnitAnimation * GetAnimation()
Definition: Unit.h:58
const std::set< CStr > & GetActorSelections() const
Definition: Unit.h:76
void SetID(entity_id_t id)
Definition: Unit.cpp:73
CUnitAnimation * m_Animation
Definition: Unit.h:86
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
void UpdateModel(float frameTime)
Update the model&#39;s animation.
Definition: Unit.cpp:67