Skip to content

Commit

Permalink
PM adjustments (#349)
Browse files Browse the repository at this point in the history
* Have to specify default pms

* manufactories -> manufacturies

* absolute cap on bureacracy generation

* account for econ of scale throughput for admin gen

* re-add smallestLargeBuilding check

* economy of scale corrections

* tech based paper

* de-pragma

* paper - sulphur adjustment

* ranges copy_if -> std copy_if to satisfy gnu?

* More econ config comments

* sulphur nudge

* typo
  • Loading branch information
gawquon authored Mar 3, 2023
1 parent 6e9c33d commit 9cf560d
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 66 deletions.
3 changes: 2 additions & 1 deletion EU4ToVic3/Data_Files/configurables/economy/buildings_map.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# NOTE: These do not make more buildings appear, they just adjust State level CP spending priority.
# Meaning States will want to spend a greater portion of their budget on boosted buildings.

# EU4 Building -> V3 building(s) it boosts.
# Ex. 1 link = { eu4 = building vic3 = { building } }
Expand All @@ -21,7 +22,7 @@ link = {
eu4 = textile
vic3 = {
building_textile_mills
building_furniture_manufactories
building_furniture_manufacturies
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# They are calibrated based on Vanilla Vic3.

# (0 <-> INTMAX)
# Total # of CP in the globe
# Total # of Construction Points(CP) in the globe
global_construction_points = 1500000
vn_global_construction_points = 871050

Expand Down
76 changes: 64 additions & 12 deletions EU4ToVic3/Data_Files/configurables/economy/national_budget.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,31 @@

# Sector weights may be modified by Vic3 laws, colonial status

# The national budget forms the country's opinon of what should be built,
# but still must face the realities of technology/resource availability and the desire of the states.
# The national budget forms the country's opinion of what should be built, but still must face the realities of technology/resource availability and the desire of the states.
# When a state asks to build logging camps, the nation will check if there still is an extraction budget left before giving its assent.
# If the state and the nation can't agree on any building, the state's opinion will win out. The state builds what it wants and takes the cost out of the largest budget remaining.
# This happens most often when there is budget for a resource that just does not exist in a state.

# State: "I'd like to build a farm."
# Nation: "We're out of farm budget."
# State: "How about a mine?."
# Nation: "Out of mine budget. We have only have whaling budget left. Do you want some whaling wharfs?"
# State: "... I'm a landlocked state, screw you I'm building a farm and our oversized whaling industry is paying for it!"

# There can be as many or as few sectors as you want, and they must have at minimum a defined non-negative weight and at least one vic3_building.
# Every vic3_building possible to start the game with should belong to one and only one sector.
# example_sector = {
# weight = 4 # Base weight of the sector
# industrial = yes # wieght is modified by civlevel and industry score (see configurables/westernization.txt)
#
# building_1 # Anytime a state builds building_1, the cost is taken from example_sector budget
# building_2 # Anytime a state builds building_2, the cost is taken from example_sector budget
#
# add = { # Modifiers to base weight based on a single trigger. Supports add/multiply
# value = 2 # Value of the addend/multiplier
# vic3_law = law_example_law # Trigger for modifier. Supported triggers are vic3_law, vic3_tech, is_colony, is_trade_company, is_eu4_gp, industry_score_less_than
# }
#}

construction = {
weight = 0.15
Expand All @@ -13,7 +36,7 @@ construction = {
}

infrastructure = {
weight = 3
weight = 3.5

building_port
building_railway
Expand Down Expand Up @@ -80,6 +103,15 @@ military_mining = {

building_lead_mine
building_sulfur_mine

add = {
value = 1
is_eu4_gp = yes
}
add = {
value = 0.5
vic3_tech = mechanical_tools
}
}

plantation = {
Expand Down Expand Up @@ -120,13 +152,29 @@ shipwrights = {
building_shipyards
}

paper_industry = {
weight = 1

building_paper_mills

add = {
value = 7
vic3_tech = centralization
}

add = {
value = 7
vic3_tech = central_archives
}
}

light_industry = {
weight = 21
weight = 16

building_textile_mills
building_furniture_manufacturies
building_glassworks
building_paper_mills


# Industry score from configurables/westernization.txt. No effect if no EuroCentrism
multiply = {
Expand Down Expand Up @@ -161,9 +209,9 @@ tooling_industry = {

building_tooling_workshops

add = {
value = 2.5
is_eu4_gp = yes
add = {
value = 2.5
is_eu4_gp = yes
}
}

Expand All @@ -186,8 +234,12 @@ heavy_industry = {
building_motor_industry
building_munition_plants

add = {
value = 4
is_eu4_gp = yes
}
add = {
value = 4
is_eu4_gp = yes
}
multiply = {
value = 0
industry_score_less_than = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# The percent is the percent of building levels that will try to move off of default to adopt the defined PM. It is assumed to be 1(100%) unless specified.

# building_government_administration # SPECIAL CASE government administration links will be ignored even if defined.
### Devlopment
##### Development
building_port = {
pm = { name = pm_basic_port }
}
Expand All @@ -14,19 +14,23 @@ building_naval_base = {
pm = { name = pm_power_of_the_purse }
}

### Urban
##### Urban
building_tooling_workshops = {
pm = { name = pm_pig_iron }
}
building_glassworks = {
pm = { name = pm_leaded_glass }
}
building_paper_mills = {
pm = { name = pm_sulfite_pulping }
pm = { name = pm_sulfite_pulping percent = 0.4 }
}
building_furniture_manufactories = {
building_furniture_manufacturies = {
pm = { name = pm_lathe }
pm = { name = pm_luxury_furniture percent = 0.5}
pm = { name = pm_luxury_furniture percent = 0.5 }
}
building_textile_mills = {
pm = { name = pm_dye_workshops percent = 0.05 }
pm = { name = pm_craftsman_sewing percent = 0.1 }
}
building_shipyards = {
pm = { name = pm_military_shipbuilding_wooden }
Expand All @@ -41,13 +45,37 @@ building_chemical_plants = {
pm = { name = pm_leblanc_process }
}

### Rural
##### Rural
building_logging_camp = {
pm = { name = pm_saw_mills }
pm = { name = pm_hardwood percent = 0.33 }
pm = { name = pm_hardwood percent = 0.4 }
}
### Farms
building_rye_farm = {
pm = { name = pm_potatoes percent = 0.15 }
}
building_wheat_farm = {
pm = { name = pm_citrus_orchards percent = 0.2 }
}
building_millet_farm = {
pm = { name = pm_fig_orchards percent = 0.2 }
}
building_maize_farm = {
pm = { name = pm_citrus_orchards percent = 0.2 }
}
building_rice_farm = {
pm = { name = pm_fig_orchards percent = 0.1 }
}
### Mines
building_coal_mine = {
pm = { name = pm_atmospheric_engine_pump_building_coal_mine }
}
building_iron_mine = {
pm = { name = pm_atmospheric_engine_pump_building_iron_mine }
}
building_gold_mine = {
pm = { name = pm_atmospheric_engine_pump_building_gold_mine }
}
building_sulfur_mine = {
pm = { name = pm_atmospheric_engine_pump_building_sulfur_mine }
}

# Farms need more code support due to clashing pm names
#building_rye_farm = {
# pm = { name = pm_potatoes percent = 0.15 }
#}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ coastal = {
building_shipyards = 0.2
building_tooling_workshops = 0.2
building_textile_mills = 0.2
building_furniture_manufactories = 0.2
building_furniture_manufacturies = 0.15
building_university = 0.2
building_glassworks = 0.1
building_paper_mills = 0.1
building_logging_camp = 0.1
building_steel_mills = 0.02
}

desert = {
Expand All @@ -46,14 +47,15 @@ forest = {
priority = 0.1

building_paper_mills = 0.3
building_furniture_manufactories = 0.2
building_furniture_manufacturies = 0.05
building_arms_industry = 0.15
building_shipyards = 0.1
building_glassworks = 0.1
building_tooling_workshops = 0.1
building_university = 0.05
building_logging_camp = 0.7
building_fishing_wharf = 0.1
building_munition_plants = 0.05
}

hills = {
Expand Down Expand Up @@ -96,7 +98,6 @@ mountain = {
building_coal_mine = 0.7
building_gold_mine = 1
building_opium_plantation = 0.3
building_chemical_plants = 0.1
building_munition_plants = 0.05
building_arts_academy = 0.3
building_tooling_workshops = 0.2
Expand All @@ -120,7 +121,7 @@ plains = {
building_cotton_plantation = 0.3
building_silk_plantation = 0.3
building_tea_plantation = 0.3
building_furniture_manufactories = 0.2
building_furniture_manufacturies = 0.2
building_barracks = 0.2
building_railway = 0.1
building_food_industry = 0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ void mappers::ProductionMethodMapper::applyRules(const V3::Country& country,
for (const auto& rule: buildingToRules.at(buildingType))
{
auto selectedBuildings = pickBuildings(builtBuildings, rule.percent);
const std::string selectedPM = pickPM(country, rule.pm, PMs, PMGroups); // select PM
if (selectedBuildings.empty())
continue;

const auto& buildingPMGroups = selectedBuildings[0]->getPMGroups();
const auto [defaultPM, selectedPM] = pickPM(country, rule.pm, buildingPMGroups, PMs, PMGroups); // select PM

// For each building in the vector, add the PMs to it
for (const auto& selectedBuilding: selectedBuildings)
selectedBuilding->addPM(selectedPM);
for (const auto& builtBuilding: builtBuildings)
{
if (std::ranges::find(selectedBuildings, builtBuilding) != selectedBuildings.end())
builtBuilding->addPM(selectedPM);
else
builtBuilding->addPM(defaultPM);
}
}
}
}
Expand Down Expand Up @@ -101,7 +110,7 @@ std::vector<std::shared_ptr<V3::Building>> mappers::ProductionMethodMapper::pick
// Select all buildings with level <= target
std::vector<std::shared_ptr<V3::Building>> selectedBuildings;
std::copy_if(buildings.begin(), buildings.end(), std::back_inserter(selectedBuildings), [target](const std::shared_ptr<V3::Building>& building) {
return building->getLevel() <= target;
return building->getLevel() <= target && building->getLevel() > 0;
});

if (std::accumulate(selectedBuildings.begin(), selectedBuildings.end(), 0, sumBuildingLevels) > target)
Expand All @@ -111,39 +120,47 @@ std::vector<std::shared_ptr<V3::Building>> mappers::ProductionMethodMapper::pick

// Now return either selectedBuildings, or a single building if the sum of selectedBuildings
// is further from target than the smallest building larger than target.
std::shared_ptr<V3::Building> smallestLargerBuilding = nullptr;
int smallestLargerBuildingLevel = INT_MAX;

// Get smallest building larger than the target number
int smallestLargeBuildingLevel = INT_MAX;
std::shared_ptr<V3::Building> smallestLargeBuilding = nullptr;

for (const auto& building: buildings)
{
if (building->getLevel() > target && building->getLevel() < smallestLargerBuildingLevel)
if (building->getLevel() > target && building->getLevel() < smallestLargeBuildingLevel)
{
smallestLargerBuilding = building;
smallestLargerBuildingLevel = building->getLevel();
smallestLargeBuildingLevel = building->getLevel();
smallestLargeBuilding = building;
}
}

if (smallestLargerBuilding)
if (!smallestLargeBuilding)
return selectedBuildings;
const int selectedSum = std::accumulate(selectedBuildings.begin(), selectedBuildings.end(), 0, sumBuildingLevels);
if (smallestLargeBuildingLevel - target < std::abs(target - selectedSum))
{
if (smallestLargerBuildingLevel - target < target - std::accumulate(selectedBuildings.begin(), selectedBuildings.end(), 0, sumBuildingLevels))
{
selectedBuildings.clear();
selectedBuildings.push_back(smallestLargerBuilding);
}
selectedBuildings.clear();
selectedBuildings.push_back(smallestLargeBuilding);
}

return selectedBuildings;
}

std::string mappers::ProductionMethodMapper::pickPM(const V3::Country& country,
std::pair<std::string, std::string> mappers::ProductionMethodMapper::pickPM(const V3::Country& country,
const std::string& targetName,
const std::set<std::string>& buildingPMGroups,
const std::map<std::string, V3::ProductionMethod>& PMs,
const std::map<std::string, V3::ProductionMethodGroup>& PMGroups)
{
// NOTE(Gawquon): This works for most PMs, but is not guaranteed to work for ownership PMs.
// This is just a basic version that will support every use-case we currently care about.
for (const auto& PMGroup: PMGroups | std::views::values)
{
if (!buildingPMGroups.contains(PMGroup.getName()))
{
continue; // We're only checking PMGroups that are present in the building we're working on
}

if (std::ranges::find(PMGroup.getPMs(), targetName) != PMGroup.getPMs().end())
{
// Validate every PM in group
Expand All @@ -152,7 +169,7 @@ std::string mappers::ProductionMethodMapper::pickPM(const V3::Country& country,
if (!PMs.contains(PM))
{
Log(LogLevel::Error) << "Unknown PM: " << PM << ".";
return "";
return {"", ""};
}
}

Expand All @@ -161,17 +178,17 @@ std::string mappers::ProductionMethodMapper::pickPM(const V3::Country& country,
for (auto PM: PMGroup.getPMs())
{
if (!country.hasAnyOfTech(PMs.at(PM).getUnlockingTechs()))
return pick;
return {PMGroup.getPMs()[0], pick};
if (PM == targetName)
return PM;
return {PMGroup.getPMs()[0], PM};
pick = PM;
}
}
}

Log(LogLevel::Error) << "Could not find a PM group for PM: " << targetName << ".";

return "";
return {"", ""};
}

////////////////////////////////////////// Subset-sum fxns
Expand Down
Loading

0 comments on commit 9cf560d

Please sign in to comment.