Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9362) use impr->sabotage value
Home

[Freeciv-Dev] (PR#9362) use impr->sabotage value

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9362) use impr->sabotage value
From: "Jason Dorje Short" <jdorje@xxxxxxxxxxx>
Date: Tue, 13 Jul 2004 01:05:02 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9362 >

This patch uses the improvement's sabotage field.  This value comes from 
the ruleset but is currently never used (hard-coded rules are used instead).

The changes are of two forms:

- Many places hard-code that wonders and the palace cannot be sabotaged, 
and the player isn't allowed to try.  Instead we just check if (sabotage 
 > 0).

- When the diplomat actually tries the sabotage, the sabotage value is 
checked.  Now instead of hard-coding the chance of success (50% for 
citywalls or buildings in the capital, 100% otherwise) the sabotage 
field from the ruleset is used.

The second is a bit tricky.  The effects patch definitely gets this 
wrong but I'm not sure what is right or best.

The code right now gives 50% resistance to city walls or any city in the 
capital.  The effects code I think gives 50% resistance to any building 
in a city with city walls.  I assume the latter is wrong but I can't say 
for sure.  Either way this should just be a matter of fiddling with the 
rulesets (giving city walls either EFT_SPY_RESISTANT or just a reduced 
sabotage value).

There's also a bug in the effects patch, whereby the "protected" 
buildings were given a flat 50% vulnerability even if this meant their 
vulnerability was increased.  This is bad.  This is why I think the 
patch needs to be split up to get sufficient scrutiny.

The solution I used was to set the "sabotage" value for citywalls in the 
ruleset to 50%.  Thus citywall resistance is dealt with automatically. 
However it does mean that citywalls in the capital gets only 25% 
vulnerability, which is a behavior change.  It might be more accurate to 
use a 50% value as "vulnerability = MIN(vulnerability, 50)".

Aside from the "bad" bug in the effects patch I think none of this 
matters too much.  However we do need to fix the helptext so that it 
shows the vulnerability somehow.  Probably the sabotage value can just 
be displayed automatically the same way the building cost is.  Also we 
should eventually verify that the civ1 and civ2 rulesets are done 
more-or-less correctly.

Finally note that all clients are supported, but I only compiled the 
gtk2 client.

jason

