<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40634 >

 This patch adds separate defense_bonus value for each base type.
"DefenseBonus" flag is removed and so is global definition of
fortress_defense_bonus. If several bases at the same tile provide
defense bonus for unit, sum of these is used (usually ruleset author
would not allow such bases to coexist).

Applies on top of #40633


 - ML

diff -Nurd -X.diff_ignore freeciv/common/base.c freeciv/common/base.c
--- freeciv/common/base.c       2009-01-07 16:53:30.000000000 +0200
+++ freeciv/common/base.c       2009-01-07 16:37:15.000000000 +0200
@@ -31,7 +31,7 @@
 static struct base_type base_types[MAX_BASE_TYPES];
 
 static const char *base_type_flag_names[] = {
-  "NoAggressive", "DefenseBonus", "NoStackDeath",
+  "NoAggressive", "NoStackDeath",
   "DiplomatDefense", "ParadropFrom"
 };
 
diff -Nurd -X.diff_ignore freeciv/common/base.h freeciv/common/base.h
--- freeciv/common/base.h       2009-01-07 16:53:30.000000000 +0200
+++ freeciv/common/base.h       2009-01-07 16:37:01.000000000 +0200
@@ -27,7 +27,6 @@
 enum base_flag_id {
   BF_NOT_AGGRESSIVE = 0, /* Unit inside are not considered aggressive
                           * if base is close to city */
-  BF_DEFENSE_BONUS,      /* Base provides defense bonus for units inside */
   BF_NO_STACK_DEATH,     /* Units inside will not die all at once */
   BF_DIPLOMAT_DEFENSE,   /* Base provides bonus for defending diplomat */
   BF_PARADROP_FROM,      /* Paratroopers can use base for paradrop */
@@ -46,6 +45,7 @@
   struct requirement_vector reqs;
   enum base_gui_type gui_type;
   int build_time;
+  int defense_bonus;
   int border_sq;
 
   bv_unit_classes native_to;
diff -Nurd -X.diff_ignore freeciv/common/combat.c freeciv/common/combat.c
--- freeciv/common/combat.c     2008-12-28 14:53:33.000000000 +0200
+++ freeciv/common/combat.c     2009-01-07 16:44:19.000000000 +0200
@@ -467,9 +467,9 @@
     }
   }
 
