summaryrefslogtreecommitdiffstats
path: root/trek
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2009-05-25 00:03:18 +0000
committerdholland <dholland@NetBSD.org>2009-05-25 00:03:18 +0000
commit823434e1f933dc114c6b85417356e1b2def22882 (patch)
tree1de3f2afd91b2d973f7024c40733ae8ef14e75ca /trek
parent478be95d8d1ddb2e9cb1831f0115097af1e41bc4 (diff)
downloadbsdgames-darwin-823434e1f933dc114c6b85417356e1b2def22882.tar.gz
bsdgames-darwin-823434e1f933dc114c6b85417356e1b2def22882.tar.zst
bsdgames-darwin-823434e1f933dc114c6b85417356e1b2def22882.zip
Fix score printing so columns line up.
Diffstat (limited to 'trek')
-rw-r--r--trek/score.c63
1 files changed, 37 insertions, 26 deletions
diff --git a/trek/score.c b/trek/score.c
index a1dff624..7d8deae8 100644
--- a/trek/score.c
+++ b/trek/score.c
@@ -1,4 +1,4 @@
-/* $NetBSD: score.c,v 1.9 2009/05/24 22:57:37 dholland Exp $ */
+/* $NetBSD: score.c,v 1.10 2009/05/25 00:03:18 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,10 +34,11 @@
#if 0
static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: score.c,v 1.9 2009/05/24 22:57:37 dholland Exp $");
+__RCSID("$NetBSD: score.c,v 1.10 2009/05/25 00:03:18 dholland Exp $");
#endif
#endif /* not lint */
+#include <stdarg.h>
#include <stdio.h>
#include "trek.h"
#include "getpar.h"
@@ -46,6 +47,25 @@ __RCSID("$NetBSD: score.c,v 1.9 2009/05/24 22:57:37 dholland Exp $");
** PRINT OUT THE CURRENT SCORE
*/
+static void scoreitem(long amount, const char *descfmt, ...)
+ __printflike(2, 3);
+
+static void
+scoreitem(long amount, const char *descfmt, ...)
+{
+ va_list ap;
+ char buf[128];
+
+ if (amount == 0)
+ return;
+
+ va_start(ap, descfmt);
+ vsnprintf(buf, sizeof(buf), descfmt, ap);
+ va_end(ap);
+
+ printf("%-40s %10ld\n", buf, amount);
+}
+
long
score(void)
{
@@ -57,64 +77,55 @@ score(void)
printf("\n*** Your score:\n");
s = t = Param.klingpwr / 4 * (u = Game.killk);
- if (t != 0)
- printf("%d Klingons killed\t\t\t%6d\n", u, t);
+ scoreitem(t, "%d Klingons killed", u);
r = Now.date - Param.date;
if (r < 1.0)
r = 1.0;
r = Game.killk / r;
s += (t = 400 * r);
- if (t != 0)
- printf("Kill rate %.2f Klingons/stardate \t%6d\n", r, t);
+ scoreitem(t, "Kill rate %.2f Klingons/stardate", r);
r = Now.klings;
r /= Game.killk + 1;
s += (t = -400 * r);
- if (t != 0)
- printf("Penalty for %d klingons remaining\t%6d\n", Now.klings,
- t);
+ scoreitem(t, "Penalty for %d klingons remaining", Now.klings);
if (Move.endgame > 0) {
s += (t = 100 * (u = Game.skill));
- printf("Bonus for winning a %s%s game\t\t%6d\n",
- Skitab[u - 1].abrev, Skitab[u - 1].full, t);
+ scoreitem(t, "Bonus for winning a %s%s game",
+ Skitab[u - 1].abrev, Skitab[u - 1].full);
}
if (Game.killed) {
s -= 500;
- printf("Penalty for getting killed\t\t -500\n");
+ scoreitem(-500, "Penalty for getting killed");
}
s += (t = -100 * (u = Game.killb));
- if (t != 0)
- printf("%d starbases killed\t\t\t%6d\n", u, t);
+ scoreitem(t, "%d starbases killed", u);
s += (t = -100 * (u = Game.helps));
- if (t != 0)
- printf("%d calls for help\t\t\t%6d\n", u, t);
+ scoreitem(t, "%d calls for help", u);
s += (t = -5 * (u = Game.kills));
- if (t != 0)
- printf("%d stars destroyed\t\t\t%6d\n", u, t);
+ scoreitem(t, "%d stars destroyed", u);
s += (t = -150 * (u = Game.killinhab));
- if (t != 0)
- printf("%d inhabited starsystems destroyed\t%6d\n", u, t);
+ scoreitem(t, "%d inhabited starsystems destroyed", u);
if (Ship.ship != ENTERPRISE) {
s -= 200;
- printf("penalty for abandoning ship\t\t -200\n");
+ scoreitem(-200, "penalty for abandoning ship");
}
s += (t = 3 * (u = Game.captives));
- if (t != 0)
- printf("%d Klingons captured\t\t\t%6d\n", u, t);
+ scoreitem(t, "%d Klingons captured", u);
s += (t = -(u = Game.deaths));
- if (t != 0)
- printf("%d casualties\t\t\t\t%6d\n", u, t);
+ scoreitem(t, "%d casualties", u);
- printf("\n*** TOTAL\t\t\t%14ld\n", s);
+ printf("\n");
+ scoreitem(s, "*** TOTAL");
return (s);
}