Source:NetHack 3.6.1/src/allmain.c

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

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

Top of file

  1.  /* NetHack 3.6	allmain.c	$NHDT-Date: 1518193644 2018/02/09 16:27:24 $  $NHDT-Branch: githash $:$NHDT-Revision: 1.86 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Robert Patrick Rankin, 2012. */
  4.  /* NetHack may be freely redistributed.  See license for details. */

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.

  1.  
  2.  /* various code that was replicated in *main.c */
  3.  
  4.  #include "hack.h"
  5.  
  6.  #ifndef NO_SIGNAL
  7.  #include <signal.h>
  8.  #endif
  9.  
  10.  #ifdef POSITIONBAR
  11.  STATIC_DCL void NDECL(do_positionbar);
  12.  #endif
  13.  STATIC_DCL void FDECL(regen_hp, (int));
  14.  STATIC_DCL void FDECL(interrupt_multi, (const char *));
  15.  

moveloop

  1.  void
  2.  moveloop(resuming)
  3.  boolean resuming;
  4.  {
  5.  #if defined(MICRO) || defined(WIN32)
  6.      char ch;
  7.      int abort_lev;
  8.  #endif
  9.      int moveamt = 0, wtcap = 0, change = 0;
  10.      boolean monscanmove = FALSE;
  11.  
  12.      /* Note:  these initializers don't do anything except guarantee that
  13.              we're linked properly.
  14.      */
  15.      decl_init();
  16.      monst_init();
  17.      monstr_init(); /* monster strengths */
  18.      objects_init();
  19.  
  20.      /* if a save file created in normal mode is now being restored in
  21.         explore mode, treat it as normal restore followed by 'X' command
  22.         to use up the save file and require confirmation for explore mode */
  23.      if (resuming && iflags.deferred_X)
  24.          (void) enter_explore_mode();
  25.  
  26.      /* side-effects from the real world */
  27.      flags.moonphase = phase_of_the_moon();
  28.      if (flags.moonphase == FULL_MOON) {
  29.          You("are lucky!  Full moon tonight.");
  30.          change_luck(1);
  31.      } else if (flags.moonphase == NEW_MOON) {
  32.          pline("Be careful!  New moon tonight.");
  33.      }
  34.      flags.friday13 = friday_13th();
  35.      if (flags.friday13) {
  36.          pline("Watch out!  Bad things can happen on Friday the 13th.");
  37.          change_luck(-1);
  38.      }
  39.  
  40.      if (!resuming) { /* new game */
  41.          context.rndencode = rnd(9000);
  42.          set_wear((struct obj *) 0); /* for side-effects of starting gear */
  43.          (void) pickup(1);      /* autopickup at initial location */
  44.      }
  45.      context.botlx = TRUE; /* for STATUS_HILITES */
  46.      update_inventory(); /* for perm_invent */
  47.      if (resuming) { /* restoring old game */
  48.          read_engr_at(u.ux, u.uy); /* subset of pickup() */
  49.      }
  50.  
  51.      (void) encumber_msg(); /* in case they auto-picked up something */
  52.      if (defer_see_monsters) {
  53.          defer_see_monsters = FALSE;
  54.          see_monsters();
  55.      }
  56.      initrack();
  57.  
  58.      u.uz0.dlevel = u.uz.dlevel;
  59.      youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */
  60.      context.move = 0;
  61.  
  62.      program_state.in_moveloop = 1;
  63.      for (;;) {
  64.  #ifdef SAFERHANGUP
  65.          if (program_state.done_hup)
  66.              end_of_input();
  67.  #endif
  68.          get_nh_event();
  69.  #ifdef POSITIONBAR
  70.          do_positionbar();
  71.  #endif
  72.  
  73.          if (context.move) {
  74.              /* actual time passed */
  75.              youmonst.movement -= NORMAL_SPEED;
  76.  
  77.              do { /* hero can't move this turn loop */
  78.                  wtcap = encumber_msg();
  79.  
  80.                  context.mon_moving = TRUE;
  81.                  do {
  82.                      monscanmove = movemon();
  83.                      if (youmonst.movement >= NORMAL_SPEED)
  84.                          break; /* it's now your turn */
  85.                  } while (monscanmove);
  86.                  context.mon_moving = FALSE;
  87.  
  88.                  if (!monscanmove && youmonst.movement < NORMAL_SPEED) {
  89.                      /* both you and the monsters are out of steam this round
  90.                       */
  91.                      /* set up for a new turn */
  92.                      struct monst *mtmp;
  93.                      mcalcdistress(); /* adjust monsters' trap, blind, etc */
  94.  
  95.                      /* reallocate movement rations to monsters */
  96.                      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  97.                          mtmp->movement += mcalcmove(mtmp);
  98.  
  99.                      if (!rn2(u.uevent.udemigod
  100.                                   ? 25
  101.                                   : (depth(&u.uz) > depth(&stronghold_level))
  102.                                         ? 50
  103.                                         : 70))
  104.                          (void) makemon((struct permonst *) 0, 0, 0,
  105.                                         NO_MM_FLAGS);
  106.  
  107.                      /* calculate how much time passed. */
  108.                      if (u.usteed && u.umoved) {
  109.                          /* your speed doesn't augment steed's speed */
  110.                          moveamt = mcalcmove(u.usteed);
  111.                      } else {
  112.                          moveamt = youmonst.data->mmove;
  113.  
  114.                          if (Very_fast) { /* speed boots or potion */
  115.                              /* gain a free action on 2/3 of turns */
  116.                              if (rn2(3) != 0)
  117.                                  moveamt += NORMAL_SPEED;
  118.                          } else if (Fast) {
  119.                              /* gain a free action on 1/3 of turns */
  120.                              if (rn2(3) == 0)
  121.                                  moveamt += NORMAL_SPEED;
  122.                          }
  123.                      }
  124.  
  125.                      switch (wtcap) {
  126.                      case UNENCUMBERED:
  127.                          break;
  128.                      case SLT_ENCUMBER:
  129.                          moveamt -= (moveamt / 4);
  130.                          break;
  131.                      case MOD_ENCUMBER:
  132.                          moveamt -= (moveamt / 2);
  133.                          break;
  134.                      case HVY_ENCUMBER:
  135.                          moveamt -= ((moveamt * 3) / 4);
  136.                          break;
  137.                      case EXT_ENCUMBER:
  138.                          moveamt -= ((moveamt * 7) / 8);
  139.                          break;
  140.                      default:
  141.                          break;
  142.                      }
  143.  
  144.                      youmonst.movement += moveamt;
  145.                      if (youmonst.movement < 0)
  146.                          youmonst.movement = 0;
  147.                      settrack();
  148.  
  149.                      monstermoves++;
  150.                      moves++;
  151.  
  152.                      /********************************/
  153.                      /* once-per-turn things go here */
  154.                      /********************************/
  155.  
  156.                      if (Glib)
  157.                          glibr();
  158.                      nh_timeout();
  159.                      run_regions();
  160.  
  161.                      if (u.ublesscnt)
  162.                          u.ublesscnt--;
  163.                      if (flags.time && !context.run)
  164.                          context.botl = 1;
  165.  
  166.                      /* One possible result of prayer is healing.  Whether or
  167.                       * not you get healed depends on your current hit points.
  168.                       * If you are allowed to regenerate during the prayer,
  169.                       * the end-of-prayer calculation messes up on this.
  170.                       * Another possible result is rehumanization, which
  171.                       * requires that encumbrance and movement rate be
  172.                       * recalculated.
  173.                       */
  174.                      if (u.uinvulnerable) {
  175.                          /* for the moment at least, you're in tiptop shape */
  176.                          wtcap = UNENCUMBERED;
  177.                      } else if (!Upolyd ? (u.uhp < u.uhpmax)
  178.                                         : (u.mh < u.mhmax
  179.                                            || youmonst.data->mlet == S_EEL)) {
  180.                          /* maybe heal */
  181.                          regen_hp(wtcap);
  182.                      }
  183.  
  184.                      /* moving around while encumbered is hard work */
  185.                      if (wtcap > MOD_ENCUMBER && u.umoved) {
  186.                          if (!(wtcap < EXT_ENCUMBER ? moves % 30
  187.                                                     : moves % 10)) {
  188.                              if (Upolyd && u.mh > 1) {
  189.                                  u.mh--;
  190.                              } else if (!Upolyd && u.uhp > 1) {
  191.                                  u.uhp--;
  192.                              } else {
  193.                                  You("pass out from exertion!");
  194.                                  exercise(A_CON, FALSE);
  195.                                  fall_asleep(-10, FALSE);
  196.                              }
  197.                          }
  198.                      }
  199.  
  200.                      if (u.uen < u.uenmax
  201.                          && ((wtcap < MOD_ENCUMBER
  202.                               && (!(moves % ((MAXULEV + 8 - u.ulevel)
  203.                                              * (Role_if(PM_WIZARD) ? 3 : 4)
  204.                                              / 6)))) || Energy_regeneration)) {
  205.                          u.uen += rn1(
  206.                              (int) (ACURR(A_WIS) + ACURR(A_INT)) / 15 + 1, 1);
  207.                          if (u.uen > u.uenmax)
  208.                              u.uen = u.uenmax;
  209.                          context.botl = 1;
  210.                          if (u.uen == u.uenmax)
  211.                              interrupt_multi("You feel full of energy.");
  212.                      }
  213.  
  214.                      if (!u.uinvulnerable) {
  215.                          if (Teleportation && !rn2(85)) {
  216.                              xchar old_ux = u.ux, old_uy = u.uy;
  217.                              tele();
  218.                              if (u.ux != old_ux || u.uy != old_uy) {
  219.                                  if (!next_to_u()) {
  220.                                      check_leash(old_ux, old_uy);
  221.                                  }
  222.                                  /* clear doagain keystrokes */
  223.                                  pushch(0);
  224.                                  savech(0);
  225.                              }
  226.                          }
  227.                          /* delayed change may not be valid anymore */
  228.                          if ((change == 1 && !Polymorph)
  229.                              || (change == 2 && u.ulycn == NON_PM))
  230.                              change = 0;
  231.                          if (Polymorph && !rn2(100))
  232.                              change = 1;
  233.                          else if (u.ulycn >= LOW_PM && !Upolyd
  234.                                   && !rn2(80 - (20 * night())))
  235.                              change = 2;
  236.                          if (change && !Unchanging) {
  237.                              if (multi >= 0) {
  238.                                  stop_occupation();
  239.                                  if (change == 1)
  240.                                      polyself(0);
  241.                                  else
  242.                                      you_were();
  243.                                  change = 0;
  244.                              }
  245.                          }
  246.                      }
  247.  
  248.                      if (Searching && multi >= 0)
  249.                          (void) dosearch0(1);
  250.                      if (Warning)
  251.                          warnreveal();
  252.                      mkot_trap_warn();
  253.                      dosounds();
  254.                      do_storms();
  255.                      gethungry();
  256.                      age_spells();
  257.                      exerchk();
  258.                      invault();
  259.                      if (u.uhave.amulet)
  260.                          amulet();
  261.                      if (!rn2(40 + (int) (ACURR(A_DEX) * 3)))
  262.                          u_wipe_engr(rnd(3));
  263.                      if (u.uevent.udemigod && !u.uinvulnerable) {
  264.                          if (u.udg_cnt)
  265.                              u.udg_cnt--;
  266.                          if (!u.udg_cnt) {
  267.                              intervene();
  268.                              u.udg_cnt = rn1(200, 50);
  269.                          }
  270.                      }
  271.                      restore_attrib();
  272.                      /* underwater and waterlevel vision are done here */
  273.                      if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz))
  274.                          movebubbles();
  275.                      else if (Is_firelevel(&u.uz))
  276.                          fumaroles();
  277.                      else if (Underwater)
  278.                          under_water(0);
  279.                      /* vision while buried done here */
  280.                      else if (u.uburied)
  281.                          under_ground(0);
  282.  
  283.                      /* when immobile, count is in turns */
  284.                      if (multi < 0) {
  285.                          if (++multi == 0) { /* finished yet? */
  286.                              unmul((char *) 0);
  287.                              /* if unmul caused a level change, take it now */
  288.                              if (u.utotype)
  289.                                  deferred_goto();
  290.                          }
  291.                      }
  292.                  }
  293.              } while (youmonst.movement
  294.                       < NORMAL_SPEED); /* hero can't move loop */
  295.  
  296.              /******************************************/
  297.              /* once-per-hero-took-time things go here */
  298.              /******************************************/
  299.  
  300.              status_eval_next_unhilite();
  301.              if (context.bypasses)
  302.                  clear_bypasses();
  303.              if ((u.uhave.amulet || Clairvoyant) && !In_endgame(&u.uz)
  304.                  && !BClairvoyant && !(moves % 15) && !rn2(2))
  305.                  do_vicinity_map((struct obj *) 0);
  306.              if (u.utrap && u.utraptype == TT_LAVA)
  307.                  sink_into_lava();
  308.              /* when/if hero escapes from lava, he can't just stay there */
  309.              else if (!u.umoved)
  310.                  (void) pooleffects(FALSE);
  311.  
  312.          } /* actual time passed */
  313.  
  314.          /****************************************/
  315.          /* once-per-player-input things go here */
  316.          /****************************************/
  317.  
  318.          clear_splitobjs();
  319.          find_ac();
  320.          if (!context.mv || Blind) {
  321.              /* redo monsters if hallu or wearing a helm of telepathy */
  322.              if (Hallucination) { /* update screen randomly */
  323.                  see_monsters();
  324.                  see_objects();
  325.                  see_traps();
  326.                  if (u.uswallow)
  327.                      swallowed(0);
  328.              } else if (Unblind_telepat) {
  329.                  see_monsters();
  330.              } else if (Warning || Warn_of_mon)
  331.                  see_monsters();
  332.  
  333.              if (vision_full_recalc)
  334.                  vision_recalc(0); /* vision! */
  335.          }
  336.          if (context.botl || context.botlx) {
  337.              bot();
  338.              curs_on_u();
  339.          }
  340.  
  341.          context.move = 1;
  342.  
  343.          if (multi >= 0 && occupation) {
  344.  #if defined(MICRO) || defined(WIN32)
  345.              abort_lev = 0;
  346.              if (kbhit()) {
  347.                  if ((ch = pgetchar()) == ABORT)
  348.                      abort_lev++;
  349.                  else
  350.                      pushch(ch);
  351.              }
  352.              if (!abort_lev && (*occupation)() == 0)
  353.  #else
  354.              if ((*occupation)() == 0)
  355.  #endif
  356.                  occupation = 0;
  357.              if (
  358.  #if defined(MICRO) || defined(WIN32)
  359.                  abort_lev ||
  360.  #endif
  361.                  monster_nearby()) {
  362.                  stop_occupation();
  363.                  reset_eat();
  364.              }
  365.  #if defined(MICRO) || defined(WIN32)
  366.              if (!(++occtime % 7))
  367.                  display_nhwindow(WIN_MAP, FALSE);
  368.  #endif
  369.              continue;
  370.          }
  371.  
  372.          if (iflags.sanity_check)
  373.              sanity_check();
  374.  
  375.  #ifdef CLIPPING
  376.          /* just before rhack */
  377.          cliparound(u.ux, u.uy);
  378.  #endif
  379.  
  380.          u.umoved = FALSE;
  381.  
  382.          if (multi > 0) {
  383.              lookaround();
  384.              if (!multi) {
  385.                  /* lookaround may clear multi */
  386.                  context.move = 0;
  387.                  if (flags.time)
  388.                      context.botl = 1;
  389.                  continue;
  390.              }
  391.              if (context.mv) {
  392.                  if (multi < COLNO && !--multi)
  393.                      context.travel = context.travel1 = context.mv =
  394.                          context.run = 0;
  395.                  domove();
  396.              } else {
  397.                  --multi;
  398.                  rhack(save_cm);
  399.              }
  400.          } else if (multi == 0) {
  401.  #ifdef MAIL
  402.              ckmailstatus();
  403.  #endif
  404.              rhack((char *) 0);
  405.          }
  406.          if (u.utotype)       /* change dungeon level */
  407.              deferred_goto(); /* after rhack() */
  408.          /* !context.move here: multiple movement command stopped */
  409.          else if (flags.time && (!context.move || !context.mv))
  410.              context.botl = 1;
  411.  
  412.          if (vision_full_recalc)
  413.              vision_recalc(0); /* vision! */
  414.          /* when running in non-tport mode, this gets done through domove() */
  415.          if ((!context.run || flags.runmode == RUN_TPORT)
  416.              && (multi && (!context.travel ? !(multi % 7) : !(moves % 7L)))) {
  417.              if (flags.time && context.run)
  418.                  context.botl = 1;
  419.              display_nhwindow(WIN_MAP, FALSE);
  420.          }
  421.      }
  422.  }
  423.  

