From fbbde469f3d7f8a4fe6548b367644f0cf8a11d8b Mon Sep 17 00:00:00 2001 From: idhrendur Date: Sat, 19 May 2012 13:54:26 -0700 Subject: [PATCH] Restrict gavelkind heirs to valid children --- Data Files/Changelog.txt | 3 ++- Source/CK2World/CK2Character.cpp | 41 +++++++++++++++++++------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Data Files/Changelog.txt b/Data Files/Changelog.txt index 18418e0c5..1bce40065 100644 --- a/Data Files/Changelog.txt +++ b/Data Files/Changelog.txt @@ -94,4 +94,5 @@ Revision Log Message 92 Lots of advisors 93 Remove option for advisors from configuration file 94 Improved variety of advisors -95 Initial gavelkind implementation \ No newline at end of file +95 Initial gavelkind implementation +96 Restrict gavelkind heirs to valid children \ No newline at end of file diff --git a/Source/CK2World/CK2Character.cpp b/Source/CK2World/CK2Character.cpp index e242ecd4e..99c8fc6cd 100644 --- a/Source/CK2World/CK2Character.cpp +++ b/Source/CK2World/CK2Character.cpp @@ -467,7 +467,16 @@ CK2Character* CK2Character::getPrimogenitureHeir(string genderLaw) void CK2Character::setGavelkindHeirs(string genderLaw) { - if (children.size() <= 0) + vector heirs; + for (list::iterator i = children.begin(); i != children.end(); i++) + { + if ( !(*i)->isBastard() && !(*i)->isDead() && !(*i)->isFemale()) + { + heirs.push_back(*i); + } + } + + if (heirs.size() <= 0) { CK2Character* heir = getPrimogenitureHeir(genderLaw); for (vector::iterator i = titles.begin(); i != titles.end(); i++) @@ -514,60 +523,60 @@ void CK2Character::setGavelkindHeirs(string genderLaw) } } - list::iterator heirItr = children.begin(); + vector::iterator heirItr = heirs.begin(); for (vector::iterator i = empireTitles.begin(); i != empireTitles.end(); i++) { - if (heirItr == children.end()) + if (heirItr == heirs.end()) { - heirItr = children.begin(); + heirItr = heirs.begin(); } (*i)->setHeir(*heirItr); heirItr++; } - heirItr = children.begin(); + heirItr = heirs.begin(); for (vector::iterator i = kingdomTitles.begin(); i != kingdomTitles.end(); i++) { - if (heirItr == children.end()) + if (heirItr == heirs.end()) { - heirItr = children.begin(); + heirItr = heirs.begin(); } (*i)->setHeir(*heirItr); heirItr++; } - heirItr = children.begin(); + heirItr = heirs.begin(); for (vector::iterator i = duchyTitles.begin(); i != duchyTitles.end(); i++) { - if (heirItr == children.end()) + if (heirItr == heirs.end()) { - heirItr = children.begin(); + heirItr = heirs.begin(); } (*i)->setHeir(*heirItr); heirItr++; } - heirItr = children.begin(); + heirItr = heirs.begin(); for (vector::iterator i = countyTitles.begin(); i != countyTitles.end(); i++) { - if (heirItr == children.end()) + if (heirItr == heirs.end()) { - heirItr = children.begin(); + heirItr = heirs.begin(); } (*i)->setHeir(*heirItr); heirItr++; } - heirItr = children.begin(); + heirItr = heirs.begin(); for (vector::iterator i = baronyTitles.begin(); i != baronyTitles.end(); i++) { - if (heirItr == children.end()) + if (heirItr == heirs.end()) { - heirItr = children.begin(); + heirItr = heirs.begin(); } (*i)->setHeir(*heirItr);