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