diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation index 56462305..c8d3d19a 160000 --- a/extension/deps/openvic-simulation +++ b/extension/deps/openvic-simulation @@ -1 +1 @@ -Subproject commit 56462305f312cabb69cd21234bfaa33883a31707 +Subproject commit c8d3d19a080c347f914fa489618287a69060c924 diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp index 46db1ec8..2a5ae530 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp @@ -9,6 +9,7 @@ #include "openvic-extension/core/Convert.hpp" #include "openvic-extension/utility/MapHelpers.hpp" +#include "openvic-simulation/core/template/Concepts.hpp" namespace OpenVic { template @@ -19,7 +20,13 @@ namespace OpenVic { || specialization_of ) && has_get_identifier_and_colour>> - && requires { static_cast(std::declval>()); }; + && ( + requires { static_cast(std::declval>()); } + || ( + is_strongly_typed> + && requires { static_cast(type_safe::get(std::declval>())); } + ) + ); class GFXPieChartTexture : public godot::ImageTexture { GDCLASS(GFXPieChartTexture, godot::ImageTexture) @@ -79,7 +86,13 @@ namespace OpenVic { } else { key_ptr = &key_ref_or_ptr; } - const float value = static_cast(non_float_value); + + float value; + if constexpr (is_strongly_typed) { + value = static_cast(type_safe::get(non_float_value)); + } else { + value = static_cast(non_float_value); + } if (value > 0.0f) { sorted_distribution.emplace_back(key_ptr, value); diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp index 0569be78..10a349da 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp @@ -432,7 +432,7 @@ static TypedArray _make_buildings_dict_array( BuildingInstance const& building = buildings[idx]; Dictionary building_dict; - building_dict[building_info_level_key] = static_cast(building.get_level()); + building_dict[building_info_level_key] = static_cast(type_safe::get(building.get_level())); building_dict[building_info_expansion_state_key] = static_cast(building.get_expansion_state()); building_dict[building_info_start_date_key] = Utilities::date_to_string(building.get_start_date()); building_dict[building_info_end_date_key] = Utilities::date_to_string(building.get_end_date()); @@ -519,7 +519,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) ret[province_info_terrain_type_key] = std::move(terrain_type_string); } - ret[province_info_life_rating_key] = province->get_life_rating(); + ret[province_info_life_rating_key] = type_safe::get(province->get_life_rating()); CountryInstance const* controller = province->get_controller(); if (controller != nullptr) { @@ -544,7 +544,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) ret[province_info_rgo_output_quantity_yesterday_key] = static_cast(rgo.get_output_quantity_yesterday()); ret[province_info_rgo_revenue_yesterday_key] = static_cast(rgo.get_revenue_yesterday()); - ret[province_info_rgo_total_employees_key] = rgo.get_total_employees_count_cache(); + ret[province_info_rgo_total_employees_key] = type_safe::get(rgo.get_total_employees_count_cache()); const pop_size_t max_employee_count = rgo.get_max_employee_count_cache(); if (max_employee_count == 0) { ret[province_info_rgo_employment_percentage_key] = 100.0f; @@ -576,11 +576,12 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) *province, owner_pop_type ); } else { - fixed_point_t effect_value = owner_job->get_effect_multiplier() * state->get_population_by_type(owner_pop_type); - - if (effect_value != fixed_point_t::_0) { - effect_value /= state->get_total_population(); - } + const fixed_point_t effect_value = state->get_total_population() == 0 + ? fixed_point_t::_0 + : owner_job->get_effect_multiplier().mul_div( + state->get_population_by_type(owner_pop_type), + state->get_total_population() + ); static const StringName owners_localisation_key = "PRODUCTION_FACTOR_OWNER"; @@ -626,7 +627,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) amount_of_employees_by_pop_type += Utilities::format( amount_of_employees_by_pop_type_template_string, tr(convert_to(pop_type.get_identifier())), - employees_of_type + type_safe::get(employees_of_type) ); for (Job const& job : production_type.get_jobs()) { @@ -635,7 +636,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) } const fixed_point_t effect_multiplier = job.get_effect_multiplier(); - fixed_point_t relative_to_workforce = fixed_point_t(employees_of_type) / max_employee_count; + fixed_point_t relative_to_workforce = fixed_point_t::from_fraction(employees_of_type, max_employee_count); const fixed_point_t effect_value = effect_multiplier == fixed_point_t::_1 ? relative_to_workforce : effect_multiplier * std::min(relative_to_workforce, job.get_amount()); @@ -877,13 +878,13 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) rgo_employment_template_string, tr(employment_localisation_key).replace(Utilities::get_long_value_placeholder(), {}), tr(employee_count_localisation_key).replace( - employee_replace_key, String::num_int64(rgo.get_total_employees_count_cache()) + employee_replace_key, String::num_int64(type_safe::get(rgo.get_total_employees_count_cache())) ).replace( - employee_max_replace_key, String::num_int64(rgo.get_max_employee_count_cache()) + employee_max_replace_key, String::num_int64(type_safe::get(rgo.get_max_employee_count_cache())) ), amount_of_employees_by_pop_type, tr(rgo_workforce_localisation_key), - production_type.base_workforce_size, + type_safe::get(production_type.base_workforce_size), size_string, tr(province_size_localisation_key), static_cast(rgo.get_size_multiplier()) // TODO - remove cast once variable is an int32_t @@ -896,7 +897,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) ret[province_info_crime_icon_key] = static_cast(crime->icon); } - ret[province_info_total_population_key] = province->get_total_population(); + ret[province_info_total_population_key] = type_safe::get(province->get_total_population()); const auto make_pie_chart_tooltip = [this]( has_get_identifier_and_colour auto const* key, String const& identifier, float weight, float total_weight @@ -1098,7 +1099,10 @@ Dictionary MenuSingleton::get_topbar_info() const { Utilities::fixed_point_to_string_dp(research_points, 2) ).replace( fraction_replace_key, Utilities::fixed_point_to_string_dp( - fixed_point_t::_100 * country->get_population_by_type(*pop_type) / country->get_total_population(), 2 + fixed_point_t::from_fraction( + 100 * country->get_population_by_type(*pop_type), + country->get_total_population() + ), 2 ) ).replace( optimal_replace_key, Utilities::fixed_point_to_string_dp(100 * pop_type->research_leadership_optimum, 2) @@ -1203,7 +1207,10 @@ Dictionary MenuSingleton::get_topbar_info() const { Utilities::fixed_point_to_string_dp(leadership_points, 2) ).replace( fraction_replace_key, Utilities::fixed_point_to_string_dp( - fixed_point_t::_100 * country->get_population_by_type(*pop_type) / country->get_total_population(), 2 + fixed_point_t::from_fraction( + 100 * country->get_population_by_type(*pop_type), + country->get_total_population() + ), 2 ) ).replace( optimal_replace_key, Utilities::fixed_point_to_string_dp(100 * pop_type->research_leadership_optimum, 2) diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp index 6fe096a9..2efb2cca 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp @@ -7,9 +7,9 @@ #include #include +#include #include #include -#include #include #include diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp index 7102562a..c0f01f7c 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp @@ -409,8 +409,8 @@ bool ModelSingleton::add_building_dict( return true; } - if (building.get_level() > 0) { - suffix = std::to_string(building.get_level()); + if (building.get_level() > building_level_t(0)) { + suffix = std::to_string(type_safe::get(building.get_level())); } if (!province.get_navies().empty()) { @@ -418,12 +418,12 @@ bool ModelSingleton::add_building_dict( } } else if (building.get_identifier() == "fort") { /* Fort */ - if (building.get_level() < 1) { + if (building.get_level() < building_level_t(1)) { return true; } - if (building.get_level() > 1) { - suffix = std::to_string(building.get_level()); + if (building.get_level() > building_level_t(1)) { + suffix = std::to_string(type_safe::get(building.get_level())); } } else { // TODO - railroad (trainstations) diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index a938dbd4..485902da 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -3,10 +3,12 @@ #include #include +#include #include #include #include +#include #include #include #include @@ -118,7 +120,7 @@ TypedArray MenuSingleton::get_population_menu_province_list_rows(int country_dict[type_key] = LIST_ENTRY_COUNTRY; country_dict[index_key] = index; country_dict[name_key] = Utilities::get_country_name(menu_singleton, country_entry.country); - country_dict[size_key] = country_entry.country.get_total_population(); + country_dict[size_key] = type_safe::get(country_entry.country.get_total_population()); country_dict[change_key] = 0; country_dict[selected_key] = country_entry.selected; @@ -139,7 +141,7 @@ TypedArray MenuSingleton::get_population_menu_province_list_rows(int state_dict[type_key] = LIST_ENTRY_STATE; state_dict[index_key] = index; state_dict[name_key] = Utilities::get_state_name(menu_singleton, state_entry.state); - state_dict[size_key] = state_entry.state.get_total_population(); + state_dict[size_key] = type_safe::get(state_entry.state.get_total_population()); state_dict[change_key] = 0; state_dict[selected_key] = state_entry.selected; state_dict[expanded_key] = state_entry.expanded; @@ -160,7 +162,7 @@ TypedArray MenuSingleton::get_population_menu_province_list_rows(int province_dict[type_key] = LIST_ENTRY_PROVINCE; province_dict[index_key] = index; province_dict[name_key] = convert_to(province_entry.province.get_identifier()); - province_dict[size_key] = province_entry.province.get_total_population(); + province_dict[size_key] = type_safe::get(province_entry.province.get_total_population()); province_dict[change_key] = 0; province_dict[selected_key] = province_entry.selected; @@ -403,7 +405,7 @@ Error MenuSingleton::_population_menu_update_filtered_pops() { } for (Pop const* pop : population_menu.filtered_pops) { - const fixed_point_t pop_size = fixed_point_t(pop->get_size()); + const fixed_point_t pop_size = fixed_point_t(type_safe::get(pop->get_size())); population_menu.workforce_distribution[pop->get_type()] += pop_size; population_menu.religion_distribution[&pop->religion] += pop_size; @@ -802,7 +804,7 @@ TypedArray MenuSingleton::get_population_menu_pop_rows(int32_t start Pop const* pop = population_menu.filtered_pops[start + idx]; Dictionary pop_dict; - pop_dict[pop_size_key] = pop->get_size(); + pop_dict[pop_size_key] = type_safe::get(pop->get_size()); pop_dict[pop_type_icon_key] = pop->get_type()->sprite; pop_dict[pop_culture_key] = convert_to(pop->culture.get_identifier()); pop_dict[pop_religion_icon_key] = pop->religion.icon; @@ -824,7 +826,7 @@ TypedArray MenuSingleton::get_population_menu_pop_rows(int32_t start if (pop->get_rebel_type() != nullptr) { pop_dict[pop_rebel_icon_key] = pop->get_rebel_type()->icon; } - pop_dict[pop_size_change_key] = pop->get_total_change(); + pop_dict[pop_size_change_key] = type_safe::get(pop->get_total_change()); pop_dict[pop_literacy_key] = static_cast(pop->get_literacy()); array[idx] = std::move(pop_dict); @@ -878,8 +880,8 @@ TypedArray MenuSingleton::get_population_menu_pop_filter_info() cons Dictionary filter_dict; - filter_dict[pop_filter_count_key] = filter.count; - filter_dict[pop_filter_change_key] = filter.promotion_demotion_change; + filter_dict[pop_filter_count_key] = type_safe::get(filter.count); + filter_dict[pop_filter_change_key] = type_safe::get(filter.promotion_demotion_change); filter_dict[pop_filter_selected_key] = filter.selected; array[idx] = std::move(filter_dict);