Skip to content

Commit dc9874c

Browse files
authored
Expand EU5World Geographic Model (#77)
* iterate on eu5location fields based on locations database block contents * fix namings from eu4 labels to eu5 labels * fix clang workflow paths * clang format fun
1 parent 60d1827 commit dc9874c

27 files changed

Lines changed: 720 additions & 336 deletions

.github/workflows/clang-format-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ jobs:
77
strategy:
88
matrix:
99
path:
10-
- 'EU4ToVic3/Source'
11-
- 'EU4ToVic3Tests'
10+
- 'EU5ToVic3/Source'
11+
- 'EU5ToVic3Tests'
1212
steps:
1313
- uses: actions/checkout@v7
1414
- name: Run clang-format style check for C/C++ programs.
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#include "EU5Location.h"
2+
3+
EU5::Location::Location(int theLocationID, std::string theLocationName): locID(theLocationID), name(std::move(theLocationName))
4+
{
5+
}
6+
7+
void EU5::Location::parseData(std::istream& theStream)
8+
{
9+
registerKeys();
10+
parseStream(theStream);
11+
clearRegisteredKeywords();
12+
}
13+
14+
void EU5::Location::registerKeys()
15+
{
16+
registerKeyword("owner", [this](std::istream& theStream) {
17+
ownerID = commonItems::getInt(theStream);
18+
});
19+
registerKeyword("controller", [this](std::istream& theStream) {
20+
controllerID = commonItems::getInt(theStream);
21+
});
22+
registerKeyword("previous_owner", [this](std::istream& theStream) {
23+
previousOwnerID = commonItems::getInt(theStream);
24+
});
25+
registerKeyword("previous_controller", [this](std::istream& theStream) {
26+
previousControllerID = commonItems::getInt(theStream);
27+
});
28+
registerKeyword("development", [this](std::istream& theStream) {
29+
development = commonItems::getDouble(theStream);
30+
});
31+
registerKeyword("prosperity", [this](std::istream& theStream) {
32+
prosperity = commonItems::getDouble(theStream);
33+
});
34+
registerKeyword("language", [this](std::istream& theStream) {
35+
language = commonItems::getString(theStream);
36+
});
37+
registerKeyword("dialect", [this](std::istream& theStream) {
38+
dialect = commonItems::getString(theStream);
39+
});
40+
registerKeyword("rank", [this](std::istream& theStream) {
41+
rank = commonItems::getString(theStream);
42+
});
43+
registerKeyword("original_rank", [this](std::istream& theStream) {
44+
originalRank = commonItems::getString(theStream);
45+
});
46+
registerKeyword("raw_material", [this](std::istream& theStream) {
47+
rawMaterial = commonItems::getString(theStream);
48+
});
49+
registerKeyword("cores", [this](std::istream& theStream) {
50+
const auto& cores = commonItems::getInts(theStream);
51+
countriesWithCore.insert(cores.begin(), cores.end());
52+
});
53+
54+
registerKeyword("religion", [this](std::istream& theStream) {
55+
religionID = commonItems::getInt(theStream);
56+
});
57+
registerKeyword("culture", [this](std::istream& theStream) {
58+
cultureID = commonItems::getInt(theStream);
59+
});
60+
registerKeyword("secondary_culture", [this](std::istream& theStream) {
61+
secondaryCultureID = commonItems::getInt(theStream);
62+
});
63+
registerKeyword("cultural_unity", [this](std::istream& theStream) {
64+
culturalUnity = commonItems::getDouble(theStream);
65+
});
66+
67+
registerKeyword("last_owner_change", [this](std::istream& theStream) {
68+
lastOwnerChange = date(commonItems::getString(theStream));
69+
});
70+
registerKeyword("last_controller_change", [this](std::istream& theStream) {
71+
lastControllerChange = date(commonItems::getString(theStream));
72+
});
73+
74+
registerKeyword("max_raw_material_workers", [this](std::istream& theStream) {
75+
maxRawMaterialWorkers = commonItems::getInt(theStream);
76+
});
77+
registerKeyword("control", [this](std::istream& theStream) {
78+
control = commonItems::getDouble(theStream);
79+
});
80+
registerKeyword("cap_control", [this](std::istream& theStream) {
81+
capControl = commonItems::getString(theStream) == "yes";
82+
});
83+
registerKeyword("road_to_capital", [this](std::istream& theStream) {
84+
roadToCapital = commonItems::getString(theStream) == "yes";
85+
});
86+
registerKeyword("proximity", [this](std::istream& theStream) {
87+
proximity = commonItems::getDouble(theStream);
88+
});
89+
registerKeyword("local_proximity_propagation", [this](std::istream& theStream) {
90+
localProximityPropagation = commonItems::getDouble(theStream);
91+
});
92+
registerKeyword("value_flow", [this](std::istream& theStream) {
93+
valueFlow = commonItems::getDouble(theStream);
94+
});
95+
96+
registerKeyword("province", [this](std::istream& theStream) {
97+
provinceID = commonItems::getInt(theStream);
98+
});
99+
registerKeyword("tax", [this](std::istream& theStream) {
100+
tax = commonItems::getDouble(theStream);
101+
});
102+
registerKeyword("possible_tax", [this](std::istream& theStream) {
103+
possibleTax = commonItems::getDouble(theStream);
104+
});
105+
registerKeyword("estate_tax", [this](std::istream& theStream) {
106+
for (const auto& [estate, value]: commonItems::assignments(theStream).getAssignments())
107+
estateTax[estate].tax = commonItems::stringToDouble(value);
108+
});
109+
registerKeyword("estate_possible_tax", [this](std::istream& theStream) {
110+
for (const auto& [estate, value]: commonItems::assignments(theStream).getAssignments())
111+
estateTax[estate].possibleTax = commonItems::stringToDouble(value);
112+
});
113+
registerKeyword("institutions", [this](std::istream& theStream) {
114+
for (const auto& [institution, spread]: commonItems::assignments(theStream).getAssignments())
115+
institutions.emplace(institution, commonItems::stringToDouble(spread));
116+
});
117+
118+
registerKeyword("units", [this](std::istream& theStream) {
119+
unitIDs = commonItems::getInts(theStream);
120+
});
121+
registerKeyword("port", [this](std::istream& theStream) {
122+
portIDs = commonItems::getInts(theStream);
123+
});
124+
//
125+
registerKeyword("population", [this](std::istream& theStream) {
126+
commonItems::parser parser;
127+
parser.registerKeyword("pops", [this](std::istream& popsStream) {
128+
popIDs = commonItems::getInts(popsStream);
129+
});
130+
parser.registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
131+
parser.parseStream(theStream);
132+
});
133+
134+
registerKeyword("garrison", [this](std::istream& theStream) {
135+
garrison = commonItems::getDouble(theStream);
136+
});
137+
registerKeyword("counters", [this](std::istream& theStream) {
138+
for (const auto& [counter, value]: commonItems::assignments(theStream).getAssignments())
139+
counters.emplace(counter, commonItems::stringToInteger<int>(value));
140+
});
141+
142+
registerKeyword("market", [this](std::istream& theStream) {
143+
marketID = commonItems::getInt(theStream);
144+
});
145+
registerKeyword("second_best_market", [this](std::istream& theStream) {
146+
secondBestMarketID = commonItems::getInt(theStream);
147+
});
148+
registerKeyword("market_parent", [this](std::istream& theStream) {
149+
marketParentID = commonItems::getInt(theStream);
150+
});
151+
registerKeyword("market_access", [this](std::istream& theStream) {
152+
marketAccess = commonItems::getDouble(theStream);
153+
});
154+
registerKeyword("market_attraction", [this](std::istream& theStream) {
155+
marketAttraction = commonItems::getDouble(theStream);
156+
});
157+
registerKeyword("second_best_market_access", [this](std::istream& theStream) {
158+
secondBestMarketAccess = commonItems::getDouble(theStream);
159+
});
160+
161+
// wanted to organize with country as key in map rather than a list
162+
// not even sure how many we can see here, max i've seen is 2 so far
163+
registerKeyword("integration_data", [this](std::istream& theStream) {
164+
for (const auto& blob: commonItems::blobList(theStream).getBlobs())
165+
{
166+
std::istringstream blobStream(blob);
167+
int owner = 0;
168+
Integration integration;
169+
commonItems::parser parser;
170+
parser.registerKeyword("integration", [&integration](std::istream& itemStream) {
171+
integration.type = commonItems::getString(itemStream);
172+
});
173+
parser.registerKeyword("integration_progress", [&integration](std::istream& itemStream) {
174+
integration.progress = commonItems::getDouble(itemStream);
175+
});
176+
parser.registerKeyword("integration_owner", [&owner](std::istream& itemStream) {
177+
owner = commonItems::getInt(itemStream);
178+
});
179+
parser.registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
180+
parser.parseStream(blobStream);
181+
integrationData.emplace(owner, integration);
182+
}
183+
});
184+
185+
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
186+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#ifndef EU5_LOCATION_H
2+
#define EU5_LOCATION_H
3+
4+
namespace EU5
5+
{
6+
struct EstateTax
7+
{
8+
double tax = 0;
9+
double possibleTax = 0;
10+
bool operator==(const EstateTax&) const = default;
11+
};
12+
13+
struct Integration
14+
{
15+
// core, integrated, or conquered (might be more)
16+
std::string type;
17+
double progress = 0;
18+
bool operator==(const Integration&) const = default;
19+
};
20+
21+
class Location: commonItems::parser
22+
{
23+
public:
24+
Location() = default;
25+
explicit Location(int theLocationID, std::string theLocationName);
26+
27+
void parseData(std::istream& theStream);
28+
29+
[[nodiscard]] int getID() const { return locID; }
30+
[[nodiscard]] int getOwnerID() const { return ownerID; }
31+
[[nodiscard]] int getControllerID() const { return controllerID; }
32+
[[nodiscard]] int getPreviousOwnerID() const { return previousOwnerID; }
33+
[[nodiscard]] int getPreviousControllerID() const { return previousControllerID; }
34+
[[nodiscard]] double getDevelopment() const { return development; }
35+
[[nodiscard]] double getProsperity() const { return prosperity; }
36+
[[nodiscard]] const auto& getName() const { return name; }
37+
[[nodiscard]] const auto& getLanguage() const { return language; }
38+
[[nodiscard]] const auto& getDialect() const { return dialect; }
39+
[[nodiscard]] const auto& getRank() const { return rank; }
40+
[[nodiscard]] const auto& getOriginalRank() const { return originalRank; }
41+
[[nodiscard]] const auto& getRawMaterial() const { return rawMaterial; }
42+
[[nodiscard]] const auto& getCountriesWithCore() const { return countriesWithCore; }
43+
44+
[[nodiscard]] int getReligionID() const { return religionID; }
45+
[[nodiscard]] int getCultureID() const { return cultureID; }
46+
[[nodiscard]] int getSecondaryCultureID() const { return secondaryCultureID; }
47+
[[nodiscard]] double getCulturalUnity() const { return culturalUnity; }
48+
49+
[[nodiscard]] const auto& getLastOwnerChange() const { return lastOwnerChange; }
50+
[[nodiscard]] const auto& getLastControllerChange() const { return lastControllerChange; }
51+
52+
[[nodiscard]] int getMaxRawMaterialWorkers() const { return maxRawMaterialWorkers; }
53+
[[nodiscard]] double getControl() const { return control; }
54+
[[nodiscard]] bool getCapControl() const { return capControl; }
55+
[[nodiscard]] bool getRoadToCapital() const { return roadToCapital; }
56+
[[nodiscard]] double getProximity() const { return proximity; }
57+
[[nodiscard]] double getLocalProximityPropagation() const { return localProximityPropagation; }
58+
[[nodiscard]] double getValueFlow() const { return valueFlow; }
59+
60+
[[nodiscard]] int getProvinceID() const { return provinceID; }
61+
[[nodiscard]] double getTax() const { return tax; }
62+
[[nodiscard]] double getPossibleTax() const { return possibleTax; }
63+
[[nodiscard]] const auto& getEstateTax() const { return estateTax; }
64+
[[nodiscard]] const auto& getInstitutions() const { return institutions; }
65+
66+
[[nodiscard]] const auto& getUnitIDs() const { return unitIDs; }
67+
[[nodiscard]] const auto& getPortIDs() const { return portIDs; }
68+
[[nodiscard]] const auto& getPopIDs() const { return popIDs; }
69+
70+
[[nodiscard]] double getGarrison() const { return garrison; }
71+
[[nodiscard]] const auto& getCounters() const { return counters; }
72+
73+
[[nodiscard]] int getMarketID() const { return marketID; }
74+
[[nodiscard]] int getSecondBestMarketID() const { return secondBestMarketID; }
75+
[[nodiscard]] int getMarketParentID() const { return marketParentID; }
76+
[[nodiscard]] double getMarketAccess() const { return marketAccess; }
77+
[[nodiscard]] double getMarketAttraction() const { return marketAttraction; }
78+
[[nodiscard]] double getSecondBestMarketAccess() const { return secondBestMarketAccess; }
79+
80+
[[nodiscard]] const auto& getIntegrationData() const { return integrationData; }
81+
82+
private:
83+
void registerKeys();
84+
85+
int locID = 0;
86+
std::string name;
87+
88+
int ownerID = 0;
89+
int controllerID = 0;
90+
int previousOwnerID = 0;
91+
int previousControllerID = 0;
92+
double development = 0;
93+
double prosperity = 0;
94+
95+
std::string language;
96+
std::string dialect;
97+
std::string rank;
98+
std::string originalRank;
99+
std::string rawMaterial;
100+
101+
// country id
102+
std::set<int> countriesWithCore;
103+
104+
int religionID = 0;
105+
int cultureID = 0;
106+
int secondaryCultureID = 0;
107+
double culturalUnity = 0;
108+
109+
date lastOwnerChange;
110+
date lastControllerChange;
111+
112+
int maxRawMaterialWorkers = 0;
113+
double control = 0;
114+
bool capControl = false;
115+
bool roadToCapital = false;
116+
double proximity = 0;
117+
double localProximityPropagation = 0;
118+
double valueFlow = 0;
119+
120+
int provinceID = 0;
121+
// TODO figure out how economy.income is calculated from shtuff like this
122+
double tax = 0;
123+
double possibleTax = 0;
124+
// estate key -> tax, possibleTax
125+
std::map<std::string, EstateTax> estateTax;
126+
127+
// instritution name -> 0.0001 - 100 representing spread %
128+
std::map<std::string, double> institutions;
129+
130+
std::vector<int> unitIDs;
131+
std::vector<int> portIDs; // list in save but I only ever see one value?
132+
// TODO figure out what to do with location-specific pop info that isn't tied to specific pop IDs
133+
// e.g. unemployment, rgo employment, culture/religion conversion
134+
std::vector<int> popIDs;
135+
136+
double garrison = 0;
137+
std::map<std::string, int> counters;
138+
139+
int marketID = 0;
140+
int secondBestMarketID = 0;
141+
int marketParentID = 0;
142+
double marketAccess = 0;
143+
double marketAttraction = 0;
144+
double secondBestMarketAccess = 0;
145+
146+
// country id -> type, progress
147+
std::map<int, Integration> integrationData;
148+
149+
// TODO figure out what these fields are:
150+
// ub, flip_sources
151+
// ub in my test saves are all no...
152+
};
153+
} // namespace EU5
154+
155+
#endif // EU5_LOCATION_H

EU5ToVic3/Source/EU5World/ProvinceManager/ProvinceManager.cpp renamed to EU5ToVic3/Source/EU5World/LocationManager/LocationManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#include "ProvinceManager.h"
1+
#include "LocationManager.h"
22
#include "Log.h"
33
#include <ranges>
44

5-
void EU5::ProvinceManager::loadProvinces(std::istream& theStream)
5+
void EU5::LocationManager::loadLocations(std::istream& theStream)
66
{
77
registerKeys();
88
parseStream(theStream);
99
clearRegisteredKeywords();
1010
}
1111

12-
void EU5::ProvinceManager::registerKeys()
12+
void EU5::LocationManager::registerKeys()
1313
{
1414
registerKeyword("locations", [this](const std::string& unused, std::istream& theStream) {
1515
parseStream(theStream); // Double-tapping locations keyword.
@@ -29,7 +29,7 @@ void EU5::ProvinceManager::registerKeys()
2929
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
3030
}
3131

32-
void EU5::ProvinceManager::registerLocation(int theLocationID, const std::string& locationName)
32+
void EU5::LocationManager::registerLocation(int theLocationID, const std::string& locationName)
3333
{
3434
if (seenLocations.contains(locationName))
3535
{
@@ -41,7 +41,7 @@ void EU5::ProvinceManager::registerLocation(int theLocationID, const std::string
4141
seenLocations.emplace(locationName, newLocation);
4242
}
4343

44-
std::shared_ptr<EU5::Location> EU5::ProvinceManager::getSeenLocationByID(int theID) const
44+
std::shared_ptr<EU5::Location> EU5::LocationManager::getSeenLocationByID(int theID) const
4545
{
4646
for (const auto& Location: seenLocations | std::views::values)
4747
{

0 commit comments

Comments
 (0)