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
32
33namespace cqsp::common {
34
35class Node;
36
37class Universe : public entt::registry {
38 public:
39 explicit Universe(std::string uuid);
40 Universe();
41
43
44 std::map<std::string, entt::entity> goods;
45 std::vector<entt::entity> consumergoods;
46 std::map<std::string, entt::entity> recipes;
47 std::map<std::string, entt::entity> terrain_data;
48 std::map<std::string, actions::NameGenerator> name_generators;
49 std::map<std::string, entt::entity> fields;
50 std::map<std::string, entt::entity> technologies;
51 std::map<std::string, entt::entity> planets;
52 std::map<std::string, entt::entity> time_zones;
53 std::map<std::string, entt::entity> countries;
54 std::map<std::string, entt::entity> provinces;
55 std::map<std::string, entt::entity> cities;
56 // color -> province map
57 std::map<entt::entity, std::map<int, entt::entity>> province_colors;
58 // province -> color
59 std::map<entt::entity, std::map<entt::entity, int>> colors_province;
60 entt::entity sun;
61
62 void EnableTick() { to_tick = true; }
63 void DisableTick() { to_tick = false; }
64 bool ToTick() { return to_tick; }
65 void ToggleTick() { to_tick = !to_tick; }
66
67 int GetDate() { return date.GetDate(); }
68 std::unique_ptr<cqsp::common::util::IRandom> random;
69 std::string uuid;
70
74 double tick_fraction = 0;
75 std::function<Node(entt::entity)> nodeFactory;
76 auto nodeTransform() { return std::views::transform(nodeFactory); }
77 std::vector<Node> Convert(const std::vector<entt::entity>& entities);
78 template <typename... Components>
79 auto nodes() { return this->template view<Components...>() | nodeTransform();}
80
81 private:
82 bool to_tick = false;
83};
84
85class Node : public entt::handle {
86 public:
87 explicit Node(Universe& universe, entt::entity entity);
88 Node(entt::handle handle, entt::entity entity);
89 explicit Node(Universe& universe);
90 Universe& universe() const;
91 std::vector<Node> Convert(const std::vector<entt::entity>& entities);
92 Node Convert(const entt::entity entity);
93};
94
95} // namespace cqsp::common
96
97template <>
98struct fmt::formatter<entt::entity> : formatter<std::string> {
99 template <typename FormatContext>
100 constexpr auto format(entt::entity entity, FormatContext& ctx) const {
101 return formatter<std::string>::format(std::to_string((uint64_t)entity), ctx);
102 }
103};
Definition: universe.h:85
Definition: universe.h:37
void DisableTick()
Definition: universe.h:63
std::map< std::string, actions::NameGenerator > name_generators
Definition: universe.h:48
std::unique_ptr< cqsp::common::util::IRandom > random
Definition: universe.h:68
std::map< entt::entity, std::map< int, entt::entity > > province_colors
Definition: universe.h:57
std::map< std::string, entt::entity > recipes
Definition: universe.h:46
std::vector< entt::entity > consumergoods
Definition: universe.h:45
int GetDate()
Definition: universe.h:67
std::map< std::string, entt::entity > planets
Definition: universe.h:51
std::map< std::string, entt::entity > terrain_data
Definition: universe.h:47
std::map< entt::entity, std::map< entt::entity, int > > colors_province
Definition: universe.h:59
std::map< std::string, entt::entity > goods
Definition: universe.h:44
std::map< std::string, entt::entity > cities
Definition: universe.h:55
auto nodeTransform()
Definition: universe.h:76
std::map< std::string, entt::entity > countries
Definition: universe.h:53
std::function< Node(entt::entity)> nodeFactory
Definition: universe.h:75
components::StarDate date
Definition: universe.h:42
void ToggleTick()
Definition: universe.h:65
Universe()
Definition: universe.cpp:26
bool ToTick()
Definition: universe.h:64
std::map< std::string, entt::entity > fields
Definition: universe.h:49
double tick_fraction
What is the current fraction of the wait of the tick we are processing
Definition: universe.h:74
std::map< std::string, entt::entity > provinces
Definition: universe.h:54
std::map< std::string, entt::entity > time_zones
Definition: universe.h:52
auto nodes()
Definition: universe.h:79
std::map< std::string, entt::entity > technologies
Definition: universe.h:50
entt::entity sun
Definition: universe.h:60
std::vector< Node > Convert(const std::vector< entt::entity > &entities)
Definition: universe.cpp:32
void EnableTick()
Definition: universe.h:62
bool to_tick
Definition: universe.h:82
std::string uuid
Definition: universe.h:69
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:98
constexpr auto format(entt::entity entity, FormatContext &ctx) const
Definition: universe.h:100
common::Universe * universe
Definition: turnsavewindow.h:3