Implement builder road construction with hex-edge auto-connection, winding rendering, and speed bonus
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
#include "roadconfig.h"
|
||||
#include "yamlparser.h"
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
|
||||
RoadConfigManager::RoadConfigManager()
|
||||
: m_defaultRoadType("dirt"),
|
||||
m_buildDurationTicks(2),
|
||||
m_meanderAmplitude(0.045f),
|
||||
m_meanderSubdivisions(5)
|
||||
{
|
||||
// Provide built-in defaults
|
||||
RoadTypeConfig dirt;
|
||||
dirt.id = "dirt";
|
||||
dirt.name = "Dirt Road";
|
||||
dirt.speedMultiplier = 1.30f;
|
||||
dirt.colorStr = "#c49a62";
|
||||
dirt.borderColorStr = "#6b4b23";
|
||||
dirt.width = 3.5f;
|
||||
dirt.cost = 5;
|
||||
m_types["dirt"] = dirt;
|
||||
|
||||
RoadTypeConfig stone;
|
||||
stone.id = "stone";
|
||||
stone.name = "Stone Road";
|
||||
stone.speedMultiplier = 1.60f;
|
||||
stone.colorStr = "#9aa1a8";
|
||||
stone.borderColorStr = "#464b50";
|
||||
stone.width = 4.0f;
|
||||
stone.cost = 15;
|
||||
m_types["stone"] = stone;
|
||||
|
||||
RoadTypeConfig rail;
|
||||
rail.id = "rail";
|
||||
rail.name = "Railroad";
|
||||
rail.speedMultiplier = 2.50f;
|
||||
rail.colorStr = "#3a3c40";
|
||||
rail.borderColorStr = "#181a1c";
|
||||
rail.width = 4.5f;
|
||||
rail.cost = 30;
|
||||
m_types["rail"] = rail;
|
||||
}
|
||||
|
||||
bool RoadConfigManager::loadConfigFile(const QString &filePath)
|
||||
{
|
||||
YamlNode root = YamlParser::parseFile(filePath);
|
||||
if (root.children.isEmpty()) {
|
||||
qWarning() << "Failed to parse roads config YAML, using defaults:" << filePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (root.hasChild("default_road_type")) {
|
||||
m_defaultRoadType = root["default_road_type"].asString("dirt");
|
||||
}
|
||||
if (root.hasChild("build_duration_ticks")) {
|
||||
m_buildDurationTicks = root["build_duration_ticks"].asInt(2);
|
||||
}
|
||||
if (root.hasChild("meander_amplitude")) {
|
||||
m_meanderAmplitude = root["meander_amplitude"].asFloat(0.045f);
|
||||
}
|
||||
if (root.hasChild("meander_subdivisions")) {
|
||||
m_meanderSubdivisions = root["meander_subdivisions"].asInt(5);
|
||||
}
|
||||
|
||||
if (root.hasChild("types")) {
|
||||
const YamlNode &typesNode = root["types"];
|
||||
for (auto it = typesNode.children.begin(); it != typesNode.children.end(); ++it) {
|
||||
RoadTypeConfig rCfg;
|
||||
rCfg.id = it.value().hasChild("id") ? it.value()["id"].asString() : it.key();
|
||||
rCfg.name = it.value().hasChild("name") ? it.value()["name"].asString() : rCfg.id;
|
||||
rCfg.speedMultiplier = it.value().hasChild("speed_multiplier") ? it.value()["speed_multiplier"].asFloat(1.30f) : 1.30f;
|
||||
rCfg.colorStr = it.value().hasChild("color") ? it.value()["color"].asString("#c49a62") : "#c49a62";
|
||||
rCfg.borderColorStr = it.value().hasChild("border_color") ? it.value()["border_color"].asString("#6b4b23") : "#6b4b23";
|
||||
rCfg.width = it.value().hasChild("width") ? it.value()["width"].asFloat(3.5f) : 3.5f;
|
||||
rCfg.cost = it.value().hasChild("cost") ? it.value()["cost"].asInt(5) : 5;
|
||||
m_types[rCfg.id] = rCfg;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const RoadTypeConfig* RoadConfigManager::getRoadType(const QString &id) const
|
||||
{
|
||||
auto it = m_types.find(id);
|
||||
if (it != m_types.end()) {
|
||||
return &it.value();
|
||||
}
|
||||
auto defIt = m_types.find(m_defaultRoadType);
|
||||
if (defIt != m_types.end()) {
|
||||
return &defIt.value();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user