home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sources / games / 166 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  56.1 KB

  1. Path: sparky!uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v14i036:  umoria4 - single player dungeon simulation (ver. 5.5), Part04/39
  5. Message-ID: <3394@master.CNA.TEK.COM>
  6. Date: 20 Aug 92 18:02:29 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 2285
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: grabiner@math.harvard.edu (David Grabiner)
  12. Posting-number: Volume 14, Issue 36
  13. Archive-name: umoria4/Part04
  14. Supersedes: umoria3: Volume 9, Issue 55-97; Volume 10, Issue 15-17
  15. Environment: Curses, Unix, Mac, MS-DOS, Atari-ST, Amiga, VMS
  16.  
  17.  
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 4 (of 39)."
  26. # Contents:  atari_st/curscomp/curses.txt source/dungeon.c
  27. # Wrapped by billr@saab on Thu Aug 20 09:11:26 1992
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'atari_st/curscomp/curses.txt' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'atari_st/curscomp/curses.txt'\"
  31. else
  32. echo shar: Extracting \"'atari_st/curscomp/curses.txt'\" \(2869 characters\)
  33. sed "s/^X//" >'atari_st/curscomp/curses.txt' <<'END_OF_FILE'
  34. XCURSES.TXT - some documentation for ST-Curses.
  35. X
  36. XThis text should come together with three other files :
  37. X  CURSES.C  - C code for the ST-Curses package
  38. X  CURSES.H  - include file for programs using curses
  39. X  CURSINC.H - include file for CURSES.C
  40. X  
  41. XCurses is a computer and terminal-independent screen package for character-
  42. Xbased programs. Curses originated in the UNIX world and many programs written
  43. Xfor UNIX require a version of curses. This is ST-curses, a port of Curses for
  44. Xthe Atari ST in monochrome or medium resolution. This text has been written by
  45. XHildo Biersma (address below), but I did not originally write the ST-Curses
  46. Xpackage. However, I did an almost complete rewrite for reasons of clarity and
  47. Xspeed; I am therefore including some documentation with it, too.
  48. X
  49. XThis version was written for use with Turbo-C 2.0; some changes may be needed
  50. Xif you intend to use it with Mark Williams C, GNU C or other compiler.
  51. XThroughout all of the code in CURSES.C I have included a number of comments that
  52. Xshould make the code understandable and therefore (I hope) maintainable.
  53. XYou should take special notice of the explanation of the *WINDOW data structure
  54. Xthat appears as a header in CURSES.C.
  55. X
  56. XST-Curses was originally written by :
  57. X  Rene van't Veen
  58. X  Debussystraat 27
  59. X  1817 GL Alkmaar
  60. X  The Netherlands
  61. Xwhom I do not personally know. Thanks, Rene.
  62. X
  63. XRene made ST-Curses available as a shareware program. That is, you can use it
  64. Xfor own programs as long as you do not remove the copyright. For commercial use
  65. Xyou are supposed to make a donation of US $5 or equivalent. Please read the
  66. Xheader in CURSES.C for more details. Also note that the copyright remains with
  67. XRene, even though the code has been extensively modified by me.
  68. X
  69. XSome bugs may remain in the code; especially the wgetstr routine looks suspect.
  70. XI used ST-Curses in a version of the game Moria and can assure you that all
  71. Xroutines used by Moria work fine. Modifications to the code have mostly been to
  72. Xuse pointers and more pointers instead of array dereferencing. The net result
  73. Xhas been that the compiled code is some 200 bytes smaller and, depending on the 
  74. Xroutine, 2 through 10 times faster. I also ensured that the routine type (void,
  75. Xinteger etc) was more in line with the original ('real') UNIX curses. For an
  76. Xidea of what I've done, I included the old version of the routine wrefresh()
  77. Xalong with the new code (commented out in CURSES.C).
  78. X
  79. XPlease note that I do not take any responsibility for this code. It may or may
  80. Xnot contain any bugs; it may or may not have been optimized completely. In my
  81. Xown opinion, it works pretty good and quite fast enough for my purposes.
  82. XShould you have any problems with the code or discover any bugs, please contact
  83. Xme - I'll do what I can to help. 
  84. X
  85. XGood luck and greetings from :
  86. X  Hildo Biersma
  87. X  Tollensstraat 138
  88. X  2513 GE Den Haag
  89. X  Holland (Europe).
  90. END_OF_FILE
  91. if test 2869 -ne `wc -c <'atari_st/curscomp/curses.txt'`; then
  92.     echo shar: \"'atari_st/curscomp/curses.txt'\" unpacked with wrong size!
  93. fi
  94. # end of 'atari_st/curscomp/curses.txt'
  95. fi
  96. if test -f 'source/dungeon.c' -a "${1}" != "-c" ; then 
  97.   echo shar: Will not clobber existing file \"'source/dungeon.c'\"
  98. else
  99. echo shar: Extracting \"'source/dungeon.c'\" \(49774 characters\)
  100. sed "s/^X//" >'source/dungeon.c' <<'END_OF_FILE'
  101. X/* source/dungeon.c: the main command interpreter, updating player status
  102. X
  103. X   Copyright (c) 1989-92 James E. Wilson, Robert A. Koeneke
  104. X
  105. X   This software may be copied and distributed for educational, research, and
  106. X   not for profit purposes provided that this copyright and statement are
  107. X   included in all such copies. */
  108. X
  109. X#ifdef __TURBOC__
  110. X#include    <conio.h>
  111. X#include    <stdio.h>
  112. X#include    <stdlib.h>
  113. X#endif /* __TURBOC__ */
  114. X#include "config.h"
  115. X#include "constant.h"
  116. X#include "types.h"
  117. X#include "externs.h"
  118. X
  119. X#ifdef USG
  120. X#ifndef ATARIST_MWC
  121. X#include <string.h>
  122. X#endif
  123. X#else
  124. X#include <strings.h>
  125. X#endif
  126. X
  127. X#if defined(LINT_ARGS)
  128. Xstatic char original_commands(char);
  129. Xstatic void do_command(char);
  130. Xstatic int valid_countcommand(char);
  131. Xstatic void regenhp(int);
  132. Xstatic void regenmana(int);
  133. Xstatic int enchanted(inven_type *);
  134. Xstatic void examine_book(void);
  135. Xstatic void go_up(void);
  136. Xstatic void go_down(void);
  137. Xstatic void jamdoor(void);
  138. Xstatic void refill_lamp(void);
  139. X#else
  140. Xstatic char original_commands();
  141. Xstatic void do_command();
  142. Xstatic int valid_countcommand();
  143. Xstatic void regenhp();
  144. Xstatic void regenmana();
  145. Xstatic int enchanted();
  146. Xstatic void examine_book();
  147. Xstatic void go_up();
  148. Xstatic void go_down();
  149. Xstatic void jamdoor();
  150. Xstatic void refill_lamp();
  151. X#endif
  152. X
  153. X#ifdef ATARIST_TC
  154. X/* Include this to get prototypes for standard library functions.  */
  155. X#include <stdlib.h>
  156. X#endif
  157. X
  158. X/* Moria game module                    -RAK-    */
  159. X/* The code in this section has gone through many revisions, and */
  160. X/* some of it could stand some more hard work.    -RAK-           */
  161. X
  162. X/* It has had a bit more hard work.            -CJS- */
  163. X
  164. Xvoid dungeon()
  165. X{
  166. X  int find_count, i;
  167. X  int regen_amount;        /* Regenerate hp and mana*/
  168. X  char command;        /* Last command         */
  169. X  register struct misc *p_ptr;
  170. X  register inven_type *i_ptr;
  171. X  register struct flags *f_ptr;
  172. X#ifdef ATARIST_WMC
  173. X  int32u holder;
  174. X#endif
  175. X
  176. X  /* Main procedure for dungeon.            -RAK-    */
  177. X  /* Note: There is a lot of preliminary magic going on here at first*/
  178. X
  179. X  /* init pointers. */
  180. X  f_ptr = &py.flags;
  181. X  p_ptr = &py.misc;
  182. X
  183. X  /* Check light status for setup       */
  184. X  i_ptr = &inventory[INVEN_LIGHT];
  185. X  if (i_ptr->p1 > 0)
  186. X    player_light = TRUE;
  187. X  else
  188. X    player_light = FALSE;
  189. X  /* Check for a maximum level           */
  190. X  if (dun_level > p_ptr->max_dlv)
  191. X    p_ptr->max_dlv = dun_level;
  192. X
  193. X  /* Reset flags and initialize variables  */
  194. X  command_count = 0;
  195. X  find_count = 0;
  196. X  new_level_flag    = FALSE;
  197. X  find_flag    = FALSE;
  198. X  teleport_flag = FALSE;
  199. X  mon_tot_mult    = 0;
  200. X  cave[char_row][char_col].cptr = 1;
  201. X  /* Ensure we display the panel. Used to do this with a global var. -CJS- */
  202. X  panel_row = panel_col = -1;
  203. X  /* Light up the area around character       */
  204. X  check_view ();
  205. X  /* must do this after panel_row/col set to -1, because search_off() will
  206. X     call check_view(), and so the panel_* variables must be valid before
  207. X     search_off() is called */
  208. X  if (py.flags.status & PY_SEARCH)
  209. X    search_off();
  210. X  /* Light,  but do not move critters        */
  211. X  creatures(FALSE);
  212. X  /* Print the depth               */
  213. X  prt_depth();
  214. X#if 0
  215. X  /* This can't be right.  */
  216. X#ifdef ATARIST_MWC
  217. X  prt_map();
  218. X#endif
  219. X#endif
  220. X
  221. X  /* Loop until dead,  or new level        */
  222. X  do
  223. X    {
  224. X      /* Increment turn counter            */
  225. X      turn++;
  226. X#ifndef MAC
  227. X      /* The Mac ignores the game hours file        */
  228. X      /* Check for game hours                   */
  229. X      if (((turn % 250) == 1) && !check_time())
  230. X    if (closing_flag > 4)
  231. X      {
  232. X        msg_print("The gates to Moria are now closed.");
  233. X        (void) strcpy (died_from, "(closing gate: saved)");
  234. X        if (!save_char())
  235. X          {
  236. X        (void) strcpy (died_from, "a slammed gate");
  237. X        death = TRUE;
  238. X          }
  239. X        exit_game();
  240. X      }
  241. X    else
  242. X      {
  243. X        disturb (0, 0);
  244. X        closing_flag++;
  245. X        msg_print("The gates to Moria are closing.");
  246. X        msg_print("Please finish up or save your game.");
  247. X      }
  248. X#endif
  249. X
  250. X      /* turn over the store contents every, say, 1000 turns */
  251. X      if ((dun_level != 0) && ((turn % 1000) == 0))
  252. X    store_maint();
  253. X
  254. X      /* Check for creature generation        */
  255. X      if (randint(MAX_MALLOC_CHANCE) == 1)
  256. X    alloc_monster(1, MAX_SIGHT, FALSE);
  257. X      /* Check light status                   */
  258. X      i_ptr = &inventory[INVEN_LIGHT];
  259. X      if (player_light)
  260. X    if (i_ptr->p1 > 0)
  261. X      {
  262. X        i_ptr->p1--;
  263. X        if (i_ptr->p1 == 0)
  264. X          {
  265. X        player_light = FALSE;
  266. X        msg_print("Your light has gone out!");
  267. X        disturb (0, 1);
  268. X        /* unlight creatures */
  269. X        creatures(FALSE);
  270. X          }
  271. X        else if ((i_ptr->p1 < 40) && (randint(5) == 1) &&
  272. X             (py.flags.blind < 1))
  273. X          {
  274. X        disturb (0, 0);
  275. X        msg_print("Your light is growing faint.");
  276. X          }
  277. X      }
  278. X    else
  279. X      {
  280. X        player_light = FALSE;
  281. X        disturb (0, 1);
  282. X        /* unlight creatures */
  283. X        creatures(FALSE);
  284. X      }
  285. X      else if (i_ptr->p1 > 0)
  286. X    {
  287. X      i_ptr->p1--;
  288. X      player_light = TRUE;
  289. X      disturb (0, 1);
  290. X      /* light creatures */
  291. X      creatures(FALSE);
  292. X    }
  293. X
  294. X      /* Update counters and messages            */
  295. X      /* Check food status           */
  296. X      regen_amount = PLAYER_REGEN_NORMAL;
  297. X      if (f_ptr->food < PLAYER_FOOD_ALERT)
  298. X    {
  299. X      if (f_ptr->food < PLAYER_FOOD_WEAK)
  300. X        {
  301. X          if (f_ptr->food < 0)
  302. X        regen_amount = 0;
  303. X          else if (f_ptr->food < PLAYER_FOOD_FAINT)
  304. X        regen_amount = PLAYER_REGEN_FAINT;
  305. X          else if (f_ptr->food < PLAYER_FOOD_WEAK)
  306. X        regen_amount = PLAYER_REGEN_WEAK;
  307. X          if ((PY_WEAK & f_ptr->status) == 0)
  308. X        {
  309. X          f_ptr->status |= PY_WEAK;
  310. X          msg_print("You are getting weak from hunger.");
  311. X          disturb (0, 0);
  312. X          prt_hunger();
  313. X        }
  314. X          if ((f_ptr->food < PLAYER_FOOD_FAINT) && (randint(8) == 1))
  315. X        {
  316. X          f_ptr->paralysis += randint(5);
  317. X          msg_print("You faint from the lack of food.");
  318. X          disturb (1, 0);
  319. X        }
  320. X        }
  321. X      else if ((PY_HUNGRY & f_ptr->status) == 0)
  322. X        {
  323. X          f_ptr->status |= PY_HUNGRY;
  324. X          msg_print("You are getting hungry.");
  325. X          disturb (0, 0);
  326. X          prt_hunger();
  327. X        }
  328. X    }
  329. X      /* Food consumption    */
  330. X      /* Note: Speeded up characters really burn up the food!  */
  331. X      if (f_ptr->speed < 0)
  332. X    f_ptr->food -=    f_ptr->speed*f_ptr->speed;
  333. X      f_ptr->food -= f_ptr->food_digested;
  334. X      if (f_ptr->food < 0)
  335. X    {
  336. X      take_hit (-f_ptr->food/16, "starvation");   /* -CJS- */
  337. X      disturb(1, 0);
  338. X    }
  339. X      /* Regenerate           */
  340. X      if (f_ptr->regenerate)  regen_amount = regen_amount * 3 / 2;
  341. X      if ((py.flags.status & PY_SEARCH) || f_ptr->rest != 0)
  342. X    regen_amount = regen_amount * 2;
  343. X      if ((py.flags.poisoned < 1) && (p_ptr->chp < p_ptr->mhp))
  344. X    regenhp(regen_amount);
  345. X      if (p_ptr->cmana < p_ptr->mana)
  346. X    regenmana(regen_amount);
  347. X      /* Blindness           */
  348. X      if (f_ptr->blind > 0)
  349. X    {
  350. X      if ((PY_BLIND & f_ptr->status) == 0)
  351. X        {
  352. X          f_ptr->status |= PY_BLIND;
  353. X          prt_map();
  354. X          prt_blind();
  355. X          disturb (0, 1);
  356. X          /* unlight creatures */
  357. X          creatures (FALSE);
  358. X        }
  359. X      f_ptr->blind--;
  360. X      if (f_ptr->blind == 0)
  361. X        {
  362. X#ifdef ATARIST_MWC
  363. X          f_ptr->status &= ~(holder = PY_BLIND);
  364. X#else
  365. X          f_ptr->status &= ~PY_BLIND;
  366. X#endif
  367. X          prt_blind();
  368. X          prt_map();
  369. X          /* light creatures */
  370. X          disturb (0, 1);
  371. X          creatures(FALSE);
  372. X          msg_print("The veil of darkness lifts.");
  373. X        }
  374. X    }
  375. X      /* Confusion           */
  376. X      if (f_ptr->confused > 0)
  377. X    {
  378. X      if ((PY_CONFUSED & f_ptr->status) == 0)
  379. X        {
  380. X          f_ptr->status |= PY_CONFUSED;
  381. X          prt_confused();
  382. X        }
  383. X      f_ptr->confused--;
  384. X      if (f_ptr->confused == 0)
  385. X        {
  386. X#ifdef ATARIST_MWC
  387. X          f_ptr->status &= ~(holder = PY_CONFUSED);
  388. X#else
  389. X          f_ptr->status &= ~PY_CONFUSED;
  390. X#endif
  391. X          prt_confused();
  392. X          msg_print("You feel less confused now.");
  393. X          if (py.flags.rest != 0)
  394. X        rest_off ();
  395. X        }
  396. X    }
  397. X      /* Afraid               */
  398. X      if (f_ptr->afraid > 0)
  399. X    {
  400. X      if ((PY_FEAR & f_ptr->status) == 0)
  401. X        {
  402. X          if ((f_ptr->shero+f_ptr->hero) > 0)
  403. X        f_ptr->afraid = 0;
  404. X          else
  405. X        {
  406. X          f_ptr->status |= PY_FEAR;
  407. X          prt_afraid();
  408. X        }
  409. X        }
  410. X      else if ((f_ptr->shero+f_ptr->hero) > 0)
  411. X        f_ptr->afraid = 1;
  412. X      f_ptr->afraid--;
  413. X      if (f_ptr->afraid == 0)
  414. X        {
  415. X#ifdef ATARIST_MWC
  416. X          f_ptr->status &= ~(holder = PY_FEAR);
  417. X#else
  418. X          f_ptr->status &= ~PY_FEAR;
  419. X#endif
  420. X          prt_afraid();
  421. X          msg_print("You feel bolder now.");
  422. X          disturb (0, 0);
  423. X        }
  424. X    }
  425. X      /* Poisoned           */
  426. X      if (f_ptr->poisoned > 0)
  427. X    {
  428. X      if ((PY_POISONED & f_ptr->status) == 0)
  429. X        {
  430. X          f_ptr->status |= PY_POISONED;
  431. X          prt_poisoned();
  432. X        }
  433. X      f_ptr->poisoned--;
  434. X      if (f_ptr->poisoned == 0)
  435. X        {
  436. X#ifdef ATARIST_MWC
  437. X          f_ptr->status &= ~(holder = PY_POISONED);
  438. X#else
  439. X          f_ptr->status &= ~PY_POISONED;
  440. X#endif
  441. X          prt_poisoned();
  442. X          msg_print("You feel better.");
  443. X          disturb (0, 0);
  444. X        }
  445. X      else
  446. X        {
  447. X          switch(con_adj())
  448. X        {
  449. X        case -4:  i = 4;  break;
  450. X        case -3:
  451. X        case -2:  i = 3;  break;
  452. X        case -1:  i = 2;  break;
  453. X        case 0:      i = 1;  break;
  454. X        case 1: case 2: case 3:
  455. X          i = ((turn % 2) == 0);
  456. X          break;
  457. X        case 4: case 5:
  458. X          i = ((turn % 3) == 0);
  459. X          break;
  460. X        case 6:
  461. X          i = ((turn % 4) == 0);
  462. X          break;
  463. X        }
  464. X          take_hit (i, "poison");
  465. X          disturb (1, 0);
  466. X        }
  467. X    }
  468. X      /* Fast               */
  469. X      if (f_ptr->fast > 0)
  470. X    {
  471. X      if ((PY_FAST & f_ptr->status) == 0)
  472. X        {
  473. X          f_ptr->status |= PY_FAST;
  474. X          change_speed(-1);
  475. X          msg_print("You feel yourself moving faster.");
  476. X          disturb (0, 0);
  477. X        }
  478. X      f_ptr->fast--;
  479. X      if (f_ptr->fast == 0)
  480. X        {
  481. X#ifdef ATARIST_MWC
  482. X          f_ptr->status &= ~(holder = PY_FAST);
  483. X#else
  484. X          f_ptr->status &= ~PY_FAST;
  485. X#endif
  486. X          change_speed(1);
  487. X          msg_print("You feel yourself slow down.");
  488. X          disturb (0, 0);
  489. X        }
  490. X    }
  491. X      /* Slow               */
  492. X      if (f_ptr->slow > 0)
  493. X    {
  494. X      if ((PY_SLOW & f_ptr->status) == 0)
  495. X        {
  496. X          f_ptr->status |= PY_SLOW;
  497. X          change_speed(1);
  498. X          msg_print("You feel yourself moving slower.");
  499. X          disturb (0, 0);
  500. X        }
  501. X      f_ptr->slow--;
  502. X      if (f_ptr->slow == 0)
  503. X        {
  504. X#ifdef ATARIST_MWC
  505. X          f_ptr->status &= ~(holder = PY_SLOW);
  506. X#else
  507. X          f_ptr->status &= ~PY_SLOW;
  508. X#endif
  509. X          change_speed(-1);
  510. X          msg_print("You feel yourself speed up.");
  511. X          disturb (0, 0);
  512. X        }
  513. X    }
  514. X      /* Resting is over?      */
  515. X      if (f_ptr->rest > 0)
  516. X    {
  517. X      f_ptr->rest--;
  518. X      if (f_ptr->rest == 0)              /* Resting over           */
  519. X        rest_off();
  520. X    }
  521. X      else if (f_ptr->rest < 0)
  522. X    {
  523. X      /* Rest until reach max mana and max hit points.  */
  524. X      f_ptr->rest++;
  525. X      if ((p_ptr->chp == p_ptr->mhp && p_ptr->cmana == p_ptr->mana)
  526. X          || f_ptr->rest == 0)
  527. X        rest_off();
  528. X    }
  529. X
  530. X      /* Check for interrupts to find or rest. */
  531. X#ifdef MAC
  532. X      /* On Mac, checking for input is expensive, since it involves handling
  533. X     events, so we only check in multiples of 16 turns. */
  534. X      if (!(turn & 0xF) && ((command_count > 0) || find_flag
  535. X                 || (f_ptr->rest != 0)))
  536. X    if (macgetkey(CNIL, TRUE))
  537. X      disturb(0, 0);
  538. X#else
  539. X      if ((command_count > 0 || find_flag || f_ptr->rest != 0)
  540. X#if defined(MSDOS) || defined(VMS)
  541. X      && kbhit()
  542. X#else
  543. X      && (check_input (find_flag ? 0 : 10000))
  544. X#endif
  545. X      )
  546. X    {
  547. X#ifdef MSDOS
  548. X      (void) msdos_getch();
  549. X#endif
  550. X#ifdef VMS
  551. X      /* Get and ignore the key used to interrupt resting/running.  */
  552. X      (void) vms_getch ();
  553. X#endif
  554. X      disturb (0, 0);
  555. X    }
  556. X#endif
  557. X
  558. X      /* Hallucinating?     (Random characters appear!)*/
  559. X      if (f_ptr->image > 0)
  560. X    {
  561. X      end_find ();
  562. X      f_ptr->image--;
  563. X      if (f_ptr->image == 0)
  564. X        prt_map ();     /* Used to draw entire screen! -CJS- */
  565. X    }
  566. X      /* Paralysis           */
  567. X      if (f_ptr->paralysis > 0)
  568. X    {
  569. X      /* when paralysis true, you can not see any movement that occurs */
  570. X      f_ptr->paralysis--;
  571. X      disturb (1, 0);
  572. X    }
  573. X      /* Protection from evil counter*/
  574. X      if (f_ptr->protevil > 0)
  575. X    {
  576. X      f_ptr->protevil--;
  577. X      if (f_ptr->protevil == 0)
  578. X        msg_print ("You no longer feel safe from evil.");
  579. X    }
  580. X      /* Invulnerability    */
  581. X      if (f_ptr->invuln > 0)
  582. X    {
  583. X      if ((PY_INVULN & f_ptr->status) == 0)
  584. X        {
  585. X          f_ptr->status |= PY_INVULN;
  586. X          disturb (0, 0);
  587. X          py.misc.pac += 100;
  588. X          py.misc.dis_ac += 100;
  589. X          prt_pac();
  590. X          msg_print("Your skin turns into steel!");
  591. X        }
  592. X      f_ptr->invuln--;
  593. X      if (f_ptr->invuln == 0)
  594. X        {
  595. X#ifdef ATARIST_MWC
  596. X          f_ptr->status &= ~(holder = PY_INVULN);
  597. X#else
  598. X          f_ptr->status &= ~PY_INVULN;
  599. X#endif
  600. X          disturb (0, 0);
  601. X          py.misc.pac -= 100;
  602. X          py.misc.dis_ac -= 100;
  603. X          prt_pac();
  604. X          msg_print("Your skin returns to normal.");
  605. X        }
  606. X    }
  607. X      /* Heroism       */
  608. X      if (f_ptr->hero > 0)
  609. X    {
  610. X      if ((PY_HERO & f_ptr->status) == 0)
  611. X        {
  612. X          f_ptr->status |= PY_HERO;
  613. X          disturb (0, 0);
  614. X          p_ptr->mhp += 10;
  615. X          p_ptr->chp += 10;
  616. X          p_ptr->bth += 12;
  617. X          p_ptr->bthb+= 12;
  618. X          msg_print("You feel like a HERO!");
  619. X          prt_mhp();
  620. X          prt_chp();
  621. X        }
  622. X      f_ptr->hero--;
  623. X      if (f_ptr->hero == 0)
  624. X        {
  625. X#ifdef ATARIST_MWC
  626. X          f_ptr->status &= ~(holder = PY_HERO);
  627. X#else
  628. X          f_ptr->status &= ~PY_HERO;
  629. X#endif
  630. X          disturb (0, 0);
  631. X          p_ptr->mhp -= 10;
  632. X          if (p_ptr->chp > p_ptr->mhp)
  633. X        {
  634. X          p_ptr->chp = p_ptr->mhp;
  635. X          p_ptr->chp_frac = 0;
  636. X          prt_chp();
  637. X        }
  638. X          p_ptr->bth -= 12;
  639. X          p_ptr->bthb-= 12;
  640. X          msg_print("The heroism wears off.");
  641. X          prt_mhp();
  642. X        }
  643. X    }
  644. X      /* Super Heroism */
  645. X      if (f_ptr->shero > 0)
  646. X    {
  647. X      if ((PY_SHERO & f_ptr->status) == 0)
  648. X        {
  649. X          f_ptr->status |= PY_SHERO;
  650. X          disturb (0, 0);
  651. X          p_ptr->mhp += 20;
  652. X          p_ptr->chp += 20;
  653. X          p_ptr->bth += 24;
  654. X          p_ptr->bthb+= 24;
  655. X          msg_print("You feel like a SUPER HERO!");
  656. X          prt_mhp();
  657. X          prt_chp();
  658. X        }
  659. X      f_ptr->shero--;
  660. X      if (f_ptr->shero == 0)
  661. X        {
  662. X#ifdef ATARIST_MWC
  663. X          f_ptr->status &= ~(holder = PY_SHERO);
  664. X#else
  665. X          f_ptr->status &= ~PY_SHERO;
  666. X#endif
  667. X          disturb (0, 0);
  668. X          p_ptr->mhp -= 20;
  669. X          if (p_ptr->chp > p_ptr->mhp)
  670. X        {
  671. X          p_ptr->chp = p_ptr->mhp;
  672. X          p_ptr->chp_frac = 0;
  673. X          prt_chp();
  674. X        }
  675. X          p_ptr->bth -= 24;
  676. X          p_ptr->bthb-= 24;
  677. X          msg_print("The super heroism wears off.");
  678. X          prt_mhp();
  679. X        }
  680. X    }
  681. X      /* Blessed       */
  682. X      if (f_ptr->blessed > 0)
  683. X    {
  684. X      if ((PY_BLESSED & f_ptr->status) == 0)
  685. X        {
  686. X          f_ptr->status |= PY_BLESSED;
  687. X          disturb (0, 0);
  688. X          p_ptr->bth += 5;
  689. X          p_ptr->bthb+= 5;
  690. X          p_ptr->pac += 2;
  691. X          p_ptr->dis_ac+= 2;
  692. X          msg_print("You feel righteous!");
  693. X          prt_pac();
  694. X        }
  695. X      f_ptr->blessed--;
  696. X      if (f_ptr->blessed == 0)
  697. X        {
  698. X#ifdef ATARIST_MWC
  699. X          f_ptr->status &= ~(holder = PY_BLESSED);
  700. X#else
  701. X          f_ptr->status &= ~PY_BLESSED;
  702. X#endif
  703. X          disturb (0, 0);
  704. X          p_ptr->bth -= 5;
  705. X          p_ptr->bthb-= 5;
  706. X          p_ptr->pac -= 2;
  707. X          p_ptr->dis_ac -= 2;
  708. X          msg_print("The prayer has expired.");
  709. X          prt_pac();
  710. X        }
  711. X    }
  712. X      /* Resist Heat   */
  713. X      if (f_ptr->resist_heat > 0)
  714. X    {
  715. X      f_ptr->resist_heat--;
  716. X      if (f_ptr->resist_heat == 0)
  717. X        msg_print ("You no longer feel safe from flame.");
  718. X    }
  719. X      /* Resist Cold   */
  720. X      if (f_ptr->resist_cold > 0)
  721. X    {
  722. X      f_ptr->resist_cold--;
  723. X      if (f_ptr->resist_cold == 0)
  724. X        msg_print ("You no longer feel safe from cold.");
  725. X    }
  726. X      /* Detect Invisible      */
  727. X      if (f_ptr->detect_inv > 0)
  728. X    {
  729. X#ifdef ATARIST_MWC
  730. X      if (((holder = PY_DET_INV) & f_ptr->status) == 0)
  731. X#else
  732. X      if ((PY_DET_INV & f_ptr->status) == 0)
  733. X#endif
  734. X        {
  735. X#ifdef ATARIST_MWC
  736. X          f_ptr->status |= holder;
  737. X#else
  738. X          f_ptr->status |= PY_DET_INV;
  739. X#endif
  740. X          f_ptr->see_inv = TRUE;
  741. X          /* light but don't move creatures */
  742. X          creatures (FALSE);
  743. X        }
  744. X      f_ptr->detect_inv--;
  745. X      if (f_ptr->detect_inv == 0)
  746. X        {
  747. X#ifdef ATARIST_MWC
  748. X          f_ptr->status &= ~holder;
  749. X#else
  750. X          f_ptr->status &= ~PY_DET_INV;
  751. X#endif
  752. X          /* may still be able to see_inv if wearing magic item */
  753. X          calc_bonuses();
  754. X          /* unlight but don't move creatures */
  755. X          creatures (FALSE);
  756. X        }
  757. X    }
  758. X      /* Timed infra-vision    */
  759. X      if (f_ptr->tim_infra > 0)
  760. X    {
  761. X#ifdef ATARIST_MWC
  762. X      if (((holder = PY_TIM_INFRA) & f_ptr->status) == 0)
  763. X#else
  764. X      if ((PY_TIM_INFRA & f_ptr->status) == 0)
  765. X#endif
  766. X        {
  767. X#ifdef ATARIST_MWC
  768. X          f_ptr->status |= holder;
  769. X#else
  770. X          f_ptr->status |= PY_TIM_INFRA;
  771. X#endif
  772. X          f_ptr->see_infra++;
  773. X          /* light but don't move creatures */
  774. X          creatures (FALSE);
  775. X        }
  776. X      f_ptr->tim_infra--;
  777. X      if (f_ptr->tim_infra == 0)
  778. X        {
  779. X#ifdef ATARIST_MWC
  780. X          f_ptr->status &= ~holder;
  781. X#else
  782. X          f_ptr->status &= ~PY_TIM_INFRA;
  783. X#endif
  784. X          f_ptr->see_infra--;
  785. X          /* unlight but don't move creatures */
  786. X          creatures (FALSE);
  787. X        }
  788. X    }
  789. X    /* Word-of-Recall  Note: Word-of-Recall is a delayed action     */
  790. X      if (f_ptr->word_recall > 0)
  791. X    if (f_ptr->word_recall == 1)
  792. X      {
  793. X        new_level_flag = TRUE;
  794. X        f_ptr->paralysis++;
  795. X        f_ptr->word_recall = 0;
  796. X        if (dun_level > 0)
  797. X          {
  798. X        dun_level = 0;
  799. X        msg_print("You feel yourself yanked upwards!");
  800. X          }
  801. X        else if (py.misc.max_dlv != 0)
  802. X          {
  803. X        dun_level = py.misc.max_dlv;
  804. X        msg_print("You feel yourself yanked downwards!");
  805. X          }
  806. X      }
  807. X    else
  808. X      f_ptr->word_recall--;
  809. X
  810. X      /* Random teleportation  */
  811. X      if ((py.flags.teleport) && (randint(100) == 1))
  812. X    {
  813. X      disturb (0, 0);
  814. X      teleport(40);
  815. X    }
  816. X
  817. X      /* See if we are too weak to handle the weapon or pack.  -CJS- */
  818. X#ifdef ATARIST_MWC
  819. X      if (py.flags.status & (holder = PY_STR_WGT))
  820. X#else
  821. X      if (py.flags.status & PY_STR_WGT)
  822. X#endif
  823. X    check_strength();
  824. X      if (py.flags.status & PY_STUDY)
  825. X    prt_study();
  826. X#ifdef ATARIST_MWC
  827. X      if (py.flags.status & (holder = PY_SPEED))
  828. X#else
  829. X      if (py.flags.status & PY_SPEED)
  830. X#endif
  831. X    {
  832. X#ifdef ATARIST_MWC
  833. X      py.flags.status &= ~holder;
  834. X#else
  835. X      py.flags.status &= ~PY_SPEED;
  836. X#endif
  837. X      prt_speed();
  838. X    }
  839. X#ifdef ATARIST_MWC
  840. X      if ((py.flags.status & (holder = PY_PARALYSED))
  841. X      && (py.flags.paralysis < 1))
  842. X#else
  843. X      if ((py.flags.status & PY_PARALYSED) && (py.flags.paralysis < 1))
  844. X#endif
  845. X    {
  846. X      prt_state();
  847. X#ifdef ATARIST_MWC
  848. X      py.flags.status &= ~holder;
  849. X#else
  850. X      py.flags.status &= ~PY_PARALYSED;
  851. X#endif
  852. X    }
  853. X      else if (py.flags.paralysis > 0)
  854. X    {
  855. X      prt_state();
  856. X#ifdef ATARIST_MWC
  857. X      py.flags.status |= (holder = PY_PARALYSED);
  858. X#else
  859. X      py.flags.status |= PY_PARALYSED;
  860. X#endif
  861. X    }
  862. X      else if (py.flags.rest != 0)
  863. X    prt_state();
  864. X
  865. X#ifdef ATARIST_MWC
  866. X      if ((py.flags.status & (holder = PY_ARMOR)) != 0)
  867. X#else
  868. X      if ((py.flags.status & PY_ARMOR) != 0)
  869. X#endif
  870. X    {
  871. X      prt_pac();
  872. X#ifdef ATARIST_MWC
  873. X      py.flags.status &= ~holder;
  874. X#else
  875. X      py.flags.status &= ~PY_ARMOR;
  876. X#endif
  877. X    }
  878. X#ifdef ATARIST_MWC
  879. X      if ((py.flags.status & (holder = PY_STATS)) != 0)
  880. X#else
  881. X      if ((py.flags.status & PY_STATS) != 0)
  882. X#endif
  883. X    {
  884. X      for (i = 0; i < 6; i++)
  885. X#ifdef ATARIST_MWC
  886. X        if (((holder = PY_STR) << i) & py.flags.status)
  887. X#else
  888. X        if ((PY_STR << i) & py.flags.status)
  889. X#endif
  890. X          prt_stat(i);
  891. X#ifdef ATARIST_MWC
  892. X      py.flags.status &= ~(holder = PY_STATS);
  893. X#else
  894. X      py.flags.status &= ~PY_STATS;
  895. X#endif
  896. X    }
  897. X#ifdef ATARIST_MWC
  898. X      if (py.flags.status & (holder = PY_HP))
  899. X#else
  900. X      if (py.flags.status & PY_HP)
  901. X#endif
  902. X    {
  903. X      prt_mhp();
  904. X      prt_chp();
  905. X#ifdef ATARIST_MWC
  906. X      py.flags.status &= ~holder;
  907. X#else
  908. X      py.flags.status &= ~PY_HP;
  909. X#endif
  910. X    }
  911. X#ifdef ATARIST_MWC
  912. X      if (py.flags.status & (holder = PY_MANA))
  913. X#else
  914. X      if (py.flags.status & PY_MANA)
  915. X#endif
  916. X    {
  917. X      prt_cmana();
  918. X#ifdef ATARIST_MWC
  919. X      py.flags.status &= ~holder;
  920. X#else
  921. X      py.flags.status &= ~PY_MANA;
  922. X#endif
  923. X    }
  924. X
  925. X      /* Allow for a slim chance of detect enchantment -CJS- */
  926. X      /* for 1st level char, check once every 2160 turns
  927. X     for 40th level char, check once every 416 turns */
  928. X      if (((turn & 0xF) == 0) && (f_ptr->confused == 0)
  929. X      && (randint((int)(10 + 750 / (5 + py.misc.lev))) == 1))
  930. X    {
  931. X      vtype tmp_str;
  932. X
  933. X      for (i = 0; i < INVEN_ARRAY_SIZE; i++)
  934. X        {
  935. X          if (i == inven_ctr)
  936. X        i = 22;
  937. X          i_ptr = &inventory[i];
  938. X          /* if in inventory, succeed 1 out of 50 times,
  939. X         if in equipment list, success 1 out of 10 times */
  940. X          if ((i_ptr->tval != TV_NOTHING) && enchanted(i_ptr) &&
  941. X          (randint(i < 22 ? 50 : 10) == 1))
  942. X        {
  943. X          extern char *describe_use();
  944. X
  945. X          (void) sprintf(tmp_str,
  946. X                 "There's something about what you are %s...",
  947. X                 describe_use(i));
  948. X          disturb(0, 0);
  949. X          msg_print(tmp_str);
  950. X          add_inscribe(i_ptr, ID_MAGIK);
  951. X        }
  952. X        }
  953. X    }
  954. X
  955. X      /* Check the state of the monster list, and delete some monsters if
  956. X     the monster list is nearly full.  This helps to avoid problems in
  957. X     creature.c when monsters try to multiply.  Compact_monsters() is
  958. X     much more likely to succeed if called from here, than if called
  959. X     from within creatures().  */
  960. X      if (MAX_MALLOC - mfptr < 10)
  961. X    (void) compact_monsters ();
  962. X
  963. X      if ((py.flags.paralysis < 1) &&         /* Accept a command?     */
  964. X      (py.flags.rest == 0) &&
  965. X      (!death))
  966. X    /* Accept a command and execute it                 */
  967. X    {
  968. X      do
  969. X        {
  970. X#ifdef ATARIST_MWC
  971. X          if (py.flags.status & (holder = PY_REPEAT))
  972. X#else
  973. X          if (py.flags.status & PY_REPEAT)
  974. X#endif
  975. X        prt_state ();
  976. X          default_dir = FALSE;
  977. X          free_turn_flag = FALSE;
  978. X
  979. X          if (find_flag)
  980. X        {
  981. X          find_run();
  982. X          find_count--;
  983. X          if (find_count == 0)
  984. X            end_find();
  985. X          put_qio();
  986. X        }
  987. X          else if (doing_inven)
  988. X        inven_command (doing_inven);
  989. X          else
  990. X        {
  991. X          /* move the cursor to the players character */
  992. X          move_cursor_relative (char_row, char_col);
  993. X          if (command_count > 0)
  994. X            {
  995. X              msg_flag = FALSE;
  996. X              default_dir = TRUE;
  997. X            }
  998. X          else
  999. X            {
  1000. X              msg_flag = FALSE;
  1001. X#ifdef MAC
  1002. X              unloadsegments();
  1003. X              enablesavecmd(TRUE);
  1004. X              command = inkeydir();
  1005. X              enablesavecmd(FALSE);
  1006. X#else
  1007. X              command = inkey();
  1008. X#endif
  1009. X              i = 0;
  1010. X              /* Get a count for a command. */
  1011. X              if ((rogue_like_commands
  1012. X               && command >= '0' && command <= '9')
  1013. X              || (!rogue_like_commands && command == '#'))
  1014. X            {
  1015. X              char tmp[8];
  1016. X
  1017. X              prt("Repeat count:", 0, 0);
  1018. X              if (command == '#')
  1019. X                command = '0';
  1020. X              i = 0;
  1021. X              while (TRUE)
  1022. X                {
  1023. X                  if (command == DELETE || command == CTRL('H'))
  1024. X                {
  1025. X                  i = i / 10;
  1026. X                  (void) sprintf(tmp, "%d", i);
  1027. X                  prt (tmp, 0, 14);
  1028. X                }
  1029. X                  else if (command >= '0' && command <= '9')
  1030. X                {
  1031. X                      if (i > 99)
  1032. X                    bell ();
  1033. X                  else
  1034. X                    {
  1035. X                      i = i * 10 + command - '0';
  1036. X                      (void) sprintf (tmp, "%d", i);
  1037. X                      prt (tmp, 0, 14);
  1038. X                    }
  1039. X                }
  1040. X                  else
  1041. X                break;
  1042. X#ifdef MAC
  1043. X                  command = inkeydir();
  1044. X#else
  1045. X                  command = inkey();
  1046. X#endif
  1047. X                }
  1048. X              if (i == 0)
  1049. X                {
  1050. X                  i = 99;
  1051. X                  (void) sprintf (tmp, "%d", i);
  1052. X                  prt (tmp, 0, 14);
  1053. X                }
  1054. X              /* a special hack to allow numbers as commands */
  1055. X              if (command == ' ')
  1056. X                {
  1057. X                  prt ("Command:", 0, 20);
  1058. X#ifdef MAC
  1059. X                  command = inkeydir();
  1060. X#else
  1061. X                  command = inkey();
  1062. X#endif
  1063. X                }
  1064. X            }
  1065. X              /* Another way of typing control codes -CJS- */
  1066. X              if (command == '^')
  1067. X            {
  1068. X              if (command_count > 0)
  1069. X                prt_state();
  1070. X              if (get_com("Control-", &command))
  1071. X                {
  1072. X                  if (command >= 'A' && command <= 'Z')
  1073. X                command -= 'A' - 1;
  1074. X                  else if (command >= 'a' && command <= 'z')
  1075. X                command -= 'a' - 1;
  1076. X                  else
  1077. X                {
  1078. X                   msg_print("Type ^ <letter> for a control char");
  1079. X                  command = ' ';
  1080. X                }
  1081. X                }
  1082. X              else
  1083. X                command = ' ';
  1084. X            }
  1085. X              /* move cursor to player char again, in case it moved */
  1086. X              move_cursor_relative (char_row, char_col);
  1087. X              /* Commands are always converted to rogue form. -CJS- */
  1088. X              if (rogue_like_commands == FALSE)
  1089. X            command = original_commands (command);
  1090. X              if (i > 0)
  1091. X            {
  1092. X              if (!valid_countcommand(command))
  1093. X                {
  1094. X                  free_turn_flag = TRUE;
  1095. X                  msg_print ("Invalid command with a count.");
  1096. X                  command = ' ';
  1097. X                }
  1098. X              else
  1099. X                {
  1100. X                  command_count = i;
  1101. X                  prt_state ();
  1102. X                }
  1103. X            }
  1104. X            }
  1105. X          /* Flash the message line. */
  1106. X          erase_line(MSG_LINE, 0);
  1107. X          move_cursor_relative(char_row, char_col);
  1108. X          put_qio();
  1109. X
  1110. X          do_command (command);
  1111. X          /* Find is counted differently, as the command changes. */
  1112. X          if (find_flag)
  1113. X            {
  1114. X              find_count = command_count - 1;
  1115. X              command_count = 0;
  1116. X            }
  1117. X          else if (free_turn_flag)
  1118. X            command_count = 0;
  1119. X          else if (command_count)
  1120. X            command_count--;
  1121. X        }
  1122. X          /* End of commands                     */
  1123. X        }
  1124. X      while (free_turn_flag && !new_level_flag && !eof_flag);
  1125. X    }
  1126. X      else
  1127. X    {
  1128. X      /* if paralyzed, resting, or dead, flush output */
  1129. X      /* but first move the cursor onto the player, for aesthetics */
  1130. X      move_cursor_relative (char_row, char_col);
  1131. X      put_qio ();
  1132. X    }
  1133. X
  1134. X      /* Teleport?               */
  1135. X      if (teleport_flag)  teleport(100);
  1136. X      /* Move the creatures           */
  1137. X      if (!new_level_flag)  creatures(TRUE);
  1138. X      /* Exit when new_level_flag is set   */
  1139. X    }
  1140. X  while (!new_level_flag && !eof_flag);
  1141. X}
  1142. X
  1143. X
  1144. Xstatic char original_commands(com_val)
  1145. Xchar com_val;
  1146. X{
  1147. X  int dir_val;
  1148. X
  1149. X  switch(com_val)
  1150. X    {
  1151. X    case CTRL('K'):    /*^K = exit    */
  1152. X      com_val = 'Q';
  1153. X      break;
  1154. X    case CTRL('J'):
  1155. X    case CTRL('M'):
  1156. X      com_val = '+';
  1157. X      break;
  1158. X    case CTRL('P'):    /*^P = repeat  */
  1159. X    case CTRL('W'):    /*^W = password*/
  1160. X    case CTRL('X'):    /*^X = save    */
  1161. X    case ' ':
  1162. X    case '!':
  1163. X    case '$':
  1164. X      break;
  1165. X    case '.':
  1166. X      if (get_dir(CNIL, &dir_val))
  1167. X    switch (dir_val)
  1168. X      {
  1169. X      case 1:    com_val = 'B';    break;
  1170. X      case 2:    com_val = 'J';    break;
  1171. X      case 3:    com_val = 'N';    break;
  1172. X      case 4:    com_val = 'H';    break;
  1173. X      case 6:    com_val = 'L';    break;
  1174. X      case 7:    com_val = 'Y';    break;
  1175. X      case 8:    com_val = 'K';    break;
  1176. X      case 9:    com_val = 'U';    break;
  1177. X      default:   com_val = ' ';    break;
  1178. X      }
  1179. X      else
  1180. X    com_val = ' ';
  1181. X      break;
  1182. X    case '/':
  1183. X    case '<':
  1184. X    case '>':
  1185. X    case '-':
  1186. X    case '=':
  1187. X    case '{':
  1188. X    case '?':
  1189. X    case 'A':
  1190. X      break;
  1191. X    case '1':
  1192. X      com_val = 'b';
  1193. X      break;
  1194. X    case '2':
  1195. X      com_val = 'j';
  1196. X      break;
  1197. X    case '3':
  1198. X      com_val = 'n';
  1199. X      break;
  1200. X    case '4':
  1201. X      com_val = 'h';
  1202. X      break;
  1203. X    case '5':    /* Rest one turn */
  1204. X      com_val = '.';
  1205. X      break;
  1206. X    case '6':
  1207. X      com_val = 'l';
  1208. X      break;
  1209. X    case '7':
  1210. X      com_val = 'y';
  1211. X      break;
  1212. X    case '8':
  1213. X      com_val = 'k';
  1214. X      break;
  1215. X    case '9':
  1216. X      com_val = 'u';
  1217. X      break;
  1218. X    case 'B':
  1219. X      com_val = 'f';
  1220. X      break;
  1221. X    case 'C':
  1222. X    case 'D':
  1223. X    case 'E':
  1224. X    case 'F':
  1225. X    case 'G':
  1226. X      break;
  1227. X    case 'L':
  1228. X      com_val = 'W';
  1229. X      break;
  1230. X    case 'M':
  1231. X      break;
  1232. X    case 'R':
  1233. X      break;
  1234. X    case 'S':
  1235. X      com_val = '#';
  1236. X      break;
  1237. X    case 'T':
  1238. X      if (get_dir(CNIL, &dir_val))
  1239. X    switch (dir_val)
  1240. X      {
  1241. X      case 1:    com_val = CTRL('B');    break;
  1242. X      case 2:    com_val = CTRL('J');    break;
  1243. X      case 3:    com_val = CTRL('N');    break;
  1244. X      case 4:    com_val = CTRL('H');    break;
  1245. X      case 6:    com_val = CTRL('L');    break;
  1246. X      case 7:    com_val = CTRL('Y');    break;
  1247. X      case 8:    com_val = CTRL('K');    break;
  1248. X      case 9:    com_val = CTRL('U');    break;
  1249. X      default:   com_val = ' ';         break;
  1250. X      }
  1251. X      else
  1252. X    com_val = ' ';
  1253. X      break;
  1254. X    case 'V':
  1255. X      break;
  1256. X    case 'a':
  1257. X      com_val = 'z';
  1258. X      break;
  1259. X    case 'b':
  1260. X      com_val = 'P';
  1261. X      break;
  1262. X    case 'c':
  1263. X    case 'd':
  1264. X    case 'e':
  1265. X      break;
  1266. X    case 'f':
  1267. X      com_val = 't';
  1268. X      break;
  1269. X    case 'h':
  1270. X      com_val = '?';
  1271. X      break;
  1272. X    case 'i':
  1273. X      break;
  1274. X    case 'j':
  1275. X      com_val = 'S';
  1276. X      break;
  1277. X    case 'l':
  1278. X      com_val = 'x';
  1279. X      break;
  1280. X    case 'm':
  1281. X    case 'o':
  1282. X    case 'p':
  1283. X    case 'q':
  1284. X    case 'r':
  1285. X    case 's':
  1286. X      break;
  1287. X    case 't':
  1288. X      com_val = 'T';
  1289. X      break;
  1290. X    case 'u':
  1291. X      com_val = 'Z';
  1292. X      break;
  1293. X    case 'v':
  1294. X    case 'w':
  1295. X      break;
  1296. X    case 'x':
  1297. X      com_val = 'X';
  1298. X      break;
  1299. X
  1300. X      /* wizard mode commands follow */
  1301. X    case CTRL('A'): /*^A = cure all */
  1302. X      break;
  1303. X    case CTRL('B'):    /*^B = objects */
  1304. X      com_val = CTRL('O');
  1305. X      break;
  1306. X    case CTRL('D'):    /*^D = up/down */
  1307. X      break;
  1308. X    case CTRL('H'):    /*^H = wizhelp */
  1309. X      com_val = '\\';
  1310. X      break;
  1311. X    case CTRL('I'):    /*^I = identify*/
  1312. X      break;
  1313. X    case CTRL('L'):    /*^L = wizlight*/
  1314. X      com_val = '*';
  1315. X      break;
  1316. X    case ':':
  1317. X    case CTRL('T'):    /*^T = teleport*/
  1318. X    case CTRL('E'):    /*^E = wizchar */
  1319. X    case CTRL('F'):    /*^F = genocide*/
  1320. X    case CTRL('G'):    /*^G = treasure*/
  1321. X    case '@':
  1322. X    case '+':
  1323. X      break;
  1324. X    case CTRL('U'):    /*^U = summon  */
  1325. X      com_val = '&';
  1326. X      break;
  1327. X    default:
  1328. X      com_val = '~';  /* Anything illegal. */
  1329. X      break;
  1330. X    }
  1331. X  return com_val;
  1332. X}
  1333. X
  1334. X
  1335. Xstatic void do_command(com_val)
  1336. Xchar com_val;
  1337. X{
  1338. X  int dir_val, do_pickup;
  1339. X  int y, x, i, j;
  1340. X  vtype out_val, tmp_str;
  1341. X  register struct flags *f_ptr;
  1342. X
  1343. X  /* hack for move without pickup.  Map '-' to a movement command. */
  1344. X  if (com_val == '-')
  1345. X    {
  1346. X      do_pickup = FALSE;
  1347. X      i = command_count;
  1348. X      if (get_dir(CNIL, &dir_val))
  1349. X    {
  1350. X      command_count = i;
  1351. X      switch (dir_val)
  1352. X        {
  1353. X        case 1:    com_val = 'b';     break;
  1354. X        case 2:    com_val = 'j';     break;
  1355. X        case 3:    com_val = 'n';     break;
  1356. X        case 4:    com_val = 'h';     break;
  1357. X        case 6:    com_val = 'l';     break;
  1358. X        case 7:    com_val = 'y';     break;
  1359. X        case 8:    com_val = 'k';     break;
  1360. X        case 9:    com_val = 'u';     break;
  1361. X        default:   com_val = '~';     break;
  1362. X        }
  1363. X    }
  1364. X      else
  1365. X    com_val = ' ';
  1366. X    }
  1367. X  else
  1368. X    do_pickup = TRUE;
  1369. X
  1370. X  switch(com_val)
  1371. X    {
  1372. X    case 'Q':    /* (Q)uit        (^K)ill */
  1373. X      flush();
  1374. X      if (get_check("Do you really want to quit?"))
  1375. X    {
  1376. X      new_level_flag = TRUE;
  1377. X      death = TRUE;
  1378. X      (void) strcpy(died_from, "Quitting");
  1379. X    }
  1380. X      free_turn_flag = TRUE;
  1381. X      break;
  1382. X    case CTRL('P'):    /* (^P)revious message. */
  1383. X      if (command_count > 0)
  1384. X    {
  1385. X      i = command_count;
  1386. X      if (i > MAX_SAVE_MSG)
  1387. X        i = MAX_SAVE_MSG;
  1388. X      command_count = 0;
  1389. X    }
  1390. X      else if (last_command != CTRL('P'))
  1391. X    i = 1;
  1392. X      else
  1393. X    i = MAX_SAVE_MSG;
  1394. X      j = last_msg;
  1395. X      if (i > 1)
  1396. X    {
  1397. X      save_screen();
  1398. X      x = i;
  1399. X      while (i > 0)
  1400. X        {
  1401. X          i--;
  1402. X          prt(old_msg[j], i, 0);
  1403. X          if (j == 0)
  1404. X        j = MAX_SAVE_MSG-1;
  1405. X          else
  1406. X        j--;
  1407. X        }
  1408. X      erase_line (x, 0);
  1409. X      pause_line(x);
  1410. X      restore_screen();
  1411. X    }
  1412. X      else
  1413. X    {
  1414. X      /* Distinguish real and recovered messages with a '>'. -CJS- */
  1415. X      put_buffer(">", 0, 0);
  1416. X      prt(old_msg[j], 0, 1);
  1417. X    }
  1418. X      free_turn_flag = TRUE;
  1419. X      break;
  1420. X    case CTRL('W'):    /* (^W)izard mode */
  1421. X      if (wizard)
  1422. X    {
  1423. X      wizard = FALSE;
  1424. X      msg_print("Wizard mode off.");
  1425. X    }
  1426. X      else if (enter_wiz_mode())
  1427. X    msg_print("Wizard mode on.");
  1428. X      prt_winner();
  1429. X      free_turn_flag = TRUE;
  1430. X      break;
  1431. X    case CTRL('X'):    /* e(^X)it and save */
  1432. X      if (total_winner)
  1433. X    {
  1434. X       msg_print("You are a Total Winner,  your character must be retired.");
  1435. X      if (rogue_like_commands)
  1436. X        msg_print("Use 'Q' to when you are ready to quit.");
  1437. X      else
  1438. X        msg_print ("Use <Control>-K when you are ready to quit.");
  1439. X    }
  1440. X      else
  1441. X    {
  1442. X      (void) strcpy (died_from, "(saved)");
  1443. X      msg_print ("Saving game...");
  1444. X#ifdef MAC
  1445. X      if (save_char (TRUE))
  1446. X        exit_game();
  1447. X#else
  1448. X      if (save_char ())
  1449. X        exit_game();
  1450. X#endif
  1451. X      (void) strcpy (died_from, "(alive and well)");
  1452. X    }
  1453. X      free_turn_flag = TRUE;
  1454. X      break;
  1455. X    case '=':        /* (=) set options */
  1456. X      save_screen();
  1457. X      set_options();
  1458. X      restore_screen();
  1459. X      free_turn_flag = TRUE;
  1460. X      break;
  1461. X    case '{':        /* ({) inscribe an object    */
  1462. X      scribe_object ();
  1463. X      free_turn_flag = TRUE;
  1464. X      break;
  1465. X    case '!':        /* (!) escape to the shell */
  1466. X    case '$':
  1467. X#ifdef SECURE
  1468. X      msg_print("Sorry, inferior shells are not allowed from Moria.");
  1469. X#else
  1470. X      shell_out();
  1471. X#endif
  1472. X      free_turn_flag = TRUE;
  1473. X      break;
  1474. X    case ESCAPE:    /* (ESC)   do nothing. */
  1475. X    case ' ':        /* (space) do nothing. */
  1476. X      free_turn_flag = TRUE;
  1477. X      break;
  1478. X    case 'b':        /* (b) down, left    (1) */
  1479. X      move_char(1, do_pickup);
  1480. X      break;
  1481. X    case 'j':        /* (j) down        (2) */
  1482. X      move_char(2, do_pickup);
  1483. X      break;
  1484. X    case 'n':        /* (n) down, right    (3) */
  1485. X      move_char(3, do_pickup);
  1486. X      break;
  1487. X    case 'h':        /* (h) left        (4) */
  1488. X      move_char(4, do_pickup);
  1489. X      break;
  1490. X    case 'l':        /* (l) right        (6) */
  1491. X      move_char(6, do_pickup);
  1492. X      break;
  1493. X    case 'y':        /* (y) up, left        (7) */
  1494. X      move_char(7, do_pickup);
  1495. X      break;
  1496. X    case 'k':        /* (k) up        (8) */
  1497. X      move_char(8, do_pickup);
  1498. X      break;
  1499. X    case 'u':        /* (u) up, right    (9) */
  1500. X      move_char(9, do_pickup);
  1501. X      break;
  1502. X    case 'B':        /* (B) run down, left    (. 1) */
  1503. X      find_init(1);
  1504. X      break;
  1505. X    case 'J':        /* (J) run down        (. 2) */
  1506. X      find_init(2);
  1507. X      break;
  1508. X    case 'N':        /* (N) run down, right    (. 3) */
  1509. X      find_init(3);
  1510. X      break;
  1511. X    case 'H':        /* (H) run left        (. 4) */
  1512. X      find_init(4);
  1513. X      break;
  1514. X    case 'L':        /* (L) run right    (. 6) */
  1515. X      find_init(6);
  1516. X      break;
  1517. X    case 'Y':        /* (Y) run up, left    (. 7) */
  1518. X      find_init(7);
  1519. X      break;
  1520. X    case 'K':        /* (K) run up        (. 8) */
  1521. X      find_init(8);
  1522. X      break;
  1523. X    case 'U':        /* (U) run up, right    (. 9) */
  1524. X      find_init(9);
  1525. X      break;
  1526. X    case '/':        /* (/) identify a symbol */
  1527. X      ident_char();
  1528. X      free_turn_flag = TRUE;
  1529. X      break;
  1530. X    case '.':        /* (.) stay in one place (5) */
  1531. X      move_char (5, do_pickup);
  1532. X      if (command_count > 1)
  1533. X    {
  1534. X      command_count--;
  1535. X      rest();
  1536. X    }
  1537. X      break;
  1538. X    case '<':        /* (<) go down a staircase */
  1539. X      go_up();
  1540. X      break;
  1541. X    case '>':        /* (>) go up a staircase */
  1542. X      go_down();
  1543. X      break;
  1544. X    case '?':        /* (?) help with commands */
  1545. X      if (rogue_like_commands)
  1546. X    helpfile(MORIA_HELP);
  1547. X      else
  1548. X    helpfile(MORIA_ORIG_HELP);
  1549. X      free_turn_flag = TRUE;
  1550. X      break;
  1551. X    case 'f':        /* (f)orce        (B)ash */
  1552. X      bash();
  1553. X      break;
  1554. X    case 'C':        /* (C)haracter description */
  1555. X      save_screen();
  1556. X      change_name();
  1557. X      restore_screen();
  1558. X      free_turn_flag = TRUE;
  1559. X      break;
  1560. X    case 'D':        /* (D)isarm trap */
  1561. X      disarm_trap();
  1562. X      break;
  1563. X    case 'E':        /* (E)at food */
  1564. X      eat();
  1565. X      break;
  1566. X    case 'F':        /* (F)ill lamp */
  1567. X      refill_lamp();
  1568. X      break;
  1569. X    case 'G':        /* (G)ain magic spells */
  1570. X      gain_spells();
  1571. X      break;
  1572. X    case 'V':        /* (V)iew scores */
  1573. X      if (last_command != 'V')
  1574. X    i = TRUE;
  1575. X      else
  1576. X    i = FALSE;
  1577. X      save_screen();
  1578. X      display_scores(i);
  1579. X      restore_screen();
  1580. X      free_turn_flag = TRUE;
  1581. X      break;
  1582. X    case 'W':        /* (W)here are we on the map    (L)ocate on map */
  1583. X      if ((py.flags.blind > 0) || no_light())
  1584. X    msg_print("You can't see your map.");
  1585. X      else
  1586. X    {
  1587. X      int cy, cx, p_y, p_x;
  1588. X
  1589. X      y = char_row;
  1590. X      x = char_col;
  1591. X      if (get_panel(y, x, TRUE))
  1592. X        prt_map();
  1593. X      cy = panel_row;
  1594. X      cx = panel_col;
  1595. X      for(;;)
  1596. X        {
  1597. X          p_y = panel_row;
  1598. X          p_x = panel_col;
  1599. X          if (p_y == cy && p_x == cx)
  1600. X        tmp_str[0] = '\0';
  1601. X          else
  1602. X        (void) sprintf(tmp_str, "%s%s of",
  1603. X                   p_y < cy ? " North" : p_y > cy ? " South" : "",
  1604. X                   p_x < cx ? " West" : p_x > cx ? " East" : "");
  1605. X          (void) sprintf(out_val,
  1606. X       "Map sector [%d,%d], which is%s your sector. Look which direction?",
  1607. X                 p_y, p_x, tmp_str);
  1608. X          if (!get_dir(out_val, &dir_val))
  1609. X        break;
  1610. X/*                                      -CJS-
  1611. X// Should really use the move function, but what the hell. This
  1612. X// is nicer, as it moves exactly to the same place in another
  1613. X// section. The direction calculation is not intuitive. Sorry.
  1614. X*/
  1615. X          for(;;){
  1616. X        x += ((dir_val-1)%3 - 1) * SCREEN_WIDTH/2;
  1617. X        y -= ((dir_val-1)/3 - 1) * SCREEN_HEIGHT/2;
  1618. X        if (x < 0 || y < 0 || x >= cur_width || y >= cur_width)
  1619. X          {
  1620. X            msg_print("You've gone past the end of your map.");
  1621. X            x -= ((dir_val-1)%3 - 1) * SCREEN_WIDTH/2;
  1622. X            y += ((dir_val-1)/3 - 1) * SCREEN_HEIGHT/2;
  1623. X            break;
  1624. X          }
  1625. X        if (get_panel(y, x, TRUE))
  1626. X          {
  1627. X            prt_map();
  1628. X            break;
  1629. X          }
  1630. X          }
  1631. X        }
  1632. X      /* Move to a new panel - but only if really necessary. */
  1633. X      if (get_panel(char_row, char_col, FALSE))
  1634. X        prt_map();
  1635. X    }
  1636. X      free_turn_flag = TRUE;
  1637. X      break;
  1638. X    case 'R':        /* (R)est a while */
  1639. X      rest();
  1640. X      break;
  1641. X    case '#':        /* (#) search toggle    (S)earch toggle */
  1642. X      if (py.flags.status & PY_SEARCH)
  1643. X    search_off();
  1644. X      else
  1645. X    search_on();
  1646. X      free_turn_flag = TRUE;
  1647. X      break;
  1648. X    case CTRL('B'):        /* (^B) tunnel down left    (T 1) */
  1649. X      tunnel(1);
  1650. X      break;
  1651. X    case CTRL('M'):        /* cr must be treated same as lf. */
  1652. X    case CTRL('J'):        /* (^J) tunnel down        (T 2) */
  1653. X      tunnel(2);
  1654. X      break;
  1655. X    case CTRL('N'):        /* (^N) tunnel down right    (T 3) */
  1656. X      tunnel(3);
  1657. X      break;
  1658. X    case CTRL('H'):        /* (^H) tunnel left        (T 4) */
  1659. X      tunnel(4);
  1660. X      break;
  1661. X    case CTRL('L'):        /* (^L) tunnel right        (T 6) */
  1662. X      tunnel(6);
  1663. X      break;
  1664. X    case CTRL('Y'):        /* (^Y) tunnel up left        (T 7) */
  1665. X      tunnel(7);
  1666. X      break;
  1667. X    case CTRL('K'):        /* (^K) tunnel up        (T 8) */
  1668. X      tunnel(8);
  1669. X      break;
  1670. X    case CTRL('U'):        /* (^U) tunnel up right        (T 9) */
  1671. X      tunnel(9);
  1672. X      break;
  1673. X    case 'z':        /* (z)ap a wand        (a)im a wand */
  1674. X      aim();
  1675. X      break;
  1676. X    case 'M':
  1677. X      screen_map();
  1678. X      free_turn_flag = TRUE;
  1679. X      break;
  1680. X    case 'P':        /* (P)eruse a book    (B)rowse in a book */
  1681. X      examine_book();
  1682. X      free_turn_flag = TRUE;
  1683. X      break;
  1684. X    case 'c':        /* (c)lose an object */
  1685. X      closeobject();
  1686. X      break;
  1687. X    case 'd':        /* (d)rop something */
  1688. X      inven_command('d');
  1689. X      break;
  1690. X    case 'e':        /* (e)quipment list */
  1691. X      inven_command('e');
  1692. X      break;
  1693. X    case 't':        /* (t)hrow something    (f)ire something */
  1694. X      throw_object();
  1695. X      break;
  1696. X    case 'i':        /* (i)nventory list */
  1697. X      inven_command('i');
  1698. X      break;
  1699. X    case 'S':        /* (S)pike a door    (j)am a door */
  1700. X      jamdoor();
  1701. X      break;
  1702. X    case 'x':        /* e(x)amine surrounds    (l)ook about */
  1703. X      look();
  1704. X      free_turn_flag = TRUE;
  1705. X      break;
  1706. X    case 'm':        /* (m)agic spells */
  1707. X      cast();
  1708. X      break;
  1709. X    case 'o':        /* (o)pen something */
  1710. X      openobject();
  1711. X      break;
  1712. X    case 'p':        /* (p)ray */
  1713. X      pray();
  1714. X      break;
  1715. X    case 'q':        /* (q)uaff */
  1716. X      quaff();
  1717. X      break;
  1718. X    case 'r':        /* (r)ead */
  1719. X      read_scroll();
  1720. X      break;
  1721. X    case 's':        /* (s)earch for a turn */
  1722. X      search(char_row, char_col, py.misc.srh);
  1723. X      break;
  1724. X    case 'T':        /* (T)ake off something    (t)ake off */
  1725. X      inven_command('t');
  1726. X      break;
  1727. X    case 'Z':        /* (Z)ap a staff    (u)se a staff */
  1728. X      use();
  1729. X      break;
  1730. X    case 'v':        /* (v)ersion of game */
  1731. X      helpfile(MORIA_VER);
  1732. X      free_turn_flag = TRUE;
  1733. X      break;
  1734. X    case 'w':        /* (w)ear or wield */
  1735. X      inven_command('w');
  1736. X      break;
  1737. X    case 'X':        /* e(X)change weapons    e(x)change */
  1738. X      inven_command('x');
  1739. X      break;
  1740. X    default:
  1741. X      if (wizard)
  1742. X    {
  1743. X      free_turn_flag = TRUE; /* Wizard commands are free moves*/
  1744. X      switch(com_val)
  1745. X        {
  1746. X        case CTRL('A'):    /*^A = Cure all*/
  1747. X          (void) remove_curse();
  1748. X          (void) cure_blindness();
  1749. X          (void) cure_confusion();
  1750. X          (void) cure_poison();
  1751. X          (void) remove_fear();
  1752. X          (void) res_stat(A_STR);
  1753. X          (void) res_stat(A_INT);
  1754. X          (void) res_stat(A_WIS);
  1755. X          (void) res_stat(A_CON);
  1756. X          (void) res_stat(A_DEX);
  1757. X          (void) res_stat(A_CHR);
  1758. X          f_ptr = &py.flags;
  1759. X          if (f_ptr->slow > 1)
  1760. X        f_ptr->slow = 1;
  1761. X          if (f_ptr->image > 1)
  1762. X        f_ptr->image = 1;
  1763. X          break;
  1764. X        case CTRL('E'):    /*^E = wizchar */
  1765. X          change_character();
  1766. X          erase_line(MSG_LINE, 0);
  1767. X          break;
  1768. X        case CTRL('F'):    /*^F = genocide*/
  1769. X          (void) mass_genocide();
  1770. X          break;
  1771. X        case CTRL('G'):    /*^G = treasure*/
  1772. X          if (command_count > 0)
  1773. X        {
  1774. X          i = command_count;
  1775. X          command_count = 0;
  1776. X        }
  1777. X          else
  1778. X        i = 1;
  1779. X          random_object(char_row, char_col, i);
  1780. X          prt_map();
  1781. X          break;
  1782. X        case CTRL('D'):    /*^D = up/down */
  1783. X          if (command_count > 0)
  1784. X        {
  1785. X          if (command_count > 99)
  1786. X            i = 0;
  1787. X          else
  1788. X            i = command_count;
  1789. X          command_count = 0;
  1790. X        }
  1791. X          else
  1792. X        {
  1793. X          prt("Go to which level (0-99) ? ", 0, 0);
  1794. X          i = -1;
  1795. X          if (get_string(tmp_str, 0, 27, 10))
  1796. X            i = atoi(tmp_str);
  1797. X        }
  1798. X          if (i > -1)
  1799. X        {
  1800. X          dun_level = i;
  1801. X          if (dun_level > 99)
  1802. X            dun_level = 99;
  1803. X          new_level_flag = TRUE;
  1804. X        }
  1805. X          else
  1806. X        erase_line(MSG_LINE, 0);
  1807. X          break;
  1808. X        case CTRL('O'):    /*^O = objects */
  1809. X          print_objects();
  1810. X          break;
  1811. X        case '\\': /* \ wizard help */
  1812. X          if (rogue_like_commands)
  1813. X        helpfile(MORIA_WIZ_HELP);
  1814. X          else
  1815. X        helpfile(MORIA_OWIZ_HELP);
  1816. X          break;
  1817. X        case CTRL('I'):    /*^I = identify*/
  1818. X          (void) ident_spell();
  1819. X          break;
  1820. X        case '*':
  1821. X          wizard_light();
  1822. X          break;
  1823. X        case ':':
  1824. X          map_area();
  1825. X          break;
  1826. X        case CTRL('T'):    /*^T = teleport*/
  1827. X          teleport(100);
  1828. X          break;
  1829. X        case '+':
  1830. X          if (command_count > 0)
  1831. X        {
  1832. X          py.misc.exp = command_count;
  1833. X          command_count = 0;
  1834. X        }
  1835. X          else if (py.misc.exp == 0)
  1836. X        py.misc.exp = 1;
  1837. X          else
  1838. X        py.misc.exp = py.misc.exp * 2;
  1839. X          prt_experience();
  1840. X          break;
  1841. X        case '&':    /*& = summon  */
  1842. X          y = char_row;
  1843. X          x = char_col;
  1844. X          (void) summon_monster(&y, &x, TRUE);
  1845. X          creatures(FALSE);
  1846. X          break;
  1847. X        case '@':
  1848. X          wizard_create();
  1849. X          break;
  1850. X        default:
  1851. X          if (rogue_like_commands)
  1852. X        prt("Type '?' or '\\' for help.", 0, 0);
  1853. X          else
  1854. X        prt("Type '?' or ^H for help.", 0, 0);
  1855. X        }
  1856. X    }
  1857. X      else
  1858. X    {
  1859. X      prt("Type '?' for help.", 0, 0);
  1860. X      free_turn_flag = TRUE;
  1861. X    }
  1862. X    }
  1863. X  last_command = com_val;
  1864. X}
  1865. X
  1866. X/* Check whether this command will accept a count.     -CJS-  */
  1867. Xstatic int valid_countcommand(c)
  1868. Xchar c;
  1869. X{
  1870. X  switch(c)
  1871. X    {
  1872. X    case 'Q':
  1873. X    case CTRL('W'):
  1874. X    case CTRL('X'):
  1875. X    case '=':
  1876. X    case '{':
  1877. X    case '/':
  1878. X    case '<':
  1879. X    case '>':
  1880. X    case '?':
  1881. X    case 'C':
  1882. X    case 'E':
  1883. X    case 'F':
  1884. X    case 'G':
  1885. X    case 'V':
  1886. X    case '#':
  1887. X    case 'z':
  1888. X    case 'P':
  1889. X    case 'c':
  1890. X    case 'd':
  1891. X    case 'e':
  1892. X    case 't':
  1893. X    case 'i':
  1894. X    case 'x':
  1895. X    case 'm':
  1896. X    case 'p':
  1897. X    case 'q':
  1898. X    case 'r':
  1899. X    case 'T':
  1900. X    case 'Z':
  1901. X    case 'v':
  1902. X    case 'w':
  1903. X    case 'W':
  1904. X    case 'X':
  1905. X    case CTRL('A'):
  1906. X    case '\\':
  1907. X    case CTRL('I'):
  1908. X    case '*':
  1909. X    case ':':
  1910. X    case CTRL('T'):
  1911. X    case CTRL('E'):
  1912. X    case CTRL('F'):
  1913. X    case CTRL('S'):
  1914. X    case CTRL('Q'):
  1915. X      return FALSE;
  1916. X    case CTRL('P'):
  1917. X    case ESCAPE:
  1918. X    case ' ':
  1919. X    case '-':
  1920. X    case 'b':
  1921. X    case 'f':
  1922. X    case 'j':
  1923. X    case 'n':
  1924. X    case 'h':
  1925. X    case 'l':
  1926. X    case 'y':
  1927. X    case 'k':
  1928. X    case 'u':
  1929. X    case '.':
  1930. X    case 'B':
  1931. X    case 'J':
  1932. X    case 'N':
  1933. X    case 'H':
  1934. X    case 'L':
  1935. X    case 'Y':
  1936. X    case 'K':
  1937. X    case 'U':
  1938. X    case 'D':
  1939. X    case 'R':
  1940. X    case CTRL('Y'):
  1941. X    case CTRL('K'):
  1942. X    case CTRL('U'):
  1943. X    case CTRL('L'):
  1944. X    case CTRL('N'):
  1945. X    case CTRL('J'):
  1946. X    case CTRL('B'):
  1947. X    case CTRL('H'):
  1948. X    case 'S':
  1949. X    case 'o':
  1950. X    case 's':
  1951. X    case CTRL('D'):
  1952. X    case CTRL('G'):
  1953. X    case '+':
  1954. X      return TRUE;
  1955. X    default:
  1956. X      return FALSE;
  1957. X    }
  1958. X}
  1959. X
  1960. X
  1961. X/* Regenerate hit points                -RAK-    */
  1962. Xstatic void regenhp(percent)
  1963. Xint percent;
  1964. X{
  1965. X  register struct misc *p_ptr;
  1966. X  register int32 new_chp, new_chp_frac;
  1967. X  int old_chp;
  1968. X
  1969. X  p_ptr = &py.misc;
  1970. X  old_chp = p_ptr->chp;
  1971. X  new_chp = ((long)p_ptr->mhp) * percent + PLAYER_REGEN_HPBASE;
  1972. X  p_ptr->chp += new_chp >> 16;    /* div 65536 */
  1973. X  /* check for overflow */
  1974. X  if (p_ptr->chp < 0 && old_chp > 0)
  1975. X    p_ptr->chp = MAX_SHORT;
  1976. X  new_chp_frac = (new_chp & 0xFFFF) + p_ptr->chp_frac; /* mod 65536 */
  1977. X  if (new_chp_frac >= 0x10000L)
  1978. X    {
  1979. X      p_ptr->chp_frac = new_chp_frac - 0x10000L;
  1980. X      p_ptr->chp++;
  1981. X    }
  1982. X  else
  1983. X    p_ptr->chp_frac = new_chp_frac;
  1984. X
  1985. X  /* must set frac to zero even if equal */
  1986. X  if (p_ptr->chp >= p_ptr->mhp)
  1987. X    {
  1988. X      p_ptr->chp = p_ptr->mhp;
  1989. X      p_ptr->chp_frac = 0;
  1990. X    }
  1991. X  if (old_chp != p_ptr->chp)
  1992. X    prt_chp();
  1993. X}
  1994. X
  1995. X
  1996. X/* Regenerate mana points                -RAK-    */
  1997. Xstatic void regenmana(percent)
  1998. Xint percent;
  1999. X{
  2000. X  register struct misc *p_ptr;
  2001. X  register int32 new_mana, new_mana_frac;
  2002. X  int old_cmana;
  2003. X
  2004. X  p_ptr = &py.misc;
  2005. X  old_cmana = p_ptr->cmana;
  2006. X  new_mana = ((long)p_ptr->mana) * percent + PLAYER_REGEN_MNBASE;
  2007. X  p_ptr->cmana += new_mana >> 16;  /* div 65536 */
  2008. X  /* check for overflow */
  2009. X  if (p_ptr->cmana < 0 && old_cmana > 0)
  2010. X    p_ptr->cmana = MAX_SHORT;
  2011. X  new_mana_frac = (new_mana & 0xFFFF) + p_ptr->cmana_frac; /* mod 65536 */
  2012. X  if (new_mana_frac >= 0x10000L)
  2013. X    {
  2014. X      p_ptr->cmana_frac = new_mana_frac - 0x10000L;
  2015. X      p_ptr->cmana++;
  2016. X    }
  2017. X  else
  2018. X    p_ptr->cmana_frac = new_mana_frac;
  2019. X
  2020. X  /* must set frac to zero even if equal */
  2021. X  if (p_ptr->cmana >= p_ptr->mana)
  2022. X    {
  2023. X      p_ptr->cmana = p_ptr->mana;
  2024. X      p_ptr->cmana_frac = 0;
  2025. X    }
  2026. X  if (old_cmana != p_ptr->cmana)
  2027. X    prt_cmana();
  2028. X}
  2029. X
  2030. X
  2031. X/* Is an item an enchanted weapon or armor and we don't know?  -CJS- */
  2032. X/* only returns true if it is a good enchantment */
  2033. Xstatic int enchanted (t_ptr)
  2034. Xregister inven_type *t_ptr;
  2035. X{
  2036. X#ifdef ATARIST_MWC
  2037. X  int32u holder;
  2038. X#endif
  2039. X
  2040. X  if (t_ptr->tval < TV_MIN_ENCHANT || t_ptr->tval > TV_MAX_ENCHANT
  2041. X#ifdef ATARIST_MWC
  2042. X      || t_ptr->flags & (holder = TR_CURSED))
  2043. X#else
  2044. X      || t_ptr->flags & TR_CURSED)
  2045. X#endif
  2046. X    return FALSE;
  2047. X  if (known2_p(t_ptr))
  2048. X    return FALSE;
  2049. X  if (t_ptr->ident & ID_MAGIK)
  2050. X    return FALSE;
  2051. X  if (t_ptr->tohit > 0 || t_ptr->todam > 0 || t_ptr->toac > 0)
  2052. X    return TRUE;
  2053. X  if ((0x4000107fL & t_ptr->flags) && t_ptr->p1 > 0)
  2054. X    return TRUE;
  2055. X  if (0x07ffe980L & t_ptr->flags)
  2056. X    return TRUE;
  2057. X
  2058. X  return FALSE;
  2059. X}
  2060. X
  2061. X
  2062. X/* Examine a Book                    -RAK-    */
  2063. Xstatic void examine_book()
  2064. X{
  2065. X  int32u j;
  2066. X  int i, k, item_val, flag;
  2067. X  int spell_index[31];
  2068. X  register inven_type *i_ptr;
  2069. X  register spell_type *s_ptr;
  2070. X
  2071. X  if (!find_range(TV_MAGIC_BOOK, TV_PRAYER_BOOK, &i, &k))
  2072. X    msg_print("You are not carrying any books.");
  2073. X  else if (py.flags.blind > 0)
  2074. X    msg_print("You can't see to read your spell book!");
  2075. X  else if (no_light())
  2076. X    msg_print("You have no light to read by.");
  2077. X  else if (py.flags.confused > 0)
  2078. X    msg_print("You are too confused.");
  2079. X  else if (get_item(&item_val, "Which Book?", i, k, CNIL, CNIL))
  2080. X    {
  2081. X      flag = TRUE;
  2082. X      i_ptr = &inventory[item_val];
  2083. X      if (class[py.misc.pclass].spell == MAGE)
  2084. X    {
  2085. X      if (i_ptr->tval != TV_MAGIC_BOOK)
  2086. X        flag = FALSE;
  2087. X    }
  2088. X      else if (class[py.misc.pclass].spell == PRIEST)
  2089. X    {
  2090. X      if (i_ptr->tval != TV_PRAYER_BOOK)
  2091. X        flag = FALSE;
  2092. X    }
  2093. X      else
  2094. X    flag = FALSE;
  2095. X
  2096. X      if (!flag)
  2097. X    msg_print("You do not understand the language.");
  2098. X      else
  2099. X    {
  2100. X      i = 0;
  2101. X      j = inventory[item_val].flags;
  2102. X      while (j)
  2103. X        {
  2104. X          k = bit_pos(&j);
  2105. X          s_ptr = &magic_spell[py.misc.pclass-1][k];
  2106. X          if (s_ptr->slevel < 99)
  2107. X        {
  2108. X          spell_index[i] = k;
  2109. X          i++;
  2110. X        }
  2111. X        }
  2112. X      save_screen();
  2113. X      print_spells(spell_index, i, TRUE, -1);
  2114. X      pause_line(0);
  2115. X      restore_screen();
  2116. X    }
  2117. X    }
  2118. X}
  2119. X
  2120. X
  2121. X/* Go up one level                    -RAK-    */
  2122. Xstatic void go_up()
  2123. X{
  2124. X  register cave_type *c_ptr;
  2125. X  register int no_stairs = FALSE;
  2126. X
  2127. X  c_ptr = &cave[char_row][char_col];
  2128. X  if (c_ptr->tptr != 0)
  2129. X    if (t_list[c_ptr->tptr].tval == TV_UP_STAIR)
  2130. X      {
  2131. X    dun_level--;
  2132. X    new_level_flag = TRUE;
  2133. X    msg_print("You enter a maze of up staircases.");
  2134. X    msg_print("You pass through a one-way door.");
  2135. X      }
  2136. X    else
  2137. X      no_stairs = TRUE;
  2138. X  else
  2139. X    no_stairs = TRUE;
  2140. X
  2141. X  if (no_stairs)
  2142. X    {
  2143. X      msg_print("I see no up staircase here.");
  2144. X      free_turn_flag = TRUE;
  2145. X    }
  2146. X}
  2147. X
  2148. X
  2149. X/* Go down one level                    -RAK-    */
  2150. Xstatic void go_down()
  2151. X{
  2152. X  register cave_type *c_ptr;
  2153. X  register int no_stairs = FALSE;
  2154. X
  2155. X  c_ptr = &cave[char_row][char_col];
  2156. X  if (c_ptr->tptr != 0)
  2157. X    if (t_list[c_ptr->tptr].tval == TV_DOWN_STAIR)
  2158. X      {
  2159. X    dun_level++;
  2160. X    new_level_flag = TRUE;
  2161. X    msg_print("You enter a maze of down staircases.");
  2162. X    msg_print("You pass through a one-way door.");
  2163. X      }
  2164. X    else
  2165. X      no_stairs = TRUE;
  2166. X  else
  2167. X    no_stairs = TRUE;
  2168. X
  2169. X  if (no_stairs)
  2170. X    {
  2171. X      msg_print("I see no down staircase here.");
  2172. X      free_turn_flag = TRUE;
  2173. X    }
  2174. X}
  2175. X
  2176. X
  2177. X/* Jam a closed door                    -RAK-    */
  2178. Xstatic void jamdoor()
  2179. X{
  2180. X  int y, x, dir, i, j;
  2181. X  register cave_type *c_ptr;
  2182. X  register inven_type *t_ptr, *i_ptr;
  2183. X  char tmp_str[80];
  2184. X
  2185. X  free_turn_flag = TRUE;
  2186. X  y = char_row;
  2187. X  x = char_col;
  2188. X  if (get_dir(CNIL, &dir))
  2189. X    {
  2190. X      (void) mmove(dir, &y, &x);
  2191. X      c_ptr = &cave[y][x];
  2192. X      if (c_ptr->tptr != 0)
  2193. X    {
  2194. X      t_ptr = &t_list[c_ptr->tptr];
  2195. X      if (t_ptr->tval == TV_CLOSED_DOOR)
  2196. X        if (c_ptr->cptr == 0)
  2197. X          {
  2198. X        if (find_range(TV_SPIKE, TV_NEVER, &i, &j))
  2199. X          {
  2200. X            free_turn_flag = FALSE;
  2201. X            count_msg_print("You jam the door with a spike.");
  2202. X            if (t_ptr->p1 > 0)
  2203. X              t_ptr->p1 = -t_ptr->p1;    /* Make locked to stuck. */
  2204. X            /* Successive spikes have a progressively smaller effect.
  2205. X               Series is: 0 20 30 37 43 48 52 56 60 64 67 70 ... */
  2206. X            t_ptr->p1 -= 1 + 190 / (10 - t_ptr->p1);
  2207. X            i_ptr = &inventory[i];
  2208. X            if (i_ptr->number > 1)
  2209. X              {
  2210. X            i_ptr->number--;
  2211. X            inven_weight -= i_ptr->weight;
  2212. X              }
  2213. X            else
  2214. X              inven_destroy(i);
  2215. X          }
  2216. X        else
  2217. X          msg_print("But you have no spikes.");
  2218. X          }
  2219. X        else
  2220. X          {
  2221. X        free_turn_flag = FALSE;
  2222. X        (void) sprintf(tmp_str, "The %s is in your way!",
  2223. X                   c_list[m_list[c_ptr->cptr].mptr].name);
  2224. X        msg_print(tmp_str);
  2225. X          }
  2226. X      else if (t_ptr->tval == TV_OPEN_DOOR)
  2227. X        msg_print("The door must be closed first.");
  2228. X      else
  2229. X        msg_print("That isn't a door!");
  2230. X    }
  2231. X      else
  2232. X    msg_print("That isn't a door!");
  2233. X    }
  2234. X}
  2235. X
  2236. X
  2237. X/* Refill the players lamp                -RAK-    */
  2238. Xstatic void refill_lamp()
  2239. X{
  2240. X  int i, j;
  2241. X  register int k;
  2242. X  register inven_type *i_ptr;
  2243. X
  2244. X  free_turn_flag = TRUE;
  2245. X  k = inventory[INVEN_LIGHT].subval;
  2246. X  if (k != 0)
  2247. X    msg_print("But you are not using a lamp.");
  2248. X  else if (!find_range(TV_FLASK, TV_NEVER, &i, &j))
  2249. X    msg_print("You have no oil.");
  2250. X  else
  2251. X    {
  2252. X      free_turn_flag = FALSE;
  2253. X      i_ptr = &inventory[INVEN_LIGHT];
  2254. X      i_ptr->p1 += inventory[i].p1;
  2255. X      if (i_ptr->p1 > OBJ_LAMP_MAX)
  2256. X    {
  2257. X      i_ptr->p1 = OBJ_LAMP_MAX;
  2258. X      msg_print ("Your lamp overflows, spilling oil on the ground.");
  2259. X      msg_print("Your lamp is full.");
  2260. X    }
  2261. X      else if (i_ptr->p1 > OBJ_LAMP_MAX/2)
  2262. X    msg_print ("Your lamp is more than half full.");
  2263. X      else if (i_ptr->p1 == OBJ_LAMP_MAX/2)
  2264. X    msg_print ("Your lamp is half full.");
  2265. X      else
  2266. X    msg_print ("Your lamp is less than half full.");
  2267. X      desc_remain(i);
  2268. X      inven_destroy(i);
  2269. X    }
  2270. X}
  2271. END_OF_FILE
  2272. if test 49774 -ne `wc -c <'source/dungeon.c'`; then
  2273.     echo shar: \"'source/dungeon.c'\" unpacked with wrong size!
  2274. fi
  2275. # end of 'source/dungeon.c'
  2276. fi
  2277. echo shar: End of archive 4 \(of 39\).
  2278. cp /dev/null ark4isdone
  2279. MISSING=""
  2280. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 ; do
  2281.     if test ! -f ark${I}isdone ; then
  2282.     MISSING="${MISSING} ${I}"
  2283.     fi
  2284. done
  2285. if test "${MISSING}" = "" ; then
  2286.     echo You have unpacked all 39 archives.
  2287.     echo "Now run "bldfiles.sh" to build split files"
  2288.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2289. else
  2290.     echo You still need to unpack the following archives:
  2291.     echo "        " ${MISSING}
  2292. fi
  2293. ##  End of shell archive.
  2294. exit 0
  2295.