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