// human -> pArea = cityid
// very quick & dirty
bool CvPlayer::splitEmpire(int iAreaId)
{
PROFILE_FUNC();
int iCity = iAreaId;;
if (isHuman())
{
int iLoop;
for (CvCity* pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
if (pLoopCity->getID() == iCity)
iAreaId = pLoopCity->getArea();
}
if (!canSplitEmpire())
{
return false;
}
if (!canSplitArea(iAreaId)&&(!isHuman()))
{
return false;
}
CvArea* pArea = GC.getMapINLINE().getArea(iAreaId);
if (NULL == pArea)
{
return false;
}
PlayerTypes eNewPlayer = getSplitEmpirePlayer(iAreaId);
if (eNewPlayer == NO_PLAYER)
{
return false;
}
bool bPlayerExists = GET_PLAYER(eNewPlayer).isAlive();
FAssert(!bPlayerExists);
if (!bPlayerExists)
{
int iBestValue = -1;
LeaderHeadTypes eBestLeader = NO_LEADER;
CivilizationTypes eBestCiv = NO_CIVILIZATION;
CivLeaderArray aLeaders;
if (getSplitEmpireLeaders(aLeaders))
{
CivLeaderArray::iterator it;
for (it = aLeaders.begin(); it != aLeaders.end(); ++it)
{
int iValue = (1 + GC.getGameINLINE().getSorenRandNum(100, "Choosing Split Personality"));
if (GC.getCivilizationInfo(getCivilizationType()).getDerivativeCiv() == it->first)
{
iValue += 1000;
}
if (iValue > iBestValue)
{
iBestValue = iValue;
eBestLeader = it->second;
eBestCiv = it->first;
}
}
}
if (eBestLeader == NO_LEADER || eBestCiv == NO_CIVILIZATION)
{
return false;
}
CvWString szMessage = gDLL->getText("TXT_KEY_MISC_EMPIRE_SPLIT", getNameKey(), GC.getCivilizationInfo(eBestCiv).getShortDescriptionKey(), GC.getLeaderHeadInfo(eBestLeader).getTextKeyWide());
for (int i = 0; i < MAX_CIV_PLAYERS; ++i)
{
if (GET_PLAYER((PlayerTypes)i).isAlive())
{
if (i == getID() || i == eNewPlayer || GET_TEAM(GET_PLAYER((PlayerTypes)i).getTeam()).isHasMet(GET_PLAYER((PlayerTypes)getID()).getTeam()))
{
gDLL->getInterfaceIFace()->addMessage((PlayerTypes)i, false, GC.getEVENT_MESSAGE_TIME(), szMessage, "AS2D_REVOLTEND", MESSAGE_TYPE_MAJOR_EVENT, ARTFILEMGR.getInterfaceArtInfo("INTERFACE_CITY_BAR_CAPITAL_TEXTURE")->getPath());
}
}
}
GC.getGameINLINE().addReplayMessage(REPLAY_MESSAGE_MAJOR_EVENT, getID(), szMessage, -1, -1, (ColorTypes)GC.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT"));
GC.getGameINLINE().addPlayer(eNewPlayer, eBestLeader, eBestCiv);
GET_PLAYER(eNewPlayer).setParent(getID());
CvTeam& kNewTeam = GET_TEAM(GET_PLAYER(eNewPlayer).getTeam());
for (int i = 0; i < GC.getNumTechInfos(); ++i)
{
kNewTeam.setHasTech((TechTypes)i, GET_TEAM(getTeam()).isHasTech((TechTypes)i), eNewPlayer, false, false);
}
for (int iTeam = 0; iTeam < MAX_TEAMS; ++iTeam)
{
CvTeam& kLoopTeam = GET_TEAM((TeamTypes)iTeam);
if (kLoopTeam.isAlive())
{
kNewTeam.setEspionagePointsAgainstTeam((TeamTypes)iTeam, GET_TEAM(getTeam()).getEspionagePointsAgainstTeam((TeamTypes)iTeam));
kLoopTeam.setEspionagePointsAgainstTeam(GET_PLAYER(eNewPlayer).getTeam(), kLoopTeam.getEspionagePointsAgainstTeam(getTeam()));
}
}
kNewTeam.setEspionagePointsEver(GET_TEAM(getTeam()).getEspionagePointsEver());
GET_TEAM(getTeam()).assignVassal(GET_PLAYER(eNewPlayer).getTeam(), false);
AI_updateBonusValue();
}
std::vector< std::pair<int, int> > aCultures;
for (int iPlot = 0; iPlot < GC.getMapINLINE().numPlotsINLINE(); ++iPlot)
{
CvPlot* pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iPlot);
bool bTranferPlot = false;
if (!bTranferPlot && pLoopPlot->area() == pArea)
{
bTranferPlot = true;
}
if (!bTranferPlot)
{
CvCity* pWorkingCity = pLoopPlot->getWorkingCity();
if (NULL != pWorkingCity && pWorkingCity->getOwnerINLINE() == getID() && pWorkingCity->area() == pArea)
{
bTranferPlot = true;
}
}
if (!bTranferPlot && pLoopPlot->isWater() && pLoopPlot->isAdjacentToArea(pArea))
{
bTranferPlot = true;
}
if (bTranferPlot)
{
int iCulture = pLoopPlot->getCulture(getID());
if (bPlayerExists)
{
iCulture = std::max(iCulture, pLoopPlot->getCulture(eNewPlayer));
}
aCultures.push_back(std::make_pair(iPlot, iCulture));
}
}
int iLoop;
for (CvCity* pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
{
// human only split 1 city
if ((!isHuman()&&(pLoopCity->area() == pArea))||(isHuman()&&(pLoopCity->getID() == iCity)))
{
int iCulture = pLoopCity->getCultureTimes100(getID());
CvPlot* pPlot = pLoopCity->plot();
GET_PLAYER(eNewPlayer).acquireCity(pLoopCity, false, true, false);
if (NULL != pPlot)
{
CvCity* pCity = pPlot->getPlotCity();
if (NULL != pCity)
{
pCity->setCultureTimes100(eNewPlayer, iCulture, false, false);
}
for (int i = 0; i < GC.getDefineINT("COLONY_NUM_FREE_DEFENDERS"); ++i)
{
pCity->initConscriptedUnit();
}
}
}
}
for (uint i = 0; i < aCultures.size(); ++i)
{
CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(aCultures[i].first);
pPlot->setCulture(eNewPlayer, aCultures[i].second, true, false);
if (!isHuman())pPlot->setCulture(getID(), 0, true, false);
for (int iTeam = 0; iTeam < MAX_TEAMS; ++iTeam)
{
if (pPlot->getRevealedOwner((TeamTypes)iTeam, false) == getID())
{
if (!isHuman()) pPlot->setRevealedOwner((TeamTypes)iTeam, eNewPlayer);
}
}
}
GC.getGameINLINE().updatePlotGroups();
return true;
}