Index: ai/aidiplomat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidiplomat.c,v
retrieving revision 1.36
diff -u -r1.36 aidiplomat.c
--- ai/aidiplomat.c     25 Jun 2004 23:43:00 -0000      1.36
+++ ai/aidiplomat.c     13 Jul 2004 07:59:58 -0000
@@ -67,7 +67,7 @@
   int count = 0;
 
   built_impr_iterate(pcity, index) {
-    if (!is_wonder(index) && index != B_PALACE) {
+    if (get_improvement_type(index)->sabotage > 0) {
       count++;
     }
   } built_impr_iterate_end;
Index: client/gui-gtk/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v
retrieving revision 1.143
diff -u -r1.143 dialogs.c
--- client/gui-gtk/dialogs.c    6 Jun 2004 21:02:15 -0000       1.143
+++ client/gui-gtk/dialogs.c    13 Jul 2004 07:59:59 -0000
@@ -824,7 +824,7 @@
   improvement_type[j++] = -1;
 
   built_impr_iterate(pcity, i) {
-    if(i != B_PALACE && !is_wonder(i)) {
+    if (get_improvement_type(i)->sabotage > 0) {
       row[0] = (char *) get_impr_name_ex(pcity, i);
       gtk_clist_append(GTK_CLIST(spy_improvements_list), row);
       improvement_type[j++] = i;
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.c,v
retrieving revision 1.69
diff -u -r1.69 dialogs.c
--- client/gui-gtk-2.0/dialogs.c        6 Jun 2004 21:02:15 -0000       1.69
+++ client/gui-gtk-2.0/dialogs.c        13 Jul 2004 08:00:00 -0000
@@ -644,7 +644,7 @@
   gtk_list_store_set(store, &it, 0, _("City Production"), 1, -1, -1);
 
   built_impr_iterate(pcity, i) {
-    if (i != B_PALACE && !is_wonder(i)) {
+    if (get_improvement_type(i)->sabotage > 0) {
       gtk_list_store_append(store, &it);
       gtk_list_store_set(store, &it, 0, get_impr_name_ex(pcity, i), 1, i, -1);
     }  
Index: client/gui-mui/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/dialogs.c,v
retrieving revision 1.55
diff -u -r1.55 dialogs.c
--- client/gui-mui/dialogs.c    8 May 2004 00:00:22 -0000       1.55
+++ client/gui-mui/dialogs.c    13 Jul 2004 08:00:00 -0000
@@ -431,7 +431,7 @@
 
     DoMethod(listview, MUIM_NList_InsertSingle, 
100-1,MUIV_NList_Insert_Bottom);
     built_impr_iterate(pcity, i) {
-      if (i != B_PALACE && !is_wonder(i))
+      if (get_improvement_type(i)->sabotage > 0) {
       {
         DoMethod(listview, MUIM_NList_InsertSingle, 
i+100,MUIV_NList_Insert_Bottom);
         any_improvements = TRUE;
Index: client/gui-sdl/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/dialogs.c,v
retrieving revision 1.46
diff -u -r1.46 dialogs.c
--- client/gui-sdl/dialogs.c    23 Jun 2004 23:08:55 -0000      1.46
+++ client/gui-sdl/dialogs.c    13 Jul 2004 08:00:01 -0000
@@ -2741,7 +2741,7 @@
   /* ------------------ */
   n = 0;
   built_impr_iterate(pCity, imp) {
-    if(imp != B_PALACE && !is_wonder(imp)) {
+    if (get_improvement_type(imp)->sabotage > 0) {
       
       create_active_iconlabel(pBuf, pWindow->dst, pStr,
              (char *) get_impr_name_ex(pCity, imp),
Index: client/gui-win32/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/dialogs.c,v
retrieving revision 1.49
diff -u -r1.49 dialogs.c
--- client/gui-win32/dialogs.c  22 Jun 2004 23:05:56 -0000      1.49
+++ client/gui-win32/dialogs.c  13 Jul 2004 08:00:01 -0000
@@ -1365,7 +1365,7 @@
   improvement_type[j++] = -1;
   
   impr_type_iterate(i) {
-    if(i != B_PALACE && pcity->improvements[i] && !is_wonder(i)) {
+    if (get_improvement_type(i)->sabotage > 0) {
       ListBox_AddString(lb,get_impr_name_ex(pcity,i));
       improvement_type[j++] = i;
     }  
Index: client/gui-xaw/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v
retrieving revision 1.98
diff -u -r1.98 dialogs.c
--- client/gui-xaw/dialogs.c    6 Jun 2004 21:02:15 -0000       1.98
+++ client/gui-xaw/dialogs.c    13 Jul 2004 08:00:02 -0000
@@ -822,7 +822,7 @@
   improvement_type[j++] = -1;
 
   built_impr_iterate(pcity, i) {
-    if (i != B_PALACE && !is_wonder(i)) {
+    if (get_improvement_type(i)->sabotage > 0) {
       improvements_can_sabotage[j] = get_impr_name_ex(pcity, i);
       improvement_type[j++] = i;
     }  
Index: common/improvement.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.h,v
retrieving revision 1.24
diff -u -r1.24 improvement.h
--- common/improvement.h        14 Jun 2004 23:43:08 -0000      1.24
+++ common/improvement.h        13 Jul 2004 08:00:02 -0000
@@ -112,7 +112,7 @@
   bool is_wonder;
   int build_cost;                      /* Use wrappers to access this. */
   int upkeep;
-  int sabotage;
+  int sabotage;                /* Base chance of diplomat sabotage succeeding. 
*/
   struct impr_effect *effect;          /* list; .type==EFT_LAST terminated */
   int variant;                 /* FIXME: remove when gen-impr obsoletes */
   struct Sprite *sprite;               /* icon of the improvement */
Index: data/civ1/buildings.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ1/buildings.ruleset,v
retrieving revision 1.33
diff -u -r1.33 buildings.ruleset
--- data/civ1/buildings.ruleset 18 May 2004 00:02:40 -0000      1.33
+++ data/civ1/buildings.ruleset 13 Jul 2004 08:00:02 -0000
@@ -277,7 +277,7 @@
 is_wonder      = 0
 build_cost     = 120
 upkeep         = 2
-sabotage       = 100
+sabotage       = 50
 effect         =
     { "type", "range", "amount", "aff_unit"
        "Unit_Defend", "City", 300, "Helicopter"
Index: data/civ2/buildings.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ2/buildings.ruleset,v
retrieving revision 1.36
diff -u -r1.36 buildings.ruleset
--- data/civ2/buildings.ruleset 30 Sep 2003 23:20:10 -0000      1.36
+++ data/civ2/buildings.ruleset 13 Jul 2004 08:00:03 -0000
@@ -259,7 +259,7 @@
 is_wonder      = 0
 build_cost     = 80
 upkeep         = 0
-sabotage       = 100
+sabotage       = 50
 effect         =
     { "type", "range", "amount", "cond_bldg", "aff_unit"
        "Unit_Defend", "City", 300, "", "Land"
Index: data/default/buildings.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/buildings.ruleset,v
retrieving revision 1.45
diff -u -r1.45 buildings.ruleset
--- data/default/buildings.ruleset      13 May 2004 18:17:37 -0000      1.45
+++ data/default/buildings.ruleset      13 Jul 2004 08:00:04 -0000
@@ -306,7 +306,7 @@
 is_wonder      = 0
 build_cost     = 60
 upkeep         = 0
-sabotage       = 100
+sabotage       = 50
 effect         =
     { "type", "range", "amount", "cond_bldg", "aff_unit"
        "Unit_Defend", "City", 300, "", "Land"
Index: data/history/buildings.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/buildings.ruleset,v
retrieving revision 1.7
diff -u -r1.7 buildings.ruleset
--- data/history/buildings.ruleset      30 Sep 2003 23:20:10 -0000      1.7
+++ data/history/buildings.ruleset      13 Jul 2004 08:00:05 -0000
@@ -259,7 +259,7 @@
 is_wonder      = 0
 build_cost     = 80
 upkeep         = 0
-sabotage       = 100
+sabotage       = 50
 effect         =
     { "type", "range", "amount", "cond_bldg", "aff_unit"
        "Unit_Defend", "City", 300, "", "Land"
Index: server/diplomats.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v
retrieving revision 1.56
diff -u -r1.56 diplomats.c
--- server/diplomats.c  14 Apr 2004 10:14:39 -0000      1.56
+++ server/diplomats.c  13 Jul 2004 08:00:05 -0000
@@ -870,7 +870,6 @@
   struct player *cplayer;
   int count, which, target;
   const char *prod;
-  struct city *capital;
 
   /* Fetch target city's player.  Sanity checks. */
   if (!pcity)
@@ -915,7 +914,7 @@
   /* Examine the city for improvements to sabotage. */
   count = 0;
   built_impr_iterate(pcity, index) {
-    if (!is_wonder(index) && index != B_PALACE) {
+    if (get_improvement_type(index)->sabotage > 0) {
       count++;
     }
   } built_impr_iterate_end;
@@ -952,7 +951,7 @@
       which = myrand (count);
 
       built_impr_iterate(pcity, index) {
-       if (!is_wonder(index) && index != B_PALACE) {
+       if (get_improvement_type(index)->sabotage > 0) {
          if (which > 0) {
            which--;
          } else {
@@ -972,14 +971,14 @@
      * If not available, say so, deduct movement cost and return.
      */
     if (city_got_building (pcity, improvement)) {
-      if ((!is_wonder (improvement)) && (improvement != B_PALACE)) {
+      if (get_improvement_type(improvement)->sabotage > 0) {
        target = improvement;
        freelog (LOG_DEBUG, "sabotage: specified target improvement: %d (%s)",
               target, get_improvement_name (target));
       } else {
        notify_player_ex(pplayer, pcity->x, pcity->y, E_MY_DIPLOMAT_FAILED,
-                        _("Game: You cannot sabotage a wonder or a %s!"),
-                        improvement_types[B_PALACE].name);
+                        _("Game: You cannot sabotage a %s!"),
+                        improvement_types[improvement].name);
        diplomat_charge_movement (pdiplomat, pcity->x, pcity->y);
        send_unit_info (pplayer, pdiplomat);
        freelog (LOG_DEBUG, "sabotage: disallowed target improvement: %d (%s)",
@@ -1022,6 +1021,8 @@
                     get_nation_name_plural(pplayer->nation));
     freelog (LOG_DEBUG, "sabotage: sabotaged production");
   } else {
+    int vulnerability;
+
     /* Sabotage a city improvement. */
 
     /*
@@ -1029,24 +1030,25 @@
      * If target was specified, and it is in the capital or are
      * City Walls, then there is a 50% chance of getting caught.
      */
-    capital = find_palace (city_owner (pcity));
-    if ((pcity == capital) || (improvement == B_CITY)) {
-      if (myrand (2) == 1) {
-       /* Caught! */
-       notify_player_ex(pplayer, pcity->x, pcity->y, E_MY_DIPLOMAT_FAILED,
-                        _("Game: Your %s was caught in the attempt"
-                          " of sabotage!"), unit_name(pdiplomat->type));
-       notify_player_ex(cplayer, pcity->x, pcity->y,
-                        E_ENEMY_DIPLOMAT_FAILED,
-                        _("Game: You caught %s %s attempting"
-                          " to sabotage the %s in %s!"),
-                        get_nation_name(pplayer->nation),
-                        unit_name(pdiplomat->type),
-                        get_improvement_name(improvement), pcity->name);
-       wipe_unit(pdiplomat);
-       freelog (LOG_DEBUG, "sabotage: caught in capital or on city walls");
-       return;
-      }
+    vulnerability = get_improvement_type(improvement)->sabotage;
+    if (city_got_building(pcity, B_CAPITAL)) {
+      vulnerability /= 2;
+    }
+    if (myrand(100) >= vulnerability) {
+      /* Caught! */
+      notify_player_ex(pplayer, pcity->x, pcity->y, E_MY_DIPLOMAT_FAILED,
+                      _("Game: Your %s was caught in the attempt"
+                        " of sabotage!"), unit_name(pdiplomat->type));
+      notify_player_ex(cplayer, pcity->x, pcity->y,
+                      E_ENEMY_DIPLOMAT_FAILED,
+                      _("Game: You caught %s %s attempting"
+                        " to sabotage the %s in %s!"),
+                      get_nation_name(pplayer->nation),
+                      unit_name(pdiplomat->type),
+                      get_improvement_name(improvement), pcity->name);
+      wipe_unit(pdiplomat);
+      freelog (LOG_DEBUG, "sabotage: caught in capital or on city walls");
+      return;
     }
 
     /* Report it. */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9362) use impr->sabotage value, Jason Dorje Short <=