Source:NetHack 3.6.0/src/quest.c

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

Below is the full text to quest.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/quest.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	quest.c	$NHDT-Date: 1446191878 2015/10/30 07:57:58 $  $NHDT-Branch: master $:$NHDT-Revision: 1.20 $ */
  2.  /*      Copyright 1991, M. Stephenson             */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  /*  quest dungeon branch routines. */
  8.  
  9.  #include "quest.h"
  10.  #include "qtext.h"
  11.  
  12.  #define Not_firsttime (on_level(&u.uz0, &u.uz))
  13.  #define Qstat(x) (quest_status.x)
  14.  
  15.  STATIC_DCL void NDECL(on_start);
  16.  STATIC_DCL void NDECL(on_locate);
  17.  STATIC_DCL void NDECL(on_goal);
  18.  STATIC_DCL boolean NDECL(not_capable);
  19.  STATIC_DCL int FDECL(is_pure, (BOOLEAN_P));
  20.  STATIC_DCL void FDECL(expulsion, (BOOLEAN_P));
  21.  STATIC_DCL void NDECL(chat_with_leader);
  22.  STATIC_DCL void NDECL(chat_with_nemesis);
  23.  STATIC_DCL void NDECL(chat_with_guardian);
  24.  STATIC_DCL void FDECL(prisoner_speaks, (struct monst *));
  25.  

on_start

  1.  STATIC_OVL void
  2.  on_start()
  3.  {
  4.      if (!Qstat(first_start)) {
  5.          qt_pager(QT_FIRSTTIME);
  6.          Qstat(first_start) = TRUE;
  7.      } else if ((u.uz0.dnum != u.uz.dnum) || (u.uz0.dlevel < u.uz.dlevel)) {
  8.          if (Qstat(not_ready) <= 2)
  9.              qt_pager(QT_NEXTTIME);
  10.          else
  11.              qt_pager(QT_OTHERTIME);
  12.      }
  13.  }
  14.  

on_locate

  1.  STATIC_OVL void
  2.  on_locate()
  3.  {
  4.      /* the locate messages are phrased in a manner such that they only
  5.         make sense when arriving on the level from above */
  6.      boolean from_above = (u.uz0.dlevel < u.uz.dlevel);
  7.  
  8.      if (Qstat(killed_nemesis)) {
  9.          return;
  10.      } else if (!Qstat(first_locate)) {
  11.          if (from_above)
  12.              qt_pager(QT_FIRSTLOCATE);
  13.          /* if we've arrived from below this will be a lie, but there won't
  14.             be any point in delivering the message upon a return visit from
  15.             above later since the level has now been seen */
  16.          Qstat(first_locate) = TRUE;
  17.      } else {
  18.          if (from_above)
  19.              qt_pager(QT_NEXTLOCATE);
  20.      }
  21.  }
  22.  

on_goal

  1.  STATIC_OVL void
  2.  on_goal()
  3.  {
  4.      if (Qstat(killed_nemesis)) {
  5.          return;
  6.      } else if (!Qstat(made_goal)) {
  7.          qt_pager(QT_FIRSTGOAL);
  8.          Qstat(made_goal) = 1;
  9.      } else {
  10.          qt_pager(QT_NEXTGOAL);
  11.          if (Qstat(made_goal) < 7)
  12.              Qstat(made_goal)++;
  13.      }
  14.  }
  15.  

onquest

  1.  void
  2.  onquest()
  3.  {
  4.      if (u.uevent.qcompleted || Not_firsttime)
  5.          return;
  6.      if (!Is_special(&u.uz))
  7.          return;
  8.  
  9.      if (Is_qstart(&u.uz))
  10.          on_start();
  11.      else if (Is_qlocate(&u.uz))
  12.          on_locate();
  13.      else if (Is_nemesis(&u.uz))
  14.          on_goal();
  15.      return;
  16.  }
  17.  

nemdead

  1.  void
  2.  nemdead()
  3.  {
  4.      if (!Qstat(killed_nemesis)) {
  5.          Qstat(killed_nemesis) = TRUE;
  6.          qt_pager(QT_KILLEDNEM);
  7.      }
  8.  }
  9.  

artitouch

  1.  void
  2.  artitouch(obj)
  3.  struct obj *obj;
  4.  {
  5.      if (!Qstat(touched_artifact)) {
  6.          /* in case we haven't seen the item yet (ie, currently blinded),
  7.             this quest message describes it by name so mark it as seen */
  8.          obj->dknown = 1;
  9.          /* only give this message once */
  10.          Qstat(touched_artifact) = TRUE;
  11.          qt_pager(QT_GOTIT);
  12.          exercise(A_WIS, TRUE);
  13.      }
  14.  }
  15.  

