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