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
194 double Average();
195
196 double Min();
197 double Max();
198
204 bool HasAllResources(const ResourceLedger&);
205
206 bool HasGood(entt::entity good) { return (*this).find(good) != (*this).end(); }
207
211 double GetSum();
212
219 double MultiplyAndGetSum(ResourceLedger& other);
220
221 std::string to_string();
222
223 // All the things that we get from map
224 using LedgerMap::operator[];
225 using LedgerMap::operator=;
226 using LedgerMap::begin;
227 using LedgerMap::cbegin;
228 using LedgerMap::cend;
229 using LedgerMap::clear;
230 using LedgerMap::contains;
231 using LedgerMap::crbegin;
232 using LedgerMap::crend;
233 using LedgerMap::emplace;
234 using LedgerMap::empty;
235 using LedgerMap::end;
236 using LedgerMap::erase;
237 using LedgerMap::mapped_type;
238 using LedgerMap::rbegin;
239 using LedgerMap::rend;
240 using LedgerMap::size;
241 using LedgerMap::value_comp;
242};
243
244ResourceLedger CopyVals(const ResourceLedger& keys, const ResourceLedger& values);
245
247 entt::entity entity;
248 double amount;
249 ResourceLedger operator*(const double value) const;
251};
252
253struct Recipe {
257 float interval;
258 // The actual factory worker amount is workers * productivity
259 double workers;
260
262};
263
267};
268
269// Factory size
271 // The size of the factory.
272 // the maximum output of the factory is
273 double size;
274 // The utilization of the factory.
276 double diff;
278
280 bool shortage = false;
281 double wages = 10;
282};
283
285 double revenue;
286 // How much it paid in materials to produce goods
288 // How much cash it took to maintain the factory
290 // How much it paid to people
291 double wages;
292 double profit;
293 // How much it paid in transport fees
294 double transport;
295
296 void Reset() {
297 revenue = 0;
298 materialcosts = 0;
299 maintenance = 0;
300 wages = 0;
301 profit = 0;
302 transport = 0;
303 }
304};
305
306// TODO(AGM): Remove
308 float interval;
310};
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:332
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:318
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:355
double MultiplyAndGetSum(ResourceLedger &other)
Multiplies the numbers stated in the resource ledger. Used for calculating the price,...
Definition: resource.cpp:347
bool operator==(const double &)
Definition: resource.cpp:237
double Min()
Finds the smallest value in the Ledger.
Definition: resource.cpp:388
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:285
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:310
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:339
void AddNegative(const ResourceLedger &)
Definition: resource.cpp:118
double Max()
Finds the largest value in the Ledger.
Definition: resource.cpp:403
void TransferTo(ResourceLedger &, const ResourceLedger &)
Definition: resource.cpp:272
void AssignFrom(const ResourceLedger &)
Definition: resource.cpp:266
ResourceLedger operator*(const ResourceLedger &) const
Definition: resource.cpp:185
void MultiplyAdd(const ResourceLedger &, double)
Definition: resource.cpp:279
std::string to_string()
Definition: resource.cpp:413
ResourceLedger LimitedRemoveResources(const ResourceLedger &)
Same as RemoveResourcesLimited, except that it returns how much resources it took out.
Definition: resource.cpp:295
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:411
bool HasGood(entt::entity good)
Definition: resource.h:206
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:439
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:284
double maintenance
Definition: resource.h:289
double transport
Definition: resource.h:294
double revenue
Definition: resource.h:285
double materialcosts
Definition: resource.h:287
double profit
Definition: resource.h:292
void Reset()
Definition: resource.h:296
double wages
Definition: resource.h:291
Definition: resource.h:38
types::joule energy
Definition: resource.h:40
Definition: resource.h:307
float interval
Definition: resource.h:308
float time_left
Definition: resource.h:309
Definition: resource.h:50
Definition: resource.h:270
int workers
Definition: resource.h:279
double size
Definition: resource.h:273
double diff
Definition: resource.h:276
double utilization
Definition: resource.h:275
double wages
Definition: resource.h:281
double diff_delta
Definition: resource.h:277
bool shortage
Definition: resource.h:280
Something that has a mass.
Definition: resource.h:33
types::kilogram mass
Definition: resource.h:35
types::meter_cube volume
Definition: resource.h:34
Definition: resource.h:68
Definition: resource.h:264
ResourceLedger scaling
Definition: resource.h:266
ResourceLedger fixed
Definition: resource.h:265
Definition: resource.h:253
RecipeOutput output
Definition: resource.h:255
float interval
Definition: resource.h:257
ResourceLedger capitalcost
Definition: resource.h:261
ResourceLedger input
Definition: resource.h:254
ProductionType type
Definition: resource.h:256
double workers
Definition: resource.h:259
Definition: resource.h:246
ResourceLedger operator*(const double value) const
Definition: resource.cpp:425
entt::entity entity
Definition: resource.h:247
double amount
Definition: resource.h:248
entt::entity recipe
Definition: resource.h:316
std::map< entt::entity, double > dist
Definition: resource.h:330
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