Skip to content

Commit 628e6ef

Browse files
committed
Never break after operator
1 parent 55c064f commit 628e6ef

Some content is hidden

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

52 files changed

+722
-515
lines changed

src/headless/main.cpp

Lines changed: 28 additions & 31 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::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-
};
261+
InstanceManager& instance_manager = *game_manager.get_instance_manager();
262+
const auto print_ranking_list = [](
263+
std::string_view title,
264+
OpenVic::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+
};
277279

278-
CountryInstanceManager const& country_instance_manager =
279-
game_manager.get_instance_manager()->get_country_instance_manager();
280+
CountryInstanceManager const& country_instance_manager = instance_manager.get_country_instance_manager();
280281

281282
OpenVic::forwardable_span<CountryInstance* const> great_powers = country_instance_manager.get_great_powers();
282283
print_ranking_list("Great Powers", great_powers);
283284
print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
284285
print_ranking_list("All countries", country_instance_manager.get_total_ranking());
285286

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-
}
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/Hash.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ namespace OpenVic {
4646
s = h(v) << (sizeof(T) * CHAR_BIT);
4747
(
4848
[&] {
49-
// If args is not last pointer of args
50-
if (static_cast<void const*>(&(std::get<sizeof...(args) - 1>(arg_tuple))) !=
51-
static_cast<void const*>(&args)) {
49+
void const* const args_ptr = static_cast<void const*>(&args);
50+
void const* const last_pointer_of_args = static_cast<void const*>(
51+
&(std::get<sizeof...(args) - 1>(arg_tuple))
52+
);
53+
if (args_ptr != last_pointer_of_args) {
5254
s <<= sizeof(Args) * CHAR_BIT;
5355
}
5456
s |= std::hash<Args> {}(args);

src/openvic-simulation/core/portable/Deque.hpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,10 @@ namespace OpenVic::utility::_detail::deque {
10221022
// (_Myoff() + _Mysize() - 1) is for the last element, i.e. the back() of the deque.
10231023
// Divide by _Block_size to get the unmasked index of the last used block.
10241024
// Add 1 to get the unmasked index of the first unused block.
1025-
const auto _Unmasked_first_unused_block_idx =
1026-
static_cast<size_type>(((_Myoff() + _Mysize() - 1) / _Block_size) + 1);
1025+
const auto _Unmasked_first_unused_block_idx = static_cast<size_type>(
1026+
((_Myoff() + _Mysize() - 1) / _Block_size)
1027+
+ 1
1028+
);
10271029

10281030
const auto _First_unused_block_idx = static_cast<size_type>(_Unmasked_first_unused_block_idx & _Mask);
10291031

@@ -1037,8 +1039,10 @@ namespace OpenVic::utility::_detail::deque {
10371039
}
10381040
}
10391041

1040-
const auto _Used_block_count =
1041-
static_cast<size_type>(_Unmasked_first_unused_block_idx - _Unmasked_first_used_block_idx);
1042+
const auto _Used_block_count = static_cast<size_type>(
1043+
_Unmasked_first_unused_block_idx
1044+
- _Unmasked_first_used_block_idx
1045+
);
10421046

10431047
size_type _New_block_count = _Minimum_map_size; // should be power of 2
10441048

@@ -1818,8 +1822,12 @@ namespace OpenVic::utility::_detail::deque {
18181822

18191823
_EXPORT_STD template<class _Ty, class _Alloc>
18201824
_NODISCARD bool operator==(const deque<_Ty, _Alloc>& _Left, const deque<_Ty, _Alloc>& _Right) {
1821-
return _Left.size() == _Right.size() &&
1822-
_STD equal(_Left._Unchecked_begin(), _Left._Unchecked_end(), _Right._Unchecked_begin());
1825+
return _Left.size() == _Right.size()
1826+
&& _STD equal(
1827+
_Left._Unchecked_begin(),
1828+
_Left._Unchecked_end(),
1829+
_Right._Unchecked_begin()
1830+
);
18231831
}
18241832

18251833
#if _HAS_CXX20

src/openvic-simulation/core/portable/ForwardableSpan.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ namespace OpenVic::_detail::forwardable_span {
4646
concept span_array_convertible = std::is_convertible_v<From (*)[], To (*)[]>;
4747

4848
template<class It, class T>
49-
concept span_compatible_iterator =
50-
std::contiguous_iterator<It> && span_array_convertible<std::remove_reference_t<std::iter_reference_t<It>>, T>;
49+
concept span_compatible_iterator = std::contiguous_iterator<It>
50+
&& span_array_convertible<std::remove_reference_t<std::iter_reference_t<It>>, T>;
5151

5252
template<class Sentinel, class It>
53-
concept span_compatible_sentinel_for =
54-
std::sized_sentinel_for<Sentinel, It> && !std::is_convertible_v<Sentinel, std::size_t>;
53+
concept span_compatible_sentinel_for = std::sized_sentinel_for<Sentinel, It>
54+
&& !std::is_convertible_v<Sentinel, std::size_t>;
5555

5656
template<size_t Extent>
5757
struct extent_storage {

src/openvic-simulation/core/random/RandomGenerator.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ namespace OpenVic {
1515
struct RandomGenerator {
1616
using generator_type = T;
1717

18-
using state_type =
19-
std::conditional_t<requires { typename generator_type::state_type; }, typename generator_type::state_type, void>;
20-
using result_type =
21-
std::conditional_t<requires { typename generator_type::result_type; }, typename generator_type::result_type, void>;
18+
using state_type = std::conditional_t<
19+
requires { typename generator_type::state_type; },
20+
typename generator_type::state_type,
21+
void
22+
>;
23+
using result_type = std::conditional_t<
24+
requires { typename generator_type::result_type; },
25+
typename generator_type::result_type,
26+
void
27+
>;
2228

2329
[[nodiscard]] OV_ALWAYS_INLINE explicit constexpr RandomGenerator()
2430
requires requires {

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

0 commit comments

Comments
 (0)