#include "sc2k/terrain/query.hpp" #include "sc2k/sim/growth.hpp" #include "sc2k/sim/disasters.hpp" #include "sc2k/sim/land_value.hpp" #include "sc2k/sim/military.hpp" #include "sc2k/sim/network_path.hpp" #include "sc2k/sim/things.hpp" #include "sc2k/ui/tools_apply.hpp" #include #include using namespace sc2k; namespace { terrain::Model model_with_top_corner(int row, int column, int base_level) { std::vector heights(129 * 129, base_level * terrain::kHeightQuantum); heights[static_cast(row) * 129 + column] += terrain::kHeightQuantum; auto model = terrain::Model::create({128, 128}, std::move(heights)); assert(model); return std::move(*model); } terrain::Model model_with_column_step(int column, int base_level) { std::vector heights(129 * 129, base_level * terrain::kHeightQuantum); for (int row = 0; row <= 128; ++row) for (int col = 0; col <= column; ++col) heights[static_cast(row) * 129 + col] += terrain::kHeightQuantum; auto model = terrain::Model::create({128, 128}, std::move(heights)); assert(model); return std::move(*model); } } // namespace int main() { City city; for (auto& altitude : city.altm.cells) altitude = 4; // The canonical model wins in both directions when compatibility bytes disagree with it. city.xter.at(10, 10) = 0; terrain::Model slope = model_with_top_corner(10, 10, 4); const terrain::Query canonical_slope(city, &slope); assert(!canonical_slope.flat({10, 10})); assert(canonical_slope.tile({10, 10}).shape == terrain::Shape::TopHigh); assert(!ui::zone_applicable(city, 10, 10, ui::Tool::ZoneR, &slope)); assert(!ui::apply_tool(city, ui::Tool::Road, 10, 10, -1, &slope).ok); assert(!construct_building_tile_ok(city, 10, 10, 210, &slope)); city.xter.at(30, 30) = 9; std::vector flat_heights(129 * 129, 4 * terrain::kHeightQuantum); auto flat = terrain::Model::create({128, 128}, std::move(flat_heights)); assert(flat); const terrain::Query canonical_flat(city, &*flat); assert(canonical_flat.flat({30, 30})); assert(canonical_flat.natural_buildable({30, 30})); assert(ui::zone_applicable(city, 30, 30, ui::Tool::ZoneR, &*flat)); assert(construct_building_tile_ok(city, 30, 30, 210, &*flat)); assert(ui::detail::power_plant_tile_ok(city, 30, 30, &*flat)); // Simulation consumers use the same authority boundary: growth merging, land value and military // siting follow canonical ground even when the renderer-compatibility bytes say something else. city.xzon.at(31, 31) = 2; city.altm.at(31, 31) = 1; assert(!can_merge_tile(city, 31, 31, 4, 2, 140)); assert(can_merge_tile(city, 31, 31, 4, 2, 140, &*flat)); city.xter.at(32, 32) = 9; assert(!sim::mil_tile_ok(city, 32, 32)); assert(sim::mil_tile_ok(city, 32, 32, &*flat)); City valueCity; valueCity.xzon.at(32, 32) = 1; std::array legacyValue{}, canonicalValue{}; valueCity.xter.at(32, 32) = 0; terrain::Model valueSlope = model_with_top_corner(32, 32, 0); land_value_step(valueCity, legacyValue); land_value_step(valueCity, canonicalValue, &valueSlope); assert(legacyValue != canonicalValue); // Disaster effects and Things no longer infer ground from compatibility presentation bytes. city.xter.at(33, 33) = 9; assert(sim::rubble_code(city, 33, 33) == 0); assert(sim::rubble_code(city, 33, 33, &*flat) != 0); city.altm.at(34, 34) = 5; sim::detail::flood_flow(city, 34, 34, 4); assert(city.xtxt.at(34, 34) == 0); sim::detail::flood_flow(city, 34, 34, 4, &*flat); assert(city.xtxt.at(34, 34) == sim::fx::Flood); std::vector highHeights(129 * 129, 7 * terrain::kHeightQuantum); auto highGround = terrain::Model::create({128, 128}, std::move(highHeights)); assert(highGround); MsRand tornadoRng(1); const int tornado = sim::spawn_tornado(city, tornadoRng, 35, 35, &*highGround); assert(tornado != 0); assert(sim::thing_field(city, tornado, sim::thg::Frame) == 7); // The live drag solver consumes canonical grade direction and terrace costs too. terrain::Model column_step = model_with_column_step(10, 4); const sim::NetworkPath legacy_path = sim::solve_network_path(city, 10, 10, 12, 10, sim::NetType::Road); const sim::NetworkPath canonical_path = sim::solve_network_path(city, 10, 10, 12, 10, sim::NetType::Road, &column_step); assert(legacy_path.steps.size() == 3); assert(canonical_path.steps.size() == 1); assert(canonical_path.endRow == 10 && canonical_path.endCol == 10); sim::NetworkPath one_tile_path; one_tile_path.steps.push_back({30, 30, 0}); assert(sim::path_terrace_tiles(city, one_tile_path) == 1); assert(sim::path_terrace_tiles(city, one_tile_path, &*flat) == 0); // Water and temporary constructed supports remain separate blockers rather than fake slopes. city.xbit.at(20, 20) |= xbit::kWater; const terrain::Query wet(city, &*flat); assert(wet.flat({20, 20})); assert(!wet.dry({20, 20})); assert(!wet.natural_buildable({20, 20})); city.xter.at(40, 40) = xter::kCube; city.xbld.at(40, 40) = xbld::kRoadFirst; const terrain::Query supported(city, &*flat); assert(supported.flat({40, 40})); assert(supported.tile({40, 40}).constructed_support); assert(!supported.natural_buildable({40, 40})); city.xbld.at(41, 41) = 0; city.xter.at(41, 41) = xter::kCube; assert(!terrain::Query(city).natural_buildable({41, 41})); // Unported callers retain deterministic legacy semantics through the explicit fallback. const terrain::Query legacy(city); assert(!legacy.flat({30, 30})); assert(legacy.base_level({10, 10}) == 4); assert(legacy.same_base_level({10, 10}, {30, 30})); assert(!legacy.contains({-1, 0})); return 0; }