From 774f5dee2832fe2562d1f4f228ec541219476c24 Mon Sep 17 00:00:00 2001 From: Malte Langkabel Date: Sun, 26 Apr 2026 20:41:40 +0200 Subject: [PATCH] read tunnel length from different config and fix tests --- bin/config/buildings.toml | 1 - bin/config/world.toml | 1 + src/lib/config/BuildingsConfig.h | 2 -- src/lib/config/ConfigLoader.cpp | 6 +----- src/lib/config/WorldConfig.h | 1 + src/lib/sim/BuildingSystem.cpp | 4 +--- src/test/ConfigLoaderTest.cpp | 3 +++ src/test/config/buildings.toml | 14 ++++++++++++++ src/test/config/world.toml | 1 + 9 files changed, 22 insertions(+), 11 deletions(-) diff --git a/bin/config/buildings.toml b/bin/config/buildings.toml index ab37609..1be0426 100644 --- a/bin/config/buildings.toml +++ b/bin/config/buildings.toml @@ -18,7 +18,6 @@ cost = 5 player_placeable = true construction_time_seconds = 3 surface_mask = ["A>"] -tunnel_max_distance = 10 [[building]] id = "tunnel_exit" diff --git a/bin/config/world.toml b/bin/config/world.toml index cca5c77..67d2ac9 100644 --- a/bin/config/world.toml +++ b/bin/config/world.toml @@ -4,6 +4,7 @@ refund_percentage = 75 starting_building_blocks = 100 scrap_despawn_seconds = 30 belt_speed_tiles_per_second = 2 +tunnel_max_distance = 10 [regions] asteroid_width = 40 diff --git a/src/lib/config/BuildingsConfig.h b/src/lib/config/BuildingsConfig.h index 32ea72e..c6fac17 100644 --- a/src/lib/config/BuildingsConfig.h +++ b/src/lib/config/BuildingsConfig.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -19,7 +18,6 @@ struct BuildingDef // Stored as raw strings here; parsing into per-cell tiles + output ports // happens when buildings are placed, not at load time. std::vector surfaceMask; - std::optional tunnelMaxDistance; }; struct BuildingsConfig diff --git a/src/lib/config/ConfigLoader.cpp b/src/lib/config/ConfigLoader.cpp index 366b3dd..e771119 100644 --- a/src/lib/config/ConfigLoader.cpp +++ b/src/lib/config/ConfigLoader.cpp @@ -224,6 +224,7 @@ WorldConfig ConfigLoader::loadWorld(const std::string& path) cfg.startingBuildingBlocks = static_cast(requireInt(tbl["world"]["starting_building_blocks"], file, "world.starting_building_blocks")); cfg.scrapDespawnSeconds = requireDouble(tbl["world"]["scrap_despawn_seconds"], file, "world.scrap_despawn_seconds"); cfg.beltSpeedTilesPerSecond = requireDouble(tbl["world"]["belt_speed_tiles_per_second"], file, "world.belt_speed_tiles_per_second"); + cfg.tunnelMaxDistance = static_cast(requireInt(tbl["world"]["tunnel_max_distance"], file, "world.tunnel_max_distance")); cfg.regions.asteroidWidth = static_cast(requireInt(tbl["regions"]["asteroid_width"], file, "regions.asteroid_width")); cfg.regions.playerBufferWidth = static_cast(requireInt(tbl["regions"]["player_buffer_width"], file, "regions.player_buffer_width")); @@ -275,11 +276,6 @@ BuildingsConfig ConfigLoader::loadBuildings(const std::string& path) def.constructionTimeSeconds = requireDouble(mt["construction_time_seconds"], file, elemPath + ".construction_time_seconds"); def.surfaceMask = requireStringArray(mt["surface_mask"], file, elemPath + ".surface_mask"); - if (const std::optional tmd = mt["tunnel_max_distance"].value()) - { - def.tunnelMaxDistance = static_cast(*tmd); - } - const std::optional parsedType = parseBuildingType(def.id); if (!parsedType) { diff --git a/src/lib/config/WorldConfig.h b/src/lib/config/WorldConfig.h index 9280858..4eccc6b 100644 --- a/src/lib/config/WorldConfig.h +++ b/src/lib/config/WorldConfig.h @@ -42,6 +42,7 @@ struct WorldConfig int startingBuildingBlocks; // REQ-HQ-STARTING-BLOCKS double scrapDespawnSeconds; // REQ-RES-SCRAP-DROP double beltSpeedTilesPerSecond; // REQ-GW-BELT-SPEED + int tunnelMaxDistance; // REQ-BLD-TUNNEL-PAIR WorldRegions regions; WorldExpansion expansion; diff --git a/src/lib/sim/BuildingSystem.cpp b/src/lib/sim/BuildingSystem.cpp index c25fc9b..3304261 100644 --- a/src/lib/sim/BuildingSystem.cpp +++ b/src/lib/sim/BuildingSystem.cpp @@ -427,9 +427,7 @@ void BuildingSystem::tickConstruction(Tick currentTick) } else if (front.type == BuildingType::TunnelEntry) { - const BuildingDef* bdef = findBuildingDef(front.type); - const int maxDist = (bdef && bdef->tunnelMaxDistance) ? *bdef->tunnelMaxDistance : 0; - m_belts.placeTunnelEntry(front.anchor, front.rotation, maxDist); + m_belts.placeTunnelEntry(front.anchor, front.rotation, m_config.world.tunnelMaxDistance); } else if (front.type == BuildingType::TunnelExit) { diff --git a/src/test/ConfigLoaderTest.cpp b/src/test/ConfigLoaderTest.cpp index 32c83da..95c3319 100644 --- a/src/test/ConfigLoaderTest.cpp +++ b/src/test/ConfigLoaderTest.cpp @@ -164,6 +164,7 @@ refund_percentage = 75 scrap_despawn_seconds = 30 belt_speed_tiles_per_second = 2 starting_building_blocks = 100 +tunnel_max_distance = 10 [regions] asteroid_width = 40 @@ -209,6 +210,7 @@ refund_percentage = 75 scrap_despawn_seconds = 30 belt_speed_tiles_per_second = 2 starting_building_blocks = 100 +tunnel_max_distance = 10 [regions] asteroid_width = 40 @@ -322,3 +324,4 @@ duration_seconds = 1.0 ConfigLoader::loadRecipes((dir.path() / "recipes.toml").string()), std::runtime_error); } + diff --git a/src/test/config/buildings.toml b/src/test/config/buildings.toml index 3826aab..1be0426 100644 --- a/src/test/config/buildings.toml +++ b/src/test/config/buildings.toml @@ -12,6 +12,20 @@ player_placeable = true construction_time_seconds = 1 surface_mask = [""] +[[building]] +id = "tunnel_entry" +cost = 5 +player_placeable = true +construction_time_seconds = 3 +surface_mask = ["A>"] + +[[building]] +id = "tunnel_exit" +cost = 5 +player_placeable = true +construction_time_seconds = 3 +surface_mask = ["A>"] + [[building]] id = "miner" cost = 15 diff --git a/src/test/config/world.toml b/src/test/config/world.toml index cca5c77..67d2ac9 100644 --- a/src/test/config/world.toml +++ b/src/test/config/world.toml @@ -4,6 +4,7 @@ refund_percentage = 75 starting_building_blocks = 100 scrap_despawn_seconds = 30 belt_speed_tiles_per_second = 2 +tunnel_max_distance = 10 [regions] asteroid_width = 40