-  if (tile_has_base_flag_for_unit(ptile, def_type, BF_DEFENSE_BONUS) && 
!pcity) {
+  if (!pcity) {
     defensepower +=
-       (defensepower * terrain_control.fortress_defense_bonus) / 100;
+      defensepower * tile_bases_defense_bonus(ptile, def_type) / 100;
   }
 
   if ((pcity || fortified) && is_ground_unittype(def_type)) {
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def  2009-01-07 16:53:30.000000000 +0200
+++ freeciv/common/packets.def  2009-01-07 16:33:42.000000000 +0200
@@ -1191,7 +1191,6 @@
   UINT16 river_trade_incr;              /* added to trade if Civ2 river */
   STRING river_help_text[MAX_LEN_PACKET]; # help for Civ2-style rivers
 
-  SINT16 fortress_defense_bonus;        /* % added to defense if fortress */
   UINT16 road_superhighway_trade_bonus;  # % added to trade if road/s-highway
   UINT16 rail_tile_bonus[O_MAX];        /* % added to output if railroad */
   UINT8 pollution_tile_penalty[O_MAX]; /* % taken from output if polluted */
diff -Nurd -X.diff_ignore freeciv/common/tile.c freeciv/common/tile.c
--- freeciv/common/tile.c       2009-01-07 16:53:30.000000000 +0200
+++ freeciv/common/tile.c       2009-01-07 16:42:32.000000000 +0200
@@ -247,6 +247,24 @@
 }
 
 /****************************************************************************
+  Calculate defense bonus given by bases
+****************************************************************************/
+int tile_bases_defense_bonus(const struct tile *ptile,
+                             const struct unit_type *punittype)
+{
+  int bonus = 0;
+
+  base_type_iterate(pbase) {
+    if (tile_has_base(ptile, pbase)
+        && is_native_base_to_uclass(pbase, utype_class(punittype))) {
+      bonus += pbase->defense_bonus;
+    }
+  } base_type_iterate_end;
+
+  return bonus;
+}
+
+/****************************************************************************
   Check if tile contains base native for unit
 ****************************************************************************/
 bool tile_has_native_base(const struct tile *ptile,
diff -Nurd -X.diff_ignore freeciv/common/tile.h freeciv/common/tile.h
--- freeciv/common/tile.h       2009-01-07 16:53:30.000000000 +0200
+++ freeciv/common/tile.h       2009-01-07 16:44:45.000000000 +0200
@@ -110,6 +110,8 @@
                           const struct unit_type *punittype);
 bool tile_has_claimable_base(const struct tile *ptile,
                              const struct unit_type *punittype);
+int tile_bases_defense_bonus(const struct tile *ptile,
+                             const struct unit_type *punittype);
 
 /* Vision related */
 enum known_type tile_get_known(const struct tile *ptile,
diff -Nurd -X.diff_ignore freeciv/data/civ1/terrain.ruleset 
freeciv/data/civ1/terrain.ruleset
--- freeciv/data/civ1/terrain.ruleset   2009-01-07 16:53:30.000000000 +0200
+++ freeciv/data/civ1/terrain.ruleset   2009-01-07 16:51:25.000000000 +0200
@@ -53,9 +53,6 @@
 ; help text for Civ2-style rivers
 river_help_text=""
 
-; percent added to defense if square has fortress
-fortress_defense_bonus=100
-
 ; percent added to trade production if road and city has superhighways
 road_superhighway_trade_bonus=0
 
@@ -663,31 +660,31 @@
 ;                           and README.effects for help on requirements)
 ; gui_type                = How gui should handle this base. 
Fortress/Airbase/Other
 ; build_time              = How long it takes for a unit to build this base
+; defense_bonus           = Percent added to defense
 ; border_sq               = Base will claim land ownership up to this radius
 ; conflicts               = List of bases that cannot be on the same tile.
 ;                           Bases with non-zero border_sq automatically 
conflict
 ;                           with each other.
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
-;   - "DefenseBonus"      = Units inside gain defense bonus
 ;   - "NoStackDeath"      = Units inside do not die all at once when attacked
 ;   - "ClaimTerritory"    = Base will claim land ownership
 ;   - "DiplomatDefense"   = Diplomats inside get bonus to diplomatic defense
 ;   - "ParadropFrom"      = Paradrop can be initiated from base
 
 [base_fortress]
-name         = _("Fortress")
-graphic      = "base.fortress"
-graphic_alt  = "-"
-activity_gfx = "unit.fortress"
-reqs         =
+name          = _("Fortress")
+graphic       = "base.fortress"
+graphic_alt   = "-"
+activity_gfx  = "unit.fortress"
+reqs          =
     { "type", "name", "range"
       "Tech", "Construction", "Player"
       "TerrainClass", "Land", "Local"
       "UnitFlag", "Settlers", "Local"
     }
-gui_type     = "Fortress"
-build_time   = 3
-native_to    = "Land"
-flags        = "NoAggressive", "DefenseBonus",
-               "NoStackDeath", "DiplomatDefense"
+gui_type      = "Fortress"
+build_time    = 3
+defense_bonus = 100
+native_to     = "Land"
+flags         = "NoAggressive", "NoStackDeath", "DiplomatDefense"
diff -Nurd -X.diff_ignore freeciv/data/civ2/terrain.ruleset 
freeciv/data/civ2/terrain.ruleset
--- freeciv/data/civ2/terrain.ruleset   2009-01-07 16:53:30.000000000 +0200
+++ freeciv/data/civ2/terrain.ruleset   2009-01-07 16:51:37.000000000 +0200
@@ -61,9 +61,6 @@
  civilization has learned Bridge Building technology.\
 ")
 
-; percent added to defense if square has fortress
-fortress_defense_bonus=100
-
 ; percent added to trade production if road and city has superhighways
 road_superhighway_trade_bonus=50
 
@@ -778,46 +775,46 @@
 ;                           and README.effects for help on requirements)
 ; gui_type                = How gui should handle this base. 
