aboutsummaryrefslogtreecommitdiff
path: root/src/openvic2/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic2/map')
-rw-r--r--src/openvic2/map/Building.cpp9
-rw-r--r--src/openvic2/map/Map.cpp32
-rw-r--r--src/openvic2/map/Map.hpp8
-rw-r--r--src/openvic2/map/Province.cpp9
-rw-r--r--src/openvic2/map/Province.hpp7
-rw-r--r--src/openvic2/map/Region.cpp6
-rw-r--r--src/openvic2/map/Region.hpp6
7 files changed, 57 insertions, 20 deletions
diff --git a/src/openvic2/map/Building.cpp b/src/openvic2/map/Building.cpp
index 1e26873..4e0b14a 100644
--- a/src/openvic2/map/Building.cpp
+++ b/src/openvic2/map/Building.cpp
@@ -76,7 +76,7 @@ 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 } {
- assert(new_max_level >= 0);
+ assert(max_level >= 0);
assert(build_time >= 0);
}
@@ -115,8 +115,13 @@ BuildingType const* BuildingManager::get_building_type_by_identifier(std::string
}
return_t BuildingManager::generate_province_buildings(Province& province) const {
- return_t ret = SUCCESS;
province.reset_buildings();
+ if (!building_types.is_locked()) {
+ Logger::error("Cannot generate buildings until building types are locked!");
+ return FAILURE;
+ }
+ if (province.is_water()) return SUCCESS;
+ return_t ret = SUCCESS;
for (BuildingType const& type : building_types.get_items())
if (province.add_building(type) != SUCCESS) ret = FAILURE;
province.lock_buildings();
diff --git a/src/openvic2/map/Map.cpp b/src/openvic2/map/Map.cpp
index 1f44c43..d456a1f 100644
--- a/src/openvic2/map/Map.cpp
+++ b/src/openvic2/map/Map.cpp
@@ -4,6 +4,7 @@
#include <unordered_set>
#include "../Logger.hpp"
+#include "../economy/Good.hpp"
using namespace OpenVic2;
@@ -95,7 +96,7 @@ return_t Map::add_region(std::string const& identifier, std::vector<std::string>
else
Logger::error("Province ", province_identifier, " is already part of an unknown region with index ", other_region_index);
ret = FAILURE;
- } else new_region.provinces.insert(province);
+ } else new_region.provinces.push_back(province);
}
} else {
Logger::error("Invalid province identifier ", province_identifier);
@@ -154,6 +155,18 @@ index_t Map::get_province_index_at(size_t x, size_t y) const {
return NULL_INDEX;
}
+void Map::set_selected_province(index_t index) {
+ selected_province = index <= get_province_count() ? index : NULL_INDEX;
+}
+
+index_t Map::get_selected_province_index() const {
+ return selected_province;
+}
+
+Province const* Map::get_selected_province() const {
+ return get_province_by_index(get_selected_province_index());
+}
+
Region* Map::get_region_by_identifier(std::string const& identifier) {
return regions.get_item_by_identifier(identifier);
}
@@ -306,18 +319,21 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target)
*target++ = 0;
for (Province const& province : provinces.get_items()) {
const colour_t colour = mapmode->get_colour(*this, province);
- *target++ = (colour >> 16) & 0xFF;
- *target++ = (colour >> 8) & 0xFF;
- *target++ = colour & 0xFF;
- *target++ = (colour >> 24) & 0xFF;
+ *target++ = (colour >> 16) & FULL_COLOUR;
+ *target++ = (colour >> 8) & FULL_COLOUR;
+ *target++ = colour & FULL_COLOUR;
+ *target++ = (colour >> 24) & FULL_COLOUR;
}
return SUCCESS;
}
-return_t Map::generate_province_buildings(BuildingManager const& manager) {
+return_t Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager) {
return_t ret = SUCCESS;
- for (Province& province : provinces.get_items())
- if (manager.generate_province_buildings(province) != SUCCESS) ret = FAILURE;
+ for (Province& province : provinces.get_items()) {
+ if (!province.is_water()) // Set all land provinces to have an RGO based on their index to test them
+ province.rgo = good_manager.get_good_by_index(province.get_index() % good_manager.get_good_count());
+ if (building_manager.generate_province_buildings(province) != SUCCESS) ret = FAILURE;
+ }
return ret;
}
diff --git a/src/openvic2/map/Map.hpp b/src/openvic2/map/Map.hpp
index cb8dcb1..dd42076 100644
--- a/src/openvic2/map/Map.hpp
+++ b/src/openvic2/map/Map.hpp
@@ -21,6 +21,8 @@ namespace OpenVic2 {
colour_t get_colour(Map const& map, Province const& province) const;
};
+ struct GoodManager;
+
/* REQUIREMENTS:
* MAP-4
*/
@@ -46,6 +48,7 @@ namespace OpenVic2 {
size_t width = 0, height = 0;
std::vector<shape_pixel_t> province_shape_image;
colour_index_map_t colour_index_map;
+ index_t selected_province = NULL_INDEX;
index_t get_index_from_colour(colour_t colour) const;
public:
@@ -64,6 +67,9 @@ namespace OpenVic2 {
Province* get_province_by_identifier(std::string const& identifier);
Province const* get_province_by_identifier(std::string const& identifier) const;
index_t get_province_index_at(size_t x, size_t y) const;
+ void set_selected_province(index_t index);
+ index_t get_selected_province_index() const;
+ Province const* get_selected_province() const;
Region* get_region_by_identifier(std::string const& identifier);
Region const* get_region_by_identifier(std::string const& identifier) const;
@@ -82,7 +88,7 @@ namespace OpenVic2 {
static constexpr size_t MAPMODE_COLOUR_SIZE = 4;
return_t generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const;
- return_t generate_province_buildings(BuildingManager const& manager);
+ return_t setup(GoodManager const& good_manager, BuildingManager const& building_manager);
void update_state(Date const& today);
void tick(Date const& today);
diff --git a/src/openvic2/map/Province.cpp b/src/openvic2/map/Province.cpp
index b3d455b..6c80317 100644
--- a/src/openvic2/map/Province.cpp
+++ b/src/openvic2/map/Province.cpp
@@ -9,7 +9,6 @@ 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" } {
assert(index != NULL_INDEX);
- assert(new_colour != NULL_COLOUR);
}
index_t Province::get_index() const {
@@ -40,6 +39,10 @@ void Province::reset_buildings() {
buildings.reset();
}
+Building const* Province::get_building_by_identifier(std::string const& identifier) const {
+ return buildings.get_item_by_identifier(identifier);
+}
+
std::vector<Building> const& Province::get_buildings() const {
return buildings.get_items();
}
@@ -50,6 +53,10 @@ return_t Province::expand_building(std::string const& building_type_identifier)
return building->expand();
}
+Good const* Province::get_rgo() const {
+ return rgo;
+}
+
std::string Province::to_string() const {
std::stringstream stream;
stream << "(#" << std::to_string(index) << ", " << get_identifier() << ", 0x" << colour_to_hex_string() << ")";
diff --git a/src/openvic2/map/Province.hpp b/src/openvic2/map/Province.hpp
index 9b07fc1..44d0dee 100644
--- a/src/openvic2/map/Province.hpp
+++ b/src/openvic2/map/Province.hpp
@@ -5,9 +5,10 @@
namespace OpenVic2 {
struct Map;
struct Region;
+ struct Good;
/* REQUIREMENTS:
- * MAP-5, MAP-8, MAP-43, MAP-47
+ * MAP-5, MAP-7, MAP-8, MAP-43, MAP-47
*/
struct Province : HasIdentifier, HasColour {
friend struct Map;
@@ -20,6 +21,8 @@ namespace OpenVic2 {
bool water = false;
life_rating_t life_rating = 0;
IdentifierRegistry<Building> buildings;
+ // TODO - change this into a factory-like structure
+ Good const* rgo = nullptr;
Province(index_t new_index, std::string const& new_identifier, colour_t new_colour);
public:
@@ -32,8 +35,10 @@ namespace OpenVic2 {
return_t add_building(BuildingType const& type);
void lock_buildings();
void reset_buildings();
+ Building const* get_building_by_identifier(std::string const& identifier) const;
std::vector<Building> const& get_buildings() const;
return_t expand_building(std::string const& building_type_identifier);
+ Good const* get_rgo() const;
std::string to_string() const;
void update_state(Date const& today);
diff --git a/src/openvic2/map/Region.cpp b/src/openvic2/map/Region.cpp
index da0dfdd..d6d8dcc 100644
--- a/src/openvic2/map/Region.cpp
+++ b/src/openvic2/map/Region.cpp
@@ -12,13 +12,13 @@ bool ProvinceSet::contains_province(Province const* province) const {
return province && std::find(provinces.begin(), provinces.end(), province) != provinces.end();
}
-std::set<Province*> const& ProvinceSet::get_provinces() const {
+std::vector<Province*> const& ProvinceSet::get_provinces() const {
return provinces;
}
Region::Region(std::string const& new_identifier) : HasIdentifier{ new_identifier } {}
colour_t Region::get_colour() const {
- if (provinces.empty()) return 0xFF0000;
- return (*provinces.cbegin())->get_colour();
+ if (provinces.empty()) return FULL_COLOUR << 16;
+ return provinces.front()->get_colour();
}
diff --git a/src/openvic2/map/Region.hpp b/src/openvic2/map/Region.hpp
index 3920dfc..f688254 100644
--- a/src/openvic2/map/Region.hpp
+++ b/src/openvic2/map/Region.hpp
@@ -1,18 +1,16 @@
#pragma once
-#include <set>
-
#include "Province.hpp"
namespace OpenVic2 {
struct ProvinceSet {
protected:
- std::set<Province*> provinces;
+ std::vector<Province*> provinces;
public:
size_t get_province_count() const;
bool contains_province(Province const* province) const;
- std::set<Province*> const& get_provinces() const;
+ std::vector<Province*> const& get_provinces() const;
};
/* REQUIREMENTS: