1 /* NetHack 3.6 minion.c $NHDT-Date: 1432512773 2015/05/25 00:12:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.33 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016 */
8 /* JNetHack may be freely redistributed. See license for details. */
17 mtmp->mextra = newmextra();
19 EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin));
20 (void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin));
28 if (mtmp->mextra && EMIN(mtmp)) {
29 free((genericptr_t) EMIN(mtmp));
30 EMIN(mtmp) = (struct emin *) 0;
35 /* count the number of monsters on the level */
37 monster_census(spotted)
38 boolean spotted; /* seen|sensed vs all */
43 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
44 if (DEADMONSTER(mtmp))
46 if (spotted && !canspotmon(mtmp))
53 /* mon summons a monster */
59 int dtype = NON_PM, cnt = 0, result = 0, census;
65 atyp = mon->ispriest ? EPRI(mon)->shralign
66 : mon->isminion ? EMIN(mon)->min_align
67 : (ptr->maligntyp == A_NONE)
69 : sgn(ptr->maligntyp);
71 ptr = &mons[PM_WIZARD_OF_YENDOR];
72 atyp = (ptr->maligntyp == A_NONE) ? A_NONE : sgn(ptr->maligntyp);
75 if (is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) {
76 dtype = (!rn2(20)) ? dprince(atyp) : (!rn2(4)) ? dlord(atyp)
78 cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
79 } else if (is_dlord(ptr)) {
80 dtype = (!rn2(50)) ? dprince(atyp) : (!rn2(20)) ? dlord(atyp)
82 cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
83 } else if (is_ndemon(ptr)) {
84 dtype = (!rn2(20)) ? dlord(atyp) : (!rn2(6)) ? ndemon(atyp)
87 } else if (is_lminion(mon)) {
88 dtype = (is_lord(ptr) && !rn2(20))
90 : (is_lord(ptr) || !rn2(6)) ? lminion() : monsndx(ptr);
91 cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
92 } else if (ptr == &mons[PM_ANGEL]) {
93 /* non-lawful angels can also summon */
95 switch (atyp) { /* see summon_minion */
97 dtype = PM_AIR_ELEMENTAL + rn2(4);
101 dtype = ndemon(atyp);
107 cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
114 if (cnt > 1 && (mons[dtype].geno & G_UNIQ))
117 * If this daemon is unique and being re-summoned (the only way we
118 * could get this far with an extinct dtype), try another.
120 if (mvitals[dtype].mvflags & G_GONE) {
121 dtype = ndemon(atyp);
126 /* some candidates can generate a group of monsters, so simple
127 count of non-null makemon() result is not sufficient */
128 census = monster_census(FALSE);
131 mtmp = makemon(&mons[dtype], u.ux, u.uy, MM_EMIN);
134 /* an angel's alignment should match the summoner */
135 if (dtype == PM_ANGEL) {
137 EMIN(mtmp)->min_align = atyp;
138 /* renegade if same alignment but not peaceful
139 or peaceful but different alignment */
140 EMIN(mtmp)->renegade =
141 (atyp != u.ualign.type) ^ !mtmp->mpeaceful;
147 /* how many monsters exist now compared to before? */
149 result = monster_census(FALSE) - census;
155 summon_minion(alignment, talk)
159 register struct monst *mon;
162 switch ((int) alignment) {
167 mnum = PM_AIR_ELEMENTAL + rn2(4);
171 mnum = ndemon(alignment);
174 impossible("unaligned player?");
175 mnum = ndemon(A_NONE);
178 if (mnum == NON_PM) {
180 } else if (mnum == PM_ANGEL) {
181 mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN);
184 EMIN(mon)->min_align = alignment;
185 EMIN(mon)->renegade = FALSE;
187 } else if (mnum != PM_SHOPKEEPER && mnum != PM_GUARD
188 && mnum != PM_ALIGNED_PRIEST && mnum != PM_HIGH_PRIEST) {
189 /* This was mons[mnum].pxlth == 0 but is this restriction
190 appropriate or necessary now that the structures are separate? */
191 mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN);
194 EMIN(mon)->min_align = alignment;
195 EMIN(mon)->renegade = FALSE;
198 mon = makemon(&mons[mnum], u.ux, u.uy, NO_MM_FLAGS);
203 pline_The("voice of %s booms:", align_gname(alignment));
205 pline("%s
\82Ì
\90º
\82ª
\8b¿
\82¢
\82½:", align_gname(alignment));
207 verbalize("Thou shalt pay for thine indiscretion!");
209 verbalize("
\93ð
\81C
\96³
\95ª
\95Ê
\82È
\82é
\8ds
\82¢
\82Ì
\94±
\82ð
\8eó
\82¯
\82é
\82×
\82µ
\81I");
212 pline("%s appears before you.", Amonnam(mon));
214 pline("%s
\82ª
\82 \82È
\82½
\82Ì
\91O
\82É
\8c»
\82í
\82ê
\82½
\81D", Amonnam(mon));
215 mon->mstrategy &= ~STRAT_APPEARMSG;
217 mon->mpeaceful = FALSE;
218 /* don't call set_malign(); player was naughty */
222 #define Athome (Inhell && (mtmp->cham == NON_PM))
224 /* returns 1 if it won't attack. */
227 register struct monst *mtmp;
229 long cash, demand, offer;
231 if (uwep && uwep->oartifact == ART_EXCALIBUR) {
233 pline("%s looks very angry.", Amonnam(mtmp));
235 pline("%s
\82Í
\82Æ
\82Ä
\82à
\93{
\82Á
\82Ä
\82¢
\82é
\82æ
\82¤
\82É
\8c©
\82¦
\82é
\81D", Amonnam(mtmp));
236 mtmp->mpeaceful = mtmp->mtame = 0;
238 newsym(mtmp->mx, mtmp->my);
243 reset_faint(); /* if fainted - wake up */
252 /* Slight advantage given. */
253 if (is_dprince(mtmp->data) && mtmp->minvis) {
254 boolean wasunseen = !canspotmon(mtmp);
256 mtmp->minvis = mtmp->perminvis = 0;
257 if (wasunseen && canspotmon(mtmp)) {
259 pline("%s appears before you.", Amonnam(mtmp));
261 pline("%s
\82ª
\96Ú
\82Ì
\91O
\82É
\8c»
\82í
\82ê
\82½
\81D", Amonnam(mtmp));
262 mtmp->mstrategy &= ~STRAT_APPEARMSG;
264 newsym(mtmp->mx, mtmp->my);
266 if (youmonst.data->mlet == S_DEMON) { /* Won't blackmail their own. */
268 pline("%s says, \"Good hunting, %s.\"", Amonnam(mtmp),
269 flags.female ? "Sister" : "Brother");
271 pline("%s
\82Í
\8c¾
\82Á
\82½
\81u
\82æ
\82¤
\8cZ%s
\81I
\81v
\81D
\82»
\82µ
\82Ä
\8fÁ
\82¦
\82½
\81D", Amonnam(mtmp),
272 flags.female ? "
\96\85" : "
\92í");
274 if (!tele_restrict(mtmp))
275 (void) rloc(mtmp, TRUE);
278 cash = money_cnt(invent);
280 (cash * (rnd(80) + 20 * Athome))
281 / (100 * (1 + (sgn(u.ualign.type) == sgn(mtmp->data->maligntyp))));
283 if (!demand || multi < 0) { /* you have no gold or can't move */
288 /* make sure that the demand is unmeetable if the monster
289 has the Amulet, preventing monster from being satisfied
290 and removed from the game (along with said Amulet...) */
291 if (mon_has_amulet(mtmp))
292 demand = cash + (long) rn1(1000, 40);
295 pline("%s demands %ld %s for safe passage.", Amonnam(mtmp), demand,
298 pline("%s
\82Í
\92Ê
\8ds
\97¿
\82Æ
\82µ
\82Ä%ld%s
\97v
\8b\81\82µ
\82½
\81D", Amonnam(mtmp), demand,
302 if ((offer = bribe(mtmp)) >= demand) {
304 pline("%s vanishes, laughing about cowardly mortals.",
306 pline("
\89°
\95a
\82È
\92è
\96½
\82Ì
\82à
\82Ì
\82ð
\8fÎ
\82¢
\82È
\82ª
\82ç
\81C%s
\82Í
\8fÁ
\82¦
\82½
\81D",
308 } else if (offer > 0L && (long) rnd(40) > (demand - offer)) {
310 pline("%s scowls at you menacingly, then vanishes.",
312 pline("%s
\82Í
\82 \82È
\82½
\82ð
\88Ð
\8ad
\82µ
\81C
\8fÁ
\82¦
\82½
\81D",
316 pline("%s gets angry...", Amonnam(mtmp));
318 pline("%s
\82Í
\93{
\82Á
\82½
\81D
\81D
\81D", Amonnam(mtmp));
334 long umoney = money_cnt(invent);
337 getlin("How much will you offer?", buf);
339 getlin("
\82¨
\8bà
\82ð
\82¢
\82
\82ç
\97^
\82¦
\82é
\81H", buf);
340 if (sscanf(buf, "%ld", &offer) != 1)
343 /*Michael Paddon -- fix for negative offer to monster*/
347 You("try to shortchange %s, but fumble.", mon_nam(mtmp));
349 You("%s
\82ð
\82¾
\82Ü
\82»
\82¤
\82Æ
\82µ
\82½
\82ª
\81C
\8e¸
\94s
\82µ
\82½
\81D", mon_nam(mtmp));
351 } else if (offer == 0L) {
355 You("
\8b\91\82ñ
\82¾
\81D");
357 } else if (offer >= umoney) {
359 You("give %s all your gold.", mon_nam(mtmp));
361 You("%s
\82É
\82¨
\8bà
\82ð
\91S
\82Ä
\97^
\82¦
\82½
\81D", mon_nam(mtmp));
365 You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer));
367 You("%s
\82É%ld%s
\97^
\82¦
\82½
\81D", mon_nam(mtmp), offer, currency(offer));
369 (void) money2mon(mtmp, offer);
380 for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) {
381 pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS);
382 if (!(mvitals[pm].mvflags & G_GONE)
383 && (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
386 return (dlord(atyp)); /* approximate */
395 for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) {
396 pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX);
397 if (!(mvitals[pm].mvflags & G_GONE)
398 && (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
401 return (ndemon(atyp)); /* approximate */
404 /* create lawful (good) lord */
408 if (!(mvitals[PM_ARCHON].mvflags & G_GONE))
411 return (lminion()); /* approximate */
418 struct permonst *ptr;
420 for (tryct = 0; tryct < 20; tryct++) {
421 ptr = mkclass(S_ANGEL, 0);
422 if (ptr && !is_lord(ptr))
423 return (monsndx(ptr));
434 struct permonst *ptr;
436 for (tryct = 0; tryct < 20; tryct++) {
437 ptr = mkclass(S_DEMON, 0);
438 if (ptr && is_ndemon(ptr)
439 && (atyp == A_NONE || sgn(ptr->maligntyp) == sgn(atyp)))
440 return (monsndx(ptr));
446 /* guardian angel has been affected by conflict so is abandoning hero */
448 lose_guardian_angel(mon)
449 struct monst *mon; /* if null, angel hasn't been created yet */
455 if (canspotmon(mon)) {
458 pline("%s rebukes you, saying:", Monnam(mon));
460 pline("%s
\82Í
\82 \82È
\82½
\82ð
\94ñ
\93ï
\82µ
\82½
\81F", Monnam(mon));
462 verbalize("Since you desire conflict, have some more!");
464 verbalize("
\93¬
\91\88\82ð
\96]
\82ñ
\82Å
\82¢
\82é
\82æ
\82¤
\82¾
\82©
\82ç
\81C
\82à
\82Á
\82Æ
\97^
\82¦
\82Ä
\82â
\82ë
\82¤
\81I");
467 pline("%s vanishes!", Monnam(mon));
469 pline("%s
\82Í
\8fÁ
\82¦
\82½
\81I", Monnam(mon));
474 /* create 2 to 4 hostile angels to replace the lost guardian */
475 for (i = rn1(3, 2); i > 0; --i) {
478 if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL]))
479 (void) mk_roamer(&mons[PM_ANGEL], u.ualign.type, mm.x, mm.y,
484 /* just entered the Astral Plane; receive tame guardian angel if worthy */
486 gain_guardian_angel()
492 Hear_again(); /* attempt to cure any deafness now (divine
493 message will be heard even if that fails) */
496 pline("A voice booms:");
498 pline("
\90º
\82ª
\8b¿
\82¢
\82½:");
500 verbalize("Thy desire for conflict shall be fulfilled!");
502 verbalize("
\81u
\93ð
\82Ì
\93¬
\91\88\82Ö
\82Ì
\96]
\82Ý
\81C
\82©
\82È
\82¦
\82ç
\82ê
\82é
\82×
\82µ
\81I
\81v");
503 /* send in some hostile angels instead */
504 lose_guardian_angel((struct monst *) 0);
505 } else if (u.ualign.record > 8) { /* fervent */
507 pline("A voice whispers:");
509 pline("
\82³
\82³
\82â
\82«
\90º
\82ª
\95·
\82±
\82¦
\82½:");
511 verbalize("Thou hast been worthy of me!");
513 verbalize("
\81u
\93ð
\81C
\89ä
\82ª
\95]
\89¿
\82ð
\93¾
\82½
\82è
\81I
\81v");
516 if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL])
517 && (mtmp = mk_roamer(&mons[PM_ANGEL], u.ualign.type, mm.x, mm.y,
519 mtmp->mstrategy &= ~STRAT_APPEARMSG;
522 pline("An angel appears near you.");
524 pline("
\93V
\8eg
\82ª
\82 \82È
\82½
\82Ì
\82»
\82Î
\82É
\8c»
\82í
\82ê
\82½
\81D");
527 You_feel("the presence of a friendly angel near you.");
529 You("
\8bß
\82
\82É
\97F
\8dD
\93I
\82È
\93V
\8eg
\82Ì
\91¶
\8dÝ
\82ð
\8a´
\82¶
\82½
\81D");
530 /* guardian angel -- the one case mtame doesn't
531 * imply an edog structure, so we don't want to
535 /* make him strong enough vs. endgame foes */
536 mtmp->m_lev = rn1(8, 15);
537 mtmp->mhp = mtmp->mhpmax =
538 d((int) mtmp->m_lev, 10) + 30 + rnd(30);
539 if ((otmp = select_hwep(mtmp)) == 0) {
540 otmp = mksobj(SILVER_SABER, FALSE, FALSE);
541 if (mpickobj(mtmp, otmp))
542 panic("merged weapon?");
547 if ((otmp = which_armor(mtmp, W_ARMS)) == 0
548 || otmp->otyp != SHIELD_OF_REFLECTION) {
549 (void) mongets(mtmp, AMULET_OF_REFLECTION);
550 m_dowear(mtmp, TRUE);