Skip to content

Commit ba43c46

Browse files
committed
Never break after operator
1 parent b7d7ee2 commit ba43c46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+738
-528
lines changed

src/headless/main.cpp

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -258,44 +258,41 @@ static bool run_headless(fs::path const& root, memory::vector<memory::string>& m
258258

259259
// TODO - REMOVE TEST CODE
260260
SPDLOG_INFO("===== Ranking system test... =====");
261-
if (game_manager.get_instance_manager()) {
262-
const auto print_ranking_list = [ //
263-
](std::string_view title, OpenVic::utility::forwardable_span<CountryInstance* const> countries) -> void {
264-
memory::string countries_str;
265-
for (CountryInstance* country : countries) {
266-
countries_str += fmt::format(
267-
"\n\t{} - Total #{} ({}), Prestige #{} ({}), Industry #{} ({}), Military #{} ({})", //
268-
*country, //
269-
country->get_total_rank(), country->total_score.get_untracked().to_string(1), //
270-
country->get_prestige_rank(), country->get_prestige_untracked().to_string(1),
271-
country->get_industrial_rank(), country->get_industrial_power_untracked().to_string(1),
272-
country->get_military_rank(), country->military_power.get_untracked().to_string(1)
273-
);
274-
}
275-
SPDLOG_INFO("{}:{}", title, countries_str);
276-
};
277-
278-
CountryInstanceManager const& country_instance_manager =
279-
game_manager.get_instance_manager()->get_country_instance_manager();
280-
281-
OpenVic::utility::forwardable_span<CountryInstance* const> great_powers = country_instance_manager.get_great_powers();
282-
print_ranking_list("Great Powers", great_powers);
283-
print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
284-
print_ranking_list("All countries", country_instance_manager.get_total_ranking());
285-
286-
SPDLOG_INFO("===== RGO test... =====");
287-
for (size_t i = 0; i < std::min<size_t>(3, great_powers.size()); ++i) {
288-
CountryInstance const& great_power = *great_powers[i];
289-
ProvinceInstance const* const capital_province = great_power.get_capital();
290-
if (capital_province == nullptr) {
291-
spdlog::warn_s("{} has no capital ProvinceInstance set.", great_power);
292-
} else {
293-
print_rgo(*capital_province);
294-
}
261+
InstanceManager& instance_manager = *game_manager.get_instance_manager();
262+
const auto print_ranking_list = [](
263+
std::string_view title,
264+
OpenVic::utility::forwardable_span<CountryInstance* const> countries
265+
) -> void {
266+
memory::string countries_str;
267+
for (CountryInstance* country : countries) {
268+
countries_str += fmt::format(
269+
"\n\t{} - Total #{} ({}), Prestige #{} ({}), Industry #{} ({}), Military #{} ({})", //
270+
*country, //
271+
country->get_total_rank(), country->total_score.get_untracked().to_string(1), //
272+
country->get_prestige_rank(), country->get_prestige_untracked().to_string(1),
273+
country->get_industrial_rank(), country->get_industrial_power_untracked().to_string(1),
274+
country->get_military_rank(), country->military_power.get_untracked().to_string(1)
275+
);
276+
}
277+
SPDLOG_INFO("{}:{}", title, countries_str);
278+
};
279+
280+
CountryInstanceManager const& country_instance_manager = instance_manager.get_country_instance_manager();
281+
282+
OpenVic::utility::forwardable_span<CountryInstance* const> great_powers = country_instance_manager.get_great_powers();
283+
print_ranking_list("Great Powers", great_powers);
284+
print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
285+
print_ranking_list("All countries", country_instance_manager.get_total_ranking());
286+
287+
SPDLOG_INFO("===== RGO test... =====");
288+
for (size_t i = 0; i < std::min<size_t>(3, great_powers.size()); ++i) {
289+
CountryInstance const& great_power = *great_powers[i];
290+
ProvinceInstance const* const capital_province = great_power.get_capital();
291+
if (capital_province == nullptr) {
292+
spdlog::warn_s("{} has no capital ProvinceInstance set.", great_power);
293+
} else {
294+
print_rgo(*capital_province);
295295
}
296-
} else {
297-
spdlog::error_s("Instance manager not available!");
298-
ret = false;
299296
}
300297

301298
if (ret) {
@@ -305,7 +302,7 @@ static bool run_headless(fs::path const& root, memory::vector<memory::string>& m
305302

306303
using test_time_units_t = std::chrono::milliseconds;
307304

308-
MapInstance& map_instance = game_manager.get_instance_manager()->get_map_instance();
305+
MapInstance& map_instance = instance_manager.get_map_instance();
309306

310307
SPDLOG_INFO("===== Land Pathfinding test... =====");
311308
test_duration_t duration = std::chrono::duration_cast<test_time_units_t>( //

src/openvic-simulation/core/template/Concepts.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ namespace OpenVic {
4242
concept not_same_as = !std::same_as<T, T2>;
4343

4444
template<typename Allocator, typename T, typename Value = std::remove_cvref_t<typename Allocator::value_type>>
45-
concept move_insertable_allocator_for =
46-
requires(Allocator& alloc, Value* value, T move) { std::allocator_traits<Allocator>::construct(alloc, value, move); };
45+
concept move_insertable_allocator_for = requires(Allocator& alloc, Value* value, T move) {
46+
std::allocator_traits<Allocator>::construct(alloc, value, move);
47+
};
4748

4849
template<typename Allocator>
4950
struct enable_copy_insertable : std::false_type {};
5051

5152
template<typename Allocator>
52-
concept copy_insertable_allocator = enable_copy_insertable<Allocator>::value ||
53-
move_insertable_allocator_for<Allocator, typename Allocator::value_type const&>;
53+
concept copy_insertable_allocator = enable_copy_insertable<Allocator>::value
54+
|| move_insertable_allocator_for<Allocator, typename Allocator::value_type const&>;
5455

5556
template<typename T>
5657
struct enable_copy_insertable<std::allocator<T>> : std::is_copy_constructible<T> {};
@@ -59,8 +60,8 @@ namespace OpenVic {
5960
struct enable_move_insertable : std::false_type {};
6061

6162
template<typename Allocator>
62-
concept move_insertable_allocator =
63-
enable_move_insertable<Allocator>::value || move_insertable_allocator_for<Allocator, typename Allocator::value_type>;
63+
concept move_insertable_allocator = enable_move_insertable<Allocator>::value
64+
|| move_insertable_allocator_for<Allocator, typename Allocator::value_type>;
6465

6566
template<typename T>
6667
struct enable_move_insertable<std::allocator<T>> : std::is_move_constructible<T> {};
@@ -109,8 +110,9 @@ namespace OpenVic {
109110
};
110111

111112
template<typename T>
112-
concept has_index = requires { typename T::index_t; } &&
113-
derived_from_specialization_of<typename T::index_t, type_safe::strong_typedef> && requires {
113+
concept has_index = requires { typename T::index_t; }
114+
&& derived_from_specialization_of<typename T::index_t, type_safe::strong_typedef>
115+
&& requires {
114116
static_cast<std::size_t>(
115117
static_cast<type_safe::underlying_type<decltype(std::declval<T>().index)>>(std::declval<T>().index)
116118
);

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,12 @@ bool CountryInstance::remove_unit_instance_group(UnitInstanceGroup const& group)
676676
const auto remove_from_vector = [this, &group]<unit_branch_t Branch>(
677677
memory::vector<UnitInstanceGroupBranched<Branch>*>& unit_instance_groups
678678
) -> bool {
679-
const typename memory::vector<UnitInstanceGroupBranched<Branch>*>::const_iterator it =
680-
std::find(unit_instance_groups.begin(), unit_instance_groups.end(), &group);
679+
using const_it_t = typename memory::vector<UnitInstanceGroupBranched<Branch>*>::const_iterator;
680+
const const_it_t it = std::find(
681+
unit_instance_groups.begin(),
682+
unit_instance_groups.end(),
683+
&group
684+
);
681685

682686
if (it != unit_instance_groups.end()) {
683687
unit_instance_groups.erase(it);
@@ -1226,12 +1230,14 @@ bool CountryInstance::apply_history_to_country(
12261230
ret &= add_reform(*reform);
12271231
}
12281232
set_optional_state(tech_school, entry.get_tech_school());
1229-
constexpr auto set_bool_map_to_indexed_map =
1230-
[]<typename T>(IndexedFlatMap<T, bool>& target, ordered_map<T const*, bool> source) {
1231-
for (auto const& [key, value] : source) {
1232-
target[*key] = value;
1233-
}
1234-
};
1233+
constexpr auto set_bool_map_to_indexed_map = []<typename T>(
1234+
IndexedFlatMap<T, bool>& target,
1235+
ordered_map<T const*, bool> source
1236+
) {
1237+
for (auto const& [key, value] : source) {
1238+
target[*key] = value;
1239+
}
1240+
};
12351241

12361242
for (auto const& [technology, level] : entry.get_technologies()) {
12371243
ret &= set_technology_unlock_level(*technology, level);
@@ -1466,9 +1472,9 @@ void CountryInstance::_update_technology(const Date today) {
14661472
}
14671473

14681474
daily_research_points += get_modifier_effect_value(*modifier_effect_cache.get_research_points());
1469-
daily_research_points *= fixed_point_t::_1 +
1470-
get_modifier_effect_value(*modifier_effect_cache.get_research_points_modifier()) +
1471-
get_modifier_effect_value(*modifier_effect_cache.get_increase_research());
1475+
daily_research_points *= fixed_point_t::_1
1476+
+ get_modifier_effect_value(*modifier_effect_cache.get_research_points_modifier())
1477+
+ get_modifier_effect_value(*modifier_effect_cache.get_increase_research());
14721478

14731479
if (daily_research_points.get_untracked() < 0) {
14741480
daily_research_points.set(0);
@@ -1592,13 +1598,15 @@ void CountryInstance::_update_military() {
15921598

15931599
// Mobilisation calculations
15941600
mobilisation_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilization_impact());
1595-
mobilisation_economy_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_tech()) +
1596-
get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_country());
1601+
mobilisation_economy_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_tech())
1602+
+ get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_country());
15971603

15981604
// TODO - use country_defines.get_min_mobilize_limit(); (wiki: "lowest maximum of brigades you can mobilize. (by default 3)")
15991605

1600-
mobilisation_max_regiment_count =
1601-
((fixed_point_t::_1 + mobilisation_impact) * fixed_point_t::parse(regiment_count)).floor<size_t>();
1606+
mobilisation_max_regiment_count = (
1607+
(fixed_point_t::_1 + mobilisation_impact)
1608+
* fixed_point_t::parse(regiment_count)
1609+
).floor<size_t>();
16021610

16031611
mobilisation_potential_regiment_count = 0; // TODO - calculate max regiments from poor citizens
16041612
if (mobilisation_potential_regiment_count > mobilisation_max_regiment_count) {
@@ -1612,9 +1620,9 @@ void CountryInstance::_update_military() {
16121620
get_modifier_effect_value(*modifier_effect_cache.get_max_war_exhaustion()), fixed_point_t::_0
16131621
);
16141622

1615-
organisation_regain = fixed_point_t::_1 +
1616-
get_modifier_effect_value(*modifier_effect_cache.get_org_regain()) +
1617-
get_modifier_effect_value(*modifier_effect_cache.get_morale_global());
1623+
organisation_regain = fixed_point_t::_1
1624+
+ get_modifier_effect_value(*modifier_effect_cache.get_org_regain())
1625+
+ get_modifier_effect_value(*modifier_effect_cache.get_morale_global());
16181626

16191627
land_organisation = fixed_point_t::_1 + get_modifier_effect_value(*modifier_effect_cache.get_land_organisation());
16201628
naval_organisation = fixed_point_t::_1 + get_modifier_effect_value(*modifier_effect_cache.get_naval_organisation());
@@ -1626,21 +1634,21 @@ void CountryInstance::_update_military() {
16261634

16271635
recruit_time = fixed_point_t::_1 + get_modifier_effect_value(*modifier_effect_cache.get_unit_recruitment_time());
16281636
combat_width = ( //
1629-
fixed_point_t::parse(military_defines.get_base_combat_width()) +
1630-
get_modifier_effect_value(*modifier_effect_cache.get_combat_width_additive())
1637+
fixed_point_t::parse(military_defines.get_base_combat_width())
1638+
+ get_modifier_effect_value(*modifier_effect_cache.get_combat_width_additive())
16311639
).floor<int32_t>();
16321640
dig_in_cap = get_modifier_effect_value(*modifier_effect_cache.get_dig_in_cap()).floor<int32_t>();
1633-
military_tactics = military_defines.get_base_military_tactics() +
1634-
get_modifier_effect_value(*modifier_effect_cache.get_military_tactics());
1641+
military_tactics = military_defines.get_base_military_tactics()
1642+
+ get_modifier_effect_value(*modifier_effect_cache.get_military_tactics());
16351643

16361644
if (leadership_point_stockpile < 0) {
16371645
leadership_point_stockpile = 0;
16381646
}
16391647
create_leader_count = (leadership_point_stockpile / military_defines.get_leader_recruit_cost()).floor<int32_t>();
16401648

16411649
monthly_leadership_points += get_modifier_effect_value(*modifier_effect_cache.get_leadership());
1642-
monthly_leadership_points *= fixed_point_t::_1 +
1643-
get_modifier_effect_value(*modifier_effect_cache.get_leadership_modifier());
1650+
monthly_leadership_points *= fixed_point_t::_1
1651+
+ get_modifier_effect_value(*modifier_effect_cache.get_leadership_modifier());
16441652

16451653
if (monthly_leadership_points < 0) {
16461654
monthly_leadership_points = 0;
@@ -1876,8 +1884,8 @@ void CountryInstance::update_gamestate(const Date today, MapInstance& map_instan
18761884
_update_politics();
18771885
_update_diplomacy();
18781886

1879-
const CountryDefinition::government_colour_map_t::const_iterator it =
1880-
country_definition.get_alternative_colours().find(government_type.get_untracked());
1887+
using const_it_t = typename CountryDefinition::government_colour_map_t::const_iterator;
1888+
const const_it_t it = country_definition.get_alternative_colours().find(government_type.get_untracked());
18811889

18821890
if (it != country_definition.get_alternative_colours().end()) {
18831891
colour = it.value();

src/openvic-simulation/country/CountryInstanceManager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ CountryInstance const& CountryInstanceManager::get_country_instance_by_definitio
202202
}
203203

204204
bool CountryInstanceManager::apply_history_to_countries(InstanceManager& instance_manager) {
205-
CountryHistoryManager const& history_manager =
206-
instance_manager.definition_manager.get_history_manager().get_country_manager();
205+
CountryHistoryManager const& history_manager = instance_manager.definition_manager
206+
.get_history_manager()
207+
.get_country_manager();
207208

208209
bool ret = true;
209210

src/openvic-simulation/dataloader/Dataloader.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212

1313
#include <fmt/std.h>
1414

15+
#include "openvic-simulation/core/template/Concepts.hpp"
16+
#include "openvic-simulation/country/CountryDefinition.hpp"
1517
#include "openvic-simulation/DefinitionManager.hpp"
18+
#include "openvic-simulation/history/Bookmark.hpp"
19+
#include "openvic-simulation/history/HistoryManager.hpp"
1620
#include "openvic-simulation/interface/UI.hpp"
1721
#include "openvic-simulation/misc/GameRulesManager.hpp"
1822
#include "openvic-simulation/misc/SoundEffect.hpp"
1923
#include "openvic-simulation/utility/Logger.hpp"
2024
#include "openvic-simulation/utility/StringUtils.hpp"
2125
#include "openvic-simulation/utility/Containers.hpp"
22-
#include "openvic-simulation/core/template/Concepts.hpp"
2326

2427
using namespace OpenVic;
2528
using namespace OpenVic::NodeTools;
@@ -381,9 +384,10 @@ bool Dataloader::_load_pop_types(DefinitionManager& definition_manager) {
381384

382385
bool ret = pop_manager.setup_stratas();
383386

384-
GoodDefinitionManager const& good_definition_manager =
385-
definition_manager.get_economy_manager().get_good_definition_manager();
386-
IdeologyManager const& ideology_manager = definition_manager.get_politics_manager().get_ideology_manager();
387+
EconomyManager const& economy_manager = definition_manager.get_economy_manager();
388+
GoodDefinitionManager const& good_definition_manager = economy_manager.get_good_definition_manager();
389+
PoliticsManager const& politics_manager = definition_manager.get_politics_manager();
390+
IdeologyManager const& ideology_manager = politics_manager.get_ideology_manager();
387391

388392
static constexpr std::string_view pop_type_directory = "poptypes";
389393

@@ -580,8 +584,10 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
580584
DeploymentManager& deployment_manager = definition_manager.get_military_manager().get_deployment_manager();
581585

582586
static constexpr std::string_view country_history_directory = "history/countries";
583-
const path_vector_t country_history_files =
584-
lookup_basic_identifier_prefixed_files_in_dir(country_history_directory, ".txt");
587+
const path_vector_t country_history_files = lookup_basic_identifier_prefixed_files_in_dir(
588+
country_history_directory,
589+
".txt"
590+
);
585591

586592
country_history_manager.reserve_more_country_histories(country_history_files.size());
587593
deployment_manager.reserve_more_deployments(country_history_files.size());
@@ -592,8 +598,10 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
592598
const memory::string filename = file.stem().string<char>(memory::string::allocator_type{});
593599
const std::string_view country_id = extract_basic_identifier_prefix(filename);
594600

595-
CountryDefinition const* country =
596-
definition_manager.get_country_definition_manager().get_country_definition_by_identifier(country_id);
601+
CountryDefinitionManager const& country_definition_manager = definition_manager.get_country_definition_manager();
602+
CountryDefinition const* country = country_definition_manager.get_country_definition_by_identifier(
603+
country_id
604+
);
597605
if (country == nullptr) {
598606
if (unused_history_file_warnings) {
599607
spdlog::warn_s("Found history file for non-existent country: {}", country_id);
@@ -618,14 +626,17 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
618626
}
619627
}
620628

629+
HistoryManager& history_manager = definition_manager.get_history_manager();
621630
{
622631
/* Province History */
623632
ProvinceHistoryManager& province_history_manager = definition_manager.get_history_manager().get_province_manager();
624633
MapDefinition const& map_definition = definition_manager.get_map_definition();
625634

626635
static constexpr std::string_view province_history_directory = "history/provinces";
627-
const path_vector_t province_history_files =
628-
lookup_basic_identifier_prefixed_files_in_dir_recursive(province_history_directory, ".txt");
636+
const path_vector_t province_history_files = lookup_basic_identifier_prefixed_files_in_dir_recursive(
637+
province_history_directory,
638+
".txt"
639+
);
629640

630641
province_history_manager.reserve_more_province_histories(province_history_files.size());
631642

@@ -655,8 +666,8 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
655666
static constexpr std::string_view pop_history_directory = "history/pops/";
656667

657668
const string_set_t pop_history_dirs = lookup_dirs_in_dir(pop_history_directory);
658-
const Date last_bookmark_date =
659-
definition_manager.get_history_manager().get_bookmark_manager().get_last_bookmark_date();
669+
BookmarkManager const& bookmark_manager = history_manager.get_bookmark_manager();
670+
const Date last_bookmark_date = bookmark_manager.get_last_bookmark_date();
660671

661672
for (memory::string const& dir : pop_history_dirs) {
662673
Date::from_chars_result result;
@@ -687,8 +698,7 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
687698

688699
{
689700
/* Diplomacy History */
690-
DiplomaticHistoryManager& diplomatic_history_manager =
691-
definition_manager.get_history_manager().get_diplomacy_manager();
701+
DiplomaticHistoryManager& diplomatic_history_manager = history_manager.get_diplomacy_manager();
692702

693703
static constexpr std::string_view diplomacy_history_directory = "history/diplomacy";
694704

src/openvic-simulation/dataloader/NodeTools.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ using namespace std::string_view_literals;
162162
template<std::signed_integral T>
163163
NodeCallback auto expect_int(callback_t<T>& callback, int base = 10) {
164164
return expect_int64([callback](int64_t val) mutable -> bool {
165-
if (static_cast<int64_t>(std::numeric_limits<T>::lowest()) <= val &&
166-
val <= static_cast<int64_t>(std::numeric_limits<T>::max())) {
165+
if (static_cast<int64_t>(std::numeric_limits<T>::lowest()) <= val
166+
&& val <= static_cast<int64_t>(std::numeric_limits<T>::max())
167+
) {
167168
return callback(val);
168169
}
169170
spdlog::error_s(

0 commit comments

Comments
 (0)