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 entt::entity target;
35 double amount;
36 double price;
37
38 MarketOrder(entt::entity target, double amount, double price) : target(target), amount(amount), price(price) {}
39};
40
41// A planetary market must have a regular market as well
43 explicit PlanetaryMarket(size_t good_count) : supplied_resources(good_count), supply_difference(good_count) {}
44 std::map<entt::entity, std::vector<MarketOrder>> demands;
45 std::map<entt::entity, std::vector<MarketOrder>> requests;
46 // Resources supplied by the interplanetary market
49};
50
51struct Market {
52 Market(size_t good_count)
53 : demand(good_count),
54 supply(good_count),
55 sd_ratio(good_count),
56 volume(good_count),
57 price(good_count),
58 chronic_shortages(good_count),
59 trade(good_count),
60 resource_fulfilled(good_count),
61 production(good_count),
62 consumption(good_count),
63 market_access(good_count) {}
64
65 Market(const Market&) = default; // Copy Constructor
66 Market(Market&&) noexcept = default; // Move Constructor
67
68 Market& operator=(const Market&) = default; // Copy Assignment
69 Market& operator=(Market&&) noexcept = default; // Move Assignment
70
71 ~Market() = default;
72
76
88
89 void ResetLedgers() {
90 // Reset the ledger values
91 demand.clear();
92 supply.clear();
93 }
94
95 std::set<entt::entity> participants;
96
97 std::vector<entt::entity> connected_markets;
98
100
101 entt::entity parent_market = entt::null;
102
103 double GDP = 0;
104 // How much money we are creating from thin air
105 // Cumulative deficit
106 double deficit = 0;
107 // Deficit in last tick
108 double last_deficit = 0;
109
110 double trade_deficit = 0;
112
113 void AddParticipant(entt::entity participant) { participants.insert(participant); }
114};
115
121struct Price {
122 double price;
123
124 operator double() { return price; }
125};
126
137struct Currency {};
138
142struct CostTable : public ResourceMap {};
143
144// TODO(EhWhoAmI): Add multiple currency support
145struct Wallet {
146 Wallet() = default;
147 Wallet(entt::entity _currency, double _balance) : balance(_balance), currency(_currency) {}
148
149 Wallet& operator+=(const double amount) {
150 this->balance += amount;
151 change += amount;
152 return *this;
153 }
154 Wallet& operator-=(const double amount) {
155 this->balance -= amount;
156 change -= amount;
157 GDP_change += amount;
158 // Record the money delta since last reset
159 return *this;
160 }
161
162 // Basic multiplication that logs the change
163 // TODO(EhWhoAmI): Make sure this is correct
164 Wallet& operator*=(const double coefficent) {
165 double newbalance = this->balance * coefficent;
166 double change = newbalance - this->balance;
167 if (change > 0) {
168 *this += change;
169 } else if (change < 0) {
170 *this -= change * -1;
171 }
172 return *this;
173 }
174
175 operator double() const { return balance; }
176
177 Wallet& operator=(double _balance) {
178 change += (_balance - balance);
179 if ((_balance - balance) < 0) {
180 GDP_change += _balance - balance;
181 }
182 balance = _balance;
183 return *this;
184 }
185
186 double GetBalance() const { return balance; }
187
188 double GetChange() const { return change; }
189
190 void Reset() {
191 change = 0;
192 GDP_change = 0;
193 }
194 double GetGDPChange() { return GDP_change; }
195
196 private:
197 double balance = 0;
198 double change = 0;
199 // Only records when spending money, so when money decreases
200 double GDP_change = 0;
201 entt::entity currency;
202};
203
208 entt::entity market;
209};
210
211// This trade node has international connections
212// For space connections, the spaceport struct exists
214
221 entt::entity city;
222 int size;
223};
224
225// Something that hires people, and will pay the people
226struct Employer {
230 entt::entity segment;
231
232 // Hiring freezes and layoff flags
233};
234
247};
248
250
251// This facility is bankrolled by something else, so if they run out of money
252// they can go to this wallet to ask for cash?
253struct Owned {
254 entt::entity owner;
255};
256
257struct TradePartners : std::vector<entt::entity> {};
258} // 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:219
int size
Definition: market.h:222
entt::entity city
The city that it's based in.
Definition: market.h:221
Records the prices of goods and other things
Definition: market.h:142
Will be handled in the future, but for now is just a market
Definition: market.h:137
Definition: market.h:226
int population_change
Definition: market.h:229
int population_fufilled
Definition: market.h:228
int population_needed
Definition: market.h:227
entt::entity segment
Definition: market.h:230
Population segment that is employed
Definition: market.h:238
int employed_population
The current population is currently working.
Definition: market.h:246
int working_population
The population that is available to work
Definition: market.h:242
An actor in a market that trades goods.
Definition: market.h:207
entt::entity market
Definition: market.h:208
Definition: market.h:51
entt::entity parent_market
Definition: market.h:101
ResourceLedger market_access
Definition: market.h:99
Market(size_t good_count)
Definition: market.h:52
ResourceLedger resource_fulfilled
Definition: market.h:85
double last_deficit
Definition: market.h:108
Market(Market &&) noexcept=default
Market(const Market &)=default
void AddParticipant(entt::entity participant)
Definition: market.h:113
void ResetLedgers()
Definition: market.h:89
ResourceLedger chronic_shortages
Definition: market.h:83
double last_trade_deficit
Definition: market.h:111
ResourceLedger demand
Definition: market.h:73
ResourceLedger production
Definition: market.h:86
ResourceLedger supply
Definition: market.h:74
ResourceLedger trade
Definition: market.h:84
ResourceLedger price
Definition: market.h:82
ResourceLedger volume
The amount of goods that changed hands. We can use this to calculate the GDP
Definition: market.h:81
ResourceLedger sd_ratio
Definition: market.h:75
double deficit
Definition: market.h:106
std::vector< entt::entity > connected_markets
Definition: market.h:97
double GDP
Definition: market.h:103
double trade_deficit
Definition: market.h:110
ResourceLedger consumption
Definition: market.h:87
std::set< entt::entity > participants
Definition: market.h:95
double price
Definition: market.h:36
entt::entity target
Definition: market.h:34
double amount
Definition: market.h:35
MarketOrder(entt::entity target, double amount, double price)
Definition: market.h:38
Definition: market.h:253
entt::entity owner
Definition: market.h:254
std::map< entt::entity, std::vector< MarketOrder > > requests
Definition: market.h:45
std::map< entt::entity, std::vector< MarketOrder > > demands
Definition: market.h:44
ResourceLedger supply_difference
Definition: market.h:48
ResourceLedger supplied_resources
Definition: market.h:47
PlanetaryMarket(size_t good_count)
Definition: market.h:43
Price of a good. This is temporary, because this is to determine initial prices for goods....
Definition: market.h:121
double price
Definition: market.h:122
Definition: market.h:145
Wallet & operator*=(const double coefficent)
Definition: market.h:164
double GetChange() const
Definition: market.h:188
double GetBalance() const
Definition: market.h:186
Wallet & operator-=(const double amount)
Definition: market.h:154
void Reset()
Definition: market.h:190
double balance
Definition: market.h:197
entt::entity currency
Definition: market.h:201
double GDP_change
Definition: market.h:200
double GetGDPChange()
Definition: market.h:194
Wallet & operator=(double _balance)
Definition: market.h:177
Wallet(entt::entity _currency, double _balance)
Definition: market.h:147
double change
Definition: market.h:198
Wallet & operator+=(const double amount)
Definition: market.h:149