Refactor farm building speed to builder unit action_speeds and enable infinite charges

This commit is contained in:
bart
2026-11-08 17:01:26 +01:00
parent 55e4276025
commit 17901ce25c
10 changed files with 847 additions and 121 deletions
+26
View File
@@ -44,8 +44,23 @@ bool UnitConfigManager::loadConfigFile(const QString &filePath)
cfg.cost = root.hasChild("cost") ? root["cost"].asInt(20) : 20;
cfg.attackDamage = root.hasChild("attack_damage") ? root["attack_damage"].asInt(0) : 0;
cfg.attackRange = root.hasChild("attack_range") ? root["attack_range"].asInt(1) : 1;
cfg.buildCharges = root.hasChild("build_charges") ? root["build_charges"].asInt(-1) : -1;
cfg.infiniteCharges = root.hasChild("infinite_charges") ? root["infinite_charges"].asBool(cfg.buildCharges < 0) : (cfg.buildCharges < 0);
cfg.iconPath = root.hasChild("icon") ? root["icon"].asString() : "";
if (root.hasChild("domain")) {
cfg.movementDomain = stringToMovementDomain(root["domain"].asString());
} else if (root.hasChild("movement_domain")) {
cfg.movementDomain = stringToMovementDomain(root["movement_domain"].asString());
}
if (root.hasChild("impassable_terrains")) {
cfg.impassableTerrains = root["impassable_terrains"].listValues;
}
if (root.hasChild("passable_terrains")) {
cfg.passableTerrains = root["passable_terrains"].listValues;
}
if (root.hasChild("actions")) {
cfg.actions = root["actions"].listValues;
}
@@ -54,6 +69,17 @@ bool UnitConfigManager::loadConfigFile(const QString &filePath)
cfg.actions.prepend("verplaatsen");
}
auto parseActionMap = [&](const QString &key) {
if (root.hasChild(key)) {
const YamlNode &sNode = root[key];
for (auto it = sNode.children.begin(); it != sNode.children.end(); ++it) {
cfg.actionSpeeds[it.key()] = it.value().asFloat(10.0f);
}
}
};
parseActionMap("action_speeds");
parseActionMap("action_durations");
m_configs[cfg.id] = cfg;
return true;
}