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