Author: cazfi
Date: Mon Mar  2 20:32:40 2015
New Revision: 28365

URL: http://svn.gna.org/viewcvs/freeciv?rev=28365&view=rev
Log:
Check _Possible effects before claiming that terrain modifications are possible 
for a terrain
in its help.

See patch #5859

Modified:
    branches/S2_6/client/gui-gtk-2.0/helpdlg.c
    branches/S2_6/client/gui-gtk-3.0/helpdlg.c
    branches/S2_6/client/gui-qt/helpdlg.cpp
    branches/S2_6/client/helpdata.c
    branches/S2_6/common/requirements.c

Modified: branches/S2_6/client/gui-gtk-2.0/helpdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/helpdlg.c?rev=28365&r1=28364&r2=28365&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/helpdlg.c  (original)
+++ branches/S2_6/client/gui-gtk-2.0/helpdlg.c  Mon Mar  2 20:32:40 2015
@@ -1094,6 +1094,8 @@
   create_help_page(HELP_TERRAIN);
 
   if (pterrain) {
+    struct universal for_terr = { .kind = VUT_TERRAIN, .value = { .terrain = 
pterrain }};
+
     sprintf(buf, "%d/%d.%d",
            pterrain->movement_cost,
            (int)((pterrain->defense_bonus + 100) / 100),
@@ -1127,38 +1129,47 @@
 
     strcpy(buf, _("n/a"));
     if (pterrain->irrigation_result == pterrain) {
-      if (pterrain->irrigation_food_incr > 0) {
-       sprintf(buf, _("+%d Food / %d"),
-               pterrain->irrigation_food_incr,
-               pterrain->irrigation_time);
+      if (effect_cumulative_max(EFT_IRRIG_POSSIBLE, &for_terr) > 0) {
+        if (pterrain->irrigation_food_incr > 0) {
+          sprintf(buf, _("+%d Food / %d"),
+                  pterrain->irrigation_food_incr,
+                  pterrain->irrigation_time);
+        }
       }
     } else if (pterrain->irrigation_result != T_NONE) {
-      sprintf(buf, "%s / %d",
-             terrain_name_translation(pterrain->irrigation_result),
-             pterrain->irrigation_time);
+      if (effect_cumulative_max(EFT_IRRIG_TF_POSSIBLE, &for_terr) > 0) {
+        sprintf(buf, "%s / %d",
+                terrain_name_translation(pterrain->irrigation_result),
+                pterrain->irrigation_time);
+      }
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[2][1]), buf);
 
     strcpy(buf, _("n/a"));
     if (pterrain->mining_result == pterrain) {
-      if (pterrain->mining_shield_incr > 0) {
-       sprintf(buf, _("+%d Res. / %d"),
-               pterrain->mining_shield_incr,
-               pterrain->mining_time);
+      if (effect_cumulative_max(EFT_MINING_POSSIBLE, &for_terr) > 0) {
+        if (pterrain->mining_shield_incr > 0) {
+          sprintf(buf, _("+%d Res. / %d"),
+                  pterrain->mining_shield_incr,
+                  pterrain->mining_time);
+        }
       }
     } else if (pterrain->mining_result != T_NONE) {
-      sprintf(buf, "%s / %d",
-             terrain_name_translation(pterrain->mining_result),
-             pterrain->mining_time);
+      if (effect_cumulative_max(EFT_MINING_TF_POSSIBLE, &for_terr) > 0) {
+        sprintf(buf, "%s / %d",
+                terrain_name_translation(pterrain->mining_result),
+                pterrain->mining_time);
+      }
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[2][4]), buf);
 
+    strcpy(buf, "n/a");
     if (pterrain->transform_result != T_NONE) {
-      sprintf(buf, "%s / %d",
-             terrain_name_translation(pterrain->transform_result),
-             pterrain->transform_time);
-    } else {
-      strcpy(buf, "n/a");
+      if (effect_cumulative_max(EFT_TRANSFORM_POSSIBLE, &for_terr) > 0) {
+        sprintf(buf, "%s / %d",
+                terrain_name_translation(pterrain->transform_result),
+                pterrain->transform_time);
+      }
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[3][1]), buf);
   }

