Skip to content

Commit

Permalink
bug-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gawquon committed Jul 25, 2024
1 parent b51bcdd commit 193b02b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions EU4ToVic3/Source/Output/outBuildings/outBuildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void outShareholders(std::ostream& output, const V3::Building& building)
output << "\t\t\t\t\t\tregion = " << shareholder.state << "\n";
output << "\t\t\t\t\t}\n";
}
if (shareholder.type == "capitalist")
if (shareholder.type == "building_financial_district")
{
output << "\t\t\t\t\tbuilding = {\n";
output << "\t\t\t\t\t\ttype = building_financial_district\n";
Expand All @@ -46,7 +46,7 @@ void outShareholders(std::ostream& output, const V3::Building& building)
output << "\t\t\t\t\t\tregion = " << shareholder.state << "\n";
output << "\t\t\t\t\t}\n";
}
if (shareholder.type == "aristocratic")
if (shareholder.type == "building_manor_house")
{
output << "\t\t\t\t\tbuilding = {\n";
output << "\t\t\t\t\t\ttype = building_manor_house\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ V3::OwnershipSector::OwnershipSector(std::istream& theStream)
clearRegisteredKeywords();
}

#pragma optimize("", off)
void V3::OwnershipSector::registerKeys()
{
ownershipsParser.registerKeyword("local", [this](const std::string& type, std::istream& theStream) {
Expand Down Expand Up @@ -40,5 +39,4 @@ void V3::OwnershipSector::registerKeys()
registerRegex(commonItems::catchallRegex, [this](const std::string& buildingName, std::istream& theStream) {
buildings.emplace(buildingName);
});
}
#pragma optimize("", on)
}
40 changes: 23 additions & 17 deletions EU4ToVic3/Source/V3World/EconomyManager/EconomyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ void V3::EconomyManager::hardcodePorts() const
if (!subState->isCoastal())
continue;

auto port = std::make_shared<Building>();
port->setName("building_port");
port->setPMGroups({"pmg_base_building_port"});
auto port = std::make_shared<Building>(buildings.at("building_port"));
port->setLevel(1);
port->addInvestor(1, "national_service", subState->getHomeStateName(), country->getTag());

subState->addBuilding(port);
++counter;
Expand Down Expand Up @@ -269,11 +266,6 @@ double V3::EconomyManager::calculateDateFactor(const Configuration::STARTDATE st
return 0.0;
}

bool V3::EconomyManager::isRecognized(const std::string& countryTier)
{
return countryTier == "great_power" || countryTier == "major_power" || countryTier == "minor_power" || countryTier == "insignificant_power";
}

std::pair<double, double> V3::EconomyManager::countryBudgetCalcs(const Configuration::ECONOMY economyType) const
{
// Returns total weight, and any special multiplicative factors specific to the method.
Expand Down Expand Up @@ -477,20 +469,26 @@ void V3::EconomyManager::distributeBudget(const double globalCP, const double to
}
}

void V3::EconomyManager::investCapital() const
void V3::EconomyManager::investCapital(const std::map<std::string, std::shared_ptr<Country>>& countries) const
{
// Each building get's it's ownership information from the ownership loader.
// Ownership levels are apportioned.
// Non-0 levels are further apportioned based on local/foreign/capital ownership
int investedLevels = 0;
int investedBuildings = 0;

for (const auto& country: centralizedCountries)
{
std::map<std::string, double> investorIOUs;
std::map<std::string, double> overlordIOUs;
std::map<std::string, double> capitalIOUs;
std::map<std::string, double> overlordIOUs;

const std::string& overlordTag = country->getOverlord();
const std::string& overlordCapital = country->getProcessedData().overlordCapitalState;
std::string overlordCapital = "";
if (const auto& overlordIt = countries.find(overlordTag); overlordIt != countries.end())
{
overlordCapital = overlordIt->second->getProcessedData().capitalStateName;
}

for (const auto& subState: country->getSubStates())
{
Expand All @@ -508,7 +506,7 @@ void V3::EconomyManager::investCapital() const
double totalWeight = 0;
for (const auto& [type, investorData]: ownershipMap)
{
if (investorData.recognized && !isRecognized(country->getProcessedData().tier))
if (investorData.recognized && country->getProcessedData().type != "recognized")
{
continue;
}
Expand All @@ -533,35 +531,43 @@ void V3::EconomyManager::investCapital() const
}

int capitalLevels = 0, empireLevels = 0;
const auto& ownership = ownershipMap.at(type);

// Send some owners to the capital
if (ownershipMap.at(type).financialCenterFrac > 0)
if (ownership.financialCenterFrac > 0)
{
// TODO(Gawquon): Do capitalist things
std::map<std::string, double> capitalWeights{{"local", 1 - ownership.financialCenterFrac}, {"capital", ownership.financialCenterFrac}};
empireLevels = apportionInvestors(levels, capitalWeights, capitalIOUs).at("capital");
}

// Send some owners to the empire
if (ownershipMap.at(type).colonialFrac > 0 && overlordTag != "" && overlordCapital != "")
if (ownership.colonialFrac > 0 && overlordTag != "" && overlordCapital != "")
{
// TODO(Gawquon): Do imperialist things
std::map<std::string, double> imperialWeights{{"local", 1 - ownership.colonialFrac}, {"overlord", ownership.colonialFrac}};
empireLevels = apportionInvestors(levels, imperialWeights, overlordIOUs).at("overlord");
}

if (levels - capitalLevels - empireLevels > 0)
{
building->addInvestor(levels - capitalLevels - empireLevels, type, subState->getHomeStateName(), country->getTag());
investedLevels += levels - capitalLevels - empireLevels;
}
if (capitalLevels > 0)
{
building->addInvestor(capitalLevels, type, country->getProcessedData().capitalStateName, country->getTag());
investedLevels += capitalLevels;
}
if (empireLevels > 0)
{
building->addInvestor(empireLevels, type, overlordCapital, overlordTag);
investedLevels += empireLevels;
}
}
investedBuildings += 1;
}
}
}
Log(LogLevel::Info) << "<> Pops invested in " << investedLevels << " shares of " << investedBuildings << " buildings world-wide.";
}

