freeciv21 icon indicating copy to clipboard operation
freeciv21 copied to clipboard

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

Open jwrober opened this issue 1 year ago • 9 comments

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):

  • OS: Linux
  • Freeciv21 version: 3.1-alpha.3
  • Ruleset/Longturn game (if applicable): Sim

Additional context None

jwrober avatar Dec 16 '23 19:12 jwrober

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 avatar Dec 17 '23 00:12 lmoureaux

Summarizing what is shown:

  • The help dialog shows the values in utype->upkeep and utype->happy_cost
  • The upkeep list shows punit->upkeep for food/shield/gold (unit_upkeep_astr in common/unit.cpp)

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 avatar Dec 23 '23 23:12 lmoureaux

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 avatar Dec 24 '23 00:12 lmoureaux

@jwrober thoughts on the above analysis?

lmoureaux avatar Jan 27 '24 00:01 lmoureaux

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.

jwrober avatar Jan 27 '24 00:01 jwrober

Sounds like a good idea

lmoureaux avatar Jan 27 '24 00:01 lmoureaux

Heck add UWT to the text while we are at it

jwrober avatar Jan 27 '24 00:01 jwrober

Heck add UWT to the text while we are at it

#309 ?

lmoureaux avatar Jan 27 '24 00:01 lmoureaux

Good catch. Yes I think that is it.

jwrober avatar Jan 27 '24 00:01 jwrober