(linenum→info "unix/slp.c:2238")

bsd-games/2.17/battlestar/command7.c

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