Source:NetHack 3.6.0/src/minion.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to minion.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/minion.c#line123]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

Top of file

Top of file

  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. */
  4.  
  5.  #include "hack.h"
  6.  

newemin

  1.  void
  2.  newemin(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (!mtmp->mextra)
  6.          mtmp->mextra = newmextra();
  7.      if (!EMIN(mtmp)) {
  8.          EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin));
  9.          (void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin));
  10.      }
  11.  }
  12.  

free_emin

  1.  void
  2.  free_emin(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (mtmp->mextra && EMIN(mtmp)) {
  6.          free((genericptr_t) EMIN(mtmp));
  7.          EMIN(mtmp) = (struct emin *) 0;
  8.     }
  9.     mtmp->isminion = 0;
  10.  }
  11.  

monster_census

  1.  /* count the number of monsters on the level */
  2.  int
  3.  monster_census(spotted)
  4.  boolean spotted; /* seen|sensed vs all */
  5.  {
  6.     struct monst *mtmp;
  7.     int count = 0;
  8.  
  9.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  10.         if (DEADMONSTER(mtmp))
  11.             continue;
  12.         if (spotted && !canspotmon(mtmp))
  13.             continue;
  14.         ++count;
  15.     }
  16.     return count;
  17.  }
  18.  

msummon

  1.  /* mon summons a monster */
  2.  int
  3.  msummon(mon)
  4.  struct monst *mon;
  5.  {
  6.     struct permonst *ptr;
  7.     int dtype = NON_PM, cnt = 0, result = 0, census;
  8.     aligntyp atyp;
  9.     struct monst *mtmp;
  10.  
  11.     if (mon) {
  12.         ptr = mon->data;
  13.         atyp = mon->ispriest ? EPRI(mon)->shralign
  14.                              : mon->isminion ? EMIN(mon)->min_align
  15.                                              : (ptr->maligntyp == A_NONE)
  16.                                                    ? A_NONE
  17.                                                    : sgn(ptr->maligntyp);
  18.     } else {
  19.         ptr = &mons[PM_WIZARD_OF_YENDOR];
  20.         atyp = (ptr->maligntyp == A_NONE) ? A_NONE : sgn(ptr->maligntyp);
  21.     }
  22.  
  23.     if (is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) {
  24.         dtype = (!rn2(20)) ? dprince(atyp) : (!rn2(4)) ? dlord(atyp)
  25.                                                        : ndemon(atyp);
  26.         cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
  27.     } else if (is_dlord(ptr)) {
  28.         dtype = (!rn2(50)) ? dprince(atyp) : (!rn2(20)) ? dlord(atyp)
  29.                                                         : ndemon(atyp);
  30.         cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
  31.     } else if (is_ndemon(ptr)) {
  32.         dtype = (!rn2(20)) ? dlord(atyp) : (!rn2(6)) ? ndemon(atyp)
  33.                                                      : monsndx(ptr);
  34.         cnt = 1;
  35.     } else if (is_lminion(mon)) {
  36.         dtype = (is_lord(ptr) && !rn2(20))
  37.                     ? llord()
  38.                     : (is_lord(ptr) || !rn2(6)) ? lminion() : monsndx(ptr);
  39.         cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
  40.     } else if (ptr == &mons[PM_ANGEL]) {
  41.         /* non-lawful angels can also summon */
  42.         if (!rn2(6)) {
  43.             switch (atyp) { /* see summon_minion */
  44.             case A_NEUTRAL:
  45.                 dtype = PM_AIR_ELEMENTAL + rn2(4);
  46.                 break;
  47.             case A_CHAOTIC:
  48.             case A_NONE:
  49.                 dtype = ndemon(atyp);
  50.                 break;
  51.             }
  52.         } else {
  53.             dtype = PM_ANGEL;
  54.         }
  55.         cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
  56.     }
  57.  
  58.     if (dtype == NON_PM)
  59.         return 0;
  60.  
  61.     /* sanity checks */
  62.     if (cnt > 1 && (mons[dtype].geno & G_UNIQ))
  63.         cnt = 1;
  64.     /*
  65.      * If this daemon is unique and being re-summoned (the only way we
  66.      * could get this far with an extinct dtype), try another.
  67.      */
  68.     if (mvitals[dtype].mvflags & G_GONE) {
  69.         dtype = ndemon(atyp);
  70.         if (dtype == NON_PM)
  71.             return 0;
  72.     }
  73.  
  74.     /* some candidates can generate a group of monsters, so simple
  75.        count of non-null makemon() result is not sufficient */
  76.     census = monster_census(FALSE);
  77.  
  78.     while (cnt > 0) {
  79.         mtmp = makemon(&mons[dtype], u.ux, u.uy, MM_EMIN);
  80.         if (mtmp) {
  81.             result++;
  82.             /* an angel's alignment should match the summoner */
  83.             if (dtype == PM_ANGEL) {
  84.                 mtmp->isminion = 1;
  85.                 EMIN(mtmp)->min_align = atyp;
  86.                 /* renegade if same alignment but not peaceful
  87.                    or peaceful but different alignment */
  88.                 EMIN(mtmp)->renegade =
  89.                     (atyp != u.ualign.type) ^ !mtmp->mpeaceful;
  90.             }
  91.         }
  92.         cnt--;
  93.     }
  94.  
  95.     /* how many monsters exist now compared to before? */
  96.     if (result)
  97.         result = monster_census(FALSE) - census;
  98.  
  99.     return result;
  100.  }
  101.  

