Skip to content

Commit

Permalink
start createPeasants
Browse files Browse the repository at this point in the history
  • Loading branch information
gawquon committed Aug 30, 2024
1 parent 4a6f032 commit 51fdd02
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 36 deletions.
30 changes: 28 additions & 2 deletions EU4ToVic3/Source/V3World/EconomyManager/Demand/MarketJobs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "MarketJobs.h"

#include <numeric>
#include <ranges>


V3::MarketJobs::MarketJobs(const std::vector<std::pair<std::string, int>>& manorHouseRoster): manorHouseRoster(manorHouseRoster)
Expand Down Expand Up @@ -28,7 +28,33 @@ void V3::MarketJobs::createJobs(const PopType& popType, double amount, const dou
jobCounts[popType.getType()] += amount - shortage;
}

void V3::MarketJobs::loadInitialJobs(const std::map<std::string, double> jobsList)
// pre: subsistenceUnitEmployment must contain peasants TODO(Gawquon): Maybe not?
// post: MarketJobs accumulates subStatePop, and an equal number of jobs are distributed
// Returns number of subsistence building levels filled.
double V3::MarketJobs::createPeasants(const std::map<std::string, int>& subsistenceUnitEmployment,
double defaultRatio,
double womenJobRate,
int arableLand,
int subStatePop,
const std::map<std::string, PopType>& popTypes)
{
auto unitEmployment = subsistenceUnitEmployment;
for (const auto& [job, amount]: manorHouseRoster) // Peasants create manor house jobs.
{
unitEmployment[job] += amount;
}
// const int totalUnitPop = std::accumulate(unitEmployment.begin(), unitEmployment.end(), 0, [](int sum, const auto& pair) {
// return sum + pair.second;
// });



double levels = getLevelsFromUnitEmploymentArable(unitEmployment, defaultRatio, womenJobRate, arableLand, subStatePop, popTypes);

// TODO getLevelsFromUnitEmploymentArable
}

void V3::MarketJobs::loadInitialJobs(const std::map<std::string, double>& jobsList)
{
jobCounts = jobsList;
population = std::accumulate(jobCounts.begin(), jobCounts.end(), 0, [](int sum, const auto& pair) {
Expand Down
16 changes: 15 additions & 1 deletion EU4ToVic3/Source/V3World/EconomyManager/Demand/MarketJobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@ class MarketJobs
[[nodsicard]] std::map<std::string, double> getJobBreakdown() const;

void createJobs(const PopType& popType, double amount, double defaultRatio, double womenJobRate, int peasantsPerLevel);
void createJobs(const std::map<std::string, int>& unitEmployment,
double defaultRatio,
double womenJobRate,
int peasantsPerLevel,
const std::map<std::string, double>& estimatedOwnerships,
const std::map<std::string, int>& ownershipEmployments,
const std::map<std::string, PopType>& popTypes);
double createPeasants(const std::map<std::string, int>& subsistenceUnitEmployment,
double defaultRatio,
double womenJobRate,
int arableLand,
int subStatePop,
const std::map<std::string, PopType>& popTypes);
void clearJobs() { jobCounts.clear(); }
void loadInitialJobs(const std::map<std::string, double> jobsList);
void loadInitialJobs(const std::map<std::string, double>& jobsList);

private:
int population = 0;
Expand All @@ -28,6 +41,7 @@ class MarketJobs
double hireFromPeasants(double amount, int peasantsPerLevel); // Returns the amount of jobs with no peasants available.
void downsizeManorHouses(double peasantAmount, int peasantsPerLevel); // Removes employment from Manor Houses based on # of peasants who got real jobs.


std::vector<std::pair<std::string, int>> manorHouseRoster;
};
} // namespace V3
Expand Down
75 changes: 47 additions & 28 deletions EU4ToVic3/Source/V3World/EconomyManager/Demand/MarketTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,38 @@ void V3::MarketTracker::resetMarket()
void V3::MarketTracker::loadPeasants(const Country& country,
const std::map<std::string, ProductionMethodGroup>& PMGroups,
const std::map<std::string, ProductionMethod>& PMs,
const std::map<std::string, Building>& buildings,
const std::map<std::string, Law>& lawsMap)
const std::map<std::string, Building>& buildings)
{
// For each state check peasant PM
// from PM calc Jobs per arable land
// multiply Unit Jobs per filled arable land
// load in jobs
// "unemployed" for all who don't fit on the arable land

// For each state check peasant PM
for (const auto& subState: country.getSubStates())
{
const std::string& subsistenceBuildingName = subState->getHomeState()->getSubsistenceBuilding();
if (const auto& subsistenceBuildingIter = buildings.find(subsistenceBuildingName); subsistenceBuildingIter != buildings.end())
{
std::map<std::string, double> subsistenceEmployment;
double total = 0;
auto subsistenceEmployment = getSubsistenceEmployment(subsistenceBuildingName, country.getProcessedData().laws, PMGroups, PMs, buildings);

const auto& subsistenceBuilding = subsistenceBuildingIter->second;
for (const auto& PMg: subsistenceBuilding.getPMGroups())
if (!subsistenceEmployment.contains("peasants"))
{
if (!subsistenceErrors.contains(subsistenceBuildingName))
{
const auto& PMName = PMGroups.at(PMg).getPMs()[getPMAllowedByLaws(PMg, country.getProcessedData().laws, PMGroups, PMs)];
const auto& thePM = PMs.at(PMName);
for (const auto& [job, amount]: thePM.getEmployment()) // TODO(Gawquon) Note that we still need to add the market goods for subsistence farms
{
subsistenceEmployment[job] += amount;
total += amount;
}
Log(LogLevel::Warning) << "Building: " << subsistenceBuildingName << " is marked as subsistence, yet has no peasants.";
subsistenceErrors.emplace(subsistenceBuildingName);
}
continue;
}

int peasantsPerLevel = subsistenceEmployment.at("peasants"); // TODO validate
// TODO (stuff)
marketJobs.createPeasants(subsistenceEmployment,
10000000000000, // TODO load in defines
10000000000000, // TODO do the law thingy
subState->getResource("bg_agriculture"),
subState->getSubStatePops().getPopCount(),
{});

marketJobs.loadInitialJobs()
// Create the Unit Employment by accounting for subsistence farm size and manor house stuff.
// Employ people base on ratios in unit employment untill arabe land is filled
// the rest are unemployed,
}
else
{
Log(LogLevel::Warning) << "Subsistence Building: " << subsistenceBuildingName << " has no definition.";
}
// Get the arable land
// marketJobs.
}
}

