BSD 1 development
[unix-history] / trek / shield.c
CommitLineData
520d5775
EA
1# include "trek.h"
2# include "getpar.h"
3
4/*
5** SHIELD AND CLOAKING DEVICE CONTROL
6**
7** 'f' is one for auto shield up (in case of Condition RED),
8** zero for shield control, and negative one for cloaking
9** device control.
10**
11** Called with an 'up' or 'down' on the same line, it puts
12** the shields/cloak into the specified mode. Otherwise it
13** reports to the user the current mode, and asks if she wishes
14** to change.
15**
16** This is not a free move. Hits that occur as a result of
17** this move appear as though the shields are half up/down,
18** so you get partial hits.
19*/
20
21struct cvntab Udtab[]
22{
23 "u", "p", 1, 0,
24 "d", "own", 0, 0,
25 0
26};
27
28shield(f)
29int f;
30{
31 register int i;
32 char c;
33 struct cvntab *r;
34 char s[100];
35 char *device, *dev2, *dev3;
36 int ind;
37 char *stat;
38
39 if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
40 return;
41 if (f < 0)
42 {
43 /* cloaking device */
44 if (Ship.ship == QUEENE)
45 return (printf("Ye Faire Queene does not have the cloaking device.\n"));
46 device = "Cloaking device";
47 dev2 = "is";
48 ind = CLOAK;
49 dev3 = "it";
50 stat = &Ship.cloaked;
51 }
52 else
53 {
54 /* shields */
55 device = "Shields";
56 dev2 = "are";
57 dev3 = "them";
58 ind = SHIELD;
59 stat = &Ship.shldup;
60 }
61 if (damaged(ind))
62 {
63 if (f <= 0)
64 out(ind);
65 return;
66 }
67 if (Ship.cond == DOCKED)
68 {
69 printf("%s %s down while docked\n", device, dev2);
70 return;
71 }
72 if (f <= 0 && !testnl())
73 {
74 r = getcodpar("Up or down", Udtab);
75 i = r->value;
76 }
77 else
78 {
79 if (*stat)
80 printf(-1, s, "%s %s up. Do you want %s down", device, dev2, dev3);
81 else
82 printf(-1, s, "%s %s down. Do you want %s up", device, dev2, dev3);
83 if (!getynpar(s))
84 return;
85 i = !*stat;
86 }
87 if (*stat == i)
88 {
89 printf("%s already ", device);
90 if (i)
91 printf("up\n");
92 else
93 printf("down\n");
94 return;
95 }
96 if (i)
97 if (f >= 0)
98 Ship.energy =- Param.shupengy;
99 else
100 Ship.cloakgood = 0;
101 Move.free = 0;
102 if (f >= 0)
103 Move.shldchg = 1;
104 *stat = i;
105 return;
106}