void V3::EconomyManager::setPMs() const
Expand Down
3 changes: 1 addition & 2 deletions EU4ToVic3/Source/V3World/EconomyManager/EconomyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ class EconomyManager
void assignSubStateCPBudgets(Configuration::ECONOMY economyType) const;
void balanceNationalBudgets() const;
void buildBuildings(const std::map<std::string, Law>& lawsMap) const;
void investCapital() const;
void investCapital(const std::map<std::string, std::shared_ptr<Country>>& countries) const;
void setPMs() const;

[[nodiscard]] const auto& getCentralizedCountries() const { return centralizedCountries; }

private:
static double calculatePopDistanceFactor(int countryPopulation, double geoMeanPopulation);
static double calculateDateFactor(Configuration::STARTDATE startDate, const DatingData& dateData);
static bool isRecognized(const std::string& countryTier);

// Budget fxns set weight for all countries, accumulates the total weight, and returns a modifier to the globalCP pool (if any).
[[nodiscard]] std::pair<double, double> countryBudgetCalcs(Configuration::ECONOMY economyType) const; // Return total weight, any special factors
Expand Down
2 changes: 0 additions & 2 deletions EU4ToVic3/Source/V3World/PoliticalManager/Country/Country.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ struct ProcessedData
std::set<std::string> techs;
std::map<std::string, Relation> relations;
std::string overlordTag;
std::string overlordCapitalState;
std::set<std::string> rivals;
std::map<std::string, int> truces;
std::vector<Character> characters;
Expand Down Expand Up @@ -241,7 +240,6 @@ class Country: commonItems::parser
void setPolStrategies(const std::map<std::string, int>& strategies) { processedData.polStrategies = strategies; }

void setOverlord(const std::string& overlordTag) { processedData.overlordTag = overlordTag; }
void trackOverlordCapital(const std::string& overlordCapitalStateName) { processedData.overlordCapitalState = overlordCapitalStateName; }
void addGoal(const std::string& target, const std::string& goal) { processedData.targetSecretGoals.emplace(target, goal); }

void setDiscriminationLevel(const ProcessedData::DISCRIMINATION_LEVEL& discrimination) { processedData.discriminationLevel = discrimination; }
Expand Down
2 changes: 1 addition & 1 deletion EU4ToVic3/Source/V3World/V3World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ V3::World::World(const Configuration& configuration, const EU4::World& sourceWor
economyManager.assignSubStateCPBudgets(configBlock.economy);
Log(LogLevel::Progress) << "76 %";
economyManager.buildBuildings(politicalManager.getLawsMap());
economyManager.investCapital();
economyManager.investCapital(politicalManager.getCountries());
economyManager.establishBureaucracy(politicalManager);
economyManager.setPMs();

Expand Down

0 comments on commit 193b02b

Please sign in to comment.