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.
economy.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 <map>
20#include <set>
21#include <string>
22#include <vector>
23
24#include <entt/entt.hpp>
25
27
28namespace cqsp {
29namespace common {
30namespace components {
36 private:
41 bool current = true;
42
43 public:
45
46 // Might not need this in the future.
48
55
56 // Supply that existed, but not fufilled last time
57 // Surplus supply
59 // Demand that existed, but was not fufilled the last time
60 // Surplus demand
64
66
67 void ResetLedgers() {
68 // Reset the ledger values
70 demand().clear();
71 supply().clear();
72 }
73
75 if (current) {
76 return _supply;
77 } else {
78 return _previous_supply;
79 }
80 }
82 if (current) {
83 return _demand;
84 } else {
85 return _previous_demand;
86 }
87 }
88
90 if (current) {
91 return _previous_supply;
92 } else {
93 return _supply;
94 }
95 }
96
98 if (current) {
99 return _previous_demand;
100 } else {
101 return _demand;
102 }
103 }
104};
105
107 // Sum of the resources traded last time.
108 double supply;
109 double demand;
110 double price;
112 double sd_ratio;
114};
115
117 std::vector<entt::entity> participants; // The markets that are connected
118};
119
121 std::vector<MarketInformation> history;
122
123 std::map<entt::entity, MarketElementInformation> market_information;
124 std::map<entt::entity, MarketElementInformation> last_market_information;
125
126 std::set<entt::entity> participants;
127 // std::vector<std::pair<entt::entity, entt::entity>> neighbors;
128 entt::basic_sparse_set<entt::entity> connected_markets;
129
130 double GDP = 0;
131
132 // Math
133 void AddSupply(const ResourceLedger& stockpile);
134 void AddSupply(const ResourceLedger& stockpile, double multiplier);
135 void AddDemand(const ResourceLedger& stockpile);
136 void AddDemand(const ResourceLedger& stockpile, double multiplier);
137
138 double GetPrice(const ResourceLedger& stockpile);
139 double GetPrice(const entt::entity& good);
140 double GetSDRatio(const entt::entity& good);
141 double GetSupply(const entt::entity& good);
142 double GetDemand(const entt::entity& good);
143
144 void AddParticipant(entt::entity participant) { participants.insert(participant); }
145
146 MarketElementInformation& operator[](entt::entity ent) { return market_information[ent]; }
147
148 auto begin() { return market_information.begin(); }
149
150 auto end() { return market_information.end(); }
151};
152
158struct Price {
159 double price;
160
161 operator double() { return price; }
162};
163
174struct Currency {};
175
179struct CostTable : public ResourceLedger {};
180
181// TODO(EhWhoAmI): Add multiple currency support
182struct Wallet {
183 Wallet() = default;
184 Wallet(entt::entity _currency, double _balance) : balance(_balance), currency(_currency) {}
185
186 Wallet& operator+=(const double amount) {
187 this->balance += amount;
188 change += amount;
189 return *this;
190 }
191 Wallet& operator-=(const double amount) {
192 this->balance -= amount;
193 change -= amount;
194 GDP_change += amount;
195 // Record the money delta since last reset
196 return *this;
197 }
198
199 // Basic multiplication that logs the change
200 // TODO(EhWhoAmI): Make sure this is correct
201 Wallet& operator*=(const double coefficent) {
202 double newbalance = this->balance * coefficent;
203 double change = newbalance - this->balance;
204 if (change > 0) {
205 *this += change;
206 } else if (change < 0) {
207 *this -= change * -1;
208 }
209 return *this;
210 }
211
212 operator double() const { return balance; }
213
214 Wallet& operator=(double _balance) {
215 change += (_balance - balance);
216 if ((_balance - balance) < 0) {
217 GDP_change += _balance - balance;
218 }
219 balance = _balance;
220 return *this;
221 }
222
223 double GetBalance() const { return balance; }
224
225 double GetChange() const { return change; }
226
227 void Reset() {
228 change = 0;
229 GDP_change = 0;
230 }
231 double GetGDPChange() { return GDP_change; }
232
233 private:
234 double balance = 0;
235 double change = 0;
236 // Only records when spending money, so when money decreases
237 double GDP_change = 0;
238 entt::entity currency;
239};
240
245 entt::entity market;
246};
247
252 entt::entity market;
253};
254
255// This trade node has international connections
256// For space connections, the spaceport struct exists
258
265 entt::entity city;
266 int size;
267};
268
269// Something that hires people, and will pay the people
270struct Employer {
273 entt::entity segment;
274};
275
288};
289
291
292// This facility is bankrolled by something else, so if they run out of money
293// they can go to this wallet to ask for cash?
294struct Owned {
295 entt::entity owner;
296};
297
298struct TradePartners : std::vector<entt::entity> {};
299} // namespace components
300} // namespace common
301} // namespace cqsp
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: clientctx.h:22
Represents commercial areas and other amenities that generate economic activity. They don't export go...
Definition: economy.h:263
entt::entity city
The city that it's based in.
Definition: economy.h:265
int size
Definition: economy.h:266
Records the prices of goods and other things
Definition: economy.h:179
Will be handled in the future, but for now is just a market
Definition: economy.h:174
Definition: economy.h:270
int population_needed
Definition: economy.h:271
entt::entity segment
Definition: economy.h:273
int population_fufilled
Definition: economy.h:272
Population segment that is employed
Definition: economy.h:279
int working_population
The population that is available to work
Definition: economy.h:283
int employed_population
The current population is currently working.
Definition: economy.h:287
An actor in a market that trades goods.
Definition: economy.h:244
entt::entity market
Definition: economy.h:245
An entity where the market is based, and the resources are traded.
Definition: economy.h:251
entt::entity market
Definition: economy.h:252
double price_ratio
Definition: economy.h:111
double sd_ratio
Definition: economy.h:112
double inputratio
Definition: economy.h:113
Definition: economy.h:120
void AddSupply(const ResourceLedger &stockpile)
Definition: economy.cpp:22
double GDP
Definition: economy.h:130
auto begin()
Definition: economy.h:148
double GetSupply(const entt::entity &good)
Definition: economy.cpp:56
std::vector< MarketInformation > history
Definition: economy.h:121
std::map< entt::entity, MarketElementInformation > market_information
Definition: economy.h:123
double GetSDRatio(const entt::entity &good)
Definition: economy.cpp:54
std::map< entt::entity, MarketElementInformation > last_market_information
Definition: economy.h:124
entt::basic_sparse_set< entt::entity > connected_markets
Definition: economy.h:128
MarketElementInformation & operator[](entt::entity ent)
Definition: economy.h:146
double GetPrice(const ResourceLedger &stockpile)
Definition: economy.cpp:46
std::set< entt::entity > participants
Definition: economy.h:126
double GetDemand(const entt::entity &good)
Definition: economy.cpp:58
void AddParticipant(entt::entity participant)
Definition: economy.h:144
void AddDemand(const ResourceLedger &stockpile)
Definition: economy.cpp:34
auto end()
Definition: economy.h:150
Historical information about the market Might change this to a different type of resource ledger so t...
Definition: economy.h:35
ResourceLedger & supply()
Definition: economy.h:74
ResourceLedger last_latent_demand
Definition: economy.h:61
ResourceLedger latent_supply
Definition: economy.h:58
ResourceLedger _supply
Definition: economy.h:38
ResourceLedger price
Definition: economy.h:54
ResourceLedger supply_difference
Definition: economy.h:63
ResourceLedger _demand
Definition: economy.h:37
ResourceLedger & previous_demand()
Definition: economy.h:97
void ResetLedgers()
Definition: economy.h:67
ResourceLedger latent_demand
Definition: economy.h:62
ResourceLedger & previous_supply()
Definition: economy.h:89
ResourceLedger _previous_demand
Definition: economy.h:39
ResourceLedger _previous_supply
Definition: economy.h:40
ResourceLedger & demand()
Definition: economy.h:81
ResourceLedger chronic_shortages
Definition: economy.h:65
ResourceLedger volume
The amount of goods that changed hands. We can use this to calculate the GDP
Definition: economy.h:53
bool current
Definition: economy.h:41
ResourceLedger sd_ratio
Definition: economy.h:44
ResourceLedger ds_ratio
Definition: economy.h:47
Definition: economy.h:294
entt::entity owner
Definition: economy.h:295
std::vector< entt::entity > participants
Definition: economy.h:117
Price of a good. This is temporary, because this is to determine initial prices for goods....
Definition: economy.h:158
double price
Definition: economy.h:159
Definition: economy.h:182
double GDP_change
Definition: economy.h:237
Wallet & operator=(double _balance)
Definition: economy.h:214
double GetChange() const
Definition: economy.h:225
double balance
Definition: economy.h:234
Wallet & operator-=(const double amount)
Definition: economy.h:191
void Reset()
Definition: economy.h:227
double change
Definition: economy.h:235
entt::entity currency
Definition: economy.h:238
double GetBalance() const
Definition: economy.h:223
Wallet & operator*=(const double coefficent)
Definition: economy.h:201
Wallet & operator+=(const double amount)
Definition: economy.h:186
double GetGDPChange()
Definition: economy.h:231
Wallet(entt::entity _currency, double _balance)
Definition: economy.h:184