aboutsummaryrefslogtreecommitdiff
path: root/extension/src
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-08-06 11:44:05 +0200
committer GitHub <noreply@github.com>2023-08-06 11:44:05 +0200
commitff0d38b5d53fa95609f2587a2be5205f0c0d3118 (patch)
tree2b08788e43e72106442ed74af78fdc67ef83f3ce /extension/src
parentce9022d0df74d6c33db3686622be2050d873ab0b (diff)
parent244a669311edc5136aaa730b31ef64fd9d56879d (diff)
Merge pull request #144 from OpenVicProject/pops
First pass at pops (test pops and density mapmode)
Diffstat (limited to 'extension/src')
-rw-r--r--extension/src/GameSingleton.cpp28
-rw-r--r--extension/src/GameSingleton.hpp12
2 files changed, 31 insertions, 9 deletions
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp
index 2668700..efacb8e 100644
--- a/extension/src/GameSingleton.cpp
+++ b/extension/src/GameSingleton.cpp
@@ -1,5 +1,7 @@
#include "GameSingleton.hpp"
+#include <cassert>
+
#include <godot_cpp/variant/utility_functions.hpp>
#include "openvic/utility/Logger.hpp"
@@ -9,6 +11,16 @@
using namespace godot;
using namespace OpenVic;
+TerrainVariant::TerrainVariant(std::string const& new_identfier,
+ colour_t new_colour, Ref<Image> const& new_image)
+ : HasIdentifier { new_identfier },
+ HasColour { new_colour, true },
+ image { new_image } {}
+
+Ref<Image> TerrainVariant::get_image() const {
+ return image;
+}
+
GameSingleton* GameSingleton::singleton = nullptr;
void GameSingleton::_bind_methods() {
@@ -62,6 +74,7 @@ void GameSingleton::_bind_methods() {
ClassDB::bind_static_method("GameSingleton", D_METHOD("get_province_info_province_key"), &GameSingleton::get_province_info_province_key);
ClassDB::bind_static_method("GameSingleton", D_METHOD("get_province_info_region_key"), &GameSingleton::get_province_info_region_key);
ClassDB::bind_static_method("GameSingleton", D_METHOD("get_province_info_life_rating_key"), &GameSingleton::get_province_info_life_rating_key);
+ ClassDB::bind_static_method("GameSingleton", D_METHOD("get_province_info_total_population_key"), &GameSingleton::get_province_info_total_population_key);
ClassDB::bind_static_method("GameSingleton", D_METHOD("get_province_info_rgo_key"), &GameSingleton::get_province_info_rgo_key);
ClassDB::bind_static_method("GameSingleton", D_METHOD("get_province_info_buildings_key"), &GameSingleton::get_province_info_buildings_key);
@@ -83,7 +96,7 @@ void GameSingleton::_on_state_updated() {
}
/* REQUIREMENTS:
- * MAP-21, MAP-23, MAP-25, MAP-32
+ * MAP-21, MAP-23, MAP-25, MAP-32, MAP-33
*/
GameSingleton::GameSingleton() : game_manager { [this]() { _on_state_updated(); } },
terrain_variants { "terrain variants" } {
@@ -119,7 +132,7 @@ Error GameSingleton::_load_hardcoded_defines() {
} },
{ "mapmode_index",
[](Map const& map, Province const& province) -> colour_t {
- const colour_t f = fraction_to_colour_byte(province.get_index(), map.get_province_count());
+ const colour_t f = fraction_to_colour_byte(province.get_index(), map.get_province_count() + 1);
return HIGH_ALPHA_VALUE | (f << 16) | (f << 8) | f;
} },
{ "mapmode_rgo",
@@ -132,7 +145,7 @@ Error GameSingleton::_load_hardcoded_defines() {
[](Map const& map, Province const& province) -> colour_t {
Building const* railroad = province.get_building_by_identifier("building_railroad");
if (railroad != nullptr) {
- colour_t val = fraction_to_colour_byte(railroad->get_level(), railroad->get_type().get_max_level(), 0.5f, 1.0f);
+ colour_t val = fraction_to_colour_byte(railroad->get_level(), railroad->get_type().get_max_level() + 1, 0.5f, 1.0f);
switch (railroad->get_expansion_state()) {
case Building::ExpansionState::CannotExpand: val <<= 16; break;
case Building::ExpansionState::CanExpand: break;
@@ -141,6 +154,10 @@ Error GameSingleton::_load_hardcoded_defines() {
return HIGH_ALPHA_VALUE | val;
}
return HIGH_ALPHA_VALUE;
+ } },
+ { "mapmode_population",
+ [](Map const& map, Province const& province) -> colour_t {
+ return HIGH_ALPHA_VALUE | (fraction_to_colour_byte(province.get_total_population(), map.get_highest_province_population() + 1, 0.1f, 1.0f) << 8);
} }
};
for (mapmode_t const& mapmode : mapmodes)
@@ -187,6 +204,10 @@ StringName const& GameSingleton::get_province_info_life_rating_key() {
static const StringName key = "life_rating";
return key;
}
+StringName const& GameSingleton::get_province_info_total_population_key() {
+ static const StringName key = "total_population";
+ return key;
+}
StringName const& GameSingleton::get_province_info_rgo_key() {
static const StringName key = "rgo";
return key;
@@ -235,6 +256,7 @@ Dictionary GameSingleton::get_province_info_from_index(int32_t index) const {
if (rgo != nullptr) ret[get_province_info_rgo_key()] = std_to_godot_string(rgo->get_identifier());
ret[get_province_info_life_rating_key()] = province->get_life_rating();
+ ret[get_province_info_total_population_key()] = province->get_total_population();
std::vector<Building> const& buildings = province->get_buildings();
if (!buildings.empty()) {
diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp
index 6c91de5..23eb334 100644
--- a/extension/src/GameSingleton.hpp
+++ b/extension/src/GameSingleton.hpp
@@ -7,20 +7,19 @@
namespace OpenVic {
struct TerrainVariant : HasIdentifier, HasColour {
+ friend class GameSingleton;
+
private:
const godot::Ref<godot::Image> image;
+ TerrainVariant(std::string const& new_identfier, colour_t new_colour,
+ godot::Ref<godot::Image> const& new_image);
public:
static constexpr size_t MAX_INDEX = 1 << (8 * sizeof(Map::terrain_t));
- TerrainVariant(std::string const& new_identfier, colour_t new_colour,
- godot::Ref<godot::Image> const& new_image)
- : HasIdentifier { new_identfier },
- HasColour { new_colour },
- image { new_image } {}
TerrainVariant(TerrainVariant&&) = default;
- godot::Ref<godot::Image> get_image() const { return image; }
+ godot::Ref<godot::Image> get_image() const;
};
class GameSingleton : public godot::Object {
GDCLASS(GameSingleton, godot::Object)
@@ -106,6 +105,7 @@ namespace OpenVic {
static godot::StringName const& get_province_info_province_key();
static godot::StringName const& get_province_info_region_key();
static godot::StringName const& get_province_info_life_rating_key();
+ static godot::StringName const& get_province_info_total_population_key();
static godot::StringName const& get_province_info_rgo_key();
static godot::StringName const& get_province_info_buildings_key();