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.3 2004/11/06 12:29:17 eirikn Exp $ */
7 extern char fut_geno[];
9 extern struct obj *mkobj_at();
10 struct monst zeromonst;
13 * called with [x,y] = coordinates;
14 * [0,0] means anyplace
15 * [u.ux,u.uy] means: call mnexto (if !in_mklev)
17 * In case we make an Orc or killer bee, we make an entire horde (swarm);
18 * note that in this case we return only one of them (the one at [x,y]).
26 boolean anything = (!ptr);
27 extern boolean in_mklev;
29 if(x != 0 || y != 0) if(m_at(x,y)) return((struct monst *) 0);
31 if(index(fut_geno, ptr->mlet)) return((struct monst *) 0);
33 ct = CMNUM - strlen(fut_geno);
34 if(index(fut_geno, 'm')) ct++; /* make only 1 minotaur */
35 if(index(fut_geno, '@')) ct++;
36 if(ct <= 0) return(0); /* no more monsters! */
37 tmp = rn2(ct*dlevel/24 + 7);
38 if(tmp < dlevel - 4) tmp = rn2(ct*dlevel/24 + 12);
39 if(tmp >= ct) tmp = rn1(ct - ct/2, ct/2);
40 for(ct = 0; ct < CMNUM; ct++){
42 if(index(fut_geno, ptr->mlet))
44 if(!tmp--) goto gotmon;
49 mtmp = newmonst(ptr->pxlth);
50 *mtmp = zeromonst; /* clear all entries in structure */
51 for(ct = 0; ct < ptr->pxlth; ct++)
52 ((char *) &(mtmp->mextra[0]))[ct] = 0;
55 mtmp->m_id = flags.ident++;
57 mtmp->mxlth = ptr->pxlth;
58 if(ptr->mlet == 'D') mtmp->mhpmax = mtmp->mhp = 80;
59 else if(!ptr->mlevel) mtmp->mhpmax = mtmp->mhp = rnd(4);
60 else mtmp->mhpmax = mtmp->mhp = d(ptr->mlevel, 8);
66 mtmp->mappearance = ']';
69 if(x == u.ux && y == u.uy && ptr->mlet != ' ')
74 if(ptr->mlet == 's' || ptr->mlet == 'S') {
75 mtmp->mhide = mtmp->mundetected = 1;
77 if(mtmp->mx && mtmp->my)
78 (void) mkobj_at(0, mtmp->mx, mtmp->my);
80 if(ptr->mlet == ':') {
82 (void) newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]);
84 if(ptr->mlet == 'I' || ptr->mlet == ';')
86 if(ptr->mlet == 'L' || ptr->mlet == 'N'
87 || (in_mklev && index("&w;", ptr->mlet) && rn2(5))
91 if(ptr->mlet == 'w' && getwn(mtmp))
95 if(anything) if(ptr->mlet == 'O' || ptr->mlet == 'k') {
102 mm = enexto(mm.x, mm.y);
103 (void) makemon(ptr, mm.x, mm.y);
115 coord foo[15], *tfoo;
120 do { /* full kludge action. */
121 for(x = xx-range; x <= xx+range; x++)
122 if(goodpos(x, yy-range)) {
124 tfoo++->y = yy-range;
125 if(tfoo == &foo[15]) goto foofull;
127 for(x = xx-range; x <= xx+range; x++)
128 if(goodpos(x,yy+range)) {
130 tfoo++->y = yy+range;
131 if(tfoo == &foo[15]) goto foofull;
133 for(y = yy+1-range; y < yy+range; y++)
134 if(goodpos(xx-range,y)) {
137 if(tfoo == &foo[15]) goto foofull;
139 for(y = yy+1-range; y < yy+range; y++)
140 if(goodpos(xx+range,y)) {
143 if(tfoo == &foo[15]) goto foofull;
146 } while(tfoo == foo);
148 return( foo[rn2(tfoo-foo)] );
151 goodpos(x,y) /* used only in mnexto and rloc */
154 ! (x < 1 || x > COLNO-2 || y < 1 || y > ROWNO-2 ||
155 m_at(x,y) || !ACCESSIBLE(levl[x][y].typ)
156 || (x == u.ux && y == u.uy)
157 || sobj_at(ENORMOUS_ROCK, x, y)
165 char ch = mtmp->data->mlet;
168 if(ch == 'w' && mtmp->mx) return; /* do not relocate worms */
173 } while(!goodpos(tx,ty));
176 if(u.ustuck == mtmp){
192 struct permonst *ptr;
194 for(ct = 0; ct < CMNUM; ct++) {
197 return(makemon(ptr,x,y));