1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.makemon.c - version 1.0.2 */
3 /* $FreeBSD: src/games/hack/hack.makemon.c,v 1.4 1999/11/16 10:26:36 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.makemon.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
8 struct monst zeromonst;
11 * called with [x,y] = coordinates;
12 * [0,0] means anyplace
13 * [u.ux,u.uy] means: call mnexto (if !in_mklev)
15 * In case we make an Orc or killer bee, we make an entire horde (swarm);
16 * note that in this case we return only one of them (the one at [x,y]).
19 makemon(struct permonst *ptr, int x, int y)
23 boolean anything = (!ptr);
29 if (strchr(fut_geno, ptr->mlet))
32 ct = CMNUM - strlen(fut_geno);
33 if (strchr(fut_geno, 'm')) /* make only 1 minotaur */
35 if (strchr(fut_geno, '@'))
37 if (ct <= 0) /* no more monsters! */
39 tmp = rn2(ct * dlevel / 24 + 7);
41 tmp = rn2(ct * dlevel / 24 + 12);
43 tmp = rn1(ct - ct / 2, ct / 2);
44 for (ct = 0; ct < CMNUM; ct++) {
46 if (strchr(fut_geno, ptr->mlet))
54 mtmp = newmonst(ptr->pxlth);
55 *mtmp = zeromonst; /* clear all entries in structure */
56 for (ct = 0; (unsigned)ct < ptr->pxlth; ct++)
57 ((char *)&(mtmp->mextra[0]))[ct] = 0;
60 mtmp->m_id = flags.ident++;
62 mtmp->mxlth = ptr->pxlth;
64 mtmp->mhpmax = mtmp->mhp = 80;
65 else if (!ptr->mlevel)
66 mtmp->mhpmax = mtmp->mhp = rnd(4);
68 mtmp->mhpmax = mtmp->mhp = d(ptr->mlevel, 8);
72 if (ptr->mlet == 'M') {
74 mtmp->mappearance = ']';
77 if (x == u.ux && y == u.uy && ptr->mlet != ' ')
82 if (ptr->mlet == 's' || ptr->mlet == 'S') {
83 mtmp->mhide = mtmp->mundetected = 1;
85 if (mtmp->mx && mtmp->my)
86 mkobj_at(0, mtmp->mx, mtmp->my);
88 if (ptr->mlet == ':') {
90 newcham(mtmp, &mons[dlevel + 14 + rn2(CMNUM - 14 - dlevel)]);
92 if (ptr->mlet == 'I' || ptr->mlet == ';')
94 if (ptr->mlet == 'L' || ptr->mlet == 'N'
95 || (in_mklev && strchr("&w;", ptr->mlet) && rn2(5)))
99 if (ptr->mlet == 'w' && getwn(mtmp))
104 if (ptr->mlet == 'O' || ptr->mlet == 'k') {
110 mm = enexto(mm.x, mm.y);
111 makemon(ptr, mm.x, mm.y);
119 enexto(xchar xx, xchar yy)
122 coord foo[15], *tfoo;
127 do { /* full kludge action. */
128 for (x = xx - range; x <= xx + range; x++)
129 if (goodpos(x, yy - range)) {
131 tfoo++->y = yy - range;
132 if (tfoo == &foo[15])
135 for (x = xx - range; x <= xx + range; x++)
136 if (goodpos(x, yy + range)) {
138 tfoo++->y = yy + range;
139 if (tfoo == &foo[15])
142 for (y = yy + 1 - range; y < yy + range; y++)
143 if (goodpos(xx - range, y)) {
144 tfoo->x = xx - range;
146 if (tfoo == &foo[15])
149 for (y = yy + 1 - range; y < yy + range; y++)
150 if (goodpos(xx + range, y)) {
151 tfoo->x = xx + range;
153 if (tfoo == &foo[15])
157 } while (tfoo == foo);
159 return (foo[rn2(tfoo - foo)]);
163 goodpos(int x, int y) /* used only in mnexto and rloc */
166 !(x < 1 || x > COLNO - 2 || y < 1 || y > ROWNO - 2 ||
167 m_at(x, y) || !ACCESSIBLE(levl[x][y].typ)
168 || (x == u.ux && y == u.uy)
169 || sobj_at(ENORMOUS_ROCK, x, y)
174 rloc(struct monst *mtmp)
177 char ch = mtmp->data->mlet;
180 if (ch == 'w' && mtmp->mx) /* do not relocate worms */
184 tx = rn1(COLNO - 3, 2);
186 } while (!goodpos(tx, ty));
189 if (u.ustuck == mtmp) {
201 mkmon_at(char let, int x, int y)
204 struct permonst *ptr;
206 for (ct = 0; ct < CMNUM; ct++) {
208 if (ptr->mlet == let)
209 return (makemon(ptr, x, y));