39 #include <glm/vec2.hpp>
41 #include "eng3d/profiler.hpp"
42 #include "eng3d/string.hpp"
43 #include "eng3d/log.hpp"
44 #include "eng3d/luavm.hpp"
62 #define LIST_FOR_TYPE(type, list, list_type)\
63 inline const list_type<type*>& get_list(const type* = nullptr) const {\
66 inline list_type<type*>& get_list(const type* = nullptr) {\
69 list_type<type*> list;
71 #define CONST_LIST_FOR_LOCAL_TYPE(type, list, list_type)\
72 inline const list_type<type>& get_list(const type* = nullptr) const {\
75 inline list_type<type>& get_list(const type* = nullptr) {\
78 inline void insert(type& ptr) {\
79 auto& type_list = this->get_list((type*)nullptr);\
80 std::scoped_lock lock(list_mutex);\
81 ptr.cached_id = type::Id(type_list.size());\
82 Eng3D::Log::debug("world_insert", "Inserting object " #type " with ID=" + std::to_string(static_cast<size_t>(ptr.cached_id)));\
83 type_list.push_back(ptr);\
87 #define LIST_FOR_LOCAL_TYPE(type, list, list_type)\
88 inline const list_type<type>& get_list(const type* = nullptr) const {\
91 inline list_type<type>& get_list(const type* = nullptr) {\
94 inline void insert(type& ptr) {\
95 auto& type_list = this->get_list((type*)nullptr);\
96 std::scoped_lock lock(list_mutex);\
97 ptr.cached_id = type::Id(type_list.size());\
98 Eng3D::Log::debug("world_insert", "Inserting object " #type " with ID=" + std::to_string(static_cast<size_t>(ptr.cached_id)));\
99 type_list.push_back(ptr);\
101 inline void remove(type& ptr) {\
102 size_t cached_id = static_cast<size_t>(this->get_id<type>(ptr));\
103 auto& type_list = this->get_list((type*)nullptr);\
104 std::scoped_lock lock(list_mutex);\
105 cached_id = type_list.size();\
106 Eng3D::Log::debug("world_remove", "Removing object " #type " with ID=" + std::to_string(static_cast<size_t>(cached_id)));\
107 for(size_t i = cached_id + 1; i < type_list.size(); i++)\
108 type_list[i].cached_id = type::Id(static_cast<size_t>(type_list[i].cached_id) - 1);\
109 type_list.erase(type_list.begin() + cached_id);\
111 list_type<type> list;
129 void fire_special_event(
const std::string_view event_ref_name,
const std::string_view nation_ref_name,
const std::string_view other_nation_ref_name);
151 auto& list = this->get_list((T*)
nullptr);
153 ptr.cached_id = list.size();
154 assert(ptr.cached_id <
static_cast<typename T::Id
>(-2));
155 list.push_back((T*)&ptr);
161 size_t cached_id =
static_cast<size_t>(this->get_id<T>(ptr));
162 auto& list = this->get_list((T*)
nullptr);
164 for(
size_t i = cached_id + 1; i < list.size(); i++)
165 list[i].cached_id = T::Id(
static_cast<size_t>(list[i].cached_id) - 1);
167 list.erase(list.begin() + cached_id);
179 inline typename T::Id
get_id(
const T& obj)
const {
180 return obj.cached_id;
187 return std::fabs(std::fabs(y) - (this->
width / 2.0));
194 if(b > a) std::swap(a, b);
195 return relations[a + b * nations.size()];
200 if(b > a) std::swap(a, b);
201 return relations[a + b * nations.size()];
205 return this->
time / this->ticks_per_month / 12;
209 return (this->
time / this->ticks_per_month) % 12;
219 std::unique_ptr<ProvinceId[]>
tiles;
232 template<
bool is_const>
234 template<
bool is_serialize>
236 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.width);
237 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.height);
238 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.time);
239 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.commodities);
240 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.unit_types);
241 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.religions);
242 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.languages);
243 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.pop_types);
244 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.terrain_types);
245 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.building_types);
246 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.ideologies);
247 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.technologies);
248 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.nations);
249 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.provinces);
250 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.events);
251 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.treaties);
252 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.unit_manager);
253 Eng3D::Deser::deser_dynamic<is_serialize>(ar, obj.relations);
257 bool has_tiles = obj.tiles.get() !=
nullptr;
258 Eng3D::Deser::deser_dynamic<is_serialize>(ar, has_tiles);
260 if constexpr(is_serialize) {
267 obj.tiles.reset(
new ProvinceId[obj.width * obj.height]);
A single province, which is used to simulate economy in a "bulk-tiles" way instead of doing economica...
float get_dist_from_equator(float y) const
Get the dist from the equator in respect to Y.
bool needs_to_sync
Used to signal the lua scripts of invalid operations (eg. adding a country midgame)
int get_month(void) const
std::vector< std::pair< Decision, NationId > > taken_decisions
Nation::Relation & get_relation(NationId a, NationId b)
T::Id get_id(const T &obj) const
Get the id of an object, this is a template for all types except for tiles and locally-stored types (...
Economy::EconomyState economy_state
std::vector< Nation::Relation > relations
void fire_special_event(const std::string_view event_ref_name, const std::string_view nation_ref_name, const std::string_view other_nation_ref_name)
World & operator=(const World &)=delete
ProvinceManager province_manager
static World & get_instance()
std::unique_ptr< ProvinceId[]> tiles
constexpr static unsigned int ticks_per_month
const Nation::Relation & get_relation(NationId a, NationId b) const
Type for military outposts.
A commodity, mostly serves as a "product type".
Base class that serves as archiver, stores (in memory) the data required for serialization/deserializ...
void expand(size_t amount)
void copy_from(const void *ptr, size_t size)
void copy_to(void *ptr, size_t size)
static void deser_dynamic(Eng3D::Deser::Archive &ar, type< is_serialize > &obj)
typename Eng3D::Deser::CondConstType< is_const, World >::type type
A serializer (base class) which can be used to serialize objects and create per-object optimized clas...
Diplomatic relations between two nations.
Defines a type of unit, it can be a tank, garrison, infantry, etc this is moddable via a lua script a...
#define CONST_LIST_FOR_LOCAL_TYPE(type, list, list_type)
#define LIST_FOR_LOCAL_TYPE(type, list, list_type)