Skip to content

Commit

Permalink
feat: added missing country history keys (except decisions)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaaarf committed Dec 10, 2023
1 parent 5688655 commit 2c562ac
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/openvic-simulation/country/CountryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool CountryInstance::apply_history_to_country(CountryHistoryMap const& history,
if (entry->get_government_type()) government_type = *entry->get_government_type();
if (entry->get_plurality()) plurality = *entry->get_plurality();
if (entry->get_national_value()) national_value = *entry->get_national_value();
if (entry->get_civilised()) civilised = *entry->get_civilised();
if (entry->is_civilised()) civilised = *entry->is_civilised();
if (entry->get_prestige()) prestige = *entry->get_prestige();
for (Reform const* reform : entry->get_reforms()) {
ret &= add_reform(reform);
Expand Down
3 changes: 1 addition & 2 deletions src/openvic-simulation/dataloader/NodeTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <optional>
#include <set>
#include <type_traits>
#include <unordered_set>

#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>

Expand Down Expand Up @@ -344,7 +343,7 @@ namespace OpenVic {
}

template<typename T>
Callback<T const&> auto set_callback_pointer(std::unordered_set<T const*>& set) {
Callback<T const&> auto set_callback_pointer(std::set<T const*>& set) {
return [&set](T const& val) -> bool {
set.insert(&val);
return true;
Expand Down
41 changes: 31 additions & 10 deletions src/openvic-simulation/history/CountryHistory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "CountryHistory.hpp"

#include "openvic-simulation/GameManager.hpp"
#include <string_view>

using namespace OpenVic;
using namespace OpenVic::NodeTools;
Expand Down Expand Up @@ -52,14 +53,9 @@ bool CountryHistoryMap::_load_history_entry(

Technology const* technology = technology_manager.get_technology_by_identifier(key);
if (technology != nullptr) {
uint8_t flag = -1;
if (expect_uint(assign_variable_callback(flag))(value)) {
if (flag == 1) return entry.technologies.emplace(technology, true).second;
else if (flag == 0) return entry.technologies.emplace(technology, false).second;
else {
Logger::warning("Refusing to load country history technology with non-boolean value: ", key, ", ", flag);
return true;
}
bool flag;
if (expect_int_bool(assign_variable_callback(flag))(value)) {
return entry.technologies.emplace(technology, flag).second;
} else return false;
}

Expand All @@ -72,7 +68,7 @@ bool CountryHistoryMap::_load_history_entry(
}

return _load_history_sub_entry_callback(
game_manager, dataloader, deployment_manager, entry.get_date(), value, key, value, key_value_success_callback
game_manager, dataloader, deployment_manager, entry.get_date(), value, key, value
);
},
/* we have to use a lambda, assign_variable_callback_pointer
Expand Down Expand Up @@ -120,7 +116,32 @@ bool CountryHistoryMap::_load_history_entry(
"schools", ZERO_OR_ONE, technology_manager.expect_technology_school_identifier(
assign_variable_callback_pointer(entry.tech_school)
),
"foreign_investment", ZERO_OR_ONE, country_manager.expect_country_decimal_map(move_variable_callback(entry.foreign_investment))
"foreign_investment", ZERO_OR_ONE, country_manager.expect_country_decimal_map(move_variable_callback(entry.foreign_investment)),
"literacy", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.literacy)),
"non_state_culture_literacy", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.nonstate_culture_literacy)),
"consciousness", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.consciousness)),
"nonstate_consciousness", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.nonstate_consciousness)),
"is_releasable_vassal", ZERO_OR_ONE, expect_bool(assign_variable_callback(entry.releasable_vassal)),
"decision", ZERO_OR_ONE, success_callback, //TODO: decisions
"govt_flag", ZERO_OR_ONE, [&entry, &politics_manager](ast::NodeCPtr value) -> bool {
GovernmentType const* government_type = nullptr;
std::string_view flag;
bool ret = expect_dictionary_keys(
"government", ONE_EXACTLY, politics_manager.get_government_type_manager()
.expect_government_type_identifier(assign_variable_callback_pointer(government_type)),
"flag", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(flag))
)(value);
if (government_type != nullptr) {
return ret & entry.government_flags.emplace(government_type, flag).second;
} else return false;
},
"colonial_points", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.colonial_points)),
"set_country_flag", ZERO_OR_ONE, expect_identifier_or_string([&entry](std::string_view flag) -> bool {
return entry.country_flags.emplace(flag).second;
}),
"set_global_flag", ZERO_OR_ONE, expect_identifier_or_string([&entry](std::string_view flag) -> bool {
return entry.global_flags.emplace(flag).second;
})
)(root);
}

Expand Down
16 changes: 13 additions & 3 deletions src/openvic-simulation/history/CountryHistory.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#pragma once

#include <map>
#include <unordered_map>
#include <vector>
#include <optional>

#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/history/Bookmark.hpp"
Expand Down Expand Up @@ -39,14 +38,25 @@ namespace OpenVic {
std::optional<GovernmentType const*> PROPERTY(government_type);
std::optional<fixed_point_t> PROPERTY(plurality);
std::optional<NationalValue const*> PROPERTY(national_value);
std::optional<bool> PROPERTY(civilised);
std::optional<bool> PROPERTY_CUSTOM_PREFIX(civilised, is);
std::optional<fixed_point_t> PROPERTY(prestige);
std::vector<Reform const*> PROPERTY(reforms);
std::optional<Deployment const*> PROPERTY(inital_oob);
std::optional<TechnologySchool const*> PROPERTY(tech_school);
std::map<Technology const*, bool> PROPERTY(technologies);
std::map<Invention const*, bool> PROPERTY(inventions);
fixed_point_map_t<Country const*> PROPERTY(foreign_investment);
std::optional<fixed_point_t> PROPERTY(consciousness);
std::optional<fixed_point_t> PROPERTY(nonstate_consciousness);
std::optional<fixed_point_t> PROPERTY(literacy);
std::optional<fixed_point_t> PROPERTY(nonstate_culture_literacy);
std::optional<bool> PROPERTY_CUSTOM_PREFIX(releasable_vassal, is);
std::optional<fixed_point_t> PROPERTY(colonial_points);
string_set_t PROPERTY(country_flags);
string_set_t PROPERTY(global_flags);
std::map<GovernmentType const*, std::string> PROPERTY(government_flags);

//TODO: decisions

CountryHistoryEntry(Country const& new_country, Date new_date);
};
Expand Down
6 changes: 3 additions & 3 deletions src/openvic-simulation/research/Invention.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace OpenVic {
struct Invention : Modifier {
friend struct InventionManager;
//TODO implement limit and chance
using unit_set_t = std::unordered_set<Unit const*>;
using building_set_t = std::unordered_set<BuildingType const*>;
using crime_set_t = std::unordered_set<Crime const*>;
using unit_set_t = std::set<Unit const*>;
using building_set_t = std::set<BuildingType const*>;
using crime_set_t = std::set<Crime const*>;

private:
const bool PROPERTY_CUSTOM_PREFIX(news, is);
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/research/Technology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace OpenVic {
struct Technology : Modifier {
friend struct TechnologyManager;

using unit_set_t = std::unordered_set<Unit const*>;
using building_set_t = std::unordered_set<BuildingType const*>;
using unit_set_t = std::set<Unit const*>;
using building_set_t = std::set<BuildingType const*>;

private:
TechnologyArea const& PROPERTY(area);
Expand Down

0 comments on commit 2c562ac

Please sign in to comment.