regen_hp

  1.  /* maybe recover some lost health (or lose some when an eel out of water) */
  2.  STATIC_OVL void
  3.  regen_hp(wtcap)
  4.  int wtcap;
  5.  {
  6.      int heal = 0;
  7.      boolean reached_full = FALSE,
  8.              encumbrance_ok = (wtcap < MOD_ENCUMBER || !u.umoved);
  9.  
  10.      if (Upolyd) {
  11.          if (u.mh < 1) { /* shouldn't happen... */
  12.              rehumanize();
  13.          } else if (youmonst.data->mlet == S_EEL
  14.                     && !is_pool(u.ux, u.uy) && !Is_waterlevel(&u.uz)) {
  15.              /* eel out of water loses hp, similar to monster eels;
  16.                 as hp gets lower, rate of further loss slows down */
  17.              if (u.mh > 1 && !Regeneration && rn2(u.mh) > rn2(8)
  18.                  && (!Half_physical_damage || !(moves % 2L)))
  19.                  heal = -1;
  20.          } else if (u.mh < u.mhmax) {
  21.              if (Regeneration || (encumbrance_ok && !(moves % 20L)))
  22.                  heal = 1;
  23.          }
  24.          if (heal) {
  25.              context.botl = 1;
  26.              u.mh += heal;
  27.              reached_full = (u.mh == u.mhmax);
  28.          }
  29.  
  30.      /* !Upolyd */
  31.      } else {
  32.          /* [when this code was in-line within moveloop(), there was
  33.             no !Upolyd check here, so poly'd hero recovered lost u.uhp
  34.             once u.mh reached u.mhmax; that may have been convenient
  35.             for the player, but it didn't make sense for gameplay...] */
  36.          if (u.uhp < u.uhpmax && (encumbrance_ok || Regeneration)) {
  37.              if (u.ulevel > 9) {
  38.                  if (!(moves % 3L)) {
  39.                      int Con = (int) ACURR(A_CON);
  40.  
  41.                      if (Con <= 12) {
  42.                          heal = 1;
  43.                      } else {
  44.                          heal = rnd(Con);
  45.                          if (heal > u.ulevel - 9)
  46.                              heal = u.ulevel - 9;
  47.                      }
  48.                  }
  49.              } else { /* u.ulevel <= 9 */
  50.                  if (!(moves % (long) ((MAXULEV + 12) / (u.ulevel + 2) + 1)))
  51.                      heal = 1;
  52.              }
  53.              if (Regeneration && !heal)
  54.                  heal = 1;
  55.  
  56.              if (heal) {
  57.                  context.botl = 1;
  58.                  u.uhp += heal;
  59.                  if (u.uhp > u.uhpmax)
  60.                      u.uhp = u.uhpmax;
  61.                  /* stop voluntary multi-turn activity if now fully healed */
  62.                  reached_full = (u.uhp == u.uhpmax);
  63.              }
  64.          }
  65.      }
  66.  
  67.      if (reached_full)
  68.          interrupt_multi("You are in full health.");
  69.  }
  70.  
  71.  void
  72.  stop_occupation()
  73.  {
  74.      if (occupation) {
  75.          if (!maybe_finished_meal(TRUE))
  76.              You("stop %s.", occtxt);
  77.          occupation = 0;
  78.          context.botl = 1; /* in case u.uhs changed */
  79.          nomul(0);
  80.          pushch(0);
  81.      } else if (multi >= 0) {
  82.          nomul(0);
  83.      }
  84.  }
  85.  
  86.  void
  87.  display_gamewindows()
  88.  {
  89.      WIN_MESSAGE = create_nhwindow(NHW_MESSAGE);
  90.  #ifdef STATUS_HILITES
  91.      status_initialize(0);
  92.  #else
  93.      WIN_STATUS = create_nhwindow(NHW_STATUS);
  94.  #endif
  95.      WIN_MAP = create_nhwindow(NHW_MAP);
  96.      WIN_INVEN = create_nhwindow(NHW_MENU);
  97.      /* in case of early quit where WIN_INVEN could be destroyed before
  98.         ever having been used, use it here to pacify the Qt interface */
  99.      start_menu(WIN_INVEN), end_menu(WIN_INVEN, (char *) 0);
  100.  
  101.  #ifdef MAC
  102.      /* This _is_ the right place for this - maybe we will
  103.       * have to split display_gamewindows into create_gamewindows
  104.       * and show_gamewindows to get rid of this ifdef...
  105.       */
  106.      if (!strcmp(windowprocs.name, "mac"))
  107.          SanePositions();
  108.  #endif
  109.  
  110.      /*
  111.       * The mac port is not DEPENDENT on the order of these
  112.       * displays, but it looks a lot better this way...
  113.       */
  114.  #ifndef STATUS_HILITES
  115.      display_nhwindow(WIN_STATUS, FALSE);
  116.  #endif
  117.      display_nhwindow(WIN_MESSAGE, FALSE);
  118.      clear_glyph_buffer();
  119.      display_nhwindow(WIN_MAP, FALSE);
  120.  }
  121.  
  122.  void
  123.  newgame()
  124.  {
  125.      int i;
  126.  
  127.  #ifdef MFLOPPY
  128.      gameDiskPrompt();
  129.  #endif
  130.  
  131.      context.botlx = 1;
  132.      context.ident = 1;
  133.      context.stethoscope_move = -1L;
  134.      context.warnlevel = 1;
  135.      context.next_attrib_check = 600L; /* arbitrary first setting */
  136.      context.tribute.enabled = TRUE;   /* turn on 3.6 tributes    */
  137.      context.tribute.tributesz = sizeof(struct tribute_info);
  138.  
  139.      for (i = LOW_PM; i < NUMMONS; i++)
  140.          mvitals[i].mvflags = mons[i].geno & G_NOCORPSE;
  141.  
  142.      init_objects(); /* must be before u_init() */
  143.  
  144.      flags.pantheon = -1; /* role_init() will reset this */
  145.      role_init();         /* must be before init_dungeons(), u_init(),
  146.                            * and init_artifacts() */
  147.  
  148.      init_dungeons();  /* must be before u_init() to avoid rndmonst()
  149.                         * creating odd monsters for any tins and eggs
  150.                         * in hero's initial inventory */
  151.      init_artifacts(); /* before u_init() in case $WIZKIT specifies
  152.                         * any artifacts */
  153.      u_init();
  154.  
  155.  #ifndef NO_SIGNAL
  156.      (void) signal(SIGINT, (SIG_RET_TYPE) done1);
  157.  #endif
  158.  #ifdef NEWS
  159.      if (iflags.news)
  160.          display_file(NEWS, FALSE);
  161.  #endif
  162.      load_qtlist();          /* load up the quest text info */
  163.      /* quest_init();  --  Now part of role_init() */
  164.  
  165.      mklev();
  166.      u_on_upstairs();
  167.      if (wizard)
  168.          obj_delivery(FALSE); /* finish wizkit */
  169.      vision_reset();          /* set up internals for level (after mklev) */
  170.      check_special_room(FALSE);
  171.  
  172.      if (MON_AT(u.ux, u.uy))
  173.          mnexto(m_at(u.ux, u.uy));
  174.      (void) makedog();
  175.      docrt();
  176.  
  177.      if (flags.legacy) {
  178.          flush_screen(1);
  179.          com_pager(1);
  180.      }
  181.  
  182.      urealtime.realtime = 0L;
  183.      urealtime.start_timing = getnow();
  184.  #ifdef INSURANCE
  185.      save_currentstate();
  186.  #endif
  187.      program_state.something_worth_saving++; /* useful data now exists */
  188.  
  189.      /* Success! */
  190.      welcome(TRUE);
  191.      return;
  192.  }
  193.  
  194.  /* show "welcome [back] to nethack" message at program startup */
  195.  void
  196.  welcome(new_game)
  197.  boolean new_game; /* false => restoring an old game */
  198.  {
  199.      char buf[BUFSZ];
  200.      boolean currentgend = Upolyd ? u.mfemale : flags.female;
  201.  
  202.      /* skip "welcome back" if restoring a doomed character */
  203.      if (!new_game && Upolyd && ugenocided()) {
  204.          /* death via self-genocide is pending */
  205.          pline("You're back, but you still feel %s inside.", udeadinside());
  206.          return;
  207.      }
  208.  
  209.      /*
  210.       * The "welcome back" message always describes your innate form
  211.       * even when polymorphed or wearing a helm of opposite alignment.
  212.       * Alignment is shown unconditionally for new games; for restores
  213.       * it's only shown if it has changed from its original value.
  214.       * Sex is shown for new games except when it is redundant; for
  215.       * restores it's only shown if different from its original value.
  216.       */
  217.      *buf = '\0';
  218.      if (new_game || u.ualignbase[A_ORIGINAL] != u.ualignbase[A_CURRENT])
  219.          Sprintf(eos(buf), " %s", align_str(u.ualignbase[A_ORIGINAL]));
  220.      if (!urole.name.f
  221.          && (new_game
  222.                  ? (urole.allow & ROLE_GENDMASK) == (ROLE_MALE | ROLE_FEMALE)
  223.                  : currentgend != flags.initgend))
  224.          Sprintf(eos(buf), " %s", genders[currentgend].adj);
  225.  
  226.      pline(new_game ? "%s %s, welcome to NetHack!  You are a%s %s %s."
  227.                     : "%s %s, the%s %s %s, welcome back to NetHack!",
  228.            Hello((struct monst *) 0), plname, buf, urace.adj,
  229.            (currentgend && urole.name.f) ? urole.name.f : urole.name.m);
  230.  }
  231.  

