aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/map
diff options
context:
space:
mode:
Diffstat (limited to 'extension/src/openvic2/map')
-rw-r--r--extension/src/openvic2/map/Building.cpp10
-rw-r--r--extension/src/openvic2/map/Building.hpp14
-rw-r--r--extension/src/openvic2/map/Map.cpp12
-rw-r--r--extension/src/openvic2/map/Map.hpp9
-rw-r--r--extension/src/openvic2/map/Province.cpp9
-rw-r--r--extension/src/openvic2/map/Province.hpp1
-rw-r--r--extension/src/openvic2/map/Region.cpp2
-rw-r--r--extension/src/openvic2/map/Region.hpp3
8 files changed, 42 insertions, 18 deletions
diff --git a/extension/src/openvic2/map/Building.cpp b/extension/src/openvic2/map/Building.cpp
index 1e26873..a2694b9 100644
--- a/extension/src/openvic2/map/Building.cpp
+++ b/extension/src/openvic2/map/Building.cpp
@@ -7,7 +7,8 @@
using namespace OpenVic2;
-Building::Building(BuildingType const& new_type) : HasIdentifier{ new_type.get_identifier() }, type{ new_type } {}
+Building::Building(BuildingType const& new_type) : HasIdentifier { new_type.get_identifier() },
+ type { new_type } {}
bool Building::_can_expand() const {
return level < type.get_max_level();
@@ -74,8 +75,9 @@ void Building::tick(Date const& today) {
}
}
-BuildingType::BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time) :
- HasIdentifier{ new_identifier }, max_level{ new_max_level }, build_time{ new_build_time } {
+BuildingType::BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time) : HasIdentifier { new_identifier },
+ max_level { new_max_level },
+ build_time { new_build_time } {
assert(new_max_level >= 0);
assert(build_time >= 0);
}
@@ -88,7 +90,7 @@ Timespan BuildingType::get_build_time() const {
return build_time;
}
-BuildingManager::BuildingManager() : building_types{ "building types" } {}
+BuildingManager::BuildingManager() : building_types { "building types" } {}
return_t BuildingManager::add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time) {
if (identifier.empty()) {
diff --git a/extension/src/openvic2/map/Building.hpp b/extension/src/openvic2/map/Building.hpp
index 78d08ae..492cbc6 100644
--- a/extension/src/openvic2/map/Building.hpp
+++ b/extension/src/openvic2/map/Building.hpp
@@ -2,8 +2,8 @@
#include <vector>
-#include "../Types.hpp"
#include "../Date.hpp"
+#include "../Types.hpp"
namespace OpenVic2 {
struct Province;
@@ -19,7 +19,13 @@ namespace OpenVic2 {
using level_t = int8_t;
- enum class ExpansionState { CannotExpand, CanExpand, Preparing, Expanding };
+ enum class ExpansionState {
+ CannotExpand,
+ CanExpand,
+ Preparing,
+ Expanding
+ };
+
private:
BuildingType const& type;
level_t level = 0;
@@ -30,6 +36,7 @@ namespace OpenVic2 {
Building(BuildingType const& new_type);
bool _can_expand() const;
+
public:
Building(Building&&) = default;
@@ -49,11 +56,13 @@ namespace OpenVic2 {
struct BuildingType : HasIdentifier {
friend struct BuildingManager;
+
private:
const Building::level_t max_level;
const Timespan build_time;
BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time);
+
public:
BuildingType(BuildingType&&) = default;
@@ -64,6 +73,7 @@ namespace OpenVic2 {
struct BuildingManager {
private:
IdentifierRegistry<BuildingType> building_types;
+
public:
BuildingManager();
diff --git a/extension/src/openvic2/map/Map.cpp b/extension/src/openvic2/map/Map.cpp
index 1f44c43..f920ccc 100644
--- a/extension/src/openvic2/map/Map.cpp
+++ b/extension/src/openvic2/map/Map.cpp
@@ -8,7 +8,9 @@
using namespace OpenVic2;
Mapmode::Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func)
- : HasIdentifier{ new_identifier }, index{ new_index }, colour_func{ new_colour_func } {
+ : HasIdentifier { new_identifier },
+ index { new_index },
+ colour_func { new_colour_func } {
assert(colour_func != nullptr);
}
@@ -20,7 +22,9 @@ colour_t Mapmode::get_colour(Map const& map, Province const& province) const {
return colour_func ? colour_func(map, province) : NULL_COLOUR;
}
-Map::Map() : provinces{ "provinces" }, regions{ "regions" }, mapmodes{ "mapmodes" } {}
+Map::Map() : provinces { "provinces" },
+ regions { "regions" },
+ mapmodes { "mapmodes" } {}
return_t Map::add_province(std::string const& identifier, colour_t colour) {
if (provinces.get_item_count() >= MAX_INDEX) {
@@ -35,7 +39,7 @@ return_t Map::add_province(std::string const& identifier, colour_t colour) {
Logger::error("Invalid province colour: ", Province::colour_to_hex_string(colour));
return FAILURE;
}
- Province new_province{ static_cast<index_t>(provinces.get_item_count() + 1), identifier, colour };
+ Province new_province { static_cast<index_t>(provinces.get_item_count() + 1), identifier, colour };
const index_t index = get_index_from_colour(colour);
if (index != NULL_INDEX) {
Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string());
@@ -78,7 +82,7 @@ return_t Map::add_region(std::string const& identifier, std::vector<std::string>
Logger::error("Invalid region identifier - empty!");
return FAILURE;
}
- Region new_region{ identifier };
+ Region new_region { identifier };
return_t ret = SUCCESS;
for (std::string const& province_identifier : province_identifiers) {
Province* province = get_province_by_identifier(province_identifier);
diff --git a/extension/src/openvic2/map/Map.hpp b/extension/src/openvic2/map/Map.hpp
index cb8dcb1..4fc97c9 100644
--- a/extension/src/openvic2/map/Map.hpp
+++ b/extension/src/openvic2/map/Map.hpp
@@ -9,13 +9,15 @@ namespace OpenVic2 {
struct Mapmode : HasIdentifier {
friend struct Map;
- using colour_func_t = std::function<colour_t (Map const&, Province const&)>;
+ using colour_func_t = std::function<colour_t(Map const&, Province const&)>;
using index_t = size_t;
+
private:
const index_t index;
const colour_func_t colour_func;
Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func);
+
public:
index_t get_index() const;
colour_t get_colour(Map const& map, Province const& province) const;
@@ -28,12 +30,12 @@ namespace OpenVic2 {
using terrain_t = uint8_t;
using terrain_variant_map_t = std::map<colour_t, terrain_t>;
- #pragma pack(push, 1)
+#pragma pack(push, 1)
struct shape_pixel_t {
index_t index;
terrain_t terrain;
};
- #pragma pack(pop)
+#pragma pack(pop)
private:
using colour_index_map_t = std::map<colour_t, index_t>;
@@ -48,6 +50,7 @@ namespace OpenVic2 {
colour_index_map_t colour_index_map;
index_t get_index_from_colour(colour_t colour) const;
+
public:
Map();
diff --git a/extension/src/openvic2/map/Province.cpp b/extension/src/openvic2/map/Province.cpp
index b3d455b..79f3ddd 100644
--- a/extension/src/openvic2/map/Province.cpp
+++ b/extension/src/openvic2/map/Province.cpp
@@ -1,13 +1,15 @@
#include "Province.hpp"
#include <cassert>
-#include <sstream>
#include <iomanip>
+#include <sstream>
using namespace OpenVic2;
-Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) :
- HasIdentifier{ new_identifier }, HasColour{ new_colour }, index{ new_index }, buildings{ "buildings" } {
+Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) : HasIdentifier { new_identifier },
+ HasColour { new_colour },
+ index { new_index },
+ buildings { "buildings" } {
assert(index != NULL_INDEX);
assert(new_colour != NULL_COLOUR);
}
@@ -59,7 +61,6 @@ std::string Province::to_string() const {
void Province::update_state(Date const& today) {
for (Building& building : buildings.get_items())
building.update_state(today);
-
}
void Province::tick(Date const& today) {
diff --git a/extension/src/openvic2/map/Province.hpp b/extension/src/openvic2/map/Province.hpp
index 9b07fc1..dd1742c 100644
--- a/extension/src/openvic2/map/Province.hpp
+++ b/extension/src/openvic2/map/Province.hpp
@@ -22,6 +22,7 @@ namespace OpenVic2 {
IdentifierRegistry<Building> buildings;
Province(index_t new_index, std::string const& new_identifier, colour_t new_colour);
+
public:
Province(Province&&) = default;
diff --git a/extension/src/openvic2/map/Region.cpp b/extension/src/openvic2/map/Region.cpp
index da0dfdd..bd87479 100644
--- a/extension/src/openvic2/map/Region.cpp
+++ b/extension/src/openvic2/map/Region.cpp
@@ -16,7 +16,7 @@ std::set<Province*> const& ProvinceSet::get_provinces() const {
return provinces;
}
-Region::Region(std::string const& new_identifier) : HasIdentifier{ new_identifier } {}
+Region::Region(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
colour_t Region::get_colour() const {
if (provinces.empty()) return 0xFF0000;
diff --git a/extension/src/openvic2/map/Region.hpp b/extension/src/openvic2/map/Region.hpp
index 3920dfc..8f1af70 100644
--- a/extension/src/openvic2/map/Region.hpp
+++ b/extension/src/openvic2/map/Region.hpp
@@ -9,6 +9,7 @@ namespace OpenVic2 {
struct ProvinceSet {
protected:
std::set<Province*> provinces;
+
public:
size_t get_province_count() const;
bool contains_province(Province const* province) const;
@@ -20,8 +21,10 @@ namespace OpenVic2 {
*/
struct Region : HasIdentifier, ProvinceSet {
friend struct Map;
+
private:
Region(std::string const& new_identifier);
+
public:
Region(Region&&) = default;