Skip to content

Commit 3c60f53

Browse files
authored
Merge pull request #656 from OpenVicProject/dependabot/submodules/extension/deps/openvic-simulation-d6b9312
Bump extension/deps/openvic-simulation from `0a08ff2` to `d6b9312`
2 parents f9ea650 + 543fced commit 3c60f53

10 files changed

Lines changed: 157 additions & 150 deletions

File tree

extension/deps/openvic-simulation

Submodule openvic-simulation updated 35 files

extension/src/openvic-extension/singletons/GameSingleton.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <cstdint>
44
#include <functional>
5+
#include <range/v3/algorithm/contains.hpp>
56
#include <type_safe/strong_typedef.hpp>
67

78
#include <godot_cpp/classes/time.hpp>
@@ -163,7 +164,7 @@ TypedArray<Dictionary> GameSingleton::get_mod_info() const {
163164
TypedArray<Dictionary> results;
164165

165166
ModManager const& mod_manager = game_manager.get_mod_manager();
166-
memory::vector<Mod const*> const& loaded_mods = mod_manager.get_loaded_mods();
167+
const forwardable_span<const std::reference_wrapper<const Mod>> loaded_mods = mod_manager.get_loaded_mods();
167168

168169
for (Mod const& mod : mod_manager.get_mods()) {
169170
Dictionary mod_info_dictionary;
@@ -178,8 +179,11 @@ TypedArray<Dictionary> GameSingleton::get_mod_info() const {
178179
return result;
179180
}();
180181

181-
mod_info_dictionary[is_loaded_key] = ranges::contains(loaded_mods, &mod);
182-
182+
mod_info_dictionary[is_loaded_key] = ranges::contains(
183+
loaded_mods,
184+
mod,
185+
[](Mod const& x) -> decltype(auto) { return x; }
186+
);
183187
results.push_back(std::move(mod_info_dictionary));
184188
}
185189

extension/src/openvic-extension/singletons/MapItemSingleton.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ int32_t MapItemSingleton::get_clicked_port_province_number(Vector2 click_positio
320320
else if(province->is_water()){
321321
// search the adjacent provinces for ones with ports
322322
for(ProvinceDefinition::adjacency_t const& adjacency : province->get_adjacencies()) {
323-
const type_safe::object_ref<const ProvinceDefinition> adjacent_province = adjacency.get_to();
324-
if(!adjacent_province->has_port()) {
323+
ProvinceDefinition const& adjacent_province = adjacency.get_to();
324+
if(!adjacent_province.has_port()) {
325325
continue; // skip provinces without ports (ie. other water provinces)
326326
}
327-
Vector2 port_position = game_singleton->normalise_map_position(*adjacent_province->get_building_position(port_building_type));
327+
Vector2 port_position = game_singleton->normalise_map_position(*adjacent_province.get_building_position(port_building_type));
328328
if(click_position.distance_to(port_position) <= port_radius){
329-
return adjacent_province->get_province_number();
329+
return adjacent_province.get_province_number();
330330
}
331331
}
332332
}

extension/src/openvic-extension/singletons/MenuSingleton.cpp

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ String MenuSingleton::_make_rules_tooltip(RuleSet const& rules) const {
153153
}
154154

155155
String MenuSingleton::_make_mobilisation_impact_tooltip() const {
156-
CountryInstance const* country = PlayerSingleton::get_singleton()->get_player_country();
156+
CountryInstance const* country_ptr = PlayerSingleton::get_singleton()->get_player_country();
157157

158-
if (country == nullptr) {
158+
if (country_ptr == nullptr) {
159159
return {};
160160
}
161161

162+
CountryInstance const& country = *country_ptr;
163+
162164
IssueManager const& issue_manager =
163165
GameSingleton::get_singleton()->get_definition_manager().get_politics_manager().get_issue_manager();
164166

@@ -176,9 +178,9 @@ String MenuSingleton::_make_mobilisation_impact_tooltip() const {
176178
PartyPolicyGroup const* war_policy_issue_group = issue_manager.get_party_policy_group_by_identifier("war_policy");
177179
PartyPolicy const* war_policy_issue = war_policy_issue_group == nullptr
178180
? nullptr
179-
: country->get_ruling_party_untracked()->get_policies(*war_policy_issue_group);
181+
: country.get_ruling_party_untracked()->get_policies(*war_policy_issue_group);
180182

181-
const String impact_string = Utilities::fixed_point_to_string_dp(country->get_mobilisation_impact() * 100, 1) + "%";
183+
const String impact_string = Utilities::fixed_point_to_string_dp(country.get_mobilisation_impact() * 100, 1) + "%";
182184

183185
return tr(
184186
mobilisation_impact_tooltip_localisation_key
@@ -192,11 +194,11 @@ String MenuSingleton::_make_mobilisation_impact_tooltip() const {
192194
)
193195
).replace(
194196
mobilisation_impact_tooltip_replace_units_key,
195-
String::num_uint64(country->get_mobilisation_max_regiment_count())
197+
String::num_uint64(country.get_mobilisation_max_regiment_count())
196198
) + "\n" + tr(
197199
mobilisation_impact_tooltip2_localisation_key
198200
).replace(
199-
mobilisation_impact_tooltip2_replace_curr_key, String::num_uint64(country->get_regiment_count())
201+
mobilisation_impact_tooltip2_replace_curr_key, String::num_uint64(country.get_regiment_count())
200202
).replace(
201203
mobilisation_impact_tooltip2_replace_impact_key, impact_string
202204
);
@@ -996,11 +998,13 @@ int32_t MenuSingleton::get_rgo_owner_pop_icon_index() const {
996998
/* TOPBAR */
997999

9981000
Dictionary MenuSingleton::get_topbar_info() const {
999-
CountryInstance* country = PlayerSingleton::get_singleton()->get_player_country();
1000-
if (country == nullptr) {
1001+
CountryInstance* country_ptr = PlayerSingleton::get_singleton()->get_player_country();
1002+
if (country_ptr == nullptr) {
10011003
return {};
10021004
}
10031005

1006+
CountryInstance& country = *country_ptr;
1007+
10041008
DefinitionManager const& definition_manager = GameSingleton::get_singleton()->get_definition_manager();
10051009
ModifierEffectCache const& modifier_effect_cache = definition_manager.get_modifier_manager().get_modifier_effect_cache();
10061010

@@ -1011,9 +1015,9 @@ Dictionary MenuSingleton::get_topbar_info() const {
10111015
static const StringName country_status_key = "country_status";
10121016
static const StringName total_rank_key = "total_rank";
10131017

1014-
ret[country_key] = convert_to<String>(country->get_identifier());
1015-
ret[country_status_key] = static_cast<int32_t>(country->get_country_status());
1016-
ret[total_rank_key] = static_cast<uint64_t>(country->get_total_rank());
1018+
ret[country_key] = convert_to<String>(country.get_identifier());
1019+
ret[country_status_key] = static_cast<int32_t>(country.get_country_status());
1020+
ret[total_rank_key] = static_cast<uint64_t>(country.get_total_rank());
10171021

10181022
// Production
10191023

@@ -1029,7 +1033,7 @@ Dictionary MenuSingleton::get_topbar_info() const {
10291033
static const StringName research_points_key = "research_points";
10301034
static const StringName research_points_tooltip_key = "research_points_tooltip";
10311035

1032-
Technology const* current_research = country->get_current_research_untracked();
1036+
Technology const* current_research = country.get_current_research_untracked();
10331037
if (current_research != nullptr) {
10341038
static const StringName research_localisation_key = "TECHNOLOGYVIEW_RESEARCH_TOOLTIP";
10351039
static const String tech_replace_key = "$TECH$";
@@ -1043,15 +1047,15 @@ Dictionary MenuSingleton::get_topbar_info() const {
10431047
ret[research_tooltip_key] = tr(research_localisation_key).replace(
10441048
tech_replace_key, current_tech_localised
10451049
).replace(
1046-
date_replace_key, Utilities::date_to_formatted_string(country->get_expected_research_completion_date_untracked(), false)
1050+
date_replace_key, Utilities::date_to_formatted_string(country.get_expected_research_completion_date_untracked(), false)
10471051
) + "\n" + tr(research_invested_localisation_key).replace(
1048-
invested_replace_key, String::num_uint64(country->get_invested_research_points_untracked().truncate<int64_t>())
1049-
).replace(cost_replace_key, String::num_uint64(country->get_current_research_cost_untracked().truncate<int64_t>()));
1052+
invested_replace_key, String::num_uint64(country.get_invested_research_points_untracked().truncate<int64_t>())
1053+
).replace(cost_replace_key, String::num_uint64(country.get_current_research_cost_untracked().truncate<int64_t>()));
10501054

10511055
ret[research_key] = std::move(current_tech_localised);
10521056

1053-
ret[research_progress_key] = static_cast<real_t>(country->research_progress.get_untracked());
1054-
} else if (country->is_civilised()) {
1057+
ret[research_progress_key] = static_cast<real_t>(country.research_progress.get_untracked());
1058+
} else if (country.is_civilised()) {
10551059
static const StringName civilised_no_research_localisation_key = "TB_TECH_NO_CURRENT";
10561060
static const StringName civilised_no_research_tooltip_localisation_key = "TECHNOLOGYVIEW_NO_RESEARCH_TOOLTIP";
10571061

@@ -1067,17 +1071,17 @@ Dictionary MenuSingleton::get_topbar_info() const {
10671071
ret[research_tooltip_key] = tr(uncivilised_no_research_tooltip_localisation_key);
10681072
}
10691073

1070-
ret[literacy_key] = static_cast<real_t>(country->get_average_literacy());
1074+
ret[literacy_key] = static_cast<real_t>(country.get_average_literacy());
10711075
// TODO - set monthly literacy change (test for precision issues)
10721076
ret[literacy_change_key] = 0.0f;
10731077

1074-
ret[research_points_key] = static_cast<real_t>(country->get_daily_research_points_untracked());
1078+
ret[research_points_key] = static_cast<real_t>(country.get_daily_research_points_untracked());
10751079

10761080
String research_points_tooltip;
10771081

10781082
fixed_point_t daily_base_research_points;
10791083

1080-
for (auto const& [pop_type, research_points] : country->get_research_points_from_pop_types()) {
1084+
for (auto const& [pop_type, research_points] : country.get_research_points_from_pop_types()) {
10811085
static const StringName pop_type_research_localisation_key = "TECH_DAILY_RESEARCHPOINTS_TOOLTIP";
10821086
static const String pop_type_replace_key = "$POPTYPE$";
10831087
static const String fraction_replace_key = "$FRACTION$";
@@ -1093,8 +1097,8 @@ Dictionary MenuSingleton::get_topbar_info() const {
10931097
).replace(
10941098
fraction_replace_key, Utilities::fixed_point_to_string_dp(
10951099
fixed_point_t::from_fraction(
1096-
100 * country->get_population_by_type(*pop_type),
1097-
country->get_total_population()
1100+
100 * country.get_population_by_type(*pop_type),
1101+
country.get_total_population()
10981102
), 2
10991103
)
11001104
).replace(
@@ -1105,7 +1109,7 @@ Dictionary MenuSingleton::get_topbar_info() const {
11051109
// Empty prefix, "\n" suffix, fitting with the potential trailing "\n" from the pop type contributions and the upcoming
11061110
// guaranteed daily base research points line. All contributions are added to daily_base_research_points.
11071111
research_points_tooltip += _make_modifier_effect_contributions_tooltip(
1108-
*country, *modifier_effect_cache.get_research_points(), &daily_base_research_points, {}, "\n"
1112+
country, *modifier_effect_cache.get_research_points(), &daily_base_research_points, {}, "\n"
11091113
);
11101114

11111115
// The daily base research points line is guaranteed to be present, but those directly above and below it aren't,
@@ -1118,11 +1122,12 @@ Dictionary MenuSingleton::get_topbar_info() const {
11181122
);
11191123

11201124
research_points_tooltip += _make_modifier_effect_contributions_tooltip(
1121-
*country, *modifier_effect_cache.get_research_points_modifier()
1125+
country, *modifier_effect_cache.get_research_points_modifier()
11221126
);
11231127

1124-
const fixed_point_t research_points_modifier_from_tech =
1125-
country->get_modifier_effect_value(*modifier_effect_cache.get_increase_research());
1128+
const fixed_point_t research_points_modifier_from_tech = country.get_modifier_effect_value(
1129+
*modifier_effect_cache.get_increase_research()
1130+
);
11261131
if (research_points_modifier_from_tech != fixed_point_t::_0) {
11271132
static const StringName from_technology_localisation_key = "FROM_TECHNOLOGY";
11281133
research_points_tooltip += "\n" + tr(from_technology_localisation_key) + ": " +
@@ -1134,7 +1139,7 @@ Dictionary MenuSingleton::get_topbar_info() const {
11341139
static const StringName daily_research_points_localisation_key = "TECH_DAILY_RESEARCHPOINTS_TOTAL_TOOLTIP";
11351140
research_points_tooltip += "\n" + tr(daily_research_points_localisation_key).replace(
11361141
Utilities::get_long_value_placeholder(),
1137-
Utilities::fixed_point_to_string_dp(country->get_daily_research_points_untracked(), 2)
1142+
Utilities::fixed_point_to_string_dp(country.get_daily_research_points_untracked(), 2)
11381143
);
11391144

11401145
// In the base game this section is only shown when no research is set, but it's useful to show it always
@@ -1143,7 +1148,7 @@ Dictionary MenuSingleton::get_topbar_info() const {
11431148
static const StringName accumulated_research_points_localisation_key = "RP_ACCUMULATED";
11441149
research_points_tooltip += tr(accumulated_research_points_localisation_key).replace(
11451150
Utilities::get_short_value_placeholder(),
1146-
Utilities::fixed_point_to_string_dp(country->get_research_point_stockpile_untracked(), 1)
1151+
Utilities::fixed_point_to_string_dp(country.get_research_point_stockpile_untracked(), 1)
11471152
);
11481153

11491154
ret[research_points_tooltip_key] = std::move(research_points_tooltip);
@@ -1161,31 +1166,31 @@ Dictionary MenuSingleton::get_topbar_info() const {
11611166
static const StringName regiment_count_key = "regiment_count";
11621167
static const StringName max_supported_regiments_key = "max_supported_regiments";
11631168

1164-
ret[regiment_count_key] = static_cast<uint64_t>(country->get_regiment_count());
1165-
ret[max_supported_regiments_key] = static_cast<uint64_t>(country->get_max_supported_regiment_count());
1169+
ret[regiment_count_key] = static_cast<uint64_t>(country.get_regiment_count());
1170+
ret[max_supported_regiments_key] = static_cast<uint64_t>(country.get_max_supported_regiment_count());
11661171

11671172
static const StringName is_mobilised_key = "is_mobilised";
11681173
static const StringName mobilisation_regiments_key = "mobilisation_regiments";
11691174
static const StringName mobilisation_impact_tooltip_key = "mobilisation_impact_tooltip";
11701175

1171-
if (country->is_mobilised()) {
1176+
if (country.is_mobilised()) {
11721177
ret[is_mobilised_key] = true;
11731178
} else {
1174-
ret[mobilisation_regiments_key] = static_cast<uint64_t>(country->get_mobilisation_potential_regiment_count());
1179+
ret[mobilisation_regiments_key] = static_cast<uint64_t>(country.get_mobilisation_potential_regiment_count());
11751180
ret[mobilisation_impact_tooltip_key] = _make_mobilisation_impact_tooltip();
11761181
}
11771182

11781183
{
11791184
static const StringName leadership_key = "leadership";
11801185
static const StringName leadership_tooltip_key = "leadership_tooltip";
11811186

1182-
ret[leadership_key] = country->get_leadership_point_stockpile().truncate<int64_t>();
1187+
ret[leadership_key] = country.get_leadership_point_stockpile().truncate<int64_t>();
11831188

11841189
String leadership_tooltip;
11851190

11861191
fixed_point_t monthly_base_leadership_points;
11871192

1188-
for (auto const& [pop_type, leadership_points] : country->get_leadership_points_from_pop_types()) {
1193+
for (auto const& [pop_type, leadership_points] : country.get_leadership_points_from_pop_types()) {
11891194
static const StringName pop_type_leadership_localisation_key = "TECH_DAILY_LEADERSHIP_TOOLTIP";
11901195
static const String pop_type_replace_key = "$POPTYPE$";
11911196
static const String fraction_replace_key = "$FRACTION$";
@@ -1201,8 +1206,8 @@ Dictionary MenuSingleton::get_topbar_info() const {
12011206
).replace(
12021207
fraction_replace_key, Utilities::fixed_point_to_string_dp(
12031208
fixed_point_t::from_fraction(
1204-
100 * country->get_population_by_type(*pop_type),
1205-
country->get_total_population()
1209+
100 * country.get_population_by_type(*pop_type),
1210+
country.get_total_population()
12061211
), 2
12071212
)
12081213
).replace(
@@ -1213,7 +1218,7 @@ Dictionary MenuSingleton::get_topbar_info() const {
12131218
// Empty prefix, "\n" suffix, fitting with the potential trailing "\n" from the pop type contributions and the upcoming
12141219
// guaranteed monthly base leadership points line. All contributions are added to monthly_base_leadership_points.
12151220
leadership_tooltip += _make_modifier_effect_contributions_tooltip(
1216-
*country, *modifier_effect_cache.get_leadership(), &monthly_base_leadership_points, {}, "\n"
1221+
country, *modifier_effect_cache.get_leadership(), &monthly_base_leadership_points, {}, "\n"
12171222
);
12181223

12191224
// The monthly base leadership points line is guaranteed to be present, but those directly above and below it aren't,
@@ -1226,18 +1231,18 @@ Dictionary MenuSingleton::get_topbar_info() const {
12261231
);
12271232

12281233
leadership_tooltip += _make_modifier_effect_contributions_tooltip(
1229-
*country, *modifier_effect_cache.get_leadership_modifier()
1234+
country, *modifier_effect_cache.get_leadership_modifier()
12301235
);
12311236

12321237
static const StringName monthly_leadership_points_localisation_key = "TECH_DAILY_LEADERSHIP_TOTAL_TOOLTIP";
12331238
leadership_tooltip += "\n" + tr(monthly_leadership_points_localisation_key).replace(
12341239
Utilities::get_long_value_placeholder(),
1235-
Utilities::fixed_point_to_string_dp(country->get_monthly_leadership_points(), 2)
1240+
Utilities::fixed_point_to_string_dp(country.get_monthly_leadership_points(), 2)
12361241
);
12371242

12381243
const fixed_point_t max_leadership_point_stockpile =
12391244
definition_manager.get_define_manager().get_military_defines().get_max_leadership_point_stockpile();
1240-
if (country->get_leadership_point_stockpile() >= max_leadership_point_stockpile) {
1245+
if (country.get_leadership_point_stockpile() >= max_leadership_point_stockpile) {
12411246
leadership_tooltip += "\n" + get_tooltip_separator() + "\n";
12421247

12431248
static const StringName max_leadership_points_localisation_key = "TOPBAR_LEADERSHIP_MAX";

extension/src/openvic-extension/singletons/MenuSingleton.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <cstdint>
4+
#include <functional>
45
#include <variant>
56

67
#include <godot_cpp/classes/control.hpp>
@@ -101,7 +102,7 @@ namespace OpenVic {
101102
IndexedFlatMap<ProvinceInstance, size_t> province_sort_cache;
102103
IndexedFlatMap<RebelType, size_t> rebel_type_sort_cache;
103104

104-
std::vector<Pop const*> pops, filtered_pops;
105+
std::vector<std::reference_wrapper<const Pop>> pops, filtered_pops;
105106
population_menu_t();
106107
};
107108

@@ -217,7 +218,7 @@ namespace OpenVic {
217218

218219
godot::Error _population_menu_update_pops();
219220
godot::Error _population_menu_update_filtered_pops();
220-
using sort_func_t = std::function<bool(Pop const*, Pop const*)>;
221+
using sort_func_t = std::function<bool(Pop const&, Pop const&)>;
221222
sort_func_t _get_population_menu_sort_func(PopSortKey sort_key) const;
222223
godot::Error _population_menu_sort_pops();
223224
godot::Error population_menu_update_locale_sort_cache();

extension/src/openvic-extension/singletons/MilitaryMenu.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) {
7070
if (group != nullptr) {
7171
leader_dict[military_info_leader_assignment_key] = convert_to<String>(group->get_name());
7272

73-
ProvinceInstance const* location = group->get_position();
74-
if (location != nullptr) {
75-
leader_dict[military_info_leader_location_key] =
76-
convert_to<String>(location->get_identifier());
77-
}
73+
ProvinceInstance const& location = group->get_location();
74+
leader_dict[military_info_leader_location_key] = convert_to<String>(location.get_identifier());
7875
}
7976
}
8077

@@ -241,10 +238,7 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched<Branch>
241238
}
242239

243240
unit_group_dict[military_info_unit_group_name_key] = convert_to<String>(unit_group.get_name());
244-
if (unit_group.get_position() != nullptr) {
245-
unit_group_dict[military_info_unit_group_location_key] =
246-
convert_to<String>(unit_group.get_position()->get_identifier());
247-
}
241+
unit_group_dict[military_info_unit_group_location_key] = convert_to<String>(unit_group.get_location().get_identifier());
248242
unit_group_dict[military_info_unit_group_unit_count_key] = static_cast<uint64_t>(unit_group.get_unit_count());
249243

250244
unit_group_dict[military_info_unit_group_organisation_key] = static_cast<real_t>(unit_group.get_organisation_proportion());
@@ -619,10 +613,10 @@ Dictionary MenuSingleton::get_military_menu_info() {
619613
if (leaders.resize(leader_count) == OK) {
620614

621615
for (size_t index = 0; index < general_count; ++index) {
622-
leaders[index] = make_leader_dict(*country->get_generals()[index]);
616+
leaders[index] = make_leader_dict(country->get_generals()[index]);
623617
}
624618
for (size_t index = 0; index < admiral_count; ++index) {
625-
leaders[general_count + index] = make_leader_dict(*country->get_admirals()[index]);
619+
leaders[general_count + index] = make_leader_dict(country->get_admirals()[index]);
626620
}
627621

628622
ret[military_info_leaders_list_key] = std::move(leaders);
@@ -650,7 +644,7 @@ Dictionary MenuSingleton::get_military_menu_info() {
650644
if (armies.resize(army_count) == OK) {
651645

652646
for (size_t index = 0; index < army_count; ++index) {
653-
armies[index] = make_unit_group_dict(*country->get_armies()[index]);
647+
armies[index] = make_unit_group_dict(country->get_armies()[index].get());
654648
}
655649

656650
ret[military_info_armies_key] = std::move(armies);
@@ -677,7 +671,7 @@ Dictionary MenuSingleton::get_military_menu_info() {
677671
if (navies.resize(navy_count) == OK) {
678672

679673
for (size_t index = 0; index < navy_count; ++index) {
680-
navies[index] = make_unit_group_dict(*country->get_navies()[index]);
674+
navies[index] = make_unit_group_dict(country->get_navies()[index].get());
681675
}
682676

683677
ret[military_info_navies_key] = std::move(navies);

0 commit comments

Comments
 (0)