Source:NetHack 3.6.0/src/mplayer.c

From NetHackWiki
(Redirected from Mplayer.c)
Jump to: navigation, search

Below is the full text to mplayer.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/mplayer.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

  1.  /* NetHack 3.6	mplayer.c	$NHDT-Date: 1432512774 2015/05/25 00:12:54 $  $NHDT-Branch: master $:$NHDT-Revision: 1.19 $ */
  2.  /*	Copyright (c) Izchak Miller, 1992.			  */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  STATIC_DCL const char *NDECL(dev_name);
  8.  STATIC_DCL void FDECL(get_mplname, (struct monst *, char *));
  9.  STATIC_DCL void FDECL(mk_mplayer_armor, (struct monst *, SHORT_P));
  10.  

Developer names

  1.  /* These are the names of those who
  2.   * contributed to the development of NetHack 3.2/3.3/3.4/3.6.
  3.   *
  4.   * Keep in alphabetical order within teams.
  5.   * Same first name is entered once within each team.
  6.   */
  7.  static const char *developers[] = {
  8.      /* devteam */
  9.      "Dave",    "Dean",   "Eric",    "Izchak", "Janet",    "Jessie",
  10.      "Ken",     "Kevin",  "Michael", "Mike",   "Pat",      "Paul",
  11.      "Steve",   "Timo",   "Warwick",
  12.      /* PC team */
  13.      "Bill",    "Eric",   "Keizo",   "Ken",    "Kevin",    "Michael",
  14.      "Mike",    "Paul",   "Stephen", "Steve",  "Timo",     "Yitzhak",
  15.      /* Amiga team */
  16.      "Andy",    "Gregg",  "Janne",   "Keni",   "Mike",     "Olaf",
  17.      "Richard",
  18.      /* Mac team */
  19.      "Andy",    "Chris",  "Dean",    "Jon",    "Jonathan", "Kevin",
  20.      "Wang",
  21.      /* Atari team */
  22.      "Eric",    "Marvin", "Warwick",
  23.      /* NT team */
  24.      "Alex",    "Dion",   "Michael",
  25.      /* OS/2 team */
  26.      "Helge",   "Ron",    "Timo",
  27.      /* VMS team */
  28.      "Joshua",  "Pat",    ""
  29.  };
  30.  

dev_name

  1.  /* return a randomly chosen developer name */
  2.  STATIC_OVL const char *
  3.  dev_name()
  4.  {
  5.      register int i, m = 0, n = SIZE(developers);
  6.      register struct monst *mtmp;
  7.      register boolean match;
  8.  
  9.      do {
  10.          match = FALSE;
  11.          i = rn2(n);
  12.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  13.              if (!is_mplayer(mtmp->data))
  14.                  continue;
  15.              if (!strncmp(developers[i], (has_mname(mtmp)) ? MNAME(mtmp) : "",
  16.                           strlen(developers[i]))) {
  17.                  match = TRUE;
  18.                  break;
  19.              }
  20.          }
  21.          m++;
  22.      } while (match && m < 100); /* m for insurance */
  23.  
  24.      if (match)
  25.          return (const char *) 0;
  26.      return (developers[i]);
  27.  }
  28.  

get_mplname

  1.  STATIC_OVL void
  2.  get_mplname(mtmp, nam)
  3.  register struct monst *mtmp;
  4.  char *nam;
  5.  {
  6.      boolean fmlkind = is_female(mtmp->data);
  7.      const char *devnam;
  8.  
  9.      devnam = dev_name();
  10.      if (!devnam)
  11.          Strcpy(nam, fmlkind ? "Eve" : "Adam");
  12.      else if (fmlkind && !!strcmp(devnam, "Janet"))
  13.          Strcpy(nam, rn2(2) ? "Maud" : "Eve");
  14.      else
  15.          Strcpy(nam, devnam);
  16.  
  17.      if (fmlkind || !strcmp(nam, "Janet"))
  18.          mtmp->female = 1;
  19.      else
  20.          mtmp->female = 0;
  21.      Strcat(nam, " the ");
  22.      Strcat(nam, rank_of((int) mtmp->m_lev, monsndx(mtmp->data),
  23.                          (boolean) mtmp->female));
  24.  }
  25.  

