Financial advisor maintenance bug (and fix)

karadoc

AI programmer
Joined
Oct 3, 2005
Messages
1,568
Location
Australia
In this thread I identified a weirdness in the maintenance numbers displayed in the financial advisor. It turned out to be a bug in the way those maintenance total are calculated. The bug does not affect the gameplay — the problem is just that the breakdown of the maintenance costs displayed in the financial advisor are wrong.

For convenience I'll just copy the last part of that thread here:
I've managed to fix the bug. Here's how I did it:

In CvGameTextMgr.cpp, CvGameTextMgr::buildFinanceCityMaintString, it calculates the maintenance costs for distance, colonial, and corporations, on a city by city basis and adds them all up. Then, to get the number of cities maintenance, it just subtracts all the other types of maintenance from the total maintenance (which is known by some other means). The problem is that when it is adding up all the maintenance from each city it does not take into account that some cities are completely exempt from maintenance.

So here's my fix:
Code:
/* Old BTS code
iDistanceMaint += (pLoopCity->calculateDistanceMaintenanceTimes100() * std::max(0, (pLoopCity->getMaintenanceModifier() + 100))) / 100;
iColonyMaint += (pLoopCity->calculateColonyMaintenanceTimes100() * std::max(0, (pLoopCity->getMaintenanceModifier() + 100))) / 100;
iCorporationMaint += (pLoopCity->calculateCorporationMaintenanceTimes100() * std::max(0, (pLoopCity->getMaintenanceModifier() + 100))) / 100;
*/
if (!pLoopCity->isDisorder() && !pLoopCity->isWeLoveTheKingDay() && (pLoopCity->getPopulation() > 0))
{
	iDistanceMaint += (pLoopCity->calculateDistanceMaintenanceTimes100() * std::max(0, (pLoopCity->getMaintenanceModifier() + 100))) / 100;
	iColonyMaint += (pLoopCity->calculateColonyMaintenanceTimes100() * std::max(0, (pLoopCity->getMaintenanceModifier() + 100))) / 100;
	iCorporationMaint += (pLoopCity->calculateCorporationMaintenanceTimes100() * std::max(0, (pLoopCity->getMaintenanceModifier() + 100))) / 100;
}
I copied the conditions of that if statement from the function which is used to calculate the total city maintenance.

An alternate fix would be to just calculate the number of cities maintenance in the same way as all the others, but that would probably be slightly less efficient.
 
Top Bottom