Author: cazfi
Date: Thu Feb 12 06:23:02 2015
New Revision: 28101

URL: http://svn.gna.org/viewcvs/freeciv?rev=28101&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:
    trunk/client/helpdata.c
    trunk/common/city.c
    trunk/common/effects.c
    trunk/common/effects.h

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=28101&r1=28100&r2=28101&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Thu Feb 12 06:23:02 2015
@@ -3683,6 +3683,8 @@
                 game.info.add_to_size_limit - utype_pop_value(utype));
   }
   if (utype_has_flag(utype, UTYF_SETTLERS)) {
+    struct universal for_utype = { .kind = VUT_UTYPE, .value = { .utype = 
utype }};
+
     /* Roads, rail, mines, irrigation. */
     extra_type_by_cause_iterate(EC_ROAD, pextra) {
       if (help_is_extra_buildable(pextra, utype)) {
@@ -3691,8 +3693,7 @@
       }
     } extra_type_by_cause_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, &for_utype) > 0) {
       extra_type_by_cause_iterate(EC_MINE, pextra) {
         if (help_is_extra_buildable(pextra, utype)) {
           cat_snprintf(buf, bufsz, _("* Can build %s on tiles.\n"),
@@ -3700,11 +3701,11 @@
         }
       } extra_type_by_cause_iterate_end;
     }
-    if (effect_cumulative_max(EFT_MINING_TF_POSSIBLE) > 0) {
+    if (effect_cumulative_max(EFT_MINING_TF_POSSIBLE, &for_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, &for_utype) > 0) {
       extra_type_by_cause_iterate(EC_IRRIGATION, pextra) {
         if (help_is_extra_buildable(pextra, utype)) {
           cat_snprintf(buf, bufsz, _("* Can build %s on tiles.\n"),
@@ -3712,7 +3713,7 @@
         }
       } extra_type_by_cause_iterate_end;
     }
-    if (effect_cumulative_max(EFT_IRRIG_TF_POSSIBLE) > 0) {
+    if (effect_cumulative_max(EFT_IRRIG_TF_POSSIBLE, &for_utype) > 0) {
       CATLSTR(buf, bufsz, _("* Can irrigate terrain to another.\n"));
     }
 

Modified: trunk/common/city.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/city.c?rev=28101&r1=28100&r2=28101&view=diff
==============================================================================
--- trunk/common/city.c (original)
+++ trunk/common/city.c Thu Feb 12 06:23:02 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: trunk/common/effects.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/effects.c?rev=28101&r1=28100&r2=28101&view=diff
==============================================================================
--- trunk/common/effects.c      (original)
+++ trunk/common/effects.c      Thu Feb 12 06:23:02 2015
@@ -285,9 +285,10 @@
 }
 
 /****************************************************************************
-  Get the maximum effect value in this ruleset.
+  Get the maximum effect value in this ruleset for the universal.
+  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 universal *for_uni)
 {
   struct effect_list *plist = ruleset_cache.tracker;
   int value = 0;
@@ -295,7 +296,10 @@
   if (plist) {
     effect_list_iterate(plist, peffect) {
       if (peffect->type == type && peffect->value > 0) {
-        value += peffect->value;
+        if (for_uni == NULL
+            || universal_fulfills_requirement(FALSE, &(peffect->reqs), 
for_uni)) {
+          value += peffect->value;
+        }
       }
     } effect_list_iterate_end;
   }
@@ -304,9 +308,10 @@
 }
 
 /****************************************************************************
-  Get the minimum effect value in this ruleset.
+  Get the minimum effect value in this ruleset for the universal.
+  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 universal *for_uni)
 {
   struct effect_list *plist = ruleset_cache.tracker;
   int value = 0;
@@ -314,7 +319,10 @@
   if (plist) {
     effect_list_iterate(plist, peffect) {
       if (peffect->type == type && peffect->value < 0) {
-        value += peffect->value;
+        if (for_uni == NULL
+            || universal_fulfills_requirement(FALSE, &(peffect->reqs), 
for_uni)) {
+          value += peffect->value;
+        }
       }
     } effect_list_iterate_end;
   }

Modified: trunk/common/effects.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/effects.h?rev=28101&r1=28100&r2=28101&view=diff
==============================================================================
--- trunk/common/effects.h      (original)
+++ trunk/common/effects.h      Thu Feb 12 06:23:02 2015
@@ -321,8 +321,8 @@
 void recv_ruleset_effect(const struct packet_ruleset_effect *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 universal *for_uni);
+int effect_cumulative_min(enum effect_type type, struct universal *for_uni);
 
 bool is_building_replaced(const struct city *pcity,
                          struct impr_type *pimprove,


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

Reply via email to