Page 1 of 1

modding city defense bonus

Posted: Sat Mar 25, 2017 4:12 am
by NotAnyoneSpecial
Is it possible to mod the city defense bonus in rulesets, for example eliminating the 50% bonus land units get while stationed in cities?

Re: modding city defense bonus

Posted: Sat Mar 25, 2017 3:40 pm
by bard
There are rulesets with extra bonuses to defense in city that do can be modded. Open the file effects.ruleset (placed in a folder with the same name than the ruleset). Then search for "Defend_Bonus", until you find an effect like this:

Code: Select all

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

Re: modding city defense bonus

Posted: Sun Mar 26, 2017 1:22 am
by GriffonSpade
bard wrote:There are rulesets with extra bonuses to defense in city that do can be modded. Open the file effects.ruleset (placed in a folder with the same name than the ruleset). Then search for "Defend_Bonus", until you find an effect like this:

Code: Select all

type    = "Defend_Bonus"
value   = 50
reqs    =
    { "type", "name", "range"
      "CityTile", "Center", "Local"
    }
I believe Fortify/City defense bonus is still pretty hardcoded. A fact that makes me terribly, terribly sad. That, along with being unable to mess around with whether terrain bonuses should add or multiply with other defense bonus factors, WHICH units get terrain bonuses, and how much (ie x1, x2, etc.) are what is holding me back.

You can try to work around it, but it's a pain and it'll never be /just right/.

Re: modding city defense bonus

Posted: Sun Mar 26, 2017 7:21 am
by NotAnyoneSpecial
After managing to find the source code (it's actually really easy to find, i was just stupid), I confirmed that much like fortified bonus. The city bonus is hardcoded:

Code: Select all

 	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; 	}
source: line 543 http://svn.gna.org/viewcvs/freeciv/trun ... iew=markup

This is a problem because one of the pecuilarites of the Freeciv ruleset is that it difers from the civ2 one in that the city walls SHOULDN'T apply with the fortified bonus. That is not defense * fortified [1.5x] * citywall [3x] but actually defense * fortified [1.5x] OR defense * citywall [3x].
While this is trivial to fix ie making the wall bonus only be double: city wall [2.0x] not city wall [3.0x], I was still trying to find a way to remove the bonus for ruleset purposes.

Re: modding city defense bonus

Posted: Mon Mar 27, 2017 2:57 pm
by bard
NotAnyoneSpecial wrote: While this is trivial to fix ie making the wall bonus only be double: city wall [2.0x] not city wall [3.0x], I was still trying to find a way to remove the bonus for ruleset purposes.
You can change the bonus of the wall in the ruleset, by changing the file effects.ruleset. But is not exactly the same, because the bonus will be reduced for all units, not only the ones that can fortify. (Note that all unit requisites like UnitClass must match the attacker, not the defender).

Code: Select all

[effect_city_walls]
type    = "Defend_Bonus"
value	= 100
reqs	=
    { "type", "name", "range"
      "Building", "City Walls", "City"
      "UnitClass", "Land", "Local"
    }
GriffonSpade wrote: I believe Fortify/City defense bonus is still pretty hardcoded. A fact that makes me terribly, terribly sad. That, along with being unable to mess around with whether terrain bonuses should add or multiply with other defense bonus factors, WHICH units get terrain bonuses, and how much (ie x1, x2, etc.) are what is holding me back.
You can try to work around it, but it's a pain and it'll never be /just right/.
I subscribe that.

Re: modding city defense bonus

Posted: Sun Apr 02, 2017 3:47 pm
by bard
I have a related question...
Is it possible to give a bonus to defense to all units adjacent to a city with walls? I tested this with no success:

Code: Select all

[effect_city_walls]
type    = "Defend_Bonus"
value   = 50
reqs   =
    { "type", "name", "range"
      "Building", "City Walls", "City"
      "CityTile", "Center", "Adjacent"
    }

Re: modding city defense bonus

Posted: Sun Apr 02, 2017 3:58 pm
by cazfi
bard wrote:

Code: Select all

[effect_city_walls]
type    = "Defend_Bonus"
value   = 50
reqs   =
    { "type", "name", "range"
      "Building", "City Walls", "City"
      "CityTile", "Center", "Adjacent"
    }
Those reqs mean that there needs to be cities in adjacent tiles (like is possible in civ1) and one in current tile has City Walls.

As for your question; no, unfortunately "Building" requirement is not supported at "Adjacent" range (See doc/README.effects)

Re: modding city defense bonus

Posted: Sun Apr 02, 2017 4:07 pm
by bard
Ok, thanks.
Btw, whats the difference between City and Local range for a building?
(someday I'll try to understand the code related to ruleset effects and to stop making these kind of questions... :)

Re: modding city defense bonus

Posted: Sun Apr 02, 2017 8:36 pm
by cazfi
bard wrote:Btw, whats the difference between City and Local range for a building?
"City" means that the building must be in the city. "Local" would mean that the effect is to that building only (I don't think there's any effects where this would be realized at the moment - we don't have building targeting effects) Similar to output bonuses that target one kind of output only; "Science" "Local"
bard wrote:(someday I'll try to understand the code related to ruleset effects and to stop making these kind of questions... :)
Sometimes things like these are somewhat arbitrary. The effects system gives the general framework, but the code implementing the details has still something to say case-by-case.