Skip to content

Commit

Permalink
Convert succession laws (#153) #minor
Browse files Browse the repository at this point in the history
* Update appveyor.yml

* Remove remnant quote from outVersion

* Create law_map.txt

* lawRegexStr

* Imperator Country laws tests

* SuccessionLawMapper

* Output converted succession laws

* Fix for outputting conflicting succession laws

* Update appveyor.yml

* PR tweaks

* Satisfying CodeFactor
  • Loading branch information
IhateTrains authored Mar 9, 2021
1 parent ed253c7 commit a6895fa
Show file tree
Hide file tree
Showing 23 changed files with 425 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
uses: anothrNick/github-tag-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BUMP: minor
DEFAULT_BUMP: patch
37 changes: 37 additions & 0 deletions ImperatorToCK3/Data_Files/configurables/succession_law_map.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# IMP-CK3 SUCCESSION LAW MAPPINGS #
# link = { imp = [law] ck3 = [law] }
# The CK3 law is output in the title's history
# folder, right after the line defining
# the holder, as succession_laws = { [law] }

# CK3 has default succession laws

# For mappings with multiple ck3 laws, all laws will be written out


# Monarchy

link = { imp = agnatic_succession_law ck3 = male_only_law ck3 = single_heir_succession_law }
link = { imp = cognatic_succession_law ck3 = male_preference_law }
link = { imp = agnatic_seniority_succession_law ck3 = single_heir_dynasty_house }
link = { imp = egyption_succession_law ck3 = equal_law }

# Republic

link = { imp = republican_election_1 ck3 = city_succession_law }
link = { imp = republican_election_2 ck3 = saxon_elective_succession_law }
link = { imp = republican_election_3 ck3 = city_succession_law }
link = { imp = republican_election_4 ck3 = princely_elective_succession_law }

# Rome

link = { imp = leges_genuciae ck3 = city_succession_law }
link = { imp = senatus_consultum_ultimum ck3 = saxon_elective_succession_law }
link = { imp = lex_antonia ck3 = city_succession_law }
link = { imp = princeps_civitatis ck3 = princely_elective_succession_law }

# Tribal

link = { imp = personal_loyalty_law ck3 = high_partition_succession_law }
link = { imp = increased_council_powers ck3 = scandinavian_elective_succession_law }
link = { imp = absolute_authority ck3 = gaelic_elective_succession_law }
10 changes: 10 additions & 0 deletions ImperatorToCK3/ImperatorToCK3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@
<ClCompile Include="Source\Mappers\RegionMapper\ImperatorRegionMapper.cpp" />
<ClCompile Include="Source\Mappers\ReligionMapper\ReligionMapper.cpp" />
<ClCompile Include="Source\Mappers\ReligionMapper\ReligionMapping.cpp" />
<ClCompile Include="Source\Mappers\SuccessionLawMapper\SuccessionLawMapper.cpp" />
<ClCompile Include="Source\Mappers\SuccessionLawMapper\SuccessionLawMapping.cpp" />
<ClCompile Include="Source\Mappers\TagTitleMapper\TagTitleMapper.cpp" />
<ClCompile Include="Source\Mappers\TagTitleMapper\TagTitleMapping.cpp" />
<ClCompile Include="Source\Mappers\TraitMapper\TraitMapper.cpp" />
Expand Down Expand Up @@ -392,6 +394,8 @@
<ClInclude Include="Source\Mappers\RegionMapper\ImperatorRegionMapper.h" />
<ClInclude Include="Source\Mappers\ReligionMapper\ReligionMapper.h" />
<ClInclude Include="Source\Mappers\ReligionMapper\ReligionMapping.h" />
<ClInclude Include="Source\Mappers\SuccessionLawMapper\SuccessionLawMapper.h" />
<ClInclude Include="Source\Mappers\SuccessionLawMapper\SuccessionLawMapping.h" />
<ClInclude Include="Source\Mappers\TagTitleMapper\TagTitleMapper.h" />
<ClInclude Include="Source\Mappers\TagTitleMapper\TagTitleMapping.h" />
<ClInclude Include="Source\Mappers\TraitMapper\TraitMapper.h" />
Expand Down Expand Up @@ -533,6 +537,12 @@
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)configurables</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Data_Files\configurables\succession_law_map.txt">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)configurables</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)configurables</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
18 changes: 18 additions & 0 deletions ImperatorToCK3/ImperatorToCK3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
<Filter Include="CK3\Provinces">
<UniqueIdentifier>{8d84171d-cbd1-49e5-aba5-9b0fc315fab3}</UniqueIdentifier>
</Filter>
<Filter Include="Mappers\SuccessionLawMapper">
<UniqueIdentifier>{7daa7234-4e79-4a3a-85f0-2720e6abb08c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Source\CK3Outputter\CK3WorldOutputter.h">
Expand Down Expand Up @@ -391,6 +394,12 @@
<ClInclude Include="Source\CK3Outputter\outDynasty.h">
<Filter>CK3Outputter</Filter>
</ClInclude>
<ClInclude Include="Source\Mappers\SuccessionLawMapper\SuccessionLawMapper.h">
<Filter>Mappers\SuccessionLawMapper</Filter>
</ClInclude>
<ClInclude Include="Source\Mappers\SuccessionLawMapper\SuccessionLawMapping.h">
<Filter>Mappers\SuccessionLawMapper</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\main.cpp" />
Expand Down Expand Up @@ -665,6 +674,12 @@
<ClCompile Include="Source\Imperator\Provinces\Province.cpp">
<Filter>Imperator\Provinces</Filter>
</ClCompile>
<ClCompile Include="Source\Mappers\SuccessionLawMapper\SuccessionLawMapper.cpp">
<Filter>Mappers\SuccessionLawMapper</Filter>
</ClCompile>
<ClCompile Include="Source\Mappers\SuccessionLawMapper\SuccessionLawMapping.cpp">
<Filter>Mappers\SuccessionLawMapper</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Resources\rakaly.dll">
Expand Down Expand Up @@ -755,5 +770,8 @@
<CopyFileToFolders Include="Data_Files\configurables\title_map.txt">
<Filter>Resources\configurables</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="Data_Files\configurables\succession_law_map.txt">
<Filter>Resources\configurables</Filter>
</CopyFileToFolders>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion ImperatorToCK3/Source/CK3/CK3World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void CK3::World::importImperatorCountries(const Imperator::World& impWorld) {
void CK3::World::importImperatorCountry(const std::pair<unsigned long long, std::shared_ptr<Imperator::Country>>& country) {
// Create a new title
auto newTitle = std::make_shared<Title>();
newTitle->initializeFromTag(country.second, localizationMapper, landedTitles, provinceMapper, coaMapper, tagTitleMapper, governmentMapper);
newTitle->initializeFromTag(country.second, localizationMapper, landedTitles, provinceMapper, coaMapper, tagTitleMapper, governmentMapper, successionLawMapper);

const auto& name = newTitle->getName();
if (auto titleItr = getTitles().find(name); titleItr!=getTitles().end()) {
Expand Down
2 changes: 2 additions & 0 deletions ImperatorToCK3/Source/CK3/CK3World.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Mappers/GovernmentMapper/GovernmentMapper.h"
#include "Mappers/RegionMapper/CK3RegionMapper.h"
#include "Mappers/RegionMapper/ImperatorRegionMapper.h"
#include "Mappers/SuccessionLawMapper/SuccessionLawMapper.h"
#include "Character/CK3Character.h"
#include "Dynasties/Dynasty.h"
#include "Province/CK3Province.h"
Expand Down Expand Up @@ -78,6 +79,7 @@ class World {
mappers::GovernmentMapper governmentMapper;
std::shared_ptr<mappers::CK3RegionMapper> ck3RegionMapper;
std::shared_ptr<mappers::ImperatorRegionMapper> imperatorRegionMapper;
mappers::SuccessionLawMapper successionLawMapper;
TitlesHistory titlesHistory;


Expand Down
26 changes: 18 additions & 8 deletions ImperatorToCK3/Source/CK3/Titles/Title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Mappers/CoaMapper/CoaMapper.h"
#include "Mappers/TagTitleMapper/TagTitleMapper.h"
#include "Mappers/GovernmentMapper/GovernmentMapper.h"
#include "Mappers/SuccessionLawMapper/SuccessionLawMapper.h"
#include "Log.h"
#include "ParserHelpers.h"
#include "CommonRegexes.h"
Expand Down Expand Up @@ -72,8 +73,14 @@ void CK3::Title::registerKeys() {
}


void CK3::Title::initializeFromTag(std::shared_ptr<Imperator::Country> theCountry, mappers::LocalizationMapper& localizationMapper, LandedTitles& landedTitles, mappers::ProvinceMapper& provinceMapper,
mappers::CoaMapper& coaMapper, mappers::TagTitleMapper& tagTitleMapper, mappers::GovernmentMapper& governmentMapper)
void CK3::Title::initializeFromTag(std::shared_ptr<Imperator::Country> theCountry,
mappers::LocalizationMapper& localizationMapper,
LandedTitles& landedTitles,
mappers::ProvinceMapper& provinceMapper,
mappers::CoaMapper& coaMapper,
mappers::TagTitleMapper& tagTitleMapper,
mappers::GovernmentMapper& governmentMapper,
mappers::SuccessionLawMapper& successionLawMapper)
{
importedOrUpdatedFromImperator = true;

Expand Down Expand Up @@ -115,12 +122,15 @@ void CK3::Title::initializeFromTag(std::shared_ptr<Imperator::Country> theCountr
government = governmentMapper.getCK3GovernmentForImperatorGovernment(*imperatorCountry->getGovernment());

// ------------------ determine color
auto colorOpt = imperatorCountry->getColor1();
if (colorOpt)
color1 = *colorOpt;
colorOpt = imperatorCountry->getColor2();
if (colorOpt)
color2 = *colorOpt;
const auto& colorOpt1 = imperatorCountry->getColor1();
if (colorOpt1)
color1 = *colorOpt1;
const auto& colorOpt2 = imperatorCountry->getColor2();
if (colorOpt2)
color2 = *colorOpt2;

// determine successions laws
successionLaws = successionLawMapper.getCK3LawsForImperatorLaws(imperatorCountry->getLaws());

// ------------------ determine CoA
coa = coaMapper.getCoaForFlagName(imperatorCountry->getFlag());
Expand Down
7 changes: 6 additions & 1 deletion ImperatorToCK3/Source/CK3/Titles/Title.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TagTitleMapper;
class CoaMapper;
class ProvinceMapper;
class GovernmentMapper;
class SuccessionLawMapper;
} // namespace mappers

namespace CK3 {
Expand All @@ -43,7 +44,9 @@ class Title: commonItems::parser, public std::enable_shared_from_this<Title>
mappers::ProvinceMapper& provinceMapper,
mappers::CoaMapper& coaMapper,
mappers::TagTitleMapper& tagTitleMapper,
mappers::GovernmentMapper& governmentMapper);
mappers::GovernmentMapper& governmentMapper,
mappers::SuccessionLawMapper& successionLawMapper
);
void updateFromTitle(const std::shared_ptr<Title>& otherTitle);
void loadTitles(std::istream& theStream);

Expand All @@ -55,6 +58,7 @@ class Title: commonItems::parser, public std::enable_shared_from_this<Title>
void setDeFactoLiege(const std::shared_ptr<Title>& liegeTitle);

[[nodiscard]] const auto& getName() const { return titleName; }
[[nodiscard]] const auto& getSuccessionLaws() const { return successionLaws; }
[[nodiscard]] auto isImportedOrUpdatedFromImperator() const { return importedOrUpdatedFromImperator; }

[[nodiscard]] const auto& getDeJureLiege() const { return deJureLiege; }
Expand Down Expand Up @@ -98,6 +102,7 @@ class Title: commonItems::parser, public std::enable_shared_from_this<Title>
void trySetAdjectiveLoc(mappers::LocalizationMapper& localizationMapper);

std::string titleName; // e.g. d_latium
std::set<std::string> successionLaws;

bool importedOrUpdatedFromImperator = false;
std::optional<commonItems::Color> color1;
Expand Down
11 changes: 10 additions & 1 deletion ImperatorToCK3/Source/CK3Outputter/outTitles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ void CK3::outputTitleHistory(const std::shared_ptr<Title>& title, std::ofstream&

if (title->government)
outputStream << "\t\tgovernment = " << *title->government << "\n";


const auto& succLaws = title->getSuccessionLaws();
if (!succLaws.empty()) {
outputStream << "\t\tsuccession_laws = {\n";
for (const auto& law : succLaws) {
outputStream << "\t\t\t" << law << "\n";
}
outputStream << "\t\t}\n";
}

outputStream << "\t}\n";
}
outputStream << "}\n";
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Source/CK3Outputter/outVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ std::ostream& mappers::operator<<(std::ostream& output, const VersionParser& ver

output << "\n\n";
output << "************ -= The Paradox Converters Team =- ********************\n";
output << "* Converter build based on commit " << commitID << "\"\n";
output << "* Converter build based on commit " << commitID << "\n";
output << "* " << versionParser.descriptionLine << "\n";
output << "* Built on " << __TIMESTAMP__ << "\n";
output << "*********** + Imperator: Rome To Crusader Kings III + **************\n";
Expand Down
9 changes: 9 additions & 0 deletions ImperatorToCK3/Source/Imperator/Countries/Country.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@



const std::set<std::string>& Imperator::Country::getLaws() const {
if (governmentType == GovernmentType::monarchy)
return monarchyLaws;
else if (governmentType == GovernmentType::republic)
return republicLaws;
else // governmentType == GovernmentType::tribal
return tribalLaws;
}

Imperator::countryRankEnum Imperator::Country::getCountryRank() const {
if (provinceCount == 0) return countryRankEnum::migrantHorde;
if (provinceCount == 1) return countryRankEnum::cityState;
Expand Down
97 changes: 52 additions & 45 deletions ImperatorToCK3/Source/Imperator/Countries/Country.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,60 @@ enum class countryRankEnum { migrantHorde, cityState, localPower, regionalPower,
class Family;
class Province;
class Country {
public:
class Factory;
Country() = default;

[[nodiscard]] auto getID() const { return ID; }
[[nodiscard]] auto getMonarch() const { return monarch; }
[[nodiscard]] const std::string& getTag() const { return tag; }
[[nodiscard]] const auto& getName() const { return name; }
[[nodiscard]] const auto& getFlag() const { return flag; }
[[nodiscard]] const auto& getCountryType() const { return countryType; }
[[nodiscard]] const auto& getCapital() const { return capital; }
[[nodiscard]] const auto& getGovernment() const { return government; }
[[nodiscard]] const auto& getCurrencies() const { return currencies; }
[[nodiscard]] const auto& getColor1() const { return color1; }
[[nodiscard]] const auto& getColor2() const { return color2; }
[[nodiscard]] const auto& getColor3() const { return color3; }
[[nodiscard]] const auto& getFamilies() const { return families; }
[[nodiscard]] const auto& getCK3Title() const { return ck3Title; }

[[nodiscard]] countryRankEnum getCountryRank() const;

void setFamilies(const std::map<unsigned long long, std::shared_ptr<Family>>& newFamilies) { families = newFamilies; }

void registerProvince(const std::shared_ptr<Province>& province) { provinces.insert(province); ++provinceCount; }
void setCK3Title(const std::shared_ptr<CK3::Title>& theTitle) { ck3Title = theTitle; }

private:
uint64_t ID = 0;
std::optional<unsigned long long> monarch; // >=0 are valid
std::string tag;
std::string name;
std::string flag;
countryTypeEnum countryType = countryTypeEnum::real;
std::optional<unsigned long long> capital;
std::optional<std::string> government;
public:
class Factory;
Country() = default;

enum class GovernmentType { monarchy, republic, tribal };

[[nodiscard]] auto getID() const { return ID; }
[[nodiscard]] auto getMonarch() const { return monarch; }
[[nodiscard]] const std::string& getTag() const { return tag; }
[[nodiscard]] const auto& getName() const { return name; }
[[nodiscard]] const auto& getFlag() const { return flag; }
[[nodiscard]] const auto& getCountryType() const { return countryType; }
[[nodiscard]] const auto& getCapital() const { return capital; }
[[nodiscard]] const auto& getGovernment() const { return government; }
[[nodiscard]] const std::set<std::string>& getLaws() const;
[[nodiscard]] const auto& getCurrencies() const { return currencies; }
[[nodiscard]] const auto& getColor1() const { return color1; }
[[nodiscard]] const auto& getColor2() const { return color2; }
[[nodiscard]] const auto& getColor3() const { return color3; }
[[nodiscard]] const auto& getFamilies() const { return families; }
[[nodiscard]] const auto& getCK3Title() const { return ck3Title; }

[[nodiscard]] countryRankEnum getCountryRank() const;

void setFamilies(const std::map<unsigned long long, std::shared_ptr<Family>>& newFamilies) { families = newFamilies; }

void registerProvince(const std::shared_ptr<Province>& province) { provinces.insert(province); ++provinceCount; }
void setCK3Title(const std::shared_ptr<CK3::Title>& theTitle) { ck3Title = theTitle; }

private:
uint64_t ID = 0;
std::optional<unsigned long long> monarch; // >=0 are valid
std::string tag;
std::string name;
std::string flag;
countryTypeEnum countryType = countryTypeEnum::real;
std::optional<unsigned long long> capital;
std::optional<std::string> government;
GovernmentType governmentType = GovernmentType::monarchy;
std::set<std::string> monarchyLaws;
std::set<std::string> republicLaws;
std::set<std::string> tribalLaws;

std::optional<commonItems::Color> color1;
std::optional<commonItems::Color> color2;
std::optional<commonItems::Color> color3;
CurrenciesStruct currencies;

std::map<unsigned long long, std::shared_ptr<Family>> families;

std::optional<commonItems::Color> color1;
std::optional<commonItems::Color> color2;
std::optional<commonItems::Color> color3;
CurrenciesStruct currencies;
std::set<std::shared_ptr<Province>> provinces;
unsigned int provinceCount = 0; // used to determine country rank

std::map<unsigned long long, std::shared_ptr<Family>> families;

std::set<std::shared_ptr<Province>> provinces;
unsigned int provinceCount = 0; // used to determine country rank

std::shared_ptr<CK3::Title> ck3Title;
std::shared_ptr<CK3::Title> ck3Title;
};

} // namespace Imperator
Expand Down
Loading

0 comments on commit a6895fa

Please sign in to comment.