Fortress/Airbase/Other
 ; build_time              = How long it takes for a unit to build this base
+; defense_bonus           = Percent added to defense
 ; border_sq               = Base will claim land ownership up to this radius
 ; conflicts               = List of bases that cannot be on the same tile.
 ;                           Bases with non-zero border_sq automatically 
conflict
 ;                           with each other.
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
-;   - "DefenseBonus"      = Units inside gain defense bonus
 ;   - "NoStackDeath"      = Units inside do not die all at once when attacked
 ;   - "DiplomatDefense"   = Diplomats inside get bonus to diplomatic defense
 ;   - "ParadropFrom"      = Paradrop can be initiated from base
 
 [base_fortress]
-name         = _("Fortress")
-graphic      = "base.fortress"
-graphic_alt  = "-"
-activity_gfx = "unit.fortress"
-reqs         =
+name          = _("Fortress")
+graphic       = "base.fortress"
+graphic_alt   = "-"
+activity_gfx  = "unit.fortress"
+reqs          =
     { "type", "name", "range"
       "Tech", "Construction", "Player"
       "TerrainClass", "Land", "Local"
       "UnitFlag", "Settlers", "Local"
     }
-gui_type     = "Fortress"
-build_time   = 3
-native_to    = "Land"
-flags        = "NoAggressive", "DefenseBonus",
-               "NoStackDeath", "DiplomatDefense"
+gui_type      = "Fortress"
+build_time    = 3
+defense_bonus = 100
+native_to     = "Land"
+flags         = "NoAggressive", "NoStackDeath", "DiplomatDefense"
 
 [base_airbase]
-name         = _("Airbase")
-graphic      = "base.airbase"
-graphic_alt  = "-"
-activity_gfx = "unit.airbase"
-reqs         =
+name          = _("Airbase")
+graphic       = "base.airbase"
+graphic_alt   = "-"
+activity_gfx  = "unit.airbase"
+reqs          =
     { "type", "name", "range"
       "Tech", "Radio", "Player"
       "TerrainClass", "Land", "Local"
       "UnitFlag", "Airbase", "Local"
     }
-gui_type     = "Airbase"
-build_time   = 3
-native_to    = "Air", "Helicopter", "Missile"
-flags        = "NoStackDeath", "DiplomatDefense", "ParadropFrom"
+gui_type      = "Airbase"
+build_time    = 3
+native_to     = "Air", "Helicopter", "Missile"
+flags         = "NoStackDeath", "DiplomatDefense", "ParadropFrom"
diff -Nurd -X.diff_ignore freeciv/data/default/terrain.ruleset 
freeciv/data/default/terrain.ruleset
--- freeciv/data/default/terrain.ruleset        2009-01-07 16:53:30.000000000 
+0200
+++ freeciv/data/default/terrain.ruleset        2009-01-07 16:51:07.000000000 
+0200
@@ -64,9 +64,6 @@
  civilization has learned Bridge Building technology.\
 ")
 
-; percent added to defense if square has fortress
-fortress_defense_bonus=100
-
 ; percent added to trade production if road and city has superhighways
 road_superhighway_trade_bonus=50
 
@@ -898,47 +895,48 @@
 ;                           and README.effects for help on requirements)
 ; gui_type                = How gui should handle this base. 
Fortress/Airbase/Other
 ; build_time              = How long it takes for a unit to build this base
