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