summon_minion

  1.  void
  2.  summon_minion(alignment, talk)
  3.  aligntyp alignment;
  4.  boolean talk;
  5.  {
  6.     register struct monst *mon;
  7.     int mnum;
  8.  
  9.     switch ((int) alignment) {
  10.     case A_LAWFUL:
  11.         mnum = lminion();
  12.         break;
  13.     case A_NEUTRAL:
  14.         mnum = PM_AIR_ELEMENTAL + rn2(4);
  15.         break;
  16.     case A_CHAOTIC:
  17.     case A_NONE:
  18.         mnum = ndemon(alignment);
  19.         break;
  20.     default:
  21.         impossible("unaligned player?");
  22.         mnum = ndemon(A_NONE);
  23.         break;
  24.     }
  25.     if (mnum == NON_PM) {
  26.         mon = 0;
  27.     } else if (mnum == PM_ANGEL) {
  28.         mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN);
  29.         if (mon) {
  30.             mon->isminion = 1;
  31.             EMIN(mon)->min_align = alignment;
  32.             EMIN(mon)->renegade = FALSE;
  33.         }
  34.     } else if (mnum != PM_SHOPKEEPER && mnum != PM_GUARD
  35.                && mnum != PM_ALIGNED_PRIEST && mnum != PM_HIGH_PRIEST) {
  36.         /* This was mons[mnum].pxlth == 0 but is this restriction
  37.            appropriate or necessary now that the structures are separate? */
  38.         mon = makemon(&mons[mnum], u.ux, u.uy, MM_EMIN);
  39.         if (mon) {
  40.             mon->isminion = 1;
  41.             EMIN(mon)->min_align = alignment;
  42.             EMIN(mon)->renegade = FALSE;
  43.         }
  44.     } else {
  45.         mon = makemon(&mons[mnum], u.ux, u.uy, NO_MM_FLAGS);
  46.     }
  47.     if (mon) {
  48.         if (talk) {
  49.             pline_The("voice of %s booms:", align_gname(alignment));
  50.             verbalize("Thou shalt pay for thine indiscretion!");
  51.             if (!Blind)
  52.                 pline("%s appears before you.", Amonnam(mon));
  53.             mon->mstrategy &= ~STRAT_APPEARMSG;
  54.         }
  55.         mon->mpeaceful = FALSE;
  56.         /* don't call set_malign(); player was naughty */
  57.     }
  58.  }
  59.  

