Author: sveinung
Date: Fri Oct 30 10:46:38 2015
New Revision: 30317

URL: http://svn.gna.org/viewcvs/freeciv?rev=30317&view=rev
Log:
helpdata: list a unit type's combat bonuses

Only able to handle simple cases like those in the bundled rulesets.

See bug #23962

Modified:
    branches/S2_6/client/helpdata.c
    branches/S2_6/client/packhand.c
    branches/S2_6/common/packets.def
    branches/S2_6/common/unittype.h
    branches/S2_6/data/alien/units.ruleset
    branches/S2_6/data/civ1/units.ruleset
    branches/S2_6/data/civ2/units.ruleset
    branches/S2_6/data/civ2civ3/units.ruleset
    branches/S2_6/data/classic/units.ruleset
    branches/S2_6/data/experimental/units.ruleset
    branches/S2_6/data/multiplayer/units.ruleset
    branches/S2_6/data/stub/units.ruleset
    branches/S2_6/fc_version
    branches/S2_6/server/ruleset.c
    branches/S2_6/tools/ruledit/rulesave.c

Modified: branches/S2_6/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/helpdata.c?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/client/helpdata.c     (original)
+++ branches/S2_6/client/helpdata.c     Fri Oct 30 10:46:38 2015
@@ -3610,6 +3610,57 @@
             _("  * Can be airlifted from a suitable city.\n"));
   }
 
+  /* The unit's combat bonuses. Won't mention that another unit type has a
+   * combat bonus against this unit type. Doesn't handle complex cases like
+   * when a unit type has multiple combat bonuses of the same kind. */
+  combat_bonus_list_iterate(utype->bonuses, cbonus) {
+    const char *against[utype_count()];
+    int targets = 0;
+
+    if (cbonus->quiet) {
+      /* Handled in the help text of the ruleset. */
+      continue;
+    }
+
+    /* Find the unit types of the bonus targets. */
+    unit_type_iterate(utype2) {
+      if (utype_has_flag(utype2, cbonus->flag)) {
+        against[targets++] = utype_name_translation(utype2);
+      }
+    } unit_type_iterate_end;
+
+    if (targets > 0) {
+      struct astring list = ASTRING_INIT;
+
+      switch (cbonus->type) {
+      case CBONUS_DEFENSE_MULTIPLIER:
+        cat_snprintf(buf, bufsz,
+                     /* TRANS: multipied by ... or-list of unit types */
+                     _("* %dx defense bonus if attacked by %s.\n"),
+                     cbonus->value + 1,
+                     astr_build_or_list(&list, against, targets));
+        break;
+      case CBONUS_DEFENSE_DIVIDER:
+        cat_snprintf(buf, bufsz,
+                     /* TRANS: defense divider ... or-list of unit types */
+                     _("* reduces target's defense to 1 / %d when "
+                       "attacking %s.\n"),
+                     cbonus->value + 1,
+                     astr_build_or_list(&list, against, targets));
+        break;
+      case CBONUS_FIREPOWER1:
+        cat_snprintf(buf, bufsz,
+                     /* TRANS: or-list of unit types */
+                     _("* reduces target's fire power to 1 when "
+                       "attacking %s.\n"),
+                     astr_build_and_list(&list, against, targets));
+        break;
+      }
+
+      astr_free(&list);
+    }
+  } combat_bonus_list_iterate_end;
+
   if (utype->need_improvement) {
     cat_snprintf(buf, bufsz,
                  _("* Can only be built if there is %s in the city.\n"),

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Fri Oct 30 10:46:38 2015
@@ -3148,6 +3148,7 @@
   bonus->flag  = p->flag;
   bonus->type  = p->type;
   bonus->value = p->value;
+  bonus->quiet = p->quiet;
 
   combat_bonus_list_append(u->bonuses, bonus);
 }

Modified: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Fri Oct 30 10:46:38 2015
@@ -1309,6 +1309,7 @@
   UTYF        flag;
   CBONUS_TYPE type;
   UINT8       value;
+  BOOL        quiet;
 end
 
 PACKET_RULESET_UNIT_FLAG = 229; sc, lsend

Modified: branches/S2_6/common/unittype.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unittype.h?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/common/unittype.h     (original)
+++ branches/S2_6/common/unittype.h     Fri Oct 30 10:46:38 2015
@@ -406,6 +406,9 @@
   enum unit_type_flag_id  flag;
   enum combat_bonus_type  type;
   int                     value;
+
+  /* Not listed in the help text. */
+  bool                    quiet;
 };
 
 /* get 'struct combat_bonus_list' and related functions: */

