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.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 {
38
39 // Might not need this in the future.
42
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
59};
60
62 // Sum of the resources traded last time.
63 double supply;
64 double demand;
65 double price;
67 double sd_ratio;
68 double inputratio;
69};
70
72
74 std::vector<MarketInformation> history;
75
76 std::map<entt::entity, MarketElementInformation> market_information;
77 std::map<entt::entity, MarketElementInformation> last_market_information;
78
79 std::set<entt::entity> participants;
80 entt::basic_sparse_set<entt::entity> connected_markets;
81
82 double GDP = 0;
83
84 // Math
85 void AddSupply(const ResourceLedger& stockpile);
86 void AddSupply(const ResourceLedger& stockpile, double multiplier);
87 void AddDemand(const ResourceLedger& stockpile);
88 void AddDemand(const ResourceLedger& stockpile, double multiplier);
89
90 double GetPrice(const ResourceLedger& stockpile);
91 double GetPrice(const entt::entity& good);
92 double GetSDRatio(const entt::entity& good);
93 double GetSupply(const entt::entity& good);
94 double GetDemand(const entt::entity& good);
95
96 void AddParticipant(entt::entity participant) { participants.insert(participant); }
97
98 MarketElementInformation& operator[](entt::entity ent) { return market_information[ent]; }
99
100 auto begin() { return market_information.begin(); }
101
102 auto end() { return market_information.end(); }
103};
104
110struct Price {
111 double price;
112
113 operator double() { return price; }
114};
115
126struct Currency {};
127
131struct CostTable : public ResourceLedger {};
132
133// TODO(EhWhoAmI): Add multiple currency support
134struct Wallet {
135 Wallet() = default;
136 Wallet(entt::entity _currency, double _balance) : balance(_balance), currency(_currency) {}
137
138 Wallet& operator+=(const double amount) {
139 this->balance += amount;
140 change += amount;
141 return *this;
142 }
143 Wallet& operator-=(const double amount) {
144 this->balance -= amount;
145 change -= amount;
146 GDP_change += amount;
147 // Record the money delta since last reset
148 return *this;
149 }
150
151 // Basic multiplication that logs the change
152 // TODO(EhWhoAmI): Make sure this is correct
153 Wallet& operator*=(const double coefficent) {
154 double newbalance = this->balance * coefficent;
155 double change = newbalance - this->balance;
156 if (change > 0) {
157 *this += change;
158 } else if (change < 0) {
159 *this -= change * -1;
160 }
161 return *this;
162 }
163
164 operator double() const { return balance; }
165
166 Wallet& operator=(double _balance) {
167 change += (_balance - balance);
168 if ((_balance - balance) < 0) {
169 GDP_change += _balance - balance;
170 }
171 balance = _balance;
172 return *this;
173 }
174
175 double GetBalance() const { return balance; }
176
177 void Reset() {
178 change = 0;
179 GDP_change = 0;
180 }
181 double GetGDPChange() { return GDP_change; }
182
183 private:
184 double balance = 0;
185 double change = 0;
186 // Only records when spending money, so when money decreases
187 double GDP_change = 0;
188 entt::entity currency;
189};
190
195 entt::entity market;
196};
197
202 entt::entity market;
203};
204
205// This trade node has international connections
206// For space connections, the spaceport struct exists
208
215 entt::entity city;
216 int size;
217};
218
219// Something that hires people, and will pay the people
220struct Employer {
223 entt::entity segment;
224};
225
238};
239
241
242// This facility is bankrolled by something else, so if they run out of money
243// they can go to this wallet to ask for cash?
244struct Owned {
245 entt::entity owner;
246};
247} // namespace components
248} // namespace common
249} // 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:213
entt::entity city
The city that it's based in.
Definition: economy.h:215
int size
Definition: economy.h:216
Records the prices of goods and other things
Definition: economy.h:131
Will be handled in the future, but for now is just a market
Definition: economy.h:126
Definition: economy.h:220
int population_needed
Definition: economy.h:221
entt::entity segment
Definition: economy.h:223
int population_fufilled
Definition: economy.h:222
Population segment that is employed
Definition: economy.h:229
int working_population
The population that is available to work
Definition: economy.h:233
int employed_population
The current population is currently working.
Definition: economy.h:237
An actor in a market that trades goods.
Definition: economy.h:194
entt::entity market
Definition: economy.h:195
An entity where the market is based, and the resources are traded.
Definition: economy.h:201
entt::entity market
Definition: economy.h:202
double price_ratio
Definition: economy.h:66
Definition: economy.h:73
void AddSupply(const ResourceLedger &stockpile)
Definition: economy.cpp:22
double GDP
Definition: economy.h:82
auto begin()
Definition: economy.h:100
double GetSupply(const entt::entity &good)
Definition: economy.cpp:56
std::vector< MarketInformation > history
Definition: economy.h:74
std::map< entt::entity, MarketElementInformation > market_information
Definition: economy.h:76
double GetSDRatio(const entt::entity &good)
Definition: economy.cpp:54
std::map< entt::entity, MarketElementInformation > last_market_information
Definition: economy.h:77
entt::basic_sparse_set< entt::entity > connected_markets
Definition: economy.h:80
MarketElementInformation & operator[](entt::entity ent)
Definition: economy.h:98
double GetPrice(const ResourceLedger &stockpile)
Definition: economy.cpp:46
std::set< entt::entity > participants
Definition: economy.h:79
double GetDemand(const entt::entity &good)
Definition: economy.cpp:58
void AddParticipant(entt::entity participant)
Definition: economy.h:96
void AddDemand(const ResourceLedger &stockpile)
Definition: economy.cpp:34
auto end()
Definition: economy.h:102
Historical information about the market Might change this to a different type of resource ledger so t...
Definition: economy.h:35
ResourceLedger last_latent_demand
Definition: economy.h:57
ResourceLedger supply
Definition: economy.h:41
ResourceLedger latent_supply
Definition: economy.h:54
ResourceLedger previous_demand
Definition: economy.h:49
ResourceLedger demand
Definition: economy.h:36
ResourceLedger price
Definition: economy.h:48
ResourceLedger latent_demand
Definition: economy.h:58
ResourceLedger previous_supply
Definition: economy.h:50
ResourceLedger volume
The amount of goods that changed hands. We can use this to calculate the GDP
Definition: economy.h:47
ResourceLedger sd_ratio
Definition: economy.h:37
ResourceLedger ds_ratio
Definition: economy.h:40
Definition: economy.h:244
entt::entity owner
Definition: economy.h:245
Price of a good. This is temporary, because this is to determine initial prices for goods....
Definition: economy.h:110
double price
Definition: economy.h:111
Definition: economy.h:134
double GDP_change
Definition: economy.h:187
Wallet & operator=(double _balance)
Definition: economy.h:166
double balance
Definition: economy.h:184
Wallet & operator-=(const double amount)
Definition: economy.h:143
void Reset()
Definition: economy.h:177
double change
Definition: economy.h:185
entt::entity currency
Definition: economy.h:188
double GetBalance() const
Definition: economy.h:175
Wallet & operator*=(const double coefficent)
Definition: economy.h:153
Wallet & operator+=(const double amount)
Definition: economy.h:138
double GetGDPChange()
Definition: economy.h:181
Wallet(entt::entity _currency, double _balance)
Definition: economy.h:136