command7.c revision 1.4 1 1.4 mrg /* $NetBSD: command7.c,v 1.4 2018/02/04 08:48:05 mrg Exp $ */
2 1.1 tv
3 1.1 tv /*
4 1.1 tv * Copyright (c) 1983, 1993
5 1.1 tv * The Regents of the University of California. All rights reserved.
6 1.1 tv *
7 1.1 tv * Redistribution and use in source and binary forms, with or without
8 1.1 tv * modification, are permitted provided that the following conditions
9 1.1 tv * are met:
10 1.1 tv * 1. Redistributions of source code must retain the above copyright
11 1.1 tv * notice, this list of conditions and the following disclaimer.
12 1.1 tv * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tv * notice, this list of conditions and the following disclaimer in the
14 1.1 tv * documentation and/or other materials provided with the distribution.
15 1.2 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 tv * may be used to endorse or promote products derived from this software
17 1.1 tv * without specific prior written permission.
18 1.1 tv *
19 1.1 tv * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 tv * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 tv * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 tv * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 tv * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 tv * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 tv * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 tv * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 tv * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 tv * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 tv * SUCH DAMAGE.
30 1.1 tv */
31 1.1 tv
32 1.1 tv #include <sys/cdefs.h>
33 1.1 tv #ifndef lint
34 1.1 tv #if 0
35 1.1 tv static char sccsid[] = "@(#)com7.c 8.2 (Berkeley) 4/28/95";
36 1.1 tv #else
37 1.4 mrg __RCSID("$NetBSD: command7.c,v 1.4 2018/02/04 08:48:05 mrg Exp $");
38 1.1 tv #endif
39 1.1 tv #endif /* not lint */
40 1.1 tv
41 1.1 tv #include "extern.h"
42 1.1 tv
43 1.1 tv int
44 1.3 jmc fight(int enemy, int strength)
45 1.1 tv {
46 1.1 tv int lifeline = 0;
47 1.1 tv int hurt;
48 1.1 tv char auxbuf[LINELENGTH];
49 1.1 tv char *next;
50 1.1 tv int i;
51 1.1 tv int exhaustion;
52 1.1 tv
53 1.1 tv exhaustion = 0;
54 1.1 tv fighton:
55 1.1 tv ourtime++;
56 1.1 tv snooze -= 5;
57 1.1 tv if (snooze > ourtime)
58 1.1 tv exhaustion = CYCLE / (snooze - ourtime);
59 1.1 tv else {
60 1.1 tv puts("You collapse exhausted, and he pulverizes your skull.");
61 1.1 tv die();
62 1.1 tv }
63 1.1 tv if (snooze - ourtime < 20)
64 1.1 tv puts("You look tired! I hope you're able to fight.");
65 1.1 tv next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0);
66 1.1 tv for (i = 0; next && i < 10; i++)
67 1.1 tv next = getword(next, words[i], -1);
68 1.1 tv parse();
69 1.1 tv switch (wordvalue[wordnumber]) {
70 1.1 tv
71 1.1 tv case KILL:
72 1.1 tv case SMITE:
73 1.1 tv if (testbit(inven, TWO_HANDED))
74 1.3 jmc hurt = rnd(70) - 2 * card(injuries, NUMOFINJURIES) -
75 1.3 jmc ucard(wear) - exhaustion;
76 1.1 tv else if (testbit(inven, SWORD) || testbit(inven, BROAD))
77 1.3 jmc hurt = rnd(50) % (WEIGHT - carrying) -
78 1.3 jmc card(injuries, NUMOFINJURIES) - encumber -
79 1.3 jmc exhaustion;
80 1.3 jmc else if (testbit(inven, KNIFE) || testbit(inven, MALLET) ||
81 1.3 jmc testbit(inven, CHAIN) || testbit(inven, MACE) ||
82 1.3 jmc testbit(inven, HALBERD))
83 1.3 jmc hurt = rnd(15) - card(injuries, NUMOFINJURIES) -
84 1.3 jmc exhaustion;
85 1.1 tv else
86 1.1 tv hurt = rnd(7) - encumber;
87 1.1 tv if (hurt < 5)
88 1.1 tv switch (rnd(3)) {
89 1.1 tv
90 1.1 tv case 0:
91 1.1 tv puts("You swung wide and missed.");
92 1.1 tv break;
93 1.1 tv case 1:
94 1.1 tv puts("He checked your blow. CLASH! CLANG!");
95 1.1 tv break;
96 1.1 tv case 2:
97 1.3 jmc printf("His filthy tunic hangs by one less ");
98 1.3 jmc puts("thread.");
99 1.1 tv break;
100 1.1 tv }
101 1.1 tv else if (hurt < 10) {
102 1.1 tv switch (rnd(3)) {
103 1.1 tv case 0:
104 1.1 tv puts("He's bleeding.");
105 1.1 tv break;
106 1.1 tv case 1:
107 1.1 tv puts("A trickle of blood runs down his face.");
108 1.1 tv break;
109 1.1 tv case 2:
110 1.3 jmc printf("A huge purple bruise is forming on ");
111 1.3 jmc puts("the side of his face.");
112 1.1 tv break;
113 1.1 tv }
114 1.1 tv lifeline++;
115 1.1 tv } else if (hurt < 20) {
116 1.1 tv switch (rnd(3)) {
117 1.1 tv case 0:
118 1.1 tv puts("He staggers back quavering.");
119 1.1 tv break;
120 1.1 tv case 1:
121 1.3 jmc printf("He jumps back with his hand over ");
122 1.3 jmc puts("the wound.");
123 1.1 tv break;
124 1.1 tv case 2:
125 1.3 jmc printf("His shirt falls open with a swath ");
126 1.3 jmc puts("across the chest.");
127 1.1 tv break;
128 1.1 tv }
129 1.1 tv lifeline += 5;
130 1.1 tv } else if (hurt < 30) {
131 1.1 tv switch (rnd(3)) {
132 1.1 tv case 0:
133 1.3 jmc printf("A bloody gash opens up on his %s ",
134 1.3 jmc (rnd(2) ? "left" : "right"));
135 1.3 jmc printf("side.\n");
136 1.1 tv break;
137 1.1 tv case 1:
138 1.3 jmc printf("The steel bites home and scrapes ");
139 1.3 jmc puts("along his ribs.");
140 1.1 tv break;
141 1.1 tv case 2:
142 1.3 jmc printf("You pierce him, and his breath ");
143 1.3 jmc puts("hisses through clenched teeth.");
144 1.1 tv break;
145 1.1 tv }
146 1.1 tv lifeline += 10;
147 1.1 tv } else if (hurt < 40) {
148 1.1 tv switch (rnd(3)) {
149 1.1 tv case 0:
150 1.1 tv puts("You smite him to the ground.");
151 1.3 jmc if (strength - lifeline > 20) {
152 1.3 jmc printf("But in a flurry of steel he ");
153 1.3 jmc puts("regains his feet!");
154 1.3 jmc }
155 1.1 tv break;
156 1.1 tv case 1:
157 1.3 jmc printf("The force of your blow sends him to ");
158 1.3 jmc puts("his knees.");
159 1.1 tv puts("His arm swings lifeless at his side.");
160 1.1 tv break;
161 1.1 tv case 2:
162 1.3 jmc printf("Clutching his blood drenched shirt, ");
163 1.3 jmc puts("he collapses stunned.");
164 1.1 tv break;
165 1.1 tv }
166 1.1 tv lifeline += 20;
167 1.1 tv } else {
168 1.1 tv switch (rnd(3)) {
169 1.1 tv case 0:
170 1.3 jmc printf("His ribs crack under your powerful ");
171 1.3 jmc puts("swing, flooding his lungs with blood.");
172 1.1 tv break;
173 1.1 tv case 1:
174 1.3 jmc printf("You shatter his upheld arm in a ");
175 1.3 jmc printf("spray of blood. The blade ");
176 1.3 jmc puts("continues deep");
177 1.3 jmc printf("into his back, severing the ");
178 1.3 jmc puts("spinal cord.");
179 1.1 tv lifeline += 25;
180 1.1 tv break;
181 1.1 tv case 2:
182 1.3 jmc printf("With a mighty lunge the steel ");
183 1.3 jmc printf("slides in, and gasping, he falls ");
184 1.3 jmc puts("to the ground.");
185 1.1 tv lifeline += 25;
186 1.1 tv break;
187 1.1 tv }
188 1.1 tv lifeline += 30;
189 1.1 tv }
190 1.1 tv break;
191 1.1 tv
192 1.1 tv case BACK:
193 1.1 tv if (enemy == DARK && lifeline > strength * 0.33) {
194 1.3 jmc printf("He throws you back against the rock and ");
195 1.3 jmc puts("pummels your face.");
196 1.1 tv if (testbit(inven, AMULET) || testbit(wear, AMULET)) {
197 1.1 tv printf("Lifting the amulet from you, ");
198 1.3 jmc if (testbit(inven, MEDALION) ||
199 1.3 jmc testbit(wear, MEDALION)) {
200 1.3 jmc printf("his power grows and the ");
201 1.3 jmc printf("walls of\nthe earth ");
202 1.3 jmc printf("tremble.\n");
203 1.3 jmc printf("When he touches the ");
204 1.3 jmc printf("medallion, your chest ");
205 1.3 jmc printf("explodes and the foundations ");
206 1.3 jmc printf("of the\nearth collapse.\n");
207 1.3 jmc printf("The planet is consumed by ");
208 1.3 jmc puts("darkness.");
209 1.1 tv die();
210 1.1 tv }
211 1.1 tv if (testbit(inven, AMULET)) {
212 1.1 tv clearbit(inven, AMULET);
213 1.1 tv carrying -= objwt[AMULET];
214 1.1 tv encumber -= objcumber[AMULET];
215 1.1 tv } else
216 1.1 tv clearbit(wear, AMULET);
217 1.1 tv puts("he flees down the dark caverns.");
218 1.1 tv clearbit(location[position].objects, DARK);
219 1.1 tv injuries[SKULL] = 1;
220 1.1 tv followfight = ourtime;
221 1.1 tv return (0);
222 1.1 tv } else {
223 1.1 tv puts("I'm afraid you have been killed.");
224 1.1 tv die();
225 1.1 tv }
226 1.1 tv } else {
227 1.3 jmc printf("You escape stunned and disoriented from ");
228 1.3 jmc puts("the fight.");
229 1.3 jmc printf("A victorious bellow echoes from the ");
230 1.3 jmc puts("battlescene.");
231 1.1 tv if (back && position != back)
232 1.1 tv moveplayer(back, BACK);
233 1.1 tv else if (ahead && position != ahead)
234 1.1 tv moveplayer(ahead, AHEAD);
235 1.1 tv else if (left && position != left)
236 1.1 tv moveplayer(left, LEFT);
237 1.1 tv else if (right && position != right)
238 1.1 tv moveplayer(right, RIGHT);
239 1.1 tv else
240 1.1 tv moveplayer(location[position].down, AHEAD);
241 1.1 tv return (0);
242 1.1 tv }
243 1.1 tv
244 1.1 tv case SHOOT:
245 1.1 tv if (testbit(inven, LASER)) {
246 1.1 tv if (strength - lifeline <= 50) {
247 1.3 jmc printf("The %s took a direct hit!\n",
248 1.3 jmc objsht[enemy]);
249 1.1 tv lifeline += 50;
250 1.1 tv } else {
251 1.3 jmc printf("With his bare hand he deflects the ");
252 1.3 jmc printf("laser blast and whips the pistol ");
253 1.3 jmc puts("from you!");
254 1.1 tv clearbit(inven, LASER);
255 1.1 tv setbit(location[position].objects, LASER);
256 1.1 tv carrying -= objwt[LASER];
257 1.1 tv encumber -= objcumber[LASER];
258 1.1 tv }
259 1.1 tv } else
260 1.1 tv puts("Unfortunately, you don't have a blaster handy.");
261 1.1 tv break;
262 1.1 tv
263 1.1 tv case DROP:
264 1.1 tv case DRAW:
265 1.1 tv cypher();
266 1.1 tv ourtime--;
267 1.1 tv break;
268 1.1 tv
269 1.1 tv default:
270 1.1 tv puts("You don't have a chance; he is too quick.");
271 1.1 tv break;
272 1.1 tv
273 1.1 tv }
274 1.1 tv if (lifeline >= strength) {
275 1.1 tv printf("You have killed the %s.\n", objsht[enemy]);
276 1.4 mrg if (enemy == ELF || enemy == DARK) {
277 1.3 jmc printf("A watery black smoke consumes his body and ");
278 1.3 jmc puts("then vanishes with a peal of thunder!");
279 1.4 mrg }
280 1.1 tv clearbit(location[position].objects, enemy);
281 1.1 tv power += 2;
282 1.1 tv notes[JINXED]++;
283 1.1 tv return (0);
284 1.1 tv }
285 1.1 tv puts("He attacks...");
286 1.1 tv /* Some embellishments. */
287 1.3 jmc hurt = rnd(NUMOFINJURIES) - (testbit(inven, SHIELD) != 0) -
288 1.3 jmc (testbit(wear, MAIL) != 0) - (testbit(wear, HELM) != 0);
289 1.3 jmc hurt += (testbit(wear, AMULET) != 0) +
290 1.3 jmc (testbit(wear, MEDALION) != 0) + (testbit(wear, TALISMAN) != 0);
291 1.1 tv hurt = hurt < 0 ? 0 : hurt;
292 1.1 tv hurt = hurt >= NUMOFINJURIES ? NUMOFINJURIES - 1 : hurt;
293 1.1 tv if (!injuries[hurt]) {
294 1.1 tv injuries[hurt] = 1;
295 1.1 tv printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
296 1.1 tv } else
297 1.1 tv puts("You emerge unscathed.");
298 1.1 tv if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
299 1.1 tv puts("I'm afraid you have suffered fatal injuries.");
300 1.1 tv die();
301 1.1 tv }
302 1.1 tv goto fighton;
303 1.1 tv }
304