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
72 changes: 35 additions & 37 deletions src/headless/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,44 +261,42 @@ static bool run_headless(fs::path const& root, memory::vector<memory::string>& m
print_memory_usage("Game Session Post-Start");

// TODO - REMOVE TEST CODE
InstanceManager& instance_manager = *game_manager.get_instance_manager();
SPDLOG_INFO("===== Ranking system test... =====");
if (game_manager.get_instance_manager()) {
const auto print_ranking_list = [ //
](std::string_view title, OpenVic::forwardable_span<const std::reference_wrapper<CountryInstance>> countries) -> void {
memory::string countries_str;
for (CountryInstance& country : countries) {
countries_str += fmt::format(
"\n\t{} - Total #{} ({:.1}), Prestige #{} ({:.1}), Industry #{} ({:.1}), Military #{} ({:.1})", //
country, //
country.get_total_rank(), country.total_score.get_untracked(), //
country.get_prestige_rank(), country.get_prestige_untracked(),
country.get_industrial_rank(), country.get_industrial_power_untracked(),
country.get_military_rank(), country.military_power.get_untracked()
);
}
SPDLOG_INFO("{}:{}", title, countries_str);
};

CountryInstanceManager const& country_instance_manager = game_manager.get_instance_manager()->get_country_instance_manager();

OpenVic::forwardable_span<const std::reference_wrapper<CountryInstance>> great_powers = country_instance_manager.get_great_powers();
print_ranking_list("Great Powers", great_powers);
print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
print_ranking_list("All countries", country_instance_manager.get_total_ranking());

SPDLOG_INFO("===== RGO test... =====");
for (size_t i = 0; i < std::min<size_t>(3, great_powers.size()); ++i) {
CountryInstance const& great_power = great_powers[i];
ProvinceInstance const* const capital_province = great_power.get_capital();
if (capital_province == nullptr) {
spdlog::warn_s("{} has no capital ProvinceInstance set.", great_power);
} else {
print_rgo(*capital_province);
}
const auto print_ranking_list = [](
std::string_view title,
OpenVic::forwardable_span<const std::reference_wrapper<CountryInstance>> countries
) -> void {
memory::string countries_str;
for (CountryInstance& country : countries) {
countries_str += fmt::format(
"\n\t{} - Total #{} ({:.1}), Prestige #{} ({:.1}), Industry #{} ({:.1}), Military #{} ({:.1})", //
country, //
country.get_total_rank(), country.total_score.get_untracked(), //
country.get_prestige_rank(), country.get_prestige_untracked(),
country.get_industrial_rank(), country.get_industrial_power_untracked(),
country.get_military_rank(), country.military_power.get_untracked()
);
}
SPDLOG_INFO("{}:{}", title, countries_str);
};

CountryInstanceManager const& country_instance_manager = game_manager.get_instance_manager()->get_country_instance_manager();

OpenVic::forwardable_span<const std::reference_wrapper<CountryInstance>> great_powers = country_instance_manager.get_great_powers();
print_ranking_list("Great Powers", great_powers);
print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
print_ranking_list("All countries", country_instance_manager.get_total_ranking());

SPDLOG_INFO("===== RGO test... =====");
for (size_t i = 0; i < std::min<size_t>(3, great_powers.size()); ++i) {
CountryInstance const& great_power = great_powers[i];
ProvinceInstance const* const capital_province = great_power.get_capital();
if (capital_province == nullptr) {
spdlog::warn_s("{} has no capital ProvinceInstance set.", great_power);
} else {
print_rgo(*capital_province);
}
} else {
spdlog::error_s("Instance manager not available!");
ret = false;
}

if (ret) {
Expand All @@ -308,7 +306,7 @@ static bool run_headless(fs::path const& root, memory::vector<memory::string>& m

using test_time_units_t = std::chrono::milliseconds;

MapInstance& map_instance = game_manager.get_instance_manager()->get_map_instance();
MapInstance& map_instance = instance_manager.get_map_instance();

SPDLOG_INFO("===== Land Pathfinding test... =====");
test_duration_t duration = std::chrono::duration_cast<test_time_units_t>( //
Expand Down
8 changes: 5 additions & 3 deletions src/openvic-simulation/core/Hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ namespace OpenVic {
s = h(v) << (sizeof(T) * CHAR_BIT);
(
[&] {
// If args is not last pointer of args
if (static_cast<void const*>(&(std::get<sizeof...(args) - 1>(arg_tuple))) !=
static_cast<void const*>(&args)) {
void const* const args_ptr = static_cast<void const*>(&args);
void const* const last_pointer_of_args = static_cast<void const*>(
&(std::get<sizeof...(args) - 1>(arg_tuple))
);
if (args_ptr != last_pointer_of_args) {
s <<= sizeof(Args) * CHAR_BIT;
}
s |= std::hash<Args> {}(args);
Expand Down
20 changes: 14 additions & 6 deletions src/openvic-simulation/core/portable/Deque.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,8 +1022,10 @@ namespace OpenVic::utility::_detail::deque {
// (_Myoff() + _Mysize() - 1) is for the last element, i.e. the back() of the deque.
// Divide by _Block_size to get the unmasked index of the last used block.
// Add 1 to get the unmasked index of the first unused block.
const auto _Unmasked_first_unused_block_idx =
static_cast<size_type>(((_Myoff() + _Mysize() - 1) / _Block_size) + 1);
const auto _Unmasked_first_unused_block_idx = static_cast<size_type>(
((_Myoff() + _Mysize() - 1) / _Block_size)
+ 1
);

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

Expand All @@ -1037,8 +1039,10 @@ namespace OpenVic::utility::_detail::deque {
}
}

const auto _Used_block_count =
static_cast<size_type>(_Unmasked_first_unused_block_idx - _Unmasked_first_used_block_idx);
const auto _Used_block_count = static_cast<size_type>(
_Unmasked_first_unused_block_idx
- _Unmasked_first_used_block_idx
);

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

Expand Down Expand Up @@ -1818,8 +1822,12 @@ namespace OpenVic::utility::_detail::deque {

_EXPORT_STD template<class _Ty, class _Alloc>
_NODISCARD bool operator==(const deque<_Ty, _Alloc>& _Left, const deque<_Ty, _Alloc>& _Right) {
return _Left.size() == _Right.size() &&
_STD equal(_Left._Unchecked_begin(), _Left._Unchecked_end(), _Right._Unchecked_begin());
return _Left.size() == _Right.size()
&& _STD equal(
_Left._Unchecked_begin(),
_Left._Unchecked_end(),
_Right._Unchecked_begin()
);
}

#if _HAS_CXX20
Expand Down
8 changes: 4 additions & 4 deletions src/openvic-simulation/core/portable/ForwardableSpan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ namespace OpenVic::_detail::forwardable_span {
concept span_array_convertible = std::is_convertible_v<From (*)[], To (*)[]>;

template<class It, class T>
concept span_compatible_iterator =
std::contiguous_iterator<It> && span_array_convertible<std::remove_reference_t<std::iter_reference_t<It>>, T>;
concept span_compatible_iterator = std::contiguous_iterator<It>
&& span_array_convertible<std::remove_reference_t<std::iter_reference_t<It>>, T>;

template<class Sentinel, class It>
concept span_compatible_sentinel_for =
std::sized_sentinel_for<Sentinel, It> && !std::is_convertible_v<Sentinel, std::size_t>;
concept span_compatible_sentinel_for = std::sized_sentinel_for<Sentinel, It>
&& !std::is_convertible_v<Sentinel, std::size_t>;

template<size_t Extent>
struct extent_storage {
Expand Down
14 changes: 10 additions & 4 deletions src/openvic-simulation/core/random/RandomGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ namespace OpenVic {
struct RandomGenerator {
using generator_type = T;

using state_type =
std::conditional_t<requires { typename generator_type::state_type; }, typename generator_type::state_type, void>;
using result_type =
std::conditional_t<requires { typename generator_type::result_type; }, typename generator_type::result_type, void>;
using state_type = std::conditional_t<
requires { typename generator_type::state_type; },
typename generator_type::state_type,
void
>;
using result_type = std::conditional_t<
requires { typename generator_type::result_type; },
typename generator_type::result_type,
void
>;

[[nodiscard]] OV_ALWAYS_INLINE explicit constexpr RandomGenerator()
requires requires {
Expand Down
18 changes: 10 additions & 8 deletions src/openvic-simulation/core/template/Concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ namespace OpenVic {
concept not_same_as = !std::same_as<T, T2>;

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

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

template<typename Allocator>
concept copy_insertable_allocator = enable_copy_insertable<Allocator>::value ||
move_insertable_allocator_for<Allocator, typename Allocator::value_type const&>;
concept copy_insertable_allocator = enable_copy_insertable<Allocator>::value
|| move_insertable_allocator_for<Allocator, typename Allocator::value_type const&>;

template<typename T>
struct enable_copy_insertable<std::allocator<T>> : std::is_copy_constructible<T> {};
Expand All @@ -58,8 +59,8 @@ namespace OpenVic {
struct enable_move_insertable : std::false_type {};

template<typename Allocator>
concept move_insertable_allocator =
enable_move_insertable<Allocator>::value || move_insertable_allocator_for<Allocator, typename Allocator::value_type>;
concept move_insertable_allocator = enable_move_insertable<Allocator>::value
|| move_insertable_allocator_for<Allocator, typename Allocator::value_type>;

template<typename T>
struct enable_move_insertable<std::allocator<T>> : std::is_move_constructible<T> {};
Expand Down Expand Up @@ -111,8 +112,9 @@ namespace OpenVic {
concept is_strongly_typed = derived_from_specialization_of<T, type_safe::strong_typedef>;

template<typename T>
concept has_index = requires { typename T::index_t; } &&
is_strongly_typed<typename T::index_t> && requires {
concept has_index = requires { typename T::index_t; }
&& is_strongly_typed<typename T::index_t>
&& requires {
static_cast<std::size_t>(
static_cast<type_safe::underlying_type<decltype(std::declval<T>().index)>>(std::declval<T>().index)
);
Expand Down
28 changes: 14 additions & 14 deletions src/openvic-simulation/country/CountryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,9 +1541,9 @@ void CountryInstance::_update_technology(const Date today) {
}

daily_research_points += get_modifier_effect_value(*modifier_effect_cache.get_research_points());
daily_research_points *= fixed_point_t::_1 +
get_modifier_effect_value(*modifier_effect_cache.get_research_points_modifier()) +
get_modifier_effect_value(*modifier_effect_cache.get_increase_research());
daily_research_points *= fixed_point_t::_1
+ get_modifier_effect_value(*modifier_effect_cache.get_research_points_modifier())
+ get_modifier_effect_value(*modifier_effect_cache.get_increase_research());

if (daily_research_points.get_untracked() < 0) {
daily_research_points.set(0);
Expand Down Expand Up @@ -1692,8 +1692,8 @@ void CountryInstance::_update_military() {

// Mobilisation calculations
mobilisation_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilization_impact());
mobilisation_economy_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_tech()) +
get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_country());
mobilisation_economy_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_tech())
+ get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_country());

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

Expand All @@ -1712,9 +1712,9 @@ void CountryInstance::_update_military() {
get_modifier_effect_value(*modifier_effect_cache.get_max_war_exhaustion()), fixed_point_t::_0
);

organisation_regain = fixed_point_t::_1 +
get_modifier_effect_value(*modifier_effect_cache.get_org_regain()) +
get_modifier_effect_value(*modifier_effect_cache.get_morale_global());
organisation_regain = fixed_point_t::_1
+ get_modifier_effect_value(*modifier_effect_cache.get_org_regain())
+ get_modifier_effect_value(*modifier_effect_cache.get_morale_global());

land_organisation = fixed_point_t::_1 + get_modifier_effect_value(*modifier_effect_cache.get_land_organisation());
naval_organisation = fixed_point_t::_1 + get_modifier_effect_value(*modifier_effect_cache.get_naval_organisation());
Expand All @@ -1730,17 +1730,17 @@ void CountryInstance::_update_military() {
get_modifier_effect_value(*modifier_effect_cache.get_combat_width_additive())
);
dig_in_cap = get_modifier_effect_value(*modifier_effect_cache.get_dig_in_cap()).floor<int32_t>();
military_tactics = military_defines.get_base_military_tactics() +
get_modifier_effect_value(*modifier_effect_cache.get_military_tactics());
military_tactics = military_defines.get_base_military_tactics()
+ get_modifier_effect_value(*modifier_effect_cache.get_military_tactics());

if (leadership_point_stockpile < 0) {
leadership_point_stockpile = 0;
}
create_leader_count = (leadership_point_stockpile / military_defines.get_leader_recruit_cost()).floor<int32_t>();

monthly_leadership_points += get_modifier_effect_value(*modifier_effect_cache.get_leadership());
monthly_leadership_points *= fixed_point_t::_1 +
get_modifier_effect_value(*modifier_effect_cache.get_leadership_modifier());
monthly_leadership_points *= fixed_point_t::_1
+ get_modifier_effect_value(*modifier_effect_cache.get_leadership_modifier());

if (monthly_leadership_points < 0) {
monthly_leadership_points = 0;
Expand Down Expand Up @@ -1985,8 +1985,8 @@ void CountryInstance::update_gamestate_after_map(const Date today) {
_update_politics();
_update_diplomacy();

const CountryDefinition::government_colour_map_t::const_iterator it =
country_definition.get_alternative_colours().find(government_type.get_untracked());
using const_it_t = typename CountryDefinition::government_colour_map_t::const_iterator;
const const_it_t it = country_definition.get_alternative_colours().find(government_type.get_untracked());

if (it != country_definition.get_alternative_colours().end()) {
colour = it.value();
Expand Down
5 changes: 3 additions & 2 deletions src/openvic-simulation/country/CountryInstanceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ CountryInstance const& CountryInstanceManager::get_country_instance_by_definitio
}

bool CountryInstanceManager::apply_history_to_countries(InstanceManager& instance_manager) {
CountryHistoryManager const& history_manager =
instance_manager.definition_manager.get_history_manager().get_country_manager();
CountryHistoryManager const& history_manager = instance_manager.definition_manager
.get_history_manager()
.get_country_manager();

bool ret = true;

Expand Down
35 changes: 22 additions & 13 deletions src/openvic-simulation/dataloader/Dataloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "openvic-simulation/core/string/Utility.hpp"
#include "openvic-simulation/core/template/Concepts.hpp"
#include "openvic-simulation/DefinitionManager.hpp"
#include "openvic-simulation/history/Bookmark.hpp"
#include "openvic-simulation/history/HistoryManager.hpp"
#include "openvic-simulation/interface/UI.hpp"
#include "openvic-simulation/misc/GameRulesManager.hpp"
#include "openvic-simulation/misc/SoundEffect.hpp"
Expand Down Expand Up @@ -378,9 +380,10 @@ bool Dataloader::_load_pop_types(DefinitionManager& definition_manager) {

bool ret = pop_manager.setup_stratas();

GoodDefinitionManager const& good_definition_manager =
definition_manager.get_economy_manager().get_good_definition_manager();
IdeologyManager const& ideology_manager = definition_manager.get_politics_manager().get_ideology_manager();
EconomyManager const& economy_manager = definition_manager.get_economy_manager();
GoodDefinitionManager const& good_definition_manager = economy_manager.get_good_definition_manager();
PoliticsManager const& politics_manager = definition_manager.get_politics_manager();
IdeologyManager const& ideology_manager = politics_manager.get_ideology_manager();

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

Expand Down Expand Up @@ -585,8 +588,10 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
DeploymentManager& deployment_manager = definition_manager.get_military_manager().get_deployment_manager();

static constexpr std::string_view country_history_directory = "history/countries";
const path_vector_t country_history_files =
lookup_basic_identifier_prefixed_files_in_dir(country_history_directory, ".txt");
const path_vector_t country_history_files = lookup_basic_identifier_prefixed_files_in_dir(
country_history_directory,
".txt"
);

country_history_manager.reserve_more_country_histories(country_history_files.size());
deployment_manager.reserve_more_deployments(country_history_files.size());
Expand All @@ -597,8 +602,10 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
const memory::string filename = file.stem().string<char>(memory::string::allocator_type{});
const std::string_view country_id = extract_basic_identifier_prefix(filename);

CountryDefinition const* country =
definition_manager.get_country_definition_manager().get_country_definition_by_identifier(country_id);
CountryDefinitionManager const& country_definition_manager = definition_manager.get_country_definition_manager();
CountryDefinition const* country = country_definition_manager.get_country_definition_by_identifier(
country_id
);
if (country == nullptr) {
if (unused_history_file_warnings) {
spdlog::warn_s("Found history file for non-existent country: {}", country_id);
Expand All @@ -623,14 +630,17 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
}
}

HistoryManager& history_manager = definition_manager.get_history_manager();
{
/* Province History */
ProvinceHistoryManager& province_history_manager = definition_manager.get_history_manager().get_province_manager();
MapDefinition const& map_definition = definition_manager.get_map_definition();

static constexpr std::string_view province_history_directory = "history/provinces";
const path_vector_t province_history_files =
lookup_basic_identifier_prefixed_files_in_dir_recursive(province_history_directory, ".txt");
const path_vector_t province_history_files = lookup_basic_identifier_prefixed_files_in_dir_recursive(
province_history_directory,
".txt"
);

province_history_manager.reserve_more_province_histories(province_history_files.size());

Expand Down Expand Up @@ -660,8 +670,8 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
static constexpr std::string_view pop_history_directory = "history/pops/";

const string_set_t pop_history_dirs = lookup_dirs_in_dir(pop_history_directory);
const Date last_bookmark_date =
definition_manager.get_history_manager().get_bookmark_manager().get_last_bookmark_date();
BookmarkManager const& bookmark_manager = history_manager.get_bookmark_manager();
const Date last_bookmark_date = bookmark_manager.get_last_bookmark_date();

for (memory::string const& dir : pop_history_dirs) {
Date::from_chars_result result;
Expand Down Expand Up @@ -692,8 +702,7 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse

{
/* Diplomacy History */
DiplomaticHistoryManager& diplomatic_history_manager =
definition_manager.get_history_manager().get_diplomacy_manager();
DiplomaticHistoryManager& diplomatic_history_manager = history_manager.get_diplomacy_manager();

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

Expand Down
Loading
Loading