The problem is in CvCity.cpp...
They avoid dividing by zero by returning iFoodLeft early if foodDifference = 0.
If we're to avoid sdk changes, I would make this suggestion for Civ4lerts.py:
I think this should work.
EDIT... As I was thinking about this, I wondered whether this function correctly shows a city will grow into unhappiness in this scenario:
City has enough food stored from its previous growth (or pop reduction) such that it doesn't need to collect any food this turn and it will grow. e.g. City has 80/60 food stored and is losing food at a rate of -1 per turn. I believe this city would not show up with an alert.
Code:
int CvCity::getFoodTurnsLeft() const
{
int iFoodLeft;
int iTurnsLeft;
iFoodLeft = (growthThreshold() - getFood());
if (foodDifference() <= 0)
{
return iFoodLeft;
}
iTurnsLeft = (iFoodLeft / foodDifference());
if ((iTurnsLeft * foodDifference()) < iFoodLeft)
{
iTurnsLeft++;
}
return std::max(1, iTurnsLeft);
}
They avoid dividing by zero by returning iFoodLeft early if foodDifference = 0.
If we're to avoid sdk changes, I would make this suggestion for Civ4lerts.py:
Code:
class CityHappiness(AbstractCityTestAlert):
"""
Displays an event when a city goes from happy to angry or vice versa.
Test: True if the city is unhappy.
"""
def __init__(self, eventManager):
AbstractCityTestAlert.__init__(self, eventManager)
def init(self):
AbstractCityAlert.init(self)
self.kiTempHappy = gc.getDefineINT("TEMP_HAPPY")
def _passesTest(self, city):
return city.angryPopulation(0) > 0
def _willPassTest(self, city):
if (city.getFoodTurnsLeft() == 1 and not city.isFoodProduction() and not city.AI_isEmphasize(5) [B][COLOR="Blue"]and city.foodDifference() > 0[/COLOR][/B]):
iExtra = 1
elif (city.getFoodTurnsLeft() == -1):
iExtra = -1
else:
iExtra = 0
iHappy = city.happyLevel()
I think this should work.
EDIT... As I was thinking about this, I wondered whether this function correctly shows a city will grow into unhappiness in this scenario:
City has enough food stored from its previous growth (or pop reduction) such that it doesn't need to collect any food this turn and it will grow. e.g. City has 80/60 food stored and is losing food at a rate of -1 per turn. I believe this city would not show up with an alert.