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.
market.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::core::components {
34 private:
35 // I forgot why we have 2 separate ledgers for supply and demand
38
39 public:
40 MarketInformation(size_t good_count)
41 : _demand(good_count),
42 _supply(good_count),
43 sd_ratio(good_count),
44 volume(good_count),
45 price(good_count),
46 chronic_shortages(good_count),
47 trade(good_count),
48 resource_fulfilled(good_count),
49 production(good_count),
50 consumption(good_count) {}
52
59
61
63
65
68
69 void ResetLedgers() {
70 // Reset the ledger values
71 demand().clear();
72 supply().clear();
73 }
74
77};
78
80 // Sum of the resources traded last time.
81 double supply;
82 double demand;
83 double price;
85 double sd_ratio;
86 double inputratio;
87};
88
94 entt::entity target;
95 double amount;
96 double price;
97
98 MarketOrder(entt::entity target, double amount, double price) : target(target), amount(amount), price(price) {}
99};
100
101// A planetary market must have a regular market as well
103 explicit PlanetaryMarket(size_t good_count) : supplied_resources(good_count), supply_difference(good_count) {}
104 std::map<entt::entity, std::vector<MarketOrder>> demands;
105 std::map<entt::entity, std::vector<MarketOrder>> requests;
106 // Resources supplied by the interplanetary market
109};
110
112 explicit Market(size_t good_count) : MarketInformation(good_count) {}
113
114 std::vector<MarketInformation> history;
115
116 std::set<entt::entity> participants;
117
118 entt::basic_sparse_set<entt::entity> connected_markets;
119
121
122 entt::entity parent_market = entt::null;
123
124 double GDP = 0;
125 // How much money we are creating from thin air
126 // Cumulative deficit
127 double deficit = 0;
128 // Deficit in last tick
129 double last_deficit = 0;
130
131 double trade_deficit = 0;
133
134 void AddParticipant(entt::entity participant) { participants.insert(participant); }
135};
136
142struct Price {
143 double price;
144
145 operator double() { return price; }
146};
147
158struct Currency {};
159
163struct CostTable : public ResourceMap {};
164
165// TODO(EhWhoAmI): Add multiple currency support
166struct Wallet {
167 Wallet() = default;
168 Wallet(entt::entity _currency, double _balance) : balance(_balance), currency(_currency) {}
169
170 Wallet& operator+=(const double amount) {
171 this->balance += amount;
172 change += amount;
173 return *this;
174 }
175 Wallet& operator-=(const double amount) {
176 this->balance -= amount;
177 change -= amount;
178 GDP_change += amount;
179 // Record the money delta since last reset
180 return *this;
181 }
182
183 // Basic multiplication that logs the change
184 // TODO(EhWhoAmI): Make sure this is correct
185 Wallet& operator*=(const double coefficent) {
186 double newbalance = this->balance * coefficent;
187 double change = newbalance - this->balance;
188 if (change > 0) {
189 *this += change;
190 } else if (change < 0) {
191 *this -= change * -1;
192 }
193 return *this;
194 }
195
196 operator double() const { return balance; }
197
198 Wallet& operator=(double _balance) {
199 change += (_balance - balance);
200 if ((_balance - balance) < 0) {
201 GDP_change += _balance - balance;
202 }
203 balance = _balance;
204 return *this;
205 }
206
207 double GetBalance() const { return balance; }
208
209 double GetChange() const { return change; }
210
211 void Reset() {
212 change = 0;
213 GDP_change = 0;
214 }
215 double GetGDPChange() { return GDP_change; }
216
217 private:
218 double balance = 0;
219 double change = 0;
220 // Only records when spending money, so when money decreases
221 double GDP_change = 0;
222 entt::entity currency;
223};
224
229 entt::entity market;
230};
231
232// This trade node has international connections
233// For space connections, the spaceport struct exists
235
242 entt::entity city;
243 int size;
244};
245
246// Something that hires people, and will pay the people
247struct Employer {
251 entt::entity segment;
252
253 // Hiring freezes and layoff flags
254};
255
268};
269
271
272// This facility is bankrolled by something else, so if they run out of money
273// they can go to this wallet to ask for cash?
274struct Owned {
275 entt::entity owner;
276};
277
278struct TradePartners : std::vector<entt::entity> {};
279} // namespace cqsp::core::components
Definition: resourceledger.h:210
void clear()
Definition: resourceledger.cpp:711
Definition: resourceledger.h:34
Definition: area.h:23
Represents commercial areas and other amenities that generate economic activity. They don't export go...
Definition: market.h:240
int size
Definition: market.h:243
entt::entity city
The city that it's based in.
Definition: market.h:242
Records the prices of goods and other things
Definition: market.h:163
Will be handled in the future, but for now is just a market
Definition: market.h:158
Definition: market.h:247
int population_change
Definition: market.h:250
int population_fufilled
Definition: market.h:249
int population_needed
Definition: market.h:248
entt::entity segment
Definition: market.h:251
Population segment that is employed
Definition: market.h:259
int employed_population
The current population is currently working.
Definition: market.h:267
int working_population
The population that is available to work
Definition: market.h:263
An actor in a market that trades goods.
Definition: market.h:228
entt::entity market
Definition: market.h:229
double price_ratio
Definition: market.h:84
double inputratio
Definition: market.h:86
Definition: market.h:111
entt::entity parent_market
Definition: market.h:122
entt::basic_sparse_set< entt::entity > connected_markets
Definition: market.h:118
Market(size_t good_count)
Definition: market.h:112
double last_deficit
Definition: market.h:129
ResourceMap market_access
Definition: market.h:120
void AddParticipant(entt::entity participant)
Definition: market.h:134
double last_trade_deficit
Definition: market.h:132
double deficit
Definition: market.h:127
double GDP
Definition: market.h:124
double trade_deficit
Definition: market.h:131
std::set< entt::entity > participants
Definition: market.h:116
std::vector< MarketInformation > history
Definition: market.h:114
Historical information about the market Might change this to a different type of resource ledger so t...
Definition: market.h:33
ResourceLedger sd_ratio
Definition: market.h:51
MarketInformation(size_t good_count)
Definition: market.h:40
ResourceLedger price
Definition: market.h:58
ResourceLedger & demand()
Definition: market.h:76
ResourceLedger resource_fulfilled
Definition: market.h:64
ResourceLedger trade
Definition: market.h:62
ResourceLedger volume
The amount of goods that changed hands. We can use this to calculate the GDP
Definition: market.h:57
ResourceLedger production
Definition: market.h:66
void ResetLedgers()
Definition: market.h:69
ResourceLedger _supply
Definition: market.h:37
ResourceLedger chronic_shortages
Definition: market.h:60
ResourceLedger & supply()
Definition: market.h:75
ResourceLedger _demand
Definition: market.h:36
ResourceLedger consumption
Definition: market.h:67
double price
Definition: market.h:96
entt::entity target
Definition: market.h:94
double amount
Definition: market.h:95
MarketOrder(entt::entity target, double amount, double price)
Definition: market.h:98
Definition: market.h:274
entt::entity owner
Definition: market.h:275
std::map< entt::entity, std::vector< MarketOrder > > requests
Definition: market.h:105
std::map< entt::entity, std::vector< MarketOrder > > demands
Definition: market.h:104
ResourceLedger supply_difference
Definition: market.h:108
ResourceLedger supplied_resources
Definition: market.h:107
PlanetaryMarket(size_t good_count)
Definition: market.h:103
Price of a good. This is temporary, because this is to determine initial prices for goods....
Definition: market.h:142
double price
Definition: market.h:143
Definition: market.h:166
Wallet & operator*=(const double coefficent)
Definition: market.h:185
double GetChange() const
Definition: market.h:209
double GetBalance() const
Definition: market.h:207
Wallet & operator-=(const double amount)
Definition: market.h:175
void Reset()
Definition: market.h:211
double balance
Definition: market.h:218
entt::entity currency
Definition: market.h:222
double GDP_change
Definition: market.h:221
double GetGDPChange()
Definition: market.h:215
Wallet & operator=(double _balance)
Definition: market.h:198
Wallet(entt::entity _currency, double _balance)
Definition: market.h:168
double change
Definition: market.h:219
Wallet & operator+=(const double amount)
Definition: market.h:170