aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-12-07 22:04:05 +0100
committer GitHub <noreply@github.com>2023-12-07 22:04:05 +0100
commit085fe94212c6f0ddbdfca1b2ba58223e7f6dcc8a (patch)
tree2a73255f595eabb1441419a08bd0d5e5407213e7 /src/openvic-simulation/map
parent48a3f1729d709847d7cad33f594c77cac414e802 (diff)
parent398377011cb3d3c970451dcd215f3610159f1ae2 (diff)
Merge pull request #85 from OpenVicProject/container-callbacks
Container (pointer) callbacks + format cleanup
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Crime.cpp40
-rw-r--r--src/openvic-simulation/map/Crime.hpp32
-rw-r--r--src/openvic-simulation/map/Map.cpp16
-rw-r--r--src/openvic-simulation/map/Map.hpp4
-rw-r--r--src/openvic-simulation/map/Province.cpp26
-rw-r--r--src/openvic-simulation/map/Province.hpp13
-rw-r--r--src/openvic-simulation/map/State.cpp2
-rw-r--r--src/openvic-simulation/map/TerrainType.cpp2
8 files changed, 100 insertions, 35 deletions
diff --git a/src/openvic-simulation/map/Crime.cpp b/src/openvic-simulation/map/Crime.cpp
new file mode 100644
index 0000000..3a9ae64
--- /dev/null
+++ b/src/openvic-simulation/map/Crime.cpp
@@ -0,0 +1,40 @@
+#include "Crime.hpp"
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+Crime::Crime(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, bool new_default_active)
+ : TriggeredModifier { new_identifier, std::move(new_values), new_icon }, default_active { new_default_active } {}
+
+CrimeManager::CrimeManager() : crime_modifiers { "crime modifiers" } {}
+
+bool CrimeManager::add_crime_modifier(
+ std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, bool default_active
+) {
+ if (identifier.empty()) {
+ Logger::error("Invalid crime modifier effect identifier - empty!");
+ return false;
+ }
+ return crime_modifiers.add_item({ identifier, std::move(values), icon, default_active }, duplicate_warning_callback);
+}
+
+bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager, ast::NodeCPtr root) {
+ const bool ret = expect_dictionary_reserve_length(
+ crime_modifiers,
+ [this, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool {
+ ModifierValue modifier_value;
+ Modifier::icon_t icon = 0;
+ bool default_active = false;
+ bool ret = modifier_manager.expect_modifier_value_and_keys(
+ move_variable_callback(modifier_value),
+ "icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)),
+ "trigger", ONE_EXACTLY, success_callback, // TODO - load condition
+ "active", ZERO_OR_ONE, expect_bool(assign_variable_callback(default_active))
+ )(value);
+ ret &= add_crime_modifier(key, std::move(modifier_value), icon, default_active);
+ return ret;
+ }
+ )(root);
+ lock_crime_modifiers();
+ return ret;
+}
diff --git a/src/openvic-simulation/map/Crime.hpp b/src/openvic-simulation/map/Crime.hpp
new file mode 100644
index 0000000..d0dd844
--- /dev/null
+++ b/src/openvic-simulation/map/Crime.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "openvic-simulation/misc/Modifier.hpp"
+
+namespace OpenVic {
+ struct Crime final : TriggeredModifier {
+ friend struct CrimeManager;
+
+ private:
+ const bool PROPERTY(default_active);
+
+ Crime(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, bool new_default_active);
+
+ public:
+ Crime(Crime&&) = default;
+ };
+
+ struct CrimeManager {
+ private:
+ IdentifierRegistry<Crime> crime_modifiers;
+
+ public:
+ CrimeManager();
+
+ bool add_crime_modifier(
+ std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, bool default_active
+ );
+ IDENTIFIER_REGISTRY_ACCESSORS(crime_modifier)
+
+ bool load_crime_modifiers(ModifierManager const& modifier_manager, ast::NodeCPtr root);
+ };
+}
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index f854cab..7bf5e7d 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -282,10 +282,10 @@ Pop::pop_size_t Map::get_total_map_population() const {
return total_map_population;
}
-bool Map::reset(BuildingManager const& building_manager) {
+bool Map::reset(BuildingTypeManager const& building_type_manager) {
bool ret = true;
for (Province& province : provinces.get_items()) {
- ret &= province.reset(building_manager);
+ ret &= province.reset(building_type_manager);
}
return ret;
}
@@ -388,9 +388,9 @@ bool Map::load_province_definitions(std::vector<LineObject> const& lines) {
return ret;
}
-bool Map::load_province_positions(BuildingManager const& building_manager, ast::NodeCPtr root) {
- return expect_province_dictionary([&building_manager](Province& province, ast::NodeCPtr node) -> bool {
- return province.load_positions(building_manager, node);
+bool Map::load_province_positions(BuildingTypeManager const& building_type_manager, ast::NodeCPtr root) {
+ return expect_province_dictionary([&building_type_manager](Province& province, ast::NodeCPtr node) -> bool {
+ return province.load_positions(building_type_manager, node);
})(root);
}
@@ -399,11 +399,7 @@ bool Map::load_region_file(ast::NodeCPtr root) {
[this](std::string_view region_identifier, ast::NodeCPtr region_node) -> bool {
std::vector<std::string_view> province_identifiers;
bool ret = expect_list_reserve_length(
- province_identifiers,
- expect_identifier([&province_identifiers](std::string_view identifier) -> bool {
- province_identifiers.push_back(identifier);
- return true;
- })
+ province_identifiers, expect_identifier(vector_callback(province_identifiers))
)(region_node);
ret &= add_region(region_identifier, province_identifiers);
return ret;
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index f286276..bb760e6 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -108,7 +108,7 @@ namespace OpenVic {
* that is the maximum allowed number of provinces plus one for the index-zero "null province". */
bool generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const;
- bool reset(BuildingManager const& building_manager);
+ bool reset(BuildingTypeManager const& building_type_manager);
bool apply_history_to_provinces(ProvinceHistoryManager const& history_manager, Date date);
void update_highest_province_population();
@@ -120,7 +120,7 @@ namespace OpenVic {
void tick(Date today);
bool load_province_definitions(std::vector<ovdl::csv::LineObject> const& lines);
- bool load_province_positions(BuildingManager const& building_manager, ast::NodeCPtr root);
+ bool load_province_positions(BuildingTypeManager const& building_type_manager, ast::NodeCPtr root);
bool load_region_file(ast::NodeCPtr root);
bool load_map_images(fs::path const& province_path, fs::path const& terrain_path, bool detailed_errors);
bool generate_and_load_province_adjacencies(std::vector<ovdl::csv::LineObject> const& additional_adjacencies);
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp
index 201d3a0..1f9ca99 100644
--- a/src/openvic-simulation/map/Province.cpp
+++ b/src/openvic-simulation/map/Province.cpp
@@ -21,7 +21,7 @@ std::string Province::to_string() const {
return stream.str();
}
-bool Province::load_positions(BuildingManager const& building_manager, ast::NodeCPtr root) {
+bool Province::load_positions(BuildingTypeManager const& building_type_manager, ast::NodeCPtr root) {
return expect_dictionary_keys(
"text_position", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.text)),
"text_rotation", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.text_rotation)),
@@ -32,16 +32,16 @@ bool Province::load_positions(BuildingManager const& building_manager, ast::Node
"factory", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.factory)),
"building_construction", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.building_construction)),
"military_construction", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.military_construction)),
- "building_position", ZERO_OR_ONE, expect_dictionary_keys( // TODO: for TGC etc are building positions available for modded-in buildings? needs testing
- "fort", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.fort)),
- "railroad", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.railroad)),
- "naval_base", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.navalbase))
+ "building_position", ZERO_OR_ONE, building_type_manager.expect_building_type_dictionary(
+ [this](BuildingType const& type, ast::NodeCPtr value) -> bool {
+ return expect_fvec2([this, &type](fvec2_t position) -> bool {
+ positions.building_position.emplace(&type, std::move(position));
+ return true;
+ })(value);
+ }
),
- "building_rotation", ZERO_OR_ONE, expect_dictionary_keys(
- "fort", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.fort_rotation)),
- "railroad", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.railroad_rotation)),
- "naval_base", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.navalbase_rotation)),
- "aeroplane_factory", ZERO_OR_ONE, success_callback /* see below */
+ "building_rotation", ZERO_OR_ONE, building_type_manager.expect_building_type_decimal_map(
+ move_variable_callback(positions.building_rotation)
),
/* the below are esoteric clausewitz leftovers that either have no impact or whose functionality is lost to time */
"spawn_railway_track", ZERO_OR_ONE, success_callback,
@@ -137,7 +137,7 @@ bool Province::add_adjacency(Province const* province, distance_t distance, flag
return true;
}
-bool Province::reset(BuildingManager const& building_manager) {
+bool Province::reset(BuildingTypeManager const& building_type_manager) {
terrain_type = default_terrain_type;
life_rating = 0;
colony_status = colony_status_t::STATE;
@@ -150,8 +150,8 @@ bool Province::reset(BuildingManager const& building_manager) {
buildings.reset();
bool ret = true;
if (!get_water()) {
- if (building_manager.building_types_are_locked()) {
- for (BuildingType const& building_type : building_manager.get_building_types()) {
+ if (building_type_manager.building_types_are_locked()) {
+ for (BuildingType const& building_type : building_type_manager.get_building_types()) {
if (building_type.get_in_province()) {
ret &= buildings.add_item({ building_type });
}
diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp
index dd440fa..b45dd9c 100644
--- a/src/openvic-simulation/map/Province.hpp
+++ b/src/openvic-simulation/map/Province.hpp
@@ -11,6 +11,7 @@ namespace OpenVic {
struct Map;
struct Region;
struct State;
+ struct Crime;
struct Good;
struct TerrainType;
struct TerrainTypeMapping;
@@ -50,12 +51,8 @@ namespace OpenVic {
fvec2_t factory;
fvec2_t building_construction;
fvec2_t military_construction;
- fvec2_t fort;
- fixed_point_t fort_rotation;
- fvec2_t railroad;
- fixed_point_t railroad_rotation;
- fvec2_t navalbase;
- fixed_point_t navalbase_rotation;
+ std::map<BuildingType const*, fvec2_t> building_position;
+ fixed_point_map_t<BuildingType const*> building_rotation;
};
static constexpr index_t NULL_INDEX = 0, MAX_INDEX = std::numeric_limits<index_t>::max();
@@ -99,7 +96,7 @@ namespace OpenVic {
std::string to_string() const;
- bool load_positions(BuildingManager const& building_manager, ast::NodeCPtr root);
+ bool load_positions(BuildingTypeManager const& building_type_manager, ast::NodeCPtr root);
IDENTIFIER_REGISTRY_ACCESSORS(building)
bool expand_building(std::string_view building_type_identifier);
@@ -115,7 +112,7 @@ namespace OpenVic {
bool is_adjacent_to(Province const* province);
bool add_adjacency(Province const* province, distance_t distance, flags_t flags);
- bool reset(BuildingManager const& building_manager);
+ bool reset(BuildingTypeManager const& building_type_manager);
bool apply_history_to_province(ProvinceHistoryEntry const* entry);
};
}
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index bc78469..8da1e85 100644
--- a/src/openvic-simulation/map/State.cpp
+++ b/src/openvic-simulation/map/State.cpp
@@ -1,6 +1,6 @@
#include "State.hpp"
-#include "Map.hpp"
+#include "openvic-simulation/map/Map.hpp"
using namespace OpenVic;
diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp
index ae10474..4134662 100644
--- a/src/openvic-simulation/map/TerrainType.cpp
+++ b/src/openvic-simulation/map/TerrainType.cpp
@@ -140,7 +140,7 @@ bool TerrainTypeManager::load_terrain_types(ModifierManager const& modifier_mana
terrain_type_mappings.reserve(size - 2);
return size;
},
- std::bind(&TerrainTypeManager::_load_terrain_type_mapping, this, std::placeholders::_1, std::placeholders::_2),
+ std::bind_front(&TerrainTypeManager::_load_terrain_type_mapping, this),
"terrain", ONE_EXACTLY, expect_uint(assign_variable_callback(terrain_texture_limit)),
"categories", ONE_EXACTLY, _load_terrain_type_categories(modifier_manager)
)(root);