Skip to content

Commit 567fa48

Browse files
committed
Merge pull request OpenXcom#1020 from myk002/soldier_name_rules
Read soldier name files from ruleset
2 parents 52dbe0d + 006cc8b commit 567fa48

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# pull in all *.nam files in the SoldierName virtual directory by default
2+
# mods can override with specific files if desired
3+
soldierNames:
4+
- SoldierName/

src/Engine/Options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ void mapResources()
727727
_loadMod(modInfo, circDepCheck);
728728
}
729729
// pick up stuff in common
730-
FileMap::load("", CrossPlatform::searchDataFolder("common"), true);
730+
FileMap::load("common", CrossPlatform::searchDataFolder("common"), false);
731731
}
732732

733733
/**

src/Ruleset/Ruleset.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ void Ruleset::resetGlobalStatics()
136136
Ruleset::Ruleset() : _costSoldier(0), _costEngineer(0), _costScientist(0), _timePersonnel(0), _initialFunding(0), _turnAIUseGrenade(3), _turnAIUseBlaster(3), _startingTime(6, 1, 1, 1999, 12, 0, 0), _facilityListOrder(0), _craftListOrder(0), _itemListOrder(0), _researchListOrder(0), _manufactureListOrder(0), _ufopaediaListOrder(0), _invListOrder(0)
137137
{
138138
_globe = new RuleGlobe();
139-
140-
std::set<std::string> names = FileMap::filterFiles(FileMap::getVFolderContents("SoldierName"), "nam");
141-
for (std::set<std::string>::iterator i = names.begin(); i != names.end(); ++i)
142-
{
143-
SoldierNamePool *pool = new SoldierNamePool();
144-
pool->load(FileMap::getFilePath("SoldierName/" + *i));
145-
_names.push_back(pool);
146-
}
147139
}
148140

149141
/**
@@ -378,6 +370,7 @@ void Ruleset::loadFile(const std::string &filename, size_t spriteOffset)
378370
rule->load(*i);
379371
}
380372
}
373+
_soldierNames = doc["soldierNames"].as<std::vector<std::string> >(_soldierNames);
381374
for (YAML::const_iterator i = doc["soldiers"].begin(); i != doc["soldiers"].end(); ++i)
382375
{
383376
RuleSoldier *rule = loadRule(*i, &_soldiers);
@@ -1502,6 +1495,13 @@ struct compareRule<ArticleDefinition> : public std::binary_function<const std::s
15021495
};
15031496
std::map<std::string, int> compareRule<ArticleDefinition>::_sections;
15041497

1498+
static void addSoldierNamePool(std::vector<SoldierNamePool*> &names, const std::string &namFile)
1499+
{
1500+
SoldierNamePool *pool = new SoldierNamePool();
1501+
pool->load(FileMap::getFilePath(namFile));
1502+
names.push_back(pool);
1503+
}
1504+
15051505
/**
15061506
* Sorts all our lists according to their weight.
15071507
*/
@@ -1517,6 +1517,24 @@ void Ruleset::sortLists()
15171517
std::sort(_craftWeaponsIndex.begin(), _craftWeaponsIndex.end(), compareRule<RuleCraftWeapon>(this));
15181518
std::sort(_armorsIndex.begin(), _armorsIndex.end(), compareRule<Armor>(this));
15191519
std::sort(_ufopaediaIndex.begin(), _ufopaediaIndex.end(), compareRule<ArticleDefinition>(this));
1520+
1521+
for (std::vector<std::string>::iterator i = _soldierNames.begin(); i != _soldierNames.end(); ++i)
1522+
{
1523+
if (i->substr(i->length() - 1, 1) == "/")
1524+
{
1525+
// load all *.nam files in given directory
1526+
std::set<std::string> names = FileMap::filterFiles(FileMap::getVFolderContents(*i), "nam");
1527+
for (std::set<std::string>::iterator j = names.begin(); j != names.end(); ++j)
1528+
{
1529+
addSoldierNamePool(_names, *i + *j);
1530+
}
1531+
}
1532+
else
1533+
{
1534+
// load given file
1535+
addSoldierNamePool(_names, *i);
1536+
}
1537+
}
15201538
}
15211539

15221540
/**

src/Ruleset/Ruleset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class RuleMusic;
7676
class Ruleset
7777
{
7878
protected:
79+
std::vector<std::string> _soldierNames;
7980
std::vector<SoldierNamePool*> _names;
8081
std::map<std::string, RuleCountry*> _countries;
8182
std::map<std::string, RuleRegion*> _regions;

0 commit comments

Comments
 (0)