]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/spec_hit.c
clean up import, NetBSD RCS Ids
[bsdgames-darwin.git] / rogue / spec_hit.c
1 /* $NetBSD: spec_hit.c,v 1.3 1995/04/22 10:28:29 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Timothy C. Stoehr.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39 #ifndef lint
40 #if 0
41 static char sccsid[] = "@(#)spec_hit.c 8.1 (Berkeley) 5/31/93";
42 #else
43 static char rcsid[] = "$NetBSD: spec_hit.c,v 1.3 1995/04/22 10:28:29 cgd Exp $";
44 #endif
45 #endif /* not lint */
46
47 /*
48 * special_hit.c
49 *
50 * This source herein may be modified and/or distributed by anybody who
51 * so desires, with the following restrictions:
52 * 1.) No portion of this notice shall be removed.
53 * 2.) Credit shall not be taken for the creation of this source.
54 * 3.) This code is not to be traded, sold, or used for personal
55 * gain or profit.
56 *
57 */
58
59 #include "rogue.h"
60
61 short less_hp = 0;
62 boolean being_held;
63
64 extern short cur_level, max_level, blind, levitate, ring_exp;
65 extern long level_points[];
66 extern boolean detect_monster, mon_disappeared;
67 extern boolean sustain_strength, maintain_armor;
68 extern char *you_can_move_again;
69
70 special_hit(monster)
71 object *monster;
72 {
73 if ((monster->m_flags & CONFUSED) && rand_percent(66)) {
74 return;
75 }
76 if (monster->m_flags & RUSTS) {
77 rust(monster);
78 }
79 if ((monster->m_flags & HOLDS) && !levitate) {
80 being_held = 1;
81 }
82 if (monster->m_flags & FREEZES) {
83 freeze(monster);
84 }
85 if (monster->m_flags & STINGS) {
86 sting(monster);
87 }
88 if (monster->m_flags & DRAINS_LIFE) {
89 drain_life();
90 }
91 if (monster->m_flags & DROPS_LEVEL) {
92 drop_level();
93 }
94 if (monster->m_flags & STEALS_GOLD) {
95 steal_gold(monster);
96 } else if (monster->m_flags & STEALS_ITEM) {
97 steal_item(monster);
98 }
99 }
100
101 rust(monster)
102 object *monster;
103 {
104 if ((!rogue.armor) || (get_armor_class(rogue.armor) <= 1) ||
105 (rogue.armor->which_kind == LEATHER)) {
106 return;
107 }
108 if ((rogue.armor->is_protected) || maintain_armor) {
109 if (monster && (!(monster->m_flags & RUST_VANISHED))) {
110 message("the rust vanishes instantly", 0);
111 monster->m_flags |= RUST_VANISHED;
112 }
113 } else {
114 rogue.armor->d_enchant--;
115 message("your armor weakens", 0);
116 print_stats(STAT_ARMOR);
117 }
118 }
119
120 freeze(monster)
121 object *monster;
122 {
123 short freeze_percent = 99;
124 short i, n;
125
126 if (rand_percent(12)) {
127 return;
128 }
129 freeze_percent -= (rogue.str_current+(rogue.str_current / 2));
130 freeze_percent -= ((rogue.exp + ring_exp) * 4);
131 freeze_percent -= (get_armor_class(rogue.armor) * 5);
132 freeze_percent -= (rogue.hp_max / 3);
133
134 if (freeze_percent > 10) {
135 monster->m_flags |= FREEZING_ROGUE;
136 message("you are frozen", 1);
137
138 n = get_rand(4, 8);
139 for (i = 0; i < n; i++) {
140 mv_mons();
141 }
142 if (rand_percent(freeze_percent)) {
143 for (i = 0; i < 50; i++) {
144 mv_mons();
145 }
146 killed_by((object *)0, HYPOTHERMIA);
147 }
148 message(you_can_move_again, 1);
149 monster->m_flags &= (~FREEZING_ROGUE);
150 }
151 }
152
153 steal_gold(monster)
154 object *monster;
155 {
156 int amount;
157
158 if ((rogue.gold <= 0) || rand_percent(10)) {
159 return;
160 }
161
162 amount = get_rand((cur_level * 10), (cur_level * 30));
163
164 if (amount > rogue.gold) {
165 amount = rogue.gold;
166 }
167 rogue.gold -= amount;
168 message("your purse feels lighter", 0);
169 print_stats(STAT_GOLD);
170 disappear(monster);
171 }
172
173 steal_item(monster)
174 object *monster;
175 {
176 object *obj;
177 short i, n, t;
178 char desc[80];
179 boolean has_something = 0;
180
181 if (rand_percent(15)) {
182 return;
183 }
184 obj = rogue.pack.next_object;
185
186 if (!obj) {
187 goto DSPR;
188 }
189 while (obj) {
190 if (!(obj->in_use_flags & BEING_USED)) {
191 has_something = 1;
192 break;
193 }
194 obj = obj->next_object;
195 }
196 if (!has_something) {
197 goto DSPR;
198 }
199 n = get_rand(0, MAX_PACK_COUNT);
200 obj = rogue.pack.next_object;
201
202 for (i = 0; i <= n; i++) {
203 obj = obj->next_object;
204 while ((!obj) || (obj->in_use_flags & BEING_USED)) {
205 if (!obj) {
206 obj = rogue.pack.next_object;
207 } else {
208 obj = obj->next_object;
209 }
210 }
211 }
212 (void) strcpy(desc, "she stole ");
213 if (obj->what_is != WEAPON) {
214 t = obj->quantity;
215 obj->quantity = 1;
216 }
217 get_desc(obj, desc+10);
218 message(desc, 0);
219
220 obj->quantity = ((obj->what_is != WEAPON) ? t : 1);
221
222 vanish(obj, 0, &rogue.pack);
223 DSPR:
224 disappear(monster);
225 }
226
227 disappear(monster)
228 object *monster;
229 {
230 short row, col;
231
232 row = monster->row;
233 col = monster->col;
234
235 dungeon[row][col] &= ~MONSTER;
236 if (rogue_can_see(row, col)) {
237 mvaddch(row, col, get_dungeon_char(row, col));
238 }
239 take_from_pack(monster, &level_monsters);
240 free_object(monster);
241 mon_disappeared = 1;
242 }
243
244 cough_up(monster)
245 object *monster;
246 {
247 object *obj;
248 short row, col, i, n;
249
250 if (cur_level < max_level) {
251 return;
252 }
253
254 if (monster->m_flags & STEALS_GOLD) {
255 obj = alloc_object();
256 obj->what_is = GOLD;
257 obj->quantity = get_rand((cur_level * 15), (cur_level * 30));
258 } else {
259 if (!rand_percent((int) monster->drop_percent)) {
260 return;
261 }
262 obj = gr_object();
263 }
264 row = monster->row;
265 col = monster->col;
266
267 for (n = 0; n <= 5; n++) {
268 for (i = -n; i <= n; i++) {
269 if (try_to_cough(row+n, col+i, obj)) {
270 return;
271 }
272 if (try_to_cough(row-n, col+i, obj)) {
273 return;
274 }
275 }
276 for (i = -n; i <= n; i++) {
277 if (try_to_cough(row+i, col-n, obj)) {
278 return;
279 }
280 if (try_to_cough(row+i, col+n, obj)) {
281 return;
282 }
283 }
284 }
285 free_object(obj);
286 }
287
288 try_to_cough(row, col, obj)
289 short row, col;
290 object *obj;
291 {
292 if ((row < MIN_ROW) || (row > (DROWS-2)) || (col < 0) || (col>(DCOLS-1))) {
293 return(0);
294 }
295 if ((!(dungeon[row][col] & (OBJECT | STAIRS | TRAP))) &&
296 (dungeon[row][col] & (TUNNEL | FLOOR | DOOR))) {
297 place_at(obj, row, col);
298 if (((row != rogue.row) || (col != rogue.col)) &&
299 (!(dungeon[row][col] & MONSTER))) {
300 mvaddch(row, col, get_dungeon_char(row, col));
301 }
302 return(1);
303 }
304 return(0);
305 }
306
307 seek_gold(monster)
308 object *monster;
309 {
310 short i, j, rn, s;
311
312 if ((rn = get_room_number(monster->row, monster->col)) < 0) {
313 return(0);
314 }
315 for (i = rooms[rn].top_row+1; i < rooms[rn].bottom_row; i++) {
316 for (j = rooms[rn].left_col+1; j < rooms[rn].right_col; j++) {
317 if ((gold_at(i, j)) && !(dungeon[i][j] & MONSTER)) {
318 monster->m_flags |= CAN_FLIT;
319 s = mon_can_go(monster, i, j);
320 monster->m_flags &= (~CAN_FLIT);
321 if (s) {
322 move_mon_to(monster, i, j);
323 monster->m_flags |= ASLEEP;
324 monster->m_flags &= (~(WAKENS | SEEKS_GOLD));
325 return(1);
326 }
327 monster->m_flags &= (~SEEKS_GOLD);
328 monster->m_flags |= CAN_FLIT;
329 mv_1_monster(monster, i, j);
330 monster->m_flags &= (~CAN_FLIT);
331 monster->m_flags |= SEEKS_GOLD;
332 return(1);
333 }
334 }
335 }
336 return(0);
337 }
338
339 gold_at(row, col)
340 short row, col;
341 {
342 if (dungeon[row][col] & OBJECT) {
343 object *obj;
344
345 if ((obj = object_at(&level_objects, row, col)) &&
346 (obj->what_is == GOLD)) {
347 return(1);
348 }
349 }
350 return(0);
351 }
352
353 check_gold_seeker(monster)
354 object *monster;
355 {
356 monster->m_flags &= (~SEEKS_GOLD);
357 }
358
359 check_imitator(monster)
360 object *monster;
361 {
362 char msg[80];
363
364 if (monster->m_flags & IMITATES) {
365 wake_up(monster);
366 if (!blind) {
367 mvaddch(monster->row, monster->col,
368 get_dungeon_char(monster->row, monster->col));
369 check_message();
370 sprintf(msg, "wait, that's a %s!", mon_name(monster));
371 message(msg, 1);
372 }
373 return(1);
374 }
375 return(0);
376 }
377
378 imitating(row, col)
379 register short row, col;
380 {
381 if (dungeon[row][col] & MONSTER) {
382 object *object_at(), *monster;
383
384 if (monster = object_at(&level_monsters, row, col)) {
385 if (monster->m_flags & IMITATES) {
386 return(1);
387 }
388 }
389 }
390 return(0);
391 }
392
393 sting(monster)
394 object *monster;
395 {
396 short sting_chance = 35;
397 char msg[80];
398
399 if ((rogue.str_current <= 3) || sustain_strength) {
400 return;
401 }
402 sting_chance += (6 * (6 - get_armor_class(rogue.armor)));
403
404 if ((rogue.exp + ring_exp) > 8) {
405 sting_chance -= (6 * ((rogue.exp + ring_exp) - 8));
406 }
407 if (rand_percent(sting_chance)) {
408 sprintf(msg, "the %s's bite has weakened you",
409 mon_name(monster));
410 message(msg, 0);
411 rogue.str_current--;
412 print_stats(STAT_STRENGTH);
413 }
414 }
415
416 drop_level()
417 {
418 int hp;
419
420 if (rand_percent(80) || (rogue.exp <= 5)) {
421 return;
422 }
423 rogue.exp_points = level_points[rogue.exp-2] - get_rand(9, 29);
424 rogue.exp -= 2;
425 hp = hp_raise();
426 if ((rogue.hp_current -= hp) <= 0) {
427 rogue.hp_current = 1;
428 }
429 if ((rogue.hp_max -= hp) <= 0) {
430 rogue.hp_max = 1;
431 }
432 add_exp(1, 0);
433 }
434
435 drain_life()
436 {
437 short n;
438
439 if (rand_percent(60) || (rogue.hp_max <= 30) || (rogue.hp_current < 10)) {
440 return;
441 }
442 n = get_rand(1, 3); /* 1 Hp, 2 Str, 3 both */
443
444 if ((n != 2) || (!sustain_strength)) {
445 message("you feel weaker", 0);
446 }
447 if (n != 2) {
448 rogue.hp_max--;
449 rogue.hp_current--;
450 less_hp++;
451 }
452 if (n != 1) {
453 if ((rogue.str_current > 3) && (!sustain_strength)) {
454 rogue.str_current--;
455 if (coin_toss()) {
456 rogue.str_max--;
457 }
458 }
459 }
460 print_stats((STAT_STRENGTH | STAT_HP));
461 }
462
463 m_confuse(monster)
464 object *monster;
465 {
466 char msg[80];
467
468 if (!rogue_can_see(monster->row, monster->col)) {
469 return(0);
470 }
471 if (rand_percent(45)) {
472 monster->m_flags &= (~CONFUSES); /* will not confuse the rogue */
473 return(0);
474 }
475 if (rand_percent(55)) {
476 monster->m_flags &= (~CONFUSES);
477 sprintf(msg, "the gaze of the %s has confused you", mon_name(monster));
478 message(msg, 1);
479 cnfs();
480 return(1);
481 }
482 return(0);
483 }
484
485 flame_broil(monster)
486 object *monster;
487 {
488 short row, col, dir;
489
490 if ((!mon_sees(monster, rogue.row, rogue.col)) || coin_toss()) {
491 return(0);
492 }
493 row = rogue.row - monster->row;
494 col = rogue.col - monster->col;
495 if (row < 0) {
496 row = -row;
497 }
498 if (col < 0) {
499 col = -col;
500 }
501 if (((row != 0) && (col != 0) && (row != col)) ||
502 ((row > 7) || (col > 7))) {
503 return(0);
504 }
505 dir = get_dir(monster->row, monster->col, row, col);
506 bounce(FIRE, dir, monster->row, monster->col, 0);
507
508 return(1);
509 }
510
511 get_dir(srow, scol, drow, dcol)
512 short srow, scol, drow, dcol;
513 {
514 if (srow == drow) {
515 if (scol < dcol) {
516 return(RIGHT);
517 } else {
518 return(LEFT);
519 }
520 }
521 if (scol == dcol) {
522 if (srow < drow) {
523 return(DOWN);
524 } else {
525 return(UPWARD);
526 }
527 }
528 if ((srow > drow) && (scol > dcol)) {
529 return(UPLEFT);
530 }
531 if ((srow < drow) && (scol < dcol)) {
532 return(DOWNRIGHT);
533 }
534 if ((srow < drow) && (scol > dcol)) {
535 return(DOWNLEFT);
536 }
537 /*if ((srow > drow) && (scol < dcol)) {*/
538 return(UPRIGHT);
539 /*}*/
540 }