Skip to content

Commit

Permalink
Set up trade ports if possible. (#387)
Browse files Browse the repository at this point in the history
Co-authored-by: Zemurin <ivo@elezovic.su>
  • Loading branch information
Zemurin and Zemurin committed Apr 29, 2023
1 parent 26187cf commit 3b30f82
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 66 deletions.
127 changes: 63 additions & 64 deletions EU4ToVic3/Data_Files/configurables/province_mappings.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions EU4ToVic3/Source/V3World/ClayManager/State/Province.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Province
[[nodiscard]] auto isCoastal() const { return coastal; }
[[nodiscard]] auto isPrime() const { return prime; }
[[nodiscard]] auto isImpassable() const { return impassable; }
[[nodiscard]] auto isPort() const { return port; }

void setSea() { sea = true; }
void setLake()
Expand All @@ -27,6 +28,7 @@ class Province
void setCoastal() { coastal = true; }
void setPrime() { prime = true; }
void setImpassable() { impassable = true; }
void setPort() { port = true; }
void setName(const std::string& theName) { name = theName; }
void setTerrain(const std::string& theTerrain) { terrain = theTerrain; };

Expand All @@ -40,6 +42,7 @@ class Province
bool coastal = false;
bool prime = false;
bool impassable = false;
bool port = false;
};
} // namespace V3

Expand Down
12 changes: 12 additions & 0 deletions EU4ToVic3/Source/V3World/ClayManager/State/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ void V3::State::registerKeys()
navalExitID = commonItems::getInt(theStream);
coastal = true;
});
registerKeyword("port", [this](std::istream& theStream) {
auto theProvinceName = commonItems::getString(theStream);
std::transform(theProvinceName.begin(), theProvinceName.end(), theProvinceName.begin(), ::toupper);
if (theProvinceName.starts_with("X") && theProvinceName.size() == 7)
theProvinceName = "x" + theProvinceName.substr(1, theProvinceName.length() - 1);
else
Log(LogLevel::Warning) << "Encountered port " << theProvinceName << " in unknown format!";
if (provinces.contains(theProvinceName))
provinces.at(theProvinceName)->setPort();
else
Log(LogLevel::Warning) << "Port province " << theProvinceName << " isn't defined in the state! (Vanilla?) Map error. Ignoring port.";
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
}

Expand Down
7 changes: 7 additions & 0 deletions EU4ToVic3/Source/V3World/ClayManager/State/SubState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,10 @@ void V3::SubState::setIncorporated(bool status)
else
subStateTypes.emplace("unincorporated");
}

void V3::SubState::setTreatyPort()
{
subStateTypes.clear();
subStateTypes.emplace("unincorporated");
subStateTypes.emplace("treaty_port");
}
4 changes: 2 additions & 2 deletions EU4ToVic3/Source/V3World/ClayManager/State/SubState.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class SubState
void setSourceProvinceData(const std::vector<std::pair<SourceProvinceData, double>>& theData) { weightedSourceProvinceData = theData; }

void setMarketCapital() { marketCapital = true; }
void setTreatyPort() { subStateTypes.emplace("treaty_port"); }
void setVanillaSubState() { vanillaSubState = true; }
void setLandshare(const double theLandshare) { landshare = theLandshare; }
void setResource(const std::string& theResource, const int theAmount) { resources[theResource] = theAmount; }
Expand Down Expand Up @@ -141,7 +140,7 @@ class SubState

[[nodiscard]] auto isVanillaSubState() const { return vanillaSubState; }
[[nodiscard]] auto isIncorporated() const { return subStateTypes.contains("incorporated"); }
[[nodiscard]] auto isTreatyPort() const { return !subStateTypes.contains("treaty_port"); }
[[nodiscard]] auto isTreatyPort() const { return subStateTypes.contains("treaty_port"); }
[[nodiscard]] auto isMarketCapital() const { return marketCapital; }
[[nodiscard]] bool isCoastal() const;

Expand All @@ -154,6 +153,7 @@ class SubState
[[nodiscard]] static bool greaterBudget(const std::shared_ptr<SubState>& lhs, const std::shared_ptr<SubState>& rhs);

void setIncorporated(bool status);
void setTreatyPort();

private:
void calculateTerrainFrequency();
Expand Down
43 changes: 43 additions & 0 deletions EU4ToVic3/Source/V3World/PoliticalManager/PoliticalManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "PoliticalManager.h"
#include "ClayManager/ClayManager.h"
#include "ClayManager/State/Province.h"
#include "ClayManager/State/State.h"
#include "ClayManager/State/SubState.h"
#include "ColonialRegionMapper/ColonialRegionMapper.h"
Expand Down Expand Up @@ -1129,3 +1130,45 @@ void V3::PoliticalManager::incorporateStates(const mappers::CultureMapper& cultu

Log(LogLevel::Info) << "<> Incorporated " << incorporated << " states, " << unIncorporated << " are unincorporated.";
}

void V3::PoliticalManager::designateTreatyPorts(const ClayManager& clayManager)
{
Log(LogLevel::Info) << "-> Designating Treaty Ports.";

auto count = 0;

for (const auto& country: countries | std::views::values)
{
const auto capitalState = country->getProcessedData().capitalStateName;
const auto capitalRegionName = clayManager.getParentRegionName(capitalState);

for (const auto& subState: country->getSubStates())
{
// If the state is in same region as capital, skip!

if (capitalRegionName)
{
const auto actualRegionName = clayManager.getParentRegionName(subState->getHomeStateName());
if (*actualRegionName == *capitalRegionName)
{
continue;
}
}

// Otherwise check if it's a single-province state and a named port.

if (subState->getProvinces().size() != 1)
continue;

const auto& theProvince = subState->getProvinces().begin()->second;

if (theProvince->isPort())
{
subState->setTreatyPort();
++count;
}
}
}

Log(LogLevel::Info) << "<> Designated " << count << " treaty ports.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class PoliticalManager
void generateAISecretGoals(const ClayManager& clayManager);
void attemptColonialTagReplacement(const mappers::ColonialRegionMapper& colonialRegionMapper, const ClayManager& clayManager);
void incorporateStates(const mappers::CultureMapper& cultureMapper, const ClayManager& clayManager);
void designateTreatyPorts(const ClayManager& clayManager);

// VN specifics
void importVNColonialDiplomacy(const ClayManager& clayManager);
Expand Down
1 change: 1 addition & 0 deletions EU4ToVic3/Source/V3World/V3World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ V3::World::World(const Configuration& configuration, const EU4::World& sourceWor
popManager.alterSlaveCultures(politicalManager, clayManager, cultureMapper.getV3CultureDefinitions());

politicalManager.incorporateStates(cultureMapper, clayManager);
politicalManager.designateTreatyPorts(clayManager);

// Place starting buildings for all centralized countries
Log(LogLevel::Progress) << "71 %";
Expand Down

0 comments on commit 3b30f82

Please sign in to comment.