aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic-simulation/country/CountryInstance.cpp2
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp3
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp59
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp23
-rw-r--r--src/openvic-simulation/research/Invention.hpp6
-rw-r--r--src/openvic-simulation/research/Technology.hpp4
-rw-r--r--src/openvic-simulation/types/Vector.cpp79
-rw-r--r--src/openvic-simulation/types/Vector.hpp132
8 files changed, 193 insertions, 115 deletions
diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp
index d4f9be7..5da787e 100644
--- a/src/openvic-simulation/country/CountryInstance.cpp
+++ b/src/openvic-simulation/country/CountryInstance.cpp
@@ -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);
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 45e6d4f..02ff239 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -7,7 +7,6 @@
#include <optional>
#include <set>
#include <type_traits>
-#include <unordered_set>
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
@@ -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;
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp
index d312261..9ee7d65 100644
--- a/src/openvic-simulation/history/CountryHistory.cpp
+++ b/src/openvic-simulation/history/CountryHistory.cpp
@@ -1,6 +1,7 @@
#include "CountryHistory.hpp"
#include "openvic-simulation/GameManager.hpp"
+#include <string_view>
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -21,10 +22,13 @@ bool CountryHistoryMap::_load_history_entry(
PoliticsManager const& politics_manager = game_manager.get_politics_manager();
IssueManager const& issue_manager = politics_manager.get_issue_manager();
CultureManager const& culture_manager = game_manager.get_pop_manager().get_culture_manager();
+ CountryManager const& country_manager = game_manager.get_country_manager();
+ TechnologyManager const& technology_manager = game_manager.get_research_manager().get_technology_manager();
+ InventionManager const& invention_manager = game_manager.get_research_manager().get_invention_manager();
return expect_dictionary_keys_and_default(
- [this, &game_manager, &dataloader, &deployment_manager, &issue_manager, &entry](
- std::string_view key, ast::NodeCPtr value) -> bool {
+ [this, &game_manager, &dataloader, &deployment_manager, &issue_manager,
+ &technology_manager, &invention_manager, &country_manager, &entry](std::string_view key, ast::NodeCPtr value) -> bool {
ReformGroup const* reform_group = issue_manager.get_reform_group_by_identifier(key);
if (reform_group != nullptr) {
return issue_manager.expect_reform_identifier([&entry, reform_group](Reform const& reform) -> bool {
@@ -46,9 +50,25 @@ bool CountryHistoryMap::_load_history_entry(
return true;
})(value);
}
- // TODO: technologies & inventions
+
+ Technology const* technology = technology_manager.get_technology_by_identifier(key);
+ if (technology != nullptr) {
+ bool flag;
+ if (expect_int_bool(assign_variable_callback(flag))(value)) {
+ return entry.technologies.emplace(technology, flag).second;
+ } else return false;
+ }
+
+ Invention const* invention = invention_manager.get_invention_by_identifier(key);
+ if (invention != nullptr) {
+ bool flag;
+ if (expect_bool(assign_variable_callback(flag))(value)) {
+ return entry.inventions.emplace(invention, flag).second;
+ } else return false;
+ }
+
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
@@ -93,8 +113,35 @@ bool CountryHistoryMap::_load_history_entry(
return ret;
}
),
- "schools", ZERO_OR_ONE, success_callback, // TODO: technology school
- "foreign_investment", ZERO_OR_ONE, success_callback // TODO: foreign investment
+ "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)),
+ "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);
}
diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp
index ed200bf..af7d502 100644
--- a/src/openvic-simulation/history/CountryHistory.hpp
+++ b/src/openvic-simulation/history/CountryHistory.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <map>
-#include <vector>
+#include <optional>
#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/history/Bookmark.hpp"
@@ -16,6 +16,8 @@
#include "openvic-simulation/pop/Religion.hpp"
#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/Date.hpp"
+#include "openvic-simulation/research/Invention.hpp"
+#include "openvic-simulation/research/Technology.hpp"
namespace OpenVic {
struct CountryHistoryMap;
@@ -36,12 +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);
- // TODO: technologies, tech schools, and inventions when PR#51 merged
- // TODO: starting foreign investment
+ 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);
};
diff --git a/src/openvic-simulation/research/Invention.hpp b/src/openvic-simulation/research/Invention.hpp
index 9cc158c..dc4256e 100644
--- a/src/openvic-simulation/research/Invention.hpp
+++ b/src/openvic-simulation/research/Invention.hpp
@@ -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);
diff --git a/src/openvic-simulation/research/Technology.hpp b/src/openvic-simulation/research/Technology.hpp
index 540d10f..52db87e 100644
--- a/src/openvic-simulation/research/Technology.hpp
+++ b/src/openvic-simulation/research/Technology.hpp
@@ -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);
diff --git a/src/openvic-simulation/types/Vector.cpp b/src/openvic-simulation/types/Vector.cpp
deleted file mode 100644
index 28f30bf..0000000
--- a/src/openvic-simulation/types/Vector.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "Vector.hpp"
-
-using namespace OpenVic;
-
-template<typename T>
-constexpr vec2_t<T>::vec2_t(T new_val) : x { new_val }, y { new_val } {}
-
-template<typename T>
-constexpr vec2_t<T>::vec2_t(T new_x, T new_y) : x { new_x }, y { new_y } {}
-
-template<typename T>
-constexpr vec2_t<T> vec2_t<T>::abs() const {
- return {};
-}
-
-template<typename T>
-constexpr T vec2_t<T>::length_squared() const {
- return x * x + y * y;
-}
-
-template<typename T>
-constexpr T* vec2_t<T>::data() {
- return reinterpret_cast<T*>(this);
-}
-
-template<typename T>
-constexpr T const* vec2_t<T>::data() const {
- return reinterpret_cast<T const*>(this);
-}
-
-template<typename T>
-constexpr T& vec2_t<T>::operator[](size_t index) {
- return data()[index & 1];
-}
-
-template<typename T>
-constexpr T const& vec2_t<T>::operator[](size_t index) const {
- return data()[index & 1];
-}
-
-template<typename T>
-constexpr vec2_t<T> operator+(vec2_t<T> const& left, vec2_t<T> const& right) {
- return { left.x + right.x, left.y + right.y };
-}
-
-template<typename T>
-constexpr vec2_t<T>& vec2_t<T>::operator+=(vec2_t const& right) {
- x += right.x;
- y += right.y;
- return *this;
-}
-
-template<typename T>
-constexpr vec2_t<T> operator-(vec2_t<T> const& arg) {
- return { -arg.x, -arg.y };
-}
-
-template<typename T>
-constexpr vec2_t<T> operator-(vec2_t<T> const& left, vec2_t<T> const& right) {
- return { left.x - right.x, left.y - right.y };
-}
-
-template<typename T>
-constexpr vec2_t<T>& vec2_t<T>::operator-=(vec2_t const& right) {
- x -= right.x;
- y -= right.y;
- return *this;
-}
-
-template<typename T>
-constexpr std::ostream& operator<<(std::ostream& stream, vec2_t<T> const& value) {
- return stream << "(" << value.x << ", " << value.y << ")";
-}
-
-template struct OpenVic::vec2_t<int64_t>;
-template struct OpenVic::vec2_t<fixed_point_t>;
-
-static_assert(sizeof(ivec2_t) == 2 * sizeof(ivec2_t::type), "ivec2_t size does not equal the sum of its parts' sizes");
-static_assert(sizeof(fvec2_t) == 2 * sizeof(fvec2_t::type), "fvec2_t size does not equal the sum of its parts' sizes");
diff --git a/src/openvic-simulation/types/Vector.hpp b/src/openvic-simulation/types/Vector.hpp
index 9f576d7..327806d 100644
--- a/src/openvic-simulation/types/Vector.hpp
+++ b/src/openvic-simulation/types/Vector.hpp
@@ -11,33 +11,129 @@ namespace OpenVic {
T x, y;
constexpr vec2_t() = default;
- constexpr vec2_t(T new_val);
- constexpr vec2_t(T new_x, T new_y);
+ constexpr vec2_t(T new_val) : x { new_val }, y { new_val } {}
+ constexpr vec2_t(T new_x, T new_y) : x { new_x }, y { new_y } {}
- constexpr vec2_t abs() const;
- constexpr T length_squared() const;
+ constexpr vec2_t abs() const {
+ return { x >= 0 ? x : -x, y >= 0 ? y : -y };
+ }
+ constexpr T length_squared() const {
+ return x * x + y * y;
+ }
- constexpr T* data();
- constexpr T const* data() const;
+ constexpr T* data() {
+ return reinterpret_cast<T*>(this);
+ }
+ constexpr T const* data() const {
+ return reinterpret_cast<T const*>(this);
+ }
- constexpr T& operator[](size_t index);
- constexpr T const& operator[](size_t index) const;
+ constexpr T& operator[](size_t index) {
+ return data()[index & 1];
+ }
+ constexpr T const& operator[](size_t index) const {
+ return data()[index & 1];
+ }
- template<typename S>
- constexpr friend vec2_t<S> operator+(vec2_t<S> const& left, vec2_t<S> const& right);
- constexpr vec2_t& operator+=(vec2_t const& right);
+ constexpr friend vec2_t operator+(vec2_t const& left, vec2_t const& right) {
+ return { left.x + right.x, left.y + right.y };
+ }
+ constexpr vec2_t& operator+=(vec2_t const& right) {
+ x += right.x;
+ y += right.y;
+ return *this;
+ }
+ constexpr friend vec2_t operator+(vec2_t const& left, T const& right) {
+ return { left.x + right, left.y + right };
+ }
+ constexpr friend vec2_t operator+(T const& left, vec2_t const& right) {
+ return { left + right.x, left + right.y };
+ }
+ constexpr vec2_t& operator+=(T const& right) {
+ x += right;
+ y += right;
+ return *this;
+ }
- template<typename S>
- constexpr friend vec2_t<S> operator-(vec2_t<S> const& arg);
+ constexpr friend vec2_t operator-(vec2_t const& arg) {
+ return { -arg.x, -arg.y };
+ }
- template<typename S>
- constexpr friend vec2_t<S> operator-(vec2_t<S> const& left, vec2_t<S> const& right);
- constexpr vec2_t& operator-=(vec2_t const& right);
+ constexpr friend vec2_t operator-(vec2_t const& left, vec2_t const& right) {
+ return { left.x - right.x, left.y - right.y };
+ }
+ constexpr vec2_t& operator-=(vec2_t const& right) {
+ x -= right.x;
+ y -= right.y;
+ return *this;
+ }
+ constexpr friend vec2_t operator-(vec2_t const& left, T const& right) {
+ return { left.x - right, left.y - right };
+ }
+ constexpr friend vec2_t operator-(T const& left, vec2_t const& right) {
+ return { left - right.x, left - right.y };
+ }
+ constexpr vec2_t& operator-=(T const& right) {
+ x -= right;
+ y -= right;
+ return *this;
+ }
- template<typename S>
- constexpr friend std::ostream& operator<<(std::ostream& stream, vec2_t<S> const& value);
+ constexpr friend vec2_t operator*(vec2_t const& left, vec2_t const& right) {
+ return { left.x * right.x, left.y * right.y };
+ }
+ constexpr vec2_t& operator*=(vec2_t const& right) {
+ x *= right.x;
+ y *= right.y;
+ return *this;
+ }
+ constexpr friend vec2_t operator*(vec2_t const& left, T const& right) {
+ return { left.x * right, left.y * right };
+ }
+ constexpr friend vec2_t operator*(T const& left, vec2_t const& right) {
+ return { left * right.x, left * right.y };
+ }
+ constexpr vec2_t& operator*=(T const& right) {
+ x *= right;
+ y *= right;
+ return *this;
+ }
+
+ constexpr friend vec2_t operator/(vec2_t const& left, vec2_t const& right) {
+ return { left.x / right.x, left.y / right.y };
+ }
+ constexpr vec2_t& operator/=(vec2_t const& right) {
+ x /= right.x;
+ y /= right.y;
+ return *this;
+ }
+ constexpr friend vec2_t operator/(vec2_t const& left, T const& right) {
+ return { left.x / right, left.y / right };
+ }
+ constexpr friend vec2_t operator/(T const& left, vec2_t const& right) {
+ return { left / right.x, left / right.y };
+ }
+ constexpr vec2_t& operator/=(T const& right) {
+ x /= right;
+ y /= right;
+ return *this;
+ }
+
+ constexpr friend bool operator==(vec2_t const& left, vec2_t const& right) {
+ return left.x == right.x && left.y == right.y;
+ }
+ constexpr friend bool operator!=(vec2_t const& left, vec2_t const& right) {
+ return left.x != right.x || left.y != right.y;
+ }
+
+ constexpr friend std::ostream& operator<<(std::ostream& stream, vec2_t const& value) {
+ return stream << "(" << value.x << ", " << value.y << ")";
+ }
};
using ivec2_t = vec2_t<int32_t>;
using fvec2_t = vec2_t<fixed_point_t>;
+
+ static_assert(sizeof(ivec2_t) == 2 * sizeof(ivec2_t::type), "ivec2_t size does not equal the sum of its parts' sizes");
+ static_assert(sizeof(fvec2_t) == 2 * sizeof(fvec2_t::type), "fvec2_t size does not equal the sum of its parts' sizes");
}