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