# The Curious Cat - City Upkeep Explained

Discussion in 'Civ4 Strategy Articles' started by Gato Loco, Nov 7, 2005.

1. ### moyangChieftain

Joined:
Mar 29, 2008
Messages:
50
Location:
Korea
Vassal's city counts toward your city numbers.

2. ### spaghettiChieftain

Joined:
Oct 21, 2006
Messages:
21
Location:
Germany-Hanover
I tried to use the formula eg577 posted here. I cannot confirm the formula. Maybe one of you can help me what I'm doing wrong.
First I'm using BTS 3.19.
Game Settings are: Emporer, Large Map, Pop=17, courthouse = Yes, Distance to Palace=4

I verified modifiers for Worldsize and handicap because it could be that those ones used in this post are not matching to BTS 3.19, but I found they were still matching.

For the city given above the City Screen tells me Distance Cost = 2.30

When I do the math using the formula eg577 provided:
DistanceMaint =
[ ([25*Distance*(Pop+7)/10] * Building_m * WorldSize_m * Handicap_m) / DistanceScale ]
my result is 2.42.

Parameters I used: Building_M=0.5; Distance=4; Handicap_m=0.95; WorldSize_m=0.9; DistanceScale=26+16=42
Expressions I calculated:
A. 25 * 4 * (17+7) / 10) = 240
B. 240 * 0.5 = 120
C. 120 * 0.9 = 108
D. 108 * 0.95 = 102.6 ( I rounded that value down to 102)
E. 102/42 = 2.42 ( City Screen says 2.30)

Can anyone explain what I'm doing wrong?
(Find the attached city screen)

File size:
474.7 KB
Views:
693
3. ### spaghettiChieftain

Joined:
Oct 21, 2006
Messages:
21
Location:
Germany-Hanover
... I forgot to mention:

In the City Screen shown in the post before this post you can see the capital city (Palace) 4 fields (8-8-8-8) away. Distance = 4.

4. ### GhpstageDeity

Joined:
Jan 15, 2009
Messages:
2,944
Location:
Bristol, England
I'm not sure what all the calcs you did mean, but do they take account of the presence of your corporation? They make maintenance skyrocket, even in the capital.

EDIT - The article hasn't been updated since 2006, before BTS was released so theres your problem, it doesn't account for corp maintenance.

5. ### spaghettiChieftain

Joined:
Oct 21, 2006
Messages:
21
Location:
Germany-Hanover
As you see in the screenshot cost for corporation are shown separately.
It is clear that total city maintenance is built from:

Difference Maintenance + Number of City Maintenance + Corporation Costs

But I'm interested in "Difference Maintenance" which is independent from Corporation Costs.

6. ### spaghettiChieftain

Joined:
Oct 21, 2006
Messages:
21
Location:
Germany-Hanover
It seems that the formula to calculate Difference City Maintenance has changed in BTS 3.19.

I found following Python code but I cannot translate it into a common formula. Is here anyone who can translate following code into a formula as it was provided by eg577 for old version?

