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