Modified: branches/S2_6/client/gui-gtk-3.0/helpdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/helpdlg.c?rev=28365&r1=28364&r2=28365&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/helpdlg.c  (original)
+++ branches/S2_6/client/gui-gtk-3.0/helpdlg.c  Mon Mar  2 20:32:40 2015
@@ -1119,6 +1119,8 @@
   create_help_page(HELP_TERRAIN);
 
   if (pterrain) {
+    struct universal for_terr = { .kind = VUT_TERRAIN, .value = { .terrain = 
pterrain }};
+
     sprintf(buf, "%d/%d.%d",
            pterrain->movement_cost,
            (int)((pterrain->defense_bonus + 100) / 100),
@@ -1152,38 +1154,47 @@
 
     strcpy(buf, _("n/a"));
     if (pterrain->irrigation_result == pterrain) {
-      if (pterrain->irrigation_food_incr > 0) {
-       sprintf(buf, _("+%d Food / %d"),
-               pterrain->irrigation_food_incr,
-               pterrain->irrigation_time);
+      if (effect_cumulative_max(EFT_IRRIG_POSSIBLE, &for_terr) > 0) {
+        if (pterrain->irrigation_food_incr > 0) {
+          sprintf(buf, _("+%d Food / %d"),
+                  pterrain->irrigation_food_incr,
+                  pterrain->irrigation_time);
+        }
       }
     } else if (pterrain->irrigation_result != T_NONE) {
-      sprintf(buf, "%s / %d",
-             terrain_name_translation(pterrain->irrigation_result),
-             pterrain->irrigation_time);
+      if (effect_cumulative_max(EFT_IRRIG_TF_POSSIBLE, &for_terr) > 0) {
+        sprintf(buf, "%s / %d",
+                terrain_name_translation(pterrain->irrigation_result),
+                pterrain->irrigation_time);
+      }
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[2][1]), buf);
 
     strcpy(buf, _("n/a"));
     if (pterrain->mining_result == pterrain) {
-      if (pterrain->mining_shield_incr > 0) {
-       sprintf(buf, _("+%d Res. / %d"),
-               pterrain->mining_shield_incr,
-               pterrain->mining_time);
+      if (effect_cumulative_max(EFT_MINING_POSSIBLE, &for_terr) > 0) {
+        if (pterrain->mining_shield_incr > 0) {
+          sprintf(buf, _("+%d Res. / %d"),
+                  pterrain->mining_shield_incr,
+                  pterrain->mining_time);
+        }
       }
     } else if (pterrain->mining_result != T_NONE) {
-      sprintf(buf, "%s / %d",
-             terrain_name_translation(pterrain->mining_result),
-             pterrain->mining_time);
+      if (effect_cumulative_max(EFT_MINING_TF_POSSIBLE, &for_terr) > 0) {
+        sprintf(buf, "%s / %d",
+                terrain_name_translation(pterrain->mining_result),
+                pterrain->mining_time);
+      }
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[2][4]), buf);
 
+    strcpy(buf, "n/a");
     if (pterrain->transform_result != T_NONE) {
-      sprintf(buf, "%s / %d",
-             terrain_name_translation(pterrain->transform_result),
-             pterrain->transform_time);
-    } else {
-      strcpy(buf, "n/a");
+      if (effect_cumulative_max(EFT_TRANSFORM_POSSIBLE, &for_terr) > 0) {
+        sprintf(buf, "%s / %d",
+                terrain_name_translation(pterrain->transform_result),
+                pterrain->transform_time);
+      }
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[3][1]), buf);
   }

