aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/GameManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/GameManager.cpp')
-rw-r--r--src/openvic-simulation/GameManager.cpp160
1 files changed, 103 insertions, 57 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp
index 427fbb1..397b729 100644
--- a/src/openvic-simulation/GameManager.cpp
+++ b/src/openvic-simulation/GameManager.cpp
@@ -37,18 +37,31 @@ void GameManager::tick() {
set_needs_update();
}
-bool GameManager::setup() {
+bool GameManager::reset() {
session_start = time(nullptr);
clock.reset();
- today = { 1836 };
+ today = {};
economy_manager.get_good_manager().reset_to_defaults();
- bool ret = map.setup(economy_manager.get_building_manager(), pop_manager);
+ bool ret = map.reset(economy_manager.get_building_manager());
set_needs_update();
return ret;
}
-Date GameManager::get_today() const {
- return today;
+bool GameManager::load_bookmark(Bookmark const* new_bookmark) {
+ bool ret = reset();
+ bookmark = new_bookmark;
+ if (bookmark == nullptr) {
+ return ret;
+ }
+ Logger::info("Loading bookmark ", bookmark->get_name(), " with start date ", bookmark->get_date());
+ if (!define_manager.in_game_period(bookmark->get_date())) {
+ Logger::warning("Bookmark date ", bookmark->get_date(), " is not in the game's time period!");
+ }
+ today = bookmark->get_date();
+ ret &= map.apply_history_to_provinces(history_manager.get_province_manager(), today);
+ // TODO - apply country history
+ // TODO - apply pop history
+ return ret;
}
bool GameManager::expand_building(Province::index_t province_index, std::string_view building_type_identifier) {
@@ -61,14 +74,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 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 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 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,87 +135,76 @@ 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);
+ colour_t val = fraction_to_colour_byte(railroad->get_level(),
+ railroad->get_building_type().get_max_level() + 1, 0.5f, 1.0f);
switch (railroad->get_expansion_state()) {
- case ExpansionState::CannotExpand:
+ case BuildingInstance::ExpansionState::CannotExpand:
val <<= 16;
break;
- case ExpansionState::CanExpand:
+ case BuildingInstance::ExpansionState::CanExpand:
break;
default:
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);
}