Skip to content

Commit

Permalink
Create peasants job part
Browse files Browse the repository at this point in the history
  • Loading branch information
gawquon committed Aug 30, 2024
1 parent 51fdd02 commit 71805ab
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
42 changes: 34 additions & 8 deletions EU4ToVic3/Source/V3World/EconomyManager/Demand/MarketJobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,26 @@ std::map<std::string, double> V3::MarketJobs::getJobBreakdown() const
return jobBreakdown;
}

// currenty assumes that enough potential workers exist
void V3::MarketJobs::createJobs(const PopType& popType, double amount, const double defaultRatio, const double womenJobRate, const int peasantsPerLevel)
{
amount /= (popType.getDependentRatio().value_or(defaultRatio) + womenJobRate);
const double shortage = hireFromWorseJobs(amount, peasantsPerLevel);
jobCounts[popType.getType()] += amount - shortage;
}

// Returns levels of displaced subsistence building.
double V3::MarketJobs::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)
{
return 0.0;
}

// 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.
Expand All @@ -43,15 +56,20 @@ double V3::MarketJobs::createPeasants(const std::map<std::string, int>& subsiste
{
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);
for (const auto& [job, amount]: unitEmployment) // Track Dependants
{
unitEmployment[job] = amount / (popTypes.at(job).getDependentRatio().value_or(defaultRatio) + womenJobRate);
}
double levels = getLevels(unitEmployment, arableLand, subStatePop);

// TODO getLevelsFromUnitEmploymentArable
const double capcity = levels > arableLand ? levels : arableLand;
for (const auto& [job, amount]: unitEmployment)
{
jobCounts[job] += amount * capcity;
jobCounts["unemployed"] += amount * (levels - capcity);
}
population += subStatePop;
return levels;
}

void V3::MarketJobs::loadInitialJobs(const std::map<std::string, double>& jobsList)
Expand Down Expand Up @@ -105,3 +123,11 @@ void V3::MarketJobs::downsizeManorHouses(const double peasantAmount, const int p
jobCounts[job] -= amount * peasantAmount / peasantsPerLevel;
}
}

double V3::MarketJobs::getLevels(std::map<std::string, int> unitEmployment, double arableLand, int subStatePop)
{
double unitPop = std::accumulate(unitEmployment.begin(), unitEmployment.end(), 0.0, [](double sum, const auto& pair) {
return sum + pair.second;
});
return std::min(static_cast<double>(arableLand), subStatePop / unitPop);
}
14 changes: 7 additions & 7 deletions EU4ToVic3/Source/V3World/EconomyManager/Demand/MarketJobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ 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 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);
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);

Expand All @@ -40,7 +40,7 @@ class MarketJobs
double hireFromUnemployed(double amount); // Returns the amount of jobs with no unemployed available.
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.

static double getLevels(std::map<std::string, int> unitEmployment, double arableLand, int subStatePop);

std::vector<std::pair<std::string, int>> manorHouseRoster;
};
Expand Down
17 changes: 8 additions & 9 deletions EU4ToVic3/Source/V3World/EconomyManager/Demand/MarketTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ void V3::MarketTracker::loadPeasants(const Country& country,
continue;
}

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

// Get the arable land
// marketJobs.
const double levels = marketJobs.createPeasants(subsistenceEmployment,
10000000000000, // TODO load in defines
10000000000000, // TODO do the law thingy
subState->getResource("bg_agriculture"),
subState->getSubStatePops().getPopCount(),
{});

// TODO(Gawquon): Account for market production of the subsistence buildings
}
}

Expand Down

0 comments on commit 71805ab

Please sign in to comment.