Skip to content

Commit

Permalink
Allow CountryParty ideology to be nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Hop311 committed Dec 16, 2024
1 parent a9f3012 commit c27dcd9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
21 changes: 16 additions & 5 deletions src/openvic-simulation/country/CountryDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ using namespace OpenVic;
using namespace OpenVic::NodeTools;

CountryParty::CountryParty(
std::string_view new_identifier, Date new_start_date, Date new_end_date, Ideology const& new_ideology,
std::string_view new_identifier, Date new_start_date, Date new_end_date, Ideology const* new_ideology,
policy_map_t&& new_policies
) : HasIdentifierAndColour { new_identifier, new_ideology.get_colour(), false }, start_date { new_start_date },
end_date { new_end_date }, ideology { new_ideology }, policies { std::move(new_policies) } {}
) : HasIdentifierAndColour {
new_identifier,
new_ideology != nullptr ? new_ideology->get_colour() : Ideology::NO_IDEOLOGY_COLOUR,
false
},
start_date { new_start_date },
end_date { new_end_date },
ideology { new_ideology },
policies { std::move(new_policies) } {}

CountryDefinition::CountryDefinition(
std::string_view new_identifier,
Expand Down Expand Up @@ -137,7 +144,7 @@ node_callback_t CountryDefinitionManager::load_country_party(
return [&politics_manager, &country_parties](ast::NodeCPtr value) -> bool {
std::string_view party_name;
Date start_date, end_date;
Ideology const* ideology;
Ideology const* ideology = nullptr;
CountryParty::policy_map_t policies { &politics_manager.get_issue_manager().get_issue_groups() };

bool ret = expect_dictionary_keys_and_default(
Expand Down Expand Up @@ -176,8 +183,12 @@ node_callback_t CountryDefinitionManager::load_country_party(
politics_manager.get_ideology_manager().expect_ideology_identifier(assign_variable_callback_pointer(ideology))
)(value);

if (ideology == nullptr) {
Logger::warning("Country party ", party_name, " has no ideology, defaulting to nullptr / no ideology");
}

ret &= country_parties.add_item(
{ party_name, start_date, end_date, *ideology, std::move(policies) }, duplicate_warning_callback
{ party_name, start_date, end_date, ideology, std::move(policies) }, duplicate_warning_callback
);

return ret;
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/country/CountryDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ namespace OpenVic {
private:
const Date PROPERTY(start_date);
const Date PROPERTY(end_date);
Ideology const& PROPERTY(ideology);
Ideology const* PROPERTY(ideology); // Can be nullptr, shows up as "No Ideology" in game
policy_map_t PROPERTY(policies);

CountryParty(
std::string_view new_identifier, Date new_start_date, Date new_end_date, Ideology const& new_ideology,
std::string_view new_identifier, Date new_start_date, Date new_end_date, Ideology const* new_ideology,
policy_map_t&& new_policies
);

Expand Down
2 changes: 2 additions & 0 deletions src/openvic-simulation/politics/Ideology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace OpenVic {
struct Ideology : HasIdentifierAndColour {
friend struct IdeologyManager;

static constexpr colour_t NO_IDEOLOGY_COLOUR = colour_t::fill_as(colour_t::max_value);

private:
IdeologyGroup const& PROPERTY(group);
const bool PROPERTY_CUSTOM_PREFIX(uncivilised, is);
Expand Down

0 comments on commit c27dcd9

Please sign in to comment.