Modified: branches/S2_6/client/gui-qt/helpdlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/helpdlg.cpp?rev=28365&r1=28364&r2=28365&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/helpdlg.cpp     (original)
+++ branches/S2_6/client/gui-qt/helpdlg.cpp     Mon Mar  2 20:32:40 2015
@@ -806,6 +806,11 @@
 
   pterrain = terrain_by_translated_name(title);
   if (pterrain) {
+    struct universal for_terr;
+
+    for_terr.kind = VUT_TERRAIN;
+    for_terr.value.terrain = pterrain;
+
     helptext_terrain(buffer, sizeof(buffer), client.conn.playing,
                      topic->text, pterrain);
     text_browser->setText(buffer);
@@ -838,60 +843,70 @@
     add_info_separator();
 
     if (pterrain->irrigation_result == pterrain) {
-      add_info_label(
-        // TRANS: When irrigated, terrain gets a bonus of %1 food;
-        //        irrigating takes %2 turns
-        QString(_(ngettext(
-          "Irrigation: +%1 food in %2 turn",
-          "Irrigation: +%1 food in %2 turns",
-          pterrain->irrigation_time)))
-        .arg(pterrain->irrigation_food_incr)
-        .arg(pterrain->irrigation_time));
+      if (effect_cumulative_max(EFT_IRRIG_POSSIBLE, &for_terr) > 0) {
+        add_info_label(
+          // TRANS: When irrigated, terrain gets a bonus of %1 food;
+          //        irrigating takes %2 turns
+          QString(_(ngettext(
+            "Irrigation: +%1 food in %2 turn",
+            "Irrigation: +%1 food in %2 turns",
+            pterrain->irrigation_time)))
+          .arg(pterrain->irrigation_food_incr)
+          .arg(pterrain->irrigation_time));
+      }
     } else if (pterrain->irrigation_result) {
-      add_info_label(
-        // TRANS: When irrigated, terrain gets changed to other terrain %1
-        //        in %2 turns
-        QString(_(ngettext(
-          "Irrigation: %1 in %2 turn",
-          "Irrigation: %1 in %2 turns",
-          pterrain->irrigation_time)))
-        .arg(terrain_name_translation(pterrain->irrigation_result))
-        .arg(pterrain->irrigation_time));
+      if (effect_cumulative_max(EFT_IRRIG_TF_POSSIBLE, &for_terr) > 0) {
+        add_info_label(
+          // TRANS: When irrigated, terrain gets changed to other terrain %1
+          //        in %2 turns
+          QString(_(ngettext(
+            "Irrigation: %1 in %2 turn",
+            "Irrigation: %1 in %2 turns",
+            pterrain->irrigation_time)))
+          .arg(terrain_name_translation(pterrain->irrigation_result))
+          .arg(pterrain->irrigation_time));
+      }
     }
 
     if (pterrain->mining_result == pterrain) {
-      add_info_label(
-        // TRANS: When mined, terrain gets a bonus of %1 food; mining takes
-        //        %2 turns
-        QString(_(ngettext(
-          "Mining: +%1 food in %2 turn",
-          "Mining: +%1 food in %2 turns",
-          pterrain->mining_time)))
-        .arg(pterrain->mining_shield_incr)
-        .arg(pterrain->mining_time));
+      if (effect_cumulative_max(EFT_MINING_POSSIBLE, &for_terr) > 0) {
+        add_info_label(
+          // TRANS: When mined, terrain gets a bonus of %1 food; mining takes
+          //        %2 turns
+          QString(_(ngettext(
+            "Mining: +%1 food in %2 turn",
+            "Mining: +%1 food in %2 turns",
+            pterrain->mining_time)))
+          .arg(pterrain->mining_shield_incr)
+          .arg(pterrain->mining_time));
+      }
     } else if (pterrain->mining_result) {
-      add_info_label(
-        // TRANS: When mined, terrain gets changed to other terrain %1
-        //        in %2 turns
-        QString(_(ngettext(
-          "Mining: %1 in %2 turn",
-          "Mining: %1 in %2 turns",
-          pterrain->mining_time)))
-        .arg(terrain_name_translation(pterrain->mining_result))
-        .arg(pterrain->mining_time));
+      if (effect_cumulative_max(EFT_MINING_TF_POSSIBLE, &for_terr) > 0) {
+        add_info_label(
+          // TRANS: When mined, terrain gets changed to other terrain %1
+          //        in %2 turns
+          QString(_(ngettext(
+            "Mining: %1 in %2 turn",
+            "Mining: %1 in %2 turns",
+            pterrain->mining_time)))
+          .arg(terrain_name_translation(pterrain->mining_result))
+          .arg(pterrain->mining_time));
+      }
     }
 
     if (pterrain->transform_result &&
         pterrain->transform_result != pterrain) {
-      add_info_label(
-        // TRANS: When transformed, terrain gets changed to other terrain %1
-        //        in %2 turns
-        QString(_(ngettext(
-          "Transform: %1 in %2 turn",
-          "Transform: %1 in %2 turns",
-          pterrain->transform_time)))
-        .arg(terrain_name_translation(pterrain->transform_result))
-        .arg(pterrain->transform_time));
+      if (effect_cumulative_max(EFT_TRANSFORM_POSSIBLE, &for_terr) > 0) {
+        add_info_label(
+          // TRANS: When transformed, terrain gets changed to other terrain %1
+          //        in %2 turns
+          QString(_(ngettext(
+            "Transform: %1 in %2 turn",
+            "Transform: %1 in %2 turns",
+            pterrain->transform_time)))
+          .arg(terrain_name_translation(pterrain->transform_result))
+          .arg(pterrain->transform_time));
+      }
     }
 
     info_panel_done();

Modified: branches/S2_6/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/helpdata.c?rev=28365&r1=28364&r2=28365&view=diff
==============================================================================
--- branches/S2_6/client/helpdata.c     (original)
+++ branches/S2_6/client/helpdata.c     Mon Mar  2 20:32:40 2015
@@ -221,6 +221,7 @@
         char irrigation_time[4], mining_time[4], transform_time[4];
         const char *terrain, *irrigation_result,
                    *mining_result,*transform_result;
+        struct universal for_terr = { .kind = VUT_TERRAIN, .value = { .terrain 
= pterrain }};
 
         fc_snprintf(irrigation_time, sizeof(irrigation_time),
                     "%d", pterrain->irrigation_time);
@@ -231,15 +232,18 @@
         terrain = terrain_name_translation(pterrain);
         irrigation_result = 
           (pterrain->irrigation_result == pterrain
-           || pterrain->irrigation_result == T_NONE) ? ""
+           || pterrain->irrigation_result == T_NONE
+           || effect_cumulative_max(EFT_IRRIG_TF_POSSIBLE, &for_terr) <= 0) ? 
""
           : terrain_name_translation(pterrain->irrigation_result);
         mining_result =
           (pterrain->mining_result == pterrain
-           || pterrain->mining_result == T_NONE) ? ""
+           || pterrain->mining_result == T_NONE
+           || effect_cumulative_max(EFT_MINING_TF_POSSIBLE, &for_terr) <= 0) ? 
""
           : terrain_name_translation(pterrain->mining_result);
         transform_result =
           (pterrain->transform_result == pterrain
-           || pterrain->transform_result == T_NONE) ? ""
+           || pterrain->transform_result == T_NONE
+           || effect_cumulative_max(EFT_TRANSFORM_POSSIBLE, &for_terr) <= 0) ? 
""
           : terrain_name_translation(pterrain->transform_result);
         /* Use get_internal_string_length() for correct alignment with
          * multibyte character encodings */