mk_mplayer_armor

  1.  STATIC_OVL void
  2.  mk_mplayer_armor(mon, typ)
  3.  struct monst *mon;
  4.  short typ;
  5.  {
  6.      struct obj *obj;
  7.  
  8.      if (typ == STRANGE_OBJECT)
  9.          return;
  10.      obj = mksobj(typ, FALSE, FALSE);
  11.      if (!rn2(3))
  12.          obj->oerodeproof = 1;
  13.      if (!rn2(3))
  14.          curse(obj);
  15.      if (!rn2(3))
  16.          bless(obj);
  17.      /* Most players who get to the endgame who have cursed equipment
  18.       * have it because the wizard or other monsters cursed it, so its
  19.       * chances of having plusses is the same as usual....
  20.       */
  21.      obj->spe = rn2(10) ? (rn2(3) ? rn2(5) : rn1(4, 4)) : -rnd(3);
  22.      (void) mpickobj(mon, obj);
  23.  }
  24.  

mk_mplayer

  1.  struct monst *
  2.  mk_mplayer(ptr, x, y, special)
  3.  register struct permonst *ptr;
  4.  xchar x, y;
  5.  register boolean special;
  6.  {
  7.      register struct monst *mtmp;
  8.      char nam[PL_NSIZ];
  9.  
  10.      if (!is_mplayer(ptr))
  11.          return ((struct monst *) 0);
  12.  
  13.      if (MON_AT(x, y))
  14.          (void) rloc(m_at(x, y), FALSE); /* insurance */
  15.  
  16.      if (!In_endgame(&u.uz))
  17.          special = FALSE;
  18.  
  19.      if ((mtmp = makemon(ptr, x, y, NO_MM_FLAGS)) != 0) {
  20.          short weapon = rn2(2) ? LONG_SWORD : rnd_class(SPEAR, BULLWHIP);
  21.          short armor =
  22.              rnd_class(GRAY_DRAGON_SCALE_MAIL, YELLOW_DRAGON_SCALE_MAIL);
  23.          short cloak = !rn2(8)
  24.                            ? STRANGE_OBJECT
  25.                            : rnd_class(OILSKIN_CLOAK, CLOAK_OF_DISPLACEMENT);
  26.          short helm = !rn2(8) ? STRANGE_OBJECT : rnd_class(ELVEN_LEATHER_HELM,
  27.                                                            HELM_OF_TELEPATHY);
  28.          short shield = !rn2(8)
  29.                             ? STRANGE_OBJECT
  30.                             : rnd_class(ELVEN_SHIELD, SHIELD_OF_REFLECTION);
  31.          int quan;
  32.          struct obj *otmp;
  33.  
  34.          mtmp->m_lev = (special ? rn1(16, 15) : rnd(16));
  35.          mtmp->mhp = mtmp->mhpmax =
  36.              d((int) mtmp->m_lev, 10) + (special ? (30 + rnd(30)) : 30);
  37.          if (special) {
  38.              get_mplname(mtmp, nam);
  39.              mtmp = christen_monst(mtmp, nam);
  40.              /* that's why they are "stuck" in the endgame :-) */
  41.              (void) mongets(mtmp, FAKE_AMULET_OF_YENDOR);
  42.          }
  43.          mtmp->mpeaceful = 0;
  44.          set_malign(mtmp); /* peaceful may have changed again */
  45.  
  46.          switch (monsndx(ptr)) {
  47.          case PM_ARCHEOLOGIST:
  48.              if (rn2(2))
  49.                  weapon = BULLWHIP;
  50.              break;
  51.          case PM_BARBARIAN:
  52.              if (rn2(2)) {
  53.                  weapon = rn2(2) ? TWO_HANDED_SWORD : BATTLE_AXE;
  54.                  shield = STRANGE_OBJECT;
  55.              }
  56.              if (rn2(2))
  57.                  armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
  58.              if (helm == HELM_OF_BRILLIANCE)
  59.                  helm = STRANGE_OBJECT;
  60.              break;
  61.          case PM_CAVEMAN:
  62.          case PM_CAVEWOMAN:
  63.              if (rn2(4))
  64.                  weapon = MACE;
  65.              else if (rn2(2))
  66.                  weapon = CLUB;
  67.              if (helm == HELM_OF_BRILLIANCE)
  68.                  helm = STRANGE_OBJECT;
  69.              break;
  70.          case PM_HEALER:
  71.              if (rn2(4))
  72.                  weapon = QUARTERSTAFF;
  73.              else if (rn2(2))
  74.                  weapon = rn2(2) ? UNICORN_HORN : SCALPEL;
  75.              if (rn2(4))
  76.                  helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY;
  77.              if (rn2(2))
  78.                  shield = STRANGE_OBJECT;
  79.              break;
  80.          case PM_KNIGHT:
  81.              if (rn2(4))
  82.                  weapon = LONG_SWORD;
  83.              if (rn2(2))
  84.                  armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
  85.              break;
  86.          case PM_MONK:
  87.              weapon = !rn2(3) ? SHURIKEN : STRANGE_OBJECT;
  88.              armor = STRANGE_OBJECT;
  89.              cloak = ROBE;
  90.              if (rn2(2))
  91.                  shield = STRANGE_OBJECT;
  92.              break;
  93.          case PM_PRIEST:
  94.          case PM_PRIESTESS:
  95.              if (rn2(2))
  96.                  weapon = MACE;
  97.              if (rn2(2))
  98.                  armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
  99.              if (rn2(4))
  100.                  cloak = ROBE;
  101.              if (rn2(4))
  102.                  helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY;
  103.              if (rn2(2))
  104.                  shield = STRANGE_OBJECT;
  105.              break;
  106.          case PM_RANGER:
  107.              if (rn2(2))
  108.                  weapon = ELVEN_DAGGER;
  109.              break;
  110.          case PM_ROGUE:
  111.              if (rn2(2))
  112.                  weapon = rn2(2) ? SHORT_SWORD : ORCISH_DAGGER;
  113.              break;
  114.          case PM_SAMURAI:
  115.              if (rn2(2))
  116.                  weapon = KATANA;
  117.              break;
  118.          case PM_TOURIST:
  119.              /* Defaults are just fine */
  120.              break;
  121.          case PM_VALKYRIE:
  122.              if (rn2(2))
  123.                  weapon = WAR_HAMMER;
  124.              if (rn2(2))
  125.                  armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
  126.              break;
  127.          case PM_WIZARD:
  128.              if (rn2(4))
  129.                  weapon = rn2(2) ? QUARTERSTAFF : ATHAME;
  130.              if (rn2(2)) {
  131.                  armor = rn2(2) ? BLACK_DRAGON_SCALE_MAIL
  132.                                 : SILVER_DRAGON_SCALE_MAIL;
  133.                  cloak = CLOAK_OF_MAGIC_RESISTANCE;
  134.              }
  135.              if (rn2(4))
  136.                  helm = HELM_OF_BRILLIANCE;
  137.              shield = STRANGE_OBJECT;
  138.              break;
  139.          default:
  140.              impossible("bad mplayer monster");
  141.              weapon = 0;
  142.              break;
  143.          }
  144.  
  145.          if (weapon != STRANGE_OBJECT) {
  146.              otmp = mksobj(weapon, TRUE, FALSE);
  147.              otmp->spe = (special ? rn1(5, 4) : rn2(4));
  148.              if (!rn2(3))
  149.                  otmp->oerodeproof = 1;
  150.              else if (!rn2(2))
  151.                  otmp->greased = 1;
  152.              if (special && rn2(2))
  153.                  otmp = mk_artifact(otmp, A_NONE);
  154.              /* usually increase stack size if stackable weapon */
  155.              if (objects[otmp->otyp].oc_merge && !otmp->oartifact)
  156.                  otmp->quan += (long) rn2(is_spear(otmp) ? 4 : 8);
  157.              /* mplayers knew better than to overenchant Magicbane */
  158.              if (otmp->oartifact == ART_MAGICBANE)
  159.                  otmp->spe = rnd(4);
  160.              (void) mpickobj(mtmp, otmp);
  161.          }
  162.  
  163.          if (special) {
  164.              if (!rn2(10))
  165.                  (void) mongets(mtmp, rn2(3) ? LUCKSTONE : LOADSTONE);
  166.              mk_mplayer_armor(mtmp, armor);
  167.              mk_mplayer_armor(mtmp, cloak);
  168.              mk_mplayer_armor(mtmp, helm);
  169.              mk_mplayer_armor(mtmp, shield);
  170.              if (rn2(8))
  171.                  mk_mplayer_armor(
  172.                      mtmp, rnd_class(LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY));
  173.              if (rn2(8))
  174.                  mk_mplayer_armor(mtmp,
  175.                                   rnd_class(LOW_BOOTS, LEVITATION_BOOTS));
  176.              m_dowear(mtmp, TRUE);
  177.  
  178.              quan = rn2(3) ? rn2(3) : rn2(16);
  179.              while (quan--)
  180.                  (void) mongets(mtmp, rnd_class(DILITHIUM_CRYSTAL, JADE));
  181.              /* To get the gold "right" would mean a player can double his */
  182.              /* gold supply by killing one mplayer.  Not good. */
  183.              mkmonmoney(mtmp, rn2(1000));
  184.              quan = rn2(10);
  185.              while (quan--)
  186.                  (void) mpickobj(mtmp, mkobj(RANDOM_CLASS, FALSE));
  187.          }
  188.          quan = rnd(3);
  189.          while (quan--)
  190.              (void) mongets(mtmp, rnd_offensive_item(mtmp));
  191.          quan = rnd(3);
  192.          while (quan--)
  193.              (void) mongets(mtmp, rnd_defensive_item(mtmp));
  194.          quan = rnd(3);
  195.          while (quan--)
  196.              (void) mongets(mtmp, rnd_misc_item(mtmp));
  197.      }
  198.  
  199.      return (mtmp);
  200.  }
  201.  

