| 1 | /* |
| 2 | * Copyright (c) 1983 Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms are permitted |
| 6 | * provided that this notice is preserved and that due credit is given |
| 7 | * to the University of California at Berkeley. The name of the University |
| 8 | * may not be used to endorse or promote products derived from this |
| 9 | * software without specific prior written permission. This software |
| 10 | * is provided ``as is'' without express or implied warranty. |
| 11 | */ |
| 12 | |
| 13 | #ifndef lint |
| 14 | static char sccsid[] = "@(#)com7.c 5.1 (Berkeley) %G%"; |
| 15 | #endif /* not lint */ |
| 16 | |
| 17 | #include "externs.h" |
| 18 | |
| 19 | fight(enemy,strength) |
| 20 | int enemy,strength; |
| 21 | { |
| 22 | int lifeline = 0; |
| 23 | int hurt; |
| 24 | char auxbuf[LINELENGTH]; |
| 25 | char *next; |
| 26 | int i; |
| 27 | int exhaustion; |
| 28 | |
| 29 | fighton: |
| 30 | time++; |
| 31 | snooze -= 5; |
| 32 | if (snooze > time) |
| 33 | exhaustion = CYCLE/(snooze - time); |
| 34 | else { |
| 35 | puts("You collapse exhausted, and he pulverizes your skull."); |
| 36 | die(); |
| 37 | } |
| 38 | if (snooze - time < 20) |
| 39 | puts("You look tired! I hope you're able to fight."); |
| 40 | next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0); |
| 41 | for (i=0; next && i < 10; i++) |
| 42 | next = getword(next, words[i], -1); |
| 43 | parse(); |
| 44 | switch(wordvalue[wordnumber]){ |
| 45 | |
| 46 | case KILL: |
| 47 | case SMITE: |
| 48 | if (testbit(inven,TWO_HANDED)) |
| 49 | hurt = rnd(70) - 2 * card(injuries,NUMOFINJURIES) - ucard(wear) - exhaustion; |
| 50 | else if (testbit(inven,SWORD) || testbit(inven, BROAD)) |
| 51 | hurt = rnd(50)%(WEIGHT-carrying)-card(injuries,NUMOFINJURIES)-encumber - exhaustion; |
| 52 | else if (testbit(inven,KNIFE) || testbit(inven,MALLET) || testbit(inven,CHAIN) || testbit(inven,MACE) || testbit(inven,HALBERD)) |
| 53 | hurt = rnd(15) - card(injuries,NUMOFINJURIES) - exhaustion; |
| 54 | else |
| 55 | hurt = rnd(7) - encumber; |
| 56 | if (hurt < 5) |
| 57 | switch(rnd(3)){ |
| 58 | |
| 59 | case 0: |
| 60 | puts("You swung wide and missed."); |
| 61 | break; |
| 62 | case 1: |
| 63 | puts("He checked your blow. CLASH! CLANG!"); |
| 64 | break; |
| 65 | case 2: |
| 66 | puts("His filthy tunic hangs by one less thread."); |
| 67 | break; |
| 68 | } |
| 69 | else if (hurt < 10){ |
| 70 | switch(rnd(3)){ |
| 71 | case 0: |
| 72 | puts("He's bleeding."); |
| 73 | break; |
| 74 | case 1: |
| 75 | puts("A trickle of blood runs down his face."); |
| 76 | break; |
| 77 | case 2: |
| 78 | puts("A huge purple bruise is forming on the side of his face."); |
| 79 | break; |
| 80 | } |
| 81 | lifeline++; |
| 82 | } |
| 83 | else if (hurt < 20){ |
| 84 | switch(rnd(3)){ |
| 85 | case 0: |
| 86 | puts("He staggers back quavering."); |
| 87 | break; |
| 88 | case 1: |
| 89 | puts("He jumps back with his hand over the wound."); |
| 90 | break; |
| 91 | case 2: |
| 92 | puts("His shirt falls open with a swath across the chest."); |
| 93 | break; |
| 94 | } |
| 95 | lifeline += 5; |
| 96 | } |
| 97 | else if (hurt < 30){ |
| 98 | switch(rnd(3)){ |
| 99 | case 0: |
| 100 | printf("A bloody gash opens up on his %s side.\n",(rnd(2) ? "left" : "right")); |
| 101 | break; |
| 102 | case 1: |
| 103 | puts("The steel bites home and scrapes along his ribs."); |
| 104 | break; |
| 105 | case 2: |
| 106 | puts("You pierce him, and his breath hisses through clenched teeth."); |
| 107 | break; |
| 108 | } |
| 109 | lifeline += 10; |
| 110 | } |
| 111 | else if (hurt < 40){ |
| 112 | switch(rnd(3)){ |
| 113 | case 0: |
| 114 | puts("You smite him to the ground."); |
| 115 | if (strength - lifeline > 20) |
| 116 | puts("But in a flurry of steel he regains his feet!"); |
| 117 | break; |
| 118 | case 1: |
| 119 | puts("The force of your blow sends him to his knees."); |
| 120 | puts("His arm swings lifeless at his side."); |
| 121 | break; |
| 122 | case 2: |
| 123 | puts("Clutching his blood drenched shirt, he collapses stunned."); |
| 124 | break; |
| 125 | } |
| 126 | lifeline += 20; |
| 127 | } |
| 128 | else { |
| 129 | switch(rnd(3)){ |
| 130 | case 0: |
| 131 | puts("His ribs crack under your powerful swing, flooding his lungs with blood."); |
| 132 | break; |
| 133 | case 1: |
| 134 | puts("You shatter his upheld arm in a spray of blood. The blade continues deep"); |
| 135 | puts("into his back, severing the spinal cord."); |
| 136 | lifeline += 25; |
| 137 | break; |
| 138 | case 2: |
| 139 | puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground."); |
| 140 | lifeline += 25; |
| 141 | break; |
| 142 | } |
| 143 | lifeline += 30; |
| 144 | } |
| 145 | break; |
| 146 | |
| 147 | case BACK: |
| 148 | if (enemy == DARK && lifeline > strength * 0.33){ |
| 149 | puts("He throws you back against the rock and pummels your face."); |
| 150 | if (testbit(inven,AMULET) || testbit(wear,AMULET)){ |
| 151 | printf("Lifting the amulet from you, "); |
| 152 | if (testbit(inven,MEDALION) || testbit(wear,MEDALION)){ |
| 153 | puts("his power grows and the walls of\nthe earth tremble."); |
| 154 | puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse."); |
| 155 | puts("The planet is consumed by darkness."); |
| 156 | die(); |
| 157 | } |
| 158 | if (testbit(inven,AMULET)){ |
| 159 | clearbit(inven,AMULET); |
| 160 | carrying -= objwt[AMULET]; |
| 161 | encumber -= objcumber[AMULET]; |
| 162 | } |
| 163 | else |
| 164 | clearbit(wear,AMULET); |
| 165 | puts("he flees down the dark caverns."); |
| 166 | clearbit(location[position].objects,DARK); |
| 167 | injuries[SKULL] = 1; |
| 168 | followfight = time; |
| 169 | return (0); |
| 170 | } |
| 171 | else{ |
| 172 | puts("I'm afraid you have been killed."); |
| 173 | die(); |
| 174 | } |
| 175 | } |
| 176 | else{ |
| 177 | puts("You escape stunned and disoriented from the fight."); |
| 178 | puts("A victorious bellow echoes from the battlescene."); |
| 179 | if (back && position != back) |
| 180 | move(back,BACK); |
| 181 | else if (ahead &&position != ahead) |
| 182 | move(ahead,AHEAD); |
| 183 | else if (left && position != left) |
| 184 | move(left,LEFT); |
| 185 | else if (right && position != right) |
| 186 | move(right,RIGHT); |
| 187 | else |
| 188 | move(location[position].down,AHEAD); |
| 189 | return(0); |
| 190 | } |
| 191 | |
| 192 | case SHOOT: |
| 193 | if (testbit(inven,LASER)){ |
| 194 | if (strength - lifeline <= 50){ |
| 195 | printf("The %s took a direct hit!\n",objsht[enemy]); |
| 196 | lifeline += 50; |
| 197 | } |
| 198 | else { |
| 199 | puts("With his bare hand he deflects the laser blast and whips the pistol from you!"); |
| 200 | clearbit(inven,LASER); |
| 201 | setbit(location[position].objects,LASER); |
| 202 | carrying -= objwt[LASER]; |
| 203 | encumber -= objcumber[LASER]; |
| 204 | } |
| 205 | } |
| 206 | else |
| 207 | puts("Unfortunately, you don't have a blaster handy."); |
| 208 | break; |
| 209 | |
| 210 | case DROP: |
| 211 | case DRAW: |
| 212 | cypher(); |
| 213 | time--; |
| 214 | break; |
| 215 | |
| 216 | default: |
| 217 | puts("You don't have a chance, he is too quick."); |
| 218 | break; |
| 219 | |
| 220 | } |
| 221 | if (lifeline >= strength){ |
| 222 | printf("You have killed the %s.\n", objsht[enemy]); |
| 223 | if (enemy == ELF || enemy == DARK) |
| 224 | puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!"); |
| 225 | clearbit(location[position].objects,enemy); |
| 226 | power += 2; |
| 227 | notes[JINXED]++; |
| 228 | return(0); |
| 229 | } |
| 230 | puts("He attacks..."); |
| 231 | /* some embellisments */ |
| 232 | hurt = rnd(NUMOFINJURIES) - (testbit(inven,SHIELD) != 0) - (testbit(wear,MAIL) != 0) - (testbit(wear,HELM) != 0); |
| 233 | hurt += (testbit(wear,AMULET) != 0) + (testbit(wear,MEDALION) != 0) + (testbit(wear,TALISMAN) != 0); |
| 234 | hurt = hurt < 0 ? 0 : hurt; |
| 235 | hurt = hurt >= NUMOFINJURIES ? NUMOFINJURIES -1 : hurt; |
| 236 | if (!injuries[hurt]){ |
| 237 | injuries[hurt] = 1; |
| 238 | printf("I'm afraid you have suffered %s.\n", ouch[hurt]); |
| 239 | } |
| 240 | else |
| 241 | puts("You emerge unscathed."); |
| 242 | if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){ |
| 243 | puts("I'm afraid you have suffered fatal injuries."); |
| 244 | die(); |
| 245 | } |
| 246 | goto fighton; |
| 247 | } |