From: Markus Armbruster Date: Sun, 11 Jan 2015 12:06:54 +0000 (+0100) Subject: subs: Clean up misuse of wu() around mission bomb damage X-Git-Tag: v4.3.33~73 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=4401cca0afa774ae575b7a5caaf77781117d4ef1 subs: Clean up misuse of wu() around mission bomb damage 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 --- diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index af2819d20..e5288bcc3 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -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 @@ -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",