@@ -2721,7 +2725,7 @@
   /* need to do something like this or bad things happen */
   popdown_help_dialog();
 
-  if(!booted) {
+  if (!booted) {
     log_verbose("Booting help texts");
   } else {
     /* free memory allocated last time booted */
@@ -2757,8 +2761,8 @@
         if (!booted) {
           continue; /* on initial boot data tables are empty */
         }
-        for(i=2; help_type_names[i]; i++) {
-          if(strcmp(gen_str, help_type_names[i])==0) {
+        for (i = 2; help_type_names[i]; i++) {
+          if (strcmp(gen_str, help_type_names[i]) == 0) {
             current_type = i;
             break;
           }

Modified: branches/S2_6/common/requirements.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/requirements.c?rev=28365&r1=28364&r2=28365&view=diff
==============================================================================
--- branches/S2_6/common/requirements.c (original)
+++ branches/S2_6/common/requirements.c Mon Mar  2 20:32:40 2015
@@ -3346,6 +3346,29 @@
   };
 }
 
+/*************************************************************************
+  Find if a terrain type fulfills a requirement
+**************************************************************************/
+static enum item_found terrain_type_found(const struct requirement *preq,
+                                          const struct universal *source)
+{
+  fc_assert(source->value.terrain);
+
+  switch (preq->source.kind) {
+  case VUT_TERRAIN:
+    return source->value.terrain == preq->source.value.terrain ? ITF_YES : 
ITF_NO;
+  case VUT_TERRAINCLASS:
+    return terrain_type_terrain_class(source->value.terrain) == 
preq->source.value.terrainclass
+      ? ITF_YES : ITF_NO;
+  case VUT_TERRFLAG:
+    return terrain_has_flag(source->value.terrain,
+                            preq->source.value.terrainflag) ? ITF_YES : ITF_NO;
+  default:
+    /* Not found and not relevant. */
+    return ITF_NOT_APPLICABLE;
+  };
+}
+
 /************************************************************************
   Initialise universal_found_callbacks array.
 *************************************************************************/
@@ -3355,6 +3378,7 @@
   universal_found_function[VUT_IMPROVEMENT] = &improvement_found;
   universal_found_function[VUT_UCLASS] = &unit_class_found;
   universal_found_function[VUT_UTYPE] = &unit_type_found;
+  universal_found_function[VUT_TERRAIN] = &terrain_type_found;
 }
 
 /**************************************************************************


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

Reply via email to