Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Commit

Permalink
Restrict gavelkind heirs to valid children
Browse files Browse the repository at this point in the history
  • Loading branch information
Idhrendur committed May 19, 2012
1 parent f706592 commit fbbde46
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Data Files/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
95 Initial gavelkind implementation
96 Restrict gavelkind heirs to valid children
41 changes: 25 additions & 16 deletions Source/CK2World/CK2Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,16 @@ CK2Character* CK2Character::getPrimogenitureHeir(string genderLaw)

void CK2Character::setGavelkindHeirs(string genderLaw)
{
if (children.size() <= 0)
vector<CK2Character*> heirs;
for (list<CK2Character*>::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<CK2Title*>::iterator i = titles.begin(); i != titles.end(); i++)
Expand Down Expand Up @@ -514,60 +523,60 @@ void CK2Character::setGavelkindHeirs(string genderLaw)
}
}

list<CK2Character*>::iterator heirItr = children.begin();
vector<CK2Character*>::iterator heirItr = heirs.begin();
for (vector<CK2Title*>::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<CK2Title*>::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<CK2Title*>::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<CK2Title*>::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<CK2Title*>::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);
Expand Down

0 comments on commit fbbde46

Please sign in to comment.