Mon May 25 00:03:18 2009 UTC ()
Fix score printing so columns line up.


(dholland)
diff -r1.9 -r1.10 src/games/trek/score.c

cvs diff -r1.9 -r1.10 src/games/trek/score.c (expand / switch to unified diff)

--- src/games/trek/score.c 2009/05/24 22:57:37 1.9
+++ src/games/trek/score.c 2009/05/25 00:03:18 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: score.c,v 1.9 2009/05/24 22:57:37 dholland Exp $ */ 1/* $NetBSD: score.c,v 1.10 2009/05/25 00:03:18 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,97 +24,108 @@ @@ -24,97 +24,108 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: score.c,v 1.9 2009/05/24 22:57:37 dholland Exp $"); 37__RCSID("$NetBSD: score.c,v 1.10 2009/05/25 00:03:18 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
 41#include <stdarg.h>
41#include <stdio.h> 42#include <stdio.h>
42#include "trek.h" 43#include "trek.h"
43#include "getpar.h" 44#include "getpar.h"
44 45
45/* 46/*
46** PRINT OUT THE CURRENT SCORE 47** PRINT OUT THE CURRENT SCORE
47*/ 48*/
48 49
 50static void scoreitem(long amount, const char *descfmt, ...)
 51 __printflike(2, 3);
 52
 53static void
 54scoreitem(long amount, const char *descfmt, ...)
 55{
 56 va_list ap;
 57 char buf[128];
 58
 59 if (amount == 0)
 60 return;
 61
 62 va_start(ap, descfmt);
 63 vsnprintf(buf, sizeof(buf), descfmt, ap);
 64 va_end(ap);
 65
 66 printf("%-40s %10ld\n", buf, amount);
 67}
 68
49long 69long
50score(void) 70score(void)
51{ 71{
52 int u; 72 int u;
53 int t; 73 int t;
54 long s; 74 long s;
55 double r; 75 double r;
56 76
57 printf("\n*** Your score:\n"); 77 printf("\n*** Your score:\n");
58 78
59 s = t = Param.klingpwr / 4 * (u = Game.killk); 79 s = t = Param.klingpwr / 4 * (u = Game.killk);
60 if (t != 0) 80 scoreitem(t, "%d Klingons killed", u);
61 printf("%d Klingons killed\t\t\t%6d\n", u, t); 
62 81
63 r = Now.date - Param.date; 82 r = Now.date - Param.date;
64 if (r < 1.0) 83 if (r < 1.0)
65 r = 1.0; 84 r = 1.0;
66 r = Game.killk / r; 85 r = Game.killk / r;
67 s += (t = 400 * r); 86 s += (t = 400 * r);
68 if (t != 0) 87 scoreitem(t, "Kill rate %.2f Klingons/stardate", r);
69 printf("Kill rate %.2f Klingons/stardate \t%6d\n", r, t); 
70 88
71 r = Now.klings; 89 r = Now.klings;
72 r /= Game.killk + 1; 90 r /= Game.killk + 1;
73 s += (t = -400 * r); 91 s += (t = -400 * r);
74 if (t != 0) 92 scoreitem(t, "Penalty for %d klingons remaining", Now.klings);
75 printf("Penalty for %d klingons remaining\t%6d\n", Now.klings, 
76 t); 
77 93
78 if (Move.endgame > 0) { 94 if (Move.endgame > 0) {
79 s += (t = 100 * (u = Game.skill)); 95 s += (t = 100 * (u = Game.skill));
80 printf("Bonus for winning a %s%s game\t\t%6d\n", 96 scoreitem(t, "Bonus for winning a %s%s game",
81 Skitab[u - 1].abrev, Skitab[u - 1].full, t); 97 Skitab[u - 1].abrev, Skitab[u - 1].full);
82 } 98 }
83 99
84 if (Game.killed) { 100 if (Game.killed) {
85 s -= 500; 101 s -= 500;
86 printf("Penalty for getting killed\t\t -500\n"); 102 scoreitem(-500, "Penalty for getting killed");
87 } 103 }
88 104
89 s += (t = -100 * (u = Game.killb)); 105 s += (t = -100 * (u = Game.killb));
90 if (t != 0) 106 scoreitem(t, "%d starbases killed", u);
91 printf("%d starbases killed\t\t\t%6d\n", u, t); 
92 107
93 s += (t = -100 * (u = Game.helps)); 108 s += (t = -100 * (u = Game.helps));
94 if (t != 0) 109 scoreitem(t, "%d calls for help", u);
95 printf("%d calls for help\t\t\t%6d\n", u, t); 
96 110
97 s += (t = -5 * (u = Game.kills)); 111 s += (t = -5 * (u = Game.kills));
98 if (t != 0) 112 scoreitem(t, "%d stars destroyed", u);
99 printf("%d stars destroyed\t\t\t%6d\n", u, t); 
100 113
101 s += (t = -150 * (u = Game.killinhab)); 114 s += (t = -150 * (u = Game.killinhab));
102 if (t != 0) 115 scoreitem(t, "%d inhabited starsystems destroyed", u);
103 printf("%d inhabited starsystems destroyed\t%6d\n", u, t); 
104 116
105 if (Ship.ship != ENTERPRISE) { 117 if (Ship.ship != ENTERPRISE) {
106 s -= 200; 118 s -= 200;
107 printf("penalty for abandoning ship\t\t -200\n"); 119 scoreitem(-200, "penalty for abandoning ship");
108 } 120 }
109 121
110 s += (t = 3 * (u = Game.captives)); 122 s += (t = 3 * (u = Game.captives));
111 if (t != 0) 123 scoreitem(t, "%d Klingons captured", u);
112 printf("%d Klingons captured\t\t\t%6d\n", u, t); 
113 124
114 s += (t = -(u = Game.deaths)); 125 s += (t = -(u = Game.deaths));
115 if (t != 0) 126 scoreitem(t, "%d casualties", u);
116 printf("%d casualties\t\t\t\t%6d\n", u, t); 
117 127
118 printf("\n*** TOTAL\t\t\t%14ld\n", s); 128 printf("\n");
 129 scoreitem(s, "*** TOTAL");
119 return (s); 130 return (s);
120} 131}