xref: /original-bsd/games/trek/win.c (revision bcd9e7a3)
1ce95aa83Sdist /*
2*bcd9e7a3Sbostic  * Copyright (c) 1980, 1993
3*bcd9e7a3Sbostic  *	The Regents of the University of California.  All rights reserved.
4afcc7e22Sbostic  *
5a748a06eSbostic  * %sccs.include.redist.c%
6ce95aa83Sdist  */
7ce95aa83Sdist 
85649f70dSmckusick #ifndef lint
9*bcd9e7a3Sbostic static char sccsid[] = "@(#)win.c	8.1 (Berkeley) 05/31/93";
10afcc7e22Sbostic #endif /* not lint */
115649f70dSmckusick 
125649f70dSmckusick # include	"trek.h"
135649f70dSmckusick # include	"getpar.h"
149d81f6f7Sbostic # include	<setjmp.h>
155649f70dSmckusick 
165649f70dSmckusick /*
175649f70dSmckusick **  Signal game won
185649f70dSmckusick **
195649f70dSmckusick **	This routine prints out the win message, arranges to print out
205649f70dSmckusick **	your score, tells you if you have a promotion coming to you,
215649f70dSmckusick **	cleans up the current input line, and arranges to have you
229d81f6f7Sbostic **	asked whether or not you want another game (via the longjmp()
235649f70dSmckusick **	call).
245649f70dSmckusick **
255649f70dSmckusick **	Pretty straightforward, although the promotion algorithm is
265649f70dSmckusick **	pretty off the wall.
275649f70dSmckusick */
285649f70dSmckusick 
win()295649f70dSmckusick win()
305649f70dSmckusick {
315649f70dSmckusick 	long			s;
329d81f6f7Sbostic 	extern jmp_buf		env;
335649f70dSmckusick 	extern long		score();
345649f70dSmckusick 	extern struct cvntab	Skitab[];
355649f70dSmckusick 	register struct cvntab	*p;
365649f70dSmckusick 
375649f70dSmckusick 	sleep(1);
385649f70dSmckusick 	printf("\nCongratulations, you have saved the Federation\n");
395649f70dSmckusick 	Move.endgame = 1;
405649f70dSmckusick 
415649f70dSmckusick 	/* print and return the score */
425649f70dSmckusick 	s = score();
435649f70dSmckusick 
445649f70dSmckusick 	/* decide if she gets a promotion */
455649f70dSmckusick 	if (Game.helps == 0 && Game.killb == 0 && Game.killinhab == 0 && 5 * Game.kills + Game.deaths < 100 &&
465649f70dSmckusick 			s >= 1000 && Ship.ship == ENTERPRISE)
475649f70dSmckusick 	{
485649f70dSmckusick 		printf("In fact, you are promoted one step in rank,\n");
495649f70dSmckusick 		if (Game.skill >= 6)
505649f70dSmckusick 			printf("to the exalted rank of Commodore Emeritus\n");
515649f70dSmckusick 		else
525649f70dSmckusick 		{
535649f70dSmckusick 			p = &Skitab[Game.skill - 1];
545649f70dSmckusick 			printf("from %s%s ", p->abrev, p->full);
555649f70dSmckusick 			p++;
565649f70dSmckusick 			printf("to %s%s\n", p->abrev, p->full);
575649f70dSmckusick 		}
585649f70dSmckusick 	}
595649f70dSmckusick 
605649f70dSmckusick 	/* clean out input, and request new game */
615649f70dSmckusick 	skiptonl(0);
629d81f6f7Sbostic 	longjmp(env, 1);
635649f70dSmckusick }
64