Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#12997) [PATCH] Generic no sink deep loss effect
Home

[Freeciv-Dev] (PR#12997) [PATCH] Generic no sink deep loss effect

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12997) [PATCH] Generic no sink deep loss effect
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Fri, 6 May 2005 17:15:52 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch makes the no sink deep effect generic. Instead of hardcoding
to check the F_TRIREME flag in the C code, it uses effects to do the check.

There are only two lingering F_TRIREME checks left. One is a unit type
check and the other for the, as usual, annoyingly harcoded help.

Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.220
diff -u -u -r1.220 aicity.c
--- ai/aicity.c 6 May 2005 16:01:42 -0000       1.220
+++ ai/aicity.c 7 May 2005 00:04:30 -0000
@@ -1049,7 +1049,7 @@
       int cost = unit_upgrade_price(pplayer, punit->type, id);
       int real_limit = limit;
       /* Triremes are DANGEROUS!! We'll do anything to upgrade 'em. */
-      if (unit_flag(punit, F_TRIREME)) {
+      if (get_unit_bonus(punit, EFT_NO_SINK_DEEP) == 0) {
         real_limit = pplayer->ai.est_upkeep;
       }
       if (pplayer->economic.gold - cost > real_limit) {
Index: ai/aiexplorer.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiexplorer.c,v
retrieving revision 1.14
diff -u -u -r1.14 aiexplorer.c
--- ai/aiexplorer.c     6 May 2005 20:11:51 -0000       1.14
+++ ai/aiexplorer.c     7 May 2005 00:04:30 -0000
@@ -102,17 +102,18 @@
 Is there a chance that a trireme would be lost, given information that 
 the player actually has.
 ***************************************************************/
-static bool is_likely_trireme_loss(struct tile *ptile, struct player *pplayer, 
-                                  struct unit *punit)
+static bool is_likely_sink_deep_loss(struct tile *ptile,
+                                    struct player *pplayer,
+                                    struct unit *punit)
 {
   /*
    * If we are in a city or next to land, we have no chance of losing
    * the ship.  To make this really useful for ai planning purposes, we'd
    * need to confirm that we can exist/move at the x,y location we are given.
    */
-  if ((likely_ocean(ptile, pplayer) < 50) || 
-      is_likely_coastline(ptile, pplayer) ||
-      get_unit_bonus(punit, EFT_NO_SINK_DEEP) > 0) {
+  if (get_unit_bonus(punit, EFT_NO_SINK_DEEP) > 0 ||
+      likely_ocean(ptile, pplayer) < 50 || 
+      is_likely_coastline(ptile, pplayer)) {
     return FALSE;
   } else {
     return TRUE;
@@ -175,8 +176,7 @@
    * is a city on the tile, or if the tile is not accessible, or if the 
    * tile is on a different continent, or if we're a barbarian and
    * the tile has a hut, don't go there. */
-  if ((unit_flag(punit, F_TRIREME) && 
-       is_likely_trireme_loss(ptile, pplayer, punit))
+  if (is_likely_sink_deep_loss(ptile, pplayer, punit)
       || tile_get_city(ptile)
       || (is_barbarian(pplayer) && tile_has_special(ptile, S_HUT))) {
     return 0;
@@ -375,7 +375,7 @@
         * in which case the goto code is simply requesting a
         * one turn delay (the next tile we would occupy is not safe).
         * In that case, we should just wait. */
-        if (unit_flag(punit, F_TRIREME) 
+        if ((get_unit_bonus(punit, EFT_NO_SINK_DEEP) == 0)
             && (punit->moves_left != unit_move_rate(punit))) {
           /* we're a trireme with non-full complement of movement points,
            * so wait until next turn. */
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.150
diff -u -u -r1.150 aitools.c
--- ai/aitools.c        5 May 2005 20:00:41 -0000       1.150
+++ ai/aitools.c        7 May 2005 00:04:31 -0000
@@ -568,13 +568,8 @@
   risk_cost->base_value = unit_build_shield_cost(punit->type);
   risk_cost->fearfulness = fearfulness * linger_fraction;
 
-  if (unit_flag(punit, F_TRIREME)) {
-    risk_cost->ocean_cost = risk_cost->base_value
-      * (double)base_trireme_loss_pct(pplayer, punit)
-      / 100.0;
-  } else {
-    risk_cost->ocean_cost = 0;
-  }
+  risk_cost->ocean_cost = risk_cost->base_value
+    * (double)base_sink_deep_loss_pct(pplayer, punit) / 100.0;
   risk_cost->unsafe_terrain_cost = risk_cost->base_value
     * (double)base_unsafe_terrain_loss_pct(pplayer, punit) / 100.0;
   risk_cost->enemy_zoc_cost = PF_TURN_FACTOR * 20;
Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.111
diff -u -u -r1.111 helpdata.c
--- client/helpdata.c   6 May 2005 16:01:42 -0000       1.111
+++ client/helpdata.c   7 May 2005 00:04:31 -0000
@@ -190,6 +190,10 @@
     cat_snprintf(buf, bufsz, _("Only applies to %s units.\n\n"),
                 unit_name(req->source.value.unittype));
     return;
+  case REQ_UNITFLAG:
+    cat_snprintf(buf, bufsz, _("Only applies to %s units.\n\n"),
+                get_unit_flag_name(req->source.value.unitflag));
+    return;
   case REQ_MINSIZE:
     cat_snprintf(buf, bufsz, _("Requires a minimum size of %d.\n\n"),
                 req->source.value.minsize);
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.240
diff -u -u -r1.240 unit.c
--- common/unit.c       6 May 2005 20:11:52 -0000       1.240
+++ common/unit.c       7 May 2005 00:04:33 -0000
@@ -1305,7 +1305,7 @@
   turn at the given location.
 
   Note this function isn't really useful for AI planning, since it needs
-  to know more.  The AI code uses base_trireme_loss_pct and
+  to know more.  The AI code uses base_sink_deep_loss_pct and
   base_unsafe_terrain_loss_pct directly.
 **************************************************************************/
 int unit_loss_pct(const struct player *pplayer, const struct tile *ptile,
@@ -1319,9 +1319,9 @@
   }
 
   /* Trireme units may be lost if they stray from coastline. */
-  if (unit_flag(punit, F_TRIREME)) {
+  if (get_unit_bonus(punit, EFT_NO_SINK_DEEP) == 0) {
     if (!is_safe_ocean(ptile)) {
-      loss_pct = base_trireme_loss_pct(pplayer, punit);
+      loss_pct = base_sink_deep_loss_pct(pplayer, punit);
     }
   }
 
@@ -1338,8 +1338,8 @@
   Triremes have a varying loss percentage based on tech and veterancy
   level.
 **************************************************************************/
-int base_trireme_loss_pct(const struct player *pplayer,
-                         const struct unit *punit)
+int base_sink_deep_loss_pct(const struct player *pplayer,
+                           const struct unit *punit)
 {
   if (get_unit_bonus(punit, EFT_NO_SINK_DEEP) > 0) {
     return 0;
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.143
diff -u -u -r1.143 unit.h
--- common/unit.h       30 Apr 2005 17:09:28 -0000      1.143
+++ common/unit.h       7 May 2005 00:04:33 -0000
@@ -311,8 +311,8 @@
 
 int unit_loss_pct(const struct player *pplayer, const struct tile *ptile,
                  const struct unit *punit);
-int base_trireme_loss_pct(const struct player *pplayer,
-                         const struct unit *punit);
+int base_sink_deep_loss_pct(const struct player *pplayer,
+                           const struct unit *punit);
 int base_unsafe_terrain_loss_pct(const struct player *pplayer,
                                 const struct unit *punit);
 
Index: common/aicore/pf_tools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/pf_tools.c,v
retrieving revision 1.32
diff -u -u -r1.32 pf_tools.c
--- common/aicore/pf_tools.c    23 Apr 2005 17:40:28 -0000      1.32
+++ common/aicore/pf_tools.c    7 May 2005 00:04:33 -0000
@@ -648,8 +648,7 @@
     parameter->get_zoc = NULL;
   }
 
-  if (unit_flag(punit, F_TRIREME)
-      && base_trireme_loss_pct(unit_owner(punit), punit) > 0) {
+  if (base_sink_deep_loss_pct(unit_owner(punit), punit) > 0) {
     parameter->turn_mode = TM_WORST_TIME;
     parameter->is_pos_dangerous = trireme_is_pos_dangerous;
   } else if (base_unsafe_terrain_loss_pct(unit_owner(punit), punit) > 0) {
@@ -665,8 +664,8 @@
 void pft_fill_unit_overlap_param(struct pf_parameter *parameter,
                                 struct unit *punit)
 {
-  const bool trireme_danger = unit_flag(punit, F_TRIREME)
-                     && base_trireme_loss_pct(unit_owner(punit), punit) > 0;
+  const bool trireme_danger
+    = base_sink_deep_loss_pct(unit_owner(punit), punit) > 0;
   const bool danger
     = base_unsafe_terrain_loss_pct(unit_owner(punit), punit) > 0;
 
Index: data/civ1/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ1/effects.ruleset,v
retrieving revision 1.5
diff -u -u -r1.5 effects.ruleset
--- data/civ1/effects.ruleset   2 May 2005 08:45:20 -0000       1.5
+++ data/civ1/effects.ruleset   7 May 2005 00:04:33 -0000
@@ -16,6 +16,14 @@
 ; /* <-- avoid gettext warnings
 ; */ <-- avoid gettext warnings
 
+; Regular sea units cannot sink on deep water
+name   = "No_Sink_Deep"
+value   = 1
+nreqs  =
+    { "type", "name", "range"
+      "UnitFlag", "Trireme", "Local"
+    }
+
 [effect_civil_war_0]
 name    = "Civil_War_Chance"
 value   = 90
Index: data/civ2/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ2/effects.ruleset,v
retrieving revision 1.7
diff -u -u -r1.7 effects.ruleset
--- data/civ2/effects.ruleset   2 May 2005 08:45:21 -0000       1.7
+++ data/civ2/effects.ruleset   7 May 2005 00:04:33 -0000
@@ -16,6 +16,14 @@
 ; /* <-- avoid gettext warnings
 ; */ <-- avoid gettext warnings
 
+; Regular sea units cannot sink on deep water
+name   = "No_Sink_Deep"
+value   = 1
+nreqs  =
+    { "type", "name", "range"
+      "UnitFlag", "Trireme", "Local"
+    }
+
 [effect_civil_war_0]
 name    = "Civil_War_Chance"
 value   = 90
@@ -1169,6 +1177,7 @@
 reqs   =
     { "type", "name", "range"
       "Building", "Lighthouse", "Player"
+      "UnitFlag", "Trireme", "Local"
     }
 
 [effect_lighthouse_2]
Index: data/default/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/effects.ruleset,v
retrieving revision 1.8
diff -u -u -r1.8 effects.ruleset
--- data/default/effects.ruleset        5 May 2005 21:14:57 -0000       1.8
+++ data/default/effects.ruleset        7 May 2005 00:04:33 -0000
@@ -16,6 +16,14 @@
 ; /* <-- avoid gettext warnings
 ; */ <-- avoid gettext warnings
 
+; Regular sea units cannot sink on deep water
+name   = "No_Sink_Deep"
+value   = 1
+nreqs  =
+    { "type", "name", "range"
+      "UnitFlag", "Trireme", "Local"
+    }
+
 ; Nuclear power gives +1 moves to sea units
 [effect_nuclear_powered_boats]
 name   = "Sea_Move"
@@ -1240,6 +1248,7 @@
 reqs   =
     { "type", "name", "range"
       "Building", "Lighthouse", "Player"
+      "UnitFlag", "Trireme", "Local"
     }
 
 [effect_lighthouse_2]
Index: data/history/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/effects.ruleset,v
retrieving revision 1.5
diff -u -u -r1.5 effects.ruleset
--- data/history/effects.ruleset        21 Apr 2005 22:53:13 -0000      1.5
+++ data/history/effects.ruleset        7 May 2005 00:04:34 -0000
@@ -16,6 +16,14 @@
 ; /* <-- avoid gettext warnings
 ; */ <-- avoid gettext warnings
 
+; Regular sea units cannot sink on deep water
+name   = "No_Sink_Deep"
+value   = 1
+nreqs  =
+    { "type", "name", "range"
+      "UnitFlag", "Trireme", "Local"
+    }
+
 ; Nuclear power gives +1 moves to sea units
 [effect_nuclear_powered_boats]
 name   = "Sea_Move"
@@ -832,6 +840,7 @@
 reqs   =
     { "type", "name", "range"
       "Building", "Lighthouse", "Player"
+      "UnitFlag", "Trireme", "Local"
     }
 
 [effect_lighthouse_2]
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.193
diff -u -u -r1.193 gotohand.c
--- server/gotohand.c   6 May 2005 20:11:52 -0000       1.193
+++ server/gotohand.c   7 May 2005 00:04:34 -0000
@@ -930,8 +930,7 @@
   int i, fitness[8], best_fitness = DONT_SELECT_ME_FITNESS;
   struct unit *passenger;
   struct player *pplayer = unit_owner(punit);
-  bool afraid_of_sinking = (unit_flag(punit, F_TRIREME)
-                           && get_unit_bonus(punit, EFT_NO_SINK_DEEP) == 0);
+  bool afraid_of_sinking = (get_unit_bonus(punit, EFT_NO_SINK_DEEP) == 0);
 
   /* 
    * If the destination is one step away, look around first or just go
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.352
diff -u -u -r1.352 unittools.c
--- server/unittools.c  6 May 2005 20:11:52 -0000       1.352
+++ server/unittools.c  7 May 2005 00:04:37 -0000
@@ -366,7 +366,7 @@
     }
 
     /* 4) Check for units on unsafe terrains. */
-    if (unit_flag(punit, F_TRIREME)) {
+    if (get_unit_bonus(punit, EFT_NO_SINK_DEEP) == 0) {
       /* Triremes away from coast have a chance of death. */
       /* Note if a trireme died on a TER_UNSAFE terrain, this would
        * erronously give the high seas message.  This is impossible under
@@ -388,7 +388,7 @@
                            unit_name(punit->type));
         }
       }
-    } else if (!(is_air_unit(punit) || is_heli_unit(punit))
+    } else if ((base_unsafe_terrain_loss_pct(pplayer, punit) > 0)
               && (myrand(100) < unit_loss_pct(pplayer,
                                               punit->tile, punit))) {
       /* All units may have a chance of dying if they are on TER_UNSAFE

[Prev in Thread] Current Thread [Next in Thread]