command7.c revision 1.2 1 1.2 agc /* $NetBSD: command7.c,v 1.2 2003/08/07 09:37:01 agc 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.2 agc __RCSID("$NetBSD: command7.c,v 1.2 2003/08/07 09:37:01 agc 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.1 tv fight(enemy, strength)
45 1.1 tv int enemy, strength;
46 1.1 tv {
47 1.1 tv int lifeline = 0;
48 1.1 tv int hurt;
49 1.1 tv char auxbuf[LINELENGTH];
50 1.1 tv char *next;
51 1.1 tv int i;
52 1.1 tv int exhaustion;
53 1.1 tv
54 1.1 tv exhaustion = 0;
55 1.1 tv fighton:
56 1.1 tv ourtime++;
57 1.1 tv snooze -= 5;
58 1.1 tv if (snooze > ourtime)
59 1.1 tv exhaustion = CYCLE / (snooze - ourtime);
60 1.1 tv else {
61 1.1 tv puts("You collapse exhausted, and he pulverizes your skull.");
62 1.1 tv die();
63 1.1 tv }
64 1.1 tv if (snooze - ourtime < 20)
65 1.1 tv puts("You look tired! I hope you're able to fight.");
66 1.1 tv next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0);
67 1.1 tv for (i = 0; next && i < 10; i++)
68 1.1 tv next = getword(next, words[i], -1);
69 1.1 tv parse();
70 1.1 tv switch (wordvalue[wordnumber]) {
71 1.1 tv
72 1.1 tv case KILL:
73 1.1 tv case SMITE:
74 1.1 tv if (testbit(inven, TWO_HANDED))
75 1.1 tv hurt = rnd(70) - 2 * card(injuries, NUMOFINJURIES) - ucard(wear) - exhaustion;
76 1.1 tv else if (testbit(inven, SWORD) || testbit(inven, BROAD))
77 1.1 tv hurt = rnd(50) % (WEIGHT - carrying) - card(injuries, NUMOFINJURIES) - encumber - exhaustion;
78 1.1 tv else if (testbit(inven, KNIFE) || testbit(inven, MALLET) || testbit(inven, CHAIN) || testbit(inven, MACE) || testbit(inven, HALBERD))
79 1.1 tv hurt = rnd(15) - card(injuries, NUMOFINJURIES) - exhaustion;
80 1.1 tv else
81 1.1 tv hurt = rnd(7) - encumber;
82 1.1 tv if (hurt < 5)
83 1.1 tv switch (rnd(3)) {
84 1.1 tv
85 1.1 tv case 0:
86 1.1 tv puts("You swung wide and missed.");
87 1.1 tv break;
88 1.1 tv case 1:
89 1.1 tv puts("He checked your blow. CLASH! CLANG!");
90 1.1 tv break;
91 1.1 tv case 2:
92 1.1 tv puts("His filthy tunic hangs by one less thread.");
93 1.1 tv break;
94 1.1 tv }
95 1.1 tv else if (hurt < 10) {
96 1.1 tv switch (rnd(3)) {
97 1.1 tv case 0:
98 1.1 tv puts("He's bleeding.");
99 1.1 tv break;
100 1.1 tv case 1:
101 1.1 tv puts("A trickle of blood runs down his face.");
102 1.1 tv break;
103 1.1 tv case 2:
104 1.1 tv puts("A huge purple bruise is forming on the side of his face.");
105 1.1 tv break;
106 1.1 tv }
107 1.1 tv lifeline++;
108 1.1 tv } else if (hurt < 20) {
109 1.1 tv switch (rnd(3)) {
110 1.1 tv case 0:
111 1.1 tv puts("He staggers back quavering.");
112 1.1 tv break;
113 1.1 tv case 1:
114 1.1 tv puts("He jumps back with his hand over the wound.");
115 1.1 tv break;
116 1.1 tv case 2:
117 1.1 tv puts("His shirt falls open with a swath across the chest.");
118 1.1 tv break;
119 1.1 tv }
120 1.1 tv lifeline += 5;
121 1.1 tv } else if (hurt < 30) {
122 1.1 tv switch (rnd(3)) {
123 1.1 tv case 0:
124 1.1 tv printf("A bloody gash opens up on his %s side.\n", (rnd(2) ? "left" : "right"));
125 1.1 tv break;
126 1.1 tv case 1:
127 1.1 tv puts("The steel bites home and scrapes along his ribs.");
128 1.1 tv break;
129 1.1 tv case 2:
130 1.1 tv puts("You pierce him, and his breath hisses through clenched teeth.");
131 1.1 tv break;
132 1.1 tv }
133 1.1 tv lifeline += 10;
134 1.1 tv } else if (hurt < 40) {
135 1.1 tv switch (rnd(3)) {
136 1.1 tv case 0:
137 1.1 tv puts("You smite him to the ground.");
138 1.1 tv if (strength - lifeline > 20)
139 1.1 tv puts("But in a flurry of steel he regains his feet!");
140 1.1 tv break;
141 1.1 tv case 1:
142 1.1 tv puts("The force of your blow sends him to his knees.");
143 1.1 tv puts("His arm swings lifeless at his side.");
144 1.1 tv break;
145 1.1 tv case 2:
146 1.1 tv puts("Clutching his blood drenched shirt, he collapses stunned.");
147 1.1 tv break;
148 1.1 tv }
149 1.1 tv lifeline += 20;
150 1.1 tv } else {
151 1.1 tv switch (rnd(3)) {
152 1.1 tv case 0:
153 1.1 tv puts("His ribs crack under your powerful swing, flooding his lungs with blood.");
154 1.1 tv break;
155 1.1 tv case 1:
156 1.1 tv puts("You shatter his upheld arm in a spray of blood. The blade continues deep");
157 1.1 tv puts("into his back, severing the spinal cord.");
158 1.1 tv lifeline += 25;
159 1.1 tv break;
160 1.1 tv case 2:
161 1.1 tv puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground.");
162 1.1 tv lifeline += 25;
163 1.1 tv break;
164 1.1 tv }
165 1.1 tv lifeline += 30;
166 1.1 tv }
167 1.1 tv break;
168 1.1 tv
169 1.1 tv case BACK:
170 1.1 tv if (enemy == DARK && lifeline > strength * 0.33) {
171 1.1 tv puts("He throws you back against the rock and pummels your face.");
172 1.1 tv if (testbit(inven, AMULET) || testbit(wear, AMULET)) {
173 1.1 tv printf("Lifting the amulet from you, ");
174 1.1 tv if (testbit(inven, MEDALION) || testbit(wear, MEDALION)) {
175 1.1 tv puts("his power grows and the walls of\nthe earth tremble.");
176 1.1 tv puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse.");
177 1.1 tv puts("The planet is consumed by darkness.");
178 1.1 tv die();
179 1.1 tv }
180 1.1 tv if (testbit(inven, AMULET)) {
181 1.1 tv clearbit(inven, AMULET);
182 1.1 tv carrying -= objwt[AMULET];
183 1.1 tv encumber -= objcumber[AMULET];
184 1.1 tv } else
185 1.1 tv clearbit(wear, AMULET);
186 1.1 tv puts("he flees down the dark caverns.");
187 1.1 tv clearbit(location[position].objects, DARK);
188 1.1 tv injuries[SKULL] = 1;
189 1.1 tv followfight = ourtime;
190 1.1 tv return (0);
191 1.1 tv } else {
192 1.1 tv puts("I'm afraid you have been killed.");
193 1.1 tv die();
194 1.1 tv }
195 1.1 tv } else {
196 1.1 tv puts("You escape stunned and disoriented from the fight.");
197 1.1 tv puts("A victorious bellow echoes from the battlescene.");
198 1.1 tv if (back && position != back)
199 1.1 tv moveplayer(back, BACK);
200 1.1 tv else if (ahead && position != ahead)
201 1.1 tv moveplayer(ahead, AHEAD);
202 1.1 tv else if (left && position != left)
203 1.1 tv moveplayer(left, LEFT);
204 1.1 tv else if (right && position != right)
205 1.1 tv moveplayer(right, RIGHT);
206 1.1 tv else
207 1.1 tv moveplayer(location[position].down, AHEAD);
208 1.1 tv return (0);
209 1.1 tv }
210 1.1 tv
211 1.1 tv case SHOOT:
212 1.1 tv if (testbit(inven, LASER)) {
213 1.1 tv if (strength - lifeline <= 50) {
214 1.1 tv printf("The %s took a direct hit!\n", objsht[enemy]);
215 1.1 tv lifeline += 50;
216 1.1 tv } else {
217 1.1 tv puts("With his bare hand he deflects the laser blast and whips the pistol from you!");
218 1.1 tv clearbit(inven, LASER);
219 1.1 tv setbit(location[position].objects, LASER);
220 1.1 tv carrying -= objwt[LASER];
221 1.1 tv encumber -= objcumber[LASER];
222 1.1 tv }
223 1.1 tv } else
224 1.1 tv puts("Unfortunately, you don't have a blaster handy.");
225 1.1 tv break;
226 1.1 tv
227 1.1 tv case DROP:
228 1.1 tv case DRAW:
229 1.1 tv cypher();
230 1.1 tv ourtime--;
231 1.1 tv break;
232 1.1 tv
233 1.1 tv default:
234 1.1 tv puts("You don't have a chance; he is too quick.");
235 1.1 tv break;
236 1.1 tv
237 1.1 tv }
238 1.1 tv if (lifeline >= strength) {
239 1.1 tv printf("You have killed the %s.\n", objsht[enemy]);
240 1.1 tv if (enemy == ELF || enemy == DARK)
241 1.1 tv puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!");
242 1.1 tv clearbit(location[position].objects, enemy);
243 1.1 tv power += 2;
244 1.1 tv notes[JINXED]++;
245 1.1 tv return (0);
246 1.1 tv }
247 1.1 tv puts("He attacks...");
248 1.1 tv /* Some embellishments. */
249 1.1 tv hurt = rnd(NUMOFINJURIES) - (testbit(inven, SHIELD) != 0) - (testbit(wear, MAIL) != 0) - (testbit(wear, HELM) != 0);
250 1.1 tv hurt += (testbit(wear, AMULET) != 0) + (testbit(wear, MEDALION) != 0) + (testbit(wear, TALISMAN) != 0);
251 1.1 tv hurt = hurt < 0 ? 0 : hurt;
252 1.1 tv hurt = hurt >= NUMOFINJURIES ? NUMOFINJURIES - 1 : hurt;
253 1.1 tv if (!injuries[hurt]) {
254 1.1 tv injuries[hurt] = 1;
255 1.1 tv printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
256 1.1 tv } else
257 1.1 tv puts("You emerge unscathed.");
258 1.1 tv if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
259 1.1 tv puts("I'm afraid you have suffered fatal injuries.");
260 1.1 tv die();
261 1.1 tv }
262 1.1 tv goto fighton;
263 1.1 tv }
264