mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Place proper towns in underground (#743)
Implement feature of proper town selection in underground and surface * Some minor refactoring of rmg
This commit is contained in:
@@ -17,11 +17,6 @@
|
||||
|
||||
using namespace rmg;
|
||||
|
||||
const std::map<std::string, CRmgTemplate *> & CRmgTemplateStorage::getTemplates() const
|
||||
{
|
||||
return templates;
|
||||
}
|
||||
|
||||
void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||
{
|
||||
//unused
|
||||
@@ -30,31 +25,20 @@ void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const
|
||||
|
||||
void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||
{
|
||||
auto tpl = new CRmgTemplate();
|
||||
try
|
||||
{
|
||||
JsonDeserializer handler(nullptr, data);
|
||||
auto fullKey = normalizeIdentifier(scope, "core", name);
|
||||
tpl->setId(name);
|
||||
tpl->serializeJson(handler);
|
||||
tpl->validate();
|
||||
templates[fullKey] = tpl;
|
||||
auto fullKey = normalizeIdentifier(scope, "core", name); //actually it's not used
|
||||
templates[fullKey].setId(name);
|
||||
templates[fullKey].serializeJson(handler);
|
||||
templates[fullKey].validate();
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
logGlobal->error("Template %s has errors. Message: %s.", tpl->getName(), std::string(e.what()));
|
||||
logGlobal->error("Template %s has errors. Message: %s.", name, std::string(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
CRmgTemplateStorage::CRmgTemplateStorage()
|
||||
{
|
||||
}
|
||||
|
||||
CRmgTemplateStorage::~CRmgTemplateStorage()
|
||||
{
|
||||
for (auto & pair : templates) delete pair.second;
|
||||
}
|
||||
|
||||
std::vector<bool> CRmgTemplateStorage::getDefaultAllowed() const
|
||||
{
|
||||
//all templates are allowed
|
||||
@@ -66,3 +50,54 @@ std::vector<JsonNode> CRmgTemplateStorage::loadLegacyData(size_t dataSize)
|
||||
return std::vector<JsonNode>();
|
||||
//it would be cool to load old rmg.txt files
|
||||
}
|
||||
|
||||
const CRmgTemplate * CRmgTemplateStorage::getTemplate(const std::string & templateName) const
|
||||
{
|
||||
auto iter = templates.find(templateName);
|
||||
if(iter==templates.end())
|
||||
return nullptr;
|
||||
return &iter->second;
|
||||
}
|
||||
|
||||
std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates() const
|
||||
{
|
||||
std::vector<const CRmgTemplate *> result;
|
||||
for(auto i=templates.cbegin(); i!=templates.cend(); ++i)
|
||||
{
|
||||
result.push_back(&i->second);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates(const int3& filterSize, si8 filterPlayers, si8 filterHumanPlayers, si8 filterCpuPlayers) const
|
||||
{
|
||||
std::vector<const CRmgTemplate *> result;
|
||||
for(auto i=templates.cbegin(); i!=templates.cend(); ++i)
|
||||
{
|
||||
auto& tmpl = i->second;
|
||||
|
||||
if (!tmpl.matchesSize(filterSize))
|
||||
continue;
|
||||
|
||||
if (filterPlayers != -1)
|
||||
{
|
||||
if (!tmpl.getPlayers().isInRange(filterPlayers))
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Human players shouldn't be banned when playing with random player count
|
||||
if (filterHumanPlayers > *boost::min_element(tmpl.getPlayers().getNumbers()))
|
||||
continue;
|
||||
}
|
||||
|
||||
if(filterCpuPlayers != -1)
|
||||
{
|
||||
if (!tmpl.getCpuPlayers().isInRange(filterCpuPlayers))
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push_back(&i->second);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user