demon_talk

  1.  #define Athome (Inhell && (mtmp->cham == NON_PM))
  2.  
  3.  /* returns 1 if it won't attack. */
  4.  int
  5.  demon_talk(mtmp)
  6.  register struct monst *mtmp;
  7.  {
  8.     long cash, demand, offer;
  9.  
  10.     if (uwep && uwep->oartifact == ART_EXCALIBUR) {
  11.         pline("%s looks very angry.", Amonnam(mtmp));
  12.         mtmp->mpeaceful = mtmp->mtame = 0;
  13.         set_malign(mtmp);
  14.         newsym(mtmp->mx, mtmp->my);
  15.         return 0;
  16.     }
  17.  
  18.     if (is_fainted()) {
  19.         reset_faint(); /* if fainted - wake up */
  20.     } else {
  21.         stop_occupation();
  22.         if (multi > 0) {
  23.             nomul(0);
  24.             unmul((char *) 0);
  25.         }
  26.     }
  27.  
  28.     /* Slight advantage given. */
  29.     if (is_dprince(mtmp->data) && mtmp->minvis) {
  30.         boolean wasunseen = !canspotmon(mtmp);
  31.  
  32.         mtmp->minvis = mtmp->perminvis = 0;
  33.         if (wasunseen && canspotmon(mtmp)) {
  34.             pline("%s appears before you.", Amonnam(mtmp));
  35.             mtmp->mstrategy &= ~STRAT_APPEARMSG;
  36.         }
  37.         newsym(mtmp->mx, mtmp->my);
  38.     }
  39.     if (youmonst.data->mlet == S_DEMON) { /* Won't blackmail their own. */
  40.         pline("%s says, \"Good hunting, %s.\"", Amonnam(mtmp),
  41.               flags.female ? "Sister" : "Brother");
  42.         if (!tele_restrict(mtmp))
  43.             (void) rloc(mtmp, TRUE);
  44.         return (1);
  45.     }
  46.     cash = money_cnt(invent);
  47.     demand =
  48.         (cash * (rnd(80) + 20 * Athome))
  49.         / (100 * (1 + (sgn(u.ualign.type) == sgn(mtmp->data->maligntyp))));
  50.  
  51.     if (!demand || multi < 0) { /* you have no gold or can't move */
  52.         mtmp->mpeaceful = 0;
  53.         set_malign(mtmp);
  54.         return 0;
  55.     } else {
  56.         /* make sure that the demand is unmeetable if the monster
  57.            has the Amulet, preventing monster from being satisfied
  58.            and removed from the game (along with said Amulet...) */
  59.         if (mon_has_amulet(mtmp))
  60.             demand = cash + (long) rn1(1000, 40);
  61.  
  62.         pline("%s demands %ld %s for safe passage.", Amonnam(mtmp), demand,
  63.               currency(demand));
  64.  
  65.         if ((offer = bribe(mtmp)) >= demand) {
  66.             pline("%s vanishes, laughing about cowardly mortals.",
  67.                   Amonnam(mtmp));
  68.         } else if (offer > 0L && (long) rnd(40) > (demand - offer)) {
  69.             pline("%s scowls at you menacingly, then vanishes.",
  70.                   Amonnam(mtmp));
  71.         } else {
  72.             pline("%s gets angry...", Amonnam(mtmp));
  73.             mtmp->mpeaceful = 0;
  74.             set_malign(mtmp);
  75.             return 0;
  76.         }
  77.     }
  78.     mongone(mtmp);
  79.     return (1);
  80.  }
  81.  

bribe

  1.  long
  2.  bribe(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.     char buf[BUFSZ];
  6.     long offer;
  7.     long umoney = money_cnt(invent);
  8.  
  9.     getlin("How much will you offer?", buf);
  10.     if (sscanf(buf, "%ld", &offer) != 1)
  11.         offer = 0L;
  12.  
  13.     /*Michael Paddon -- fix for negative offer to monster*/
  14.     /*JAR880815 - */
  15.     if (offer < 0L) {
  16.         You("try to shortchange %s, but fumble.", mon_nam(mtmp));
  17.         return 0L;
  18.     } else if (offer == 0L) {
  19.         You("refuse.");
  20.         return 0L;
  21.     } else if (offer >= umoney) {
  22.         You("give %s all your gold.", mon_nam(mtmp));
  23.         offer = umoney;
  24.     } else {
  25.         You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer));
  26.     }
  27.     (void) money2mon(mtmp, offer);
  28.     context.botl = 1;
  29.     return (offer);
  30.  }
  31.  

dprince

  1.  int
  2.  dprince(atyp)
  3.  aligntyp atyp;
  4.  {
  5.     int tryct, pm;
  6.  
  7.     for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) {
  8.         pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS);
  9.         if (!(mvitals[pm].mvflags & G_GONE)
  10.             && (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
  11.             return (pm);
  12.     }
  13.     return (dlord(atyp)); /* approximate */
  14.  }
  15.  

