Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384// Runtime map-size contract across storage, simulation, rendering, and 256-edge coordinates.#include "sc2k/render/minimap.hpp"#include "sc2k/render/rotate.hpp"#include "sc2k/sim/census.hpp"#include "sc2k/sim/growth.hpp"#include "sc2k/sim/power.hpp"#include "sc2k/sim/simulation.hpp"#include "sc2k/ui/new_city.hpp"
#include <array>#include <cstdint>#include <cstdio>
#include "test_harness.hpp"
int main() { using namespace sc2k;
constexpr std::array sizes = {MapSize::Tiny, MapSize::Small, MapSize::Medium, MapSize::Large}; CHECK(ui::kDefaultNewCityDifficulty == 1); CHECK(ui::kDefaultNewCityEra == 2); CHECK(ui::kDefaultNewCityMapSize == MapSize::Small); CHECK(ui::kDefaultNewCityTerrainStyle == "grassland"); CHECK(ui::new_city_zoom_fraction(MapSize::Tiny) == 1.f); CHECK(ui::new_city_zoom_fraction(MapSize::Small) == 0.5f); CHECK(ui::new_city_zoom_fraction(MapSize::Medium) == 1.f / 3.f); CHECK(ui::new_city_zoom_fraction(MapSize::Large) == 0.25f); for (const MapSize size : sizes) { City city(size); const int dimension = map_dimension(size); const std::size_t tiles = static_cast<std::size_t>(dimension) * dimension; CHECK(city.dimension() == dimension); CHECK((city.extent() == MapExtent{dimension, dimension})); CHECK(city.xter.cells.size() == tiles); CHECK(city.xtrf.cells.size() == tiles / 4); CHECK(city.xplc.cells.size() == tiles / 16); CHECK(city.on_map(dimension - 1, dimension - 1)); CHECK(!city.on_map(dimension, dimension - 1));
city.xtxt.at(dimension - 1, dimension - 1) = 42; const City rotated = render::rotate_once(city); CHECK(rotated.map_size() == size); CHECK(rotated.xtxt.at(0, dimension - 1) == 42); const City identity = render::rotate_city(city, 4); CHECK(identity.xtxt.cells == city.xtxt.cells);
const render::Framebuffer minimap = render::render_minimap_overview(city); CHECK(minimap.width() == dimension); CHECK(minimap.height() == dimension);
city.set_misc_be32(misc::kCityClass, 2); Simulation simulation(city); for (int tick = 0; tick < 50; ++tick) simulation.tick(); CHECK(city.xplt.cells.size() == tiles / 4); CHECK(city.xpop.cells.size() == tiles / 16); }
City large(MapSize::Large); TileCensus census; census.recount(large); CHECK(census.count[0] == 65536u);
// Two powered components cross the old seven-bit coordinate boundary and reach coordinate 255. const auto power_component = [&](int row, int plantColumn) { large.xbld.at(row, plantColumn) = 0xCA; large.xbit.at(row, plantColumn) = 0x80; large.xbld.at(row, plantColumn + 1) = 221; large.xbit.at(row, plantColumn + 1) = 0x80; CHECK(construct_building(large, row, plantColumn + 2, 225, 1, 0)); }; power_component(128, 126); power_component(255, 253); update_power(large); CHECK((large.xbit.at(128, 128) & 0x40) != 0); CHECK((large.xbit.at(255, 255) & 0x40) != 0);
if (failures == 0) { std::printf("map sizes: storage/simulation/render/power contract passed at 64/128/192/256\n"); return 0; } std::printf("map sizes: %d failure(s)\n", failures); return 1;}