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.
resource.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 <iostream>
20#include <map>
21#include <string>
22#include <vector>
23
24#include <entt/entt.hpp>
25
28
33struct Matter {
36};
37
38struct Energy {
39 // Energy per unit
41};
42
46struct Unit {
47 std::string unit_name;
48};
49
50struct Good {};
51
66};
67
68struct Mineral {};
69// Good is for capital goods
70struct CapitalGood {};
71
72typedef std::map<entt::entity, double> LedgerMap;
73
74class ResourceLedger : private LedgerMap {
75 public:
76 ResourceLedger() = default;
77 ~ResourceLedger() = default;
78
79 double operator[](const entt::entity) const;
80
86 bool EnoughToTransfer(const ResourceLedger& amount);
87
88 void operator-=(const ResourceLedger&);
89 void operator+=(const ResourceLedger&);
90 void operator*=(const ResourceLedger&);
91 void operator/=(const ResourceLedger&);
92 void operator-=(const double value);
93 void operator+=(const double value);
94 void operator*=(const double value);
95 void operator/=(const double value);
96
101 ResourceLedger operator-(const double value) const;
102 ResourceLedger operator+(const double value) const;
103 ResourceLedger operator*(const double value) const;
104 ResourceLedger operator/(const double value) const;
105
109 bool operator<(const ResourceLedger&);
110
114 bool operator>(const ResourceLedger&);
115
119 bool operator<=(const ResourceLedger&);
120
124 bool operator>=(const ResourceLedger&);
125
126 bool LedgerEquals(const ResourceLedger&);
127
131 bool operator>(const double&);
132
136 bool operator<(const double&);
137
138 bool operator==(const double&);
139
140 bool operator<=(const double&);
141 bool operator>=(const double&);
142
143 void AssignFrom(const ResourceLedger&);
144
146 // Equivalant to this += other * double
147 void MultiplyAdd(const ResourceLedger&, double);
148
155
161
165 ResourceLedger UnitLedger(const double);
166
167 // Add all the positive values in the other ledger to this ledger
168 // Essentially this += other (if idx > 0)
169 void AddPositive(const ResourceLedger&);
170
171 // Add all the negative values in the other ledger to this ledger
172 // Essentially this += abs(other) (if idx < 0)
173 void AddNegative(const ResourceLedger&);
174
178 ResourceLedger Clamp(const double, const double);
179
184
189 double Average();
190
191 double Min();
192 double Max();
193
199 bool HasAllResources(const ResourceLedger&);
200
201 bool HasGood(entt::entity good) { return (*this).find(good) != (*this).end(); }
202
206 double GetSum();
207
214 double MultiplyAndGetSum(ResourceLedger& other);
215
216 std::string to_string();
217
218 // All the things that we get from map
219 using LedgerMap::operator[];
220 using LedgerMap::operator=;
221 using LedgerMap::begin;
222 using LedgerMap::cbegin;
223 using LedgerMap::cend;
224 using LedgerMap::clear;
225 using LedgerMap::contains;
226 using LedgerMap::crbegin;
227 using LedgerMap::crend;
228 using LedgerMap::emplace;
229 using LedgerMap::empty;
230 using LedgerMap::end;
231 using LedgerMap::erase;
232 using LedgerMap::mapped_type;
233 using LedgerMap::rbegin;
234 using LedgerMap::rend;
235 using LedgerMap::size;
236 using LedgerMap::value_comp;
237};
238
239ResourceLedger CopyVals(const ResourceLedger& keys, const ResourceLedger& values);
240
242 entt::entity entity;
243 double amount;
244 ResourceLedger operator*(const double value) const;
246};
247
248struct Recipe {
252 float interval;
253 // The actual factory worker amount is workers * productivity
254 double workers;
255
257};
258
262};
263
264// Factory size
266 // The size of the factory.
267 // the maximum output of the factory is
268 double size;
269 // The utilization of the factory.
271
272 double workers;
273 double wages = 100;
274};
275
277 double revenue;
278 // How much it paid in materials to produce goods
280 // How much cash it took to maintain the factory
282 // How much it paid to people
283 double wages;
284 double profit;
285 // How much it paid in transport fees
286 double transport;
287
288 void Reset() {
289 revenue = 0;
290 materialcosts = 0;
291 maintenance = 0;
292 wages = 0;
293 profit = 0;
294 transport = 0;
295 }
296};
297
298//Essentially resource consumption + production
302};
303
304// TODO(AGM): Remove
306 float interval;
308};
309
310//Resource generator
311
314
316 entt::entity recipe;
317};
318
320
322 // Ledgers later to show how much
323};
324
326
328
330 std::map<entt::entity, double> dist;
331};
332} // namespace cqsp::common::components
bool HasAllResources(const ResourceLedger &)
Checks if this current resource ledger has any resources in this list
Definition: resource.cpp:329
ResourceLedger Clamp(const double, const double)
Returns a copy of the vector with the values clamped between the min and max indicated
Definition: resource.cpp:315
ResourceLedger SafeDivision(const ResourceLedger &)
Returns a copy of the vector divided by the indicated vector, with division by zero resulting in infi...
Definition: resource.cpp:352
double MultiplyAndGetSum(ResourceLedger &other)
Multiplies the numbers stated in the resource ledger. Used for calculating the price,...
Definition: resource.cpp:344
bool operator==(const double &)
Definition: resource.cpp:237
double Min()
Finds the smallest value in the Ledger.
Definition: resource.cpp:370
ResourceLedger operator-(const ResourceLedger &) const
Definition: resource.cpp:179
bool operator>=(const ResourceLedger &)
All resources in this ledger are greater than or equal to the other ledger
Definition: resource.cpp:243
bool LedgerEquals(const ResourceLedger &)
Definition: resource.cpp:247
void operator/=(const ResourceLedger &)
Definition: resource.cpp:143
void operator-=(const ResourceLedger &)
Definition: resource.cpp:125
void AddPositive(const ResourceLedger &)
Definition: resource.cpp:111
bool operator>(const ResourceLedger &)
All resources in this ledger are greater than the other ledger
Definition: resource.cpp:255
void RemoveResourcesLimited(const ResourceLedger &)
Removes the resources, and if the amount of resources removed are more than the resources inside the ...
Definition: resource.cpp:282
void operator*=(const ResourceLedger &)
Definition: resource.cpp:137
ResourceLedger operator/(const ResourceLedger &) const
Definition: resource.cpp:191
ResourceLedger UnitLedger(const double)
Returns a copy of the vector with the values set to indicated value
Definition: resource.cpp:307
bool EnoughToTransfer(const ResourceLedger &amount)
This resource ledger has enough resources inside to transfer "amount" amount of resources away
Definition: resource.cpp:103
double GetSum()
Definition: resource.cpp:336
void AddNegative(const ResourceLedger &)
Definition: resource.cpp:118
double Max()
Finds the largest value in the Ledger.
Definition: resource.cpp:382
void TransferTo(ResourceLedger &, const ResourceLedger &)
Definition: resource.cpp:269
void AssignFrom(const ResourceLedger &)
Definition: resource.cpp:263
ResourceLedger operator*(const ResourceLedger &) const
Definition: resource.cpp:185
void MultiplyAdd(const ResourceLedger &, double)
Definition: resource.cpp:276
std::string to_string()
Definition: resource.cpp:392
ResourceLedger LimitedRemoveResources(const ResourceLedger &)
Same as RemoveResourcesLimited, except that it returns how much resources it took out.
Definition: resource.cpp:292
bool operator<(const ResourceLedger &)
All resources in this ledger are smaller than than the other ledger
Definition: resource.cpp:251
double Average()
Returns a copy of the vector divided by the indicated vector, with division by zero resulting in infi...
Definition: resource.cpp:390
bool HasGood(entt::entity good)
Definition: resource.h:201
void operator+=(const ResourceLedger &)
Definition: resource.cpp:131
bool operator<=(const ResourceLedger &)
All resources in this ledger are smaller than or equal to than the other ledger
Definition: resource.cpp:259
ResourceLedger operator+(const ResourceLedger &) const
Definition: resource.cpp:173
double operator[](const entt::entity) const
Definition: resource.cpp:94
double kilogram
Definition: units.h:39
double joule
Definition: units.h:41
double meter_cube
Definition: units.h:38
Definition: area.h:23
ProductionType
Definition: area.h:28
std::map< entt::entity, double > LedgerMap
Definition: resource.h:72
ResourceLedger CopyVals(const ResourceLedger &keys, const ResourceLedger &values)
Creates a new resource ledger using the keys from one resource ledger, and the values from annother
Definition: resource.cpp:418
Definition: resource.h:70
See SysPopulationConsumption for an explanation of these values
Definition: resource.h:55
double autonomous_consumption
Definition: resource.h:60
double marginal_propensity
Definition: resource.h:65
Definition: resource.h:276
double maintenance
Definition: resource.h:281
double transport
Definition: resource.h:286
double revenue
Definition: resource.h:277
double materialcosts
Definition: resource.h:279
double profit
Definition: resource.h:284
void Reset()
Definition: resource.h:288
double wages
Definition: resource.h:283
Definition: resource.h:38
cqsp::common::components::types::joule energy
Definition: resource.h:40
Definition: resource.h:305
float interval
Definition: resource.h:306
float time_left
Definition: resource.h:307
Definition: resource.h:50
Definition: resource.h:265
double size
Definition: resource.h:268
double utilization
Definition: resource.h:270
double wages
Definition: resource.h:273
double workers
Definition: resource.h:272
Something that has a mass.
Definition: resource.h:33
cqsp::common::components::types::meter_cube volume
Definition: resource.h:34
cqsp::common::components::types::kilogram mass
Definition: resource.h:35
Definition: resource.h:68
Definition: resource.h:259
ResourceLedger scaling
Definition: resource.h:261
ResourceLedger fixed
Definition: resource.h:260
Definition: resource.h:248
RecipeOutput output
Definition: resource.h:250
float interval
Definition: resource.h:252
ResourceLedger capitalcost
Definition: resource.h:256
ResourceLedger input
Definition: resource.h:249
ProductionType type
Definition: resource.h:251
double workers
Definition: resource.h:254
Definition: resource.h:241
ResourceLedger operator*(const double value) const
Definition: resource.cpp:404
entt::entity entity
Definition: resource.h:242
double amount
Definition: resource.h:243
entt::entity recipe
Definition: resource.h:316
std::map< entt::entity, double > dist
Definition: resource.h:330
Definition: resource.h:299
ResourceLedger input
Definition: resource.h:300
ResourceLedger output
Definition: resource.h:301
The unit name of the good. If it doesn't have it, then it's a quantity.
Definition: resource.h:46
std::string unit_name
Definition: resource.h:47