How to make AI ALWAYS raze a city?

vmsbass

Chieftain
Joined
Apr 17, 2008
Messages
18
I have seen many many posts asking how to stop the AI from razing cities, but I have not seen anything about how to always make them raze a captured city. I know about the <iRazeCityProb> code in the LeaderHeadInfos, but it seems that even with this set to 100, they still will not always raze a city. I am also aware that certain conditions trump the <iRazeCityProb>, such there being Great Wonders in the city. So I guess what I need to know is:

where can I find the coding that controls these conditions?

Thanks :D
 
I found this in the CvPlayerAI.ccp file of the SDK:

void CvPlayerAI::AI_conquerCity(CvCity* pCity)
{
CvCity* pNearestCity;
bool bRaze;

if (canRaze(pCity))
{
if (GC.getGameINLINE().getElapsedGameTurns() > 20)
{
if (getNumCities() > 4)
{
if (!(pCity->isHolyCity()) && !(pCity->hasActiveWorldWonder()))
{
bRaze = true;

if (!bRaze)
{
if (pCity->getPreviousOwner() != BARBARIAN_PLAYER)
{
pNearestCity = GC.getMapINLINE().findCity(pCity->getX_INLINE(), pCity->getY_INLINE(), NO_PLAYER, getTeam(), true, false, NO_TEAM, NO_DIRECTION, pCity);

if (pNearestCity == NULL)
{
if (pCity->getPreviousOwner() != NO_PLAYER)
{
if (GET_TEAM(GET_PLAYER(pCity->getPreviousOwner()).getTeam()).countNumCitiesByArea(pCity->area()) > 3)
{
bRaze = true;
}
}
}
else
{
if (plotDistance(pCity->getX_INLINE(), pCity->getY_INLINE(), pNearestCity->getX_INLINE(), pNearestCity->getY_INLINE()) > 9)
{
bRaze = true;
}
}
}
}

if (!bRaze)
{
if (pCity->area()->getCitiesPerPlayer(getID()) > 0)
{
if (AI_isFinancialTrouble())
{
if (pCity->getPopulation() < 4)
{
bRaze = true;
}
}
}
}

if (!bRaze)
{
if (pCity->area()->getCitiesPerPlayer(getID()) > 0)
{
if (pCity->getPreviousOwner() != BARBARIAN_PLAYER)
{
if (GC.getGameINLINE().getSorenRandNum(100, "AI Raze City") < GC.getLeaderHeadInfo(getPersonalityType()).getRazeCityProb())
{
bRaze = true;
}
}
}
}

if (bRaze)
{
pCity->doTask(TASK_RAZE);
}
}
}
}
}
}

The bold 'true' I changed from false, but it didn't matter. Any idea if I am in the right area and if so what exactly I need to do?
 
iRazeCityProb is just a %, so going over 100 should not matter. Even so, I tried it and it didnt work.

The code that I printed seems to be pointing out conditions that need to be met for the AI to indeed raze a city. If you look in there, you will note when the <iRazeCityProb> factors in (seems to only matter when the city in question belonged to barbarians).

I am only guessing here, though. This is my first attempt at trying to understand this type of coding. I am sure if I knoew more about C++ I could figure it out :cry:
 
If anyone knows how to adjust the decrease in population that results from capturing a city, that should be all it takes. Normally, capturing a city decreases its population by 1. If that could be increased to some ridiculous number (e.g. 50), then any city would automatically be destroyed after capture.

(although this might ruin the Enhanced Tech Conquest mod I have running, which gives the victor tech advances for capturing a city ... but it only works if the city has more than 1 population, since capture automatically brings the population to 0. So I fear even if I found out how to increase the populations loss number, I personally wouldn't be satisfied)
 
My problem was an incorrect use of SDK modding. So, now that I got the CodeBlocks SDK program working, the following modification to the original code does the trick:

void CvPlayerAI::AI_conquerCity(CvCity* pCity)
{
CvCity* pNearestCity;
bool bRaze;

if (canRaze(pCity))
{




bRaze = true;

if (!bRaze)
{
if (pCity->getPreviousOwner() != BARBARIAN_PLAYER)
{
pNearestCity = GC.getMapINLINE().findCity(pCity->getX_INLINE(), pCity->getY_INLINE(), NO_PLAYER, getTeam(), true, false, NO_TEAM, NO_DIRECTION, pCity);

if (pNearestCity == NULL)
{
if (pCity->getPreviousOwner() != NO_PLAYER)
{
if (GET_TEAM(GET_PLAYER(pCity->getPreviousOwner()).getTeam()).countNumCitiesByArea(pCity->area()) > 3)
{
bRaze = true;
}
}
}
else
{
if (plotDistance(pCity->getX_INLINE(), pCity->getY_INLINE(), pNearestCity->getX_INLINE(), pNearestCity->getY_INLINE()) > 9)
{
bRaze = true;
}
}
}
}





if (bRaze)
{
pCity->doTask(TASK_RAZE);
}



}
}
 
For anyone looking to do the same, you may receive a syntax error if you just cut and paste the code I gave, since the html of the forums 'flattens' the code, whereas in the SDK it is 'layered'. Just manually cut out all that I did to achieve the same results.
 
Back
Top Bottom