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