Modified: branches/S2_6/data/alien/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/alien/units.ruleset?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/data/alien/units.ruleset      (original)
+++ branches/S2_6/data/alien/units.ruleset      Fri Oct 30 10:46:38 2015
@@ -215,6 +215,11 @@
 ; bonuses.flag  = flag of the unit that bonus applies against
 ; bonuses.type  = type of the bonus. See below
 ; bonuses.value = value of the bonus. Sum of these is used if multiple apply.
+; bonuses.quiet = don't auto generate help text for this bonus. Use this if
+;                 the bonus is documented in the unit type's help text.
+;                 This is useful when the combination of a unit's bonuses
+;                 becomes complex enough to make the auto generated help
+;                 ugly or inaccurate.
 ; flags         = special flag strings; list of built-in flags described below
 ;                 and/or user flags defined above
 ;

Modified: branches/S2_6/data/civ1/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/civ1/units.ruleset?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/data/civ1/units.ruleset       (original)
+++ branches/S2_6/data/civ1/units.ruleset       Fri Oct 30 10:46:38 2015
@@ -204,6 +204,11 @@
 ; bonuses.flag  = flag of the unit that bonus applies against
 ; bonuses.type  = type of the bonus. See below
 ; bonuses.value = value of the bonus. Sum of these is used if multiple apply.
+; bonuses.quiet = don't auto generate help text for this bonus. Use this if
+;                 the bonus is documented in the unit type's help text.
+;                 This is useful when the combination of a unit's bonuses
+;                 becomes complex enough to make the auto generated help
+;                 ugly or inaccurate.
 ; flags         = special flag strings; list of built-in flags (see
 ;                 classic/units.ruleset) and/or user flags defined above
 ;

Modified: branches/S2_6/data/civ2/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/civ2/units.ruleset?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/data/civ2/units.ruleset       (original)
+++ branches/S2_6/data/civ2/units.ruleset       Fri Oct 30 10:46:38 2015
@@ -216,6 +216,11 @@
 ; bonuses.flag  = flag of the unit that bonus applies against
 ; bonuses.type  = type of the bonus. See below
 ; bonuses.value = value of the bonus. Sum of these is used if multiple apply.
+; bonuses.quiet = don't auto generate help text for this bonus. Use this if
+;                 the bonus is documented in the unit type's help text.
+;                 This is useful when the combination of a unit's bonuses
+;                 becomes complex enough to make the auto generated help
+;                 ugly or inaccurate.
 ; flags         = special flag strings; list of built-in flags (see
 ;                 classic/units.ruleset) and/or user flags defined above
 ;

Modified: branches/S2_6/data/civ2civ3/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/civ2civ3/units.ruleset?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/data/civ2civ3/units.ruleset   (original)
+++ branches/S2_6/data/civ2civ3/units.ruleset   Fri Oct 30 10:46:38 2015
@@ -255,6 +255,11 @@
 ; bonuses.flag  = flag of the unit that bonus applies against
 ; bonuses.type  = type of the bonus. See below
 ; bonuses.value = value of the bonus. Sum of these is used if multiple apply.
+; bonuses.quiet = don't auto generate help text for this bonus. Use this if
+;                 the bonus is documented in the unit type's help text.
+;                 This is useful when the combination of a unit's bonuses
+;                 becomes complex enough to make the auto generated help
+;                 ugly or inaccurate.
 ; flags         = special flag strings; list of built-in flags described below
 ;                 and/or user flags defined above
 ;

Modified: branches/S2_6/data/classic/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/classic/units.ruleset?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/data/classic/units.ruleset    (original)
+++ branches/S2_6/data/classic/units.ruleset    Fri Oct 30 10:46:38 2015
@@ -232,6 +232,11 @@
 ; bonuses.flag  = flag of the unit that bonus applies against
 ; bonuses.type  = type of the bonus. See below
 ; bonuses.value = value of the bonus. Sum of these is used if multiple apply.
+; bonuses.quiet = don't auto generate help text for this bonus. Use this if
+;                 the bonus is documented in the unit type's help text.
+;                 This is useful when the combination of a unit's bonuses
+;                 becomes complex enough to make the auto generated help
+;                 ugly or inaccurate.
 ; flags         = special flag strings; list of built-in flags described below
 ;                 and/or user flags defined above
 ;

