1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Unit maintenance explained

Discussion in 'Civ4 Strategy Articles' started by Roland Johansen, Nov 16, 2005.

  1. Roland Johansen

    Roland Johansen Chieftain

    Joined:
    Apr 29, 2003
    Messages:
    4,292
    Location:
    the Netherlands
    As I didn't see an article covering the unit maintenance and did see a few questions about this subject, I thought about researching it myself. I hope it will be useful to some people.

    The first section of this article is about the ingame information of unit costs and how to read it correctly. The second part is about how the unit costs are calculated in Civ 4. In the third part some strategical consequences of the way Civ4 calculates unit maintenance are considered. The fourth part considers some of the differences for unit maintenance between the human and the AI. A fifth part contains some information for modders that want to change the way the game calculates the free unit support or want to change the basic costs of units whether they are inside or outside of your borders.


    How to read the ingame information.


    Unit maintenance is divided in two sections, unit costs and unit supply. Both of these costs are mentioned in the financial adviser (F2). You can mouse over these sections and get some additional information.

    The unit cost section has the following mouse over information (the numbers are just an example):
    10: Unit cost for 10 units (free support for 14)
    15: Military unit cost for 15 units (free support for 3)
    -13: handicap cost

    The first line means that your empire has 24 units. You only have to pay maintenance for 10 of them as you have a free support of 14 units. The second line shows that your empire has 18 military units (every unit except settlers, workers and missionaries). You only have to pay maintenance for 15 of them as you have a free support of 3 units. This military unit cost is usually 0 and will only have a positive number when you're running the pacifism civic. The last line is a discount and is dependent on the difficulty level of the game (it is 0 for deity level).

    The unit supply section has the following mouse over information (again the numbers are just an example):
    3: away supply for 7 units (free support for 4)

    This means that your empire has 11 units outside its cultural borders. You only have to pay supply costs for 7 of them as you have a free supply support for 4 units. These 7 units have a supply cost of 7/2=3 rounded down. Note that also non-military units like settlers, workers and missionaries have supply costs.


    How does the game calculate the free unit support and the handicap cost?


    Some of you might have noticed that the amount of free support increases as you play the game. This is true for the free support in the unit cost section, but not the free support in the unit supply section. The free support in the unit supply section is always 4.

    However, the free support in the unit cost section is dependent on the total size of your population (the sum of all of your city sizes) and the difficulty level. If we name the size of your population N and the difficulty level bonus D then the free support for units is [0.24 * N] + D. This difficulty level bonus is 5 at Deity, 6 at Immortal, 7 at Emperor, 8 at Monarch, 10 at Prince, 12 at Noble, 16 at Warlord, 22 at Chieftain and finally 28 at Settler level.
    The vassalage civic provides you with an additional free unit support which is again dependent on your population size: [0.1 * N] + 5.
    The free support in the military unit section is also dependent on the size of your population: [0.12 * N] + 2.
    All of these numbers are rounded down.
    The handicap cost is a percentage of the total unit cost (unit cost + military unit cost) which is dependent on the difficulty level. The percentage is 0 at Deity, 10 at Immortal, 20 at Emperor, 30 at Monarch, 40 at Prince, 50 at Noble, 60 at Warlord, 70 at Chieftain and finally 80 at Settler level. This number is rounded up.

    An example:

    10: Unit cost for 10 units (free support for 14)
    15: Military unit cost for 15 units (free support for 3)
    -13: handicap cost

    These are the unit costs from an empire with a size 5, 3 and 2 city. So the total population size is 10. It is a game at Noble difficulty level, so the difficulty level bonus is 12. In this game the vassalage civic that grants additional free support is not used. So the free support is 0.24 * 10 + 12 = 14 (rounded down).
    In this game, the pacifism civic is used and we thus have to pay military unit costs. The free support is 0.12 * 10 + 2 = 3 (rounded down).
    As this is a game at Noble difficulty level, the handicap costs are 50% of 25 = 13 (rounded up).


    Strategic Consequences


    -The unit cost limits fast expansion.

    The free unit support can take a large chunk out of your unit maintenance cost and should thus be maximized. There is only one real way to do that and that is to increase your population before you create a lot of units. To support all the units needed for a fast expansion a large population size is needed, but that is against the nature of fast expansion. If you neglect you defences in order to save yourself from high unit maintenance costs, then you risk your cities being taken over by barbarians or your settlers eaten by lions.

    -Early exploration/attack with many units is very expensive.

    The free support cost for unit supply is only 4. This means that if 6 or more units are not within your cultural borders (including workers, settlers and missionaries), then you will start to pay unit supply costs for those units. As money is scarce in the beginning of the game, this upkeep can be too much.

    -An empire with large cities can easily support a sizable army without any unit maintenance cost.

    As a rule of thumb, you can say that 4 units of population supply 1 unit for free (not exact, but close enough). So if your cities are size 8 on average, then each city can support 2 units free of charge. If your cities are size 16 on average then each city can support 4 units free of charge.
    This doesn't mean that building farms to grow big cities is the way to go as there are other terrain improvements that are often worth more. It does mean that building many small cities close to each other is not as smart as a few larger cities, because the larger cities can be better defended or can supply an additional offensive army next to its own defensive units. (You also don't want to have many small cities because of high city maintenance.)

    - In combination with the article on civic upkeep, one can see that the additional free unit support from the vassalage civic is less than the upkeep cost of this civic (except for very small empires). (The vassalage civic gives 0.1 N + 5 extra free unit support, but it costs more than 0.15 N as a civic.) This doesn't make the civic useless as it also offers 2 experience to all units that are trained, but it is something to consider when choosing this civic. If your leader is organized, then the civic upkeep costs are halved and the additional free unit support offered by the vassalage civic is actually comparable to its upkeep cost.


    Different unit maintenance cost between the human and the AI


    The AI pays a different unit upkeep as the human player. It pays the same as a human with a similar empire would pay at noble level if you play the game at settler, chieftain, warlord or noble difficulty level. It pays 95% at prince level, 90% at monarch level, 85% at emperor level, 80% at immortal level and only 60% at deity level (all compared to a human player with a similar empire at noble difficulty level).

    The human player pays 50% extra for units outside of its borders (see first section on unit supply). However, the AI only pays a percentage of this cost that is again dependent on difficulty level: 50% at settler, 45% at chieftain, 40% at warlord, 35% at noble, 30% at prince, 25% at monarch, 20% at emperor, 15% at immortal and finally 10% at deity level.

    There are more differences between the AI and the humans at the various difficulty levels, but these are the only ones that have to do with this article. An important discount for the AI that is somewhat related to this article is the AI discount on unit upgrade costs. The AI pays much less for upgrading units at every difficulty level.


    Some information for modders


    I found the XML files that determine the free unit support and it might be interesting for some modders.
    The modifiers that determine the amount of free support and the maintenance cost of units (inside or outside of your borders) can be found in the file GlobalDefines.xml and are named: INITIAL_BASE_FREE_UNITS, INITIAL_BASE_FREE_MILITARY_UNITS, INITIAL_FREE_UNITS_POPULATION_PERCENT, INITIAL_FREE_MILITARY_UNITS_POPULATION_PERCENT, INITIAL_GOLD_PER_UNIT, INITIAL_FREE_OUTSIDE_UNITS, INITIAL_OUTSIDE_UNIT_GOLD_PERCENT

    I think that the names of these modifiers speak for themselves if combined with the formulas for free unit support above.

    For the civic Vassalage, the modifiers that determine free unit support can be found in the file CIV4CivicInfos.xml and are named iBaseFreeUnits and iFreeUnitsPopulationPercent.

    The difficulty modifier that adds to the free unit support is of course found in the file Civ4HandicapInfo.xml and is named iFreeUnits. The modifier that determines the handicap cost is also in this file and is named iUnitCostPercent. Note that this modifier denotes the amount that you actually pay and not the amount of cost reduction.

    Note that the basic number of free units named D in the formula above is the number denoted behind iFreeUnits in the file Civ4HandicapInfo.xml added to the number denoted behind INITIAL_BASE_FREE_UNITS in the file GlobalDefines.xml.
     
  2. tera

    tera Chieftain

    Joined:
    Nov 3, 2005
    Messages:
    7
    Quite a good analysis. Thanks for the effort! =)
     
  3. Denniz

    Denniz Where's my breakfast? Moderator Hall of Fame Staff

    Joined:
    Nov 28, 2003
    Messages:
    11,091
    Gender:
    Male
    Location:
    Dallas
  4. remconius

    remconius Chieftain

    Joined:
    Jun 22, 2003
    Messages:
    2,470
    Location:
    Amstelveen, NL
    Excellent stuff!

    You could actually keep defense in line with maintenance costs. city 4 gets 1 unit, 8 gets 2 units, 12 gets 3 units for defense, etc. Of course frontier and coastal cities need more units for defense.
     
  5. Arathorn

    Arathorn Catan player

    Joined:
    Jan 10, 2002
    Messages:
    3,778
    Location:
    Illinois
    Thanks, Roland. Good stuff.

    Arathorn
     
  6. Theoden

    Theoden Chieftain GOTM Staff

    Joined:
    Sep 17, 2003
    Messages:
    2,569
    Location:
    Denmark
    This is very useful. Thank you, Roland.
     
  7. Roland Johansen

    Roland Johansen Chieftain

    Joined:
    Apr 29, 2003
    Messages:
    4,292
    Location:
    the Netherlands
    It's nice to see that the writing is appreciated.

    I personally think that the civic maintenance cost are also linearly dependent on the total population size. But I don't want to research that now, as I haven't finished a full game of Civ4 yet (had some problems to get it working when I first got the game). Probably cheap, medium and expensive civics each have a different linear factor and the difficulty level might influence the factors too.

    If someone feels like researching it, then it can probably done with the world editor. One can raise the city size step by step and watch the effect on the civic upkeep. You can raise the city size up to 1000 in the world editor and that can make it easy to find such linear factors. If the civics are not linearly dependent on the total population size, then other tricks are needed and it could get more difficult.
     
  8. Specialj

    Specialj Chieftain

    Joined:
    Mar 5, 2004
    Messages:
    6
    Location:
    Montreal
    Terrific Job, Thx a lot :)
     
  9. Tauro

    Tauro Chieftain

    Joined:
    Nov 20, 2005
    Messages:
    251
    Impressive job, very useful.
    thx :)
     
  10. Blazer6

    Blazer6 Chieftain

    Joined:
    Aug 15, 2005
    Messages:
    906
    I think growing cities will cause civic costs to balloon. A small city should not be a burden with regards to civic costs, as they have little to add to civics.
    I think it goes up a point by some population multiple. Cost reductions might warrant city stagnation until you have room to keep it one less than the next increase.
     
  11. josephstalin

    josephstalin Kremlin Highlander

    Joined:
    Apr 15, 2005
    Messages:
    728
    Location:
    Paris
    That is a very nice article. But how pacifism affects unit costs. Is it +1 gold for every military unit or military units above unit costs?
     
  12. colony

    colony Slow Typer

    Joined:
    Nov 29, 2003
    Messages:
    573
    Location:
    UK
    Nice article :goodjob:

    I've just been having a look in the XML files and testing things in the world editor, and it appears that civic costs are linearly related to your total population, as well as the number of cities you control, as being handicapped by difficulty level (50% on Settler, up to 100% on Deity). The AI also gets a discount on civic costs starting on Prince difficulty, down to 60% cost on Deity:crazyeye:

    Each cost of civic (High, Medium, Low) has a percentage modifier for total population and number of cities. To calculate the total cost for using that civic you add the two parts together to get the final value, which is then multiplied by the difficulty level handicap. For population these are 15/10/5 (High/Medium/Low), and the population cost is simply found from: (Modifier/100) * (Total Pop). The cost due to the number of cities is: (Modifier/100) * (Number of Cites - 5).

    Where the modifiers are 60/40/20 for High/Medium/Low upkeep civics.This value can be negative, giving you a discount if you have less than 5 cities.

    For example, say I have 12 cities, which have a total population of 60, on an Immortal level game, and am using Police State, which has a population modifier of 15%, and a number of cities modifier of 60%. The handicap percentage for Immortal is 100%, so full price civics
    The cost due to population will be (15/100) * (60) = 9
    The cost due to number of cities will be (60/100) * (12 - 5) = 4.2
    The total cost is therefore 13.2 * 1, which is rounded down to 13. Also, unlike a lot of other number in the game, the civic upkeep costs appear to be rounded to the nearest integer, rather than always being rounded down, although this could just need more testing.

    Of course this could be wrong, but it does fit what I found from testing different numbers of cities and total population in the world builder. Also, if someone could explain to me how to put tables in posts, then I could edit the modifiers and difficulty level handicaps in
     
  13. KrikkitTwo

    KrikkitTwo Immortal

    Joined:
    Apr 3, 2004
    Messages:
    12,313
    So a bit more simply

    Civic upkeep=(Population/20+Max(City-5,0)/5)*(Maintenance Levels)
    Low=1
    Medium=2
    High=3
    with a lowest possible of 1 (Representative, Free Speech, Emancipation, State Property, Pacifism), and a maximum of 14 (Police, Vassalage, Caste, Environmental, Organized Religion)
     
  14. Roland Johansen

    Roland Johansen Chieftain

    Joined:
    Apr 29, 2003
    Messages:
    4,292
    Location:
    the Netherlands
    Thank you!


    Nice work yourself! I had been looking for this formula a little last week and came up with a formula that was a little bit different but largely the same, which is good news. To describe the differences between our formulas, I will define some variables first.

    Define total size of population N and number of cities M. Define a civic multiplyer C, that is equal to 0 if a free civic is used, 1 if a low cost civic is used, 2 if a medium cost civic is used and 3 if a high cost civic is used. Define the dificulty modifier D, which is equal to
    1 at deity, immortal and emperor level,
    0.95 at monarch level,
    0.9 at prince level,
    0.8 at noble level,
    0.7 at warlord level,
    0.6 at chieftain level,
    0.5 at settler level.
    Then your formula for the upkeep cost of one civic is:
    D * C ( 0.05 * N + 0.2 * ( M - 5 ) )

    My formula is largely the same:
    [D * ( [0.05 C * ( N - 8 )] + [0.2 C * ( M - 1 )] ) ] where terms between [ ] means rounding down. If N - 8 is negative or M - 1 is negative than the value 0 is used instead.

    The main difference is the N - 8 instead of N and the M - 1 instead of the M - 5.

    I took the liberty of finding some instances where my formula gave the correct answer and yours didn't (all instances are at deity level to get D=1): With 3 cities of size 1 and using 1 civic of high upkeep cost, we get a civic upkeep cost of 1 (ingame value). Your formula produces the value: (0.15 * 3 + 0.6 * (-2)) = 0? My formula produces the value:
    [0.15 * 0] + [0.6 * 2] = 0+1=1.
    With 1 city of size 15 and using 1 civic of high upkeep cost, we get a civic upkeep cost of 1 (ingame value). Your formula produces the value (0.15 * 15 + 0.6 * (-4)) = 0. My formula produces the value: [0.15 * 7] + [0.6 * 0] = 1 + 0 = 1.

    I didn't put my formula in the strategy forum because there are also some issues with my formula. I don't seem to get the rounding right when multiple non-free civics are used. Sometimes when multiple civics of say high cost are used in a large empire, then not all of the high cost civics are equally priced. There are some small fluctuations (say police state costs 16 and organized religion 17).
    I tried removing the instance of rounding down untill all the costs of population are added and all the costs of number of cities are added ( [totalcivicmultiplier * 0.05 * (N-8)] + [totalcivicmultiplier * 0.2 * (M-1)] ), but that also caused some small errors of 1 or 2 in the total civic costs.
    So, I'm also not totally satisfied with my formula.

    To everyone reading this: If someone can find the error in my formula, then please do. If someone can find an error in my formula when only one non-free civic is used, then I would like to know. I think my formula produces the right value when only one non-free civic is used but I'm not 100% sure.

    To Colony: If I made a mistake and your formula proves to be correct, then I'm sorry. But I think the counter examples are correct. Both of our formulas are at least largely correct.
     
  15. Roland Johansen

    Roland Johansen Chieftain

    Joined:
    Apr 29, 2003
    Messages:
    4,292
    Location:
    the Netherlands
    It is + 1 gold for every military unit above the free support for military units (which is not that high). Note however that there is a discount (named handicap cost), which reduces any costs related to units. At noble difficulty level (where the handicap cost is -50%), this means that every military unit above the free support effectively only costs 0.5.

    Maybe you want to reread the example in the 'how to read the ingame information' section. If it's not clear, then ask a question about the example.

    Edit: I might have misunderstood your question. You mean a situation where the free support costs are higher than the number of units and the free support for military units is lower than the number of military units:

    Example:

    First, the example in the article:

    The unit cost section has the following mouse over information (the numbers are just an example):
    10: Unit cost for 10 units (free support for 14)
    15: Military unit cost for 15 units (free support for 3)
    -13: handicap cost

    Now, you disband most of your army, you disband 13 military units:

    The unit cost section has the following mouse over information (the numbers are just an example):
    0: Unit cost for 0 units (free support for 14)
    2: Military unit cost for 2 units (free support for 3)
    -1: handicap cost

    The unit upkeep cost should now actually be negative because you only have 24-13 = 11 units and free upkeep for 14 units. But the game uses a minimum unit upkeep of 0. Also the 3 extra units that could be supported aren't added to the military free support, that's still only 3.

    Does this answer your question?
     
  16. colony

    colony Slow Typer

    Joined:
    Nov 29, 2003
    Messages:
    573
    Location:
    UK
    Well, after looking at it, I think the main problem I was having was not using a small enough number of cities, and using a population that was too big. It would explain why I get a slightly different equation for it overall, that (in some cases) gives similar results. I should have expected there to be rounding somewhere I suppose, but I just didn't notice, due to the numbers I was using, which weren't giving me any reason to think there was something wrong when I checked in the game.

    I noticed this whilst testing too, as well as during general gameplay, and I don't know what is causing it. Maybe there's some sort of combined factor when you're using two or more civics with the same upkeep (perhaps as a way of minimising the impact of rounding on the total upkeep cost?). I'll have a closer look tonight (hopefully using some numbers prone to rounding to check it too:blush: ).

    Edit: Your formula seems to give the correct answer for the Government civics I've tried with various pop levels and city numbers. But I have noticed some strange results with a couple of civics (seems to be mainly from Org. Rel. and Environmentalism). As there are no default government civics with no upkeep I modded despotism to give no upkeep, and tried again. I've only had a chance to test it once (using one 100pop city). Police State and Vassalage both gave 13 upkeep, Environmentalism gave 14 and Org Rel gave 15 (all tested to avoid having multiple civics with upkeep costs), so one option is that different civic type upkeep costs are calculated differently. Anyway, it's 3am now, and I'm getting tired, so I'll have a better look tomorrow and let you know if I find anything out (probably by PM to avoid cluttering up this thread any more).
     
  17. Roland Johansen

    Roland Johansen Chieftain

    Joined:
    Apr 29, 2003
    Messages:
    4,292
    Location:
    the Netherlands
    Thank, you for checking that there are really different formulas being used for the different categories of civics. I really hadn't considered that as a possibility. I thought it was some rounding effect. It's pretty strange that civics of different categories use different formulas, but it is a fact now. I tested what these formulas are and here the come:

    Using N, M, C and D as in post 14. There is another modifier O, that is 1/2 if the leader is organized and 1 if the leader is not organized. Terms between [ ] are rounded down:

    Goverment civics:
    [O * [ D * ( [ 0.05 * C (N-8) ] + [ 0.2 * C (M-1) ] ) ] ]
    Legal civics:
    [O * [ D * ( [ 0.05 * C (N-9) ] + [ 0.2 * C M ] ) ] ]
    Labor civics:
    [O * [ D * ( [ 0.05 * C (N-10) ] + [ 0.2 * C (M+1) ] ) ] ]
    Economy civics:
    [O * [ D * ( [ 0.05 * C (N-11) ] + [ 0.2 * C (M+2) ] ) ] ]
    Religion civics:
    [O * [ D * ( [ 0.05 * C (N-12) ] + [ 0.2 * C (M+3) ] ) ] ]

    There is a very clear patern in these formalas, but I think it is better to leave them seperate to avoid cluttering the formulas.

    I think we should make a different thread about civic upkeep costs where these formulas are mentioned. People are probably not looking for formulas about civic upkeep costs in this thread.
     
  18. colony

    colony Slow Typer

    Joined:
    Nov 29, 2003
    Messages:
    573
    Location:
    UK
    True, I'll let you make it though, as you actually did almost all of the work on it. If you like I'll test these formulae later (even though I expect you've already checked them, you seem to be much more thorough than me).
     
  19. Tauro

    Tauro Chieftain

    Joined:
    Nov 20, 2005
    Messages:
    251
    wow! Now who builds a simply military costs calculator program? :)
    It should be wonderful
     
  20. Roland Johansen

    Roland Johansen Chieftain

    Joined:
    Apr 29, 2003
    Messages:
    4,292
    Location:
    the Netherlands
    Not thorough enough to see that my major assumption (civic costs are independent of the category of civics (government/legal/etc) ) is actually wrong. I thought it had to be some rounding error, you found out that it had to be calculated in a different way. We both independently found the population and number of cities multipliers which are actually the most important things in the formulas. So, I'm planning to write it as a joint article. Two minds can achieve more than one which we clearly showed here. It's a joint contribution to this gaming community.

    I would appreciate if you could check it with an endgame save (especially one not at emperor/immortal/deity level so that the D-multiplier is used). It might be some work to sum up all the population in all of your cities, but it will be a good check. Could you do that? I wouldn't be that surprised if there were still some rounding errors in the present formulas (but I hope not).
     

Share This Page