ok_to_quest

  1.  /* external hook for do.c (level change check) */
  2.  boolean
  3.  ok_to_quest()
  4.  {
  5.      return (boolean) ((Qstat(got_quest) || Qstat(got_thanks))
  6.                        && is_pure(FALSE) > 0);
  7.  }
  8.  

not_capable

  1.  STATIC_OVL boolean
  2.  not_capable()
  3.  {
  4.      return (boolean) (u.ulevel < MIN_QUEST_LEVEL);
  5.  }
  6.  

is_pure

  1.  STATIC_OVL int
  2.  is_pure(talk)
  3.  boolean talk;
  4.  {
  5.      int purity;
  6.      aligntyp original_alignment = u.ualignbase[A_ORIGINAL];
  7.  
  8.      if (wizard && talk) {
  9.          if (u.ualign.type != original_alignment) {
  10.              You("are currently %s instead of %s.", align_str(u.ualign.type),
  11.                  align_str(original_alignment));
  12.          } else if (u.ualignbase[A_CURRENT] != original_alignment) {
  13.              You("have converted.");
  14.          } else if (u.ualign.record < MIN_QUEST_ALIGN) {
  15.              You("are currently %d and require %d.", u.ualign.record,
  16.                  MIN_QUEST_ALIGN);
  17.              if (yn_function("adjust?", (char *) 0, 'y') == 'y')
  18.                  u.ualign.record = MIN_QUEST_ALIGN;
  19.          }
  20.      }
  21.      purity = (u.ualign.record >= MIN_QUEST_ALIGN
  22.                && u.ualign.type == original_alignment
  23.                && u.ualignbase[A_CURRENT] == original_alignment)
  24.                   ? 1
  25.                   : (u.ualignbase[A_CURRENT] != original_alignment) ? -1 : 0;
  26.      return purity;
  27.  }
  28.  

expulsion

  1.  /*
  2.   * Expel the player to the stairs on the parent of the quest dungeon.
  3.   *
  4.   * This assumes that the hero is currently _in_ the quest dungeon and that
  5.   * there is a single branch to and from it.
  6.   */
  7.  STATIC_OVL void
  8.  expulsion(seal)
  9.  boolean seal;
  10.  {
  11.      branch *br;
  12.      d_level *dest;
  13.      struct trap *t;
  14.      int portal_flag;
  15.  
  16.      br = dungeon_branch("The Quest");
  17.      dest = (br->end1.dnum == u.uz.dnum) ? &br->end2 : &br->end1;
  18.      portal_flag = u.uevent.qexpelled ? 0 /* returned via artifact? */
  19.                                       : !seal ? 1 : -1;
  20.      schedule_goto(dest, FALSE, FALSE, portal_flag, (char *) 0, (char *) 0);
  21.      if (seal) { /* remove the portal to the quest - sealing it off */
  22.          int reexpelled = u.uevent.qexpelled;
  23.          u.uevent.qexpelled = 1;
  24.          remdun_mapseen(quest_dnum);
  25.          /* Delete the near portal now; the far (main dungeon side)
  26.             portal will be deleted as part of arrival on that level.
  27.             If monster movement is in progress, any who haven't moved
  28.             yet will now miss out on a chance to wander through it... */
  29.          for (t = ftrap; t; t = t->ntrap)
  30.              if (t->ttyp == MAGIC_PORTAL)
  31.                  break;
  32.          if (t)
  33.              deltrap(t); /* (display might be briefly out of sync) */
  34.          else if (!reexpelled)
  35.              impossible("quest portal already gone?");
  36.      }
  37.  }
  38.  

