Rogue 3.6 reconstruction from http://rogue.rogueforge.net/rogue36/.
[rogue-pphs.git] / monsters.c
1 /*
2 * File with various monster functions in it
3 *
4 * @(#)monsters.c 3.18 (Berkeley) 6/15/81
5 *
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
8 * All rights reserved.
9 *
10 * See the file LICENSE.TXT for full copyright and licensing information.
11 */
12
13 #include "curses.h"
14 #include "rogue.h"
15 #include <string.h>
16 #include <ctype.h>
17
18 /*
19 * List of monsters in rough order of vorpalness
20 */
21 char lvl_mons[27] = "KJBSHEAOZGLCRQNYTWFIXUMVDP";
22 char wand_mons[27] = "KJBSH AOZG CRQ Y W IXU V ";
23
24 /*
25 * randmonster:
26 * Pick a monster to show up. The lower the level,
27 * the meaner the monster.
28 */
29
30 randmonster(wander)
31 bool wander;
32 {
33 register int d;
34 register char *mons;
35
36 mons = wander ? wand_mons : lvl_mons;
37 do
38 {
39 d = level + (rnd(10) - 5);
40 if (d < 1)
41 d = rnd(5) + 1;
42 if (d > 26)
43 d = rnd(5) + 22;
44 } while (mons[--d] == ' ');
45 return mons[d];
46 }
47
48 /*
49 * new_monster:
50 * Pick a new monster and add it to the list
51 */
52
53 new_monster(item, type, cp)
54 struct linked_list *item;
55 char type;
56 register coord *cp;
57 {
58 register struct thing *tp;
59 register struct monster *mp;
60
61 attach(mlist, item);
62 tp = (struct thing *) ldata(item);
63 tp->t_type = type;
64 tp->t_pos = *cp;
65 tp->t_oldch = mvwinch(cw, cp->y, cp->x);
66 mvwaddch(mw, cp->y, cp->x, tp->t_type);
67 mp = &monsters[tp->t_type-'A'];
68 tp->t_stats.s_hpt = roll(mp->m_stats.s_lvl, 8);
69 tp->t_stats.s_lvl = mp->m_stats.s_lvl;
70 tp->t_stats.s_arm = mp->m_stats.s_arm;
71 strcpy(tp->t_stats.s_dmg,mp->m_stats.s_dmg);
72 tp->t_stats.s_exp = mp->m_stats.s_exp;
73 tp->t_stats.s_str.st_str = 10;
74 tp->t_flags = mp->m_flags;
75 tp->t_turn = TRUE;
76 tp->t_pack = NULL;
77 if (ISWEARING(R_AGGR))
78 runto(cp, &hero);
79 if (type == 'M')
80 {
81 char mch;
82
83 if (tp->t_pack != NULL)
84 mch = ((struct object *) ldata(tp->t_pack))->o_type;
85 else
86 switch (rnd(level > 25 ? 9 : 8))
87 {
88 case 0: mch = GOLD;
89 when 1: mch = POTION;
90 when 2: mch = SCROLL;
91 when 3: mch = STAIRS;
92 when 4: mch = WEAPON;
93 when 5: mch = ARMOR;
94 when 6: mch = RING;
95 when 7: mch = STICK;
96 when 8: mch = AMULET;
97 }
98 tp->t_disguise = mch;
99 }
100 }
101
102 /*
103 * wanderer:
104 * A wandering monster has awakened and is headed for the player
105 */
106
107 wanderer()
108 {
109 register int i, ch;
110 register struct room *rp, *hr = roomin(&hero);
111 register struct linked_list *item;
112 register struct thing *tp;
113 coord cp;
114
115 item = new_item(sizeof *tp);
116 do
117 {
118 i = rnd_room();
119 if ((rp = &rooms[i]) == hr)
120 continue;
121 rnd_pos(rp, &cp);
122 if ((ch = mvwinch(stdscr, cp.y, cp.x)) == ERR)
123 {
124 debug("Routine wanderer: mvwinch failed to %d,%d", cp.y, cp.x);
125 if (wizard)
126 wait_for(cw,'\n');
127 return;
128 }
129 } until(hr != rp && step_ok(ch));
130 new_monster(item, randmonster(TRUE), &cp);
131 tp = (struct thing *) ldata(item);
132 tp->t_flags |= ISRUN;
133 tp->t_pos = cp;
134 tp->t_dest = &hero;
135 if (wizard)
136 msg("Started a wandering %s", monsters[tp->t_type-'A'].m_name);
137 }
138
139 /*
140 * what to do when the hero steps next to a monster
141 */
142 struct linked_list *
143 wake_monster(y, x)
144 int y, x;
145 {
146 register struct thing *tp;
147 register struct linked_list *it;
148 register struct room *rp;
149 register char ch;
150
151 if ((it = find_mons(y, x)) == NULL)
152 fatal("Can't find monster in wake");
153 tp = (struct thing *) ldata(it);
154 ch = tp->t_type;
155 /*
156 * Every time he sees mean monster, it might start chasing him
157 */
158 if (rnd(100) > 33 && on(*tp, ISMEAN) && off(*tp, ISHELD)
159 && !ISWEARING(R_STEALTH))
160 {
161 tp->t_dest = &hero;
162 tp->t_flags |= ISRUN;
163 }
164 if (ch == 'U' && off(player, ISBLIND))
165 {
166 rp = roomin(&hero);
167 if ((rp != NULL && !(rp->r_flags&ISDARK))
168 || DISTANCE(y, x, hero.y, hero.x) < 3)
169 {
170 if (off(*tp, ISFOUND) && !save(VS_MAGIC))
171 {
172 msg("The umber hulk's gaze has confused you.");
173 if (on(player, ISHUH))
174 lengthen(unconfuse, rnd(20)+HUHDURATION);
175 else
176 fuse(unconfuse, 0, rnd(20)+HUHDURATION, AFTER);
177 player.t_flags |= ISHUH;
178 }
179 tp->t_flags |= ISFOUND;
180 }
181 }
182 /*
183 * Hide invisible monsters
184 */
185 if (on(*tp, ISINVIS) && off(player, CANSEE))
186 ch = mvwinch(stdscr, y, x);
187 /*
188 * Let greedy ones guard gold
189 */
190 if (on(*tp, ISGREED) && off(*tp, ISRUN))
191 {
192 rp = roomin(&hero);
193
194 if (rp != NULL && rp->r_goldval)
195 {
196 tp->t_dest = &rp->r_gold;
197 tp->t_flags |= ISRUN;
198 }
199 }
200
201 return it;
202 }
203
204 genocide()
205 {
206 register struct linked_list *ip;
207 register struct thing *mp;
208 register char c;
209 register int i;
210 register struct linked_list *nip;
211
212 addmsg("Which monster");
213 if (!terse)
214 addmsg(" do you wish to wipe out");
215 msg("? ");
216 while (!isalpha(c = readchar(cw)))
217 if (c == ESCAPE)
218 return;
219 else
220 {
221 mpos = 0;
222 msg("Please specify a letter between 'A' and 'Z'");
223 }
224 if (islower(c))
225 c = toupper(c);
226 for (ip = mlist; ip; ip = nip)
227 {
228 mp = (struct thing *) ldata(ip);
229 nip = next(ip);
230 if (mp->t_type == c)
231 remove_monster(&mp->t_pos, ip);
232 }
233 for (i = 0; i < 26; i++)
234 if (lvl_mons[i] == c)
235 {
236 lvl_mons[i] = ' ';
237 wand_mons[i] = ' ';
238 break;
239 }
240 }