Skip to content

Commit

Permalink
Adjust westernization logic for HPM
Browse files Browse the repository at this point in the history
  • Loading branch information
cetvrtak committed Apr 16, 2024
1 parent 69fdd4d commit b3a658c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 10 deletions.
27 changes: 26 additions & 1 deletion EU4ToVic2/Data_Files/configurables/tech_groups.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ ottoman = {

muslim = {
westernization = 6
hpm_westernization = 2
industry = 2
cultures = {
# Arabic
Expand All @@ -128,6 +129,7 @@ muslim = {

indian = {
westernization = 5
hpm_westernization = 2
industry = 2
cultures = {
# Indian
Expand All @@ -143,6 +145,7 @@ indian = {

east_african = {
westernization = 4
hpm_westernization = 1
industry = 0
cultures = {
# Horn
Expand All @@ -158,6 +161,7 @@ east_african = {

central_african = {
westernization = 3
hpm_westernization = 1
industry = 0
cultures = {
# North central
Expand All @@ -177,10 +181,19 @@ central_african = {

chinese = {
westernization = 4
hpm_westernization = 3
industry = 2
cultures = {
# East Asian
dongren nanren heiren japanese manchu beifaren nanfaren korean ainu hakka miao min zhuang yi yue xiyeren beieren naiyeren
dongren nanren heiren manchu beifaren nanfaren korean ainu hakka miao min zhuang yi yue xiyeren beieren naiyeren
}
}

indochinese = {
westernization = 4
hpm_westernization = 2
industry = 2
cultures = {
# Khmer
thegioimoi phianam dhen vietnamese khmer
# Malay
Expand All @@ -192,8 +205,19 @@ chinese = {
}
}

japanese = {
westernization = 4
hpm_westernization = 5
industry = 2
cultures = {
# Just Japan
japanese
}
}

nomad_group = {
westernization = 3
hpm_westernization = 1
industry = 1
cultures = {
# Altaic
Expand All @@ -203,6 +227,7 @@ nomad_group = {

sub_saharan = {
westernization = 2
hpm_westernization = 1
industry = 0
cultures = {
# Sahelian
Expand Down
5 changes: 5 additions & 0 deletions EU4ToVic2/Source/Mappers/TechGroups/TechGroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ mappers::TechGroups::TechGroups(std::istream& theStream)
const auto& cultureList = commonItems::getStrings(theStream);
hpmCultures.insert(cultureList.begin(), cultureList.end());
});
registerKeyword("hpm_westernization", [this](std::istream& theStream) {
hpmWesternization = commonItems::getInt(theStream);
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);

parseStream(theStream);
clearRegisteredKeywords();

if (theConfiguration.isHpmEnabled() && !hpmCultures.empty())
cultures = hpmCultures;
if (theConfiguration.isHpmEnabled() && hpmWesternization != 0)
westernization = hpmWesternization;
}
1 change: 1 addition & 0 deletions EU4ToVic2/Source/Mappers/TechGroups/TechGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TechGroups: commonItems::parser
int industry = 5;
std::set<std::string> cultures;
std::set<std::string> hpmCultures;
int hpmWesternization = 0;
};
} // namespace mappers

Expand Down
2 changes: 1 addition & 1 deletion EU4ToVic2/Source/V2World/Country/Country.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ void V2::Country::newCivConversionMethod(double topTech, int topInstitutions, co
totalTechs = totalTechs - srcCountry->getDipTech();
const auto militaryDev = srcCountry->getMilTech() / totalTechs;
const auto socioEconDev = srcCountry->getAdmTech() / totalTechs;
uncivReforms = UncivReforms(lround(civLevel), militaryDev, socioEconDev, this);
uncivReforms = UncivReforms(lround(civLevel), militaryDev, socioEconDev, this, theConfiguration.isHpmEnabled());
}
}

Expand Down
36 changes: 29 additions & 7 deletions EU4ToVic2/Source/V2World/Reforms/UncivReforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../Country/Country.h"
#include "../Province/Province.h"

V2::UncivReforms::UncivReforms(const int westernizationProgress, const double milFocus, const double socioEcoFocus, Country* country)
V2::UncivReforms::UncivReforms(const int westernizationProgress, const double milFocus, const double socioEcoFocus, Country* country, bool hpm)
{
int westernizationCost[16];
westernizationCost[0] = 15;
Expand Down Expand Up @@ -40,21 +40,43 @@ V2::UncivReforms::UncivReforms(const int westernizationProgress, const double mi

// Get all valid military reforms
auto milProgress = westernizationProgress * milFocus;
for (unsigned int i = 8; i < 16; i++)
if (hpm)
{
if (milProgress >= westernizationCost[i] - 0.001)
if (milProgress >= westernizationCost[9] - 0.001)
{
reforms[i] = true;
milProgress -= westernizationCost[i];
reforms[9] = true; // yes_foreign_weapons
milProgress -= westernizationCost[9];
}
else

if (milProgress >= westernizationCost[8] - 0.001)
{
reforms[i] = false;
reforms[8] = true; // yes_foreign_training
}
}
else
{
for (unsigned int i = 8; i < 16; i++)
{
if (milProgress >= westernizationCost[i] - 0.001)
{
reforms[i] = true;
milProgress -= westernizationCost[i];
}
else
{
reforms[i] = false;
}
}
}

// Use remaining progress to get any reforms in preferred category
auto remainingProgress = socioEconProgress + milProgress;

if (hpm) // No progress transfer
{
remainingProgress = 0;
}

if (socioEconProgress >= milProgress)
{
for (unsigned int i = 0; i < 8; i++)
Expand Down
2 changes: 1 addition & 1 deletion EU4ToVic2/Source/V2World/Reforms/UncivReforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UncivReforms
{
public:
UncivReforms() = default;
UncivReforms(int westernizationProgress, double milFocus, double socioEcoFocus, Country* country);
UncivReforms(int westernizationProgress, double milFocus, double socioEcoFocus, Country* country, bool hpm = false);

friend std::ostream& operator<<(std::ostream& output, const UncivReforms& uncivReforms);

Expand Down

0 comments on commit b3a658c

Please sign in to comment.