Pyrogenesis  trunk
Unit.h
Go to the documentation of this file.
1 /* Copyright (C) 2016 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 <map>
22 #include <set>
23 
24 #include "ps/CStr.h"
25 #include "simulation2/system/Entity.h" // entity_id_t
26 
27 class CModelAbstract;
28 class CObjectEntry;
29 class CObjectManager;
30 class CSkeletonAnim;
31 class CUnitAnimation;
32 
33 
34 /////////////////////////////////////////////////////////////////////////////////////////////
35 // CUnit: simple "actor" definition - defines a sole object within the world
36 class CUnit
37 {
39 private:
40  // Private constructor. Needs complete list of selections for the variation.
41  CUnit(CObjectEntry* object, CObjectManager& objectManager,
42  const std::set<CStr>& actorSelections, uint32_t seed);
43 
44 public:
45  // Attempt to create a unit with the given actor, with a set of
46  // suggested selections (with the rest being randomised using the
47  // given random seed).
48  // Returns NULL on failure.
49  static CUnit* Create(const CStrW& actorName, uint32_t seed, const std::set<CStr>& selections, CObjectManager& objectManager);
50 
51  // destructor
52  ~CUnit();
53 
54  // get unit's template object
55  const CObjectEntry& GetObject() const { return *m_Object; }
56  // get unit's model data
57  CModelAbstract& GetModel() const { return *m_Model; }
58 
60 
61  /**
62  * Update the model's animation.
63  * @param frameTime time in seconds
64  */
65  void UpdateModel(float frameTime);
66 
67  // Sets the entity-selection, and updates the unit to use the new
68  // actor variation. Either set one key at a time, or a complete map.
69  void SetEntitySelection(const CStr& key, const CStr& selection);
70  void SetEntitySelection(const std::map<CStr, CStr>& selections);
71 
72  // Most units have a hopefully-unique ID number, so they can be referred to
73  // persistently despite saving/loading maps. Default for new units is -1; should
74  // usually be set to CUnitManager::GetNewID() after creation.
75  entity_id_t GetID() const { return m_ID; }
76  void SetID(entity_id_t id);
77 
78  const std::set<CStr>& GetActorSelections() const { return m_ActorSelections; }
79 
80  void SetActorSelections(const std::set<CStr>& selections);
81 
82 private:
83  // object from which unit was created; never NULL
85  // object model representation; never NULL
87 
89 
90  // unique (per map) ID number for units created in the editor, as a
91  // permanent way of referencing them.
93 
94  // seed used when creating unit
96 
97  // actor-level selections for this unit
98  std::set<CStr> m_ActorSelections;
99  // entity-level selections for this unit
100  std::map<CStr, CStr> m_EntitySelections;
101 
102  // object manager which looks after this unit's objectentry
104 
105  void ReloadObject();
106 
107  friend class CUnitAnimation;
108 };
109 
110 #endif
~CUnit()
Definition: Unit.cpp:41
std::set< CStr > m_ActorSelections
Definition: Unit.h:98
void ReloadObject()
Definition: Unit.cpp:105
std::map< CStr, CStr > m_EntitySelections
Definition: Unit.h:100
Definition: ObjectManager.h:37
Definition: Unit.h:36
CModelAbstract & GetModel() const
Definition: Unit.h:57
uint32_t m_Seed
Definition: Unit.h:95
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:92
CObjectManager & m_ObjectManager
Definition: Unit.h:103
void SetActorSelections(const std::set< CStr > &selections)
Definition: Unit.cpp:99
pthread_key_t key
Definition: wpthread.cpp:140
entity_id_t GetID() const
Definition: Unit.h:75
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:86
const CObjectEntry & GetObject() const
Definition: Unit.h:55
CObjectEntry * m_Object
Definition: Unit.h:84
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
void SetEntitySelection(const CStr &key, const CStr &selection)
Definition: Unit.cpp:80
CUnitAnimation * GetAnimation()
Definition: Unit.h:59
const std::set< CStr > & GetActorSelections() const
Definition: Unit.h:78
void SetID(entity_id_t id)
Definition: Unit.cpp:73
CUnitAnimation * m_Animation
Definition: Unit.h:88
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
void UpdateModel(float frameTime)
Update the model&#39;s animation.
Definition: Unit.cpp:67
Definition: ObjectEntry.h:38
Definition: SkeletonAnim.h:32