Initial import from FreeBSD RELENG_4:
[dragonfly.git] / games / battlestar / com7.c
1 /*
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  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 #if 0
36 static char sccsid[] = "@(#)com7.c      8.1 (Berkeley) 5/31/93";
37 #endif
38 static const char rcsid[] =
39  "$FreeBSD: src/games/battlestar/com7.c,v 1.4.2.1 2001/03/05 11:45:36 kris Exp $";
40 #endif /* not lint */
41
42 #include "externs.h"
43
44 int
45 fight(enemy,strength)
46 int enemy,strength;
47 {
48         int lifeline = 0;
49         int hurt;
50         char auxbuf[LINELENGTH];
51         char *next;
52         int i;
53         int exhaustion = 0;
54
55 fighton:
56         gtime++;
57         snooze -= 5;
58         if (snooze > gtime)
59                 exhaustion = CYCLE/(snooze - gtime);
60         else {
61                 puts("You collapse exhausted, and he pulverizes your skull.");
62                 die(0);
63         }
64         if (snooze - gtime < 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                         }
109                         else if (hurt < 20){
110                                 switch(rnd(3)){
111                                         case 0:
112                                                 puts("He staggers back quavering.");
113                                                 break;
114                                         case 1:
115                                                 puts("He jumps back with his hand over the wound.");
116                                                 break;
117                                         case 2:
118                                                 puts("His shirt falls open with a swath across the chest.");
119                                                 break;
120                                 }
121                                 lifeline += 5;
122                         }
123                         else if (hurt < 30){
124                                 switch(rnd(3)){
125                                         case 0:
126                                                 printf("A bloody gash opens up on his %s side.\n",(rnd(2) ? "left" : "right"));
127                                                 break;
128                                         case 1:
129                                                 puts("The steel bites home and scrapes along his ribs.");
130                                                 break;
131                                         case 2:
132                                                 puts("You pierce him, and his breath hisses through clenched teeth.");
133                                                 break;
134                                 }
135                                 lifeline += 10;
136                         }
137                         else if (hurt < 40){
138                                 switch(rnd(3)){
139                                         case 0:
140                                                 puts("You smite him to the ground.");
141                                                 if (strength - lifeline > 20)
142                                                         puts("But in a flurry of steel he regains his feet!");
143                                                 break;
144                                         case 1:
145                                                 puts("The force of your blow sends him to his knees.");
146                                                 puts("His arm swings lifeless at his side.");
147                                                 break;
148                                         case 2:
149                                                 puts("Clutching his blood drenched shirt, he collapses stunned.");
150                                                 break;
151                                 }
152                                 lifeline += 20;
153                         }
154                         else {
155                                 switch(rnd(3)){
156                                         case 0:
157                                                 puts("His ribs crack under your powerful swing, flooding his lungs with blood.");
158                                                 break;
159                                         case 1:
160                                                 puts("You shatter his upheld arm in a spray of blood.  The blade continues deep");
161                                                 puts("into his back, severing the spinal cord.");
162                                                 lifeline += 25;
163                                                 break;
164                                         case 2:
165                                                 puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground.");
166                                                 lifeline += 25;
167                                                 break;
168                                 }
169                                 lifeline += 30;
170                         }
171                         break;
172
173                 case BACK:
174                         if (enemy == DARK && lifeline > strength * 0.33){
175                                 puts("He throws you back against the rock and pummels your face.");
176                                 if (testbit(inven,AMULET) || testbit(wear,AMULET)){
177                                         printf("Lifting the amulet from you, ");
178                                         if (testbit(inven,MEDALION) || testbit(wear,MEDALION)){
179                                                 puts("his power grows and the walls of\nthe earth tremble.");
180                                                 puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse.");
181                                                 puts("The planet is consumed by darkness.");
182                                                 die(0);
183                                         }
184                                         if (testbit(inven,AMULET)){
185                                                 clearbit(inven,AMULET);
186                                                 carrying -= objwt[AMULET];
187                                                 encumber -= objcumber[AMULET];
188                                         }
189                                         else
190                                                 clearbit(wear,AMULET);
191                                         puts("he flees down the dark caverns.");
192                                         clearbit(location[position].objects,DARK);
193                                         injuries[SKULL] = 1;
194                                         followfight = gtime;
195                                         return (0);
196                                 }
197                                 else{
198                                         puts("I'm afraid you have been killed.");
199                                         die(0);
200                                 }
201                         }
202                         else{
203                                 puts("You escape stunned and disoriented from the fight.");
204                                 puts("A victorious bellow echoes from the battlescene.");
205                                 if (back && position != back)
206                                         battlestar_move(back,BACK);
207                                 else if (ahead &&position != ahead)
208                                         battlestar_move(ahead,AHEAD);
209                                 else if (left && position != left)
210                                         battlestar_move(left,LEFT);
211                                 else if (right && position != right)
212                                         battlestar_move(right,RIGHT);
213                                 else
214                                         battlestar_move(location[position].down,
215                                                         AHEAD);
216                                 return(0);
217                         }
218
219                 case SHOOT:
220                         if (testbit(inven,LASER)){
221                                 if (strength - lifeline <= 50){
222                                         printf("The %s took a direct hit!\n",objsht[enemy]);
223                                         lifeline += 50;
224                                 }
225                                 else {
226                                         puts("With his bare hand he deflects the laser blast and whips the pistol from you!");
227                                         clearbit(inven,LASER);
228                                         setbit(location[position].objects,LASER);
229                                         carrying -= objwt[LASER];
230                                         encumber -= objcumber[LASER];
231                                 }
232                         }
233                         else
234                                 puts("Unfortunately, you don't have a blaster handy.");
235                         break;
236
237                 case DROP:
238                 case DRAW:
239                         cypher();
240                         gtime--;
241                         break;
242
243                 default:
244                         puts("You don't have a chance, he is too quick.");
245                         break;
246
247         }
248         if (lifeline >= strength){
249                 printf("You have killed the %s.\n", objsht[enemy]);
250                 if (enemy == ELF || enemy == DARK)
251                         puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!");
252                 clearbit(location[position].objects,enemy);
253                 power += 2;
254                 notes[JINXED]++;
255                 return(0);
256         }
257         puts("He attacks...");
258         /* some embellisments */
259         hurt = rnd(NUMOFINJURIES) - (testbit(inven,SHIELD) != 0) - (testbit(wear,MAIL) != 0) - (testbit(wear,HELM) != 0);
260         hurt += (testbit(wear,AMULET) != 0) + (testbit(wear,MEDALION) != 0) + (testbit(wear,TALISMAN) != 0);
261         hurt = hurt < 0 ? 0 : hurt;
262         hurt =  hurt >= NUMOFINJURIES ? NUMOFINJURIES -1 : hurt;
263         if (!injuries[hurt]){
264                 injuries[hurt] = 1;
265                 printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
266         }
267         else
268                 puts("You emerge unscathed.");
269         if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){
270                 puts("I'm afraid you have suffered fatal injuries.");
271                 die(0);
272         }
273         goto fighton;
274 }