/* * Make a chameleon look like a new monster * returns 1 if the monster actuall changed */ int newcham(struct monst *mtmp, struct permonst *mdat) { int mhp; int hpn; int hpd; /* Still the same monster */ if(mdat == mtmp->data) { return 0; } #ifndef NOWORM /* Throw tail away */ if(mtmp->wormno) { wormdead(mtmp); } #endif hpn = mtmp->mhp; hpd = mtmp->data->mlevel * 8; if(hpd == 0) { hpd = 4; } mtmp->data = mdat; mhp = mdat->mlevel * 8; /* New hp: same fraction of max as before */ mtmp->mhp = 2 + ((hpn * mhp) / hpd); hpn = mtmp->orig_hp; mtmp->orig_hp = 2 + ((hpn * mhp) / hpd); if(mdat->mlet == 'I') { mtmp->minvis = 1; } else { mtmp->minvis = 0; } #ifndef NOWORM if((mdat->mlet == 'w') && (getwn(mtmp) != 0)) { initworm(mtmp); } #endif /* Necessary for 'I' and to force pmon */ unpmon(mtmp); pmon(mtmp); return 1; }
/* * called with [x,y] = coordinates; * [0,0] means anyplace * [u.ux,u.uy] means: call mnexto (if !in_mklev) * * In case we make an Orc or killer bee, we make an entire horde (swarm); * note that in this case we return only one of them (the one at [x,y]). */ struct monst * makemon(struct permonst *ptr, int x, int y) { struct monst *mtmp; int tmp, ct; boolean anything = (!ptr); extern boolean in_mklev; if(x != 0 || y != 0) if(m_at(x,y)) return((struct monst *) 0); if(ptr){ if(strchr(fut_geno, ptr->mlet)) return((struct monst *) 0); } else { ct = CMNUM - strlen(fut_geno); if(strchr(fut_geno, 'm')) ct++; /* make only 1 minotaur */ if(strchr(fut_geno, '@')) ct++; if(ct <= 0) return(0); /* no more monsters! */ tmp = rn2(ct*dlevel/24 + 7); if(tmp < dlevel - 4) tmp = rn2(ct*dlevel/24 + 12); if(tmp >= ct) tmp = rn1(ct - ct/2, ct/2); for(ct = 0; ct < CMNUM; ct++){ ptr = &mons[ct]; if(strchr(fut_geno, ptr->mlet)) continue; if(!tmp--) goto gotmon; } panic("makemon?"); } gotmon: mtmp = newmonst(ptr->pxlth); *mtmp = zeromonst; /* clear all entries in structure */ for(ct = 0; ct < ptr->pxlth; ct++) ((char *) &(mtmp->mextra[0]))[ct] = 0; mtmp->nmon = fmon; fmon = mtmp; mtmp->m_id = flags.ident++; mtmp->data = ptr; mtmp->mxlth = ptr->pxlth; if(ptr->mlet == 'D') mtmp->mhpmax = mtmp->mhp = 80; else if(!ptr->mlevel) mtmp->mhpmax = mtmp->mhp = rnd(4); else mtmp->mhpmax = mtmp->mhp = d(ptr->mlevel, 8); mtmp->mx = x; mtmp->my = y; mtmp->mcansee = 1; if(ptr->mlet == 'M'){ mtmp->mimic = 1; mtmp->mappearance = ']'; } if(!in_mklev) { if(x == u.ux && y == u.uy && ptr->mlet != ' ') mnexto(mtmp); if(x == 0 && y == 0) rloc(mtmp); } if(ptr->mlet == 's' || ptr->mlet == 'S') { mtmp->mhide = mtmp->mundetected = 1; if(in_mklev) if(mtmp->mx && mtmp->my) (void) mkobj_at(0, mtmp->mx, mtmp->my); } if(ptr->mlet == ':') { mtmp->cham = 1; (void) newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]); } if(ptr->mlet == 'I' || ptr->mlet == ';') mtmp->minvis = 1; if(ptr->mlet == 'L' || ptr->mlet == 'N' || (in_mklev && strchr("&w;", ptr->mlet) && rn2(5)) ) mtmp->msleep = 1; #ifndef NOWORM if(ptr->mlet == 'w' && getwn(mtmp)) initworm(mtmp); #endif /* NOWORM */ if(anything) if(ptr->mlet == 'O' || ptr->mlet == 'k') { coord mm; int cnt = rnd(10); mm.x = x; mm.y = y; while(cnt--) { mm = enexto(mm.x, mm.y); (void) makemon(ptr, mm.x, mm.y); } } return(mtmp); }
/* weptyp: uwep->otyp or 0 */ void cutworm(struct monst *mtmp, xchar x, xchar y, uchar weptyp) { struct wseg *wtmp, *wtmp2; struct monst *mtmp2; int tmp, tmp2; if (mtmp->mx == x && mtmp->my == y) /* hit headon */ return; /* cutting goes best with axe or sword */ tmp = rnd(20); if (weptyp == LONG_SWORD || weptyp == TWO_HANDED_SWORD || weptyp == AXE) tmp += 5; if (tmp < 12) return; /* if tail then worm just loses a tail segment */ tmp = mtmp->wormno; wtmp = wsegs[tmp]; if (wtmp->wx == x && wtmp->wy == y) { wsegs[tmp] = wtmp->nseg; remseg(wtmp); return; } /* cut the worm in two halves */ mtmp2 = newmonst(0); *mtmp2 = *mtmp; mtmp2->mxlth = mtmp2->mnamelth = 0; /* sometimes the tail end dies */ if (rn2(3) || !getwn(mtmp2)) { monfree(mtmp2); tmp2 = 0; } else { tmp2 = mtmp2->wormno; wsegs[tmp2] = wsegs[tmp]; wgrowtime[tmp2] = 0; } do { if (wtmp->nseg->wx == x && wtmp->nseg->wy == y) { if (tmp2) wheads[tmp2] = wtmp; wsegs[tmp] = wtmp->nseg->nseg; remseg(wtmp->nseg); wtmp->nseg = 0; if (tmp2) { pline("You cut the worm in half."); mtmp2->mhpmax = mtmp2->mhp = d(mtmp2->data->mlevel, 8); mtmp2->mx = wtmp->wx; mtmp2->my = wtmp->wy; mtmp2->nmon = fmon; fmon = mtmp2; pmon(mtmp2); } else { pline("You cut off part of the worm's tail."); remseg(wtmp); } mtmp->mhp /= 2; return; } wtmp2 = wtmp->nseg; if (!tmp2) remseg(wtmp); wtmp = wtmp2; } while (wtmp->nseg); panic("Cannot find worm segment"); }