Skip to content

Commit

Permalink
Option for a custom start date (#529)
Browse files Browse the repository at this point in the history
* Option for a custom start date

* Option for a custom start date.

* Fix logic

* Expand tests
  • Loading branch information
Zemurin authored Mar 2, 2024
1 parent 17c3709 commit fd8d8e8
Show file tree
Hide file tree
Showing 21 changed files with 364 additions and 35 deletions.
8 changes: 8 additions & 0 deletions CK3ToEU4/Data_Files/configurables/start_date.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file is used for MANUAL start date option - you have to enable it in converter options.
# Hard limits are 500-1821. Don't set a date outside these.

year = 1425
month = 7
day = 19

# Please keep in mind EU4 doesn't know of leap years (February is always 28 days), and don't try to do 31st of April.
6 changes: 6 additions & 0 deletions CK3ToEU4/Data_Files/fronter-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ option = {
tooltip = STARTDATE2TIP
default = false
}
radioOption = {
name = 3
displayName = STARTDATE3
tooltip = STARTDATE3TIP
default = false
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions CK3ToEU4/Data_Files/options_l_english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ l_english:
STARTDATE1TIP: "Start at vanilla EU4 start date."
STARTDATE2: "Crusader Universalis (dynamic)"
STARTDATE2TIP: "Start at CK savegame date."
STARTDATE3: "Customized - start_date.txt"
STARTDATE3TIP: "Manually configured."
DEJURE: "Should countries get permaclaims on de jure land?"
DEJURETIP: "Some, like BYZ, might get a lot of those."
DEJURE1: "Yeah, what's the worst that could happen?"
Expand Down
2 changes: 2 additions & 0 deletions CK3ToEU4/Data_Files/options_l_french.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ l_french:
STARTDATE1TIP: "Commencez à la date de début de EU4 vanilla."
STARTDATE2: "Crusader Universalis (dynamique)"
STARTDATE2TIP: "Commencez à la date du sauvegarde de CK."
STARTDATE3: "Personnalisé - start_date.txt"
STARTDATE3TIP: "Configuré manuellement."
DEJURE: "Les pays devraient-ils obtenir des revendications permanentes sur leurs terres de jure?"
DEJURETIP: "Certains, comme BYZ, pourraient en obtenir beaucoup."
DEJURE1: "Ouais, quel est le pire qui puisse arriver?"
Expand Down
2 changes: 2 additions & 0 deletions CK3ToEU4/Data_Files/options_l_german.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ l_german:
STARTDATE1TIP: "Beginnen Sie am Startdatum von Vanille EU4."
STARTDATE2: "Crusader Universalis (dynamisch)"
STARTDATE2TIP: "Beginnen Sie am CK-Savegame-Datum."
STARTDATE3: "Maßgeschneidert - start_date.txt"
STARTDATE3TIP: "Manuell konfiguriert."
DEJURE: "Sollten Länder dauerhafte Ansprüche auf de jure Land erhalten?"
DEJURETIP: "Einige, wie BYZ, könnten viele davon bekommen."
DEJURE1: "Ja, was ist das Schlimmste, was passieren kann?"
Expand Down
2 changes: 2 additions & 0 deletions CK3ToEU4/Data_Files/options_l_italian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ l_italian:
STARTDATE1TIP: "Si comincia secondo EU4 vanilla."
STARTDATE2: "Crusader Universalis (dinamico)"
STARTDATE2TIP: "Si comincia secondo il salvataggio."
STARTDATE3: "Personalizzata - start_date.txt"
STARTDATE3TIP: "Configurato manualmente."
DEJURE: "I paesi dovrebbero ottenere rivendicazioni permanenti sulle terre de jure?"
DEJURETIP: "Alcuni, come BYZ, potrebbero ottenerne molti."
DEJURE1: "Sì, qual è il peggio che potrebbe succedere?"
Expand Down
2 changes: 2 additions & 0 deletions CK3ToEU4/Data_Files/options_l_latin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ l_latin:
STARTDATE1TIP: "Incipitur secundum vanillam EU4."
STARTDATE2: "Per Cruciatorum Universalibus (dynamice)"
STARTDATE2TIP: "Incipitur secundum ludum transcriptum."
STARTDATE3: "Nativus - start_date.txt"
STARTDATE3TIP: "Manually set.."
DEJURE: "Dentur regnibus vindicationes in terris de jure?"
DEJURETIP: "Aliquibus, sicut BYZ, darentur complures."
DEJURE1: "Age, quod maxime mali esse potest?"
Expand Down
2 changes: 2 additions & 0 deletions CK3ToEU4/Data_Files/options_l_russian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ l_russian:
STARTDATE1TIP: "Начать на изначальной дате старта EU4."
STARTDATE2: "Crusader Universalis (динамичное)"
STARTDATE2TIP: "Начать с конечной даты сейва CK."
STARTDATE3: "Индивидуальные - start_date.txt"
STARTDATE3TIP: "Настраивается вручную."
DEJURE: "Должны ли страны иметь вечные притязание на деюр?"
DEJURETIP: "Некоторые, по типу Византии, могут их иметь."
DEJURE1: "Ага, а что может пойти не так?"
Expand Down
5 changes: 3 additions & 2 deletions CK3ToEU4/Source/Configuration/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Configuration: commonItems::parser
enum class STARTDATE
{
EU = 1,
CK = 2
CK = 2,
MANUAL = 3
};
enum class SPLITVASSALS
{
Expand Down Expand Up @@ -87,7 +88,7 @@ class Configuration: commonItems::parser
[[nodiscard]] const auto& getCK3DocPath() const { return CK3DocPath; }
[[nodiscard]] const auto& getEU4Path() const { return EU4Path; }
[[nodiscard]] const auto& getOutputName() const { return outputName; }
[[nodiscard]] const auto& getStartDate() const { return startDate; }
[[nodiscard]] const auto& getStartDateOption() const { return startDate; }
[[nodiscard]] const auto& getHRE() const { return iAmHre; }
[[nodiscard]] const auto& getShatterEmpires() const { return shatterEmpires; }
[[nodiscard]] const auto& getShatterLevel() const { return shatterLevel; }
Expand Down
41 changes: 27 additions & 14 deletions CK3ToEU4/Source/EU4World/Country/Country.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ void EU4::Country::initializeFromTitle(const std::string& theTag,
const mappers::LocalizationMapper& localizationMapper,
const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
date theConversionDate,
date startDate,
Configuration::STARTDATE startDateOption,
bool dynasticNames)
{
tag = theTag;
if (startDateOption == Configuration::STARTDATE::CK)
conversionDate = theConversionDate;
else if (startDateOption == Configuration::STARTDATE::MANUAL)
conversionDate = startDate;
else
conversionDate = date(1444, 11, 11);
title = theTitle;
Expand All @@ -74,7 +77,7 @@ void EU4::Country::initializeFromTitle(const std::string& theTag,
populateCommons(cultureMapper, localizationMapper);
populateMisc();
populateLocs(localizationMapper, dynasticNames);
populateRulers(religionMapper, cultureMapper, rulerPersonalitiesMapper, localizationMapper, startDateOption, theConversionDate);
populateRulers(religionMapper, cultureMapper, rulerPersonalitiesMapper, localizationMapper, startDateOption, theConversionDate, startDate);
}

void EU4::Country::populateHistory(const mappers::GovernmentsMapper& governmentsMapper,
Expand Down Expand Up @@ -593,7 +596,8 @@ void EU4::Country::populateRulers(const mappers::ReligionMapper& religionMapper,
const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
const mappers::LocalizationMapper& localizationMapper,
Configuration::STARTDATE startDateOption,
const date& theConversionDate)
const date& theConversionDate,
const date& startDate)
{
// do we HAVE a ruler? Broken saves come to mind.
if (!details.holder || details.holder->isDead())
Expand All @@ -616,9 +620,9 @@ void EU4::Country::populateRulers(const mappers::ReligionMapper& religionMapper,
if (details.holder->getCharacterDomain()->getDomain()[0].second->getName() != title->first && details.government == "monarchy")
return;

convertHolder(rulerPersonalitiesMapper, localizationMapper, startDateOption, theConversionDate);
convertSpouse(religionMapper, cultureMapper, rulerPersonalitiesMapper, localizationMapper, startDateOption, theConversionDate);
convertHeirs(religionMapper, cultureMapper, rulerPersonalitiesMapper, localizationMapper, startDateOption, theConversionDate);
convertHolder(rulerPersonalitiesMapper, localizationMapper, startDateOption, theConversionDate, startDate);
convertSpouse(religionMapper, cultureMapper, rulerPersonalitiesMapper, localizationMapper, startDateOption, theConversionDate, startDate);
convertHeirs(religionMapper, cultureMapper, rulerPersonalitiesMapper, localizationMapper, startDateOption, theConversionDate, startDate);

// this transformation is always true, heir or not.
if (conversionDate.diffInYears(details.monarch.birthDate) < 16)
Expand Down Expand Up @@ -647,7 +651,8 @@ void EU4::Country::convertHeirs(const mappers::ReligionMapper& religionMapper,
const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
const mappers::LocalizationMapper& localizationMapper,
Configuration::STARTDATE startDateOption,
const date& theConversionDate)
const date& theConversionDate,
const date& startDate)
{
if (!title->second->getHeirs().empty())
{
Expand Down Expand Up @@ -700,7 +705,7 @@ void EU4::Country::convertHeirs(const mappers::ReligionMapper& religionMapper,
details.heir.adm = std::min((heir.second->getSkills().stewardship + heir.second->getSkills().learning) / 2, 6);
details.heir.dip = std::min((heir.second->getSkills().diplomacy + heir.second->getSkills().intrigue) / 2, 6);
details.heir.mil = std::min((heir.second->getSkills().martial + heir.second->getSkills().learning) / 2, 6);
details.heir.birthDate = normalizeDate(heir.second->getBirthDate(), startDateOption, theConversionDate);
details.heir.birthDate = normalizeDate(heir.second->getBirthDate(), startDateOption, theConversionDate, startDate);
details.heir.female = heir.second->isFemale();
if (!heir.second->getFaith() || !heir.second->getFaith()->second)
{
Expand Down Expand Up @@ -752,7 +757,8 @@ void EU4::Country::convertSpouse(const mappers::ReligionMapper& religionMapper,
const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
const mappers::LocalizationMapper& localizationMapper,
Configuration::STARTDATE startDateOption,
const date& theConversionDate)
const date& theConversionDate,
const date& startDate)
{
if (details.holder->getSpouse() && details.holder->getSpouse()->second && details.holder->getSpouse()->second->getHouse().second &&
!details.holder->isDead()) // making sure she's alive.
Expand Down Expand Up @@ -785,7 +791,7 @@ void EU4::Country::convertSpouse(const mappers::ReligionMapper& religionMapper,
details.queen.adm = std::min((spouse->getSkills().stewardship + spouse->getSkills().learning) / 3, 6);
details.queen.dip = std::min((spouse->getSkills().diplomacy + spouse->getSkills().intrigue) / 3, 6);
details.queen.mil = std::min((spouse->getSkills().martial + spouse->getSkills().learning) / 3, 6);
details.queen.birthDate = normalizeDate(spouse->getBirthDate(), startDateOption, theConversionDate);
details.queen.birthDate = normalizeDate(spouse->getBirthDate(), startDateOption, theConversionDate, startDate);
details.queen.female = spouse->isFemale();
if (spouse->getFaith() && spouse->getFaith()->second)
{
Expand Down Expand Up @@ -832,7 +838,8 @@ void EU4::Country::convertSpouse(const mappers::ReligionMapper& religionMapper,
void EU4::Country::convertHolder(const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
const mappers::LocalizationMapper& localizationMapper,
Configuration::STARTDATE startDateOption,
const date& theConversionDate)
const date& theConversionDate,
const date& startDate)
{
// Determine regnalness.
std::string actualName = details.holder->getName();
Expand Down Expand Up @@ -884,7 +891,7 @@ void EU4::Country::convertHolder(const mappers::RulerPersonalitiesMapper& rulerP
details.monarch.adm = std::min((details.holder->getSkills().stewardship + details.holder->getSkills().learning) / 3, 6);
details.monarch.dip = std::min((details.holder->getSkills().diplomacy + details.holder->getSkills().intrigue) / 3, 6);
details.monarch.mil = std::min((details.holder->getSkills().martial + details.holder->getSkills().learning) / 3, 6);
details.monarch.birthDate = normalizeDate(details.holder->getBirthDate(), startDateOption, theConversionDate);
details.monarch.birthDate = normalizeDate(details.holder->getBirthDate(), startDateOption, theConversionDate, startDate);
details.monarch.female = details.holder->isFemale();
// religion and culture were already determining our country's primary culture and religion. If we set there, we'll copy here.
if (!details.primaryCulture.empty())
Expand Down Expand Up @@ -1799,14 +1806,20 @@ void EU4::Country::correctRoyaltyToBuddhism()
adviser.religion = "buddhism";
}

date EU4::Country::normalizeDate(const date& incomingDate, Configuration::STARTDATE startDateOption, const date& theConversionDate) const
date EU4::Country::normalizeDate(const date& incomingDate, Configuration::STARTDATE startDateOption, const date& theConversionDate, const date& startDate) const
{
if (startDateOption == Configuration::STARTDATE::CK)
return incomingDate;

// for 1444 bookmark we need to adjust dates. Instead of being anal about days and months, we'll just fix the year so ages match approximately.
// for 1444 or manual start date bookmark we need to adjust dates. Instead of being anal about days and months, we'll just fix the year so ages match
// approximately.
const auto incomingYear = incomingDate.getYear();
const auto yearDelta = 1444 - theConversionDate.getYear();

int yearDelta;
if (startDateOption == Configuration::STARTDATE::EU)
yearDelta = 1444 - theConversionDate.getYear();
else
yearDelta = startDate.getYear() - theConversionDate.getYear();

return date(incomingYear + yearDelta, incomingDate.getMonth(), incomingDate.getDay());
}
16 changes: 11 additions & 5 deletions CK3ToEU4/Source/EU4World/Country/Country.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Country
const mappers::LocalizationMapper& localizationMapper,
const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
date theConversionDate,
date startDate,
Configuration::STARTDATE startDateOption,
bool dynasticNames);
void setSunsetCountry(bool isSunsetCountry) { details.isSunsetCountry = isSunsetCountry; }
Expand Down Expand Up @@ -117,27 +118,32 @@ class Country
const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
const mappers::LocalizationMapper& localizationMapper,
Configuration::STARTDATE startDateOption,
const date& theConversionDate);
const date& theConversionDate,
const date& startDate);
void convertHolder(const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
const mappers::LocalizationMapper& localizationMapper,
Configuration::STARTDATE startDateOption,
const date& theConversionDate);
const date& theConversionDate,
const date& startDate);
void convertSpouse(const mappers::ReligionMapper& religionMapper,
const mappers::CultureMapper& cultureMapper,
const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
const mappers::LocalizationMapper& localizationMapper,
Configuration::STARTDATE startDateOption,
const date& theConversionDate);
const date& theConversionDate,
const date& startDate);
void convertHeirs(const mappers::ReligionMapper& religionMapper,
const mappers::CultureMapper& cultureMapper,
const mappers::RulerPersonalitiesMapper& rulerPersonalitiesMapper,
const mappers::LocalizationMapper& localizationMapper,
Configuration::STARTDATE startDateOption,
const date& theConversionDate);
const date& theConversionDate,
const date& startDate);

[[nodiscard]] date normalizeDate(const date& incomingDate,
Configuration::STARTDATE startDateOption,
const date& theConversionDate) const; // Uses bookmark date to shift dates if required.
const date& theConversionDate,
const date& startDate) const; // Uses bookmark date to shift dates if required.

std::string tag;
std::string commonCountryFile;
Expand Down
25 changes: 17 additions & 8 deletions CK3ToEU4/Source/EU4World/EU4World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ EU4::World::World(const CK3::World& sourceWorld, const Configuration& theConfigu
Log(LogLevel::Progress) << "55 %";

// Which happens now. Translating incoming titles into EU4 tags, with new tags being added to our countries.
importCK3Countries(sourceWorld, theConfiguration.getStartDate(), dynasticNames);
importCK3Countries(sourceWorld, theConfiguration.getStartDateOption(), startDateMapper.getStartDate(), dynasticNames);

Log(LogLevel::Progress) << "56 %";
// Now we can deal with provinces since we know to whom to assign them. We first import vanilla province data.
Expand Down Expand Up @@ -142,7 +142,11 @@ EU4::World::World(const CK3::World& sourceWorld, const Configuration& theConfigu
if (sourceWorld.getHRETitle())
{
Log(LogLevel::Info) << "-> Marking HRE Title";
markHRETag(theConfiguration, *sourceWorld.getHRETitle(), sourceWorld.getConversionDate(), theConfiguration.getStartDate());
markHRETag(theConfiguration,
*sourceWorld.getHRETitle(),
sourceWorld.getConversionDate(),
startDateMapper.getStartDate(),
theConfiguration.getStartDateOption());
}
Log(LogLevel::Progress) << "66 %";

Expand Down Expand Up @@ -204,7 +208,7 @@ EU4::World::World(const CK3::World& sourceWorld, const Configuration& theConfigu
Log(LogLevel::Info) << "---> The Dump <---";
modFile.outname = theConfiguration.getOutputName();
modFile.version = converterVersion.getMaxTarget();
output(converterVersion, theConfiguration, sourceWorld);
output(converterVersion, theConfiguration, sourceWorld, startDateMapper.getStartDate());
Log(LogLevel::Info) << "*** Farewell EU4, granting you independence. ***";
}

Expand Down Expand Up @@ -379,7 +383,7 @@ void EU4::World::loadCountriesFromSource(std::istream& theStream, const std::str
}
}

void EU4::World::importCK3Countries(const CK3::World& sourceWorld, Configuration::STARTDATE startDateOption, const bool dynasticNames)
void EU4::World::importCK3Countries(const CK3::World& sourceWorld, Configuration::STARTDATE startDateOption, date startDate, const bool dynasticNames)
{
Log(LogLevel::Info) << "-> Importing CK3 Countries";
// countries holds all tags imported from EU4. We'll now overwrite some and
Expand All @@ -388,32 +392,33 @@ void EU4::World::importCK3Countries(const CK3::World& sourceWorld, Configuration
{
if (title.second->getLevel() != CK3::LEVEL::EMPIRE)
continue;
importCK3Country(title, sourceWorld, startDateOption, dynasticNames);
importCK3Country(title, sourceWorld, startDateOption, startDate, dynasticNames);
}
for (const auto& title: sourceWorld.getIndeps())
{
if (title.second->getLevel() != CK3::LEVEL::KINGDOM)
continue;
importCK3Country(title, sourceWorld, startDateOption, dynasticNames);
importCK3Country(title, sourceWorld, startDateOption, startDate, dynasticNames);
}
for (const auto& title: sourceWorld.getIndeps())
{
if (title.second->getLevel() != CK3::LEVEL::DUCHY)
continue;
importCK3Country(title, sourceWorld, startDateOption, dynasticNames);
importCK3Country(title, sourceWorld, startDateOption, startDate, dynasticNames);
}
for (const auto& title: sourceWorld.getIndeps())
{
if (title.second->getLevel() != CK3::LEVEL::COUNTY)
continue;
importCK3Country(title, sourceWorld, startDateOption, dynasticNames);
importCK3Country(title, sourceWorld, startDateOption, startDate, dynasticNames);
}
Log(LogLevel::Info) << ">> " << countries.size() << " total countries recognized.";
}

void EU4::World::importCK3Country(const std::pair<std::string, std::shared_ptr<CK3::Title>>& title,
const CK3::World& sourceWorld,
Configuration::STARTDATE startDateOption,
date startDate,
bool dynasticNames)
{
// Are we being fed crap?
Expand Down Expand Up @@ -472,6 +477,7 @@ void EU4::World::importCK3Country(const std::pair<std::string, std::shared_ptr<C
localizationMapper,
rulerPersonalitiesMapper,
sourceWorld.getConversionDate(),
startDate,
startDateOption,
dynasticNames);
title.second->loadEU4Tag(std::pair(*tag, countryItr->second));
Expand All @@ -489,6 +495,7 @@ void EU4::World::importCK3Country(const std::pair<std::string, std::shared_ptr<C
localizationMapper,
rulerPersonalitiesMapper,
sourceWorld.getConversionDate(),
startDate,
startDateOption,
dynasticNames);
newCountry->setGeneratedNation();
Expand Down Expand Up @@ -1217,6 +1224,7 @@ void EU4::World::resolvePersonalUnions()
void EU4::World::markHRETag(const Configuration& theConfiguration,
const std::pair<std::string, std::shared_ptr<CK3::Title>>& hreTitle,
const date& conversionDate,
date startDate,
Configuration::STARTDATE startDateOption)
{
if (theConfiguration.getHRE() == Configuration::I_AM_HRE::NONE)
Expand Down Expand Up @@ -1246,6 +1254,7 @@ void EU4::World::markHRETag(const Configuration& theConfiguration,
localizationMapper,
rulerPersonalitiesMapper,
conversionDate,
startDate,
startDateOption,
false);
countries.emplace(actualHRETag, newCountry);
Expand Down
Loading

0 comments on commit fd8d8e8

Please sign in to comment.