Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10153) show requirements met by buildings
Home

[Freeciv-Dev] (PR#10153) show requirements met by buildings

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10153) show requirements met by buildings
From: "Jason Short via RT" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 16 Sep 2004 19:01:31 -0700
Reply-to: RT_CorrespondAddressNotSet@xxxxxxxxxxxxxx

<URL: http://RT::WebBaseURL.not.configured:80/Ticket/Display.html?id=10153 >

This patch changes helptext_building to show the requirements met by the
building.  It is best explained by looking at the attached screenshot
(made with a modified ruleset of course).

There's a problem with this kind of thing in general.  As an example,
the clients currently use a GUI interface to show the allowances
provided by technologies.  But this won't show up in the autogenerated
manual because it's not found by helptext_tech.  By contrast for
buildings the allowances are put in the text, but will not be
cross-referenced by the GUI.  I'm not sure how to fix this in the long
run.  One option is to pass a "show_reqs" parameter to the helptext
function (if set, both allowances and reqs are shown).  Another option
is for the GUI to search the strings to find linkable text, and
cross-reference directly (which is probably what the manual generator
should do).

Two side notes:

- Improvements have bldg_reqs, units have impr_reqs.  Bad.  The unittype
fields should be renamed.

- Items (techs, terrains, units, buildings, specials, governments)
shouldn't have any duplicated names.  This prevents general confusion
and allows cross-referencing by text to work.

jason

? drawn_sprites.diff
? freeciv.spec
? ftwl.diff
? settler_recursion_crash
? client/tilespec.diff
Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.80
diff -u -r1.80 helpdata.c
--- client/helpdata.c   16 Sep 2004 09:19:06 -0000      1.80
+++ client/helpdata.c   17 Sep 2004 01:45:44 -0000
@@ -509,6 +509,18 @@
   assert(buf);
   buf[0] = '\0';
 
+  if (imp->helptext && imp->helptext[0] != '\0') {
+    my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
+               "%s\n\n", _(imp->helptext));
+  }
+
+  if (tech_exists(improvement_types[which].obsolete_by)) {
+    my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
+               _("* The discovery of %s will make %s obsolete.\n"),
+               advances[improvement_types[which].obsolete_by].name,
+               improvement_types[which].name);
+  }
+
   if (building_has_effect(which, EFT_ENABLE_NUKE)
       && num_role_units(F_NUCLEAR) > 0) {
     Unit_Type_id u;
@@ -520,25 +532,62 @@
     assert(t < game.num_tech_types);
 
     my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-               _("Allows all players with knowledge of %s "
-                 "to build %s units."),
+               _("* Allows all players with knowledge of %s "
+                 "to build %s units.\n"),
                advances[t].name, get_unit_type(u)->name);
     my_snprintf(buf + strlen(buf), bufsz - strlen(buf), "  ");
   }
 
-  if (imp->helptext && imp->helptext[0] != '\0') {
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-               "%s  ", _(imp->helptext));
-  }
+  impr_type_iterate(impr) {
+    const struct impr_type *b = get_improvement_type(impr);
 
-  if (tech_exists(improvement_types[which].obsolete_by)) {
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf), "\n\n");
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
-               _("The discovery of %s will make %s obsolete."),
-               advances[improvement_types[which].obsolete_by].name,
-               improvement_types[which].name);
-    my_snprintf(buf + strlen(buf), bufsz - strlen(buf), "  ");
-  }
+    if (improvement_exists(impr) && b->bldg_req == which) {
+      char req_buf[1024] = "";
+      int i;
+
+#define req_append(s)                                                      \
+      (req_buf[0] != '\0'                                                  \
+       ? my_snprintf(req_buf + strlen(req_buf),                                
    \
+                    sizeof(req_buf) - strlen(req_buf),                     \
+                    ", %s", (s))                                           \
+       : sz_strlcpy(req_buf, (s)))
+
+      if (b->tech_req != A_NONE) {
+       req_append(advances[b->tech_req].name);
+      }
+
+      for (i = 0; b->terr_gate[i] != T_NONE; i++) {
+       req_append(get_terrain_name(b->terr_gate[i]));
+      }
+      for (i = 0; b->spec_gate[i] != S_NO_SPECIAL; i++) {
+       req_append(get_special_name(b->spec_gate[i]));
+      }
+#undef req_append
+
+      if (req_buf[0] != '\0') {
+       my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
+                   _("* Allows %s (with %s).\n"), b->name, req_buf);
+      } else {
+       my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
+                   _("* Allows %s.\n"), b->name);
+      }
+    }
+  } impr_type_iterate_end;
+
+  unit_type_iterate(utype) {
+    const struct unit_type *u = get_unit_type(utype);
+
+    if (unit_type_exists(utype) && u->impr_requirement == which) {
+      if (u->tech_requirement != A_LAST) {
+       my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
+                   _("* Allows %s (with %s).\n"), u->name,
+                   advances[u->tech_requirement].name);
+      } else {
+       my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
+                   _("* Allows %s.\n"), u->name);
+      }
+    }
+  } unit_type_iterate_end;
 
   if (user_text && user_text[0] != '\0') {
     my_snprintf(buf + strlen(buf), bufsz - strlen(buf), "\n\n%s", user_text);

PNG image


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