From e002bf207fc9c7780c5fd4bfe2d128810184d9ff Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 6 Jun 2010 23:05:58 +0200 Subject: [PATCH] Clean up misuse of mpr() in pln_damage() Don't use multiple calls of mpr() 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. While there, wrap long "blam" lines. Can only happen for bomb loads above 16. Stock game needs a tech 406 jhb for that. The mpr() misuse was introduced in Empire 2. --- src/lib/subs/plnsub.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index 54f870d5c..00f2b37c7 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -985,12 +985,11 @@ int pln_damage(struct plnstr *pp, char type, int noisy) { struct plchrstr *pcp = plchr + pp->pln_type; - int load, i; - int hitroll; + int load, i, hitroll, aim, len; int dam = 0; - int aim; int effective = 1; int pinbomber = 0; + char buf[80]; if (CANT_HAPPEN(nuk_on_plane(pp) >= 0)) return 0; @@ -1018,27 +1017,34 @@ pln_damage(struct plnstr *pp, char type, int noisy) aim = 100 - aim; } + len = 0; while (i--) { dam += roll(6); hitroll = roll(100); if (hitroll >= 90) { dam += 8; if (noisy) - mpr(pp->pln_own, "BLAM"); + len += sprintf(buf + len, "BLAM"); } else if (hitroll < aim) { dam += 5; if (noisy) - mpr(pp->pln_own, "Blam"); + len += sprintf(buf + len, "Blam"); } else { dam += 1; if (noisy) - mpr(pp->pln_own, "blam"); + len += sprintf(buf + len, "blam"); + } + if (noisy) { + if (len > 75) { + mpr(pp->pln_own, "%s\n", buf); + len = 0; + } + if (i) + len += sprintf(buf + len, "-"); } - if (i && noisy) - mpr(pp->pln_own, "-"); } - if (noisy) - mpr(pp->pln_own, "\n"); + if (noisy && len) + mpr(pp->pln_own, "%s\n", buf); if (effective) dam *= 2; return dam; -- 2.43.0