11#include " PlayerSingleton.hpp"
22
3+ #include < type_safe/strong_typedef.hpp>
4+
35#include < openvic-simulation/country/CountryInstance.hpp>
46#include < openvic-simulation/map/ProvinceInstance.hpp>
57
@@ -98,7 +100,7 @@ void PlayerSingleton::set_player_country(CountryInstance* new_player_country) {
98100 if (player_country != nullptr ) {
99101 instance_manager->queue_game_action (
100102 game_action_type_t ::GAME_ACTION_SET_AI,
101- std::pair<uint64_t , bool > { player_country->index , true }
103+ std::pair<uint64_t , bool > { type_safe::get ( player_country->index ) , true }
102104 );
103105 }
104106
@@ -107,7 +109,7 @@ void PlayerSingleton::set_player_country(CountryInstance* new_player_country) {
107109 if (player_country != nullptr ) {
108110 instance_manager->queue_game_action (
109111 game_action_type_t ::GAME_ACTION_SET_AI,
110- std::pair<uint64_t , bool > { player_country->index , false }
112+ std::pair<uint64_t , bool > { type_safe::get ( player_country->index ) , false }
111113 );
112114 }
113115
@@ -150,21 +152,21 @@ void PlayerSingleton::set_selected_province(ProvinceInstance const* new_selected
150152}
151153
152154void PlayerSingleton::set_selected_province_by_number (int32_t province_number) {
153- if (province_number == ProvinceDefinition::NULL_INDEX) {
155+ MapInstance const & map_instance = instance_manager->get_map_instance ();
156+ const province_index_t province_index = ProvinceDefinition::get_index_from_province_number (province_number);
157+ if (province_index == ProvinceDefinition::NULL_INDEX) {
154158 unset_selected_province ();
155159 } else {
156- InstanceManager const * instance_manager = GameSingleton::get_singleton ()->get_instance_manager ();
157- ERR_FAIL_NULL (instance_manager);
158-
159- MapInstance const & map_instance = instance_manager->get_map_instance ();
160-
161- set_selected_province (map_instance.get_province_instance_from_number (province_number));
162-
160+ ProvinceInstance const * const selected_province = map_instance.get_province_instance_from_index (province_index);
163161 if (selected_province == nullptr ) {
164162 spdlog::error_s (
165163 " Trying to set selected province to an invalid number {} (max number is {})" ,
166164 map_instance.get_province_instance_by_definition ().get_count (), province_number
167165 );
166+ } else {
167+ InstanceManager const * instance_manager = GameSingleton::get_singleton ()->get_instance_manager ();
168+ ERR_FAIL_NULL (instance_manager);
169+ set_selected_province (selected_province);
168170 }
169171 }
170172}
@@ -217,7 +219,7 @@ void PlayerSingleton::expand_selected_province_building(int32_t building_index)
217219
218220 instance_manager->queue_game_action (
219221 game_action_type_t ::GAME_ACTION_EXPAND_PROVINCE_BUILDING,
220- std::pair<uint64_t , uint64_t > { selected_province->index , building_index }
222+ std::pair<uint64_t , uint64_t > { type_safe::get ( selected_province->index ) , building_index }
221223 );
222224}
223225
@@ -229,7 +231,7 @@ void PlayerSingleton::set_##value_name##_slider_value(fixed_point_t const value)
229231 } \
230232 GameSingleton::get_singleton ()->get_instance_manager ()->queue_game_action ( \
231233 game_action_type_t ::GAME_ACTION_SET_##game_action_name, \
232- std::pair<uint64_t , fixed_point_t > { player_country->index , value } \
234+ std::pair<uint64_t , fixed_point_t > { type_safe::get ( player_country->index ) , value } \
233235 ); \
234236}
235237
@@ -250,7 +252,7 @@ void PlayerSingleton::set_strata_tax_rate_slider_value(Strata const& strata, fix
250252 }
251253 GameSingleton::get_singleton ()->get_instance_manager ()->queue_game_action (
252254 game_action_type_t ::GAME_ACTION_SET_STRATA_TAX,
253- std::tuple<uint64_t , uint64_t , fixed_point_t > { player_country->index , strata.index , value }
255+ std::tuple<uint64_t , uint64_t , fixed_point_t > { type_safe::get ( player_country->index ) , strata.index , value }
254256 );
255257}
256258
@@ -269,7 +271,7 @@ void PlayerSingleton::set_good_automated(int32_t good_index, bool is_automated)
269271
270272 instance_manager->queue_game_action (
271273 game_action_type_t ::GAME_ACTION_SET_GOOD_AUTOMATED,
272- std::tuple<uint64_t , uint64_t , bool > { player_country->index , good_index, is_automated }
274+ std::tuple<uint64_t , uint64_t , bool > { type_safe::get ( player_country->index ) , good_index, is_automated }
273275 );
274276}
275277
@@ -282,7 +284,7 @@ void PlayerSingleton::set_good_trade_order(int32_t good_index, bool is_selling,
282284
283285 instance_manager->queue_game_action (
284286 game_action_type_t ::GAME_ACTION_SET_GOOD_TRADE_ORDER, std::tuple<uint64_t , uint64_t , bool , fixed_point_t > {
285- player_country->index , good_index, is_selling,
287+ type_safe::get ( player_country->index ) , good_index, is_selling,
286288 MenuSingleton::calculate_trade_menu_stockpile_cutoff_amount_fp (amount_slider->get_value_scaled_fp ())
287289 }
288290 );
@@ -299,7 +301,7 @@ void PlayerSingleton::create_leader(bool is_general) const {
299301
300302 instance_manager->queue_game_action (
301303 game_action_type_t ::GAME_ACTION_CREATE_LEADER,
302- std::pair<uint64_t , bool > { player_country->index , is_general }
304+ std::pair<uint64_t , bool > { type_safe::get ( player_country->index ) , is_general }
303305 );
304306}
305307
@@ -321,7 +323,7 @@ void PlayerSingleton::set_auto_create_leaders(bool value) const {
321323
322324 instance_manager->queue_game_action (
323325 game_action_type_t ::GAME_ACTION_SET_AUTO_CREATE_LEADERS,
324- std::pair<uint64_t , bool > { player_country->index , value }
326+ std::pair<uint64_t , bool > { type_safe::get ( player_country->index ) , value }
325327 );
326328}
327329
@@ -333,7 +335,7 @@ void PlayerSingleton::set_auto_assign_leaders(bool value) const {
333335
334336 instance_manager->queue_game_action (
335337 game_action_type_t ::GAME_ACTION_SET_AUTO_ASSIGN_LEADERS,
336- std::pair<uint64_t , bool > { player_country->index , value }
338+ std::pair<uint64_t , bool > { type_safe::get ( player_country->index ) , value }
337339 );
338340}
339341
@@ -345,6 +347,6 @@ void PlayerSingleton::set_mobilise(bool value) const {
345347
346348 instance_manager->queue_game_action (
347349 game_action_type_t ::GAME_ACTION_SET_MOBILISE,
348- std::pair<uint64_t , bool > { player_country->index , value }
350+ std::pair<uint64_t , bool > { type_safe::get ( player_country->index ) , value }
349351 );
350352}
0 commit comments