home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / mor4873s.lzh / MORIA2.C < prev    next >
C/C++ Source or Header  |  1988-12-14  |  52KB  |  2,055 lines

  1. #include <stdio.h>
  2.  
  3. #include "constant.h"
  4. #include "config.h"
  5. #include "types.h"
  6. #include "externs.h"
  7.  
  8. #ifdef USG
  9. #include <string.h>
  10. #else
  11. #include <strings.h>
  12. #endif
  13.  
  14. #ifdef sun   /* correct SUN stupidity in the stdio.h file */
  15. char *sprintf();
  16. #endif
  17.  
  18. /* global flags */
  19. extern int moria_flag;        /* Next level when true  */
  20. extern int search_flag;       /* Player is searching   */
  21. extern int teleport_flag;     /* Handle teleport traps  */
  22. extern int player_light;      /* Player carrying light */
  23. extern int cave_flag;         /* used in get_panel */
  24. extern int light_flag;        /* used in move_light */
  25.  
  26. char cur_char1();
  27.  
  28.  
  29. /* Teleport the player to a new location         -RAK-    */
  30. teleport(dis)
  31. int dis;
  32. {
  33.   register int y, x;
  34.   cave_type *c_ptr;
  35.   register int i, j;
  36.  
  37.   do
  38.     {
  39.       y = randint(cur_height) - 1;
  40.       x = randint(cur_width) - 1;
  41.       while (distance(y, x, char_row, char_col) > dis)
  42.     {
  43.       y += ((char_row-y)/2);
  44.       x += ((char_col-x)/2);
  45.     }
  46.     }
  47.   while ((!cave[y][x].fopen) || (cave[y][x].cptr >= 2));
  48.   move_rec(char_row, char_col, y, x);
  49.   for (i = char_row-1; i <= char_row+1; i++)
  50.     for (j = char_col-1; j <= char_col+1; j++)
  51.       {
  52.     c_ptr = &cave[i][j];
  53.     c_ptr->tl = FALSE;
  54.     if (!test_light(i, j))
  55.       unlite_spot(i, j);
  56.       }
  57.   if (test_light(char_row, char_col))
  58.     lite_spot(char_row, char_col);
  59.   char_row = y;
  60.   char_col = x;
  61.   move_char(5);
  62.   creatures(FALSE);
  63.   teleport_flag = FALSE;
  64. }
  65.  
  66.  
  67. /* Player hit a trap...    (Chuckle)            -RAK-    */
  68. hit_trap(y, x)
  69. int *y, *x;
  70. {
  71.   int i, ty, tx;
  72.   int dam;
  73.   register cave_type *c_ptr;
  74.   register struct misc *p_ptr;
  75.  
  76.   change_trap(*y, *x);
  77.   lite_spot(char_row, char_col);
  78.   if (find_flag)
  79.     {
  80.       find_flag = FALSE;
  81.       move_light (char_row, char_col, char_row, char_col);
  82.     }
  83.   c_ptr = &cave[*y][*x];
  84.   p_ptr = &py.misc;
  85.   dam = damroll(t_list[c_ptr->tptr].damage);
  86.   switch(t_list[c_ptr->tptr].subval)
  87.     {
  88.     case 1:  /* Open pit*/
  89.       msg_print("You fell into a pit!");
  90.       if (py.flags.ffall)
  91.     msg_print("You gently float down.");
  92.       else
  93.     take_hit(dam, "an open pit.");
  94.       break;
  95.     case 2: /* Arrow trap*/
  96.       if (test_hit(125, 0, 0, p_ptr->pac+p_ptr->ptoac))
  97.     {
  98.       take_hit(dam, "an arrow trap.");
  99.       msg_print("An arrow hits you.");
  100.     }
  101.       else
  102.     msg_print("An arrow barely misses you.");
  103.       break;
  104.     case 3: /* Covered pit*/
  105.       msg_print("You fell into a covered pit.");
  106.       if (py.flags.ffall)
  107.     msg_print("You gently float down.");
  108.       else
  109.     take_hit(dam, "a covered pit.");
  110.       place_trap(*y, *x, 2, 1);
  111.       break;
  112.     case 4: /* Trap door*/
  113.       msg_print("You fell through a trap door!");
  114.       /* make sure player reads message before new level drawn! */
  115.       msg_print(" ");
  116.       moria_flag = TRUE;
  117.       dun_level++;
  118.       if (py.flags.ffall)
  119.     msg_print("You gently float down.");
  120.       else
  121.     take_hit(dam, "a trap door.");
  122.       break;
  123.     case 5: /* Sleep gas*/
  124.       if (py.flags.paralysis == 0)
  125.     {
  126.       msg_print("A strange white mist surrounds you!");
  127.       if (py.flags.free_act)
  128.         msg_print("You are unaffected.");
  129.       else
  130.         {
  131.           msg_print("You fall asleep.");
  132.           py.flags.paralysis += randint(10) + 4;
  133.         }
  134.     }
  135.       break;
  136.     case 6: /* Hid Obj*/
  137.       c_ptr->fm = FALSE;
  138.       pusht((int)c_ptr->tptr);
  139.       place_object(*y, *x);
  140.       msg_print("Hmmm, there was something under this rock.");
  141.       break;
  142.     case 7:  /* STR Dart*/
  143.       if (test_hit(125, 0, 0, p_ptr->pac+p_ptr->ptoac))
  144.     {
  145.       if (!py.flags.sustain_str)
  146.         {
  147.           py.stats.cstr = de_statp(py.stats.cstr);
  148.           take_hit(dam, "a dart trap.");
  149.           print_stat |= 0x0001;
  150.           msg_print("A small dart weakens you!");
  151.           /* adjust misc stats */
  152.           py_bonuses(blank_treasure, 0);
  153.         }
  154.       else
  155.         msg_print("A small dart hits you.");
  156.     }
  157.       else
  158.     msg_print("A small dart barely misses you.");
  159.       break;
  160.     case 8: /* Teleport*/
  161.       teleport_flag = TRUE;
  162.       msg_print("You hit a teleport trap!");
  163.       break;
  164.     case 9: /* Rockfall*/
  165.       take_hit(dam, "a falling rock.");
  166.       pusht((int)c_ptr->tptr);
  167.       place_rubble(*y, *x);
  168.       msg_print("You are hit by a falling rock");
  169.       break;
  170.     case 10: /* Corrode gas*/
  171.       corrode_gas("corrosion gas.");
  172.       msg_print("A strange red gas surrounds you.");
  173.       break;
  174.     case 11: /* Summon mon*/
  175.       c_ptr->fm = FALSE;        /* Rune disappears...    */
  176.       pusht((int)c_ptr->tptr);
  177.       c_ptr->tptr = 0;
  178.       for (i = 0; i < (2+randint(3)); i++)
  179.     {
  180.       ty = char_row;
  181.       tx = char_col;
  182.       (void) summon_monster(&ty, &tx, FALSE);
  183.     }
  184.       break;
  185.     case 12: /* Fire trap*/
  186.       fire_dam(dam, "a fire trap.");
  187.       msg_print("You are enveloped in flames!");
  188.       break;
  189.     case 13: /* Acid trap*/
  190.       acid_dam(dam, "an acid trap.");
  191.       msg_print("You are splashed with acid!");
  192.       break;
  193.     case 14: /* Poison gas*/
  194.       poison_gas(dam, "a poison gas trap.");
  195.       msg_print("A pungent green gas surrounds you!");
  196.       break;
  197.     case 15: /* Blind Gas */
  198.       msg_print("A black gas surrounds you!");
  199.       py.flags.blind += randint(50) + 50;
  200.       break;
  201.     case 16: /* Confuse Gas*/
  202.       msg_print("A gas of scintillating colors surrounds you!");
  203.       py.flags.confused += randint(15) + 15;
  204.       break;
  205.     case 17: /* Slow Dart*/
  206.       if (test_hit(125, 0, 0, p_ptr->pac+p_ptr->ptoac))
  207.     {
  208.       take_hit(dam, "a dart trap.");
  209.       msg_print("A small dart hits you!");
  210.       py.flags.slow += randint(20) + 10;
  211.     }
  212.       else
  213.     msg_print("A small dart barely misses you.");
  214.       break;
  215.     case 18: /* CON Dart*/
  216.       if (test_hit(125, 0, 0, p_ptr->pac+p_ptr->ptoac))
  217.     {
  218.       if (!py.flags.sustain_con)
  219.         {
  220.           py.stats.ccon = de_statp(py.stats.ccon);
  221.           take_hit(dam, "a dart trap.");
  222.           print_stat |= 0x0004;
  223.           msg_print("A small dart weakens you!");
  224.         }
  225.       else
  226.         msg_print("A small dart hits you.");
  227.     }
  228.       else
  229.     msg_print("A small dart barely misses you.");
  230.       break;
  231.     case 19: /*Secret Door*/
  232.       break;
  233.     case 99: /* Scare Mon*/
  234.       break;
  235.  
  236.       /* Town level traps are special,  the stores...    */
  237.     case 101: /* General    */
  238.       enter_store(0);
  239.       break;
  240.     case 102: /* Armory     */
  241.       enter_store(1);
  242.       break;
  243.     case 103: /* Weaponsmith*/
  244.       enter_store(2);
  245.       break;
  246.     case 104: /* Temple     */
  247.       enter_store(3);
  248.       break;
  249.     case 105: /* Alchemy    */
  250.       enter_store(4);
  251.       break;
  252.     case 106: /* Magic-User */
  253.       enter_store(5);
  254.       break;
  255.  
  256.     default:
  257.       msg_print("Unknown trap value");
  258.       break;
  259.     }
  260. }
  261.  
  262.  
  263. /* Return spell number and failure chance        -RAK-    */
  264. /* returns -1 if no spells in book
  265.    returns 1 if choose a spell in book to cast
  266.    returns 0 if don't choose a spell, i.e. exit with an escape */
  267. int cast_spell(prompt, item_val, sn, sc, redraw)
  268. char *prompt;
  269. int item_val;
  270. int *sn, *sc;
  271. int *redraw;
  272. {
  273.   bitset_t j;
  274.   register int i, k;
  275.   spl_type spell;
  276.   int cast;
  277.   register spell_type *s_ptr;
  278.  
  279.   cast = -1;
  280.   i = 0;
  281.   j = inventory[item_val].flags;
  282.   do
  283.     {
  284.       k = bit_pos(&j);
  285.       if (k >= 0)
  286.     {
  287.       s_ptr = &magic_spell[py.misc.pclass][k];
  288.       if (s_ptr->slevel <= py.misc.lev)
  289.         if (s_ptr->learned)
  290.           {
  291.         spell[i].splnum = k;
  292.         i++;
  293.           }
  294.     }
  295.     }
  296.   while (j != 0);
  297.   if (i > 0)
  298.     {
  299.       cast = get_spell(spell, i, sn, sc, prompt, redraw);
  300.       if (cast && magic_spell[py.misc.pclass][*sn].smana > py.misc.cmana)
  301.     cast = confirm();
  302.     }
  303.   if (*redraw)
  304.     draw_cave();
  305.   return(cast);
  306. }
  307.  
  308.  
  309. /* Finds range of item in inventory list         -RAK-    */
  310. int find_range(item1, item2, j, k)
  311. int item1, item2;
  312. register int *j, *k;
  313. {
  314.   register int i;
  315.   int flag;
  316.  
  317.   i = 0;
  318.   *j = -1;
  319.   *k = -1;
  320.   flag = FALSE;
  321.   while(i < inven_ctr)
  322.     {
  323.       if (((inventory[i].tval == item1)  || (inventory[i].tval == item2))
  324.       && (!flag))
  325.     {
  326.       flag = TRUE;
  327.       *j = i;
  328.     }
  329.       if (((inventory[i].tval != item1) && (inventory[i].tval != item2))
  330.       && (flag) && (*k == -1))
  331.     *k = i - 1;
  332.       i++;
  333.     }
  334.   if ((flag) && (*k == -1))
  335.     *k = inven_ctr - 1;
  336.   return(flag);
  337. }
  338.  
  339.  
  340. /* Examine a Book                    -RAK-    */
  341. examine_book()
  342. {
  343.   bitset_t j;
  344.   int i, k, item_val;
  345.   int redraw, flag;
  346.   char dummy;
  347.   vtype out_val;
  348.   register treasure_type *i_ptr;
  349.   register spell_type *s_ptr;
  350.  
  351.   redraw = FALSE;
  352.   if (!find_range(90, 91, &i, &k))
  353.     msg_print("You are not carrying any books.");
  354.   else if (get_item(&item_val, "Which Book?", &redraw, i, k))
  355.     {
  356.       flag = TRUE;
  357.       i_ptr = &inventory[item_val];
  358.       if (class[py.misc.pclass].mspell)
  359.     {
  360.       if (i_ptr->tval != 90)
  361.         {
  362.           msg_print("You do not understand the language.");
  363.           flag = FALSE;
  364.         }
  365.     }
  366.       else if (class[py.misc.pclass].pspell)
  367.     {
  368.       if (i_ptr->tval != 91)
  369.         {
  370.           msg_print("You do not understand the language.");
  371.           flag = FALSE;
  372.         }
  373.     }
  374.       else
  375.     {
  376.       msg_print("You do not understand the language.");
  377.       flag = FALSE;
  378.     }
  379.       if (flag)
  380.     {
  381.       redraw = TRUE;
  382.       i = 0;
  383.       j = inventory[item_val].flags;
  384.       clear_screen(0, 0);
  385.       (void) strcpy(out_val,
  386.          "   Name                         Level  Mana  Known");
  387.       prt(out_val, 0, 0);
  388.       do
  389.         {
  390.           k = bit_pos(&j);
  391.           if (k >= 0)
  392.         s_ptr = &magic_spell[py.misc.pclass][k];
  393.           {
  394.             if (s_ptr->slevel < 99)
  395.               {
  396.             (void) sprintf(out_val, "%c) %s%3d   %3d   %4s", 97+i,
  397.                 pad(s_ptr->sname, " ", 30), s_ptr->slevel,
  398.                 s_ptr->smana, s_ptr->learned ? "yes" : "no");
  399.             prt(out_val, i+1, 0);
  400.               }
  401.             else
  402.               prt("", i+1, 0);  /* clear the line */
  403.             i++;
  404.           }
  405.         }
  406.       while (j != 0);
  407.       prt("[Press any key to continue]", 23, 19);
  408.       inkey(&dummy);
  409.     }
  410.     }
  411.   if (redraw)  draw_cave();
  412. }
  413.  
  414.  
  415. /* Player is on an object.  Many things can happen BASED -RAK-    */
  416. /* on the TVAL of the object.  Traps are set off, money and most */
  417. /* objects are picked up.  Some objects, such as open doors, just*/
  418. /* sit there...                                                  */
  419. carry(y, x)
  420. int y, x;
  421. {
  422.   int item_val;
  423.   bigvtype out_val, tmp_str;
  424.   register cave_type *c_ptr;
  425.   register treasure_type *i_ptr;
  426.  
  427.   if (find_flag)
  428.     {
  429.       find_flag = FALSE;
  430.       move_light (char_row, char_col, char_row, char_col);
  431.     }
  432.   c_ptr = &cave[y][x];
  433.   inventory[INVEN_MAX] = t_list[c_ptr->tptr];
  434.   /* There's GOLD in them thar hills!      */
  435.   if (t_list[c_ptr->tptr].tval == 100)
  436.     {
  437.       pusht((int)c_ptr->tptr);
  438.       c_ptr->tptr = 0;
  439.       i_ptr = &inventory[INVEN_MAX];
  440.       py.misc.au += i_ptr->cost;
  441.       (void) sprintf(out_val, "You have found %ld gold pieces worth of %s.",
  442.           i_ptr->cost, i_ptr->name);
  443.       prt_gold();
  444.       msg_print(out_val);
  445.     }
  446.   /* OPPS!                                 */
  447.   else if ((t_list[c_ptr->tptr].tval == 101) ||
  448.        (t_list[c_ptr->tptr].tval == 102) ||
  449.        (t_list[c_ptr->tptr].tval == 109) ||
  450.        (t_list[c_ptr->tptr].tval == 110))
  451.     hit_trap(&y, &x);
  452.   /* Attempt to pick up an object.         */
  453.   else if (t_list[c_ptr->tptr].tval < 100)
  454.     {
  455.       if (inven_check_weight())     /* Weight limit check    */
  456.     if (inven_check_num())      /* Too many objects?     */
  457.       {                       /* Okay,  pick it up      */
  458.         pusht((int)c_ptr->tptr);
  459.         c_ptr->tptr = 0;
  460.         inven_carry(&item_val);
  461.         objdes(tmp_str, item_val, TRUE);
  462.         (void) sprintf(out_val, "You have %s (%c%c", tmp_str, item_val+97,
  463.             cur_char1(item_val));
  464.         msg_print(out_val);
  465.       }
  466.     else
  467.       msg_print("You can't carry that many items.");
  468.       else
  469.     msg_print("You can't carry that much weight.");
  470.     }
  471. }
  472.  
  473.  
  474. /* Drop an object being carried                -RAK-    */
  475. /* Note: Only one object per floor spot...                       */
  476. drop()
  477. {
  478.   int com_val;
  479.   int redraw;
  480.   bigvtype out_val, tmp_str;
  481.   register cave_type *c_ptr;
  482.  
  483.   redraw = FALSE;
  484.   reset_flag = TRUE;
  485.   if (inven_ctr > 0)
  486.     {
  487.       c_ptr = &cave[char_row][char_col];
  488.       if (c_ptr->tptr != 0)
  489.     msg_print("There is something there already.");
  490.       else if (get_item(&com_val, "Which one? ", &redraw, 0, inven_ctr-1))
  491.     {
  492.       reset_flag = FALSE;
  493.       if (redraw)  draw_cave();
  494.       inven_drop(com_val, char_row, char_col);
  495.       objdes(tmp_str, INVEN_MAX, TRUE);
  496.       (void) sprintf(out_val, "Dropped %s", tmp_str);
  497.       msg_print(out_val);
  498.     }
  499.       else if (redraw)
  500.     draw_cave();
  501.     }
  502.   else
  503.     msg_print("You are not carrying anything.");
  504. }
  505.  
  506.  
  507. /* Deletes a monster entry from the level        -RAK-    */
  508. delete_monster(j)
  509. int j;
  510. {
  511.   register int i, k;
  512.   register cave_type *c_ptr;
  513.   register monster_type *m_ptr;
  514.  
  515.   i = muptr;
  516.   k = m_list[j].nptr;
  517.   if (i == j)
  518.     muptr = k;
  519.   else
  520.     {
  521.       while (m_list[i].nptr != j)
  522.     i = m_list[i].nptr;
  523.       m_list[i].nptr = k;
  524.     }
  525.   m_ptr = &m_list[j];
  526.   cave[m_ptr->fy][m_ptr->fx].cptr = 0;
  527.   if (m_ptr->ml)
  528.     {
  529.       c_ptr = &cave[m_ptr->fy][m_ptr->fx];
  530.       if ((c_ptr->pl) || (c_ptr->tl))
  531.     lite_spot((int)m_ptr->fy, (int)m_ptr->fx);
  532.       else
  533.     unlite_spot((int)m_ptr->fy, (int)m_ptr->fx);
  534.     }
  535.   pushm(j);
  536.   if (mon_tot_mult > 0)
  537.     mon_tot_mult--;
  538. }
  539.  
  540.  
  541. /* Makes sure new creature gets lit up            -RAK-    */
  542. check_mon_lite(y, x)
  543. register int y, x;
  544. {
  545.   register cave_type *c_ptr;
  546.  
  547.   c_ptr = &cave[y][x];
  548.   if (c_ptr->cptr > 1)
  549.     if (!m_list[c_ptr->cptr].ml)
  550.       if ((c_ptr->tl) || (c_ptr->pl))
  551.     if (los(char_row, char_col, y, x))
  552.       {
  553.         m_list[c_ptr->cptr].ml = TRUE;
  554.         lite_spot(y, x);
  555.       }
  556. }
  557.  
  558.  
  559. /* Places creature adjacent to given location        -RAK-    */
  560. /* Rats and Flys are fun!                                        */
  561. multiply_monster(y, x, z, slp)
  562. int y, x, z;
  563. int slp;
  564. {
  565.   register int i, j, k;
  566.   register cave_type *c_ptr;
  567.  
  568.   i = 0;
  569.   do
  570.     {
  571.       j = y - 2 + randint(3);
  572.       k = x - 2 + randint(3);
  573.       if (in_bounds(j, k))
  574.     {
  575.       c_ptr = &cave[j][k];
  576.       if ((c_ptr->fval >= 1) && (c_ptr->fval <= 7 ) && (c_ptr->fval != 3))
  577.         if ((c_ptr->tptr == 0) && (c_ptr->cptr != 1))
  578.           {
  579.         if (c_ptr->cptr > 1)     /* Creature there already?       */
  580.           {
  581.             /* Some critters are cannibalistic!       */
  582.             if (c_list[z].cmove & 0x00080000)
  583.               {
  584.             delete_monster((int)c_ptr->cptr);
  585.             place_monster(j, k, z, slp);
  586.             check_mon_lite(j, k);
  587.             mon_tot_mult++;
  588.               }
  589.           }
  590.         else
  591.           /* All clear,  place a monster    */
  592.           {
  593.             place_monster(j, k, z, slp);
  594.             check_mon_lite(j, k);
  595.             mon_tot_mult++;
  596.           }
  597.         i = 18;
  598.           }
  599.     }
  600.       i++;
  601.     }
  602.   while (i <= 18);
  603. }
  604.  
  605.  
  606. /* Creates objects nearby the coordinates given        -RAK-      */
  607. /* BUG: Because of the range, objects can actually be placed into */
  608. /*      areas closed off to the player, this is rarely noticeable, */
  609. /*      and never a problem to the game.                          */
  610. summon_object(y, x, num, typ)
  611. int y, x, num, typ;
  612. {
  613.   register int i, j, k;
  614.   register cave_type *c_ptr;
  615.  
  616.   do
  617.     {
  618.       i = 0;
  619.       do
  620.     {
  621.       j = y - 3 + randint(5);
  622.       k = x - 3 + randint(5);
  623.       if (in_bounds(j, k))
  624.         {
  625.           c_ptr = &cave[j][k];
  626.           if ((c_ptr->fval >= 1) && (c_ptr->fval <= 7) &&
  627.           (c_ptr->fval != 3))
  628.         if (c_ptr->tptr == 0)
  629.           {
  630.             switch(typ)                 /* Select type of object */
  631.               {
  632.               case 1:  place_object(j, k); break;
  633.               case 2:  place_gold(j, k); break;
  634.               case 3:
  635.             if (randint(100) < 50)
  636.               place_object(j, k);
  637.             else
  638.               place_gold(j, k);
  639.             break;
  640.               default:
  641.             break;
  642.               }
  643.             if (test_light(j, k))
  644.               lite_spot(j, k);
  645.             i = 10;
  646.           }
  647.         }
  648.       i++;
  649.     }
  650.       while (i <= 10);
  651.       num--;
  652.     }
  653.   while (num != 0);
  654. }
  655.  
  656.  
  657. /* Deletes object from given location            -RAK-    */
  658. int delete_object(y, x)
  659. int y, x;
  660. {
  661.   register int delete;
  662.   register cave_type *c_ptr;
  663.  
  664.   delete = FALSE;
  665.   c_ptr = &cave[y][x];
  666.   if ((t_list[c_ptr->tptr].tval == 109) || (t_list[c_ptr->tptr].tval == 105)
  667.       || (t_list[c_ptr->tptr].tval == 104))
  668.     c_ptr->fval = corr_floor2.ftval;
  669.   c_ptr->fopen = TRUE;
  670.   pusht((int)c_ptr->tptr);
  671.   c_ptr->tptr = 0;
  672.   c_ptr->fm = FALSE;
  673.   if (test_light(y, x))
  674.     {
  675.       lite_spot(y, x);
  676.       delete = TRUE;
  677.     }
  678.   else
  679.     unlite_spot(y, x);
  680.   return(delete);
  681. }
  682.  
  683.  
  684. /* Allocates objects upon a creatures death        -RAK-    */
  685. /* Oh well,  another creature bites the dust...  Reward the victor*/
  686. /* based on flags set in the main creature record                */
  687. monster_death(y, x, flags)
  688. int y, x;
  689. register bitset_t flags;
  690. {
  691.   register int i;
  692.  
  693.   if (flags & 0x01000000)
  694.     i = 1;
  695.   else
  696.     i = 0;
  697.   if (flags & 0x02000000)
  698.     i += 2;
  699.   if (flags & 0x04000000)
  700.     if (randint(100) < 60)
  701.       summon_object(y, x, 1, i);
  702.   if (flags & 0x08000000)
  703.     if (randint(100) < 90)
  704.       summon_object(y, x, 1, i);
  705.   if (flags & 0x10000000)
  706.     summon_object(y, x, randint(2), i);
  707.   if (flags & 0x20000000)
  708.     summon_object(y, x, damroll("2d2"), i);
  709.   if (flags & 0x40000000)
  710.     summon_object(y, x, damroll("4d3"), i);
  711.   if (flags & 0x80000000)
  712.     {
  713.       total_winner = TRUE;
  714.       prt_winner();
  715.       msg_print("*** CONGRATULATIONS *** You have won the game...");
  716.       msg_print("Use <CONTROL>-K when you are ready to quit.");
  717.     }
  718. }
  719.  
  720.  
  721. /* Decreases monsters hit points and deletes monster if needed.    */
  722. /* (Picking on my babies...)                             -RAK-   */
  723. int mon_take_hit(monptr, dam)
  724. int monptr, dam;
  725. {
  726.   register int i;
  727.   double acc_tmp;
  728.   register monster_type *m_ptr;
  729.   register struct misc *p_ptr;
  730.   register creature_type *c_ptr;
  731.   int m_take_hit;
  732.  
  733.   m_ptr = &m_list[monptr];
  734.   m_ptr->hp -= dam;
  735.   m_ptr->csleep = 0;
  736.   if (m_ptr->hp < 0)
  737.     {
  738.       monster_death((int)m_ptr->fy, (int)m_ptr->fx,c_list[m_ptr->mptr].cmove);
  739.       c_ptr = &c_list[m_ptr->mptr];
  740.       p_ptr = &py.misc;
  741.       acc_tmp = c_ptr->mexp*((c_ptr->level+0.1)/p_ptr->lev);
  742.       i = (int)(acc_tmp);
  743.       acc_exp += (acc_tmp - i);
  744.       if (acc_exp > 1)
  745.     {
  746.       i++;
  747.       acc_exp -= 1.0;
  748.     }
  749.       p_ptr->exp += i;
  750.       if (i > 0)  prt_experience();
  751.       m_take_hit = m_ptr->mptr;
  752.       delete_monster(monptr);
  753.     }
  754.   else
  755.     m_take_hit = -1;
  756.   return(m_take_hit);
  757. }
  758.  
  759.  
  760. /* Special damage due to magical abilities of object    -RAK-    */
  761. int tot_dam(item, tdam, monster)
  762. treasure_type item;
  763. register int tdam;
  764. creature_type monster;
  765. {
  766.   register treasure_type *i_ptr;
  767.   register creature_type *m_ptr;
  768.  
  769.   i_ptr = &item;
  770.   if (((i_ptr->tval >= 10) && (i_ptr->tval <= 12)) ||
  771.       ((i_ptr->tval >= 20) && (i_ptr->tval <= 23)) ||
  772.       (i_ptr->tval == 77))
  773.     {
  774.       m_ptr = &monster;
  775.       /* Slay Dragon  */
  776.       if ((m_ptr->cdefense & 0x0001) && (i_ptr->flags & 0x00002000))
  777.     tdam = tdam * 4;
  778.       /* Slay Undead  */
  779.       else if ((m_ptr->cdefense & 0x0008) && (i_ptr->flags & 0x00010000))
  780.     tdam = tdam * 3;
  781.       /* Slay Monster  */
  782.       else if ((m_ptr->cdefense & 0x0002) && (i_ptr->flags & 0x00004000))
  783.     tdam = tdam * 2;
  784.       /* Slay Evil     */
  785.       else if ((m_ptr->cdefense & 0x0004) && (i_ptr->flags & 0x00008000))
  786.     tdam = tdam * 2;
  787.       /* Frost         */
  788.       else if ((m_ptr->cdefense & 0x0010) && (i_ptr->flags & 0x00020000))
  789.     tdam = tdam * 1.5;
  790.       /* Fire         */
  791.       else if ((m_ptr->cdefense & 0x0020) && (i_ptr->flags & 0x00040000))
  792.     tdam = tdam * 1.5;
  793.     }
  794.   return(tdam);
  795. }
  796.  
  797.  
  798. /* Player attacks a (poor, defenseless) creature     -RAK-    */
  799. int py_attack(y, x)
  800. int y, x;
  801. {
  802.   register int k, blows;
  803.   int i, j, tot_tohit, attack;
  804.   vtype m_name, out_val;
  805.   register treasure_type *i_ptr;
  806.   register struct misc *p_ptr;
  807.  
  808.   attack = FALSE;
  809.   i = cave[y][x].cptr;
  810.   j = m_list[i].mptr;
  811.   m_list[i].csleep = 0;
  812.   /* Does the player know what he's fighting?      */
  813.   if ((0x10000 & c_list[j].cmove) && (!py.flags.see_inv))
  814.     (void) strcpy(m_name, "it");
  815.   else if (py.flags.blind > 0)
  816.     (void) strcpy(m_name, "it");
  817.   else if (!m_list[i].ml)
  818.     (void) strcpy(m_name, "it");
  819.   else
  820.     (void) sprintf(m_name, "the %s", c_list[j].name);
  821.   if (inventory[INVEN_WIELD].tval != 0)         /* Proper weapon */
  822.     blows = attack_blows((int)inventory[INVEN_WIELD].weight, &tot_tohit);
  823.   else                                    /* Bare hands?   */
  824.     {
  825.       blows = 2;
  826.       tot_tohit = -3;
  827.     }
  828.   if ((inventory[INVEN_WIELD].tval >= 10) && (inventory[INVEN_WIELD].tval <= 12))
  829.     /* Fix for arrows */
  830.     blows = 1;
  831.   tot_tohit += py.misc.ptohit;
  832.   /* Loop for number of blows,  trying to hit the critter...        */
  833.   p_ptr = &py.misc;
  834.   do
  835.     {
  836.       if (test_hit(p_ptr->bth, (int)p_ptr->lev, tot_tohit, (int)c_list[j].ac))
  837.     {
  838.       (void) sprintf(out_val, "You hit %s.", m_name);
  839.       msg_print(out_val);
  840.       i_ptr = &inventory[INVEN_WIELD];
  841.       if (i_ptr->tval != 0)           /* Weapon?       */
  842.         {
  843.           k = damroll(i_ptr->damage);
  844.           k = tot_dam(inventory[INVEN_WIELD], k, c_list[j]);
  845.           k = critical_blow((int)i_ptr->weight, tot_tohit, k);
  846.         }
  847.       else                        /* Bare hands!?  */
  848.         {
  849.           k = damroll(bare_hands);
  850.           k = critical_blow(1, 0, k);
  851.         }
  852.       k += p_ptr->ptodam;
  853.       if (k < 0)  k = 0;
  854.       /* See if we done it in...                               */
  855.       if (mon_take_hit(i, k) >= 0)
  856.         {
  857.           (void) sprintf(out_val, "You have slain %s.", m_name);
  858.           msg_print(out_val);
  859.           blows = 0;
  860.           attack = FALSE;
  861.         }
  862.       else
  863.         attack = TRUE;  /* If creature hit,  but alive...*/
  864.       i_ptr = &inventory[INVEN_WIELD];
  865.       if ((i_ptr->tval >= 10) && (i_ptr->tval <= 12)) /* Use missiles up*/
  866.         {
  867.           i_ptr->number--;
  868.           if (i_ptr->number == 0)
  869.         {
  870.           inven_weight = inven_weight - i_ptr->weight;
  871.           equip_ctr--;
  872.           inventory[INVEN_MAX] = inventory[INVEN_WIELD];
  873.           inventory[INVEN_WIELD] = blank_treasure;
  874.           py_bonuses(inventory[INVEN_MAX], -1);
  875.         }
  876.         }
  877.     }
  878.       else
  879.     {
  880.       (void) sprintf(out_val, "You miss %s.", m_name);
  881.       msg_print(out_val);
  882.     }
  883.       blows--;
  884.     }
  885.   while (blows >= 1);
  886.   return(attack);
  887. }
  888.  
  889.  
  890. /* Moves player from one space to another...        -RAK-    */
  891. /* Note: This routine has been pre-declared; see that for argument*/
  892. move_char(dir)
  893. int dir;
  894. {
  895.   int test_row, test_col;
  896.   register int i, j;
  897.   register cave_type *c_ptr, *d_ptr;
  898.  
  899.   test_row = char_row;
  900.   test_col = char_col;
  901.   if (py.flags.confused > 0)          /* Confused?             */
  902.     if (randint(4) > 1)               /* 75% random movement   */
  903.       if (dir != 5)                   /* Never random if sitting*/
  904.     {
  905.       dir = randint(9);
  906.       find_flag = FALSE; /* no need for move_light () */
  907.     }
  908.   if (move(dir, &test_row, &test_col))    /* Legal move?           */
  909.     {
  910.       c_ptr = &cave[test_row][test_col];
  911.       if (c_ptr->cptr < 2)                   /* No creature?          */
  912.     {
  913.       if (c_ptr->fopen)                  /* Open floor spot       */
  914.         {
  915.           /* Move character record (-1)            */
  916.           move_rec(char_row, char_col, test_row, test_col);
  917.           /* Check for new panel                   */
  918.           if (get_panel(test_row, test_col))
  919.         prt_map();
  920.           /* Check to see if he should stop        */
  921.           if (find_flag)
  922.         area_affect(dir, test_row, test_col);
  923.           /* Check to see if he notices something  */
  924.           if (py.flags.blind < 1)
  925.         /* fos may be negative if have good rings of searching */
  926.         if ((py.misc.fos <= 1) || (randint(py.misc.fos) == 1) ||
  927.             (search_flag))
  928.           search(test_row, test_col, py.misc.srh);
  929.           /* An object is beneath him...           */
  930.           if (c_ptr->tptr != 0)
  931.         carry(test_row, test_col);
  932.           /* Move the light source                 */
  933.           move_light(char_row, char_col, test_row, test_col);
  934.           /* A room of light should be lit...      */
  935.           if (c_ptr->fval == lopen_floor.ftval)
  936.         {
  937.           if (py.flags.blind < 1)
  938.             if (!c_ptr->pl)
  939.               light_room(test_row, test_col);
  940.         }
  941.           /* In doorway of light-room?             */
  942.           else if ((c_ptr->fval == 5) || (c_ptr->fval == 6))
  943.         if (py.flags.blind < 1)
  944.           {
  945.             for (i = (test_row - 1); i <= (test_row + 1); i++)
  946.               for (j = (test_col - 1); j <= (test_col + 1); j++)
  947.             if (in_bounds(i, j))
  948.               {
  949.                 d_ptr = &cave[i][j];
  950.                 if (d_ptr->fval == lopen_floor.ftval)
  951.                   if (!d_ptr->pl)
  952.                 light_room(i, j);
  953.               }
  954.           }
  955.           /* Make final assignments of char co-ords*/
  956.           char_row = test_row;
  957.           char_col = test_col;
  958.         }
  959.       else    /*Can't move onto floor space*/
  960.         /* Try a new direction if in find mode   */
  961.         if (!pick_dir(dir))
  962.           {
  963.         if (find_flag)
  964.           {
  965.             find_flag = FALSE;
  966.             move_light (char_row, char_col, char_row, char_col);
  967.           }
  968.         else if (c_ptr->tptr != 0)
  969.           {
  970.             reset_flag = TRUE;
  971.             if (t_list[c_ptr->tptr].tval == 103)
  972.               msg_print("There is rubble blocking your way.");
  973.             else if (t_list[c_ptr->tptr].tval == 105)
  974.               msg_print("There is a closed door blocking your way.");
  975.           }
  976.         else
  977.           reset_flag = TRUE;
  978.           }
  979.     }
  980.       else        /* Attacking a creature! */
  981.     {
  982.       if (find_flag)
  983.         {
  984.           find_flag = FALSE;
  985.           move_light(char_row, char_col, char_row, char_col);
  986.         }
  987.       if (py.flags.afraid < 1)    /* Coward?       */
  988.         (void) py_attack(test_row, test_col);
  989.       else                            /* Coward!       */
  990.         msg_print("You are too afraid!");
  991.     }
  992.     }
  993. }
  994.  
  995.  
  996. /* Chests have traps too...                -RAK-    */
  997. /* Note: Chest traps are based on the FLAGS value                */
  998. chest_trap(y, x)
  999. int y, x;
  1000. {
  1001.   register int i;
  1002.   int j, k;
  1003.   register treasure_type *t_ptr;
  1004.  
  1005.   t_ptr = &t_list[cave[y][x].tptr];
  1006.   if (0x00000010 & t_ptr->flags)
  1007.     {
  1008.       msg_print("A small needle has pricked you!");
  1009.       if (!py.flags.sustain_str)
  1010.     {
  1011.       py.stats.cstr = de_statp(py.stats.cstr);
  1012.       take_hit(damroll("1d4"), "a poison needle.");
  1013.       print_stat |= 0x0001;
  1014.       msg_print("You feel weakened!");
  1015.       /* adjust misc stats */
  1016.       py_bonuses(blank_treasure, 0);
  1017.     }
  1018.       else
  1019.     msg_print("You are unaffected.");
  1020.     }
  1021.   if (0x00000020 & t_ptr->flags)
  1022.     {
  1023.       msg_print("A small needle has pricked you!");
  1024.       take_hit(damroll("1d6"), "a poison needle.");
  1025.       py.flags.poisoned += 10 + randint(20);
  1026.     }
  1027.   if (0x00000040 & t_ptr->flags)
  1028.     {
  1029.       msg_print("A puff of yellow gas surrounds you!");
  1030.       if (py.flags.free_act)
  1031.     msg_print("You are unaffected.");
  1032.       else
  1033.     {
  1034.       msg_print("You choke and pass out.");
  1035.       py.flags.paralysis = 10 + randint(20);
  1036.     }
  1037.     }
  1038.   if (0x00000080 & t_ptr->flags)
  1039.     {
  1040.       msg_print("There is a sudden explosion!");
  1041.       (void) delete_object(y, x);
  1042.       take_hit(damroll("5d8"), "an exploding chest.");
  1043.     }
  1044.   if (0x00000100 & t_ptr->flags)
  1045.     {
  1046.       for (i = 0; i < 3; i++)
  1047.     {
  1048.       j = y;
  1049.       k = x;
  1050.       (void) summon_monster(&j, &k, FALSE);
  1051.     }
  1052.     }
  1053. }
  1054.  
  1055.  
  1056. /* Opens a closed door or closed chest...        -RAK-    */
  1057. openobject()
  1058. {
  1059.   int y, x, tmp;
  1060.   int flag;
  1061.   char *tmp_str;
  1062.   register cave_type *c_ptr;
  1063.   register treasure_type *t_ptr;
  1064.   register struct misc *p_ptr;
  1065.  
  1066.   y = char_row;
  1067.   x = char_col;
  1068.   if (get_dir("Which direction?", &tmp, &tmp, &y, &x))
  1069.     {
  1070.       c_ptr = &cave[y][x];
  1071.       if (c_ptr->tptr != 0)
  1072.     /* Closed door           */
  1073.     if (t_list[c_ptr->tptr].tval == 105)
  1074.       {
  1075.         t_ptr = &t_list[c_ptr->tptr];
  1076.         if (t_ptr->p1 > 0)   /* It's locked...        */
  1077.           {
  1078.         p_ptr = &py.misc;
  1079.         tmp = p_ptr->disarm + p_ptr->lev + 2*todis_adj() + int_adj();
  1080.         if (py.flags.confused > 0)
  1081.           msg_print("You are too confused to pick the lock.");
  1082.         else if ((tmp-t_ptr->p1) > randint(100))
  1083.           {
  1084.             msg_print("You have picked the lock.");
  1085.             py.misc.exp++;
  1086.             prt_experience();
  1087.             t_ptr->p1 = 0;
  1088.           }
  1089.         else
  1090.           msg_print("You failed to pick the lock.");
  1091.           }
  1092.         else if (t_ptr->p1 < 0)      /* It's stuck    */
  1093.           msg_print("It appears to be stuck.");
  1094.         if (t_ptr->p1 == 0)
  1095.           {
  1096.         t_list[c_ptr->tptr] = door_list[0];
  1097.         c_ptr->fopen = TRUE;
  1098.         lite_spot(y, x);
  1099.           }
  1100.       }
  1101.       /* Open a closed chest...                */
  1102.     else if (t_list[c_ptr->tptr].tval == 2)
  1103.       {
  1104.         p_ptr = &py.misc;
  1105.         tmp = p_ptr->disarm + p_ptr->lev + 2*todis_adj() + int_adj();
  1106.         t_ptr = &t_list[c_ptr->tptr];
  1107.         flag = FALSE;
  1108.         if (0x00000001 & t_ptr->flags)
  1109.           if (py.flags.confused > 0)
  1110.         msg_print("You are too confused to pick the lock.");
  1111.           else if ((tmp-(2*t_ptr->level)) > randint(100))
  1112.         {
  1113.           msg_print("You have picked the lock.");
  1114.           flag = TRUE;
  1115.           py.misc.exp += t_ptr->level;
  1116.           prt_experience();
  1117.         }
  1118.           else
  1119.         msg_print("You failed to pick the lock.");
  1120.         else
  1121.           flag = TRUE;
  1122.         if (flag)
  1123.           {
  1124.         t_ptr->flags &= 0xFFFFFFFE;
  1125.         tmp_str = index(t_ptr->name, '(');
  1126.         if (tmp_str != 0)
  1127.           tmp_str[0] = '\0';
  1128.         (void) strcat(t_ptr->name, " (Empty)");
  1129.         known2(t_ptr->name);
  1130.         t_ptr->cost = 0;
  1131.           }
  1132.         flag = FALSE;
  1133.         /* Was chest still trapped?  (Snicker)   */
  1134.         if ((0x00000001 & t_ptr->flags) == 0)
  1135.           {
  1136.         chest_trap(y, x);
  1137.         if (c_ptr->tptr != 0)
  1138.           flag = TRUE;
  1139.           }
  1140.         /* Chest treasure is allocated as if a creature   */
  1141.         /* had been killed...                            */
  1142.         if (flag)
  1143.           {
  1144.         monster_death(y, x, t_list[c_ptr->tptr].flags);
  1145.         t_list[c_ptr->tptr].flags = 0;
  1146.           }
  1147.       }
  1148.     else
  1149.       msg_print("I do not see anything you can open there.");
  1150.       else
  1151.     msg_print("I do not see anything you can open there.");
  1152.     }
  1153. }
  1154.  
  1155.  
  1156. /* Closes an open door...                -RAK-    */
  1157. closeobject()
  1158. {
  1159.   int y, x, tmp;
  1160.   vtype out_val;
  1161.   register cave_type *c_ptr;
  1162.  
  1163.   y = char_row;
  1164.   x = char_col;
  1165.   if (get_dir("Which direction?", &tmp, &tmp, &y, &x))
  1166.     {
  1167.       c_ptr = &cave[y][x];
  1168.       if (c_ptr->tptr != 0)
  1169.     if (t_list[c_ptr->tptr].tval == 104)
  1170.       if (c_ptr->cptr == 0)
  1171.         if (t_list[c_ptr->tptr].p1 == 0)
  1172.           {
  1173.         t_list[c_ptr->tptr] = door_list[1];
  1174.         c_ptr->fopen = FALSE;
  1175.         lite_spot(y, x);
  1176.           }
  1177.         else
  1178.           msg_print("The door appears to be broken.");
  1179.       else
  1180.         {
  1181.           (void) sprintf(out_val, "The %s is in your way!",
  1182.               c_list[m_list[c_ptr->cptr].mptr].name);
  1183.           msg_print(out_val);
  1184.         }
  1185.     else
  1186.       msg_print("I do not see anything you can close there.");
  1187.       else
  1188.     msg_print("I do not see anything you can close there.");
  1189.     }
  1190. }
  1191.  
  1192.  
  1193. /* Go up one level                    -RAK-    */
  1194. go_up()
  1195. {
  1196.   register cave_type *c_ptr;
  1197.  
  1198.   c_ptr = &cave[char_row][char_col];
  1199.   if (c_ptr->tptr != 0)
  1200.     if (t_list[c_ptr->tptr].tval == 107)
  1201.       {
  1202.     dun_level--;
  1203.     moria_flag = TRUE;
  1204.     msg_print("You enter a maze of up staircases.");
  1205.     msg_print("You pass through a one-way door.");
  1206.       }
  1207.     else
  1208.       msg_print("I see no up staircase here.");
  1209.   else
  1210.     msg_print("I see no up staircase here.");
  1211. }
  1212.  
  1213.  
  1214. /* Go down one level                    -RAK-    */
  1215. go_down()
  1216. {
  1217.   register cave_type *c_ptr;
  1218.  
  1219.   c_ptr = &cave[char_row][char_col];
  1220.   if (c_ptr->tptr != 0)
  1221.     if (t_list[c_ptr->tptr].tval == 108)
  1222.       {
  1223.     dun_level++;
  1224.     moria_flag = TRUE;
  1225.     msg_print("You enter a maze of down staircases.");
  1226.     msg_print("You pass through a one-way door.");
  1227.       }
  1228.     else
  1229.       msg_print("I see no down staircase here.");
  1230.   else
  1231.     msg_print("I see no down staircase here.");
  1232. }
  1233.  
  1234.  
  1235. /* Tunneling through real wall: 10, 11, 12         -RAK-    */
  1236. /* Used by TUNNEL and WALL_TO_MUD                                */
  1237. int twall(y, x, t1, t2)
  1238. int y, x, t1, t2;
  1239. {
  1240.   int res;
  1241.   register cave_type *c_ptr;
  1242.  
  1243.   res = FALSE;
  1244.   c_ptr = &cave[y][x];
  1245.   if (t1 > t2)
  1246.     {
  1247.       if (next_to4(y, x, 1, 2, -1) > 0)
  1248.     {
  1249.       c_ptr->fval  = corr_floor2.ftval;
  1250.       c_ptr->fopen = corr_floor2.ftopen;
  1251.     }
  1252.       else
  1253.     {
  1254.       c_ptr->fval  = corr_floor1.ftval;
  1255.       c_ptr->fopen = corr_floor1.ftopen;
  1256.     }
  1257.       if (test_light(y, x))
  1258.     if (panel_contains(y, x))
  1259.       {
  1260.         if (c_ptr->tptr != 0)
  1261.           msg_print("You have found something!");
  1262.         lite_spot(y, x);
  1263.       }
  1264.       c_ptr->fm = FALSE;
  1265.       c_ptr->pl = FALSE;
  1266.       res = TRUE;
  1267.     }
  1268.   return(res);
  1269. }
  1270.  
  1271.  
  1272. /* Tunnels through rubble and walls            -RAK-    */
  1273. /* Must take into account: secret doors,  special tools           */
  1274. tunnel(y, x)
  1275. int y, x;
  1276. {
  1277.   register int i, tabil;
  1278.   register cave_type *c_ptr;
  1279.   register treasure_type *i_ptr;
  1280.  
  1281.   c_ptr = &cave[y][x];
  1282.   /* Compute the digging ability of player; based on       */
  1283.   /* strength, and type of tool used                       */
  1284.   tabil = py.stats.cstr;
  1285.   if (inventory[INVEN_WIELD].tval != 0)
  1286.     {
  1287.       i_ptr = &inventory[INVEN_WIELD];
  1288.       if (0x20000000 & i_ptr->flags)
  1289.     tabil += 25 + i_ptr->p1*50;
  1290.       /* Regular walls; Granite, magma intrusion, quartz vein  */
  1291.       /* Don't forget the boundary walls, made of titanium (255)*/
  1292.       switch(c_ptr->fval)
  1293.     {
  1294.     case 10:
  1295.       i = randint(1200) + 80;
  1296.       if (twall(y, x, tabil, i))
  1297.         msg_print("You have finished the tunnel.");
  1298.       else
  1299.         msg_print("You tunnel into the granite wall.");
  1300.       break;
  1301.     case 11:
  1302.       i = randint(600) + 10;
  1303.       if (twall(y, x, tabil, i))
  1304.         msg_print("You have finished the tunnel.");
  1305.       else
  1306.         msg_print("You tunnel into the magma intrusion.");
  1307.       break;
  1308.     case 12:
  1309.       i = randint(400) + 10;
  1310.       if (twall(y, x, tabil, i))
  1311.         msg_print("You have finished the tunnel.");
  1312.       else
  1313.         msg_print("You tunnel into the quartz vein.");
  1314.       break;
  1315.     case 15:
  1316.       msg_print("This seems to be permanent rock.");
  1317.       break;
  1318.     default:
  1319.       /* Is there an object in the way?  (Rubble and secret doors)*/
  1320.       if (c_ptr->tptr != 0)
  1321.         {
  1322.           /* Rubble...     */
  1323.           if (t_list[c_ptr->tptr].tval == 103)
  1324.         {
  1325.           if (tabil > randint(180))
  1326.             {
  1327.               pusht((int)c_ptr->tptr);
  1328.               c_ptr->tptr = 0;
  1329.               c_ptr->fm = FALSE;
  1330.               c_ptr->fopen = TRUE;
  1331.               msg_print("You have removed the rubble.");
  1332.               if (randint(10) == 1)
  1333.             {
  1334.               place_object(y, x);
  1335.               if (test_light(y, x))
  1336.                 msg_print("You have found something!");
  1337.             }
  1338.               lite_spot(y, x);
  1339.             }
  1340.           else
  1341.             msg_print("You dig in the rubble...");
  1342.         }
  1343.           /* Secret doors...*/
  1344.           else if (t_list[c_ptr->tptr].tval == 109)
  1345.         {
  1346.           msg_print("You tunnel into the granite wall.");
  1347.           search(char_row, char_col, py.misc.srh);
  1348.         }
  1349.           else
  1350.         msg_print("You can't tunnel through that.");
  1351.         }
  1352.       else
  1353.         msg_print("Tunnel through what?  Empty air???");
  1354.       break;
  1355.     }
  1356.     }
  1357. }
  1358.  
  1359.  
  1360. /* Disarms a trap                    -RAK-    */
  1361. disarm_trap()
  1362. {
  1363.   int y, x, i, tdir;
  1364.   int tot, t1, t2, t3, t4, t5;
  1365.   register cave_type *c_ptr;
  1366.   register treasure_type *i_ptr;
  1367.   char *tmp_str;
  1368.  
  1369.   y = char_row;
  1370.   x = char_col;
  1371.   if (get_dir("Which direction?", &tdir, &i, &y, &x))
  1372.     {
  1373.       c_ptr = &cave[y][x];
  1374.       if (c_ptr->tptr != 0)
  1375.     {
  1376.       t1 = py.misc.disarm; /* Ability to disarm     */
  1377.       t2 = py.misc.lev;    /* Level adjustment      */
  1378.       t3 = 2*todis_adj();    /* Dexterity adjustment  */
  1379.       t4 = int_adj();        /* Intelligence adjustment*/
  1380.       tot = t1 + t2 + t3 + t4;
  1381.       if (py.flags.blind > 0)
  1382.         tot = tot / 5.0;
  1383.       else if (no_light())
  1384.         tot = tot / 2.0;
  1385.       if (py.flags.confused > 0)
  1386.         tot = tot / 3.0;
  1387.       i = t_list[c_ptr->tptr].tval;
  1388.       t5 = t_list[c_ptr->tptr].level;
  1389.       if (i == 102)             /* Floor trap    */
  1390.         {
  1391.           i_ptr = &t_list[c_ptr->tptr];
  1392.           if ((tot - t5) > randint(100))
  1393.         {
  1394.           msg_print("You have disarmed the trap.");
  1395.           py.misc.exp += i_ptr->p1;
  1396.           c_ptr->fm = FALSE;
  1397.           pusht((int)c_ptr->tptr);
  1398.           c_ptr->tptr = 0;
  1399.           move_char(tdir);
  1400.           lite_spot(y, x);
  1401.           prt_experience();
  1402.         }
  1403.           /* avoid randint(0) call */
  1404.           else if ((tot > 5) && (randint(tot) > 5))
  1405.         msg_print("You failed to disarm the trap.");
  1406.           else
  1407.         {
  1408.           msg_print("You set the trap off!");
  1409.           move_char(tdir);
  1410.         }
  1411.         }
  1412.       else if (i == 2)          /* Chest trap    */
  1413.         {
  1414.           i_ptr = &t_list[c_ptr->tptr];
  1415.           if (index(i_ptr->name, '^') != 0)
  1416.         msg_print("I don't see a trap...");
  1417.           else if (0x000001F0 & i_ptr->flags)
  1418.         {
  1419.           if ((tot - t5) > randint(100))
  1420.             {
  1421.               i_ptr->flags &= 0xFFFFFE0F;
  1422.               tmp_str = index(i_ptr->name, '(');
  1423.               if (tmp_str != 0)
  1424.                 tmp_str[0] = '\0';
  1425.               if (0x00000001 & i_ptr->flags)
  1426.             (void) strcat(i_ptr->name, " (Locked)");
  1427.               else
  1428.             (void) strcat(i_ptr->name, " (Disarmed)");
  1429.               msg_print("You have disarmed the chest.");
  1430.               known2(i_ptr->name);
  1431.               py.misc.exp += t5;
  1432.               prt_experience();
  1433.             }
  1434.           else if ((tot > 5) && (randint(tot) > 5))
  1435.             msg_print("You failed to disarm the chest.");
  1436.           else
  1437.             {
  1438.               msg_print("You set a trap off!");
  1439.               known2(i_ptr->name);
  1440.               chest_trap(y, x);
  1441.             }
  1442.         }
  1443.           else
  1444.         msg_print("The chest was not trapped.");
  1445.         }
  1446.       else
  1447.         msg_print("I do not see anything to disarm there.");
  1448.     }
  1449.       else
  1450.     msg_print("I do not see anything to disarm there.");
  1451.     }
  1452. }
  1453.  
  1454.  
  1455. /* Look at an object,  trap,  or monster            -RAK-    */
  1456. /* Note: Looking is a free move,  see where invoked...            */
  1457. look()
  1458. {
  1459.   register int i, j;
  1460.   int y, x;
  1461.   int dir, dummy;
  1462.   int flag;
  1463.   char fchar;
  1464.   register cave_type *c_ptr;
  1465.   bigvtype out_val, tmp_str;
  1466.  
  1467.   flag = FALSE;
  1468.   y = char_row;
  1469.   x = char_col;
  1470.   if (get_dir("Look which direction?", &dir, &dummy, &y, &x))
  1471.     if (py.flags.blind < 1)
  1472.       {
  1473.     y = char_row;
  1474.     x = char_col;
  1475.     i = 0;
  1476.     do
  1477.       {
  1478.         (void) move(dir, &y, &x);
  1479.         c_ptr = &cave[y][x];
  1480.         if (c_ptr->cptr > 1)
  1481.           if (m_list[c_ptr->cptr].ml)
  1482.         {
  1483.           j = m_list[c_ptr->cptr].mptr;
  1484.           fchar = c_list[j].name[0];
  1485.           if (is_a_vowel(fchar))
  1486.             (void) sprintf(out_val, "You see an %s.", c_list[j].name);
  1487.           else
  1488.             (void) sprintf(out_val, "You see a %s.", c_list[j].name);
  1489.           msg_print(out_val);
  1490.           flag = TRUE;
  1491.         }
  1492.         if ((c_ptr->tl) || (c_ptr->pl) || (c_ptr->fm))
  1493.           {
  1494.         if (c_ptr->tptr != 0)
  1495.           if (t_list[c_ptr->tptr].tval == 109)
  1496.             msg_print("You see a granite wall.");
  1497.           else if (t_list[c_ptr->tptr].tval != 101)
  1498.             {
  1499.               inventory[INVEN_MAX] = t_list[c_ptr->tptr];
  1500.               objdes(tmp_str, INVEN_MAX, TRUE);
  1501.               (void) sprintf(out_val, "You see %s", tmp_str);
  1502.               msg_print(out_val);
  1503.               flag = TRUE;
  1504.             }
  1505.         if (!c_ptr->fopen)
  1506.           {
  1507.             flag = TRUE;
  1508.             switch(c_ptr->fval)
  1509.               {
  1510.               case 10: msg_print("You see a granite wall."); break;
  1511.               case 11: msg_print("You see some dark rock."); break;
  1512.               case 12: msg_print("You see a quartz vein."); break;
  1513.               case 15: msg_print("You see a granite wall."); break;
  1514.               default: break;
  1515.               }
  1516.           }
  1517.           }
  1518.         i++;
  1519.       }
  1520.     while ((cave[y][x].fopen) && (i <= MAX_SIGHT));
  1521.     if (!flag)
  1522.       msg_print("You see nothing of interest in that direction.");
  1523.       }
  1524.     else
  1525.       msg_print("You can't see a damn thing!");
  1526. }
  1527.  
  1528.  
  1529. /* Add to the players food time                -RAK-    */
  1530. add_food(num)
  1531. int num;
  1532. {
  1533.   register struct flags *p_ptr;
  1534.  
  1535.   p_ptr = &py.flags;
  1536.   if (p_ptr->food < 0)  p_ptr->food = 0;
  1537.   p_ptr->food += num;
  1538.   if (p_ptr->food > PLAYER_FOOD_MAX)
  1539.     {
  1540.       msg_print("You are bloated from overeating.");
  1541.       p_ptr->slow = (p_ptr->food - PLAYER_FOOD_MAX) / 50;
  1542.       p_ptr->food = PLAYER_FOOD_MAX;
  1543.     }
  1544.   else if (p_ptr->food > PLAYER_FOOD_FULL)
  1545.     msg_print("You are full.");
  1546. }
  1547.  
  1548.  
  1549. /* Describe number of remaining charges...        -RAK-    */
  1550. desc_charges(item_val)
  1551. int item_val;
  1552. {
  1553.   register int rem_num;
  1554.   vtype out_val;
  1555.  
  1556.   if (index(inventory[item_val].name, '^') == 0)
  1557.     {
  1558.       rem_num = inventory[item_val].p1;
  1559.       (void) sprintf(out_val, "You have %d charges remaining.", rem_num);
  1560.       msg_print(out_val);
  1561.     }
  1562. }
  1563.  
  1564.  
  1565. /* Describe amount of item remaining...            -RAK-    */
  1566. desc_remain(item_val)
  1567. int item_val;
  1568. {
  1569.   bigvtype out_val, tmp_str;
  1570.   register treasure_type *i_ptr;
  1571.  
  1572.   inventory[INVEN_MAX] = inventory[item_val];
  1573.   i_ptr = &inventory[INVEN_MAX];
  1574.   i_ptr->number--;
  1575.   objdes(tmp_str, INVEN_MAX, TRUE);
  1576.   tmp_str[strlen(tmp_str)-1] = '\0';
  1577.   (void) sprintf(out_val, "You have %s.", tmp_str);
  1578.   msg_print(out_val);
  1579. }
  1580.  
  1581.  
  1582. inven_throw(item_val)
  1583. int item_val;
  1584. {
  1585.   register treasure_type *i_ptr;
  1586.  
  1587.   inventory[INVEN_MAX] = inventory[item_val];
  1588.   inventory[INVEN_MAX].number = 1;
  1589.   i_ptr = &inventory[item_val];
  1590.   if ((i_ptr->number > 1) && (i_ptr->subval > 511))
  1591.     {
  1592.       i_ptr->number--;
  1593.       inven_weight -= i_ptr->weight;
  1594.     }
  1595.   else
  1596.     inven_destroy(item_val);
  1597. }
  1598.  
  1599.  
  1600. facts(tbth, tpth, tdam, tdis)
  1601. int *tbth, *tpth, *tdam, *tdis;
  1602. {
  1603.   register int tmp_weight;
  1604.   register treasure_type *i_ptr;
  1605.  
  1606.   i_ptr = &inventory[INVEN_MAX];
  1607.   if (i_ptr->weight < 1)
  1608.     tmp_weight = 1;
  1609.   else
  1610.     tmp_weight = i_ptr->weight;
  1611.  
  1612.   /* Throwing objects            */
  1613.   *tdam = damroll(i_ptr->damage) + i_ptr->todam;
  1614.   *tbth = (py.misc.bthb*0.75);
  1615.   *tpth = py.misc.ptohit + i_ptr->tohit;
  1616.   *tdis = (((py.stats.cstr+20)*10)/tmp_weight);
  1617.   if (*tdis > 10)  *tdis = 10;
  1618.  
  1619.   /* Using Bows,  slings,  or crossbows    */
  1620.   if (inventory[INVEN_WIELD].tval == 20)
  1621.     switch(inventory[INVEN_WIELD].p1)
  1622.       {
  1623.       case 1:
  1624.     if (i_ptr->tval == 10)        /* Sling and Bullet       */
  1625.       {
  1626.         *tbth = py.misc.bthb;
  1627.         *tpth += inventory[INVEN_WIELD].tohit;
  1628.         *tdam += 2;
  1629.         *tdis = 20;
  1630.       }
  1631.     break;
  1632.       case 2:
  1633.     if (i_ptr->tval == 12)        /* Short Bow and Arrow    */
  1634.       {
  1635.         *tbth = py.misc.bthb;
  1636.         *tpth += inventory[INVEN_WIELD].tohit;
  1637.         *tdam += 2;
  1638.         *tdis = 25;
  1639.       }
  1640.     break;
  1641.       case 3:
  1642.     if (i_ptr->tval == 12)        /* Long Bow and Arrow     */
  1643.       {
  1644.         *tbth = py.misc.bthb;
  1645.         *tpth += inventory[INVEN_WIELD].tohit;
  1646.         *tdam += 3;
  1647.         *tdis = 30;
  1648.       }
  1649.     break;
  1650.       case 4:
  1651.     if (i_ptr->tval == 12)        /* Composite Bow and Arrow*/
  1652.       {
  1653.         *tbth = py.misc.bthb;
  1654.         *tpth += inventory[INVEN_WIELD].tohit;
  1655.         *tdam += 4;
  1656.         *tdis = 35;
  1657.       }
  1658.     break;
  1659.       case 5:
  1660.     if (i_ptr->tval == 11)        /* Light Crossbow and Bolt*/
  1661.       {
  1662.         *tbth = py.misc.bthb;
  1663.         *tpth += inventory[INVEN_WIELD].tohit;
  1664.         *tdam += 2;
  1665.         *tdis = 25;
  1666.       }
  1667.     break;
  1668.       case 6:
  1669.     if (i_ptr->tval == 11)        /* Heavy Crossbow and Bolt*/
  1670.       {
  1671.         *tbth = py.misc.bthb;
  1672.         *tpth += inventory[INVEN_WIELD].tohit;
  1673.         *tdam += 4;
  1674.         *tdis = 35;
  1675.         break;
  1676.       }
  1677.       }
  1678. }
  1679.  
  1680.  
  1681. drop_throw(y, x)
  1682. int y, x;
  1683. {
  1684.   register int i, j, k;
  1685.   int flag, cur_pos;
  1686.   bigvtype out_val, tmp_str;
  1687.   register cave_type *c_ptr;
  1688.  
  1689.   flag = FALSE;
  1690.   i = y;
  1691.   j = x;
  1692.   k = 0;
  1693.   if (randint(10) > 1)
  1694.     {
  1695.       do
  1696.     {
  1697.       if (in_bounds(i, j))
  1698.         {
  1699.           c_ptr = &cave[i][j];
  1700.           if (c_ptr->fopen)
  1701.         if (c_ptr->tptr == 0)
  1702.           flag = TRUE;
  1703.         }
  1704.       if (!flag)
  1705.         {
  1706.           i = y + randint(3) - 2;
  1707.           j = x + randint(3) - 2;
  1708.           k++;
  1709.         }
  1710.     }
  1711.       while ((!flag) && (k <= 9));
  1712.     }
  1713.   if (flag)
  1714.     {
  1715.       popt(&cur_pos);
  1716.       cave[i][j].tptr = cur_pos;
  1717.       t_list[cur_pos] = inventory[INVEN_MAX];
  1718.       if (test_light(i, j))
  1719.     lite_spot(i, j);
  1720.     }
  1721.   else
  1722.     {
  1723.       objdes(tmp_str, INVEN_MAX, FALSE);
  1724.       (void) sprintf(out_val, "The %s disappears", tmp_str);
  1725.       msg_print(out_val);
  1726.     }
  1727. }
  1728.  
  1729. /* Throw an object across the dungeon...         -RAK-    */
  1730. /* Note: Flasks of oil do fire damage                            */
  1731. /* Note: Extra damage and chance of hitting when missiles are used*/
  1732. /*       with correct weapon.  I.E.  wield bow and throw arrow.  */
  1733. throw_object()
  1734. {
  1735.   int item_val, tbth, tpth, tdam, tdis;
  1736.   int y_dumy, x_dumy, dumy;
  1737.   int y, x, oldy, oldx, dir, cur_dis;
  1738.   int redraw, flag;
  1739.   char tchar[2];
  1740.   bigvtype out_val, tmp_str; vtype m_name;
  1741.   register treasure_type *i_ptr;
  1742.   register cave_type *c_ptr;
  1743.   register monster_type *m_ptr;
  1744.   register int i;
  1745.  
  1746.   redraw = FALSE;
  1747.   if (inven_ctr == 0)
  1748.     msg_print("But you are not carrying anything.");
  1749.   else if (get_item(&item_val, "Fire/Throw which one?",
  1750.             &redraw, 0, inven_ctr-1))
  1751.     {
  1752.       if (redraw)
  1753.     draw_cave();
  1754.       y_dumy = char_row;
  1755.       x_dumy = char_col;
  1756.       if (get_dir("Which direction?", &dir, &dumy, &y_dumy, &x_dumy))
  1757.     {
  1758.       desc_remain(item_val);
  1759.       if (py.flags.confused > 0)
  1760.         {
  1761.           msg_print("You are confused...");
  1762.           do
  1763.         {
  1764.           dir = randint(9);
  1765.         }
  1766.           while (dir == 5);
  1767.         }
  1768.       inven_throw(item_val);
  1769.       facts(&tbth, &tpth, &tdam, &tdis);
  1770.       i_ptr = &inventory[INVEN_MAX];
  1771.       tchar[0] = i_ptr->tchar;
  1772.       tchar[1] = '\0';
  1773.       flag = FALSE;
  1774.       y = char_row;
  1775.       x = char_col;
  1776.       oldy = char_row;
  1777.       oldx = char_col;
  1778.       cur_dis = 0;
  1779.       do
  1780.         {
  1781.           (void) move(dir, &y, &x);
  1782.           cur_dis++;
  1783.           if (test_light(oldy, oldx))
  1784.         lite_spot(oldy, oldx);
  1785.           if (cur_dis > tdis)  flag = TRUE;
  1786.           c_ptr = &cave[y][x];
  1787.           if ((c_ptr->fopen) && (!flag))
  1788.         {
  1789.           if (c_ptr->cptr > 1)
  1790.             {
  1791.               flag = TRUE;
  1792.               m_ptr = &m_list[c_ptr->cptr];
  1793.               tbth = tbth - cur_dis;
  1794.               if (test_hit(tbth, (int)py.misc.lev, tpth,
  1795.                    (int)c_list[m_ptr->mptr].ac))
  1796.             {
  1797.               i = m_ptr->mptr;
  1798.               objdes(tmp_str, INVEN_MAX, FALSE);
  1799.               /* Does the player know what he's fighting?      */
  1800.               if ((0x10000 & c_list[i].cmove) &&
  1801.                   (!py.flags.see_inv))
  1802.                 (void) strcpy(m_name, "it");
  1803.               else if (py.flags.blind > 0)
  1804.                 (void) strcpy(m_name, "it");
  1805.               else if (!m_ptr->ml)
  1806.                 (void) strcpy(m_name, "it");
  1807.               else
  1808.                 (void) sprintf(m_name, "the %s", c_list[i].name);
  1809.  
  1810.               (void) sprintf(out_val,"The %s hits %s.", tmp_str,
  1811.                   m_name);
  1812.               msg_print(out_val);
  1813.               tdam = tot_dam(inventory[INVEN_MAX], tdam,
  1814.                      c_list[i]);
  1815.               i_ptr = &inventory[INVEN_MAX];
  1816.               tdam = critical_blow((int)i_ptr->weight, tpth, tdam);
  1817.               i = mon_take_hit((int)c_ptr->cptr, tdam);
  1818.               if (i >= 0)
  1819.                 {
  1820.                   (void) sprintf(out_val,"You have killed %s.",
  1821.                       m_name);
  1822.                   msg_print(out_val);
  1823.                 }
  1824.             }
  1825.               else
  1826.             drop_throw(oldy, oldx);
  1827.             }
  1828.           else
  1829.             {
  1830.               if (panel_contains(y, x))
  1831.             if (test_light(y, x))
  1832.               {
  1833.                 print(tchar, y, x);
  1834.                 put_qio();
  1835.               }
  1836.             }
  1837.         }
  1838.           else
  1839.         {
  1840.           flag = TRUE;
  1841.           drop_throw(oldy, oldx);
  1842.         }
  1843.           oldy = y;
  1844.           oldx = x;
  1845.         }
  1846.       while (!flag);
  1847.     }
  1848.     }
  1849.   else
  1850.     if (redraw)
  1851.       draw_cave();
  1852. }
  1853.  
  1854.  
  1855. /* Bash open a door or chest                -RAK-    */
  1856. /* Note: Affected by strength and weight of character            */
  1857. bash()
  1858. {
  1859.   int y, x, tmp;
  1860.   int old_ptodam, old_ptohit, old_bth;
  1861.   vtype tmp_str, m_name;
  1862.   register cave_type *c_ptr;
  1863.   register treasure_type *i_ptr, *t_ptr;
  1864.   register player_type *p_ptr;
  1865.   register monster_type *m_ptr;
  1866.  
  1867.   y = char_row;
  1868.   x = char_col;
  1869.   if (get_dir("Which direction?", &tmp, &tmp, &y, &x))
  1870.     {
  1871.       c_ptr = &cave[y][x];
  1872.       if (c_ptr->cptr > 1)
  1873.     {
  1874.       if (py.flags.afraid > 0)
  1875.         msg_print("You are afraid!");
  1876.       else
  1877.         {
  1878.           /* Save old values of attacking  */
  1879.           inventory[INVEN_MAX] = inventory[INVEN_WIELD];
  1880.           old_ptohit = py.misc.ptohit;
  1881.           old_ptodam = py.misc.ptodam;
  1882.           old_bth    = py.misc.bth;
  1883.           /* Use these values              */
  1884.           inventory[INVEN_WIELD] = blank_treasure;
  1885.           i_ptr = &inventory[INVEN_WIELD];
  1886.           (void) strcpy(i_ptr->damage, inventory[26].damage);
  1887.           i_ptr->weight = py.stats.cstr;
  1888.           i_ptr->tval   = 1;
  1889.           p_ptr = &py;
  1890.           p_ptr->misc.bth    = ((p_ptr->stats.cstr+
  1891.                      p_ptr->misc.wt)/6.0);
  1892.           p_ptr->misc.ptohit = 0;
  1893.           p_ptr->misc.ptodam = (p_ptr->misc.wt/75.0) + 1;
  1894.           if (py_attack(y, x))
  1895.         {
  1896.           m_ptr = &m_list[c_ptr->cptr];
  1897.           m_ptr->stunned += randint(2) + 1;
  1898.           if (m_ptr->stunned > 24)  m_ptr->stunned = 24;
  1899.           /* Does the player know what he's fighting?      */
  1900.           if ((0x10000 & c_list[m_ptr->mptr].cmove) &&
  1901.               (!py.flags.see_inv))
  1902.             (void) strcpy(m_name, "It");
  1903.           else if (py.flags.blind > 0)
  1904.             (void) strcpy(m_name, "It");
  1905.           else if (!m_list[c_ptr->cptr].ml)
  1906.             (void) strcpy(m_name, "It");
  1907.           else
  1908.             (void) sprintf(m_name, "The %s", c_list[m_ptr->mptr].name);
  1909.           (void) sprintf(tmp_str, "%s appears stunned!",
  1910.               m_name);
  1911.           msg_print(tmp_str);
  1912.         }
  1913.           /* Restore old values            */
  1914.           inventory[INVEN_WIELD] = inventory[INVEN_MAX];
  1915.           py.misc.ptohit = old_ptohit;
  1916.           py.misc.ptodam = old_ptodam;
  1917.           py.misc.bth    = old_bth;
  1918.           if (randint(140) > py.stats.cdex)
  1919.         {
  1920.           msg_print("You are off-balance.");
  1921.           py.flags.paralysis = randint(3);
  1922.         }
  1923.         }
  1924.     }
  1925.       else if (c_ptr->tptr != 0)
  1926.     {
  1927.       t_ptr = &t_list[c_ptr->tptr];
  1928.       if (t_ptr->tval == 105)
  1929.         {
  1930.           msg_print("You smash into the door!");
  1931.           p_ptr = &py;
  1932.           if (test_hit((int)(p_ptr->misc.wt+p_ptr->stats.cstr), 0, 0,
  1933.                abs(t_ptr->p1)+150))
  1934.         {
  1935.           msg_print("The door crashes open!");
  1936.           t_list[c_ptr->tptr] = door_list[0];
  1937.           t_ptr->p1 = 1;
  1938.           c_ptr->fopen = TRUE;
  1939.           lite_spot(y, x);
  1940.         }
  1941.           else
  1942.         {
  1943.           msg_print("The door holds firm.");
  1944.           py.flags.paralysis = 2;
  1945.         }
  1946.         }
  1947.       else if (t_ptr->tval == 2)
  1948.         {
  1949.           if (randint(10) == 1)
  1950.         {
  1951.           msg_print("You have destroyed the chest...");
  1952.           msg_print("and it's contents!");
  1953.           (void) strcpy(t_ptr->name, "& ruined chest");
  1954.           t_ptr->flags = 0;
  1955.         }
  1956.           else if (0x00000001 & t_ptr->flags)
  1957.         if (randint(10) == 1)
  1958.           {
  1959.             msg_print("The lock breaks open!");
  1960.             t_ptr->flags &= 0xFFFFFFFE;
  1961.           }
  1962.         }
  1963.       else
  1964.         msg_print("I do not see anything you can bash there.");
  1965.     }
  1966.       else
  1967.     msg_print("I do not see anything you can bash there.");
  1968.     }
  1969. }
  1970.  
  1971.  
  1972. /* Jam a closed door                    -RAK-    */
  1973. jamdoor()
  1974. {
  1975.   int y, x, tmp;
  1976.   int i, j;
  1977.   register cave_type *c_ptr;
  1978.   register treasure_type *t_ptr, *i_ptr;
  1979.   char tmp_str[80];
  1980.  
  1981.   y = char_row;
  1982.   x = char_col;
  1983.   if (get_dir("Which direction?", &tmp, &tmp, &y, &x))
  1984.     {
  1985.       c_ptr = &cave[y][x];
  1986.       if (c_ptr->tptr != 0)
  1987.     {
  1988.       t_ptr = &t_list[c_ptr->tptr];
  1989.       if (t_ptr->tval == 105)
  1990.         if (c_ptr->cptr == 0)
  1991.           {
  1992.         if (find_range(13, -1, &i, &j))
  1993.           {
  1994.             msg_print("You jam the door with a spike.");
  1995.             i_ptr = &inventory[i];
  1996.             if (i_ptr->number > 1)
  1997.             i_ptr->number--;
  1998.             else
  1999.               inven_destroy(i);
  2000.             t_ptr->p1 = -abs(i_ptr->p1) - 20;
  2001.           }
  2002.         else
  2003.           msg_print("But you have no spikes...");
  2004.           }
  2005.         else
  2006.           {
  2007.         (void) sprintf(tmp_str, "The %s is in your way!",
  2008.             c_list[m_list[c_ptr->cptr].mptr].name);
  2009.         msg_print(tmp_str);
  2010.         }
  2011.       else if (t_ptr->tval == 104)
  2012.         msg_print("The door must be closed first.");
  2013.       else
  2014.         msg_print("That isn't a door!");
  2015.     }
  2016.       else
  2017.     msg_print("That isn't a door!");
  2018.     }
  2019. }
  2020.  
  2021.  
  2022. /* Refill the players lamp                -RAK-    */
  2023. refill_lamp()
  2024. {
  2025.   int i, j;
  2026.   register int k;
  2027.   register treasure_type *i_ptr;
  2028.  
  2029.   k = inventory[32].subval;
  2030.   if ((k > 0) && (k < 10))
  2031.     if (find_range(77, -1, &i, &j))
  2032.       {
  2033.     i_ptr = &inventory[32];
  2034.     i_ptr->p1 += inventory[i].p1;
  2035.     if (i_ptr->p1 > OBJ_LAMP_MAX)
  2036.       {
  2037.         i_ptr->p1 = OBJ_LAMP_MAX;
  2038.         msg_print ("Your lamp overflows, spilling oil on the ground.");
  2039.         msg_print("Your lamp is full.");
  2040.       }
  2041.     else if (i_ptr->p1 > OBJ_LAMP_MAX/2)
  2042.       msg_print ("Your lamp is more than half full.");
  2043.     else if (i_ptr->p1 == OBJ_LAMP_MAX/2)
  2044.       msg_print ("Your lamp is half full.");
  2045.     else
  2046.       msg_print ("Your lamp is less than half full.");
  2047.     desc_remain(i);
  2048.     inven_destroy(i);
  2049.       }
  2050.     else
  2051.       msg_print("You have no oil.");
  2052.   else
  2053.     msg_print("But you are not using a lamp.");
  2054. }
  2055.