forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuleSoldier.cpp
More file actions
269 lines (244 loc) · 6.07 KB
/
Copy pathRuleSoldier.cpp
File metadata and controls
269 lines (244 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
* Copyright 2010-2016 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RuleSoldier.h"
#include "Mod.h"
#include "SoldierNamePool.h"
#include "../Engine/FileMap.h"
namespace OpenXcom
{
/**
* Creates a blank ruleunit for a certain
* type of soldier.
* @param type String defining the type.
*/
RuleSoldier::RuleSoldier(const std::string &type) : _type(type), _costBuy(0), _costSalary(0), _standHeight(0), _kneelHeight(0), _floatHeight(0), _femaleFrequency(50), _value(20), _transferTime(0)
{
}
/**
*
*/
RuleSoldier::~RuleSoldier()
{
for (std::vector<SoldierNamePool*>::iterator i = _names.begin(); i != _names.end(); ++i)
{
delete *i;
}
}
/**
* Loads the soldier from a YAML file.
* @param node YAML node.
* @param mod Mod for the unit.
*/
void RuleSoldier::load(const YAML::Node &node, Mod *mod)
{
_type = node["type"].as<std::string>(_type);
// Just in case
if (_type == "XCOM")
_type = "STR_SOLDIER";
_requires = node["requires"].as< std::vector<std::string> >(_requires);
_minStats.merge(node["minStats"].as<UnitStats>(_minStats));
_maxStats.merge(node["maxStats"].as<UnitStats>(_maxStats));
_statCaps.merge(node["statCaps"].as<UnitStats>(_statCaps));
_armor = node["armor"].as<std::string>(_armor);
_costBuy = node["costBuy"].as<int>(_costBuy);
_costSalary = node["costSalary"].as<int>(_costSalary);
_standHeight = node["standHeight"].as<int>(_standHeight);
_kneelHeight = node["kneelHeight"].as<int>(_kneelHeight);
_floatHeight = node["floatHeight"].as<int>(_floatHeight);
_femaleFrequency = node["femaleFrequency"].as<int>(_femaleFrequency);
_value = node["value"].as<int>(_value);
_transferTime = node["transferTime"].as<int>(_transferTime);
mod->loadSoundOffset(_type, _deathSoundMale, node["deathMale"], "BATTLE.CAT");
mod->loadSoundOffset(_type, _deathSoundFemale, node["deathFemale"], "BATTLE.CAT");
for (YAML::const_iterator i = node["soldierNames"].begin(); i != node["soldierNames"].end(); ++i)
{
std::string fileName = (*i).as<std::string>();
if (fileName == "delete")
{
for (std::vector<SoldierNamePool*>::iterator j = _names.begin(); j != _names.end(); ++j)
{
delete *j;
}
_names.clear();
}
else
{
if (fileName[fileName.length() - 1] == '/')
{
// load all *.nam files in given directory
std::set<std::string> names = FileMap::filterFiles(FileMap::getVFolderContents(fileName), "nam");
for (std::set<std::string>::iterator j = names.begin(); j != names.end(); ++j)
{
addSoldierNamePool(fileName + *j);
}
}
else
{
// load given file
addSoldierNamePool(fileName);
}
}
}
}
void RuleSoldier::addSoldierNamePool(const std::string &namFile)
{
SoldierNamePool *pool = new SoldierNamePool();
pool->load(FileMap::getFilePath(namFile));
_names.push_back(pool);
}
/**
* Returns the language string that names
* this soldier. Each soldier type has a unique name.
* @return Soldier name.
*/
std::string RuleSoldier::getType() const
{
return _type;
}
/**
* Gets the list of research required to
* acquire this soldier.
* @return The list of research IDs.
*/
const std::vector<std::string> &RuleSoldier::getRequirements() const
{
return _requires;
}
/**
* Gets the minimum stats for the random stats generator.
* @return The minimum stats.
*/
UnitStats RuleSoldier::getMinStats() const
{
return _minStats;
}
/**
* Gets the maximum stats for the random stats generator.
* @return The maximum stats.
*/
UnitStats RuleSoldier::getMaxStats() const
{
return _maxStats;
}
/**
* Gets the stat caps.
* @return The stat caps.
*/
UnitStats RuleSoldier::getStatCaps() const
{
return _statCaps;
}
/**
* Gets the cost of hiring this soldier.
* @return The cost.
*/
int RuleSoldier::getBuyCost() const
{
return _costBuy;
}
/**
* Gets the cost of salary for a month.
* @return The cost.
*/
int RuleSoldier::getSalaryCost() const
{
return _costSalary;
}
/**
* Gets the height of the soldier when it's standing.
* @return The standing height.
*/
int RuleSoldier::getStandHeight() const
{
return _standHeight;
}
/**
* Gets the height of the soldier when it's kneeling.
* @return The kneeling height.
*/
int RuleSoldier::getKneelHeight() const
{
return _kneelHeight;
}
/**
* Gets the elevation of the soldier when it's flying.
* @return The floating height.
*/
int RuleSoldier::getFloatHeight() const
{
return _floatHeight;
}
/**
* Gets the default armor name.
* @return The armor name.
*/
std::string RuleSoldier::getArmor() const
{
return _armor;
}
/**
* Gets the female appearance ratio.
* @return The percentage ratio.
*/
int RuleSoldier::getFemaleFrequency() const
{
return _femaleFrequency;
}
/**
* Gets the death sounds for male soldiers.
* @return List of sound IDs.
*/
const std::vector<int> &RuleSoldier::getMaleDeathSounds() const
{
return _deathSoundMale;
}
/**
* Gets the death sounds for female soldiers.
* @return List of sound IDs.
*/
const std::vector<int> &RuleSoldier::getFemaleDeathSounds() const
{
return _deathSoundFemale;
}
/**
* Returns the list of soldier name pools.
* @return Pointer to soldier name pool list.
*/
const std::vector<SoldierNamePool*> &RuleSoldier::getNames() const
{
return _names;
}
/**
* Gets the soldier's base value, without experience modifiers.
* @return The soldier's value.
*/
int RuleSoldier::getValue() const
{
return _value;
}
/**
* Gets the amount of time this item
* takes to arrive at a base.
* @return The time in hours.
*/
int RuleSoldier::getTransferTime() const
{
return _transferTime;
}
}