+; defense_bonus           = Percent added to defense
 ; border_sq               = Base will claim land ownership up to this radius
 ; conflicts               = List of bases that cannot be on the same tile.
 ;                           Bases with non-zero border_sq automatically 
conflict
 ;                           with each other.
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
-;   - "DefenseBonus"      = Units inside gain defense bonus
 ;   - "NoStackDeath"      = Units inside do not die all at once when attacked
 ;   - "DiplomatDefense"   = Diplomats inside get bonus to diplomatic defense
 ;   - "ParadropFrom"      = Paradrop can be initiated from base
 
 [base_fortress]
-name         = _("Fortress")
-graphic      = "base.fortress"
-graphic_alt  = "-"
-activity_gfx = "unit.fortress"
-reqs         =
+name          = _("Fortress")
+graphic       = "base.fortress"
+graphic_alt   = "-"
+activity_gfx  = "unit.fortress"
+reqs          =
     { "type", "name", "range"
       "Tech", "Construction", "Player"
       "TerrainClass", "Land", "Local"
       "UnitFlag", "Settlers", "Local"
     }
-gui_type     = "Fortress"
-build_time   = 3
-border_sq    = 5
-native_to    = "Land"
-flags        = "NoAggressive", "DefenseBonus",
-               "NoStackDeath", "DiplomatDefense"
+gui_type      = "Fortress"
+build_time    = 3
+defense_bonus = 100
+border_sq     = 5
+native_to     = "Land"
+flags         = "NoAggressive", "NoStackDeath", "DiplomatDefense"
 
 [base_airbase]
-name         = _("Airbase")
-graphic      = "base.airbase"
-graphic_alt  = "-"
-activity_gfx = "unit.airbase"
-reqs         =
+name          = _("Airbase")
+graphic       = "base.airbase"
+graphic_alt   = "-"
+activity_gfx  = "unit.airbase"
+reqs          =
     { "type", "name", "range"
       "Tech", "Radio", "Player"
       "TerrainClass", "Land", "Local"
       "UnitFlag", "Airbase", "Local"
     }
-gui_type     = "Airbase"
-build_time   = 3
-native_to    = "Air", "Helicopter", "Missile"
-flags        = "NoStackDeath", "DiplomatDefense", "ParadropFrom"
+gui_type      = "Airbase"
+build_time    = 3
+defense_bonus = 0
+native_to     = "Air", "Helicopter", "Missile"
+flags         = "NoStackDeath", "DiplomatDefense", "ParadropFrom"
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c    2009-01-07 16:53:30.000000000 +0200
+++ freeciv/server/ruleset.c    2009-01-07 16:36:28.000000000 +0200
@@ -1729,8 +1729,6 @@
       "parameters.river_help_text");
     sz_strlcpy(terrain_control.river_help_text, s);
   }
-  terrain_control.fortress_defense_bonus =
-    secfile_lookup_int_default(file, 100, "parameters.fortress_defense_bonus");
 
   terrain_control.road_superhighway_trade_bonus =
     secfile_lookup_int_default(file, 50, 
"parameters.road_superhighway_trade_bonus");
@@ -2019,6 +2017,9 @@
     pbase->build_time = secfile_lookup_int(file, "%s.build_time", section);
     pbase->border_sq  = secfile_lookup_int_default(file, 0, "%s.border_sq",
                                                    section);
+    pbase->defense_bonus  = secfile_lookup_int_default(file, 0,
+                                                       "%s.defense_bonus",
+                                                       section);
 
     slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
     BV_CLR_ALL(pbase->flags);
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in  2009-01-07 16:53:30.000000000 +0200
+++ freeciv/version.in  2009-01-07 16:34:03.000000000 +0200
@@ -23,5 +23,5 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel.2009.Jan.07"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel.2009.Jan.07-2"
 NETWORK_CAPSTRING_OPTIONAL=""
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to