longturn / freeciv21

Develop your civilization from humble roots to a global empire
GNU General Public License v3.0
222 stars 42 forks source link

Provide more detail in the city dialog about how unit upkeep is calculated #2076

Open jwrober opened 11 months ago

jwrober commented 11 months ago

Describe the bug Client doesn't properly show unit upkeep in city dialog.

To Reproduce Steps to reproduce the behavior:

  1. Open a game
  2. Lookup the upkeep of a unit in game help
  3. Open a city dialog
  4. Hover over a unit and notice the client doesn't give proper stats
  5. See error

Expected behavior Upkeep icons and proper stats shown

Screenshots image image

Platform and version (please complete the following information):

Additional context None

lmoureaux commented 11 months ago

Let me add to the mix the government help, that usually reads as:

  • Each city can support up to 2 units for free; further units each cost 1 gold per turn.

Not all units have the same upkeep in the help.

lmoureaux commented 10 months ago

Summarizing what is shown:

When computing upkeep (city_units_upkeep in server/citytools.cpp), the cost of each unit is calculated in utype_upkeep_cost(utype, player, output_type). This works as follows:

  1. The base upkeep is taken from utype->upkeep
  2. If the unit is a Fanatic and EFT_FANATICS is active, upkeep is zeroed out
  3. If the unit type has the UTYF_SHIELD2GOLD flag and the effect EFT_SHIELD2GOLD_FACTOR is > 0:
    • Any gold upkeep is replaced with shield upkeep * EFT_SHIELD2GOLD_FACTOR
    • Shield upkeep is zeroed
  4. The result is multiplied with the value of the effect EFT_UPKEEP_FACTOR

Every city gets free support for a number of units. This is controlled by EFT_UNIT_UPKEEP_FREE_PER_CITY.

lmoureaux commented 10 months ago

Sim05 numbers for EFT_UNIT_UPKEEP_FREE_PER_CITY:

Government Gold Shields Food
Anarchy 99 99 100
Tribal 99 99 100
Despotism 2 2 6
Fundamentalism 2 1 6
Communism 2 1 3
Monarchy 2 1 5
Others 0 0 3

Cities get one more free unit free of food support at even sizes between 2 and 30 except at size 10.

Sim05 has two effects with EFT_SHIELD2GOLD_FACTOR, one for Raiders and one for Bowmen. They are irrelevant for the current case.

From the numbers above and the issue description, we are in the "Others" case with two units free of food upkeep, not costing any shields (even in the base upkeep) but costing one gold each. A similar logic must explain the lack of unhappy citizens.

:arrow_right: Unit upkeep is more complicated than can be represented in the unit type help summary :arrow_right: What is shown is (most likely) correct :arrow_right: Suggest to reclassify as a doc bug (documenting the above logic) or GUI feature request (for more detailed explanations)

lmoureaux commented 9 months ago

@jwrober thoughts on the above analysis?

jwrober commented 9 months ago

The challenge is that is really hard for a regular player to fully understand this when looking at units in the city dialog. What if we add some kind of extra text to the pop up when hovering over a unit? Something similar to what we do on the citizens tab in city dialog. The text would give upkeep information taking into account the varying effects from Government, Wonders, Improvements, etc.

lmoureaux commented 9 months ago

Sounds like a good idea

jwrober commented 9 months ago

Heck add UWT to the text while we are at it

lmoureaux commented 9 months ago

Heck add UWT to the text while we are at it

309 ?

jwrober commented 9 months ago

Good catch. Yes I think that is it.