]> git.pond.sub.org Git - empserver/commitdiff
subs: De-duplicate formatting in intelligence_report()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 11 Jan 2015 12:38:40 +0000 (13:38 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 2 Mar 2015 07:20:50 +0000 (08:20 +0100)
Every piece is formatted either with pr(), or with sprintf() for later
sending with wu().  The output is actually identical.  Format with
sprintf() always, and then either pr() or wu() the results.

While there, change the first parameter's type from int to natid.

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

index 7c1aa3b9b2d6b7ed9bc1d92524cd213015b5e252..9e9e099f3f77942cda6fa5b8c14e028178845675 100644 (file)
@@ -192,7 +192,7 @@ extern int lnd_take_casualty(int, struct ulist *, int);
 extern void lnd_submil(struct lndstr *, int);
 extern void lnd_takemob(struct emp_qelem *, double);
 extern int lnd_spyval(struct lndstr *);
-extern void intelligence_report(int, struct lndstr *, int, char *);
+extern void intelligence_report(natid, struct lndstr *, int, char *);
 extern void lnd_mar_stay_behind(struct emp_qelem *, natid);
 extern void lnd_mar_put(struct emp_qelem *, natid);
 extern void lnd_put(struct emp_qelem *);
index 2c0b1e4a4bb0bee5fdb6ccbd87b23fdc13bd3b42..cfb43bc14884e2efaf72dfa0738dd570968a4a34 100644 (file)
@@ -341,61 +341,39 @@ lnd_spyval(struct lndstr *lp)
 }
 
 void
-intelligence_report(int destination, struct lndstr *lp, int spy,
+intelligence_report(natid destination, struct lndstr *lp, int spy,
                    char *mess)
 {
     int vis = lnd_vis(lp);
     char buf1[80], buf2[80], buf3[80];
 
-    if (destination == 0)
+    if (!destination || !lp->lnd_own)
        return;
 
-    if (lp->lnd_own == 0)
-       return;
-
-    memset(buf1, 0, sizeof(buf1));
-    memset(buf2, 0, sizeof(buf2));
-    memset(buf3, 0, sizeof(buf3));
     if (chance((spy + vis) / 10.0)) {
-       if (destination == player->cnum)
-           pr("%s %s", mess, prland(lp));
-       else
-           sprintf(buf1, "%s %s", mess, prland(lp));
+       sprintf(buf1, "%s %s", mess, prland(lp));
 
        if (chance((spy + vis) / 20.0)) {
-           if (destination == player->cnum)
-               pr(" (eff %d, mil %d",
-                  roundintby(lp->lnd_effic, 5),
-                  roundintby(lp->lnd_item[I_MILIT], 10));
-           else
-               sprintf(buf2, " (eff %d, mil %d",
-                       roundintby(lp->lnd_effic, 5),
-                       roundintby(lp->lnd_item[I_MILIT], 10));
+           sprintf(buf2, " (eff %d, mil %d",
+                   roundintby(lp->lnd_effic, 5),
+                   roundintby(lp->lnd_item[I_MILIT], 10));
 
            if (chance((spy + vis) / 20.0)) {
                int t;
                t = lp->lnd_tech - 20 + roll(40);
                t = MAX(t, 0);
-               if (destination == player->cnum)
-                   pr(", tech %d)\n", t);
-               else
-                   sprintf(buf3, ", tech %d)\n", t);
+               sprintf(buf3, ", tech %d)\n", t);
            } else {
-               if (destination == player->cnum)
-                   pr(")\n");
-               else
-                   sprintf(buf3, ")\n");
+               sprintf(buf3, ")\n");
            }
        } else {
-           if (destination == player->cnum)
-               pr("\n");
-           else
-               sprintf(buf2, "\n");
+           sprintf(buf2, "\n");
+           buf3[0] = 0;
        }
-    }
-
-    if (destination != player->cnum) {
-       wu(0, destination, "%s%s%s", buf1, buf2, buf3);
+       if (destination == player->cnum)
+           pr("%s%s%s", buf1, buf2, buf3);
+       else
+           wu(0, destination, "%s%s%s", buf1, buf2, buf3);
     }
 }