OSDN Git Service

add translation
[jnethack/source.git] / src / minion.c
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 /*-Copyright (c) Robert Patrick Rankin, 2008. */
4 /* NetHack may be freely redistributed.  See license for details. */
5
6 /* JNetHack Copyright */
7 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
8 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016            */
9 /* JNetHack may be freely redistributed.  See license for details. */
10
11 #include "hack.h"
12
13 void
14 newemin(mtmp)
15 struct monst *mtmp;
16 {
17     if (!mtmp->mextra)
18         mtmp->mextra = newmextra();
19     if (!EMIN(mtmp)) {
20         EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin));
21         (void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin));
22     }
23 }
24
25 void
26 free_emin(mtmp)
27 struct monst *mtmp;
28 {
29     if (mtmp->mextra && EMIN(mtmp)) {
30         free((genericptr_t) EMIN(mtmp));
31         EMIN(mtmp) = (struct emin *) 0;
32     }
33     mtmp->isminion = 0;
34 }
35
36 /* count the number of monsters on the level */
37 int
38 monster_census(spotted)
39 boolean spotted; /* seen|sensed vs all */
40 {
41     struct monst *mtmp;
42     int count = 0;
43
44     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
45         if (DEADMONSTER(mtmp))
46             continue;
47         if (spotted && !canspotmon(mtmp))
48             continue;
49         ++count;
50     }
51     return count;
52 }
53
54 /* mon summons a monster */
55 int
56 msummon(mon)
57 struct monst *mon;
58 {
59     struct permonst *ptr;
60     int dtype = NON_PM, cnt = 0, result = 0, census;
61     aligntyp atyp;
62     struct monst *mtmp;
63
64     if (mon) {
65         ptr = mon->data;
66
67         if (uwep && uwep->oartifact == ART_DEMONBANE && is_demon(ptr)) {
68             if (canseemon(mon))
69 /*JP
70                 pline("%s looks puzzled for a moment.", Monnam(mon));
71 */
72                 pline("%s\82Í\8f­\82µ\8d¢\98f\82µ\82Ä\82¢\82é\82æ\82¤\82¾\81D", Monnam(mon));
73             return 0;
74         }
75
76         atyp = mon->ispriest ? EPRI(mon)->shralign
77                              : mon->isminion ? EMIN(mon)->min_align
78                                              : (ptr->maligntyp == A_NONE)
79                                                    ? A_NONE
80                                                    : sgn(ptr->maligntyp);
81     } else {
82         ptr = &mons[PM_WIZARD_OF_YENDOR];
83         atyp = (ptr->maligntyp == A_NONE) ? A_NONE : sgn(ptr->maligntyp);
84     }
85
86     if (is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) {
87         dtype = (!rn2(20)) ? dprince(atyp) : (!rn2(4)) ? dlord(atyp)
88                                                        : ndemon(atyp);
89         cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
90     } else if (is_dlord(ptr)) {
91         dtype = (!rn2(50)) ? dprince(atyp) : (!rn2(20)) ? dlord(atyp)
92                                                         : ndemon(atyp);
93         cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
94     } else if (is_ndemon(ptr)) {
95         dtype = (!rn2(20)) ? dlord(atyp) : (!rn2(6)) ? ndemon(atyp)
96                                                      : monsndx(ptr);
97         cnt = 1;
98     } else if (is_lminion(mon)) {
99         dtype = (is_lord(ptr) && !rn2(20))
100                     ? llord()
101                     : (is_lord(ptr) || !rn2(6)) ? lminion() : monsndx(ptr);
102         cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
103     } else if (ptr == &mons[PM_ANGEL]) {
104         /* non-lawful angels can also summon */
105         if (!rn2(6)) {
106             switch (atyp) { /* see summon_minion */
107             case A_NEUTRAL:
108                 dtype = PM_AIR_ELEMENTAL + rn2(4);
109                 break;
110             case A_CHAOTIC:
111             case A_NONE:
112                 dtype = ndemon(atyp);
113                 break;
114             }
115         } else {
116             dtype = PM_ANGEL;
117         }
118         cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
119     }
120
121     if (dtype == NON_PM)
122         return 0;
123
124     /* sanity checks */
125     if (cnt > 1 && (mons[dtype].geno & G_UNIQ))
126         cnt = 1;
127     /*
128      * If this daemon is unique and being re-summoned (the only way we
129      * could get this far with an extinct dtype), try another.
130      */
131     if (mvitals[dtype].mvflags & G_GONE) {
132         dtype = ndemon(atyp);
133         if (dtype == NON_PM)
134             return 0;
135     }
136
137     /* some candidates can generate a group of monsters, so simple
138        count of non-null makemon() result is not sufficient */
139     census = monster_census(FALSE);
140
141     while (cnt > 0) {
142         mtmp = makemon(&mons[dtype], u.ux, u.uy, MM_EMIN);
143         if (mtmp) {
144             result++;
145             /* an angel's alignment should match the summoner */
146             if (dtype == PM_ANGEL) {
147                 mtmp->isminion = 1;
148                 EMIN(mtmp)->min_align = atyp;
149                 /* renegade if same alignment but not peaceful
150                    or peaceful but different alignment */
151                 EMIN(mtmp)->renegade =
152                     (atyp != u.ualign.type) ^ !mtmp->mpeaceful;
153             }
154         }
155         cnt--;
156     }
157
158     /* how many monsters exist now compared to before? */
159     if (result)
160         result = monster_census(FALSE) - census;
161
162     return result;
163 }
164
165 void
166 summon_minion(alignment, talk)
167 aligntyp alignment;
168 boolean talk;
169 {
170     register struct monst *mon;
171     int mnum;
172
173     switch ((int) alignment) {
174     case A_LAWFUL:
175         mnum = lminion();
176         break;
177     case A_NEUTRAL:
178         mnum = PM_AIR_ELEMENTAL + rn2(4);
179         break;
180     case A_CHAOTIC:
181     case A_NONE:
182         mnum = ndemon(alignment);
183         break;
184     default:
185         impossible("unaligned player?");
186         mnum = ndemon(A_NONE);
187         break;
188     }
189     if (mnum == NON_PM) {
190         mon = 0;
191     } else if (mnum == PM_ANGEL) {
192         mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN);
193         if (mon) {
194             mon->isminion = 1;
195             EMIN(mon)->min_align = alignment;
196             EMIN(mon)->renegade = FALSE;
197         }
198     } else if (mnum != PM_SHOPKEEPER && mnum != PM_GUARD
199                && mnum != PM_ALIGNED_PRIEST && mnum != PM_HIGH_PRIEST) {
200         /* This was mons[mnum].pxlth == 0 but is this restriction
201            appropriate or necessary now that the structures are separate? */
202         mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN);
203         if (mon) {
204             mon->isminion = 1;
205             EMIN(mon)->min_align = alignment;
206             EMIN(mon)->renegade = FALSE;
207         }
208     } else {
209         mon = makemon(&mons[mnum], u.ux, u.uy, NO_MM_FLAGS);
210     }
211     if (mon) {
212         if (talk) {
213 /*JP
214             pline_The("voice of %s booms:", align_gname(alignment));
215 */
216             pline("%s\82Ì\90º\82ª\8b¿\82¢\82½:", align_gname(alignment));
217 /*JP
218             verbalize("Thou shalt pay for thine indiscretion!");
219 */
220             verbalize("\93ð\81C\96³\95ª\95Ê\82È\82é\8ds\82¢\82Ì\94±\82ð\8eó\82¯\82é\82×\82µ\81I");
221             if (!Blind)
222 /*JP
223                 pline("%s appears before you.", Amonnam(mon));
224 */
225                 pline("%s\82ª\82 \82È\82½\82Ì\91O\82É\8c»\82í\82ê\82½\81D", Amonnam(mon));
226             mon->mstrategy &= ~STRAT_APPEARMSG;
227         }
228         mon->mpeaceful = FALSE;
229         /* don't call set_malign(); player was naughty */
230     }
231 }
232
233 #define Athome (Inhell && (mtmp->cham == NON_PM))
234
235 /* returns 1 if it won't attack. */
236 int
237 demon_talk(mtmp)
238 register struct monst *mtmp;
239 {
240     long cash, demand, offer;
241
242     if (uwep && uwep->oartifact == ART_EXCALIBUR) {
243 /*JP
244         pline("%s looks very angry.", Amonnam(mtmp));
245 */
246         pline("%s\82Í\82Æ\82Ä\82à\93{\82Á\82Ä\82¢\82é\82æ\82¤\82É\8c©\82¦\82é\81D", Amonnam(mtmp));
247         mtmp->mpeaceful = mtmp->mtame = 0;
248         set_malign(mtmp);
249         newsym(mtmp->mx, mtmp->my);
250         return 0;
251     }
252
253     if (is_fainted()) {
254         reset_faint(); /* if fainted - wake up */
255     } else {
256         stop_occupation();
257         if (multi > 0) {
258             nomul(0);
259             unmul((char *) 0);
260         }
261     }
262
263     /* Slight advantage given. */
264     if (is_dprince(mtmp->data) && mtmp->minvis) {
265         boolean wasunseen = !canspotmon(mtmp);
266
267         mtmp->minvis = mtmp->perminvis = 0;
268         if (wasunseen && canspotmon(mtmp)) {
269 /*JP
270             pline("%s appears before you.", Amonnam(mtmp));
271 */
272             pline("%s\82ª\96Ú\82Ì\91O\82É\8c»\82í\82ê\82½\81D", Amonnam(mtmp));
273             mtmp->mstrategy &= ~STRAT_APPEARMSG;
274         }
275         newsym(mtmp->mx, mtmp->my);
276     }
277     if (youmonst.data->mlet == S_DEMON) { /* Won't blackmail their own. */
278 #if 0 /*JP*/
279         pline("%s says, \"Good hunting, %s.\"", Amonnam(mtmp),
280               flags.female ? "Sister" : "Brother");
281 #else
282         pline("%s\82Í\8c¾\82Á\82½\81u\82æ\82¤\8cZ%s\81I\81v\81D\82»\82µ\82Ä\8fÁ\82¦\82½\81D", Amonnam(mtmp),
283               flags.female ? "\96\85" : "\92í");
284 #endif
285         if (!tele_restrict(mtmp))
286             (void) rloc(mtmp, TRUE);
287         return (1);
288     }
289     cash = money_cnt(invent);
290     demand =
291         (cash * (rnd(80) + 20 * Athome))
292         / (100 * (1 + (sgn(u.ualign.type) == sgn(mtmp->data->maligntyp))));
293
294     if (!demand || multi < 0) { /* you have no gold or can't move */
295         mtmp->mpeaceful = 0;
296         set_malign(mtmp);
297         return 0;
298     } else {
299         /* make sure that the demand is unmeetable if the monster
300            has the Amulet, preventing monster from being satisfied
301            and removed from the game (along with said Amulet...) */
302         if (mon_has_amulet(mtmp))
303             demand = cash + (long) rn1(1000, 40);
304
305 #if 0 /*JP*/
306         pline("%s demands %ld %s for safe passage.", Amonnam(mtmp), demand,
307               currency(demand));
308 #else
309         pline("%s\82Í\92Ê\8ds\97¿\82Æ\82µ\82Ä%ld%s\97v\8b\81\82µ\82½\81D", Amonnam(mtmp), demand,
310               currency(demand));
311 #endif
312
313         if ((offer = bribe(mtmp)) >= demand) {
314 /*JP
315             pline("%s vanishes, laughing about cowardly mortals.",
316 */
317             pline("\89°\95a\82È\92è\96½\82Ì\82à\82Ì\82ð\8fÎ\82¢\82È\82ª\82ç\81C%s\82Í\8fÁ\82¦\82½\81D",
318                   Amonnam(mtmp));
319         } else if (offer > 0L
320                    && (long) rnd(5 * ACURR(A_CHA)) > (demand - offer)) {
321 /*JP
322             pline("%s scowls at you menacingly, then vanishes.",
323 */
324             pline("%s\82Í\82 \82È\82½\82ð\88Ð\8ad\82µ\81C\8fÁ\82¦\82½\81D",
325                   Amonnam(mtmp));
326         } else {
327 /*JP
328             pline("%s gets angry...", Amonnam(mtmp));
329 */
330             pline("%s\82Í\93{\82Á\82½\81D\81D\81D", Amonnam(mtmp));
331             mtmp->mpeaceful = 0;
332             set_malign(mtmp);
333             return 0;
334         }
335     }
336     mongone(mtmp);
337     return (1);
338 }
339
340 long
341 bribe(mtmp)
342 struct monst *mtmp;
343 {
344     char buf[BUFSZ] = DUMMY;
345     long offer;
346     long umoney = money_cnt(invent);
347
348 /*JP
349     getlin("How much will you offer?", buf);
350 */
351     getlin("\82¨\8bà\82ð\82¢\82­\82ç\97^\82¦\82é\81H", buf);
352     if (sscanf(buf, "%ld", &offer) != 1)
353         offer = 0L;
354
355     /*Michael Paddon -- fix for negative offer to monster*/
356     /*JAR880815 - */
357     if (offer < 0L) {
358 /*JP
359         You("try to shortchange %s, but fumble.", mon_nam(mtmp));
360 */
361         You("%s\82ð\82¾\82Ü\82»\82¤\82Æ\82µ\82½\82ª\81C\8e¸\94s\82µ\82½\81D", mon_nam(mtmp));
362         return 0L;
363     } else if (offer == 0L) {
364 /*JP
365         You("refuse.");
366 */
367         You("\8b\91\82ñ\82¾\81D");
368         return 0L;
369     } else if (offer >= umoney) {
370 /*JP
371         You("give %s all your gold.", mon_nam(mtmp));
372 */
373         You("%s\82É\82¨\8bà\82ð\91S\82Ä\97^\82¦\82½\81D", mon_nam(mtmp));
374         offer = umoney;
375     } else {
376 /*JP
377         You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer));
378 */
379         You("%s\82É%ld%s\97^\82¦\82½\81D", mon_nam(mtmp), offer, currency(offer));
380     }
381     (void) money2mon(mtmp, offer);
382     context.botl = 1;
383     return (offer);
384 }
385
386 int
387 dprince(atyp)
388 aligntyp atyp;
389 {
390     int tryct, pm;
391
392     for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) {
393         pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS);
394         if (!(mvitals[pm].mvflags & G_GONE)
395             && (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
396             return (pm);
397     }
398     return (dlord(atyp)); /* approximate */
399 }
400
401 int
402 dlord(atyp)
403 aligntyp atyp;
404 {
405     int tryct, pm;
406
407     for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) {
408         pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX);
409         if (!(mvitals[pm].mvflags & G_GONE)
410             && (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
411             return (pm);
412     }
413     return (ndemon(atyp)); /* approximate */
414 }
415
416 /* create lawful (good) lord */
417 int
418 llord()
419 {
420     if (!(mvitals[PM_ARCHON].mvflags & G_GONE))
421         return (PM_ARCHON);
422
423     return (lminion()); /* approximate */
424 }
425
426 int
427 lminion()
428 {
429     int tryct;
430     struct permonst *ptr;
431
432     for (tryct = 0; tryct < 20; tryct++) {
433         ptr = mkclass(S_ANGEL, 0);
434         if (ptr && !is_lord(ptr))
435             return (monsndx(ptr));
436     }
437
438     return NON_PM;
439 }
440
441 int
442 ndemon(atyp)
443 aligntyp atyp;
444 {
445     int tryct;
446     struct permonst *ptr;
447
448     for (tryct = 0; tryct < 20; tryct++) {
449         ptr = mkclass(S_DEMON, 0);
450         if (ptr && is_ndemon(ptr)
451             && (atyp == A_NONE || sgn(ptr->maligntyp) == sgn(atyp)))
452             return (monsndx(ptr));
453     }
454
455     return NON_PM;
456 }
457
458 /* guardian angel has been affected by conflict so is abandoning hero */
459 void
460 lose_guardian_angel(mon)
461 struct monst *mon; /* if null, angel hasn't been created yet */
462 {
463     coord mm;
464     int i;
465
466     if (mon) {
467         if (canspotmon(mon)) {
468             if (!Deaf) {
469 /*JP
470                 pline("%s rebukes you, saying:", Monnam(mon));
471 */
472                 pline("%s\82Í\82 \82È\82½\82ð\94ñ\93ï\82µ\82½\81F", Monnam(mon));
473 /*JP
474                 verbalize("Since you desire conflict, have some more!");
475 */
476                 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");
477             } else {
478 /*JP
479                 pline("%s vanishes!", Monnam(mon));
480 */
481                 pline("%s\82Í\8fÁ\82¦\82½\81I", Monnam(mon));
482             }
483         }
484         mongone(mon);
485     }
486     /* create 2 to 4 hostile angels to replace the lost guardian */
487     for (i = rn1(3, 2); i > 0; --i) {
488         mm.x = u.ux;
489         mm.y = u.uy;
490         if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL]))
491             (void) mk_roamer(&mons[PM_ANGEL], u.ualign.type, mm.x, mm.y,
492                              FALSE);
493     }
494 }
495
496 /* just entered the Astral Plane; receive tame guardian angel if worthy */
497 void
498 gain_guardian_angel()
499 {
500     struct monst *mtmp;
501     struct obj *otmp;
502     coord mm;
503
504     Hear_again(); /* attempt to cure any deafness now (divine
505                      message will be heard even if that fails) */
506     if (Conflict) {
507 /*JP
508         pline("A voice booms:");
509 */
510         pline("\90º\82ª\8b¿\82¢\82½:");
511 /*JP
512         verbalize("Thy desire for conflict shall be fulfilled!");
513 */
514         verbalize("\81u\93ð\82Ì\93¬\91\88\82Ö\82Ì\96]\82Ý\81C\82©\82È\82¦\82ç\82ê\82é\82×\82µ\81I\81v");
515         /* send in some hostile angels instead */
516         lose_guardian_angel((struct monst *) 0);
517     } else if (u.ualign.record > 8) { /* fervent */
518 /*JP
519         pline("A voice whispers:");
520 */
521         pline("\82³\82³\82â\82«\90º\82ª\95·\82±\82¦\82½:");
522 /*JP
523         verbalize("Thou hast been worthy of me!");
524 */
525         verbalize("\81u\93ð\81C\89ä\82ª\95]\89¿\82ð\93¾\82½\82è\81I\81v");
526         mm.x = u.ux;
527         mm.y = u.uy;
528         if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL])
529             && (mtmp = mk_roamer(&mons[PM_ANGEL], u.ualign.type, mm.x, mm.y,
530                                  TRUE)) != 0) {
531             mtmp->mstrategy &= ~STRAT_APPEARMSG;
532             if (!Blind)
533 /*JP
534                 pline("An angel appears near you.");
535 */
536                 pline("\93V\8eg\82ª\82 \82È\82½\82Ì\82»\82Î\82É\8c»\82í\82ê\82½\81D");
537             else
538 /*JP
539                 You_feel("the presence of a friendly angel near you.");
540 */
541                 You("\8bß\82­\82É\97F\8dD\93I\82È\93V\8eg\82Ì\91\8dÝ\82ð\8a´\82\82½\81D");
542             /* guardian angel -- the one case mtame doesn't
543              * imply an edog structure, so we don't want to
544              * call tamedog().
545              */
546             mtmp->mtame = 10;
547             /* make him strong enough vs. endgame foes */
548             mtmp->m_lev = rn1(8, 15);
549             mtmp->mhp = mtmp->mhpmax =
550                 d((int) mtmp->m_lev, 10) + 30 + rnd(30);
551             if ((otmp = select_hwep(mtmp)) == 0) {
552                 otmp = mksobj(SILVER_SABER, FALSE, FALSE);
553                 if (mpickobj(mtmp, otmp))
554                     panic("merged weapon?");
555             }
556             bless(otmp);
557             if (otmp->spe < 4)
558                 otmp->spe += rnd(4);
559             if ((otmp = which_armor(mtmp, W_ARMS)) == 0
560                 || otmp->otyp != SHIELD_OF_REFLECTION) {
561                 (void) mongets(mtmp, AMULET_OF_REFLECTION);
562                 m_dowear(mtmp, TRUE);
563             }
564         }
565     }
566 }
567
568 /*minion.c*/