finish_quest

  1.  /* Either you've returned to quest leader while carrying the quest
  2.     artifact or you've just thrown it to/at him or her.  If quest
  3.     completion text hasn't been given yet, give it now.  Otherwise
  4.     give another message about the character keeping the artifact
  5.     and using the magic portal to return to the dungeon. */
  6.  void
  7.  finish_quest(obj)
  8.  struct obj *obj; /* quest artifact; possibly null if carrying Amulet */
  9.  {
  10.      struct obj *otmp;
  11.  
  12.      if (u.uhave.amulet) { /* unlikely but not impossible */
  13.          qt_pager(QT_HASAMULET);
  14.          /* leader IDs the real amulet but ignores any fakes */
  15.          if ((otmp = carrying(AMULET_OF_YENDOR)) != 0)
  16.              fully_identify_obj(otmp);
  17.      } else {
  18.          qt_pager(!Qstat(got_thanks) ? QT_OFFEREDIT : QT_OFFEREDIT2);
  19.          /* should have obtained bell during quest;
  20.             if not, suggest returning for it now */
  21.          if ((otmp = carrying(BELL_OF_OPENING)) == 0)
  22.              com_pager(5);
  23.      }
  24.      Qstat(got_thanks) = TRUE;
  25.  
  26.      if (obj) {
  27.          u.uevent.qcompleted = 1; /* you did it! */
  28.          /* behave as if leader imparts sufficient info about the
  29.             quest artifact */
  30.          fully_identify_obj(obj);
  31.          update_inventory();
  32.      }
  33.  }
  34.  

chat_with_leader

  1.  STATIC_OVL void
  2.  chat_with_leader()
  3.  {
  4.      /*  Rule 0: Cheater checks. */
  5.      if (u.uhave.questart && !Qstat(met_nemesis))
  6.          Qstat(cheater) = TRUE;
  7.  
  8.      /*  It is possible for you to get the amulet without completing
  9.       *  the quest.  If so, try to induce the player to quest.
  10.       */
  11.      if (Qstat(got_thanks)) {
  12.          /* Rule 1: You've gone back with/without the amulet. */
  13.          if (u.uhave.amulet)
  14.              finish_quest((struct obj *) 0);
  15.  
  16.          /* Rule 2: You've gone back before going for the amulet. */
  17.          else
  18.              qt_pager(QT_POSTHANKS);
  19.  
  20.      /* Rule 3: You've got the artifact and are back to return it. */
  21.      } else if (u.uhave.questart) {
  22.          struct obj *otmp;
  23.  
  24.          for (otmp = invent; otmp; otmp = otmp->nobj)
  25.              if (is_quest_artifact(otmp))
  26.                  break;
  27.  
  28.          finish_quest(otmp);
  29.  
  30.      /* Rule 4: You haven't got the artifact yet. */
  31.      } else if (Qstat(got_quest)) {
  32.          qt_pager(rn1(10, QT_ENCOURAGE));
  33.  
  34.      /* Rule 5: You aren't yet acceptable - or are you? */
  35.      } else {
  36.          if (!Qstat(met_leader)) {
  37.              qt_pager(QT_FIRSTLEADER);
  38.              Qstat(met_leader) = TRUE;
  39.              Qstat(not_ready) = 0;
  40.          } else
  41.              qt_pager(QT_NEXTLEADER);
  42.  
  43.          /* the quest leader might have passed through the portal into
  44.             the regular dungeon; none of the remaining make sense there */
  45.          if (!on_level(&u.uz, &qstart_level))
  46.              return;
  47.  
  48.          if (not_capable()) {
  49.              qt_pager(QT_BADLEVEL);
  50.              exercise(A_WIS, TRUE);
  51.              expulsion(FALSE);
  52.          } else if (is_pure(TRUE) < 0) {
  53.              com_pager(QT_BANISHED);
  54.              expulsion(TRUE);
  55.          } else if (is_pure(TRUE) == 0) {
  56.              qt_pager(QT_BADALIGN);
  57.              if (Qstat(not_ready) == MAX_QUEST_TRIES) {
  58.                  qt_pager(QT_LASTLEADER);
  59.                  expulsion(TRUE);
  60.              } else {
  61.                  Qstat(not_ready)++;
  62.                  exercise(A_WIS, TRUE);
  63.                  expulsion(FALSE);
  64.              }
  65.          } else { /* You are worthy! */
  66.              qt_pager(QT_ASSIGNQUEST);
  67.              exercise(A_WIS, TRUE);
  68.              Qstat(got_quest) = TRUE;
  69.          }
  70.      }
  71.  }
  72.  

leader_speaks

  1.  void
  2.  leader_speaks(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      /* maybe you attacked leader? */
  6.      if (!mtmp->mpeaceful) {
  7.          Qstat(pissed_off) = TRUE;
  8.          mtmp->mstrategy &= ~STRAT_WAITMASK; /* end the inaction */
  9.      }
  10.      /* the quest leader might have passed through the portal into the
  11.         regular dungeon; if so, mustn't perform "backwards expulsion" */
  12.      if (!on_level(&u.uz, &qstart_level))
  13.          return;
  14.  
  15.      if (Qstat(pissed_off)) {
  16.          qt_pager(QT_LASTLEADER);
  17.          expulsion(TRUE);
  18.      } else
  19.          chat_with_leader();
  20.  }
  21.  

