Author: sveinung
Date: Fri Oct 30 10:45:07 2015
New Revision: 30316

URL: http://svn.gna.org/viewcvs/freeciv?rev=30316&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:
    trunk/client/helpdata.c
    trunk/client/packhand.c
    trunk/common/packets.def
    trunk/common/unittype.h
    trunk/data/alien/units.ruleset
    trunk/data/civ1/units.ruleset
    trunk/data/civ2/units.ruleset
    trunk/data/civ2civ3/units.ruleset
    trunk/data/classic/units.ruleset
    trunk/data/experimental/units.ruleset
    trunk/data/multiplayer/units.ruleset
    trunk/data/stub/units.ruleset
    trunk/fc_version
    trunk/server/ruleset.c
    trunk/tools/ruledit/rulesave.c

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Fri Oct 30 10:45:07 2015
@@ -3696,6 +3696,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: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Fri Oct 30 10:45:07 2015
@@ -3163,6 +3163,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: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Fri Oct 30 10:45:07 2015
@@ -1320,6 +1320,7 @@
   UTYF        flag;
   CBONUS_TYPE type;
   UINT8       value;
+  BOOL        quiet;
 end
 
 PACKET_RULESET_UNIT_FLAG = 229; sc, lsend

Modified: trunk/common/unittype.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unittype.h?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/common/unittype.h     (original)
+++ trunk/common/unittype.h     Fri Oct 30 10:45:07 2015
@@ -400,6 +400,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: trunk/data/alien/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/alien/units.ruleset?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/data/alien/units.ruleset      (original)
+++ trunk/data/alien/units.ruleset      Fri Oct 30 10:45:07 2015
@@ -222,6 +222,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: trunk/data/civ1/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ1/units.ruleset?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/data/civ1/units.ruleset       (original)
+++ trunk/data/civ1/units.ruleset       Fri Oct 30 10:45:07 2015
@@ -209,6 +209,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: trunk/data/civ2/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2/units.ruleset?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/data/civ2/units.ruleset       (original)
+++ trunk/data/civ2/units.ruleset       Fri Oct 30 10:45:07 2015
@@ -221,6 +221,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: trunk/data/civ2civ3/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2civ3/units.ruleset?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/data/civ2civ3/units.ruleset   (original)
+++ trunk/data/civ2civ3/units.ruleset   Fri Oct 30 10:45:07 2015
@@ -263,6 +263,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: trunk/data/classic/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/classic/units.ruleset?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/data/classic/units.ruleset    (original)
+++ trunk/data/classic/units.ruleset    Fri Oct 30 10:45:07 2015
@@ -237,6 +237,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: trunk/data/experimental/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/experimental/units.ruleset?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/data/experimental/units.ruleset       (original)
+++ trunk/data/experimental/units.ruleset       Fri Oct 30 10:45:07 2015
@@ -251,6 +251,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: trunk/data/multiplayer/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/multiplayer/units.ruleset?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/data/multiplayer/units.ruleset        (original)
+++ trunk/data/multiplayer/units.ruleset        Fri Oct 30 10:45:07 2015
@@ -236,6 +236,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: trunk/data/stub/units.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/stub/units.ruleset?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/data/stub/units.ruleset       (original)
+++ trunk/data/stub/units.ruleset       Fri Oct 30 10:45:07 2015
@@ -164,6 +164,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: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Fri Oct 30 10:45:07 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-3.0-2015.Oct.26"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Oct.30"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Fri Oct 30 10:45:07 2015
@@ -482,6 +482,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);
   }
 
@@ -6118,6 +6121,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: trunk/tools/ruledit/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/rulesave.c?rev=30316&r1=30315&r2=30316&view=diff
==============================================================================
--- trunk/tools/ruledit/rulesave.c      (original)
+++ trunk/tools/ruledit/rulesave.c      Fri Oct 30 10:45:07 2015
@@ -2111,7 +2111,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),
@@ -2120,6 +2129,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