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

Maintenance questions

Discussion in 'Civ4 - General Discussions' started by karadoc, Sep 3, 2010.

  1. karadoc

    karadoc AI programmer

    Joined:
    Oct 3, 2005
    Messages:
    1,568
    Location:
    Australia
    Short version:
    I'd like to know how the various type of maintenance are calculated, and where the calculations can be modified so that I can tweaks some of the numbers. Also, there seems to be something weird going on with "number of cities" maintenance. Does anyone know how this works?

    I thinking of modding the game to make huge civs a bit less powerful, and increase the importance of having colonies etc. I figure the best way to do this is to increase some component of maintenance which scales super-linearly with the size of the civ.

    To get a feel for the numbers, I opened one of my recent save games in which I control a large part of the map. According to the financial adviser,
    civic upkeep:275
    Number of cities cost:91
    distance cost: 0 (state property)
    colonies: 0
    corporations: 0

    Then I switched to free market — no anarchy... here are the numbers on the same turn:
    civic upkeep: 295
    Number of cities cost: 16 (???)
    distance cost: 142
    Colonies: 16
    Corporations: 30

    I didn't realise that free market could reduce to # of cities cost... and what's even more weird is that in the city screen (in any city) the stated cost for # of cities maintenance was 7 with either civic. Based my number of cities (27), the state property cost of 91 was about right (taking into account "we love the X" day and courthouses). I have no idea where the free market cost of 16 came from.

    Anyway, it seems to me that increasing the # of cities maintenance cost is probably the best way to hurt large civs without unbalancing other things (increasing distance cost would just make state property even better. Increasing civic costs, although very tempting, may make "organized" too powerful, and I'm not sure if civic costs scale super-linearly anyway.)

    I guess my main question is this: what's going on with that # of cities cost under free market?

    ... and why does state property have lower upkeep than free market? I would have thought state property would have more organizational costs can free market — it would probably be more balanced if it was higher upkeep, too.
     
  2. BornInCantaloup

    BornInCantaloup Agent of Chaos

    Joined:
    Feb 9, 2010
    Messages:
    4,128
    Location:
    Cantaloupe Island
  3. karadoc

    karadoc AI programmer

    Joined:
    Oct 3, 2005
    Messages:
    1,568
    Location:
    Australia
    Interesting...

    I think I've read that civic one before. The take-home message is basically that you pay a bit for each city, and for each population point. So that's a linear cost.

    Strangely (and disappointingly) the # of cities cost is actually linear as well, because "the number of cities component of city maintenance can never exceed 6 gpt per city". Well... in the example I wrote about in my first post I said that it was at 7 per city; that probably just means the guide is out of date. But still, it seems likely to me that there is a cap on # of cities maintenance cost. So the distance cost is the only one that is super-linear (because as you get more cities, you must be putting them further from your capitol city and thus have higher costs for each) — but this super-linear distance cost is completely eliminated by state property...

    None of this explains why my # of cities cost dropped when I switched to free market. Clearly there is still more to learn about this.

    [edit]
    I found the city maintenance calculation in the source code. It is capped. The maintenance is calculated in a sensible way, and then it does this:
    Code:
    iNumCitiesMaintenance = std::min(iNumCitiesMaintenance, GC.getHandicapInfo(getHandicapType()).getMaxNumCitiesMaintenance() * 100);
    The cap probably depends on the difficulty level and stuff like that.

    It's tempting to just remove that line and see how much it hurts to have lots of cities... but on the other hand I can think of some good reasons to have a cap. I'm not sure how best to proceed, and I still don't know why the maintenance dropped when I switched to free market. The code that I'm looking at just calculates the per city cost, and as I said, that was 7 with and without free market. Only the total was different.
     
  4. Derakon

    Derakon Prince

    Joined:
    Aug 2, 2010
    Messages:
    387
    As for why State Property is cheaper to run than Free Market, maintaining an actual free market is a lot of work. Having the state simply boss everyone around is comparatively refreshingly simple. It just doesn't work as well in practice because the state is corrupt and/or underincentivized.
     
  5. Jerrymander

    Jerrymander Epistemologist

    Joined:
    Mar 21, 2007
    Messages:
    2,624
    Location:
    Hallways of Always
    "Underincentivised"? Hey, I can make up words, too! You're a dinglebooperplooger.

    How can you explain an ingame mechanic (that's not related to real life) with a real life statement (that is false, anyway)?
     
  6. karadoc

    karadoc AI programmer

    Joined:
    Oct 3, 2005
    Messages:
    1,568
    Location:
    Australia
    Underincentivized? State property has nothing to do how much people are paid, does it? I'm under the impression that it is only referring to land ownership. The government owns all the land, and the people essentially lease it from them. Isn't that what state property is? So the way I see it, the government has to do a whole lot of work to keep track of who has what land and how much it is worth etc... as opposed to non-state property where all that work is done by the private sector.
     
  7. kochman

    kochman Deity

    Joined:
    Jun 8, 2009
    Messages:
    10,818
    State Property is enabled by which technology again?

    You guys filling in your own blanks about what SP means arbitrarily are missing that it is total state control of the economy via communism.
    It's simple... don't over think it.
     
  8. Derakon

    Derakon Prince

    Joined:
    Aug 2, 2010
    Messages:
    387
    What I meant by "underincentivized" is that the government doesn't really have any reason to want to do a good job. "Adequate" is entirely sufficient for the paper-pusher to get his salary.

    But I suspect this is gonna get into a huge flamewar, so forget about it.
     
  9. Jerrymander

    Jerrymander Epistemologist

    Joined:
    Mar 21, 2007
    Messages:
    2,624
    Location:
    Hallways of Always
    How about "lacking incentive"?
     
  10. kochman

    kochman Deity

    Joined:
    Jun 8, 2009
    Messages:
    10,818
    Jerrymander, do you really need this broken down for you?
    Just look at the places where "communism" is in place, ok.
    And, yes, I understand, true Marxism has never been implemented, nor will it ever, so it's pretty obvious what he meant.
     
  11. Jerrymander

    Jerrymander Epistemologist

    Joined:
    Mar 21, 2007
    Messages:
    2,624
    Location:
    Hallways of Always
    I'm not badgering him on whether or not these two economic models have been successful. I'm badgering him on attempting to prove an ingame mechanic with real life assertions (regardless of their truth) and making up words.

    Don't put words in my mouth.
     
  12. karadoc

    karadoc AI programmer

    Joined:
    Oct 3, 2005
    Messages:
    1,568
    Location:
    Australia
    Kochman, is this a sensitive political issue for your or something? This thread is about maintenance costs in the game. Whether or not communism is a viable system is somewhat beside the point. The only reason I was speculating as to what was meant by "state property" was that I wanted to make sure it wouldn't been seen as ridiculous if I changed it into a high-upkeep civic.

    [edit]
    I've done some experimenting, and I've decided that it wouldn't be too painful if the # of cities maintenance cap was removed completely. I tested a situation where I controlled most of the map. Removing the cap only increased the maintenance by about 1% of my total income. So I figure it is pretty safe to remove the cap. I just want to slow really big civs. I'll probably make some other changes later.

    Another idea I'm toying with is to make it so that small cities don't add to the per city cost. Let me try to explain that a bit better... Currently, each city pays a cost which depends on the total number of cities. So the overall cost for the whole civ is roughly
    0.4 * N * N
    where N is the number of cities. I want to make it so that small cities still pay the cost, but not increase it for the other cities. So the total cost would be more like.
    0.4 * N * N_large
    where N_big is just the number of large cities. I'd probably define "large" to mean "bigger than half of the average city size for this civ". So for example, if you had some cities with size {6, 4, 5, 2, 2}, average/2 is just less than 2, so all of the cities would count and the total maintenance would be around 0.4*5*5. But if you had {12, 5, 7, 2, 3, 15, 8}, then the size 2 and 3 cities wouldn't count and so the maintenance would be more like 0.4*7*5. The purpose of this change would be to make it so that small cities do not result in a huge marginal cost by increasing the cost for all of your other cities (eg, a tundra city for getting silver/deer).

    (By the way the "0.4" in these formulas is actually something that depends on the size of the city. I'm just writing 0.4 to keep it simple for discussion.)


    Finally, I've noticed that State Property eliminates colony maintenance as well as distance maintenance. I'm not sure if this is intended or not... I'm thinking of changing it.
     
  13. BornInCantaloup

    BornInCantaloup Agent of Chaos

    Joined:
    Feb 9, 2010
    Messages:
    4,128
    Location:
    Cantaloupe Island
    Without really entering any ideological debate, the easy way is to consider "State property" as opposed to "Private property" :)
    Neither of those economic models are ever absolute, nor do they induce "0 costs". However, because an extensive State property requires a high level of centralization and a developped bureaucracy, it may make sense to increase the civic upkeep cost, yes, if you assume centralization has a cost.
    On the other hand, one may consider State property (as compared to the Private property) as a highly rational and organized system, therefore as a highly efficient system. In that case there is a considerable reward that should lead you to lower the civic cost and/or to grant the civic considerable economic advantages.

    How you choose to balance those things and some others is up to you. Most probably, that is a matter of context and/or personal opinion.
     
  14. karadoc

    karadoc AI programmer

    Joined:
    Oct 3, 2005
    Messages:
    1,568
    Location:
    Australia
    Well said, BornInCantaloup. And with that, I think I'll try setting state property to "high upkeep" to see how it goes, although I don't think it will make a lot of difference.


    By the way, I found the answer to my question about weird behavior with the "number of cities" maintenance cost in the original post (where the total cost on the financial adviser was much less than the sum of the individual costs). It turns out that it is a bug in the way the totals are calculated. The bug doesn't affect the actual amount of money you get, so it doesn't affect balance or strategy or anything like that, it only affects the breakdown of the totals displayed on the financial adviser.

    This is how the bug works: a city in anarchy does not pay any maintenance costs at all; but the components of the maintenance that it would have paid if it was not in anarchy are still added to the total. ie. the distance maintenance, corporation maintenance etc are all added into the totals that are displayed on the financial adviser, even though those costs don't actually apply while the city is in anarchy.. however, at the same time as adding all of those components to totals, the sum of the components for the city in anarchy are subtracted from "number of cities" maintenance so that the total of the components totals on the financial adviser is correct.

    For example, in a game I just played, I had a few cities in anarchy and the total city maintenance costs reported by the financial adviser looked like this:
    distance maintenance: 60
    number of cities maintenance: -9
    Colonial maintenance: 10
    Corporation maintenance: 193

    Obviously "-9" is wrong... and then when I gave away one of the cities that was in anarchy, the number changed to this:
    distance maintenance: 52
    number of cities maintenance: 10
    Colonial maintenance: 2
    Corporation maintenance: 190

    So number of cities maintenance went up, and the rest went down and the total maintenance was unchanged. The difference in the distance maintenance etc is exactly what the anarchy city would have been paying if it was not in anarchy.

    So that's that mystery solved.

    [edit]
    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.
     

Share This Page