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-2023 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 UnitLeger(const double);
168
172 ResourceLedger Clamp(const double, const double);
173
178
183 double Average();
184
185 double Min();
186 double Max();
187
193 bool HasAllResources(const ResourceLedger&);
194
195 bool HasGood(entt::entity good) { return (*this).find(good) != (*this).end(); }
196
197 double GetSum();
198
205 double MultiplyAndGetSum(ResourceLedger& other);
206
207 std::string to_string();
208
209 // All the things that we get from map
210 using LedgerMap::operator[];
211 using LedgerMap::begin;
212 using LedgerMap::cbegin;
213 using LedgerMap::cend;
214 using LedgerMap::clear;
215 using LedgerMap::crbegin;
216 using LedgerMap::crend;
217 using LedgerMap::emplace;
218 using LedgerMap::empty;
219 using LedgerMap::end;
220 using LedgerMap::mapped_type;
221 using LedgerMap::rbegin;
222 using LedgerMap::rend;
223 using LedgerMap::size;
224 using LedgerMap::value_comp;
225};
226
227ResourceLedger CopyVals(const ResourceLedger& keys, const ResourceLedger& values);
229
231 entt::entity entity;
232 double amount;
233 ResourceLedger operator*(const double value) const;
235};
236
237struct Recipe {
241 float interval;
242 // The actual factory worker amount is workers * productivity
243 double workers;
244
246};
247
251};
252
253// Factory size
255 double size;
257 double wages = 100;
258};
259
261 double revenue;
262 // How much it paid in materials to produce goods
264 // How much cash it took to maintain the factory
266 // How much it paid to people
267 double wages;
268 double profit;
269 // How much it paid in transport fees
270 double transport;
271
272 void Reset() {
273 revenue = 0;
274 materialcosts = 0;
275 maintenance = 0;
276 wages = 0;
277 profit = 0;
278 transport = 0;
279 }
280};
281
282//Essentially resource consumption + production
286};
287
288// TODO(AGM): Remove
290 float interval;
292};
293
294//Resource generator
295
298
300 entt::entity recipe;
301};
302
304
306 // Ledgers later to show how much
307};
308
310
312
314 std::map<entt::entity, double> dist;
315};
316} // namespace components
317} // namespace common
318} // namespace cqsp
bool HasAllResources(const ResourceLedger &)
Checks if this current resource ledger has any resources in this list
Definition: resource.cpp:315
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:301
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:338
double MultiplyAndGetSum(ResourceLedger &other)
Multiplies the numbers stated in the resource ledger. Used for calculating the price,...
Definition: resource.cpp:330
ResourceLedger UnitLeger(const double)
Returns a copy of the vector with the values set to indicated value
Definition: resource.cpp:293
bool operator==(const double &)
Definition: resource.cpp:223
double Min()
Finds the smallest value in the Ledger.
Definition: resource.cpp:356
ResourceLedger operator-(const ResourceLedger &) const
Definition: resource.cpp:165
bool operator>=(const ResourceLedger &)
All resources in this ledger are greater than or equal to the other ledger
Definition: resource.cpp:229
bool LedgerEquals(const ResourceLedger &)
Definition: resource.cpp:233
void operator/=(const ResourceLedger &)
Definition: resource.cpp:129
void operator-=(const ResourceLedger &)
Definition: resource.cpp:111
bool operator>(const ResourceLedger &)
All resources in this ledger are greater than the other ledger
Definition: resource.cpp:241
void RemoveResourcesLimited(const ResourceLedger &)
Removes the resources, and if the amount of resources removed are more than the resources inside the ...
Definition: resource.cpp:268
void operator*=(const ResourceLedger &)
Definition: resource.cpp:123
ResourceLedger operator/(const ResourceLedger &) const
Definition: resource.cpp:177
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:322
double Max()
Finds the largest value in the Ledger.
Definition: resource.cpp:368
void TransferTo(ResourceLedger &, const ResourceLedger &)
Definition: resource.cpp:255
void AssignFrom(const ResourceLedger &)
Definition: resource.cpp:249
ResourceLedger operator*(const ResourceLedger &) const
Definition: resource.cpp:171
void MultiplyAdd(const ResourceLedger &, double)
Definition: resource.cpp:262
std::string to_string()
Definition: resource.cpp:378
ResourceLedger LimitedRemoveResources(const ResourceLedger &)
Same as RemoveResourcesLimited, except that it returns how much resources it took out.
Definition: resource.cpp:278
bool operator<(const ResourceLedger &)
All resources in this ledger are smaller than than the other ledger
Definition: resource.cpp:237
double Average()
Returns a copy of the vector divided by the indicated vector, with division by zero resulting in infi...
Definition: resource.cpp:376
bool HasGood(entt::entity good)
Definition: resource.h:195
void operator+=(const ResourceLedger &)
Definition: resource.cpp:117
bool operator<=(const ResourceLedger &)
All resources in this ledger are smaller than or equal to than the other ledger
Definition: resource.cpp:245
ResourceLedger operator+(const ResourceLedger &) const
Definition: resource.cpp:159
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:404
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: clientctx.h:21
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:260
double maintenance
Definition: resource.h:265
double transport
Definition: resource.h:270
double revenue
Definition: resource.h:261
double materialcosts
Definition: resource.h:263
double profit
Definition: resource.h:268
void Reset()
Definition: resource.h:272
double wages
Definition: resource.h:267
Definition: resource.h:40
cqsp::common::components::types::joule energy
Definition: resource.h:42
Definition: resource.h:289
float interval
Definition: resource.h:290
float time_left
Definition: resource.h:291
Definition: resource.h:52
Definition: resource.h:254
double size
Definition: resource.h:255
double utilization
Definition: resource.h:256
double wages
Definition: resource.h:257
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:248
ResourceLedger scaling
Definition: resource.h:250
ResourceLedger fixed
Definition: resource.h:249
Definition: resource.h:237
RecipeOutput output
Definition: resource.h:239
float interval
Definition: resource.h:241
ResourceLedger capitalcost
Definition: resource.h:245
ResourceLedger input
Definition: resource.h:238
ProductionType type
Definition: resource.h:240
double workers
Definition: resource.h:243
Definition: resource.h:230
ResourceLedger operator*(const double value) const
Definition: resource.cpp:390
entt::entity entity
Definition: resource.h:231
double amount
Definition: resource.h:232
entt::entity recipe
Definition: resource.h:300
std::map< entt::entity, double > dist
Definition: resource.h:314
Definition: resource.h:283
ResourceLedger input
Definition: resource.h:284
ResourceLedger output
Definition: resource.h:285
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