Page 1 of 1

What is the actual defense bonus in a city?

Posted: Fri Oct 12, 2018 6:16 pm
by Hans_Lemurson
I have a few questions about how strongly units defend a city:
1. I have read that units get get a 1.5x defense bonus just from BEING in a city. Is this correct?
2. Does this "In a City" bonus replace the 1.5x defense bonus they get from the normal unit-fortify command? Or are fortified units in a city get a 2.25x bonus?
3. Do city walls give a 2x defense bonus, or do they replace the "In a City" bonus, increasing it from 1.5 to 2?
4. Size 8 cities get a 1.5x defense bonus. Is this a separate bonus from all the others?

I have witnessed shockingly tenacious defense in a city, and I'm unsure whether this was bad luck or incorrect calculations.

Posted: Fri Oct 12, 2018 6:29 pm
by Corbeau
This is what I have:

(base defence) * (terrain) * 1.5 (city or fortified) * [1.0 + (city size %) + (walls/coastal)]

Posted: Fri Oct 12, 2018 11:05 pm
by Hans_Lemurson
So, a Phalanx in a Size 2 unwalled city on on a hill defends at what level of strength?

2(Phalanx def) * 1.5(Hill bonus) * 1.5(city or fortified bonus) * (1+0(size2 city has no bonus)+0(no walls)) = 4.5?

Posted: Fri Oct 12, 2018 11:16 pm
by Corbeau
Again, defence bonus due to city size is ruleset-specific and in most (if not all so far) LT games is 50% for all cities smaller than 8.

So this example would be 6.75.

Posted: Sat Oct 13, 2018 6:21 am
by Hans_Lemurson
And for cities size-8 and above, it would be def strength 9?

Posted: Sat Oct 13, 2018 8:27 am
by Corbeau
I think so.

Posted: Sat Oct 13, 2018 9:33 am
by Wahazar
Corbeau wrote:I think so.
Doubt, that there is such high defense factor.
Didn't find anything in combat.c, could you point me the line where it is?

In LT45 effetcs.ruleset I found only 50% bonus for land units in any city and additional 50% bonus for land and naval units for city of size 8 and more.

Posted: Sat Oct 13, 2018 9:50 am
by kevin551
I agree. Your formula is not correct.

The two effects for city size are -

Code: Select all

[effect_city_defense_0]
type    = "Defend_Bonus"
value   = 50
reqs    =
    { "type", "name", "range"
      "CityTile", "Center", "Local"
}

[effect_city_defense_1]
type    = "Defend_Bonus"
value   = 50
reqs    =
    { "type", "name", "range"
      "MinSize", "8", "City"
      "CityTile", "Center", "Local"
}
A size 2 city only gets the 50% bonus once not twice.
A size 8+ city gets both bonuses. Once each. It gets a 100% bonus. (You add the bonuses then multiply, not multiply by first then multiply by second.)

A green Phalanx in a Size 2 unwalled city on on a hill defends at 4.5
A green Phalanx in a Size 8+ unwalled city on on a hill defends at 6.0

To be certain we need to look at the source code.

In combat.c lines 544 to 533 however it does look like you get the city bonus twice.
It seems strange to have effects that allow the values to be modified in the ruleset,
and then combine that with a hard coded value in the binary.

Code: Select all

  defensepower +=
    defensepower * tile_extras_defense_bonus(ptile, def_type) / 100;

  if ((pcity || fortified)
      && uclass_has_flag(utype_class(def_type), UCF_CAN_FORTIFY)
      && !utype_has_flag(def_type, UTYF_CANT_FORTIFY)) {
    defensepower = (defensepower * 3) / 2;
  }

return defensepower;
The page http://freeciv.wikia.com/wiki/Combat is almost useless at explaining this properly.
"These factors are combined, thus a city built on a hill with a river that has city walls is very hard to conquer. "

Posted: Sat Oct 13, 2018 10:24 am
by Corbeau
Ok, I misread. The example Hans gave had NO walls, and I calculated WITH walls. My bad.

Posted: Sat Oct 13, 2018 12:43 pm
by kevin551
This topic was previously discussed here - The best possible defense value for a unit in a city
Caedo wrote:All the different bonuses in Freeciv's supplied rulesets are multiplicative, since it's never possible to have multiple Defense_Bonus effects applying at the same time. However, as with any effect type, the values of all active effects are simply added, so if there's one Defense_Bonus effect with a value of 50 for a city of size 9 and another with a value of 100 for city walls, they're the same effect type and thus added up, giving a total value of 150, or +150% (or *2.5).
The part that puzzles me is that there appear to be two 50% bonuses for cities smaller than size 8. One hardcoded and one in the effects.ruleset.
I looked back and this was also the case in LT32. In that game I certainly tested attacking cities. I never noticed an extra 50% defence.

This was also mentioned by Caedo in the thread linked previously.
Caedo wrote:EDIT 2: Also, there seems to be an additional +50% Defend_Bonus in a city, apart from the built-in factor of 1.5. However, this defense only works against land units.

Posted: Mon Oct 15, 2018 3:15 pm
by dion
it seems to me that the quoted source code is giving an additional 50% bonus for fortifying the unit itself inside the city. am I wrong?

Posted: Mon Oct 15, 2018 4:10 pm
by Corbeau
I don't even know what language that is (C?), but "if ((pcity || fortified)" looks like "if a unit is in a city OR fortified". Meaning, even if both conditions are met, it's still just one instance of it. 1 OR 1 is still just 1.

Posted: Mon Oct 15, 2018 4:16 pm
by kevin551
Yes it is C.
And yes 1 OR 1 is 1.
There is no point fortifying in a city. You do not gain anything.

Posted: Mon Oct 15, 2018 4:31 pm
by Corbeau
Well, you don't get a bonus, but you do get some peace from preventing the unit to pop up every time someone passes by :)

Posted: Mon Oct 15, 2018 5:29 pm
by Wahazar
Doesn't fortify increase speed of healing?

Posted: Mon Oct 15, 2018 5:48 pm
by Corbeau
Ok, THAT is a good point. Yes, it does.