chat_with_nemesis

  1.  STATIC_OVL void
  2.  chat_with_nemesis()
  3.  {
  4.      /*  The nemesis will do most of the talking, but... */
  5.      qt_pager(rn1(10, QT_DISCOURAGE));
  6.      if (!Qstat(met_nemesis))
  7.          Qstat(met_nemesis++);
  8.  }
  9.  

nemesis_speaks

  1.  void
  2.  nemesis_speaks()
  3.  {
  4.      if (!Qstat(in_battle)) {
  5.          if (u.uhave.questart)
  6.              qt_pager(QT_NEMWANTSIT);
  7.          else if (Qstat(made_goal) == 1 || !Qstat(met_nemesis))
  8.              qt_pager(QT_FIRSTNEMESIS);
  9.          else if (Qstat(made_goal) < 4)
  10.              qt_pager(QT_NEXTNEMESIS);
  11.          else if (Qstat(made_goal) < 7)
  12.              qt_pager(QT_OTHERNEMESIS);
  13.          else if (!rn2(5))
  14.              qt_pager(rn1(10, QT_DISCOURAGE));
  15.          if (Qstat(made_goal) < 7)
  16.              Qstat(made_goal)++;
  17.          Qstat(met_nemesis) = TRUE;
  18.      } else /* he will spit out random maledictions */
  19.          if (!rn2(5))
  20.          qt_pager(rn1(10, QT_DISCOURAGE));
  21.  }
  22.  

chat_with_guardian

  1.  STATIC_OVL void
  2.  chat_with_guardian()
  3.  {
  4.      /*  These guys/gals really don't have much to say... */
  5.      if (u.uhave.questart && Qstat(killed_nemesis))
  6.          qt_pager(rn1(5, QT_GUARDTALK2));
  7.      else
  8.          qt_pager(rn1(5, QT_GUARDTALK));
  9.  }
  10.  

prisoner_speaks

  1.  STATIC_OVL void
  2.  prisoner_speaks(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (mtmp->data == &mons[PM_PRISONER]
  6.          && (mtmp->mstrategy & STRAT_WAITMASK)) {
  7.          /* Awaken the prisoner */
  8.          if (canseemon(mtmp))
  9.              pline("%s speaks:", Monnam(mtmp));
  10.          verbalize("I'm finally free!");
  11.          mtmp->mstrategy &= ~STRAT_WAITMASK;
  12.          mtmp->mpeaceful = 1;
  13.  
  14.          /* Your god is happy... */
  15.          adjalign(3);
  16.  
  17.          /* ...But the guards are not */
  18.          (void) angry_guards(FALSE);
  19.      }
  20.      return;
  21.  }
  22.  

quest_chat

  1.  void
  2.  quest_chat(mtmp)
  3.  register struct monst *mtmp;
  4.  {
  5.      if (mtmp->m_id == Qstat(leader_m_id)) {
  6.          chat_with_leader();
  7.          return;
  8.      }
  9.      switch (mtmp->data->msound) {
  10.      case MS_NEMESIS:
  11.          chat_with_nemesis();
  12.          break;
  13.      case MS_GUARDIAN:
  14.          chat_with_guardian();
  15.          break;
  16.      default:
  17.          impossible("quest_chat: Unknown quest character %s.", mon_nam(mtmp));
  18.      }
  19.  }
  20.  

quest_talk

  1.  void
  2.  quest_talk(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (mtmp->m_id == Qstat(leader_m_id)) {
  6.          leader_speaks(mtmp);
  7.          return;
  8.      }
  9.      switch (mtmp->data->msound) {
  10.      case MS_NEMESIS:
  11.          nemesis_speaks();
  12.          break;
  13.      case MS_DJINNI:
  14.          prisoner_speaks(mtmp);
  15.          break;
  16.      default:
  17.          break;
  18.      }
  19.  }
  20.  

quest_stat_check

  1.  void
  2.  quest_stat_check(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (mtmp->data->msound == MS_NEMESIS)
  6.          Qstat(in_battle) = (mtmp->mcanmove && !mtmp->msleeping
  7.                              && monnear(mtmp, u.ux, u.uy));
  8.  }
  9.  
  10.  /*quest.c*/