Skip to content
Merged
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 53 files
+113 −0 src/openvic-simulation/core/Assert.hpp
+13 −4 src/openvic-simulation/core/template/Concepts.hpp
+96 −76 src/openvic-simulation/country/CountryInstance.cpp
+3 −3 src/openvic-simulation/country/CountryInstance.hpp
+2 −2 src/openvic-simulation/dataloader/Dataloader.cpp
+40 −12 src/openvic-simulation/dataloader/NodeTools.hpp
+1 −1 src/openvic-simulation/defines/CountryDefines.cpp
+2 −2 src/openvic-simulation/defines/CountryDefines.hpp
+3 −8 src/openvic-simulation/defines/MilitaryDefines.cpp
+1 −1 src/openvic-simulation/defines/MilitaryDefines.hpp
+3 −3 src/openvic-simulation/defines/PopsDefines.cpp
+5 −5 src/openvic-simulation/defines/PopsDefines.hpp
+2 −2 src/openvic-simulation/economy/BuildingInstance.hpp
+26 −0 src/openvic-simulation/economy/BuildingLevel.hpp
+2 −2 src/openvic-simulation/economy/BuildingType.cpp
+2 −2 src/openvic-simulation/economy/BuildingType.hpp
+3 −3 src/openvic-simulation/economy/production/ArtisanalProducer.cpp
+1 −1 src/openvic-simulation/economy/production/ArtisanalProducer.hpp
+1 −1 src/openvic-simulation/economy/production/Employee.hpp
+1 −1 src/openvic-simulation/economy/production/FactoryProducer.hpp
+2 −1 src/openvic-simulation/economy/production/ProductionType.cpp
+1 −1 src/openvic-simulation/economy/production/ProductionType.hpp
+38 −22 src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
+4 −3 src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
+1 −1 src/openvic-simulation/history/CountryHistory.cpp
+1 −1 src/openvic-simulation/history/CountryHistory.hpp
+4 −4 src/openvic-simulation/history/ProvinceHistory.cpp
+2 −2 src/openvic-simulation/history/ProvinceHistory.hpp
+26 −0 src/openvic-simulation/map/LifeRating.hpp
+1 −1 src/openvic-simulation/map/MapInstance.cpp
+3 −2 src/openvic-simulation/map/MapInstance.hpp
+5 −5 src/openvic-simulation/map/Mapmode.cpp
+2 −2 src/openvic-simulation/map/ProvinceInstance.hpp
+7 −7 src/openvic-simulation/population/Pop.cpp
+4 −2 src/openvic-simulation/population/Pop.hpp
+6 −3 src/openvic-simulation/population/PopManager.cpp
+69 −0 src/openvic-simulation/population/PopSize.hpp
+111 −0 src/openvic-simulation/population/PopSum.hpp
+1 −1 src/openvic-simulation/population/PopType.hpp
+77 −56 src/openvic-simulation/population/PopsAggregate.cpp
+18 −9 src/openvic-simulation/population/PopsAggregate.hpp
+29 −0 src/openvic-simulation/research/TechnologyUnlockLevel.hpp
+0 −7 src/openvic-simulation/types/BuildingLevel.hpp
+2 −2 src/openvic-simulation/types/Colour.hpp
+29 −10 src/openvic-simulation/types/CowVector.hpp
+7 −6 src/openvic-simulation/types/FixedVector.hpp
+5 −63 src/openvic-simulation/types/IndexedFlatMap.hpp
+0 −7 src/openvic-simulation/types/PopSize.hpp
+0 −7 src/openvic-simulation/types/ProvinceLifeRating.hpp
+30 −9 src/openvic-simulation/types/RingBuffer.hpp
+2 −0 src/openvic-simulation/types/StackString.hpp
+0 −7 src/openvic-simulation/types/TechnologyUnlockLevel.hpp
+43 −2 src/openvic-simulation/types/fixed_point/FixedPoint.hpp
17 changes: 15 additions & 2 deletions extension/src/openvic-extension/classes/GFXPieChartTexture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename MapType>
Expand All @@ -19,7 +20,13 @@ namespace OpenVic {
|| specialization_of<MapType, IndexedFlatMap>
)
&& has_get_identifier_and_colour<std::remove_pointer_t<map_key_t<MapType>>>
&& requires { static_cast<float>(std::declval<map_value_t<MapType>>()); };
&& (
requires { static_cast<float>(std::declval<map_value_t<MapType>>()); }
|| (
is_strongly_typed<map_value_t<MapType>>
&& requires { static_cast<float>(type_safe::get(std::declval<map_value_t<MapType>>())); }
)
);