dlord

  1.  int
  2.  dlord(atyp)
  3.  aligntyp atyp;
  4.  {
  5.     int tryct, pm;
  6.  
  7.     for (tryct = !In_endgame(&u.uz) ? 20 : 0; tryct > 0; --tryct) {
  8.         pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX);
  9.         if (!(mvitals[pm].mvflags & G_GONE)
  10.             && (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
  11.             return (pm);
  12.     }
  13.     return (ndemon(atyp)); /* approximate */
  14.  }
  15.  

llord

  1.  /* create lawful (good) lord */
  2.  int
  3.  llord()
  4.  {
  5.     if (!(mvitals[PM_ARCHON].mvflags & G_GONE))
  6.         return (PM_ARCHON);
  7.  
  8.     return (lminion()); /* approximate */
  9.  }
  10.  

lminion

  1.  int
  2.  lminion()
  3.  {
  4.     int tryct;
  5.     struct permonst *ptr;
  6.  
  7.     for (tryct = 0; tryct < 20; tryct++) {
  8.         ptr = mkclass(S_ANGEL, 0);
  9.         if (ptr && !is_lord(ptr))
  10.             return (monsndx(ptr));
  11.     }
  12.  
  13.     return NON_PM;
  14.  }
  15.  

ndemon

  1.  int
  2.  ndemon(atyp)
  3.  aligntyp atyp;
  4.  {
  5.     int tryct;
  6.     struct permonst *ptr;
  7.  
  8.     for (tryct = 0; tryct < 20; tryct++) {
  9.         ptr = mkclass(S_DEMON, 0);
  10.         if (ptr && is_ndemon(ptr)
  11.             && (atyp == A_NONE || sgn(ptr->maligntyp) == sgn(atyp)))
  12.             return (monsndx(ptr));
  13.     }
  14.  
  15.     return NON_PM;
  16.  }
  17.  

lose_guardian_angel

  1.  /* guardian angel has been affected by conflict so is abandoning hero */
  2.  void
  3.  lose_guardian_angel(mon)
  4.  struct monst *mon; /* if null, angel hasn't been created yet */
  5.  {
  6.     coord mm;
  7.     int i;
  8.  
  9.     if (mon) {
  10.         if (canspotmon(mon)) {
  11.             if (!Deaf) {
  12.                 pline("%s rebukes you, saying:", Monnam(mon));
  13.                 verbalize("Since you desire conflict, have some more!");
  14.             } else {
  15.                 pline("%s vanishes!", Monnam(mon));
  16.             }
  17.         }
  18.         mongone(mon);
  19.     }
  20.     /* create 2 to 4 hostile angels to replace the lost guardian */
  21.     for (i = rn1(3, 2); i > 0; --i) {
  22.         mm.x = u.ux;
  23.         mm.y = u.uy;
  24.         if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL]))
  25.             (void) mk_roamer(&mons[PM_ANGEL], u.ualign.type, mm.x, mm.y,
  26.                              FALSE);
  27.     }
  28.  }
  29.  

gain_guardian_angel

  1.  /* just entered the Astral Plane; receive tame guardian angel if worthy */
  2.  void
  3.  gain_guardian_angel()
  4.  {
  5.     struct monst *mtmp;
  6.     struct obj *otmp;
  7.     coord mm;
  8.  
  9.     Hear_again(); /* attempt to cure any deafness now (divine
  10.                      message will be heard even if that fails) */
  11.     if (Conflict) {
  12.         pline("A voice booms:");
  13.         verbalize("Thy desire for conflict shall be fulfilled!");
  14.         /* send in some hostile angels instead */
  15.         lose_guardian_angel((struct monst *) 0);
  16.     } else if (u.ualign.record > 8) { /* fervent */
  17.         pline("A voice whispers:");
  18.         verbalize("Thou hast been worthy of me!");
  19.         mm.x = u.ux;
  20.         mm.y = u.uy;
  21.         if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL])
  22.             && (mtmp = mk_roamer(&mons[PM_ANGEL], u.ualign.type, mm.x, mm.y,
  23.                                  TRUE)) != 0) {
  24.             mtmp->mstrategy &= ~STRAT_APPEARMSG;
  25.             if (!Blind)
  26.                 pline("An angel appears near you.");
  27.             else
  28.                 You_feel("the presence of a friendly angel near you.");
  29.             /* guardian angel -- the one case mtame doesn't
  30.              * imply an edog structure, so we don't want to
  31.              * call tamedog().
  32.              */
  33.             mtmp->mtame = 10;
  34.             /* make him strong enough vs. endgame foes */
  35.             mtmp->m_lev = rn1(8, 15);
  36.             mtmp->mhp = mtmp->mhpmax =
  37.                 d((int) mtmp->m_lev, 10) + 30 + rnd(30);
  38.             if ((otmp = select_hwep(mtmp)) == 0) {
  39.                 otmp = mksobj(SILVER_SABER, FALSE, FALSE);
  40.                 if (mpickobj(mtmp, otmp))
  41.                     panic("merged weapon?");
  42.             }
  43.             bless(otmp);
  44.             if (otmp->spe < 4)
  45.                 otmp->spe += rnd(4);
  46.             if ((otmp = which_armor(mtmp, W_ARMS)) == 0
  47.                 || otmp->otyp != SHIELD_OF_REFLECTION) {
  48.                 (void) mongets(mtmp, AMULET_OF_REFLECTION);
  49.                 m_dowear(mtmp, TRUE);
  50.             }
  51.         }
  52.     }
  53.  }
  54.  
  55.  /*minion.c*/