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
203 double GetSum();
204
211 double MultiplyAndGetSum(ResourceLedger& other);
212
213 std::string to_string();
214
215 // All the things that we get from map
216 using LedgerMap::operator[];
217 using LedgerMap::operator=;
218 using LedgerMap::begin;
219 using LedgerMap::cbegin;
220 using LedgerMap::cend;
221 using LedgerMap::clear;
222 using LedgerMap::contains;
223 using LedgerMap::crbegin;
224 using LedgerMap::crend;
225 using LedgerMap::emplace;
226 using LedgerMap::empty;
227 using LedgerMap::end;
228 using LedgerMap::erase;
229 using LedgerMap::mapped_type;
230 using LedgerMap::rbegin;
231 using LedgerMap::rend;
232 using LedgerMap::size;
233 using LedgerMap::value_comp;
234};
235
236ResourceLedger CopyVals(const ResourceLedger& keys, const ResourceLedger& values);
238
240 entt::entity entity;
241 double amount;
242 ResourceLedger operator*(const double value) const;
244};
245
246struct Recipe {
250 float interval;
251 // The actual factory worker amount is workers * productivity
252 double workers;
253
255};
256
260};
261
262// Factory size
264 double size;
266 double wages = 100;
267};
268
270 double revenue;
271 // How much it paid in materials to produce goods
273 // How much cash it took to maintain the factory
275 // How much it paid to people
276 double wages;
277 double profit;
278 // How much it paid in transport fees
279 double transport;
280
281 void Reset() {
282 revenue = 0;
283 materialcosts = 0;
284 maintenance = 0;
285 wages = 0;
286 profit = 0;
287 transport = 0;
288 }
289};
290
291//Essentially resource consumption + production
295};
296
297// TODO(AGM): Remove
299 float interval;
301};
302
303//Resource generator
304
307
309 entt::entity recipe;
310};
311
313
315 // Ledgers later to show how much
316};
317
319
321
323 std::map<entt::entity, double> dist;
324};
325} // 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
ResourceLedger ResourceLedgerZip(const ResourceLedger &key, const ResourceLedger &value)
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:269
double maintenance
Definition: resource.h:274
double transport
Definition: resource.h:279
double revenue
Definition: resource.h:270
double materialcosts
Definition: resource.h:272
double profit
Definition: resource.h:277
void Reset()
Definition: resource.h:281
double wages
Definition: resource.h:276
Definition: resource.h:38
cqsp::common::components::types::joule energy
Definition: resource.h:40
Definition: resource.h:298
float interval
Definition: resource.h:299
float time_left
Definition: resource.h:300
Definition: resource.h:50
Definition: resource.h:263
double size
Definition: resource.h:264
double utilization
Definition: resource.h:265
double wages
Definition: resource.h:266
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:257
ResourceLedger scaling
Definition: resource.h:259
ResourceLedger fixed
Definition: resource.h:258
Definition: resource.h:246
RecipeOutput output
Definition: resource.h:248
float interval
Definition: resource.h:250
ResourceLedger capitalcost
Definition: resource.h:254
ResourceLedger input
Definition: resource.h:247
ProductionType type
Definition: resource.h:249
double workers
Definition: resource.h:252
Definition: resource.h:239
ResourceLedger operator*(const double value) const
Definition: resource.cpp:404
entt::entity entity
Definition: resource.h:240
double amount
Definition: resource.h:241
entt::entity recipe
Definition: resource.h:309
std::map< entt::entity, double > dist
Definition: resource.h:323
Definition: resource.h:292
ResourceLedger input
Definition: resource.h:293
ResourceLedger output
Definition: resource.h:294
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