6
6
7
7
#include " components/debug/Debug.h"
8
8
9
- bool EntityDefinitionLibrary::Key::CreatureKey:: operator ==(const CreatureKey &other) const
9
+ bool CreatureEntityDefinitionKey:: operator ==(const CreatureEntityDefinitionKey &other) const
10
10
{
11
- return (this ->creatureIndex == other.creatureIndex ) &&
12
- (this ->isFinalBoss == other.isFinalBoss );
11
+ return (this ->creatureIndex == other.creatureIndex ) && (this ->isFinalBoss == other.isFinalBoss );
13
12
}
14
13
15
- void EntityDefinitionLibrary::Key::CreatureKey ::init (int creatureIndex, bool isFinalBoss)
14
+ void CreatureEntityDefinitionKey ::init (int creatureIndex, bool isFinalBoss)
16
15
{
17
16
this ->creatureIndex = creatureIndex;
18
17
this ->isFinalBoss = isFinalBoss;
@@ -29,38 +28,38 @@ void EntityDefinitionLibrary::Key::HumanEnemyKey::init(bool male, int charClassI
29
28
this->charClassID = charClassID;
30
29
}*/
31
30
32
- bool EntityDefinitionLibrary::Key::CitizenKey:: operator ==(const CitizenKey &other) const
31
+ bool CitizenEntityDefinitionKey:: operator ==(const CitizenEntityDefinitionKey &other) const
33
32
{
34
33
return (this ->male == other.male ) && (this ->climateType == other.climateType );
35
34
}
36
35
37
- void EntityDefinitionLibrary::Key::CitizenKey ::init (bool male, ArenaTypes::ClimateType climateType)
36
+ void CitizenEntityDefinitionKey ::init (bool male, ArenaTypes::ClimateType climateType)
38
37
{
39
38
this ->male = male;
40
39
this ->climateType = climateType;
41
40
}
42
41
43
- EntityDefinitionLibrary::Key::Key ()
42
+ EntityDefinitionKey::EntityDefinitionKey ()
44
43
{
45
- this ->type = static_cast <Key::Type >(-1 );
44
+ this ->type = static_cast <EntityDefinitionKeyType >(-1 );
46
45
}
47
46
48
- bool EntityDefinitionLibrary::Key:: operator ==(const Key &other) const
47
+ bool EntityDefinitionKey:: operator ==(const EntityDefinitionKey &other) const
49
48
{
50
49
if (this ->type != other.type )
51
50
{
52
51
return false ;
53
52
}
54
53
55
- if (this ->type == Key::Type ::Creature)
54
+ if (this ->type == EntityDefinitionKeyType ::Creature)
56
55
{
57
56
return this ->creature == other.creature ;
58
57
}
59
58
/* else if (this->type == Key::Type::HumanEnemy)
60
59
{
61
60
return this->humanEnemy == other.humanEnemy;
62
61
}*/
63
- else if (this ->type == Key::Type ::Citizen)
62
+ else if (this ->type == EntityDefinitionKeyType ::Citizen)
64
63
{
65
64
return this ->citizen == other.citizen ;
66
65
}
@@ -70,37 +69,14 @@ bool EntityDefinitionLibrary::Key::operator==(const Key &other) const
70
69
}
71
70
}
72
71
73
- void EntityDefinitionLibrary::Key:: init (Type type)
72
+ void EntityDefinitionKey:: init (EntityDefinitionKeyType type)
74
73
{
75
74
this ->type = type;
76
75
}
77
76
78
- EntityDefinitionLibrary::Key::Type EntityDefinitionLibrary::Key::getType () const
77
+ void EntityDefinitionKey::initCreature ( int creatureIndex, bool isFinalBoss)
79
78
{
80
- return this ->type ;
81
- }
82
-
83
- const EntityDefinitionLibrary::Key::CreatureKey &EntityDefinitionLibrary::Key::getCreature () const
84
- {
85
- DebugAssert (this ->type == Key::Type::Creature);
86
- return this ->creature ;
87
- }
88
-
89
- /* const EntityDefinitionLibrary::Key::HumanEnemyKey &EntityDefinitionLibrary::Key::getHumanEnemy() const
90
- {
91
- DebugAssert(this->type == Key::Type::HumanEnemy);
92
- return this->humanEnemy;
93
- }*/
94
-
95
- const EntityDefinitionLibrary::Key::CitizenKey &EntityDefinitionLibrary::Key::getCitizen () const
96
- {
97
- DebugAssert (this ->type == Key::Type::Citizen);
98
- return this ->citizen ;
99
- }
100
-
101
- void EntityDefinitionLibrary::Key::initCreature (int creatureIndex, bool isFinalBoss)
102
- {
103
- this ->init (Key::Type::Creature);
79
+ this ->init (EntityDefinitionKeyType::Creature);
104
80
this ->creature .init (creatureIndex, isFinalBoss);
105
81
}
106
82
@@ -110,16 +86,16 @@ void EntityDefinitionLibrary::Key::initCreature(int creatureIndex, bool isFinalB
110
86
this->humanEnemy.init(male, charClassID);
111
87
}*/
112
88
113
- void EntityDefinitionLibrary::Key ::initCitizen (bool male, ArenaTypes::ClimateType climateType)
89
+ void EntityDefinitionKey ::initCitizen (bool male, ArenaTypes::ClimateType climateType)
114
90
{
115
- this ->init (Key::Type ::Citizen);
91
+ this ->init (EntityDefinitionKeyType ::Citizen);
116
92
this ->citizen .init (male, climateType);
117
93
}
118
94
119
- EntityDefinitionLibrary::Entry::Entry (Key &&key, EntityDefinition &&def)
95
+ EntityDefinitionLibrary::Entry::Entry (EntityDefinitionKey &&key, EntityDefinition &&def)
120
96
: key(std::move(key)), def(std::move(def)) { }
121
97
122
- int EntityDefinitionLibrary::findDefIndex (const Key &key) const
98
+ int EntityDefinitionLibrary::findDefIndex (const EntityDefinitionKey &key) const
123
99
{
124
100
for (int i = 0 ; i < static_cast <int >(this ->entries .size ()); i++)
125
101
{
@@ -139,74 +115,63 @@ void EntityDefinitionLibrary::init(const ExeData &exeData, TextureManager &textu
139
115
// in advance of loading any levels, and any code that relies on those definitions can
140
116
// assume that no others are added by a level.
141
117
142
- auto addCreatureDefs = [this , &exeData, &textureManager]()
118
+ auto addCreatureDef = [this , &exeData, &textureManager](int creatureID, bool isFinalBoss )
143
119
{
144
- auto addCreatureDef = [this , &exeData, &textureManager](int creatureID, bool isFinalBoss)
120
+ EntityAnimationDefinition animDef;
121
+ if (!ArenaAnimUtils::tryMakeDynamicEntityCreatureAnims (creatureID, exeData, textureManager, &animDef))
145
122
{
146
- EntityAnimationDefinition animDef;
147
- if (!ArenaAnimUtils::tryMakeDynamicEntityCreatureAnims (creatureID, exeData, textureManager, &animDef))
148
- {
149
- DebugLogWarning (" Couldn't make creature anims for creature ID \" " +
150
- std::to_string (creatureID) + " \" ." );
151
- return ;
152
- }
153
-
154
- const int creatureIndex = ArenaAnimUtils::getCreatureIndexFromID (creatureID);
155
-
156
- Key key;
157
- key.initCreature (creatureIndex, isFinalBoss);
123
+ DebugLogWarning (" Couldn't make creature anims for creature ID \" " + std::to_string (creatureID) + " \" ." );
124
+ return ;
125
+ }
158
126
159
- EntityDefinition entityDef;
160
- entityDef.initEnemyCreature (creatureIndex, isFinalBoss, exeData, std::move (animDef));
127
+ const int creatureIndex = ArenaAnimUtils::getCreatureIndexFromID (creatureID);
161
128
162
- this -> addDefinition ( std::move (key), std::move (entityDef)) ;
163
- } ;
129
+ EntityDefinitionKey key ;
130
+ key. initCreature (creatureIndex, isFinalBoss) ;
164
131
165
- // Iterate all creatures + final boss.
166
- const int creatureCount = static_cast <int >(exeData.entities .creatureNames .size ());
167
- for (int i = 0 ; i < creatureCount; i++)
168
- {
169
- const ArenaTypes::ItemIndex itemIndex = ArenaAnimUtils::FirstCreatureItemIndex + i;
170
- const int creatureID = ArenaAnimUtils::getCreatureIDFromItemIndex (itemIndex);
171
- addCreatureDef (creatureID, false );
172
- }
132
+ EntityDefinition entityDef;
133
+ entityDef.initEnemyCreature (creatureIndex, isFinalBoss, exeData, std::move (animDef));
173
134
174
- const int finalBossID = ArenaAnimUtils::FinalBossCreatureID;
175
- addCreatureDef (finalBossID, true );
135
+ this ->addDefinition (std::move (key), std::move (entityDef));
176
136
};
177
137
178
- auto addCitizenDefs = [this , &exeData, &textureManager]()
138
+ auto addCitizenDef = [this , &exeData, &textureManager](ArenaTypes::ClimateType climateType, bool male )
179
139
{
180
- auto addCitizenDef = [this , &exeData, &textureManager](ArenaTypes::ClimateType climateType, bool male)
140
+ EntityAnimationDefinition animDef;
141
+ if (!ArenaAnimUtils::tryMakeCitizenAnims (climateType, male, exeData, textureManager, &animDef))
181
142
{
182
- EntityAnimationDefinition animDef;
183
- if (!ArenaAnimUtils::tryMakeCitizenAnims (climateType, male, exeData, textureManager, &animDef))
184
- {
185
- DebugLogWarning (" Couldn't make citizen anims for citizen \" " +
186
- std::to_string (static_cast <int >(climateType)) + " \" ." );
187
- return ;
188
- }
189
-
190
- Key key;
191
- key.initCitizen (male, climateType);
143
+ DebugLogWarning (" Couldn't make citizen anims for citizen \" " + std::to_string (static_cast <int >(climateType)) + " \" ." );
144
+ return ;
145
+ }
192
146
193
- EntityDefinition entityDef ;
194
- entityDef .initCitizen (male, climateType, std::move (animDef) );
147
+ EntityDefinitionKey key ;
148
+ key .initCitizen (male, climateType);
195
149
196
- this -> addDefinition ( std::move (key), std::move ( entityDef)) ;
197
- } ;
150
+ EntityDefinition entityDef;
151
+ entityDef. initCitizen (male, climateType, std::move (animDef)) ;
198
152
199
- // Iterate all climate type + gender combinations.
200
- for (int i = 0 ; i < ArenaClimateUtils::getClimateTypeCount (); i++)
201
- {
202
- const ArenaTypes::ClimateType climateType = ArenaClimateUtils::getClimateType (i);
203
- addCitizenDef (climateType, true );
204
- addCitizenDef (climateType, false );
205
- }
153
+ this ->addDefinition (std::move (key), std::move (entityDef));
206
154
};
207
155
208
- addCreatureDefs ();
209
- addCitizenDefs ();
156
+ // Iterate all creatures + final boss.
157
+ const int creatureCount = static_cast <int >(exeData.entities .creatureNames .size ());
158
+ for (int i = 0 ; i < creatureCount; i++)
159
+ {
160
+ const ArenaTypes::ItemIndex itemIndex = ArenaAnimUtils::FirstCreatureItemIndex + i;
161
+ const int creatureID = ArenaAnimUtils::getCreatureIDFromItemIndex (itemIndex);
162
+ addCreatureDef (creatureID, false );
163
+ }
164
+
165
+ const int finalBossID = ArenaAnimUtils::FinalBossCreatureID;
166
+ addCreatureDef (finalBossID, true );
167
+
168
+ // Iterate all climate type + gender combinations.
169
+ for (int i = 0 ; i < ArenaClimateUtils::getClimateTypeCount (); i++)
170
+ {
171
+ const ArenaTypes::ClimateType climateType = ArenaClimateUtils::getClimateType (i);
172
+ addCitizenDef (climateType, true );
173
+ addCitizenDef (climateType, false );
174
+ }
210
175
}
211
176
212
177
int EntityDefinitionLibrary::getDefinitionCount () const
@@ -220,7 +185,7 @@ const EntityDefinition &EntityDefinitionLibrary::getDefinition(EntityDefID defID
220
185
return this ->entries [defID].def ;
221
186
}
222
187
223
- bool EntityDefinitionLibrary::tryGetDefinitionID (const Key &key, EntityDefID *outDefID) const
188
+ bool EntityDefinitionLibrary::tryGetDefinitionID (const EntityDefinitionKey &key, EntityDefID *outDefID) const
224
189
{
225
190
const int index = this ->findDefIndex (key);
226
191
if (index != NO_INDEX)
@@ -234,7 +199,7 @@ bool EntityDefinitionLibrary::tryGetDefinitionID(const Key &key, EntityDefID *ou
234
199
}
235
200
}
236
201
237
- EntityDefID EntityDefinitionLibrary::addDefinition (Key &&key, EntityDefinition &&def)
202
+ EntityDefID EntityDefinitionLibrary::addDefinition (EntityDefinitionKey &&key, EntityDefinition &&def)
238
203
{
239
204
EntityDefID existingDefID;
240
205
if (this ->tryGetDefinitionID (key, &existingDefID))
0 commit comments