home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / games / battlestar / com7.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-08  |  8.1 KB  |  269 lines

  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, 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. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)com7.c    5.3 (Berkeley) 6/1/90";
  36. #endif /* not lint */
  37.  
  38. #include "externs.h"
  39.  
  40. fight(enemy,strength)
  41. int enemy,strength;
  42. {
  43.     int lifeline = 0;
  44.     int hurt;
  45.     char auxbuf[LINELENGTH];
  46.     char *next;
  47.     int i;
  48.     int exhaustion;
  49.  
  50. fighton:
  51.     time++;
  52.     snooze -= 5;
  53.     if (snooze > time)
  54.         exhaustion = CYCLE/(snooze - time);
  55.     else {
  56.         puts("You collapse exhausted, and he pulverizes your skull.");
  57.         die();
  58.     }
  59.     if (snooze - time < 20)
  60.         puts("You look tired! I hope you're able to fight.");
  61.     next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0);
  62.     for (i=0; next && i < 10; i++)
  63.         next = getword(next, words[i], -1);
  64.     parse();
  65.     switch(wordvalue[wordnumber]){
  66.  
  67.         case KILL:
  68.         case SMITE:
  69.             if (testbit(inven,TWO_HANDED))
  70.                 hurt = rnd(70) - 2 * card(injuries,NUMOFINJURIES) - ucard(wear) - exhaustion;
  71.             else if (testbit(inven,SWORD) || testbit(inven, BROAD))
  72.                 hurt = rnd(50)%(WEIGHT-carrying)-card(injuries,NUMOFINJURIES)-encumber - exhaustion;
  73.             else if (testbit(inven,KNIFE) || testbit(inven,MALLET) || testbit(inven,CHAIN) || testbit(inven,MACE) || testbit(inven,HALBERD))
  74.                 hurt = rnd(15) - card(injuries,NUMOFINJURIES) - exhaustion;
  75.             else 
  76.                 hurt = rnd(7) - encumber;
  77.             if (hurt < 5)
  78.                 switch(rnd(3)){
  79.  
  80.                     case 0:
  81.                         puts("You swung wide and missed.");
  82.                         break;
  83.                     case 1:
  84.                         puts("He checked your blow. CLASH! CLANG!");
  85.                         break;
  86.                     case 2:
  87.                         puts("His filthy tunic hangs by one less thread.");
  88.                         break;
  89.                 }
  90.             else if (hurt < 10){
  91.                 switch(rnd(3)){
  92.                     case 0:
  93.                         puts("He's bleeding.");
  94.                         break;
  95.                     case 1:
  96.                         puts("A trickle of blood runs down his face.");
  97.                         break;
  98.                     case 2:
  99.                         puts("A huge purple bruise is forming on the side of his face.");
  100.                         break;
  101.                 }
  102.                 lifeline++;
  103.             }
  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;
  115.                 }
  116.                 lifeline += 5;
  117.             }
  118.             else if (hurt < 30){
  119.                 switch(rnd(3)){
  120.                     case 0:
  121.                         printf("A bloody gash opens up on his %s side.\n",(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;
  129.                 }
  130.                 lifeline += 10;
  131.             }
  132.             else if (hurt < 40){
  133.                 switch(rnd(3)){
  134.                     case 0:
  135.                         puts("You smite him to the ground.");
  136.                         if (strength - lifeline > 20)
  137.                             puts("But in a flurry of steel he regains his feet!");
  138.                         break;
  139.                     case 1:
  140.                         puts("The force of your blow sends him to his knees.");
  141.                         puts("His arm swings lifeless at his side.");
  142.                         break;
  143.                     case 2:
  144.                         puts("Clutching his blood drenched shirt, he collapses stunned.");
  145.                         break;
  146.                 }
  147.                 lifeline += 20;
  148.             }
  149.             else {
  150.                 switch(rnd(3)){
  151.                     case 0:
  152.                         puts("His ribs crack under your powerful swing, flooding his lungs with blood.");
  153.                         break;
  154.                     case 1:
  155.                         puts("You shatter his upheld arm in a spray of blood.  The blade continues deep");
  156.                         puts("into his back, severing the spinal cord.");
  157.                         lifeline += 25;
  158.                         break;
  159.                     case 2:
  160.                         puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground.");
  161.                         lifeline += 25;
  162.                         break;
  163.                 }
  164.                 lifeline += 30;
  165.             }
  166.             break;
  167.  
  168.         case BACK:
  169.             if (enemy == DARK && lifeline > strength * 0.33){
  170.                 puts("He throws you back against the rock and pummels your face.");
  171.                 if (testbit(inven,AMULET) || testbit(wear,AMULET)){
  172.                     printf("Lifting the amulet from you, ");
  173.                     if (testbit(inven,MEDALION) || testbit(wear,MEDALION)){
  174.                         puts("his power grows and the walls of\nthe earth tremble.");
  175.                         puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse.");
  176.                         puts("The planet is consumed by darkness.");
  177.                         die();
  178.                     }
  179.                     if (testbit(inven,AMULET)){
  180.                         clearbit(inven,AMULET);
  181.                         carrying -= objwt[AMULET];
  182.                         encumber -= objcumber[AMULET];
  183.                     }
  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 = time;
  190.                     return (0);
  191.                 }
  192.                 else{
  193.                     puts("I'm afraid you have been killed.");
  194.                     die();
  195.                 }
  196.             }
  197.             else{
  198.                 puts("You escape stunned and disoriented from the fight.");
  199.                 puts("A victorious bellow echoes from the battlescene.");
  200.                 if (back && position != back)
  201.                     move(back,BACK);
  202.                 else if (ahead &&position != ahead)
  203.                     move(ahead,AHEAD);
  204.                 else if (left && position != left)
  205.                     move(left,LEFT);
  206.                 else if (right && position != right)
  207.                     move(right,RIGHT);
  208.                 else
  209.                     move(location[position].down,AHEAD);
  210.                 return(0);
  211.             }
  212.  
  213.         case SHOOT:
  214.             if (testbit(inven,LASER)){
  215.                 if (strength - lifeline <= 50){
  216.                     printf("The %s took a direct hit!\n",objsht[enemy]);
  217.                     lifeline += 50;
  218.                 }
  219.                 else {
  220.                     puts("With his bare hand he deflects the laser blast and whips the pistol from you!");
  221.                     clearbit(inven,LASER);
  222.                     setbit(location[position].objects,LASER);
  223.                     carrying -= objwt[LASER];
  224.                     encumber -= objcumber[LASER];
  225.                 }
  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.             time--;
  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 embellisments */
  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.     }
  261.     else
  262.         puts("You emerge unscathed.");
  263.     if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){
  264.         puts("I'm afraid you have suffered fatal injuries.");
  265.         die();
  266.     }
  267.     goto fighton;
  268. }
  269.