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
29namespace cqsp {
30namespace common {
31namespace components {
35struct Matter {
38};
39
40struct Energy {
41 // Energy per unit
43};
44
48struct Unit {
49 std::string unit_name;
50};
51
52struct Good {};
53
68};
69
70struct Mineral {};
71// Good is for capital goods
72struct CapitalGood {};
73
74typedef std::map<entt::entity, double> LedgerMap;
75
76class ResourceLedger : private LedgerMap {
77 public:
78 ResourceLedger() = default;
79 ~ResourceLedger() = default;
80
81 double operator[](const entt::entity) const;
82
88 bool EnoughToTransfer(const ResourceLedger& amount);
89
90 void operator-=(const ResourceLedger&);
91 void operator+=(const ResourceLedger&);
92 void operator*=(const ResourceLedger&);
93 void operator/=(const ResourceLedger&);
94 void operator-=(const double value);
95 void operator+=(const double value);
96 void operator*=(const double value);
97 void operator/=(const double value);
98
103 ResourceLedger operator-(const double value) const;
104 ResourceLedger operator+(const double value) const;
105 ResourceLedger operator*(const double value) const;
106 ResourceLedger operator/(const double value) const;
107
111 bool operator<(const ResourceLedger&);
112
116 bool operator>(const ResourceLedger&);
117
121 bool operator<=(const ResourceLedger&);
122
126 bool operator>=(const ResourceLedger&);
127
128 bool LedgerEquals(const ResourceLedger&);
129
133 bool operator>(const double&);
134
138 bool operator<(const double&);
139
140 bool operator==(const double&);
141
142 bool operator<=(const double&);
143 bool operator>=(const double&);
144
145 void AssignFrom(const ResourceLedger&);
146
148 // Equivalant to this += other * double
149 void MultiplyAdd(const ResourceLedger&, double);
150
157
163
167 ResourceLedger UnitLedger(const double);
168
169 // Add all the positive values in the other ledger to this ledger
170 // Essentially this += other (if idx > 0)
171 void AddPositive(const ResourceLedger&);
172
173 // Add all the negative values in the other ledger to this ledger
174 // Essentially this += abs(other) (if idx < 0)
175 void AddNegative(const ResourceLedger&);
176
180 ResourceLedger Clamp(const double, const double);
181
186
191 double Average();
192
193 double Min();
194 double Max();
195
201 bool HasAllResources(const ResourceLedger&);
202
203 bool HasGood(entt::entity good) { return (*this).find(good) != (*this).end(); }
204
205 double GetSum();
206
213 double MultiplyAndGetSum(ResourceLedger& other);
214
215 std::string to_string();
216
217 // All the things that we get from map
218 using LedgerMap::operator[];
219 using LedgerMap::operator=;
220 using LedgerMap::begin;
221 using LedgerMap::cbegin;
222 using LedgerMap::cend;
223 using LedgerMap::clear;
224 using LedgerMap::contains;
225 using LedgerMap::crbegin;
226 using LedgerMap::crend;
227 using LedgerMap::emplace;
228 using LedgerMap::empty;
229 using LedgerMap::end;
230 using LedgerMap::erase;
231 using LedgerMap::mapped_type;
232 using LedgerMap::rbegin;
233 using LedgerMap::rend;
234 using LedgerMap::size;
235 using LedgerMap::value_comp;
236};
237
238ResourceLedger 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 double size;
268 double wages = 100;
269};
270
272 double revenue;
273 // How much it paid in materials to produce goods
275 // How much cash it took to maintain the factory
277 // How much it paid to people
278 double wages;
279 double profit;
280 // How much it paid in transport fees
281 double transport;
282
283 void Reset() {
284 revenue = 0;
285 materialcosts = 0;
286 maintenance = 0;
287 wages = 0;
288 profit = 0;
289 transport = 0;
290 }
291};
292
293//Essentially resource consumption + production
297};
298
299// TODO(AGM): Remove
301 float interval;
303};
304
305//Resource generator
306
309
311 entt::entity recipe;
312};
313
315
317 // Ledgers later to show how much
318};
319
321
323
325 std::map<entt::entity, double> dist;
326};
327} // namespace components
328} // namespace common
329} // namespace cqsp
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:203
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
ProductionType
Definition: area.h:30
ResourceLedger ResourceLedgerZip(const ResourceLedger &key, const ResourceLedger &value)
std::map< entt::entity, double > LedgerMap
Definition: resource.h:74
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
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: clientctx.h:22
Definition: resource.h:72
See SysPopulationConsumption for an explanation of these values
Definition: resource.h:57
double autonomous_consumption
Definition: resource.h:62
double marginal_propensity
Definition: resource.h:67
Definition: resource.h:271
double maintenance
Definition: resource.h:276
double transport
Definition: resource.h:281
double revenue
Definition: resource.h:272
double materialcosts
Definition: resource.h:274
double profit
Definition: resource.h:279
void Reset()
Definition: resource.h:283
double wages
Definition: resource.h:278
Definition: resource.h:40
cqsp::common::components::types::joule energy
Definition: resource.h:42
Definition: resource.h:300
float interval
Definition: resource.h:301
float time_left
Definition: resource.h:302
Definition: resource.h:52
Definition: resource.h:265
double size
Definition: resource.h:266
double utilization
Definition: resource.h:267
double wages
Definition: resource.h:268
Something that has a mass.
Definition: resource.h:35
cqsp::common::components::types::meter_cube volume
Definition: resource.h:36
cqsp::common::components::types::kilogram mass
Definition: resource.h:37
Definition: resource.h:70
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:311
std::map< entt::entity, double > dist
Definition: resource.h:325
Definition: resource.h:294
ResourceLedger input
Definition: resource.h:295
ResourceLedger output
Definition: resource.h:296
The unit name of the good. If it doesn't have it, then it's a quantity.
Definition: resource.h:48
std::string unit_name
Definition: resource.h:49