int CvCity::calculateDistanceMaintenanceTimes100() const
{
CvCity* pLoopCity;
int iWorstCityMaintenance;
int iBestCapitalMaintenance;
int iTempMaintenance;
int iLoop;

iWorstCityMaintenance = 0;
iBestCapitalMaintenance = MAX_INT;

for (pLoopCity = GET_PLAYER(getOwnerINLINE()).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(getOwnerINLINE()).nextCity(&iLoop))
{
iTempMaintenance = 100 * (GC.getDefineINT("MAX_DISTANCE_CITY_MAINTENANCE") * plotDistance(getX_INLINE(), getY_INLINE(), pLoopCity->getX_INLINE(), pLoopCity->getY_INLINE()));

iTempMaintenance *= (getPopulation() + 7);
iTempMaintenance /= 10;

iTempMaintenance *= std::max(0, (GET_PLAYER(getOwnerINLINE()).getDistanceMaintenanceModifier() + 100));
iTempMaintenance /= 100;

iTempMaintenance *= GC.getWorldInfo(GC.getMapINLINE().getWorldSize()).getDistanceMaintenancePercent();
iTempMaintenance /= 100;

iTempMaintenance *= GC.getHandicapInfo(getHandicapType()).getDistanceMaintenancePercent();
iTempMaintenance /= 100;

iTempMaintenance /= GC.getMapINLINE().maxPlotDistance();

iWorstCityMaintenance = std::max(iWorstCityMaintenance, iTempMaintenance);

if (pLoopCity->isGovernmentCenter())
{
iBestCapitalMaintenance = std::min(iBestCapitalMaintenance, iTempMaintenance);
}
}

iTempMaintenance = std::min(iWorstCityMaintenance, iBestCapitalMaintenance);
FAssert(iTempMaintenance >= 0);

return iTempMaintenance;

7. ### spaghettiChieftain

Joined:
Oct 21, 2006
Messages:
21
Location:
Germany-Hanover
After spending the weekend with Python and a test game I found a formula which is providing the Distance Maintenance as shown in the City Screen.

There are two errors in the formula provided by eg577 earlier in this thread:
First, there is no building_M (Building Modifier) for Distance Maintenance. A courthouse has no influence on Distance Maintenance.
Second, MaxPlotDistance (eg577 was calling it DistanceScale) is not MapHeight + MapWidth.

Here my Formula for Distance Maintenance:

=(100 x (MaxDistanceCityMaint x Distance) x (CityPop + 7) / 10 x (DistanceModifier + 100) / 100 x DistanceMaintPercent/100 x HandicapPercent/100) / MaxPlotDistance

With:
MaxDistanceCityMaint a constant =25
Distance: Distance of City to Palace (or Forbidden Palace, Versailles)
CityPop: Population of City
DistanceModifier: Is always 0 except if civic is State property. Then it is -100 and CityMaint gets 0
DistanceMaintPercent: Depending from Mapsize. For Standard = 80
HandicapPercent: Depending from Difficulty Level. For Emporer =95
MaxPlotDistance: For cylindrical map with Standard size (64 x 42): 58

Note: MaxPlotDistance 58 will not work. I had to use 55. To me it is not clear how to determine MaxPlotsize for different maps.

At the end the formula above works fine for my 2 test games. Distance Maintenance is a linear function on not only the distance from Palace but the city population as well. So whipping your pop will reduce your maintenance cost.

Graph in Spoiler is showing dependency of DistanceMaintenance from Distance to Palace for Emporer game on standard map and city population = 4
Spoiler :

Graph in Spoiler is showing dependency of DistanceMaintenance from City population for Emporer game on standard map and distance to palace = 10
Spoiler :

Spoiler shows how I determined MaxPlotDistance for Standard map size.
Spoiler :

Maybe one of you can help me to understand the calculation of MaxPlotSize better. That's one thing I'm still unclear. And I would appriciate if more users could verify my formula.
But at the end I'm happy that I can calculate Distance Maintenace for BTS 3.19.
Regards,
Spaghetti

File size:
98.4 KB
Views:
726
File size:
132.2 KB
Views:
734
File size:
221 KB
Views:
729
8. ### OlsonWarlord

Joined:
May 5, 2013
Messages:
283
Location:
Long Island, NY
I took a look at the pdf's equation and found that, regardless of difficulty level or map size XML values, the fluctuating in-game variable expenses within the Distance-Based City Maintenance (DBCM) remain constant to each other.

After a game is started, the player has control over the following DBCM related costs:
- distance of city from the gov't center
- # of buildings within the city
- city population
- whether or not the city contains a maintenance reducing building (ie. courthouse)

Of the first three, the least expensive is
population 'X' (X = the DBCM cost of increasing the city population by 1), then

distance to a gov't center '4X' (each additional tile away from the gov't. center is equal to the cost of increasing the population by 4), and then

# of buildings within the city '8X' (each additional building is equal to the cost of increasing the population by 8 [note: this is reduced by 50% with a courthouse or 20% with a Zulu barracks]).

I did not consider the impact of State Property/Kremlin as none of my games last that long.