Expand Down Expand Up @@ -140,4 +131,32 @@ bool V3::MarketTracker::hasBlockingLaws(const std::set<std::string>& laws, const
return std::ranges::any_of(targetLaws, [laws](const std::string& targetLaw) {
return laws.contains(targetLaw);
});
}
}

std::map<std::string, int> V3::MarketTracker::getSubsistenceEmployment(const std::string& buildingName,
const std::set<std::string>& laws,
const std::map<std::string, ProductionMethodGroup>& PMGroups,
const std::map<std::string, ProductionMethod>& PMs,
const std::map<std::string, Building>& buildings) const
{
const auto& subsistenceBuildingIter = buildings.find(buildingName);
if (subsistenceBuildingIter == buildings.end())
{
Log(LogLevel::Warning) << "Subsistence Building: " << buildingName << " has no definition.";
}

std::map<std::string, int> subsistenceEmployment;

const auto& subsistenceBuilding = subsistenceBuildingIter->second;
for (const auto& PMGroup: subsistenceBuilding.getPMGroups())
{
const auto& PMName = PMGroups.at(PMGroup).getPMs()[getPMAllowedByLaws(PMGroup, laws, PMGroups, PMs)];
const auto& thePM = PMs.at(PMName);
for (const auto& [job, amount]: thePM.getEmployment()) // TODO(Gawquon) Note that we still need to add the market goods for subsistence farms
{
subsistenceEmployment[job] += amount;
}
}

return subsistenceEmployment;
}
14 changes: 10 additions & 4 deletions EU4ToVic3/Source/V3World/EconomyManager/Demand/MarketTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class MarketTracker
void loadPeasants(const Country& country,
const std::map<std::string, ProductionMethodGroup>& PMGroups,
const std::map<std::string, ProductionMethod>& PMs,
const std::map<std::string, Building>& buildings,
const std::map<std::string, Law>& lawsMap);
const std::map<std::string, Building>& buildings);
void loadCultures(const std::map<std::string, double> cultureData) { marketCulture = cultureData; }

void updatePopNeeds(const Vic3DefinesLoader& defines,
Expand All @@ -41,12 +40,19 @@ class MarketTracker
const std::set<std::string>& laws,
const std::map<std::string, ProductionMethodGroup>& PMGroups,
const std::map<std::string, ProductionMethod>& PMs) const;
bool hasUnlockingLaws(const std::set<std::string>& laws, const std::set<std::string>& targetLaws) const;
bool hasBlockingLaws(const std::set<std::string>& laws, const std::set<std::string>& targetLaws) const;
[[nodiscard]] bool hasUnlockingLaws(const std::set<std::string>& laws, const std::set<std::string>& targetLaws) const;
[[nodiscard]] bool hasBlockingLaws(const std::set<std::string>& laws, const std::set<std::string>& targetLaws) const;
[[nodiscard]] std::map<std::string, int> getSubsistenceEmployment(const std::string& subsistenceBuildingName,
const std::set<std::string>& laws,
const std::map<std::string, ProductionMethodGroup>& PMGroups,
const std::map<std::string, ProductionMethod>& PMs,
const std::map<std::string, Building>& buildings) const;

Market market;
MarketJobs marketJobs;
std::map<std::string, double> marketCulture;

static inline std::set<std::string> subsistenceErrors = {};
};
} // namespace V3

Expand Down
2 changes: 1 addition & 1 deletion EU4ToVic3/Source/V3World/EconomyManager/EconomyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void V3::EconomyManager::buildBuildings(const std::map<std::string, Law>& lawsMa
const auto& estimatedPMs = PMMapper.estimatePMs(*country, PMs, PMGroups, buildings);
const auto& estimatedOwnershipFracs = estimateInvestorBuildings(*country);
market.resetMarket();
market.loadPeasants(*country, PMGroups, PMs, buildings, lawsMap);
market.loadPeasants(*country, PMGroups, PMs, buildings);
market.loadCultures(country->getCultureBreakdown());

// Until every substate is unable to build anything
Expand Down

0 comments on commit 51fdd02

Please sign in to comment.