aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/GameManager.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-10-28 11:39:08 +0200
committer hop311 <hop3114@gmail.com>2023-10-29 20:42:47 +0100
commit164264b047921dbe1567d2af183e1cffb200a8cb (patch)
tree21c3c81f65ac3259db4808ebe9fd32a94ca993af /src/openvic-simulation/GameManager.cpp
parentd8ec90f07342876e9331819bd3cc372050f78248 (diff)
Astyle formatting (with manual cleanup)
Diffstat (limited to 'src/openvic-simulation/GameManager.cpp')
-rw-r--r--src/openvic-simulation/GameManager.cpp98
1 files changed, 68 insertions, 30 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp
index 1c4efb3..c1710f6 100644
--- a/src/openvic-simulation/GameManager.cpp
+++ b/src/openvic-simulation/GameManager.cpp
@@ -3,18 +3,28 @@
using namespace OpenVic;
GameManager::GameManager(state_updated_func_t state_updated_callback)
- : clock { [this]() { tick(); }, [this]() { update_state(); } },
- state_updated { state_updated_callback } {}
+ : clock {
+ [this]() {
+ tick();
+ },
+ [this]() {
+ update_state();
+ }
+}, state_updated { state_updated_callback } {}
void GameManager::set_needs_update() {
needs_update = true;
}
void GameManager::update_state() {
- if (!needs_update) return;
+ if (!needs_update) {
+ return;
+ }
Logger::info("Update: ", today);
map.update_state(today);
- if (state_updated) state_updated();
+ if (state_updated) {
+ state_updated();
+ }
needs_update = false;
}
@@ -46,7 +56,8 @@ bool GameManager::expand_building(Province::index_t province_index, std::string_
set_needs_update();
Province* province = map.get_province_by_index(province_index);
if (province == nullptr) {
- Logger::error("Invalid province index ", province_index, " while trying to expand building ", building_type_identifier);
+ Logger::error("Invalid province index ", province_index,
+ " while trying to expand building ", building_type_identifier);
return false;
}
return province->expand_building(building_type_identifier);
@@ -67,65 +78,92 @@ bool GameManager::load_hardcoded_defines() {
using mapmode_t = std::pair<std::string, Mapmode::colour_func_t>;
const std::vector<mapmode_t> mapmodes {
- { "mapmode_terrain",
+ {
+ "mapmode_terrain",
[](Map const&, Province const& province) -> colour_t {
return default_colour(province);
- } },
- { "mapmode_province",
+ }
+ },
+ {
+ "mapmode_province",
[](Map const&, Province const& province) -> colour_t {
return HIGH_ALPHA_VALUE | province.get_colour();
- } },
- { "mapmode_region",
+ }
+ },
+ {
+ "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_index",
+ }
+ },
+ {
+ "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() + 1);
return HIGH_ALPHA_VALUE | (f << 16) | (f << 8) | f;
- } },
- { "mapmode_terrain_type",
+ }
+ },
+ {
+ "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_rgo",
+ }
+ },
+ {
+ "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_infrastructure",
+ }
+ },
+ {
+ "mapmode_infrastructure",
[](Map const& map, Province const& province) -> colour_t {
BuildingInstance const* railroad = province.get_building_by_identifier("building_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_current_level(),
+ railroad->get_building().get_max_level() + 1, 0.5f, 1.0f);
switch (railroad->get_expansion_state()) {
- case ExpansionState::CannotExpand: val <<= 16; break;
- case ExpansionState::CanExpand: break;
- default: val <<= 8; break;
+ case ExpansionState::CannotExpand:
+ val <<= 16;
+ break;
+ case ExpansionState::CanExpand:
+ break;
+ default:
+ val <<= 8;
+ break;
}
return HIGH_ALPHA_VALUE | val;
}
return default_colour(province);
- } },
- { "mapmode_population",
+ }
+ },
+ {
+ "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);
- } },
- { "mapmode_culture",
+ }
+ },
+ {
+ "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_religion",
+ }
+ },
+ {
+ "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);
- } }
+ }
+ }
};
- for (mapmode_t const& mapmode : mapmodes)
+ for (mapmode_t const& mapmode : mapmodes) {
ret &= map.add_mapmode(mapmode.first, mapmode.second);
+ }
map.lock_mapmodes();
return ret;