-
Notifications
You must be signed in to change notification settings - Fork 0
/
monsters.c
233 lines (189 loc) · 5.3 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
/*
* monsters.c: Rog-O-Matic XIV (CMU) Tue Mar 19 21:39:44 1985 - mlm
* Copyright (C) 1985 by A. Appel, G. Jacobson, L. Hamey, and M. Mauldin
*
* This file contains all of the monster specific functions.
*/
# include <stdio.h>
# include <ctype.h>
# include <curses.h>
# include "types.h"
# include "globals.h"
# define ADJACENT(m) (max (abs (mlist[m].mrow - atrow),\
abs (mlist[m].mcol - atcol)) == 1)
/*
* monname: Return a monster name given letter '@ABC..Z'
*/
char *monname (m)
char m;
{ return (monhist[monindex[m-'A'+1]].m_name);
}
/*
* addmonster: add a monster to this level. Remove any monsters on the
* list which are in the same square.
*/
addmonster (ch, r, c, quiescence)
char ch;
int r, c, quiescence;
{ char *monster = monname (ch);
if (r > 1 || c > 3)
{ if (isholder (monster)) quiescence = AWAKE;
deletemonster (r, c);
mlist[mlistlen].chr = ch;
mlist[mlistlen].mrow = r;
mlist[mlistlen].mcol = c;
mlist[mlistlen].q = quiescence;
if (++mlistlen >= MAXMONST) dwait (D_FATAL, "Too many monsters");
setrc (MONSTER, r, c);
lyinginwait = 0;
new_arch = 1;
/* If we can see it, it is not really invisible */
if (stlmatch (monster, "invisible") || streq (monster, "phantom"))
beingstalked = 0;
}
}
/*
* deletemonster: remove a monster from the list at location (row, col).
*/
deletemonster (r, c)
int r, c;
{ int i;
new_arch = 1;
unsetrc (MONSTER, r, c);
for (i = 0; i < mlistlen; ++i)
if (mlist[i].mcol == c && mlist[i].mrow == r)
{ mlist[i] = mlist[--mlistlen]; i--; }
}
/*
* dumpmonsters: (debugging) dump the list of monsters on this level.
*/
dumpmonster ()
{ int i;
at (1, 0);
for (i = 0; i < mlistlen; ++i)
printw ("%s at %d,%d(%c) \n",
mlist[i].q == AWAKE ? "alert" :
mlist[i].q == ASLEEP ? "sleeping" :
mlist[i].q == HELD ? "held" : "unknown",
mlist[i].mrow, mlist[i].mcol,
mlist[i].chr);
printw ("You are at %d,%d.", atrow, atcol);
at (row, col);
}
/*
* sleepmonster: Turn all unknown monsters into sleeping monsters.
* This routine is called after we have executed a command, so if
* the value of ASLEEP is not overridden by the monsters movement,
* it sat still for a turn and must be asleep.
*/
sleepmonster ()
{ register int m;
for (m = 0; m < mlistlen; ++m)
{ if (mlist[m].q == 0 && ! ADJACENT (m))
{ dwait (D_MONSTER, "Found a sleeping %s at %d,%d",
monname (mlist[m].chr), mlist[m].mrow, mlist[m].mcol);
mlist[m].q = ASLEEP;
}
}
}
/*
* holdmonsters: Mark all close monsters as being held.
*/
holdmonsters ()
{ register int m;
for (m = 0; m < mlistlen; ++m)
{ if (mlist[m].q == 0 &&
(max (abs (mlist[m].mrow - atrow),
abs (mlist[m].mcol - atcol)) < 3))
{ dwait (D_MONSTER, "Holding %s at %d,%d",
monname (mlist[m].chr), mlist[m].mrow, mlist[m].mcol);
mlist[m].q = HELD;
}
}
}
/*
* wakemonster: Turn monsters into waking monsters
*
* dir = 0-7 means wake up adjacent plus monster in that dir
* dir = 8 means wake up only adjacent monster
* dir = ALL means wake up all monsters
* dir = -m means wake up all adjacent monsters of type m.
*/
wakemonster (dir)
int dir;
{ register int m;
for (m = 0; m < mlistlen; ++m)
{ if (mlist[m].q != AWAKE &&
(dir == ALL ||
(dir < 0 && ADJACENT(m) && mlist[m].chr == -dir + 'A' - 1) ||
(dir >= 0 && dir < 8 &&
mlist[m].mrow == atdrow(dir) && mlist[m].mcol == atdcol(dir))))
{ dwait (D_MONSTER, "Waking up %s at %d,%d",
monname (mlist[m].chr), mlist[m].mrow, mlist[m].mcol);
mlist[m].q = AWAKE;
setrc (EVERCLR, mlist[m].mrow, mlist[m].mcol);
}
}
}
/*
* seemonster: Return true if a particular monster is on the monster list.
*/
seemonster (monster)
char *monster;
{ register int m;
for (m = 0; m < mlistlen; ++m)
if (streq (monname (mlist[m].chr), monster))
return (1);
return (0);
}
/*
* seeawakemonster: Returns true if there is a particular awake
* monster on the monster list. DR UTexas 26 Jan 84
*/
seeawakemonster (monster)
char *monster;
{ register int m;
for (m = 0; m < mlistlen; ++m)
if (streq (monname (mlist[m].chr), monster) && mlist[m].q == AWAKE)
return (1);
return (0);
}
/*
* monsternum: Given a string e.g. "umber hulk", return the monster
* number from 0 to 26, e.g. "umber hulk" ==> 21. Zero
* is used for unknown monsters (e.g. "it").
*/
monsternum (monster)
char *monster;
{ int m, mh;
if ((mh = findmonster (monster)) != NONE)
for (m=0; m<=26; m++)
if (monindex[m] == mh) return (m);
return (0);
}
/*
* newmonsterlevel: Starting a new level. Set the initial sleep status of
* each monster.
*/
newmonsterlevel ()
{ register int m;
register char *monster;
for (m=0; m<mlistlen; m++)
{ monster = monname (mlist[m].chr);
if (streq (monster, "floating eye") ||
streq (monster, "leprechaun") ||
streq (monster, "nymph") ||
streq (monster, "ice monster"))
mlist[m].q = ASLEEP;
else
mlist[m].q = 0;
}
}
/*
* isholder: Return true if the monster can hold us.
*/
isholder (monster)
register char *monster;
{
return (streq (monster, "venus flytrap") || streq (monster, "violet fungi"));
}