xref: /csrg-svn/games/trek/win.c (revision 60859)
121298Sdist /*
2*60859Sbostic  * Copyright (c) 1980, 1993
3*60859Sbostic  *	The Regents of the University of California.  All rights reserved.
434205Sbostic  *
542606Sbostic  * %sccs.include.redist.c%
621298Sdist  */
721298Sdist 
811705Smckusick #ifndef lint
9*60859Sbostic static char sccsid[] = "@(#)win.c	8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111705Smckusick 
1211705Smckusick # include	"trek.h"
1311705Smckusick # include	"getpar.h"
1444314Sbostic # include	<setjmp.h>
1511705Smckusick 
1611705Smckusick /*
1711705Smckusick **  Signal game won
1811705Smckusick **
1911705Smckusick **	This routine prints out the win message, arranges to print out
2011705Smckusick **	your score, tells you if you have a promotion coming to you,
2111705Smckusick **	cleans up the current input line, and arranges to have you
2244314Sbostic **	asked whether or not you want another game (via the longjmp()
2311705Smckusick **	call).
2411705Smckusick **
2511705Smckusick **	Pretty straightforward, although the promotion algorithm is
2611705Smckusick **	pretty off the wall.
2711705Smckusick */
2811705Smckusick 
win()2911705Smckusick win()
3011705Smckusick {
3111705Smckusick 	long			s;
3244314Sbostic 	extern jmp_buf		env;
3311705Smckusick 	extern long		score();
3411705Smckusick 	extern struct cvntab	Skitab[];
3511705Smckusick 	register struct cvntab	*p;
3611705Smckusick 
3711705Smckusick 	sleep(1);
3811705Smckusick 	printf("\nCongratulations, you have saved the Federation\n");
3911705Smckusick 	Move.endgame = 1;
4011705Smckusick 
4111705Smckusick 	/* print and return the score */
4211705Smckusick 	s = score();
4311705Smckusick 
4411705Smckusick 	/* decide if she gets a promotion */
4511705Smckusick 	if (Game.helps == 0 && Game.killb == 0 && Game.killinhab == 0 && 5 * Game.kills + Game.deaths < 100 &&
4611705Smckusick 			s >= 1000 && Ship.ship == ENTERPRISE)
4711705Smckusick 	{
4811705Smckusick 		printf("In fact, you are promoted one step in rank,\n");
4911705Smckusick 		if (Game.skill >= 6)
5011705Smckusick 			printf("to the exalted rank of Commodore Emeritus\n");
5111705Smckusick 		else
5211705Smckusick 		{
5311705Smckusick 			p = &Skitab[Game.skill - 1];
5411705Smckusick 			printf("from %s%s ", p->abrev, p->full);
5511705Smckusick 			p++;
5611705Smckusick 			printf("to %s%s\n", p->abrev, p->full);
5711705Smckusick 		}
5811705Smckusick 	}
5911705Smckusick 
6011705Smckusick 	/* clean out input, and request new game */
6111705Smckusick 	skiptonl(0);
6244314Sbostic 	longjmp(env, 1);
6311705Smckusick }
64