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