]> git.pond.sub.org Git - empserver/commitdiff
subs: Clean up misuse of wu() around mission bomb damage
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 11 Jan 2015 12:06:54 +0000 (13:06 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 2 Mar 2015 07:20:50 +0000 (08:20 +0100)
Don't use multiple calls of wu() to print a single line, because that
creates a separate bulletin for each part.  The read command normally
merges the bulletins, but if the bulletins are more than five seconds
apart (clock jumped somehow), we get a bulletin header in the middle
of a line.  Unlikely to happen, but it also messes up pln_damage()'s
line wrapping (see commit e002bf2).  Clean it up.

The wu() misuse was introduced in Empire 2.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/subs/mission.c

index af2819d205893e971f5d02cd65c5cb9fa4e2632c..e5288bcc3185b18eb13d08890dca8ba433e6c90e 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996-2000
- *     Markus Armbruster, 2003-2012
+ *     Markus Armbruster, 2003-2015
  */
 
 #include <config.h>
@@ -1027,6 +1027,7 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
     struct plist *plp;
     struct plnstr *pp;
     int newdam, dam = 0;
+    char buf[32];
     int hitchance;
 
     for (qp = bombers->q_forw; qp != bombers; qp = qp->q_forw) {
@@ -1060,20 +1061,25 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
               "\t%s pinbombing %s %s in %s\n",
               prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own));
        }
-       hitchance = pln_hitchance(pp, hardtarget, EF_SHIP);
+
+       buf[0] = 0;
        if (nuk_on_plane(&plp->plane) >= 0)
            hitchance = 100;
-       else if (hardtarget != SECT_HARDTARGET)
-           wu(0, pp->pln_own, "\t\t%d%% hitchance...", hitchance);
+       else {
+           hitchance = pln_hitchance(pp, hardtarget, EF_SHIP);
+           if (hardtarget != SECT_HARDTARGET)
+               snprintf(buf, sizeof(buf), "\t\t%d%% hitchance...",
+                        hitchance);
+       }
        if (pct_chance(hitchance)) {
-           newdam = pln_damage(&plp->plane, 'p', "");
+           newdam = pln_damage(&plp->plane, 'p', buf);
            wu(0, pp->pln_own,
               "\t\thit %s %s for %d damage\n",
               cname(victim), s, newdam);
            dam += newdam;
        } else {
-           newdam = pln_damage(&plp->plane, 'p', 0);
-           wu(0, pp->pln_own, "missed\n");
+           newdam = pln_damage(&plp->plane, 'p', NULL);
+           wu(0, pp->pln_own, "%smissed\n", buf);
            if (mission == MI_SINTERDICT) {
                mpr(victim,
                    "RUMBLE... your sub in %s hears a depth-charge explode nearby\n",