aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/GameManager.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-11-14 22:27:39 +0100
committer hop311 <hop3114@gmail.com>2023-11-15 21:06:16 +0100
commite031758cf68535e97045c07f36e2524676447778 (patch)
treed6e49915c414c86ce808b2e1d7289c7e4e7d76df /src/openvic-simulation/GameManager.cpp
parenta00b558a53edb40c9e6789790036f0b618e80ec1 (diff)
Striped mapmode and improved distributions
Diffstat (limited to 'src/openvic-simulation/GameManager.cpp')
-rw-r--r--src/openvic-simulation/GameManager.cpp131
1 files changed, 82 insertions, 49 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp
index 427fbb1..755ab37 100644
--- a/src/openvic-simulation/GameManager.cpp
+++ b/src/openvic-simulation/GameManager.cpp
@@ -61,14 +61,58 @@ bool GameManager::expand_building(Province::index_t province_index, std::string_
return province->expand_building(building_type_identifier);
}
-static constexpr colour_t LOW_ALPHA_VALUE = float_to_alpha_value(0.4f);
-static constexpr colour_t HIGH_ALPHA_VALUE = float_to_alpha_value(0.7f);
-
-static colour_t default_colour(Province const& province) {
- /* Nice looking colours to blend with the terrain textures */
- static constexpr colour_t LAND_COLOUR = 0x0D7017;
- static constexpr colour_t WATER_COLOUR = 0x4287F5;
- return LOW_ALPHA_VALUE | (province.get_water() ? WATER_COLOUR : LAND_COLOUR);
+static constexpr colour_t ALPHA_VALUE = float_to_alpha_value(0.5f);
+
+static constexpr Mapmode::base_stripe_t combine_base_stripe(colour_t base, colour_t stripe) {
+ return (static_cast<Mapmode::base_stripe_t>(stripe) << (sizeof(colour_t) * 8)) | base;
+}
+
+static constexpr Mapmode::base_stripe_t make_solid_base_stripe(colour_t colour) {
+ return combine_base_stripe(colour, colour);
+}
+
+static constexpr auto make_solid_base_stripe_func(auto func) {
+ return [func](Map const& map, Province const& province) -> Mapmode::base_stripe_t {
+ return make_solid_base_stripe(func(map, province));
+ };
+}
+
+template<std::derived_from<HasColour> T>
+static constexpr Mapmode::base_stripe_t get_colour_mapmode(T const* item) {
+ return item != nullptr ? make_solid_base_stripe(ALPHA_VALUE | item->get_colour()) : NULL_COLOUR;
+}
+
+template<std::derived_from<HasColour> T>
+static constexpr auto get_colour_mapmode(T const*(Province::*get_item)() const) {
+ return [get_item](Map const& map, Province const& province) -> Mapmode::base_stripe_t {
+ T const* item = (province.*get_item)();
+ return item != nullptr ? make_solid_base_stripe(ALPHA_VALUE | item->get_colour()) : NULL_COLOUR;
+ };
+}
+
+template<std::derived_from<HasColour> T>
+static constexpr Mapmode::base_stripe_t shaded_mapmode(fixed_point_map_t<T const*> const& map) {
+ const std::pair<fixed_point_map_const_iterator_t<T const*>, fixed_point_map_const_iterator_t<T const*>> largest =
+ get_largest_two_items(map);
+ if (largest.first != map.end()) {
+ const colour_t base_colour = ALPHA_VALUE | largest.first->first->get_colour();
+ if (largest.second != map.end()) {
+ /* If second largest is at least a third... */
+ if (largest.second->second * 3 >= get_total(map)) {
+ const colour_t stripe_colour = ALPHA_VALUE | largest.second->first->get_colour();
+ return combine_base_stripe(base_colour, stripe_colour);
+ }
+ }
+ return make_solid_base_stripe(base_colour);
+ }
+ return NULL_COLOUR;
+}
+
+template<std::derived_from<HasColour> T>
+static constexpr auto shaded_mapmode(fixed_point_map_t<T const*> const&(Province::*get_map)() const) {
+ return [get_map](Map const& map, Province const& province) -> Mapmode::base_stripe_t {
+ return shaded_mapmode((province.*get_map)());
+ };
}
bool GameManager::load_hardcoded_defines() {
@@ -78,48 +122,39 @@ bool GameManager::load_hardcoded_defines() {
const std::vector<mapmode_t> mapmodes {
{
"mapmode_terrain",
- [](Map const&, Province const& province) -> colour_t {
- return default_colour(province);
+ [](Map const&, Province const& province) -> Mapmode::base_stripe_t {
+ return NULL_COLOUR;
}
},
{
+ "mapmode_political", get_colour_mapmode(&Province::get_owner)
+ },
+ {
"mapmode_province",
- [](Map const&, Province const& province) -> colour_t {
- return HIGH_ALPHA_VALUE | province.get_colour();
- }
+ make_solid_base_stripe_func([](Map const&, Province const& province) -> colour_t {
+ return ALPHA_VALUE | province.get_colour();
+ })
},
{
- "mapmode_region",
- [](Map const&, Province const& province) -> colour_t {
- Region const* region = province.get_region();
- return region != nullptr ? HIGH_ALPHA_VALUE | region->get_colour() : default_colour(province);
- }
+ "mapmode_region", get_colour_mapmode(&Province::get_region)
},
{
"mapmode_index",
- [](Map const& map, Province const& province) -> colour_t {
+ make_solid_base_stripe_func([](Map const& map, Province const& province) -> colour_t {
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;
- }
+ return ALPHA_VALUE | (f << 16) | (f << 8) | f;
+ })
},
{
- "mapmode_terrain_type",
- [](Map const& map, Province const& province) -> colour_t {
- TerrainType const* terrarin_type = province.get_terrain_type();
- return terrarin_type != nullptr ? HIGH_ALPHA_VALUE | terrarin_type->get_colour() : default_colour(province);
- }
+ "mapmode_terrain_type", get_colour_mapmode(&Province::get_terrain_type)
},
{
- "mapmode_rgo",
- [](Map const& map, Province const& province) -> colour_t {
- Good const* rgo = province.get_rgo();
- return rgo != nullptr ? HIGH_ALPHA_VALUE | rgo->get_colour() : default_colour(province);
- }
+ "mapmode_rgo", get_colour_mapmode(&Province::get_rgo)
},
{
"mapmode_infrastructure",
- [](Map const& map, Province const& province) -> colour_t {
- BuildingInstance const* railroad = province.get_building_by_identifier("building_railroad");
+ make_solid_base_stripe_func([](Map const& map, Province const& province) -> colour_t {
+ BuildingInstance const* railroad = province.get_building_by_identifier("railroad");
if (railroad != nullptr) {
colour_t val = fraction_to_colour_byte(railroad->get_current_level(),
railroad->get_building().get_max_level() + 1, 0.5f, 1.0f);
@@ -133,32 +168,30 @@ bool GameManager::load_hardcoded_defines() {
val <<= 8;
break;
}
- return HIGH_ALPHA_VALUE | val;
+ return ALPHA_VALUE | val;
}
- return default_colour(province);
- }
+ return NULL_COLOUR;
+ })
},
{
"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);
- }
+ make_solid_base_stripe_func([](Map const& map, Province const& province) -> colour_t {
+ // TODO - explore non-linear scaling to have more variation among non-massive provinces
+ // TODO - when selecting a province, only show the population of provinces controlled (or owned?)
+ // by the same country, relative to the most populous province in that set of provinces
+ return ALPHA_VALUE | (fraction_to_colour_byte(
+ province.get_total_population(), map.get_highest_province_population() + 1, 0.1f, 1.0f
+ ) << 8);
+ })
},
{
- "mapmode_culture",
- [](Map const& map, Province const& province) -> colour_t {
- HasIdentifierAndColour const* largest = get_largest_item(province.get_culture_distribution()).first;
- return largest != nullptr ? HIGH_ALPHA_VALUE | largest->get_colour() : default_colour(province);
- }
+ "mapmode_culture", shaded_mapmode(&Province::get_culture_distribution)
},
{
- "mapmode_religion",
- [](Map const& map, Province const& province) -> colour_t {
- HasIdentifierAndColour const* largest = get_largest_item(province.get_religion_distribution()).first;
- return largest != nullptr ? HIGH_ALPHA_VALUE | largest->get_colour() : default_colour(province);
- }
+ "mapmode_religion", shaded_mapmode(&Province::get_religion_distribution)
}
};
+
for (mapmode_t const& mapmode : mapmodes) {
ret &= map.add_mapmode(mapmode.first, mapmode.second);
}