create_mplayers

  1.  /* create the indicated number (num) of monster-players,
  2.   * randomly chosen, and in randomly chosen (free) locations
  3.   * on the level.  If "special", the size of num should not
  4.   * be bigger than the number of _non-repeated_ names in the
  5.   * developers array, otherwise a bunch of Adams and Eves will
  6.   * fill up the overflow.
  7.   */
  8.  void
  9.  create_mplayers(num, special)
  10.  register int num;
  11.  boolean special;
  12.  {
  13.      int pm, x, y;
  14.      struct monst fakemon;
  15.  
  16.      while (num) {
  17.          int tryct = 0;
  18.  
  19.          /* roll for character class */
  20.          pm = PM_ARCHEOLOGIST + rn2(PM_WIZARD - PM_ARCHEOLOGIST + 1);
  21.          fakemon.data = &mons[pm];
  22.  
  23.          /* roll for an available location */
  24.          do {
  25.              x = rn1(COLNO - 4, 2);
  26.              y = rnd(ROWNO - 2);
  27.          } while (!goodpos(x, y, &fakemon, 0) && tryct++ <= 50);
  28.  
  29.          /* if pos not found in 50 tries, don't bother to continue */
  30.          if (tryct > 50)
  31.              return;
  32.  
  33.          (void) mk_mplayer(&mons[pm], (xchar) x, (xchar) y, special);
  34.          num--;
  35.      }
  36.  }
  37.  

mplayer_talk

  1.  void
  2.  mplayer_talk(mtmp)
  3.  register struct monst *mtmp;
  4.  {
  5.      static const char *same_class_msg[3] =
  6.          {
  7.            "I can't win, and neither will you!", "You don't deserve to win!",
  8.            "Mine should be the honor, not yours!",
  9.          },
  10.                        *other_class_msg[3] = {
  11.                            "The low-life wants to talk, eh?", "Fight, scum!",
  12.                            "Here is what I have to say!",
  13.                        };
  14.  
  15.      if (mtmp->mpeaceful)
  16.          return; /* will drop to humanoid talk */
  17.  
  18.      pline("Talk? -- %s", (mtmp->data == &mons[urole.malenum]
  19.                            || mtmp->data == &mons[urole.femalenum])
  20.                               ? same_class_msg[rn2(3)]
  21.                               : other_class_msg[rn2(3)]);
  22.  }
  23.  
  24.  /*mplayer.c*/