]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/hit.c
bogus lseek extern
[bsdgames-darwin.git] / rogue / hit.c
1 /*
2 * Copyright (c) 1988 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Timothy C. Stoehr.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37 #ifndef lint
38 /*static char sccsid[] = "from: @(#)hit.c 5.3 (Berkeley) 6/1/90";*/
39 static char rcsid[] = "$Id: hit.c,v 1.2 1993/08/01 18:52:31 mycroft Exp $";
40 #endif /* not lint */
41
42 /*
43 * hit.c
44 *
45 * This source herein may be modified and/or distributed by anybody who
46 * so desires, with the following restrictions:
47 * 1.) No portion of this notice shall be removed.
48 * 2.) Credit shall not be taken for the creation of this source.
49 * 3.) This code is not to be traded, sold, or used for personal
50 * gain or profit.
51 *
52 */
53
54 #include "rogue.h"
55
56 object *fight_monster = 0;
57 char hit_message[80] = "";
58
59 extern short halluc, blind, cur_level;
60 extern short add_strength, ring_exp, r_rings;
61 extern boolean being_held, interrupted, wizard, con_mon;
62
63 mon_hit(monster)
64 register object *monster;
65 {
66 short damage, hit_chance;
67 char *mn;
68 float minus;
69
70 if (fight_monster && (monster != fight_monster)) {
71 fight_monster = 0;
72 }
73 monster->trow = NO_ROOM;
74 if (cur_level >= (AMULET_LEVEL * 2)) {
75 hit_chance = 100;
76 } else {
77 hit_chance = monster->m_hit_chance;
78 hit_chance -= (((2 * rogue.exp) + (2 * ring_exp)) - r_rings);
79 }
80 if (wizard) {
81 hit_chance /= 2;
82 }
83 if (!fight_monster) {
84 interrupted = 1;
85 }
86 mn = mon_name(monster);
87
88 if (!rand_percent(hit_chance)) {
89 if (!fight_monster) {
90 sprintf(hit_message + strlen(hit_message), "the %s misses", mn);
91 message(hit_message, 1);
92 hit_message[0] = 0;
93 }
94 return;
95 }
96 if (!fight_monster) {
97 sprintf(hit_message + strlen(hit_message), "the %s hit", mn);
98 message(hit_message, 1);
99 hit_message[0] = 0;
100 }
101 if (!(monster->m_flags & STATIONARY)) {
102 damage = get_damage(monster->m_damage, 1);
103 if (cur_level >= (AMULET_LEVEL * 2)) {
104 minus = (float) ((AMULET_LEVEL * 2) - cur_level);
105 } else {
106 minus = (float) get_armor_class(rogue.armor) * 3.00;
107 minus = minus/100.00 * (float) damage;
108 }
109 damage -= (short) minus;
110 } else {
111 damage = monster->stationary_damage++;
112 }
113 if (wizard) {
114 damage /= 3;
115 }
116 if (damage > 0) {
117 rogue_damage(damage, monster, 0);
118 }
119 if (monster->m_flags & SPECIAL_HIT) {
120 special_hit(monster);
121 }
122 }
123
124 rogue_hit(monster, force_hit)
125 register object *monster;
126 boolean force_hit;
127 {
128 short damage, hit_chance;
129
130 if (monster) {
131 if (check_imitator(monster)) {
132 return;
133 }
134 hit_chance = force_hit ? 100 : get_hit_chance(rogue.weapon);
135
136 if (wizard) {
137 hit_chance *= 2;
138 }
139 if (!rand_percent(hit_chance)) {
140 if (!fight_monster) {
141 (void) strcpy(hit_message, "you miss ");
142 }
143 goto RET;
144 }
145 damage = get_weapon_damage(rogue.weapon);
146 if (wizard) {
147 damage *= 3;
148 }
149 if (con_mon) {
150 s_con_mon(monster);
151 }
152 if (mon_damage(monster, damage)) { /* still alive? */
153 if (!fight_monster) {
154 (void) strcpy(hit_message, "you hit ");
155 }
156 }
157 RET: check_gold_seeker(monster);
158 wake_up(monster);
159 }
160 }
161
162 rogue_damage(d, monster, other)
163 short d;
164 object *monster;
165 short other;
166 {
167 if (d >= rogue.hp_current) {
168 rogue.hp_current = 0;
169 print_stats(STAT_HP);
170 killed_by(monster, other);
171 }
172 if (d > 0) {
173 rogue.hp_current -= d;
174 print_stats(STAT_HP);
175 }
176 }
177
178 get_damage(ds, r)
179 char *ds;
180 boolean r;
181 {
182 register i = 0, j, n, d, total = 0;
183
184 while (ds[i]) {
185 n = get_number(ds+i);
186 while (ds[i++] != 'd') ;
187 d = get_number(ds+i);
188 while ((ds[i] != '/') && ds[i]) i++;
189
190 for (j = 0; j < n; j++) {
191 if (r) {
192 total += get_rand(1, d);
193 } else {
194 total += d;
195 }
196 }
197 if (ds[i] == '/') {
198 i++;
199 }
200 }
201 return(total);
202 }
203
204 get_w_damage(obj)
205 object *obj;
206 {
207 char new_damage[12];
208 register to_hit, damage;
209 register i = 0;
210
211 if ((!obj) || (obj->what_is != WEAPON)) {
212 return(-1);
213 }
214 to_hit = get_number(obj->damage) + obj->hit_enchant;
215 while (obj->damage[i++] != 'd') ;
216 damage = get_number(obj->damage + i) + obj->d_enchant;
217
218 sprintf(new_damage, "%dd%d", to_hit, damage);
219
220 return(get_damage(new_damage, 1));
221 }
222
223 get_number(s)
224 register char *s;
225 {
226 register i = 0;
227 register total = 0;
228
229 while ((s[i] >= '0') && (s[i] <= '9')) {
230 total = (10 * total) + (s[i] - '0');
231 i++;
232 }
233 return(total);
234 }
235
236 long
237 lget_number(s)
238 char *s;
239 {
240 short i = 0;
241 long total = 0;
242
243 while ((s[i] >= '0') && (s[i] <= '9')) {
244 total = (10 * total) + (s[i] - '0');
245 i++;
246 }
247 return(total);
248 }
249
250 to_hit(obj)
251 object *obj;
252 {
253 if (!obj) {
254 return(1);
255 }
256 return(get_number(obj->damage) + obj->hit_enchant);
257 }
258
259 damage_for_strength()
260 {
261 short strength;
262
263 strength = rogue.str_current + add_strength;
264
265 if (strength <= 6) {
266 return(strength-5);
267 }
268 if (strength <= 14) {
269 return(1);
270 }
271 if (strength <= 17) {
272 return(3);
273 }
274 if (strength <= 18) {
275 return(4);
276 }
277 if (strength <= 20) {
278 return(5);
279 }
280 if (strength <= 21) {
281 return(6);
282 }
283 if (strength <= 30) {
284 return(7);
285 }
286 return(8);
287 }
288
289 mon_damage(monster, damage)
290 object *monster;
291 short damage;
292 {
293 char *mn;
294 short row, col;
295
296 monster->hp_to_kill -= damage;
297
298 if (monster->hp_to_kill <= 0) {
299 row = monster->row;
300 col = monster->col;
301 dungeon[row][col] &= ~MONSTER;
302 mvaddch(row, col, (int) get_dungeon_char(row, col));
303
304 fight_monster = 0;
305 cough_up(monster);
306 mn = mon_name(monster);
307 sprintf(hit_message+strlen(hit_message), "defeated the %s", mn);
308 message(hit_message, 1);
309 hit_message[0] = 0;
310 add_exp(monster->kill_exp, 1);
311 take_from_pack(monster, &level_monsters);
312
313 if (monster->m_flags & HOLDS) {
314 being_held = 0;
315 }
316 free_object(monster);
317 return(0);
318 }
319 return(1);
320 }
321
322 fight(to_the_death)
323 boolean to_the_death;
324 {
325 short ch, c, d;
326 short row, col;
327 boolean first_miss = 1;
328 short possible_damage;
329 object *monster;
330
331 while (!is_direction(ch = rgetchar(), &d)) {
332 sound_bell();
333 if (first_miss) {
334 message("direction?", 0);
335 first_miss = 0;
336 }
337 }
338 check_message();
339 if (ch == CANCEL) {
340 return;
341 }
342 row = rogue.row; col = rogue.col;
343 get_dir_rc(d, &row, &col, 0);
344
345 c = mvinch(row, col);
346 if (((c < 'A') || (c > 'Z')) ||
347 (!can_move(rogue.row, rogue.col, row, col))) {
348 message("I see no monster there", 0);
349 return;
350 }
351 if (!(fight_monster = object_at(&level_monsters, row, col))) {
352 return;
353 }
354 if (!(fight_monster->m_flags & STATIONARY)) {
355 possible_damage = ((get_damage(fight_monster->m_damage, 0) * 2) / 3);
356 } else {
357 possible_damage = fight_monster->stationary_damage - 1;
358 }
359 while (fight_monster) {
360 (void) one_move_rogue(ch, 0);
361 if (((!to_the_death) && (rogue.hp_current <= possible_damage)) ||
362 interrupted || (!(dungeon[row][col] & MONSTER))) {
363 fight_monster = 0;
364 } else {
365 monster = object_at(&level_monsters, row, col);
366 if (monster != fight_monster) {
367 fight_monster = 0;
368 }
369 }
370 }
371 }
372
373 get_dir_rc(dir, row, col, allow_off_screen)
374 short dir;
375 short *row, *col;
376 short allow_off_screen;
377 {
378 switch(dir) {
379 case LEFT:
380 if (allow_off_screen || (*col > 0)) {
381 (*col)--;
382 }
383 break;
384 case DOWN:
385 if (allow_off_screen || (*row < (DROWS-2))) {
386 (*row)++;
387 }
388 break;
389 case UPWARD:
390 if (allow_off_screen || (*row > MIN_ROW)) {
391 (*row)--;
392 }
393 break;
394 case RIGHT:
395 if (allow_off_screen || (*col < (DCOLS-1))) {
396 (*col)++;
397 }
398 break;
399 case UPLEFT:
400 if (allow_off_screen || ((*row > MIN_ROW) && (*col > 0))) {
401 (*row)--;
402 (*col)--;
403 }
404 break;
405 case UPRIGHT:
406 if (allow_off_screen || ((*row > MIN_ROW) && (*col < (DCOLS-1)))) {
407 (*row)--;
408 (*col)++;
409 }
410 break;
411 case DOWNRIGHT:
412 if (allow_off_screen || ((*row < (DROWS-2)) && (*col < (DCOLS-1)))) {
413 (*row)++;
414 (*col)++;
415 }
416 break;
417 case DOWNLEFT:
418 if (allow_off_screen || ((*row < (DROWS-2)) && (*col > 0))) {
419 (*row)++;
420 (*col)--;
421 }
422 break;
423 }
424 }
425
426 get_hit_chance(weapon)
427 object *weapon;
428 {
429 short hit_chance;
430
431 hit_chance = 40;
432 hit_chance += 3 * to_hit(weapon);
433 hit_chance += (((2 * rogue.exp) + (2 * ring_exp)) - r_rings);
434 return(hit_chance);
435 }
436
437 get_weapon_damage(weapon)
438 object *weapon;
439 {
440 short damage;
441
442 damage = get_w_damage(weapon);
443 damage += damage_for_strength();
444 damage += ((((rogue.exp + ring_exp) - r_rings) + 1) / 2);
445 return(damage);
446 }
447
448 s_con_mon(monster)
449 object *monster;
450 {
451 if (con_mon) {
452 monster->m_flags |= CONFUSED;
453 monster->moves_confused += get_rand(12, 22);
454 message("the monster appears confused", 0);
455 con_mon = 0;
456 }
457 }