+/* $NetBSD: score.c,v 1.11 2009/05/25 00:39:45 dholland Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-/*static char sccsid[] = "from: @(#)score.c 5.4 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: score.c,v 1.2 1993/08/01 18:50:01 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: score.c,v 1.11 2009/05/25 00:39:45 dholland Exp $");
+#endif
#endif /* not lint */
-# include "trek.h"
-# include "getpar.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include "trek.h"
+#include "getpar.h"
/*
** PRINT OUT THE CURRENT SCORE
*/
-long score()
+static void scoreitem(long amount, const char *descfmt, ...)
+ __printflike(2, 3);
+
+static void
+scoreitem(long amount, const char *descfmt, ...)
{
- register int u;
- register int t;
- long s;
- double r;
- extern struct cvntab Skitab[];
+ 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)
+{
+ int u;
+ int t;
+ long s;
+ double r;
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);
- if (Move.endgame > 0)
- {
+ 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].abbrev, Skitab[u - 1].full);
}
- if (Game.killed)
- {
+
+ 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);
- if (Ship.ship != ENTERPRISE)
- {
+ 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);
- printf("\n*** TOTAL\t\t\t%14ld\n", s);
+ scoreitem(t, "%d casualties", u);
+
+ printf("\n");
+ scoreitem(s, "*** TOTAL");
return (s);
}