do_positionbar

  1.  #ifdef POSITIONBAR
  2.  STATIC_DCL void
  3.  do_positionbar()
  4.  {
  5.      static char pbar[COLNO];
  6.      char *p;
  7.  
  8.      p = pbar;
  9.      /* up stairway */
  10.      if (upstair.sx
  11.          && (glyph_to_cmap(level.locations[upstair.sx][upstair.sy].glyph)
  12.                  == S_upstair
  13.              || glyph_to_cmap(level.locations[upstair.sx][upstair.sy].glyph)
  14.                     == S_upladder)) {
  15.          *p++ = '<';
  16.          *p++ = upstair.sx;
  17.      }
  18.      if (sstairs.sx
  19.          && (glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph)
  20.                  == S_upstair
  21.              || glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph)
  22.                     == S_upladder)) {
  23.          *p++ = '<';
  24.          *p++ = sstairs.sx;
  25.      }
  26.  
  27.      /* down stairway */
  28.      if (dnstair.sx
  29.          && (glyph_to_cmap(level.locations[dnstair.sx][dnstair.sy].glyph)
  30.                  == S_dnstair
  31.              || glyph_to_cmap(level.locations[dnstair.sx][dnstair.sy].glyph)
  32.                     == S_dnladder)) {
  33.          *p++ = '>';
  34.          *p++ = dnstair.sx;
  35.      }
  36.      if (sstairs.sx
  37.          && (glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph)
  38.                  == S_dnstair
  39.              || glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph)
  40.                     == S_dnladder)) {
  41.          *p++ = '>';
  42.          *p++ = sstairs.sx;
  43.      }
  44.  
  45.      /* hero location */
  46.      if (u.ux) {
  47.          *p++ = '@';
  48.          *p++ = u.ux;
  49.      }
  50.      /* fence post */
  51.      *p = 0;
  52.  
  53.      update_positionbar(pbar);
  54.  }
  55.  #endif
  56.  