class GFXPieChartTexture : public godot::ImageTexture {
GDCLASS(GFXPieChartTexture, godot::ImageTexture)
Expand Down Expand Up @@ -79,7 +86,13 @@ namespace OpenVic {
} else {
key_ptr = &key_ref_or_ptr;
}
const float value = static_cast<float>(non_float_value);

float value;
if constexpr (is_strongly_typed<decltype(non_float_value)>) {
value = static_cast<float>(type_safe::get(non_float_value));
} else {
value = static_cast<float>(non_float_value);
}

if (value > 0.0f) {
sorted_distribution.emplace_back(key_ptr, value);
Expand Down
39 changes: 23 additions & 16 deletions extension/src/openvic-extension/singletons/MenuSingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static TypedArray<Dictionary> _make_buildings_dict_array(
BuildingInstance const& building = buildings[idx];

Dictionary building_dict;
building_dict[building_info_level_key] = static_cast<int32_t>(building.get_level());
building_dict[building_info_level_key] = static_cast<int32_t>(type_safe::get(building.get_level()));
building_dict[building_info_expansion_state_key] = static_cast<int32_t>(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());
Expand Down Expand Up @@ -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) {
Expand All @@ -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<real_t>(rgo.get_output_quantity_yesterday());
ret[province_info_rgo_revenue_yesterday_key] = static_cast<real_t>(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;
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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<String>(pop_type.get_identifier())),
employees_of_type
type_safe::get(employees_of_type)
);

for (Job const& job : production_type.get_jobs()) {
Expand All @@ -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());
Expand Down Expand Up @@ -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<int32_t>(rgo.get_size_multiplier()) // TODO - remove cast once variable is an int32_t
Expand All @@ -896,7 +897,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number)
ret[province_info_crime_icon_key] = static_cast<int32_t>(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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <godot_cpp/classes/image.hpp>

#include <openvic-simulation/military/UnitInstanceGroup.hpp>
#include <openvic-simulation/population/PopSize.hpp>
#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>
#include <openvic-simulation/types/IndexedFlatMap.hpp>
#include <openvic-simulation/types/PopSize.hpp>
#include <openvic-simulation/types/OrderedContainers.hpp>
#include <openvic-simulation/types/UnitBranchType.hpp>

Expand Down
10 changes: 5 additions & 5 deletions extension/src/openvic-extension/singletons/ModelSingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,21 @@ 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()) {
suffix += "_ships";
}
} 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)
Expand Down
18 changes: 10 additions & 8 deletions extension/src/openvic-extension/singletons/PopulationMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <type_traits>

#include <godot_cpp/variant/utility_functions.hpp>
#include <type_safe/strong_typedef.hpp>

#include <openvic-simulation/DefinitionManager.hpp>
#include <openvic-simulation/InstanceManager.hpp>
#include <openvic-simulation/map/ProvinceDefinition.hpp>
#include <openvic-simulation/map/ProvinceInstance.hpp>
#include <openvic-simulation/population/Culture.hpp>
#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>
#include <openvic-simulation/types/IndexedFlatMap.hpp>
Expand Down Expand Up @@ -118,7 +120,7 @@ TypedArray<Dictionary> 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;

Expand All @@ -139,7 +141,7 @@ TypedArray<Dictionary> 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;
Expand All @@ -160,7 +162,7 @@ TypedArray<Dictionary> 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<String>(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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -802,7 +804,7 @@ TypedArray<Dictionary> 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<String>(pop->culture.get_identifier());
pop_dict[pop_religion_icon_key] = pop->religion.icon;
Expand All @@ -824,7 +826,7 @@ TypedArray<Dictionary> 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<real_t>(pop->get_literacy());

array[idx] = std::move(pop_dict);
Expand Down Expand Up @@ -878,8 +880,8 @@ TypedArray<Dictionary> 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);
Expand Down
Loading