Merge from vendor branch OPENSSH:
[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  * @(#)com7.c   8.1 (Berkeley) 5/31/93
34  * $FreeBSD: src/games/battlestar/com7.c,v 1.4.2.1 2001/03/05 11:45:36 kris Exp $
35  * $DragonFly: src/games/battlestar/com7.c,v 1.2 2003/06/17 04:25:22 dillon Exp $
36  */
37
38 #include "externs.h"
39
40 int
41 fight(enemy,strength)
42 int enemy,strength;
43 {
44         int lifeline = 0;
45         int hurt;
46         char auxbuf[LINELENGTH];
47         char *next;
48         int i;
49         int exhaustion = 0;
50
51 fighton:
52         gtime++;
53         snooze -= 5;
54         if (snooze > gtime)
55                 exhaustion = CYCLE/(snooze - gtime);
56         else {
57                 puts("You collapse exhausted, and he pulverizes your skull.");
58                 die(0);
59         }
60         if (snooze - gtime < 20)
61                 puts("You look tired! I hope you're able to fight.");
62         next = getcom(auxbuf, LINELENGTH, "<fight!>-: ", 0);
63         for (i=0; next && i < 10; i++)
64                 next = getword(next, words[i], -1);
65         parse();
66         switch(wordvalue[wordnumber]){
67
68                 case KILL:
69                 case SMITE:
70                         if (testbit(inven,TWO_HANDED))
71                                 hurt = rnd(70) - 2 * card(injuries,NUMOFINJURIES) - ucard(wear) - exhaustion;
72                         else if (testbit(inven,SWORD) || testbit(inven, BROAD))
73                                 hurt = rnd(50)%(WEIGHT-carrying)-card(injuries,NUMOFINJURIES)-encumber - exhaustion;
74                         else if (testbit(inven,KNIFE) || testbit(inven,MALLET) || testbit(inven,CHAIN) || testbit(inven,MACE) || testbit(inven,HALBERD))
75                                 hurt = rnd(15) - card(injuries,NUMOFINJURIES) - exhaustion;
76                         else
77                                 hurt = rnd(7) - encumber;
78                         if (hurt < 5)
79                                 switch(rnd(3)){
80
81                                         case 0:
82                                                 puts("You swung wide and missed.");
83                                                 break;
84                                         case 1:
85                                                 puts("He checked your blow. CLASH! CLANG!");
86                                                 break;
87                                         case 2:
88                                                 puts("His filthy tunic hangs by one less thread.");
89                                                 break;
90                                 }
91                         else if (hurt < 10){
92                                 switch(rnd(3)){
93                                         case 0:
94                                                 puts("He's bleeding.");
95                                                 break;
96                                         case 1:
97                                                 puts("A trickle of blood runs down his face.");
98                                                 break;
99                                         case 2:
100                                                 puts("A huge purple bruise is forming on the side of his face.");
101                                                 break;
102                                 }
103                                 lifeline++;
104                         }
105                         else if (hurt < 20){
106                                 switch(rnd(3)){
107                                         case 0:
108                                                 puts("He staggers back quavering.");
109                                                 break;
110                                         case 1:
111                                                 puts("He jumps back with his hand over the wound.");
112                                                 break;
113                                         case 2:
114                                                 puts("His shirt falls open with a swath across the chest.");
115                                                 break;
116                                 }
117                                 lifeline += 5;
118                         }
119                         else if (hurt < 30){
120                                 switch(rnd(3)){
121                                         case 0:
122                                                 printf("A bloody gash opens up on his %s side.\n",(rnd(2) ? "left" : "right"));
123                                                 break;
124                                         case 1:
125                                                 puts("The steel bites home and scrapes along his ribs.");
126                                                 break;
127                                         case 2:
128                                                 puts("You pierce him, and his breath hisses through clenched teeth.");
129                                                 break;
130                                 }
131                                 lifeline += 10;
132                         }
133                         else if (hurt < 40){
134                                 switch(rnd(3)){
135                                         case 0:
136                                                 puts("You smite him to the ground.");
137                                                 if (strength - lifeline > 20)
138                                                         puts("But in a flurry of steel he regains his feet!");
139                                                 break;
140                                         case 1:
141                                                 puts("The force of your blow sends him to his knees.");
142                                                 puts("His arm swings lifeless at his side.");
143                                                 break;
144                                         case 2:
145                                                 puts("Clutching his blood drenched shirt, he collapses stunned.");
146                                                 break;
147                                 }
148                                 lifeline += 20;
149                         }
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(0);
179                                         }
180                                         if (testbit(inven,AMULET)){
181                                                 clearbit(inven,AMULET);
182                                                 carrying -= objwt[AMULET];
183                                                 encumber -= objcumber[AMULET];
184                                         }
185                                         else
186                                                 clearbit(wear,AMULET);
187                                         puts("he flees down the dark caverns.");
188                                         clearbit(location[position].objects,DARK);
189                                         injuries[SKULL] = 1;
190                                         followfight = gtime;
191                                         return (0);
192                                 }
193                                 else{
194                                         puts("I'm afraid you have been killed.");
195                                         die(0);
196                                 }
197                         }
198                         else{
199                                 puts("You escape stunned and disoriented from the fight.");
200                                 puts("A victorious bellow echoes from the battlescene.");
201                                 if (back && position != back)
202                                         battlestar_move(back,BACK);
203                                 else if (ahead &&position != ahead)
204                                         battlestar_move(ahead,AHEAD);
205                                 else if (left && position != left)
206                                         battlestar_move(left,LEFT);
207                                 else if (right && position != right)
208                                         battlestar_move(right,RIGHT);
209                                 else
210                                         battlestar_move(location[position].down,
211                                                         AHEAD);
212                                 return(0);
213                         }
214
215                 case SHOOT:
216                         if (testbit(inven,LASER)){
217                                 if (strength - lifeline <= 50){
218                                         printf("The %s took a direct hit!\n",objsht[enemy]);
219                                         lifeline += 50;
220                                 }
221                                 else {
222                                         puts("With his bare hand he deflects the laser blast and whips the pistol from you!");
223                                         clearbit(inven,LASER);
224                                         setbit(location[position].objects,LASER);
225                                         carrying -= objwt[LASER];
226                                         encumber -= objcumber[LASER];
227                                 }
228                         }
229                         else
230                                 puts("Unfortunately, you don't have a blaster handy.");
231                         break;
232
233                 case DROP:
234                 case DRAW:
235                         cypher();
236                         gtime--;
237                         break;
238
239                 default:
240                         puts("You don't have a chance, he is too quick.");
241                         break;
242
243         }
244         if (lifeline >= strength){
245                 printf("You have killed the %s.\n", objsht[enemy]);
246                 if (enemy == ELF || enemy == DARK)
247                         puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!");
248                 clearbit(location[position].objects,enemy);
249                 power += 2;
250                 notes[JINXED]++;
251                 return(0);
252         }
253         puts("He attacks...");
254         /* some embellisments */
255         hurt = rnd(NUMOFINJURIES) - (testbit(inven,SHIELD) != 0) - (testbit(wear,MAIL) != 0) - (testbit(wear,HELM) != 0);
256         hurt += (testbit(wear,AMULET) != 0) + (testbit(wear,MEDALION) != 0) + (testbit(wear,TALISMAN) != 0);
257         hurt = hurt < 0 ? 0 : hurt;
258         hurt =  hurt >= NUMOFINJURIES ? NUMOFINJURIES -1 : hurt;
259         if (!injuries[hurt]){
260                 injuries[hurt] = 1;
261                 printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
262         }
263         else
264                 puts("You emerge unscathed.");
265         if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){
266                 puts("I'm afraid you have suffered fatal injuries.");
267                 die(0);
268         }
269         goto fighton;
270 }