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