]> git.pond.sub.org Git - empserver/commitdiff
Clean up misuse of mpr() in pln_damage()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Jun 2010 21:05:58 +0000 (23:05 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 11 Jul 2010 05:59:34 +0000 (07:59 +0200)
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

index 54f870d5c648d9a46faf92a5afa374ec98c0c230..00f2b37c72ac3f0c9144a0b19def8cfedb3dabbc 100644 (file)
@@ -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;