xref: /original-bsd/games/trek/win.c (revision 7f0a8b44)
1 /*
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)win.c	8.1 (Berkeley) 05/31/93";
10 #endif /* not lint */
11 
12 # include	"trek.h"
13 # include	"getpar.h"
14 # include	<setjmp.h>
15 
16 /*
17 **  Signal game won
18 **
19 **	This routine prints out the win message, arranges to print out
20 **	your score, tells you if you have a promotion coming to you,
21 **	cleans up the current input line, and arranges to have you
22 **	asked whether or not you want another game (via the longjmp()
23 **	call).
24 **
25 **	Pretty straightforward, although the promotion algorithm is
26 **	pretty off the wall.
27 */
28 
29 win()
30 {
31 	long			s;
32 	extern jmp_buf		env;
33 	extern long		score();
34 	extern struct cvntab	Skitab[];
35 	register struct cvntab	*p;
36 
37 	sleep(1);
38 	printf("\nCongratulations, you have saved the Federation\n");
39 	Move.endgame = 1;
40 
41 	/* print and return the score */
42 	s = score();
43 
44 	/* decide if she gets a promotion */
45 	if (Game.helps == 0 && Game.killb == 0 && Game.killinhab == 0 && 5 * Game.kills + Game.deaths < 100 &&
46 			s >= 1000 && Ship.ship == ENTERPRISE)
47 	{
48 		printf("In fact, you are promoted one step in rank,\n");
49 		if (Game.skill >= 6)
50 			printf("to the exalted rank of Commodore Emeritus\n");
51 		else
52 		{
53 			p = &Skitab[Game.skill - 1];
54 			printf("from %s%s ", p->abrev, p->full);
55 			p++;
56 			printf("to %s%s\n", p->abrev, p->full);
57 		}
58 	}
59 
60 	/* clean out input, and request new game */
61 	skiptonl(0);
62 	longjmp(env, 1);
63 }
64