interrupt_multi

  1.  STATIC_DCL void
  2.  interrupt_multi(msg)
  3.  const char *msg;
  4.  {
  5.      if (multi > 0 && !context.travel && !context.run) {
  6.          nomul(0);
  7.          if (flags.verbose && msg)
  8.              Norep("%s", msg);
  9.      }
  10.  }
  11.  
  12.  /*
  13.   * Argument processing helpers - for xxmain() to share
  14.   * and call.
  15.   *
  16.   * These should return TRUE if the argument matched,
  17.   * whether the processing of the argument was
  18.   * successful or not.
  19.   *
  20.   * Most of these do their thing, then after returning
  21.   * to xxmain(), the code exits without starting a game.
  22.   *
  23.   */
  24.  
  25.  static struct early_opt earlyopts[] = {
  26.      {ARG_DEBUG, "debug", 5, FALSE},
  27.      {ARG_VERSION, "version", 4, TRUE},
  28.  };
  29.  

argcheck

  1.  boolean
  2.  argcheck(argc, argv, e_arg)
  3.  int argc;
  4.  char *argv[];
  5.  enum earlyarg e_arg;
  6.  {
  7.      int i, idx;
  8.      boolean match = FALSE;
  9.      char *userea = (char *)0;
  10.      const char *dashdash = "";
  11.  
  12.      for (idx = 0; idx < SIZE(earlyopts); idx++) {
  13.          if (earlyopts[idx].e == e_arg)
  14.              break;
  15.      }
  16.      if ((idx >= SIZE(earlyopts)) || (argc <= 1))
  17.              return FALSE;
  18.  
  19.      for (i = 1; i < argc; ++i) {
  20.          if (argv[i][0] != '-')
  21.              continue;
  22.          if (argv[i][1] == '-') {
  23.              userea = &argv[i][2];
  24.              dashdash = "-";
  25.          } else {
  26.              userea = &argv[i][1];
  27.          }
  28.          match = match_optname(userea, earlyopts[idx].name,
  29.                      earlyopts[idx].minlength, earlyopts[idx].valallowed);
  30.          if (match) break;
  31.      }
  32.  
  33.      if (match) {
  34.          switch(e_arg) {
  35.              case ARG_DEBUG:
  36.                          break;
  37.              case ARG_VERSION: {
  38.                          boolean insert_into_pastebuf = FALSE;
  39.                          const char *extended_opt = index(userea,':');
  40.  
  41.                          if (!extended_opt)
  42.                              extended_opt = index(userea, '=');
  43.  
  44.                          if (extended_opt) {
  45.                              extended_opt++;
  46.                              if (match_optname(extended_opt, "paste",
  47.                                                     5, FALSE)) {
  48.                                  insert_into_pastebuf = TRUE;
  49.                              } else {
  50.                                  raw_printf(
  51.                       "-%sversion can only be extended with -%sversion:paste.\n",
  52.                                              dashdash, dashdash);
  53.                                  return TRUE;
  54.              		    }
  55.          		}
  56.                          early_version_info(insert_into_pastebuf);
  57.                          return TRUE;
  58.                          break;
  59.              }
  60.              default:
  61.                          break;
  62.          }
  63.      };
  64.      return FALSE;
  65.  }
  66.  
  67.  /*allmain.c*/