Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension/deps/openvic-simulation
Submodule openvic-simulation updated 58 files
+3 −0 .gitmodules
+5 −0 COPYRIGHT
+56 −1 deps/SCsub
+1 −0 deps/type_safe
+2 −1 pyproject.toml
+3 −3 src/openvic-simulation/country/CountryDefinition.cpp
+2 −1 src/openvic-simulation/country/CountryDefinition.hpp
+54 −22 src/openvic-simulation/country/CountryInstance.cpp
+9 −5 src/openvic-simulation/country/CountryInstance.hpp
+1 −1 src/openvic-simulation/dataloader/Dataloader.cpp
+25 −0 src/openvic-simulation/dataloader/NodeTools.hpp
+2 −2 src/openvic-simulation/economy/BuildingType.cpp
+2 −1 src/openvic-simulation/economy/BuildingType.hpp
+1 −1 src/openvic-simulation/economy/GoodDefinition.cpp
+2 −1 src/openvic-simulation/economy/GoodDefinition.hpp
+1 −1 src/openvic-simulation/economy/GoodInstance.cpp
+2 −1 src/openvic-simulation/economy/GoodInstance.hpp
+3 −1 src/openvic-simulation/economy/production/ArtisanalProducer.cpp
+4 −2 src/openvic-simulation/history/Bookmark.cpp
+2 −1 src/openvic-simulation/history/Bookmark.hpp
+3 −1 src/openvic-simulation/history/ProvinceHistory.cpp
+2 −2 src/openvic-simulation/map/Crime.cpp
+2 −1 src/openvic-simulation/map/Crime.hpp
+15 −13 src/openvic-simulation/map/MapDefinition.cpp
+7 −3 src/openvic-simulation/map/Mapmode.cpp
+2 −1 src/openvic-simulation/map/Mapmode.hpp
+8 −6 src/openvic-simulation/map/ProvinceDefinition.hpp
+2 −1 src/openvic-simulation/map/ProvinceInstance.hpp
+2 −2 src/openvic-simulation/map/TerrainType.cpp
+2 −1 src/openvic-simulation/map/TerrainType.hpp
+4 −4 src/openvic-simulation/military/UnitType.cpp
+3 −2 src/openvic-simulation/military/UnitType.hpp
+20 −20 src/openvic-simulation/misc/GameAction.cpp
+12 −3 src/openvic-simulation/misc/GameAction.hpp
+2 −2 src/openvic-simulation/politics/Government.cpp
+2 −1 src/openvic-simulation/politics/Government.hpp
+1 −1 src/openvic-simulation/politics/Ideology.cpp
+2 −1 src/openvic-simulation/politics/Ideology.hpp
+4 −4 src/openvic-simulation/politics/IssueManager.cpp
+5 −4 src/openvic-simulation/politics/PartyPolicy.hpp
+2 −2 src/openvic-simulation/politics/Rebel.cpp
+2 −1 src/openvic-simulation/politics/Rebel.hpp
+2 −2 src/openvic-simulation/politics/Reform.cpp
+3 −2 src/openvic-simulation/politics/Reform.hpp
+1 −1 src/openvic-simulation/politics/Rule.cpp
+2 −1 src/openvic-simulation/politics/Rule.hpp
+5 −2 src/openvic-simulation/population/Pop.cpp
+2 −2 src/openvic-simulation/population/PopManager.cpp
+3 −2 src/openvic-simulation/population/PopType.hpp
+2 −2 src/openvic-simulation/research/Invention.cpp
+2 −1 src/openvic-simulation/research/Invention.hpp
+2 −2 src/openvic-simulation/research/Technology.cpp
+3 −2 src/openvic-simulation/research/Technology.hpp
+4 −3 src/openvic-simulation/types/HasIndex.hpp
+35 −14 src/openvic-simulation/types/IndexedFlatMap.hpp
+67 −0 src/openvic-simulation/types/TypedIndices.hpp
+32 −0 src/openvic-simulation/types/TypedSpan.hpp
+6 −2 src/openvic-simulation/utility/Concepts.hpp
12 changes: 8 additions & 4 deletions extension/src/openvic-extension/classes/GUILabel.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "GUILabel.hpp"

#include <optional>

#include <godot_cpp/classes/font_file.hpp>
#include <godot_cpp/classes/style_box_texture.hpp>
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/node_path.hpp>
#include <godot_cpp/variant/string_name.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

#include <openvic-simulation/types/TypedIndices.hpp>