Modified: branches/S2_6/data/experimental/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/experimental/units.ruleset?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/data/experimental/units.ruleset       (original)
+++ branches/S2_6/data/experimental/units.ruleset       Fri Oct 30 10:46:38 2015
@@ -246,6 +246,11 @@
 ; bonuses.flag  = flag of the unit that bonus applies against
 ; bonuses.type  = type of the bonus. See below
 ; bonuses.value = value of the bonus. Sum of these is used if multiple apply.
+; bonuses.quiet = don't auto generate help text for this bonus. Use this if
+;                 the bonus is documented in the unit type's help text.
+;                 This is useful when the combination of a unit's bonuses
+;                 becomes complex enough to make the auto generated help
+;                 ugly or inaccurate.
 ; flags         = special flag strings; list of built-in flags described below
 ;                 and/or user flags defined above
 ;

Modified: branches/S2_6/data/multiplayer/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/multiplayer/units.ruleset?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/data/multiplayer/units.ruleset        (original)
+++ branches/S2_6/data/multiplayer/units.ruleset        Fri Oct 30 10:46:38 2015
@@ -231,6 +231,11 @@
 ; bonuses.flag  = flag of the unit that bonus applies against
 ; bonuses.type  = type of the bonus. See below
 ; bonuses.value = value of the bonus. Sum of these is used if multiple apply.
+; bonuses.quiet = don't auto generate help text for this bonus. Use this if
+;                 the bonus is documented in the unit type's help text.
+;                 This is useful when the combination of a unit's bonuses
+;                 becomes complex enough to make the auto generated help
+;                 ugly or inaccurate.
 ; flags         = special flag strings; list of built-in flags described below
 ;                 and/or user flags defined above
 ;

Modified: branches/S2_6/data/stub/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/stub/units.ruleset?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/data/stub/units.ruleset       (original)
+++ branches/S2_6/data/stub/units.ruleset       Fri Oct 30 10:46:38 2015
@@ -163,6 +163,11 @@
 ; bonuses.flag  = flag of the unit that bonus applies against
 ; bonuses.type  = type of the bonus. See below
 ; bonuses.value = value of the bonus. Sum of these is used if multiple apply.
+; bonuses.quiet = don't auto generate help text for this bonus. Use this if
+;                 the bonus is documented in the unit type's help text.
+;                 This is useful when the combination of a unit's bonuses
+;                 becomes complex enough to make the auto generated help
+;                 ugly or inaccurate.
 ; flags         = special flag strings; list of built-in flags described below
 ;                 and/or user flags defined above
 ; roles         = special role strings

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Fri Oct 30 10:46:38 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Oct.24"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Oct.30"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/ruleset.c?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/server/ruleset.c      (original)
+++ branches/S2_6/server/ruleset.c      Fri Oct 30 10:46:38 2015
@@ -502,6 +502,9 @@
       success = FALSE;
       continue;
     }
+    bonus->quiet = secfile_lookup_bool_default(file, FALSE,
+                                               "%s.%s%d.quiet",
+                                               sec, sub, j);
     combat_bonus_list_append(list, bonus);
   }
 
@@ -5938,6 +5941,7 @@
       bonuspacket.flag  = pbonus->flag;
       bonuspacket.type  = pbonus->type;
       bonuspacket.value = pbonus->value;
+      bonuspacket.quiet = pbonus->quiet;
 
       lsend_packet_ruleset_unit_bonus(dest, &bonuspacket);
     } combat_bonus_list_iterate_end;

Modified: branches/S2_6/tools/ruledit/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/rulesave.c?rev=30317&r1=30316&r2=30317&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/rulesave.c      (original)
+++ branches/S2_6/tools/ruledit/rulesave.c      Fri Oct 30 10:46:38 2015
@@ -2044,7 +2044,16 @@
                                 struct unit_type *put,
                                 char *path)
 {
-  int i = 0;
+  int i;
+  bool has_quiet = FALSE;
+
+  combat_bonus_list_iterate(put->bonuses, pbonus) {
+    if (pbonus->quiet) {
+      has_quiet = TRUE;
+    }
+  } combat_bonus_list_iterate_end;
+
+  i = 0;
 
   combat_bonus_list_iterate(put->bonuses, pbonus) {
     secfile_insert_str(sfile, unit_type_flag_id_name(pbonus->flag),
@@ -2053,6 +2062,12 @@
                        "%s.bonuses%d.type", path, i);
     secfile_insert_int(sfile, pbonus->value,
                        "%s.bonuses%d.value", path, i);
+
+    if (has_quiet) {
+      secfile_insert_bool(sfile, pbonus->quiet,
+                          "%s.bonuses%d.quiet", path, i);
+    }
+
     i++;
   } combat_bonus_list_iterate_end;
 


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

Reply via email to