-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonsters.c
381 lines (357 loc) · 8.32 KB
/
monsters.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*
* File with various monster functions in it
*
* @(#)monsters.c 9.0 (rdk) 7/17/84
*
* Super-Rogue
* Copyright (C) 1984 Robert D. Kindelberger
* All rights reserved.
*
* Based on "Rogue: Exploring the Dungeons of Doom"
* Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <ctype.h>
#include <curses.h>
#include <stdbool.h>
#include <stddef.h>
#include "rogue.h"
#include "rogue.ext"
/*
* rnd_mon:
* Pick a monster to show up. The lower the level,
* the meaner the monster.
*/
int rnd_mon(bool wander,bool baddie)
/* baddie == TRUE when from a polymorph stick */
{
int i, ok, cnt;
cnt = 0;
if (levcount == 0) /* if only asmodeus possible */
return(MAXMONS);
if (baddie) {
while (1) {
i = rnd(MAXMONS); /* pick ANY monster */
if (monsters[i].m_lev.l_lev < 0) /* skip genocided ones */
continue;
return i;
}
}
ok = FALSE;
do {
/*
* get a random monster from this range
*/
i = rnd(levcount);
/*
* Only create a wandering monster if we want one
* (or the count is exceeded)
*/
if (!wander || mtlev[i]->m_lev.d_wand || ++cnt > 500)
ok = TRUE;
} while(!ok);
return (midx(mtlev[i]->m_show));
}
/*
* lev_mon:
* This gets all monsters possible on this level
*/
void lev_mon()
{
int i;
struct monster *mm;
levcount = 0;
for (i = 0; i < MAXMONS; i++) {
mm = &monsters[i];
if (mm->m_lev.h_lev >= level && mm->m_lev.l_lev <= level) {
mtlev[levcount] = mm;
if (++levcount >= MONRANGE)
break;
}
}
if (levcount == 0) /* if no monsters are possible */
mtlev[0] = &monsters[MAXMONS]; /* then asmodeus 'A' */
}
/*
* new_monster:
* Pick a new monster and add it to the list
*/
struct linked_list *new_monster(char type,struct coord *cp,bool treas)
{
struct linked_list *item;
struct thing *tp;
struct monster *mp;
struct stats *st;
float killexp; /* experience gotten for killing him */
item = new_item(sizeof(struct thing));
attach(mlist, item);
tp = THINGPTR(item);
st = &tp->t_stats;
mp = &monsters[type]; /* point to this monsters structure */
tp->t_type = mp->m_show;
tp->t_indx = type;
tp->t_pos = *cp;
tp->t_room = roomin(cp);
tp->t_oldch = mvwinch(cw, cp->y, cp->x);
tp->t_nomove = 0;
tp->t_nocmd = 0;
mvwaddch(mw, cp->y, cp->x, tp->t_type);
/*
* copy monster data
*/
tp->t_stats = mp->m_stats;
/*
* If below amulet level, make the monsters meaner the
* deeper the hero goes.
*/
if (level > AMLEVEL)
st->s_lvl += ((level - AMLEVEL) / 4);
/*
* If monster in treasure room, then tougher.
*/
if (treas)
st->s_lvl += 1;
if (levtype == MAZELEV)
st->s_lvl += 1;
/*
* If the hero is going back up, then the monsters are more
* prepared for him, so tougher.
*/
if (goingup())
st->s_lvl += 1;
/*
* Get hit points for monster depending on his experience
*/
st->s_hpt = roll(st->s_lvl, 8);
st->s_maxhp = st->s_hpt;
/*
* Adjust experience point we get for killing it by the
* strength of this particular monster by ~~ +- 50%
*/
killexp = mp->m_stats.s_exp * (0.47 + (float)st->s_hpt /
(8 * (float)st->s_lvl));
st->s_exp = killexp; /* use float for accuracy */
if(st->s_exp < 1)
st->s_exp = 1; /* minimum 1 experience point */
tp->t_flags = mp->m_flags;
/*
* If monster in treasure room, then MEAN
*/
if (treas || levtype == MAZELEV)
tp->t_flags |= ISMEAN;
tp->t_turn = TRUE;
tp->t_pack = NULL;
/*
* Dont wander if treas room
*/
if (iswearing(R_AGGR) && !treas)
runto(cp, &hero);
if (tp->t_type == 'M') {
char mch;
if (tp->t_pack != NULL)
mch = (OBJPTR(tp->t_pack))->o_type;
else {
switch (rnd(level >= AMLEVEL ? 9 : 8)) {
case 0: mch = GOLD;
when 1: mch = POTION;
when 2: mch = SCROLL;
when 3: mch = STAIRS;
when 4: mch = WEAPON;
when 5: mch = ARMOR;
when 6: mch = RING;
when 7: mch = STICK;
when 8: mch = AMULET;
}
}
if (treas)
mch = 'M'; /* no disguise in treasure room */
tp->t_disguise = mch;
}
return item;
}
/*
* wanderer:
* A wandering monster has awakened and is headed for the player
*/
void wanderer()
{
int ch;
struct room *rp, *hr = player.t_room;
struct linked_list *item;
struct thing *tp;
struct coord mp;
do {
rp = &rooms[rnd_room()];
if (rp != hr || levtype == MAZELEV) {
mp = *rnd_pos(rp);
ch = mvinch(mp.y, mp.x);
}
} while (!step_ok(ch));
item = new_monster(rnd_mon(TRUE,FALSE), &mp, FALSE);
tp = THINGPTR(item);
tp->t_flags |= ISRUN;
tp->t_dest = &hero;
}
/*
* wake_monster:
* What to do when the hero steps next to a monster
*/
struct linked_list *wake_monster(int y,int x)
{
struct thing *tp;
struct linked_list *it;
struct room *rp;
char ch;
bool treas = FALSE;
if ((it = find_mons(y, x)) == NULL)
return NULL;
tp = THINGPTR(it);
ch = tp->t_type;
/*
* Every time he sees mean monster, it might start chasing him
*/
rp = player.t_room;
if (rp != NULL && rf_on(rp,ISTREAS)) {
tp->t_flags &= ~ISHELD;
treas = TRUE;
}
if (treas || (rnd(100) > 33 && on(*tp,ISMEAN) && off(*tp,ISHELD) &&
!iswearing(R_STEALTH))) {
tp->t_dest = &hero;
tp->t_flags |= ISRUN;
}
if (ch == 'U' && pl_off(ISBLIND)) {
if ((rp != NULL && !rf_on(rp,ISDARK) && levtype != MAZELEV)
|| DISTANCE(y, x, hero.y, hero.x) < 3) {
if (off(*tp,ISFOUND) && !save(VS_PETRIFICATION)
&& !iswearing(R_SUSAB) && pl_off(ISINVINC)) {
msg("The umber hulk's gaze has confused you.");
if (pl_on(ISHUH))
lengthen(unconfuse,rnd(20)+HUHDURATION);
else
fuse(unconfuse,TRUE,rnd(20)+HUHDURATION);
player.t_flags |= ISHUH;
}
tp->t_flags |= ISFOUND;
}
}
/*
* Hide invisible monsters
*/
if ((tp->t_flags & ISINVIS) && pl_off(CANSEE))
ch = mvinch(y, x);
/*
* Let greedy ones guard gold
*/
if (on(*tp, ISGREED) && off(*tp, ISRUN)) {
if (rp != NULL && rp->r_goldval) {
tp->t_dest = &rp->r_gold;
tp->t_flags |= ISRUN;
}
}
return it;
}
/*
* genocide:
* Eradicate a monster forevermore
*/
int genocide()
{
struct linked_list *ip, *nip;
struct thing *mp;
struct monster *mm;
int i, ii, c;
if (levcount == 0) {
mpos = 0;
msg("You cannot genocide Asmodeus !!");
return 0;
}
tryagain:
i = TRUE; /* assume an error now */
while (i) {
msg("Which monster (remember UPPER & lower case)?");
c = readchar(); /* get a char */
if (c == ESCAPE) { /* he can abort (the fool) */
msg("");
return 0;
}
if (isalpha(c)) /* valid char here */
i = FALSE; /* exit the loop */
else { /* he didn't type a letter */
mpos = 0;
msg("Please specify a letter between 'A' and 'z'");
}
}
i = midx(c); /* get index to monster */
mm = &monsters[i];
if (mm->m_lev.l_lev < 0) {
mpos = 0;
msg("You have already eliminated the %s.",mm->m_name);
goto tryagain;
}
for (ip = mlist; ip != NULL; ip = nip) {
mp = THINGPTR(ip);
nip = next(ip);
if (mp->t_type == c)
remove_monster(&mp->t_pos, ip);
}
mm->m_lev.l_lev = -1; /* get rid of it */
mm->m_lev.h_lev = -1;
lev_mon(); /* redo monster list */
mpos = 0;
msg("You have wiped out the %s.",mm->m_name);
return 0;
}
/*
* unhold:
* Release the player from being held
*/
void unhold(char whichmon)
{
switch (whichmon) {
case 'F':
fung_hit = 0;
strcpy(monsters[midx('F')].m_stats.s_dmg, "000d0");
case 'd':
player.t_flags &= ~ISHELD;
}
}
/*
* midx:
* This returns an index to 'whichmon'
*/
int midx(char whichmon)
{
if (isupper(whichmon))
return(whichmon - 'A'); /* 0 to 25 for uppercase */
else if (islower(whichmon))
return(whichmon - 'a' + 26); /* 26 to 51 for lowercase */
else
return(MAXMONS); /* 52 for Asmodeus */
}
/*
* monhurt:
* See when monster should run or fight. Return
* TRUE if hit points less than acceptable.
*/
bool monhurt(struct thing *th)
{
int ewis, crithp, f1, f2;
struct stats *st;
st = &th->t_stats;
ewis = st->s_ef.a_wis;
if (ewis <= MONWIS) /* stupid monsters dont know */
return FALSE;
f1 = st->s_maxhp / 4; /* base hpt for being hurt */
f2 = (ewis - MONWIS) * 5 / 3; /* bonus for smart monsters */
if (th->t_flags & ISWOUND) /* if recovering from being */
f1 *= 2; /* wounded, then double the base */
crithp = f1 + f2; /* get critical hpt for hurt */
if (crithp > st->s_maxhp) /* only up to max hpt */
crithp = st->s_maxhp;
if (st->s_hpt < crithp) /* if < critical, then still hurt */
return TRUE;
return FALSE;
}