xref: /original-bsd/games/trek/destruct.c (revision 3f73ce2f)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)destruct.c	5.5 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 # include	"trek.h"
13 
14 /*
15 **  Self Destruct Sequence
16 **
17 **	The computer starts up the self destruct sequence.  Obviously,
18 **	if the computer is out nothing can happen.  You get a countdown
19 **	and a request for password.  This must match the password that
20 **	you entered at the start of the game.
21 **
22 **	You get to destroy things when you blow up; hence, it is
23 **	possible to win the game by destructing if you take the last
24 **	Klingon with you.
25 **
26 **	By the way, the \032 in the message is a ^Z, which is because
27 **	the terminal in my office is an ADM-3, which uses that char-
28 **	acter to clear the screen.  I also stick in a \014 (form feed)
29 **	because that clears some other screens.
30 **
31 **	Uses trace flag 41
32 */
33 
34 destruct()
35 {
36 	char		checkpass[15];
37 	register int	i, j;
38 	double		zap;
39 
40 	if (damaged(COMPUTER))
41 		return (out(COMPUTER));
42 	printf("\n\07 --- WORKING ---\07\n");
43 	sleep(3);
44 	/* output the count 10 9 8 7 6 */
45 	for (i = 10; i > 5; i--)
46 	{
47 		for (j = 10;  j > i; j--)
48 			printf("   ");
49 		printf("%d\n", i);
50 		sleep(1);
51 	}
52 	/* check for password on new line only */
53 	skiptonl(0);
54 	getstrpar("Enter password verification", checkpass, 14, 0);
55 	sleep(2);
56 	if (!sequal(checkpass, Game.passwd))
57 		return (printf("Self destruct sequence aborted\n"));
58 	printf("Password verified; self destruct sequence continues:\n");
59 	sleep(2);
60 	/* output count 5 4 3 2 1 0 */
61 	for (i = 5; i >= 0; i--)
62 	{
63 		sleep(1);
64 		for (j = 5; j > i; j--)
65 			printf("   ");
66 		printf("%d\n", i);
67 	}
68 	sleep(2);
69 	printf("\032\014***** %s destroyed *****\n", Ship.shipname);
70 	Game.killed = 1;
71 	/* let's see what we can blow up!!!! */
72 	zap = 20.0 * Ship.energy;
73 	Game.deaths += Ship.crew;
74 	for (i = 0; i < Etc.nkling; )
75 	{
76 		if (Etc.klingon[i].power * Etc.klingon[i].dist <= zap)
77 			killk(Etc.klingon[i].x, Etc.klingon[i].y);
78 		else
79 			i++;
80 	}
81 	/* if we didn't kill the last Klingon (detected by killk), */
82 	/* then we lose.... */
83 	lose(L_DSTRCT);
84 }
85