From 34d9e9318387f2b2a0ae924a512f352540b84e07 Mon Sep 17 00:00:00 2001 From: hop311 Date: Sun, 7 Jan 2024 20:25:27 +0000 Subject: More impassable adjacencies + WVPM mod fixes --- src/openvic-simulation/GameManager.cpp | 12 +-- src/openvic-simulation/history/CountryHistory.cpp | 2 +- src/openvic-simulation/map/Map.cpp | 93 +++++++++++++---------- src/openvic-simulation/map/Province.cpp | 11 --- src/openvic-simulation/map/Province.hpp | 4 - src/openvic-simulation/politics/Rebel.cpp | 8 +- 6 files changed, 65 insertions(+), 65 deletions(-) (limited to 'src/openvic-simulation') diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp index c7dd470..50ec2b2 100644 --- a/src/openvic-simulation/GameManager.cpp +++ b/src/openvic-simulation/GameManager.cpp @@ -206,13 +206,13 @@ bool GameManager::load_hardcoded_defines() { colour_argb_t::integer_type base_int; switch (adj->get_type()) { using enum Province::adjacency_t::type_t; - case LAND: base_int = 0x00FF00; break; - case WATER: base_int = 0x0000FF; break; - case COASTAL: base_int = 0xF9D199; break; + case LAND: base_int = 0x00FF00; break; + case WATER: base_int = 0x0000FF; break; + case COASTAL: base_int = 0xF9D199; break; case IMPASSABLE: base_int = 0x8B4513; break; - case STRAIT: base_int = 0x00FFFF; break; - case CANAL: base_int = 0x888888; break; - default: base_int = 0xFF0000; break; + case STRAIT: base_int = 0x00FFFF; break; + case CANAL: base_int = 0x888888; break; + default: base_int = 0xFF0000; break; } base = colour_argb_t::from_integer(base_int).with_alpha(ALPHA_VALUE); stripe = base; diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp index 681b2b9..96a0b7c 100644 --- a/src/openvic-simulation/history/CountryHistory.cpp +++ b/src/openvic-simulation/history/CountryHistory.cpp @@ -141,7 +141,7 @@ bool CountryHistoryMap::_load_history_entry( "nonstate_consciousness", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.nonstate_consciousness)), "is_releasable_vassal", ZERO_OR_ONE, expect_bool(assign_variable_callback(entry.releasable_vassal)), "decision", ZERO_OR_MORE, decision_manager.expect_decision_identifier(set_callback_pointer(entry.decisions)), - "govt_flag", ZERO_OR_ONE, [&entry, &politics_manager](ast::NodeCPtr value) -> bool { + "govt_flag", ZERO_OR_MORE, [&entry, &politics_manager](ast::NodeCPtr value) -> bool { GovernmentTypeManager const& government_type_manager = politics_manager.get_government_type_manager(); GovernmentType const* government_type = nullptr; bool flag_expected = false; diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index a8cc4a0..27079f4 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -4,12 +4,11 @@ #include #include -#include "openvic-simulation/economy/Good.hpp" #include "openvic-simulation/history/ProvinceHistory.hpp" #include "openvic-simulation/types/Colour.hpp" +#include "openvic-simulation/types/OrderedContainers.hpp" #include "openvic-simulation/utility/BMP.hpp" #include "openvic-simulation/utility/Logger.hpp" -#include "openvic-simulation/types/OrderedContainers.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -84,6 +83,8 @@ Province::distance_t Map::calculate_distance_between(Province const& from, Provi return fvec2_t { min_x, to_pos.y - from_pos.y}.length_squared().sqrt(); } +using adjacency_t = Province::adjacency_t; + /* This is called for all adjacent pixel pairs and returns whether or not a new adjacency was add, * hence the lack of error messages in the false return cases. */ bool Map::add_standard_adjacency(Province& from, Province& to) const { @@ -100,10 +101,10 @@ bool Map::add_standard_adjacency(Province& from, Province& to) const { const Province::distance_t distance = calculate_distance_between(from, to); - using enum Province::adjacency_t::type_t; + using enum adjacency_t::type_t; /* Default land-to-land adjacency */ - Province::adjacency_t::type_t type = LAND; + adjacency_t::type_t type = LAND; if (from.is_water() != to.is_water()) { /* Land-to-water adjacency */ type = COASTAL; @@ -126,30 +127,28 @@ bool Map::add_standard_adjacency(Province& from, Province& to) const { } bool Map::add_special_adjacency( - Province& from, Province& to, Province::adjacency_t::type_t type, Province const* through, - Province::adjacency_t::data_t data + Province& from, Province& to, adjacency_t::type_t type, Province const* through, adjacency_t::data_t data ) const { if (from == to) { - Logger::error("Trying to add ", Province::adjacency_t::get_type_name(type), " adjacency from province ", from, " to itself!"); + Logger::error("Trying to add ", adjacency_t::get_type_name(type), " adjacency from province ", from, " to itself!"); return false; } - using enum Province::adjacency_t::type_t; + using enum adjacency_t::type_t; /* Check end points */ switch (type) { case LAND: - case IMPASSABLE: case STRAIT: if (from.is_water() || to.is_water()) { - Logger::error(Province::adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has water endpoint(s)!"); + Logger::error(adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has water endpoint(s)!"); return false; } break; case WATER: case CANAL: if (!from.is_water() || !to.is_water()) { - Logger::error(Province::adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has land endpoint(s)!"); + Logger::error(adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has land endpoint(s)!"); return false; } break; @@ -159,6 +158,12 @@ bool Map::add_special_adjacency( return false; } break; + case IMPASSABLE: + /* Impassable is valid for all combinations of land and water: + * - land-land = replace existing land adjacency with impassable adjacency (blue borders) + * - land-water = delete existing coastal adjacency, preventing armies and navies from moving between the provinces + * - water-water = delete existing water adjacency, preventing navies from moving between the provinces */ + break; default: Logger::error("Invalid adjacency type ", static_cast(type)); return false; @@ -169,56 +174,66 @@ bool Map::add_special_adjacency( const bool water_expected = type == STRAIT; if (through == nullptr || through->is_water() != water_expected) { Logger::error( - Province::adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has a ", + adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has a ", (through == nullptr ? "null" : water_expected ? "land" : "water"), " through province ", through ); return false; } } else if (through != nullptr) { Logger::warning( - Province::adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has a non-null through province ", + adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has a non-null through province ", through ); through = nullptr; } /* Check canal data */ - if (data != Province::adjacency_t::NO_CANAL && type != CANAL) { + if (data != adjacency_t::NO_CANAL && type != CANAL) { Logger::warning( - Province::adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has invalid data ", + adjacency_t::get_type_name(type), " adjacency from ", from, " to ", to, " has invalid data ", static_cast(data) ); - data = Province::adjacency_t::NO_CANAL; + data = adjacency_t::NO_CANAL; } const Province::distance_t distance = calculate_distance_between(from, to); const auto add_adjacency = [distance, type, through, data](Province& from, Province const& to) -> bool { - Province::adjacency_t* existing_adjacency = from.get_adjacency_to(&to); - if (existing_adjacency != nullptr) { + const std::vector::iterator existing_adjacency = std::find_if( + from.adjacencies.begin(), from.adjacencies.end(), + [&to](adjacency_t const& adj) -> bool { return adj.get_to() == &to; } + ); + if (existing_adjacency != from.adjacencies.end()) { if (type == existing_adjacency->get_type()) { Logger::warning( - "Adjacency from ", from, " to ", to, " already has type ", Province::adjacency_t::get_type_name(type), "!" + "Adjacency from ", from, " to ", to, " already has type ", adjacency_t::get_type_name(type), "!" ); if (type != STRAIT && type != CANAL) { /* Straits and canals might change through or data, otherwise we can exit early */ return true; } } - if (type != IMPASSABLE && type != STRAIT && type != CANAL) { - Logger::error( - "Provinces ", from, " and ", to, " already have an existing ", - Province::adjacency_t::get_type_name(existing_adjacency->get_type()), " adjacency, cannot create a ", - Province::adjacency_t::get_type_name(type), " adjacency!" - ); - return false; - } - if (type != existing_adjacency->get_type() && existing_adjacency->get_type() != (type == CANAL ? WATER : LAND)) { - Logger::error( - "Cannot convert ", Province::adjacency_t::get_type_name(existing_adjacency->get_type()), " adjacency from ", from, - " to ", to, " to type ", Province::adjacency_t::get_type_name(type), "!" - ); - return false; + if (type == IMPASSABLE) { + if (existing_adjacency->get_type() == WATER || existing_adjacency->get_type() == COASTAL) { + from.adjacencies.erase(existing_adjacency); + return true; + } + } else { + if (type != STRAIT && type != CANAL) { + Logger::error( + "Provinces ", from, " and ", to, " already have an existing ", + adjacency_t::get_type_name(existing_adjacency->get_type()), " adjacency, cannot create a ", + adjacency_t::get_type_name(type), " adjacency!" + ); + return false; + } + if (type != existing_adjacency->get_type() && existing_adjacency->get_type() != (type == CANAL ? WATER : LAND)) { + Logger::error( + "Cannot convert ", adjacency_t::get_type_name(existing_adjacency->get_type()), " adjacency from ", from, + " to ", to, " to type ", adjacency_t::get_type_name(type), "!" + ); + return false; + } } *existing_adjacency = { &to, distance, type, through, data }; return true; @@ -783,30 +798,30 @@ bool Map::generate_and_load_province_adjacencies(std::vector const& return; } - using enum Province::adjacency_t::type_t; - static const string_map_t type_map { + using enum adjacency_t::type_t; + static const string_map_t type_map { { "land", LAND }, { "sea", STRAIT }, { "impassable", IMPASSABLE }, { "canal", CANAL } }; const std::string_view type_str = adjacency.get_value_for(2); - const string_map_t::const_iterator it = type_map.find(type_str); + const string_map_t::const_iterator it = type_map.find(type_str); if (it == type_map.end()) { Logger::error("Invalid adjacency type: \"", type_str, "\""); ret = false; return; } - const Province::adjacency_t::type_t type = it->second; + const adjacency_t::type_t type = it->second; Province const* const through = get_province_by_identifier(adjacency.get_value_for(3)); const std::string_view data_str = adjacency.get_value_for(4); bool successful = false; const uint64_t data_uint = StringUtils::string_to_uint64(data_str, &successful); - if (!successful || data_uint > std::numeric_limits::max()) { + if (!successful || data_uint > std::numeric_limits::max()) { Logger::error("Invalid adjacency data: \"", data_str, "\""); ret = false; return; } - const Province::adjacency_t::data_t data = data_uint; + const adjacency_t::data_t data = data_uint; ret &= add_special_adjacency(*from, *to, type, through, data); } diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index a9bf329..1c3c76f 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -141,17 +141,6 @@ std::string_view Province::adjacency_t::get_type_name(type_t type) { } } -Province::adjacency_t* Province::get_adjacency_to(Province const* province) { - const std::vector::iterator it = std::find_if(adjacencies.begin(), adjacencies.end(), - [province](adjacency_t const& adj) -> bool { return adj.get_to() == province; } - ); - if (it != adjacencies.end()) { - return &*it; - } else { - return nullptr; - } -} - Province::adjacency_t const* Province::get_adjacency_to(Province const* province) const { const std::vector::const_iterator it = std::find_if(adjacencies.begin(), adjacencies.end(), [province](adjacency_t const& adj) -> bool { return adj.get_to() == province; } diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp index b77ec06..1df5676 100644 --- a/src/openvic-simulation/map/Province.hpp +++ b/src/openvic-simulation/map/Province.hpp @@ -146,10 +146,6 @@ namespace OpenVic { void update_gamestate(Date today); void tick(Date today); - private: - adjacency_t* get_adjacency_to(Province const* province); - - public: adjacency_t const* get_adjacency_to(Province const* province) const; bool is_adjacent_to(Province const* province) const; std::vector get_adjacencies_going_through(Province const* province) const; diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp index ca8e945..9f8b6c4 100644 --- a/src/openvic-simulation/politics/Rebel.cpp +++ b/src/openvic-simulation/politics/Rebel.cpp @@ -96,8 +96,8 @@ bool RebelManager::load_rebels_file( RebelType::icon_t icon = 0; RebelType::area_t area = RebelType::area_t::ALL; RebelType::government_map_t desired_governments; - RebelType::defection_t defection = RebelType::defection_t::ANY; - RebelType::independence_t independence = RebelType::independence_t::ANY; + RebelType::defection_t defection = RebelType::defection_t::NONE; + RebelType::independence_t independence = RebelType::independence_t::NONE; uint16_t defect_delay = 0; Ideology const* ideology = nullptr; bool break_alliance_on_win = false, allow_all_cultures = true, allow_all_culture_groups = true, @@ -127,9 +127,9 @@ bool RebelManager::load_rebels_file( )(value); } ), - "defection", ONE_EXACTLY, + "defection", ZERO_OR_ONE, expect_identifier(expect_mapped_string(defection_map, assign_variable_callback(defection))), - "independence", ONE_EXACTLY, + "independence", ZERO_OR_ONE, expect_identifier(expect_mapped_string(independence_map, assign_variable_callback(independence))), "defect_delay", ONE_EXACTLY, expect_uint(assign_variable_callback(defect_delay)), "ideology", ZERO_OR_ONE, -- cgit v1.2.3-56-ga3b1