#include "openvic-extension/classes/GUINode.hpp"
#include "openvic-extension/core/Convert.hpp"
#include "openvic-extension/singletons/AssetManager.hpp"
Expand Down Expand Up @@ -690,7 +694,7 @@ void GUILabel::separate_currency_segments(
GUILabel::flag_segment_t GUILabel::make_flag_segment(String const& identifier) {
GameSingleton& game_singleton = *GameSingleton::get_singleton();

int32_t country_index = -1;
std::optional<country_index_t> country_index = std::nullopt;
StringName flag_type;

InstanceManager* instance_manager = game_singleton.get_instance_manager();
Expand Down Expand Up @@ -721,14 +725,14 @@ GUILabel::flag_segment_t GUILabel::make_flag_segment(String const& identifier) {
}

// If no country with the given identifier can be found, fallback to country index 0 (usually REB) and empty flag type
if (country_index < 0) {
if (!country_index.has_value()) {
UtilityFunctions::push_warning(
"Failed to find country with identifier \"", identifier, "\" for GUILabel flag segment, falling back to index 0"
);
country_index = 0;
country_index = country_index_t(0);
}

const Rect2 flag_image_rect = game_singleton.get_flag_sheet_rect(country_index, flag_type);
const Rect2 flag_image_rect = game_singleton.get_flag_sheet_rect(country_index.value(), flag_type);
ERR_FAIL_COND_V(!flag_image_rect.has_area(), {});

flag_segment_t flag_segment;
Expand Down
42 changes: 29 additions & 13 deletions extension/src/openvic-extension/singletons/GameSingleton.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#include "GameSingleton.hpp"

#include <functional>
#include <type_safe/strong_typedef.hpp>

#include <godot_cpp/classes/time.hpp>
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/packed_string_array.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

#include <openvic-simulation/dataloader/ModManager.hpp>
#include <openvic-simulation/DefinitionManager.hpp>
#include <openvic-simulation/map/Crime.hpp>
#include <openvic-simulation/types/TypedIndices.hpp>
#include <openvic-simulation/utility/Containers.hpp>
#include <openvic-simulation/utility/Logger.hpp>

Expand Down Expand Up @@ -203,19 +207,24 @@ TypedArray<Dictionary> GameSingleton::get_bookmark_info() const {
}

Error GameSingleton::setup_game(int32_t bookmark_index) {
Bookmark const* bookmark =
game_manager.get_definition_manager().get_history_manager().get_bookmark_manager().get_bookmark_by_index(bookmark_index
);
DefinitionManager const& definition_manager = game_manager.get_definition_manager();
Bookmark const* bookmark = definition_manager.get_history_manager()
.get_bookmark_manager()
.get_bookmark_by_index(bookmark_index_t(bookmark_index));
ERR_FAIL_NULL_V_MSG(bookmark, FAILED, Utilities::format("Failed to get bookmark with index: %d", bookmark_index));
bool ret = game_manager.setup_instance(bookmark);

// TODO - remove this temporary crime assignment
InstanceManager* instance_manager = get_instance_manager();
ERR_FAIL_NULL_V_MSG(instance_manager, FAILED, "Failed to setup instance manager!");

CrimeManager const& crime_manager = definition_manager.get_crime_manager();
for (ProvinceInstance& province : instance_manager->get_map_instance().get_province_instances()) {
province.set_crime(get_definition_manager().get_crime_manager().get_crime_modifier_by_index(
province.index % get_definition_manager().get_crime_manager().get_crime_modifier_count()
));
const crime_index_t crime_index = crime_index_t(province.index % crime_manager.get_crime_modifier_count());
province.set_crime(crime_manager.get_crime_modifier_by_index(crime_index));
}

ret &= MenuSingleton::get_singleton()->_population_menu_update_provinces() == OK;
Expand Down Expand Up @@ -314,7 +323,7 @@ Ref<ImageTexture> GameSingleton::get_flag_sheet_texture() const {
return flag_sheet_texture;
}

int32_t GameSingleton::get_flag_sheet_index(int32_t country_index, StringName const& flag_type) const {
int32_t GameSingleton::get_flag_sheet_index(country_index_t country_index, StringName const& flag_type) const {
ERR_FAIL_COND_V_MSG(
country_index < 0 ||
country_index >= get_definition_manager().get_country_definition_manager().get_country_definition_count(),
Expand All @@ -324,7 +333,7 @@ int32_t GameSingleton::get_flag_sheet_index(int32_t country_index, StringName co
const typename decltype(flag_type_index_map)::const_iterator it = flag_type_index_map.find(flag_type);
ERR_FAIL_COND_V_MSG(it == flag_type_index_map.end(), -1, Utilities::format("Invalid flag type %s", flag_type));

return flag_type_index_map.size() * country_index + it->second;
return flag_type_index_map.size() * type_safe::get(country_index) + it->second;
}

Rect2i GameSingleton::get_flag_sheet_rect(int32_t flag_index) const {
Expand All @@ -335,7 +344,7 @@ Rect2i GameSingleton::get_flag_sheet_rect(int32_t flag_index) const {
return { Vector2i { flag_index % flag_sheet_dims.x, flag_index / flag_sheet_dims.x } * flag_dims, flag_dims };
}

Rect2i GameSingleton::get_flag_sheet_rect(int32_t country_index, StringName const& flag_type) const {
Rect2i GameSingleton::get_flag_sheet_rect(country_index_t country_index, StringName const& flag_type) const {
return get_flag_sheet_rect(get_flag_sheet_index(country_index, flag_type));
}

Expand Down Expand Up @@ -408,7 +417,7 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const {
TypedArray<Dictionary> ret;
ERR_FAIL_COND_V(ret.resize(map_definition.get_province_definition_count()) != OK, {});

for (int32_t index = 0; index < map_definition.get_province_definition_count(); ++index) {
for (province_index_t index = 0; index < map_definition.get_province_definition_count(); ++index) {
ProvinceDefinition const& province = map_definition.get_province_definitions()[index];

Dictionary province_dict;
Expand All @@ -433,35 +442,42 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const {
}

int32_t GameSingleton::get_mapmode_count() const {
return get_definition_manager().get_mapmode_manager().get_mapmode_count();
const auto count = get_definition_manager().get_mapmode_manager().get_mapmode_count();
return type_safe::get(count);
}

String GameSingleton::get_mapmode_identifier(int32_t index) const {
Mapmode const* identifier_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index);
Mapmode const* identifier_mapmode = get_definition_manager()
.get_mapmode_manager()
.get_mapmode_by_index(map_mode_index_t(index));
if (identifier_mapmode != nullptr) {
return convert_to<String>(identifier_mapmode->get_identifier());
}
return String {};
}

String GameSingleton::get_mapmode_localisation_key(int32_t index) const {
Mapmode const* localisation_key_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index);
Mapmode const* localisation_key_mapmode = get_definition_manager()
.get_mapmode_manager()
.get_mapmode_by_index(map_mode_index_t(index));
if (localisation_key_mapmode != nullptr) {
return convert_to<String>(localisation_key_mapmode->get_localisation_key());
}
return String {};
}

int32_t GameSingleton::get_current_mapmode_index() const {
return mapmode->index;
return type_safe::get(mapmode->index);
}

Error GameSingleton::set_mapmode(int32_t index) {
Mapmode const* new_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index);
Mapmode const* new_mapmode = get_definition_manager()
.get_mapmode_manager()
.get_mapmode_by_index(map_mode_index_t(index));
ERR_FAIL_NULL_V_MSG(new_mapmode, FAILED, Utilities::format("Failed to find mapmode with index: %d", index));
mapmode = new_mapmode;
const Error err = _update_colour_image();
emit_signal(_signal_mapmode_changed(), mapmode->index);
emit_signal(_signal_mapmode_changed(), typesafe::get(mapmode->index));
return err;
}

Expand Down
5 changes: 3 additions & 2 deletions extension/src/openvic-extension/singletons/GameSingleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <openvic-simulation/GameManager.hpp>
#include <openvic-simulation/dataloader/Dataloader.hpp>
#include <openvic-simulation/types/TypedIndices.hpp>

namespace OpenVic {

Expand Down Expand Up @@ -106,9 +107,9 @@ namespace OpenVic {

/* The index of the flag in the flag sheet corresponding to the requested country / flag_type
* combination, or -1 if no such flag can be found. */
int32_t get_flag_sheet_index(int32_t country_index, godot::StringName const& flag_type) const;
int32_t get_flag_sheet_index(country_index_t country_index, godot::StringName const& flag_type) const;
godot::Rect2i get_flag_sheet_rect(int32_t flag_index) const;
godot::Rect2i get_flag_sheet_rect(int32_t country_index, godot::StringName const& flag_type) const;
godot::Rect2i get_flag_sheet_rect(country_index_t country_index, godot::StringName const& flag_type) const;

/* Number of (vertical, horizontal) subdivisions the province shape image
* was split into when making the province_shape_texture to ensure no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ PackedByteArray MapItemSingleton::get_rgo_icons() const {
}

GoodDefinition const* rgo_good = prov_inst.get_rgo_good();
icons[index++] = rgo_good != nullptr ? rgo_good->index + 1 : 0; // 0 if no rgo good in the province
icons[index++] = rgo_good != nullptr ? type_safe::get(rgo_good->index) + 1 : 0; // 0 if no rgo good in the province
}

return icons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number)
ProductionType const& production_type = *rgo.get_production_type_nullable();
GoodDefinition const& rgo_good = *province->get_rgo_good();

ret[province_info_rgo_icon_key] = static_cast<int32_t>(rgo_good.index);
ret[province_info_rgo_icon_key] = type_safe::get(rgo_good.index);

ret[province_info_rgo_output_quantity_yesterday_key] = static_cast<real_t>(rgo.get_output_quantity_yesterday());
ret[province_info_rgo_revenue_yesterday_key] = static_cast<real_t>(rgo.get_revenue_yesterday());
Expand Down
40 changes: 21 additions & 19 deletions extension/src/openvic-extension/singletons/PlayerSingleton.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "PlayerSingleton.hpp"

#include <type_safe/strong_typedef.hpp>

#include <openvic-simulation/country/CountryInstance.hpp>
#include <openvic-simulation/map/ProvinceInstance.hpp>

Expand Down Expand Up @@ -98,7 +100,7 @@ void PlayerSingleton::set_player_country(CountryInstance* new_player_country) {
if (player_country != nullptr) {
instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_SET_AI,
std::pair<uint64_t, bool> { player_country->index, true }
std::pair<uint64_t, bool> { type_safe::get(player_country->index), true }
);
}

Expand All @@ -107,7 +109,7 @@ void PlayerSingleton::set_player_country(CountryInstance* new_player_country) {
if (player_country != nullptr) {
instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_SET_AI,
std::pair<uint64_t, bool> { player_country->index, false }
std::pair<uint64_t, bool> { type_safe::get(player_country->index), false }
);
}

Expand Down Expand Up @@ -150,21 +152,21 @@ void PlayerSingleton::set_selected_province(ProvinceInstance const* new_selected
}

void PlayerSingleton::set_selected_province_by_number(int32_t province_number) {
if (province_number == ProvinceDefinition::NULL_INDEX) {
MapInstance const& map_instance = instance_manager->get_map_instance();
const province_index_t province_index = ProvinceDefinition::get_index_from_province_number(province_number);
if (province_index == ProvinceDefinition::NULL_INDEX) {
unset_selected_province();
} else {
InstanceManager const* instance_manager = GameSingleton::get_singleton()->get_instance_manager();
ERR_FAIL_NULL(instance_manager);

MapInstance const& map_instance = instance_manager->get_map_instance();

set_selected_province(map_instance.get_province_instance_from_number(province_number));

ProvinceInstance const* const selected_province = map_instance.get_province_instance_from_index(province_index);
if (selected_province == nullptr) {
spdlog::error_s(
"Trying to set selected province to an invalid number {} (max number is {})",
map_instance.get_province_instance_by_definition().get_count(), province_number
);
} else {
InstanceManager const* instance_manager = GameSingleton::get_singleton()->get_instance_manager();
ERR_FAIL_NULL(instance_manager);
set_selected_province(selected_province);
}
}
}
Expand Down Expand Up @@ -217,7 +219,7 @@ void PlayerSingleton::expand_selected_province_building(int32_t building_index)

instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_EXPAND_PROVINCE_BUILDING,
std::pair<uint64_t, uint64_t> { selected_province->index, building_index }
std::pair<uint64_t, uint64_t> { type_safe::get(selected_province->index), building_index }
);
}

Expand All @@ -229,7 +231,7 @@ void PlayerSingleton::set_##value_name##_slider_value(fixed_point_t const value)
} \
GameSingleton::get_singleton()->get_instance_manager()->queue_game_action( \
game_action_type_t::GAME_ACTION_SET_##game_action_name, \
std::pair<uint64_t, fixed_point_t> { player_country->index, value } \
std::pair<uint64_t, fixed_point_t> { type_safe::get(player_country->index), value } \
); \
}

Expand All @@ -250,7 +252,7 @@ void PlayerSingleton::set_strata_tax_rate_slider_value(Strata const& strata, fix
}
GameSingleton::get_singleton()->get_instance_manager()->queue_game_action(
game_action_type_t::GAME_ACTION_SET_STRATA_TAX,
std::tuple<uint64_t, uint64_t, fixed_point_t> { player_country->index, strata.index, value }
std::tuple<uint64_t, uint64_t, fixed_point_t> { type_safe::get(player_country->index), strata.index, value }
);
}

Expand All @@ -269,7 +271,7 @@ void PlayerSingleton::set_good_automated(int32_t good_index, bool is_automated)

instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_SET_GOOD_AUTOMATED,
std::tuple<uint64_t, uint64_t, bool> { player_country->index, good_index, is_automated }
std::tuple<uint64_t, uint64_t, bool> { type_safe::get(player_country->index), good_index, is_automated }
);
}

Expand All @@ -282,7 +284,7 @@ void PlayerSingleton::set_good_trade_order(int32_t good_index, bool is_selling,

instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_SET_GOOD_TRADE_ORDER, std::tuple<uint64_t, uint64_t, bool, fixed_point_t> {
player_country->index, good_index, is_selling,
type_safe::get(player_country->index), good_index, is_selling,
MenuSingleton::calculate_trade_menu_stockpile_cutoff_amount_fp(amount_slider->get_value_scaled_fp())
}
);
Expand All @@ -299,7 +301,7 @@ void PlayerSingleton::create_leader(bool is_general) const {

instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_CREATE_LEADER,
std::pair<uint64_t, bool> { player_country->index, is_general }
std::pair<uint64_t, bool> { type_safe::get(player_country->index), is_general }
);
}

Expand All @@ -321,7 +323,7 @@ void PlayerSingleton::set_auto_create_leaders(bool value) const {

instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_SET_AUTO_CREATE_LEADERS,
std::pair<uint64_t, bool> { player_country->index, value }
std::pair<uint64_t, bool> { type_safe::get(player_country->index), value }
);
}

Expand All @@ -333,7 +335,7 @@ void PlayerSingleton::set_auto_assign_leaders(bool value) const {

instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_SET_AUTO_ASSIGN_LEADERS,
std::pair<uint64_t, bool> { player_country->index, value }
std::pair<uint64_t, bool> { type_safe::get(player_country->index), value }
);
}

Expand All @@ -345,6 +347,6 @@ void PlayerSingleton::set_mobilise(bool value) const {

instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_SET_MOBILISE,
std::pair<uint64_t, bool> { player_country->index, value }
std::pair<uint64_t, bool> { type_safe::get(player_country->index), value }
);
}
5 changes: 3 additions & 2 deletions extension/src/openvic-extension/singletons/PopulationMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>
#include <openvic-simulation/types/IndexedFlatMap.hpp>
#include <openvic-simulation/types/OrderedContainersMath.hpp>
#include <openvic-simulation/types/TypedIndices.hpp>

#include "openvic-extension/classes/GFXPieChartTexture.hpp"
#include "openvic-extension/classes/GUINode.hpp"
Expand Down Expand Up @@ -261,7 +262,7 @@ Error MenuSingleton::population_menu_select_province_list_entry(int32_t select_i
}

Error MenuSingleton::population_menu_select_province(int32_t province_number) {
const ProvinceDefinition::index_t province_index = ProvinceDefinition::get_index_from_province_number(province_number);
const province_index_t province_index = ProvinceDefinition::get_index_from_province_number(province_number);
GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, FAILED);
InstanceManager const* instance_manager = game_singleton->get_instance_manager();
Expand All @@ -276,7 +277,7 @@ Error MenuSingleton::population_menu_select_province(int32_t province_number) {

MenuSingleton& menu_singleton;

const ProvinceDefinition::index_t _province_index = 0;
const province_index_t _province_index = province_index_t(0);

int32_t index = 0;

Expand Down
4 changes: 2 additions & 2 deletions extension/src/openvic-extension/singletons/TradeMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ Dictionary MenuSingleton::get_trade_menu_trade_details_info(
InstanceManager const* instance_manager = GameSingleton::get_singleton()->get_instance_manager();
ERR_FAIL_NULL_V(instance_manager, {});

GoodInstance const* good_instance =
instance_manager->get_good_instance_manager().get_good_instance_by_index(trade_detail_good_index);
GoodInstance const* good_instance = instance_manager->get_good_instance_manager()
.get_good_instance_by_index(good_index_t(trade_detail_good_index));
ERR_FAIL_NULL_V(good_instance, {});

CountryInstance const* country = PlayerSingleton::get_singleton()->get_player_country();
Expand Down
Loading