Author: cazfi
Date: Thu Feb 12 06:23:18 2015
New Revision: 28103

URL: http://svn.gna.org/viewcvs/freeciv?rev=28103&view=rev
Log:
Check that relevant "_Possible" effect is ever enabled to the particular unit 
type before
help claims that it can do the activity.

Requested by Jacob Nevins <jtn>

See patch #5006

Modified:
    branches/S2_5/client/helpdata.c
    branches/S2_5/common/city.c
    branches/S2_5/common/effects.c
    branches/S2_5/common/effects.h

Modified: branches/S2_5/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/helpdata.c?rev=28103&r1=28102&r2=28103&view=diff
==============================================================================
--- branches/S2_5/client/helpdata.c     (original)
+++ branches/S2_5/client/helpdata.c     Thu Feb 12 06:23:18 2015
@@ -2630,15 +2630,14 @@
       }
     } road_type_iterate_end;
 
-    /* TODO: Check also that specific unit fulfills the requirements of the 
effects */
-    if (effect_cumulative_max(EFT_MINING_POSSIBLE) > 0) {
+    if (effect_cumulative_max(EFT_MINING_POSSIBLE, utype) > 0) {
       CATLSTR(buf, bufsz, _("* Can build mines on tiles.\n"));
     }
-    if (effect_cumulative_max(EFT_MINING_TF_POSSIBLE) > 0) {
+    if (effect_cumulative_max(EFT_MINING_TF_POSSIBLE, utype) > 0) {
       CATLSTR(buf, bufsz, _("* Can mine terrain to another.\n"));
     }
 
-    if (effect_cumulative_max(EFT_IRRIG_POSSIBLE) > 0) {
+    if (effect_cumulative_max(EFT_IRRIG_POSSIBLE, utype) > 0) {
       CATLSTR(buf, bufsz, _("* Can build irrigation on tiles.\n"));
       /* Farmland. */
       switch (techs_with_flag_string(buf2, sizeof(buf2), pplayer, 
TF_FARMLAND)) {
@@ -2656,7 +2655,7 @@
         break;
       }
     }
-    if (effect_cumulative_max(EFT_IRRIG_TF_POSSIBLE) > 0) {
+    if (effect_cumulative_max(EFT_IRRIG_TF_POSSIBLE, utype) > 0) {
       CATLSTR(buf, bufsz, _("* Can irrigate terrain to another.\n"));
     }
 

Modified: branches/S2_5/common/city.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/city.c?rev=28103&r1=28102&r2=28103&view=diff
==============================================================================
--- branches/S2_5/common/city.c (original)
+++ branches/S2_5/common/city.c Thu Feb 12 06:23:18 2015
@@ -153,7 +153,7 @@
 int rs_max_city_radius_sq(void)
 {
   int max_rad = game.info.init_city_radius_sq
-    + effect_cumulative_max(EFT_CITY_RADIUS_SQ);
+    + effect_cumulative_max(EFT_CITY_RADIUS_SQ, NULL);
 
   return MIN(max_rad, CITY_MAP_MAX_RADIUS_SQ);
 }

Modified: branches/S2_5/common/effects.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/effects.c?rev=28103&r1=28102&r2=28103&view=diff
==============================================================================
--- branches/S2_5/common/effects.c      (original)
+++ branches/S2_5/common/effects.c      Thu Feb 12 06:23:18 2015
@@ -294,17 +294,63 @@
 }
 
 /****************************************************************************
-  Get the maximum effect value in this ruleset.
+  Get the maximum effect value in this ruleset for the unit type.
+  Universal can be NULL to get overall max
 ****************************************************************************/
-int effect_cumulative_max(enum effect_type type)
+int effect_cumulative_max(enum effect_type type, struct unit_type *for_unit)
 {
   struct effect_list *plist = ruleset_cache.tracker;
   int value = 0;
 
   if (plist) {
+    struct unit_class *pclass = NULL;
+
+    if (for_unit != NULL) {
+      pclass = utype_class(for_unit);
+    }
+
     effect_list_iterate(plist, peffect) {
       if (peffect->type == type && peffect->value > 0) {
-        value += peffect->value;
+        if (for_unit == NULL) {
+          value += peffect->value;
+        } else {
+          bool failed = FALSE;
+
+          requirement_list_iterate(peffect->reqs, preq) {
+            if (preq->source.kind == VUT_UTYPE) {
+              if (preq->source.value.utype == for_unit) {
+                failed |= preq->negated;
+              } else {
+                failed |= (!preq->negated);
+              }
+            } else if (preq->source.kind == VUT_UCLASS) {
+              if (preq->source.value.uclass == pclass) {
+                failed |= preq->negated;
+              } else {
+                failed |= (!preq->negated);
+              }
+            }
+          } requirement_list_iterate_end;
+          requirement_list_iterate(peffect->nreqs, preq) {
+            if (preq->source.kind == VUT_UTYPE) {
+              if (preq->source.value.utype == for_unit) {
+                failed |= (!preq->negated);
+              } else {
+                failed |= preq->negated;
+              }
+            } else if (preq->source.kind == VUT_UCLASS) {
+              if (preq->source.value.uclass == pclass) {
+                failed |= (!preq->negated);
+              } else {
+                failed |= preq->negated;
+              }
+            }
+          } requirement_list_iterate_end;
+
+          if (!failed) {
+            value += peffect->value;
+          }
+        }
       }
     } effect_list_iterate_end;
   }
@@ -313,17 +359,63 @@
 }
 
 /****************************************************************************
-  Get the minimum effect value in this ruleset.
+  Get the minimum effect value in this ruleset for the unit type.
+  Universal can be NULL for the overall minimum
 ****************************************************************************/
-int effect_cumulative_min(enum effect_type type)
+int effect_cumulative_min(enum effect_type type, struct unit_type *for_unit)
 {
   struct effect_list *plist = ruleset_cache.tracker;
   int value = 0;
 
   if (plist) {
+    struct unit_class *pclass = NULL;
+
+    if (for_unit != NULL) {
+      pclass = utype_class(for_unit);
+    }
+
     effect_list_iterate(plist, peffect) {
       if (peffect->type == type && peffect->value < 0) {
-        value += peffect->value;
+        if (for_unit == NULL) {
+          value += peffect->value;
+        } else {
+          bool failed = FALSE;
+
+          requirement_list_iterate(peffect->reqs, preq) {
+            if (preq->source.kind == VUT_UTYPE) {
+              if (preq->source.value.utype == for_unit) {
+                failed |= preq->negated;
+              } else {
+                failed |= (!preq->negated);
+              }
+            } else if (preq->source.kind == VUT_UCLASS) {
+              if (preq->source.value.uclass == pclass) {
+                failed |= preq->negated;
+              } else {
+                failed |= (!preq->negated);
+              }
+            }
+          } requirement_list_iterate_end;
+          requirement_list_iterate(peffect->nreqs, preq) {
+            if (preq->source.kind == VUT_UTYPE) {
+              if (preq->source.value.utype == for_unit) {
+                failed |= (!preq->negated);
+              } else {
+                failed |= preq->negated;
+              }
+            } else if (preq->source.kind == VUT_UCLASS) {
+              if (preq->source.value.uclass == pclass) {
+                failed |= (!preq->negated);
+              } else {
+                failed |= preq->negated;
+              }
+            }
+          } requirement_list_iterate_end;
+
+          if (!failed) {
+            value += peffect->value;
+          }
+        }
       }
     } effect_list_iterate_end;
   }

Modified: branches/S2_5/common/effects.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/effects.h?rev=28103&r1=28102&r2=28103&view=diff
==============================================================================
--- branches/S2_5/common/effects.h      (original)
+++ branches/S2_5/common/effects.h      Thu Feb 12 06:23:18 2015
@@ -294,8 +294,8 @@
 void recv_ruleset_effect_req(const struct packet_ruleset_effect_req *packet);
 void send_ruleset_cache(struct conn_list *dest);
 
-int effect_cumulative_max(enum effect_type type);
-int effect_cumulative_min(enum effect_type type);
+int effect_cumulative_max(enum effect_type type, struct unit_type *for_unit);
+int effect_cumulative_min(enum effect_type type, struct unit_type *for_unit);
 
 bool is_effect_useful(const struct player *target_player,
                      const struct city *target_pcity,


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to