Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
universe.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2025 Conquer Space
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <fmt/format.h>
20
21#include <map>
22#include <memory>
23#include <ranges>
24#include <string>
25#include <vector>
26
27#include <entt/entt.hpp>
28
33
34namespace cqsp::common {
35
36class Node;
37
38class Universe : public entt::registry {
39 public:
40 explicit Universe(std::string uuid);
41 Universe();
42
44
45 std::map<std::string, entt::entity> goods;
46 std::vector<entt::entity> consumergoods;
47 std::map<std::string, entt::entity> recipes;
48 std::map<std::string, entt::entity> terrain_data;
49 std::map<std::string, actions::NameGenerator> name_generators;
50 std::map<std::string, entt::entity> fields;
51 std::map<std::string, entt::entity> technologies;
52 std::map<std::string, entt::entity> planets;
53 std::map<std::string, entt::entity> time_zones;
54 std::map<std::string, entt::entity> countries;
55 std::map<std::string, entt::entity> provinces;
56 std::map<std::string, entt::entity> cities;
57 // color -> province map
58 std::map<entt::entity, std::map<int, entt::entity>> province_colors;
59 // province -> color
60 std::map<entt::entity, std::map<entt::entity, int>> colors_province;
61 entt::entity sun;
62
63 void EnableTick() { to_tick = true; }
64 void DisableTick() { to_tick = false; }
65 bool ToTick() { return to_tick; }
66 void ToggleTick() { to_tick = !to_tick; }
67
68 int GetDate() { return date.GetDate(); }
69 std::unique_ptr<cqsp::common::util::IRandom> random;
70 std::string uuid;
71
75 double tick_fraction = 0;
76 std::function<Node(entt::entity)> nodeFactory;
77 auto nodeTransform() { return std::views::transform(nodeFactory); }
78 std::vector<Node> Convert(const std::vector<entt::entity>& entities);
79 template <typename... Components>
80 auto nodes() {
81 return this->template view<Components...>() | nodeTransform();
82 }
83
84 systems::EconomyConfig economy_config;
85
86 private:
87 bool to_tick = false;
88};
89
90class Node : public entt::handle {
91 public:
92 explicit Node(Universe& universe, entt::entity entity);
93 Node(entt::handle handle, entt::entity entity);
94 explicit Node(Universe& universe);
95 Universe& universe() const;
96 std::vector<Node> Convert(const std::vector<entt::entity>& entities);
97 Node Convert(const entt::entity entity);
98};
99
100} // namespace cqsp::common
101
102template <>
103struct fmt::formatter<entt::entity> : formatter<std::string> {
104 template <typename FormatContext>
105 constexpr auto format(entt::entity entity, FormatContext& ctx) const {
106 return formatter<std::string>::format(std::to_string((uint64_t)entity), ctx);
107 }
108};
Definition: universe.h:90
Definition: universe.h:38
void DisableTick()
Definition: universe.h:64
std::map< std::string, actions::NameGenerator > name_generators
Definition: universe.h:49
std::unique_ptr< cqsp::common::util::IRandom > random
Definition: universe.h:69
std::map< entt::entity, std::map< int, entt::entity > > province_colors
Definition: universe.h:58
std::map< std::string, entt::entity > recipes
Definition: universe.h:47
std::vector< entt::entity > consumergoods
Definition: universe.h:46
int GetDate()
Definition: universe.h:68
std::map< std::string, entt::entity > planets
Definition: universe.h:52
std::map< std::string, entt::entity > terrain_data
Definition: universe.h:48
std::map< entt::entity, std::map< entt::entity, int > > colors_province
Definition: universe.h:60
systems::EconomyConfig economy_config
Definition: universe.h:84
std::map< std::string, entt::entity > goods
Definition: universe.h:45
std::map< std::string, entt::entity > cities
Definition: universe.h:56
auto nodeTransform()
Definition: universe.h:77
std::map< std::string, entt::entity > countries
Definition: universe.h:54
std::function< Node(entt::entity)> nodeFactory
Definition: universe.h:76
components::StarDate date
Definition: universe.h:43
void ToggleTick()
Definition: universe.h:66
Universe()
Definition: universe.cpp:26
bool ToTick()
Definition: universe.h:65
std::map< std::string, entt::entity > fields
Definition: universe.h:50
double tick_fraction
What is the current fraction of the wait of the tick we are processing
Definition: universe.h:75
std::map< std::string, entt::entity > provinces
Definition: universe.h:55
std::map< std::string, entt::entity > time_zones
Definition: universe.h:53
auto nodes()
Definition: universe.h:80
std::map< std::string, entt::entity > technologies
Definition: universe.h:51
entt::entity sun
Definition: universe.h:61
std::vector< Node > Convert(const std::vector< entt::entity > &entities)
Definition: universe.cpp:32
void EnableTick()
Definition: universe.h:63
bool to_tick
Definition: universe.h:87
std::string uuid
Definition: universe.h:70
Holds and calculates the tick that is on going. Date is the number of hours that has been ongoing sin...
Definition: stardate.h:45
int GetDate()
Definition: stardate.h:56
std::vector< std::string > entities
Definition: loadcities.cpp:40
Definition: cityactions.cpp:23
Definition: universe.h:103
constexpr auto format(entt::entity entity, FormatContext &ctx) const
Definition: universe.h:105
common::Universe * universe
Definition: turnsavewindow.h:3