コード例 #1
0
void CK2Title::determineHeir(map<int, std::shared_ptr<CK2Character>>& characters)
{
	if (holder != NULL)
	{
		if (successionLaw == "primogeniture")
		{
			CK2Character* tempHolder = holder;
			do
			{
				heir = tempHolder->getPrimogenitureHeir(genderLaw, holder);
				tempHolder = tempHolder->getFather();
				if (tempHolder == NULL)
				{
					break;
				}
			} while (heir == NULL);
		}
		else if (successionLaw == "ultimogeniture")
		{
			CK2Character* tempHolder = holder;
			do
			{
				heir = tempHolder->getUltimogenitureHeir(genderLaw, holder);
				tempHolder = tempHolder->getFather();
				if (tempHolder == NULL)
				{
					break;
				}
			} while (heir == NULL);
		}
		else if (successionLaw == "gavelkind")
		{
			if(heir == NULL) // if the heir is not null, we've already set this
			{
				holder->setGavelkindHeirs(genderLaw);
			}
		}
		else if (successionLaw == "seniority")
		{
			heir = holder->getDynasty()->getSenoirityHeir(genderLaw);
		}
		else if ( (successionLaw == "feudal_elective") || (successionLaw == "tanistry") )
		{
			heir = getElectiveHeir(characters);
		}
		else if (successionLaw == "turkish_succession")
		{
			heir = getTurkishSuccessionHeir();
		}
	}
}
コード例 #2
0
CK2Character* CK2Title::getTurkishSuccessionHeir()
{
	vector<CK2Character*> potentialHeirs;
	potentialHeirs.clear();
	CK2Character* tempHolder = holder;
	do
	{
		potentialHeirs = tempHolder->getPotentialOpenHeirs(genderLaw, holder);
		tempHolder = tempHolder->getFather();
		if (tempHolder == NULL)
		{
			break;
		}
	} while (potentialHeirs.size() == 0);

	int largestDemesne = 0;
	for (vector<CK2Character*>::iterator i = potentialHeirs.begin(); i != potentialHeirs.end(); i++)
	{
		vector<CK2Title*> titles = (*i)->getTitles();
		int demesne = 0;
		for (vector<CK2Title*>::iterator j = titles.begin(); j != titles.end(); j++)
		{
			if ( (*j)->getTitleString().substr(0, 2) == "k_" )
			{
				demesne++;
			}
		}
		if (demesne > largestDemesne)
		{
			heir = *i;
			largestDemesne = demesne;
		}
	}

	if (heir == NULL)
	{
		for (vector<CK2Character*>::iterator i = potentialHeirs.begin(); i != potentialHeirs.end(); i++)
		{
			vector<CK2Title*> titles = (*i)->getTitles();
			int demesne = 0;
			for (vector<CK2Title*>::iterator j = titles.begin(); j != titles.end(); j++)
			{
				if ( (*j)->getTitleString().substr(0, 2) == "d_" )
				{
					demesne++;
				}
			}
			if (demesne > largestDemesne)
			{
				heir = *i;
				largestDemesne = demesne;
			}
		}
	}

	if (heir == NULL)
	{
		for (vector<CK2Character*>::iterator i = potentialHeirs.begin(); i != potentialHeirs.end(); i++)
		{
			vector<CK2Title*> titles = (*i)->getTitles();
			int demesne = 0;
			for (vector<CK2Title*>::iterator j = titles.begin(); j != titles.end(); j++)
			{
				if ( (*j)->getTitleString().substr(0, 2) == "c_" )
				{
					demesne++;
				}
			}
			if (demesne > largestDemesne)
			{
				heir = *i;
				largestDemesne = demesne;
			}
		}
	}

	if (heir == NULL)
	{
		for (vector<CK2Character*>::iterator i = potentialHeirs.begin(); i != potentialHeirs.end(); i++)
		{
			vector<CK2Title*> titles = (*i)->getTitles();
			int demesne = 0;
			for (vector<CK2Title*>::iterator j = titles.begin(); j != titles.end(); j++)
			{
				if ( (*j)->getTitleString().substr(0, 2) == "b_" )
				{
					demesne++;
				}
			}
			if (demesne > largestDemesne)
			{
				heir = *i;
				largestDemesne = demesne;
			}
		}
	}

	if ( (heir == NULL) && (potentialHeirs.size() > 0) )
	{
		heir = potentialHeirs[0];
	}

	return heir;
}
コード例 #3
0
void CK2Character::setGavelkindHeirs(string genderLaw)
{
	vector<CK2Character*> heirs;
	CK2Character* tempHolder = this;
	do
	{
			heirs = tempHolder->getGavelkindHeirs(genderLaw);
			tempHolder = tempHolder->getFather();
			if (tempHolder == NULL)
			{
				break;
			}
	} while (heirs.size() <= 0);
	if (heirs.size() <= 0)
	{
		return;
	}

	vector<CK2Title*>	empireTitles;
	vector<CK2Title*>	kingdomTitles;
	vector<CK2Title*>	duchyTitles;
	vector<CK2Title*>	countyTitles;
	vector<CK2Title*>	baronyTitles;
	for (vector<CK2Title*>::iterator i = titles.begin(); i != titles.end(); i++)
	{
		if ( (*i)->getSuccessionLaw() == "gavelkind")
		{
			string titleString = (*i)->getTitleString();
			if ( titleString.substr(0, 2) == "e_")
			{
				empireTitles.push_back(*i);
			}
			else if ( titleString.substr(0, 2) == "k_")
			{
				kingdomTitles.push_back(*i);
			}
			else if ( titleString.substr(0, 2) == "d_")
			{
				duchyTitles.push_back(*i);
			}
			else if ( titleString.substr(0, 2) == "c_")
			{
				countyTitles.push_back(*i);
			}
			else if ( titleString.substr(0, 2) == "b_")
			{
				baronyTitles.push_back(*i);
			}
		}
	}

	vector<CK2Character*>::iterator heirItr = heirs.begin();
	for (vector<CK2Title*>::iterator i = empireTitles.begin(); i != empireTitles.end(); i++)
	{
		if (heirItr == heirs.end())
		{
			heirItr = heirs.begin();
		}

		(*i)->setHeir(*heirItr);
		heirItr++;
	}

	heirItr = heirs.begin();
	for (vector<CK2Title*>::iterator i = kingdomTitles.begin(); i != kingdomTitles.end(); i++)
	{
		if (heirItr == heirs.end())
		{
			heirItr = heirs.begin();
		}

		(*i)->setHeir(*heirItr);
		heirItr++;
	}

	heirItr = heirs.begin();
	for (vector<CK2Title*>::iterator i = duchyTitles.begin(); i != duchyTitles.end(); i++)
	{
		if (heirItr == heirs.end())
		{
			heirItr = heirs.begin();
		}

		(*i)->setHeir(*heirItr);
		heirItr++;
	}

	heirItr = heirs.begin();
	for (vector<CK2Title*>::iterator i = countyTitles.begin(); i != countyTitles.end(); i++)
	{
		if (heirItr == heirs.end())
		{
			heirItr = heirs.begin();
		}

		(*i)->setHeir(*heirItr);
		heirItr++;
	}

	heirItr = heirs.begin();
	for (vector<CK2Title*>::iterator i = baronyTitles.begin(); i != baronyTitles.end(); i++)
	{
		if (heirItr == heirs.end())
		{
			heirItr = heirs.begin();
		}

		(*i)->setHeir(*heirItr);
		heirItr++;
	}
}