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