Refactor farm building speed to builder unit action_speeds and enable infinite charges
This commit is contained in:
+67
-36
@@ -1,4 +1,5 @@
|
||||
#include "terrainyieldmanager.h"
|
||||
#include "terrainmovementmanager.h"
|
||||
#include "yamlparser.h"
|
||||
#include "pathfinder.h"
|
||||
#include <QDebug>
|
||||
@@ -17,6 +18,9 @@ TerrainYieldManager::TerrainYieldManager()
|
||||
|
||||
bool TerrainYieldManager::loadConfigs(const QString &baseDir)
|
||||
{
|
||||
// 0. Load terrain_movement.yaml
|
||||
TerrainMovementManager::instance().loadConfig(baseDir + "/config/terrain_movement.yaml");
|
||||
|
||||
// 1. Load city.yaml
|
||||
QString cityFile = baseDir + "/config/city.yaml";
|
||||
YamlNode cityRoot = YamlParser::parseFile(cityFile);
|
||||
@@ -26,6 +30,25 @@ bool TerrainYieldManager::loadConfigs(const QString &baseDir)
|
||||
m_cityConfig.initialBorderRadius = cityRoot["initial_border_radius"].asInt(1);
|
||||
m_cityConfig.maxWorkableRadius = cityRoot["max_workable_radius"].asInt(3);
|
||||
m_cityConfig.defaultTileSlots = cityRoot["default_tile_slots"].asInt(1);
|
||||
m_cityConfig.cityViewZoom = cityRoot["city_view_zoom"].asFloat(4.8f);
|
||||
|
||||
m_cityConfig.baseResourceYieldPerTick = cityRoot["base_resource_yield_per_tick"].asInt(500);
|
||||
m_cityConfig.tileCultureCost = cityRoot["tile_culture_cost"].asInt(10000);
|
||||
m_cityConfig.foodToInhabitantsRatio = cityRoot["food_to_inhabitants_ratio"].asFloat(1.0f);
|
||||
|
||||
if (cityRoot.hasChild("base_yields")) {
|
||||
const YamlNode &bNode = cityRoot["base_yields"];
|
||||
for (auto it = bNode.children.begin(); it != bNode.children.end(); ++it) {
|
||||
m_cityConfig.baseYields[it.key()] = it.value().asInt(m_cityConfig.baseResourceYieldPerTick);
|
||||
}
|
||||
}
|
||||
|
||||
if (cityRoot.hasChild("initial_national_resources")) {
|
||||
const YamlNode &rNode = cityRoot["initial_national_resources"];
|
||||
for (auto it = rNode.children.begin(); it != rNode.children.end(); ++it) {
|
||||
m_cityConfig.initialNationalResources[it.key()] = it.value().asInt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Load terrain_yields.yaml
|
||||
@@ -53,48 +76,46 @@ bool TerrainYieldManager::loadConfigs(const QString &baseDir)
|
||||
m_yieldConfigs[typeKey] = cfg;
|
||||
}
|
||||
|
||||
// 3. Load improvements.yaml
|
||||
QString impFile = baseDir + "/config/improvements.yaml";
|
||||
YamlNode impRoot = YamlParser::parseFile(impFile);
|
||||
for (auto it = impRoot.children.begin(); it != impRoot.children.end(); ++it) {
|
||||
QString impKey = it.key();
|
||||
const YamlNode &node = it.value();
|
||||
|
||||
ImprovementConfig cfg;
|
||||
cfg.id = node.hasChild("id") ? node["id"].asString() : impKey;
|
||||
cfg.name = node.hasChild("name") ? node["name"].asString() : cfg.id;
|
||||
cfg.action = node.hasChild("action") ? node["action"].asString() : "boerderij_bouwen";
|
||||
cfg.texturePath = node.hasChild("texture") ? node["texture"].asString() : "images/farm.jpeg";
|
||||
cfg.textureScale = node.hasChild("texture_scale") ? node["texture_scale"].asFloat(0.6f) : 0.6f;
|
||||
cfg.textureMapping = node.hasChild("texture_mapping") ? node["texture_mapping"].asString("world") : "world";
|
||||
|
||||
if (node.hasChild("valid_terrains")) {
|
||||
cfg.validTerrains = node["valid_terrains"].listValues;
|
||||
} else {
|
||||
cfg.validTerrains = QStringList{"grasland", "tundra"};
|
||||
}
|
||||
|
||||
if (node.hasChild("yield_bonus")) {
|
||||
const YamlNode &ybNode = node["yield_bonus"];
|
||||
for (auto ybIt = ybNode.children.begin(); ybIt != ybNode.children.end(); ++ybIt) {
|
||||
cfg.yieldBonus[ybIt.key()] = ybIt.value().asInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
m_improvementConfigs[impKey] = cfg;
|
||||
}
|
||||
|
||||
m_loaded = true;
|
||||
qDebug() << "TerrainYieldManager loaded" << m_yieldConfigs.size() << "terrain types and city config.";
|
||||
qDebug() << "TerrainYieldManager loaded" << m_yieldConfigs.size() << "terrain types,"
|
||||
<< m_improvementConfigs.size() << "improvements, and city config.";
|
||||
return true;
|
||||
}
|
||||
|
||||
QString TerrainYieldManager::getTerrainType(int tx, int ty, Matrix2D<TerrainPoint> *mapPoints, int numPoints05) const
|
||||
{
|
||||
if (!mapPoints || numPoints05 <= 0) return "grasland";
|
||||
|
||||
QVector2D w = Pathfinder::hexToWorld(tx, ty);
|
||||
float scaleX = numPoints05 * 2.0f;
|
||||
float scaleY = numPoints05 / LOD_0_SIZE_Y;
|
||||
|
||||
int mapX = (int) std::round(w.x() * scaleX);
|
||||
int mapY = (int) std::round(w.y() * scaleY);
|
||||
|
||||
if (mapX < 0) mapX = 0;
|
||||
if (mapX >= (int)mapPoints->getWidth()) mapX = (int)mapPoints->getWidth() - 1;
|
||||
if (mapY < 0) mapY = 0;
|
||||
if (mapY >= (int)mapPoints->getHeight()) mapY = (int)mapPoints->getHeight() - 1;
|
||||
|
||||
TerrainPoint tp = mapPoints->operator()(mapX, mapY);
|
||||
|
||||
// Sea level water
|
||||
if (tp.height < 6) return "water";
|
||||
|
||||
float heightKm = (tp.height / 255.0f) * 3.5f + 1.0f;
|
||||
|
||||
// High peaks have snow
|
||||
if (heightKm >= 3.1f) return "sneeuw";
|
||||
|
||||
// Mountain rock
|
||||
if (heightKm >= 2.3f) return "steen";
|
||||
|
||||
switch (tp.type) {
|
||||
case 0: return "grasland";
|
||||
case 1: return "sahara";
|
||||
case 2: return "tundra";
|
||||
case 3: return "red_canyon";
|
||||
case 4: return "bos";
|
||||
default: return "grasland";
|
||||
}
|
||||
return TerrainMovementManager::instance().getTerrainType(tx, ty, mapPoints, numPoints05);
|
||||
}
|
||||
|
||||
const TerrainYieldConfig* TerrainYieldManager::getYieldConfig(const QString &terrainType) const
|
||||
@@ -105,3 +126,13 @@ const TerrainYieldConfig* TerrainYieldManager::getYieldConfig(const QString &ter
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const ImprovementConfig* TerrainYieldManager::getImprovementConfig(const QString &id) const
|
||||
{
|
||||
auto it = m_improvementConfigs.find(id);
|
||||
if (it != m_improvementConfigs.end()) {
|
||||
return &it.value();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user