home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / mor4873s.lzh / MORIA1.C < prev    next >
C/C++ Source or Header  |  1988-12-14  |  49KB  |  2,062 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. byteint de_statt();
  19. byteint in_statt();
  20.  
  21. /* global flags */
  22. extern int moria_flag;        /* Next level when true  */
  23. extern int search_flag;       /* Player is searching   */
  24. extern int teleport_flag;     /* Handle teleport traps  */
  25. extern int player_light;      /* Player carrying light */
  26. extern int cave_flag;         /* used in get_panel */
  27. extern int light_flag;        /* used in move_light */
  28.  
  29.  
  30. /* Changes stats up or down for magic items        -RAK-    */
  31. change_stat_factor(stat, amount, factor)
  32. register byteint *stat;
  33. int amount, factor;
  34. {
  35.   register int i, j, k;
  36.  
  37.   j = amount * factor;
  38.   if (amount < 0)
  39.     k = -amount;
  40.   else
  41.     k = amount;
  42.   for (i = 0; i < k; i++)
  43.     if (j < 0)
  44.       *stat = de_statt(*stat);
  45.     else
  46.       *stat = in_statt(*stat);
  47. }
  48.  
  49.  
  50. /* Changes speed of monsters relative to player        -RAK-    */
  51. /* Note: When the player is sped up or slowed down, I simply     */
  52. /*       change the speed of all the monsters.  This greatly     */
  53. /*       simplified the logic...                                 */
  54. change_speed(num)
  55. register int num;
  56. {
  57.   register int i;
  58.  
  59.   py.flags.speed += num;
  60.   i = muptr;
  61.   while (i > 0)
  62.     {
  63.       m_list[i].cspeed += num;
  64.       i = m_list[i].nptr;
  65.     }
  66. }
  67.  
  68.  
  69. /* Player bonuses                    -RAK-    */
  70. /* When an item is worn or taken off, this re-adjusts the player */
  71. /* bonuses.  Factor==1 : wear; Factor==-1 : removed                */
  72. py_bonuses(tobj, factor)
  73. treasure_type tobj;
  74. int factor;
  75. {
  76.   register bitset_t item_flags;
  77.   int old_dis_ac;
  78.   register struct flags *p_ptr;
  79.   register struct misc *m_ptr;
  80.   register treasure_type *i_ptr;
  81.   register int i;
  82.  
  83.   p_ptr = &py.flags;
  84.   m_ptr = &py.misc;
  85.   if (p_ptr->slow_digest)
  86.     p_ptr->food_digested++;
  87.   if (p_ptr->regenerate)
  88.     p_ptr->food_digested -= 3;
  89.   p_ptr->see_inv     = FALSE;
  90.   p_ptr->teleport    = FALSE;
  91.   p_ptr->free_act    = FALSE;
  92.   p_ptr->slow_digest = FALSE;
  93.   p_ptr->aggravate   = FALSE;
  94.   p_ptr->sustain_str = FALSE;
  95.   p_ptr->sustain_int = FALSE;
  96.   p_ptr->sustain_wis = FALSE;
  97.   p_ptr->sustain_con = FALSE;
  98.   p_ptr->sustain_dex = FALSE;
  99.   p_ptr->sustain_chr = FALSE;
  100.   p_ptr->fire_resist = FALSE;
  101.   p_ptr->acid_resist = FALSE;
  102.   p_ptr->cold_resist = FALSE;
  103.   p_ptr->regenerate  = FALSE;
  104.   p_ptr->lght_resist = FALSE;
  105.   p_ptr->ffall       = FALSE;
  106.  
  107.   if (0x00000001 & tobj.flags)
  108.     {
  109.       change_stat_factor(&py.stats.cstr, tobj.p1, factor);
  110.       change_stat_factor(&py.stats.str, tobj.p1, factor);
  111.       print_stat = (0x0001 | print_stat);
  112.     }
  113.   if (0x00000002 & tobj.flags)
  114.     {
  115.       change_stat_factor(&py.stats.cdex, tobj.p1, factor);
  116.       change_stat_factor(&py.stats.dex, tobj.p1, factor);
  117.       print_stat = (0x0002 | print_stat);
  118.     }
  119.   if (0x00000004 & tobj.flags)
  120.     {
  121.       change_stat_factor(&py.stats.ccon, tobj.p1, factor);
  122.       change_stat_factor(&py.stats.con, tobj.p1, factor);
  123.       print_stat = (0x0004 | print_stat);
  124.     }
  125.   if (0x00000008 & tobj.flags)
  126.     {
  127.       change_stat_factor(&py.stats.cint, tobj.p1, factor);
  128.       change_stat_factor(&py.stats.intel, tobj.p1, factor);
  129.       print_stat = (0x0008 | print_stat);
  130.     }
  131.   if (0x00000010 & tobj.flags)
  132.     {
  133.       change_stat_factor(&py.stats.cwis, tobj.p1, factor);
  134.       change_stat_factor(&py.stats.wis, tobj.p1, factor);
  135.       print_stat = (0x0010 | print_stat);
  136.     }
  137.   if (0x00000020 & tobj.flags)
  138.     {
  139.       change_stat_factor(&py.stats.cchr, tobj.p1, factor);
  140.       change_stat_factor(&py.stats.chr, tobj.p1, factor);
  141.       print_stat = (0x0020 | print_stat);
  142.     }
  143.   if (0x00000040 & tobj.flags)
  144.     {
  145.       m_ptr->srh += (tobj.p1 * factor);
  146.       m_ptr->fos -= (tobj.p1 * factor);
  147.     }
  148.   if (0x00000100 & tobj.flags)
  149.     m_ptr->stl += 2*factor;
  150.   if (0x00001000 & tobj.flags)
  151.     {
  152.       i = tobj.p1*factor;
  153.       change_speed(-i);
  154.     }
  155.   if (0x08000000 & tobj.flags)
  156.     if (factor > 0)
  157.       p_ptr->blind += 1000;
  158.   if (0x10000000 & tobj.flags)
  159.     if (factor > 0)
  160.       p_ptr->afraid += 50;
  161.   if (0x40000000 & tobj.flags)
  162.     p_ptr->see_infra += (tobj.p1 * factor);
  163.  
  164.   old_dis_ac = m_ptr->dis_ac;
  165.   m_ptr->ptohit  = tohit_adj();       /* Real To Hit   */
  166.   m_ptr->ptodam  = todam_adj();       /* Real To Dam   */
  167.   m_ptr->ptoac   = toac_adj();        /* Real To AC    */
  168.   m_ptr->pac     = 0;               /* Real AC       */
  169.   m_ptr->dis_th  = m_ptr->ptohit;  /* Display To Hit        */
  170.   m_ptr->dis_td  = m_ptr->ptodam;  /* Display To Dam        */
  171.   m_ptr->dis_ac  = 0;       /* Display To AC         */
  172.   m_ptr->dis_tac = m_ptr->ptoac;   /* Display AC            */
  173.   for (i = 22; i < INVEN_MAX-2; i++)
  174.     {
  175.       i_ptr = &inventory[i];
  176.       if (i_ptr->tval != 0)
  177.     {
  178.       if ((0x80000000 & i_ptr->flags) == 0)
  179.         {
  180.           m_ptr->pac += i_ptr->ac;
  181.           m_ptr->dis_ac += i_ptr->ac;
  182.         }
  183.       m_ptr->ptohit += i_ptr->tohit;
  184.       m_ptr->ptodam += i_ptr->todam;
  185.       m_ptr->ptoac  += i_ptr->toac;
  186.       if (index(i_ptr->name, '^') == 0)
  187.         {
  188.           m_ptr->dis_th  += i_ptr->tohit;
  189.           m_ptr->dis_td  += i_ptr->todam;
  190.           m_ptr->dis_tac += i_ptr->toac;
  191.         }
  192.     }
  193.     }
  194.   m_ptr->dis_ac += m_ptr->dis_tac;
  195.  
  196.   /* Add in temporary spell increases    */
  197.   if (p_ptr->invuln > 0)
  198.     {
  199.       m_ptr->pac += 100;
  200.       m_ptr->dis_ac += 100;
  201.     }
  202.   if (p_ptr->blessed > 0)
  203.     {
  204.       m_ptr->pac    += 2;
  205.       m_ptr->dis_ac += 2;
  206.     }
  207.   if (p_ptr->detect_inv > 0)
  208.     p_ptr->see_inv = TRUE;
  209.  
  210.   if (old_dis_ac != m_ptr->dis_ac)
  211.     print_stat = (0x0040 | print_stat);
  212.  
  213.   item_flags = 0;
  214.   for (i = 22; i < INVEN_MAX-2; i++)
  215.     {
  216.       i_ptr = &inventory[i];
  217.       item_flags |= i_ptr->flags;
  218.     }
  219.   if (0x00000080 & item_flags)
  220.     p_ptr->slow_digest = TRUE;
  221.   if (0x00000200 & item_flags)
  222.     p_ptr->aggravate = TRUE;
  223.   if (0x00000400 & item_flags)
  224.     p_ptr->teleport = TRUE;
  225.   if (0x00000800 & item_flags)
  226.     p_ptr->regenerate = TRUE;
  227.   if (0x00080000 & item_flags)
  228.     p_ptr->fire_resist = TRUE;
  229.   if (0x00100000 & item_flags)
  230.     p_ptr->acid_resist = TRUE;
  231.   if (0x00200000 & item_flags)
  232.     p_ptr->cold_resist = TRUE;
  233.   if (0x00800000 & item_flags)
  234.     p_ptr->free_act = TRUE;
  235.   if (0x01000000 & item_flags)
  236.     p_ptr->see_inv = TRUE;
  237.   if (0x02000000 & item_flags)
  238.     p_ptr->lght_resist = TRUE;
  239.   if (0x04000000 & item_flags)
  240.     p_ptr->ffall = TRUE;
  241.  
  242.   for (i = 22; i < INVEN_MAX-2; i++)
  243.     {
  244.       i_ptr = &inventory[i];
  245.       if (0x00400000 & i_ptr->flags)
  246.     switch(i_ptr->p1)
  247.       {
  248.       case 1: p_ptr->sustain_str = TRUE; break;
  249.       case 2: p_ptr->sustain_int = TRUE; break;
  250.       case 3: p_ptr->sustain_wis = TRUE; break;
  251.       case 4: p_ptr->sustain_con = TRUE; break;
  252.       case 5: p_ptr->sustain_dex = TRUE; break;
  253.       case 6: p_ptr->sustain_chr = TRUE; break;
  254.       default: break;
  255.       }
  256.     }
  257.  
  258.   if (p_ptr->slow_digest)
  259.     p_ptr->food_digested--;
  260.   if (p_ptr->regenerate)
  261.     p_ptr->food_digested += 3;
  262. }
  263.  
  264.  
  265. /* Returns a "*" for cursed items, a ")" for normal ones -RAK-    */
  266. /* NOTE: "*" returned only if item has been identified...        */
  267. char cur_char1(item_val)
  268. int item_val;
  269. {
  270.   register treasure_type *i_ptr;
  271.  
  272.   i_ptr = &inventory[item_val];
  273.   if ((0x80000000 & i_ptr->flags) == 0)
  274.     return(')');    /* Not cursed...                 */
  275.   else if (index(i_ptr->name, '^') != 0)
  276.     return(')');    /* Cursed, but not identified    */
  277.   else
  278.     return('*');   /* Cursed and identified...      */
  279. }
  280.  
  281.  
  282. /* Returns a "*" for cursed items, a ")" for normal ones -RAK-    */
  283. char cur_char2(item_val)
  284. int item_val;
  285. {
  286.   register treasure_type *i_ptr;
  287.  
  288.   i_ptr = &inventory[item_val];
  289.   if ((0x80000000 & i_ptr->flags) == 0)
  290.     return(')');    /* Not cursed... */
  291.   else
  292.     return('*');   /* Cursed...     */
  293. }
  294.  
  295.  
  296. /* inventory functions, define some global variables here */
  297. /* scr_state == 0 : normal screen (i.e. map of dungeon)
  298.              or partial inventory list, (calling function sets redraw)
  299.    scr_state == 1 : inventory is displayed on the screen
  300.    scr_state == 2 : equipment list is displayed on the screen */
  301. int scr_state;
  302.  
  303. /* Displays inventory items from r1 to r2    -RAK-    */
  304. show_inven(r1, r2)
  305. register int r1, r2;
  306. {
  307.   register int i;
  308.   bigvtype tmp_val, out_val;
  309.  
  310.   if (r1 >= 0)                       /* R1 == 0 dummy call     */
  311.     {
  312.       for (i = r1; i <= r2; i++)             /* Print the items       */
  313.     {
  314.       objdes(tmp_val, i, TRUE);
  315.       (void) sprintf(out_val, "%c%c %s", i+97, cur_char1(i), tmp_val);
  316.       prt(out_val, i+1, 0);
  317.     }
  318.       if (r2 < 22)
  319.     prt("", r2+2, 0); /* Clear line after      */
  320.       scr_state = 1;                   /* Set state to 1        */
  321.     }
  322. }
  323.  
  324. /* Displays equipment items from r1 to end    -RAK-    */
  325. show_equip(r1)
  326. register int r1;
  327. {
  328.   register int i, j;
  329.   vtype prt1; bigvtype prt2, out_val;
  330.   register treasure_type *i_ptr;
  331.  
  332.   if (r1 >= equip_ctr)       /* Last item gone                */
  333.     prt("", equip_ctr+2, 0);  /* clear the line */
  334.   else if (r1 >= 0)          /* R1 == 0 dummy call             */
  335.     {
  336.       j = 0;
  337.       for (i = 22; i < INVEN_MAX; i++) /* Range of equipment        */
  338.     {
  339.       i_ptr = &inventory[i];
  340.       if (i_ptr->tval != 0)
  341.         {
  342.           if (j >= r1) /* Display only given range    */
  343.         {
  344.           switch(i)          /* Get position          */
  345.             {
  346.             case 22:
  347.               (void) strcpy(prt1, " You are wielding   : "); break;
  348.             case 23:
  349.               (void) strcpy(prt1, " Worn on head       : "); break;
  350.             case 24:
  351.               (void) strcpy(prt1, " Worn around neck   : "); break;
  352.             case 25:
  353.               (void) strcpy(prt1, " Worn on body       : "); break;
  354.             case 26:
  355.               (void) strcpy(prt1, " Worn on arm        : "); break;
  356.             case 27:
  357.               (void) strcpy(prt1, " Worn on hands      : "); break;
  358.             case 28:
  359.               (void) strcpy(prt1, " Worn on right hand : "); break;
  360.             case 29:
  361.               (void) strcpy(prt1, " Worn on left hand  : "); break;
  362.             case 30:
  363.               (void) strcpy(prt1, " Worn on feet       : "); break;
  364.             case 31:
  365.               (void) strcpy(prt1, " Worn about body    : "); break;
  366.             case 32:
  367.               (void) strcpy(prt1, " Light source       : "); break;
  368.             case 33:
  369.               (void) strcpy(prt1, " Secondary weapon   : "); break;
  370.             default:
  371.               (void) strcpy(prt1, " Unknown value      : "); break;
  372.             }
  373.           objdes(prt2, i, TRUE);
  374.           (void) sprintf(out_val,
  375.                  "%c%c%s%s", j+97, cur_char2(i), prt1, prt2);
  376.           prt(out_val, j+2, 0);
  377.         }
  378.           j++;
  379.         }
  380.     }
  381.       prt("", j+2, 0);   /* Clear last line       */
  382.       scr_state = 2;   /* Set state of screen   */
  383.     }
  384. }
  385.  
  386. /* Remove item from equipment list        -RAK-    */
  387. static int remove(item_val)
  388. int item_val;
  389. {
  390.   register int i, j, typ;
  391.   vtype prt1; bigvtype out_val, prt2;
  392.   int flag;
  393.   register treasure_type *i_ptr;
  394.  
  395.   i = 0;
  396.   flag = FALSE;
  397.   typ  = inventory[item_val].tval;
  398.   do
  399.     {
  400.       i_ptr = &inventory[i];
  401.       if (typ > i_ptr->tval)
  402.     {
  403.       for (j = inven_ctr-1; j >= i; j--)
  404.         inventory[j+1] = inventory[j];
  405.       inventory[i]  = inventory[item_val];
  406.       inven_ctr++;
  407.       equip_ctr--;
  408.       flag = TRUE;
  409.     }
  410.       i++;
  411.     }
  412.   while (!flag);
  413.   i--;
  414.   switch(typ)
  415.     {
  416.     case 10: case 11: case 12: case 20: case 21: case 22: case 23: case 25 :
  417.       (void) strcpy(prt1, "Was wielding ");
  418.       break;
  419.     case 15:
  420.       (void) strcpy(prt1, "Light source was ");
  421.       break;
  422.     default:
  423.       (void) strcpy(prt1, "Was wearing ");
  424.       break;
  425.     }
  426.   objdes(prt2, i, TRUE);
  427.   (void) sprintf(out_val, "%s%s (%c)", prt1, prt2, i+97);
  428.   msg_print(out_val);
  429.   inventory[item_val] = blank_treasure;
  430.   if (item_val != INVEN_AUX)      /* For secondary weapon  */
  431.     py_bonuses(inventory[i], -1);
  432.   return(i);
  433. }
  434.  
  435.  
  436. /* Unwear routine,  remove a piece of equipment    -RAK-    */
  437. unwear()
  438. {
  439.   register int i, j;
  440.   int exit_flag, test_flag, com_val;
  441.   char command;
  442.   vtype out_val;
  443.  
  444.   if (scr_state == 1)
  445.     {
  446.       clear_screen(0, 0);
  447.       show_equip(0);
  448.     }
  449.   exit_flag = FALSE;
  450.   do
  451.     {
  452.       (void) sprintf(out_val,
  453.           "(a-%c, * for equipment list, ESC to exit) Take off which one ?",
  454.           equip_ctr+96);
  455.       test_flag = FALSE;
  456.       msg_print(out_val);
  457.       do
  458.     {
  459.       inkey(&command);
  460.       com_val = (command);
  461.       switch(com_val)
  462.         {
  463.         case 0: case 27:
  464.           test_flag = TRUE;
  465.           exit_flag = TRUE;
  466.           break;
  467.         case 42:
  468.           clear_screen(1, 0);
  469.           show_equip(0);
  470.           break;
  471.         default:
  472.           com_val -= 97;
  473.           if ((com_val >= 0) &&
  474.           (com_val < equip_ctr))
  475.         test_flag = TRUE;
  476.           break;
  477.         }
  478.     }
  479.       while (!test_flag);
  480.       if (!exit_flag)
  481.     {
  482.       reset_flag = FALSE;    /* Player turn   */
  483.       i = -1;
  484.       j = 21;
  485.       do
  486.         {
  487.           j++;
  488.           if (inventory[j].tval != 0)
  489.         i++;
  490.         }
  491.       while (i != com_val);
  492.       if (0x80000000 & inventory[j].flags)
  493.         {
  494.           msg_print("Hmmm, it seems to be cursed...");
  495.           com_val = 0;
  496.         }
  497.       else
  498.         (void) remove(j);
  499.     }
  500.       if (scr_state == 0)
  501.     exit_flag = TRUE;
  502.       else if (equip_ctr == 0)
  503.     exit_flag = TRUE;
  504.       else if (inven_ctr > 21)
  505.     {
  506.       exit_flag = TRUE;
  507.       show_equip(0);
  508.     }
  509.       else if (!exit_flag)
  510.     show_equip(0);
  511.     }
  512.   while (!exit_flag);
  513.   if (scr_state != 0)
  514.     if (equip_ctr == 0)
  515.       clear_screen(0, 0);
  516.     else
  517.       prt("You are currently using -", 0, 0);
  518. }
  519.  
  520.  
  521. /* Wear routine, wear or wield an item        -RAK-    */
  522. wear()
  523. {
  524.   register int i, j, k;
  525.   int com_val, tmp;
  526.   bigvtype prt1, out_val, prt2;
  527.   treasure_type unwear_obj;
  528.   int exit_flag, test_flag;
  529.   char command;
  530.   register treasure_type *i_ptr;
  531.  
  532.   if (scr_state == 2)
  533.     {
  534.       clear_screen(0, 0);
  535.       show_inven(0, inven_ctr-1);
  536.     }
  537.   exit_flag = FALSE;
  538.   do
  539.     {
  540.       (void) sprintf(out_val,
  541.          "(a-%c, * for equipment list, ESC to exit) Wear/Wield which one?",
  542.           inven_ctr+96);
  543.       test_flag = FALSE;
  544.       msg_print(out_val);
  545.       do
  546.     {
  547.       inkey(&command);
  548.       com_val = (command);
  549.       switch(com_val)
  550.         {
  551.         case 0: case 27:
  552.           test_flag = TRUE;
  553.           exit_flag = TRUE;
  554.           break;
  555.         case 42:
  556.           clear_screen(1, 0);
  557.           show_inven(0, inven_ctr-1);
  558.           break;
  559.         default:
  560.           com_val -= 97;
  561.           if ((com_val >= 0) &&
  562.           (com_val < inven_ctr))
  563.         test_flag = TRUE;
  564.           break;
  565.         }
  566.     }
  567.       while (!test_flag);
  568.       if (!exit_flag)     /* Main logic for wearing        */
  569.     {
  570.       reset_flag = FALSE;    /* Player turn   */
  571.       test_flag = TRUE;
  572.       switch(inventory[com_val].tval) /* Slot for equipment    */
  573.         {
  574.         case 10: i = 22; break;
  575.         case 11: i = 22; break;
  576.         case 12: i = 22; break;
  577.         case 15: i = 32; break;
  578.         case 20: i = 22; break;
  579.         case 21: i = 22; break;
  580.         case 22: i = 22; break;
  581.         case 23: i = 22; break;
  582.         case 25: i = 22; break;
  583.         case 30: i = 30; break;
  584.         case 31: i = 27; break;
  585.         case 32: i = 31; break;
  586.         case 33: i = 23; break;
  587.         case 34: i = 26; break;
  588.         case 35: i = 25; break;
  589.         case 36: i = 25; break;
  590.         case 40: i = 24; break;
  591.         case 45:
  592.           if (inventory[INVEN_RIGHT].tval == 0)       /* Rings */
  593.             i = INVEN_RIGHT;
  594.           else
  595.             i = INVEN_LEFT;
  596.           break;
  597.             default:
  598.           msg_print("I don't see how you can use that.");
  599.           test_flag = FALSE;
  600.           com_val = 0;
  601.           break;
  602.         }
  603.       if (test_flag)
  604.         if (inventory[i].tval != 0)
  605.           {
  606.         if (0x80000000 & inventory[i].flags)
  607.           {
  608.             objdes(prt1, i, FALSE);
  609.             (void) sprintf(out_val, "The %s you are ", prt1);
  610.             switch(i)
  611.               {
  612.               case 23: (void) strcat(out_val, "wielding "); break;
  613.               default: (void) strcat(out_val, "wearing "); break;
  614.               }
  615.             msg_print(strcat(out_val, "appears to be cursed."));
  616.             test_flag = FALSE;
  617.             com_val = 0;
  618.           }
  619.         else if (inven_ctr > 21)
  620.           if (inventory[com_val].number > 1)
  621.             if (inventory[com_val].subval < 512)
  622.               {
  623.             msg_print("You will have to drop something first.");
  624.             test_flag = FALSE;
  625.             com_val = 0;
  626.               }
  627.           }
  628.       if (test_flag)
  629.         {
  630.           /* save old item */
  631.           unwear_obj = inventory[i];
  632.           /* now wear/wield new object */
  633.           inventory[i] = inventory[com_val];
  634.           i_ptr = &inventory[i];
  635.           /* Fix for torches       */
  636.           if ((i_ptr->subval > 255) && (i_ptr->subval < 512))
  637.         {
  638.           i_ptr->number = 1;
  639.           i_ptr->subval -= 255;
  640.         }
  641.           /* Fix for weight        */
  642.           inven_weight += i_ptr->weight*i_ptr->number;
  643.           inven_destroy(com_val);     /* Subtracts weight      */
  644.           equip_ctr++;
  645.           /* subtract bonuses for old item before add bonuses for new */
  646.           /* must do this after inven_destroy, otherwise inventory
  647.          may increase to 23 items thus destroying INVEN_WIELD */
  648.           if (unwear_obj.tval != 0)
  649.         {
  650.           inventory[INVEN_MAX] = unwear_obj;
  651.           /* decrements equip_ctr, and calls py_bonuses with -1 */
  652.           tmp = remove(INVEN_MAX);
  653.           if (tmp < com_val)
  654.             com_val = tmp;
  655.         }
  656.           py_bonuses(inventory[i], 1);
  657.           switch(i)
  658.         {
  659.         case 22: (void) strcpy(prt1, "You are wielding "); break;
  660.         case 32: (void) strcpy(prt1, "Your light source is "); break;
  661.         default: (void) strcpy(prt1, "You are wearing "); break;
  662.         }
  663.           objdes(prt2, i, TRUE);
  664.           j = -1;
  665.           k = 21;
  666.           do      /* Get the right letter of equipment     */
  667.         {
  668.           k++;
  669.           if (inventory[k].tval != 0)
  670.             j++;
  671.         }
  672.           while (k != i);
  673.           (void) sprintf(out_val, "%s%s (%c%c",
  674.               prt1, prt2, j+97, cur_char2(i));
  675.           msg_print(out_val);
  676.           if ((i == 22) && (py.stats.cstr*15 < i_ptr->weight))
  677.         msg_print("You have trouble wielding such a heavy weapon.");
  678.         }
  679.     }
  680.       if (scr_state == 0)
  681.     exit_flag = TRUE;
  682.       else if (inven_ctr == 0)
  683.     exit_flag = TRUE;
  684.       else if (!exit_flag)
  685.     show_inven(com_val, inven_ctr-1);
  686.     }
  687.   while (!exit_flag);
  688.   if (scr_state != 0)  prt("You are currently carrying -", 0, 0);
  689. }
  690.  
  691. /* Switch primary and secondary weapons        -RAK-    */
  692. switch_weapon()
  693. {
  694.   bigvtype prt1, prt2;
  695.   treasure_type tmp_obj;
  696.  
  697.   if (0x80000000 & inventory[INVEN_WIELD].flags)
  698.     {
  699.       objdes(prt1, INVEN_WIELD, FALSE);
  700.       (void) sprintf(prt2,
  701.              "The %s you are wielding appears to be cursed.", prt1);
  702.       msg_print(prt2);
  703.     }
  704.   else
  705.     {
  706.       /* Switch weapons        */
  707.       reset_flag = FALSE;
  708.       tmp_obj = inventory[INVEN_AUX];
  709.       inventory[INVEN_AUX] = inventory[INVEN_WIELD];
  710.       inventory[INVEN_WIELD] = tmp_obj;
  711.       py_bonuses(inventory[INVEN_AUX], -1);     /* Subtract bonuses      */
  712.       py_bonuses(inventory[INVEN_WIELD], 1);      /* Add bonuses           */
  713.       if (inventory[INVEN_WIELD].tval != 0)
  714.     {
  715.       (void) strcpy(prt1, "Primary weapon   : ");
  716.       objdes(prt2, INVEN_WIELD, TRUE);
  717.       msg_print(strcat(prt1, prt2));
  718.       if (py.stats.cstr * 15 < inventory[INVEN_WIELD].weight)
  719.         msg_print("You have trouble wielding such a heavy weapon.");
  720.     }
  721.       if (inventory[INVEN_AUX].tval != 0)
  722.     {
  723.       (void) strcpy(prt1, "Secondary weapon : ");
  724.       objdes(prt2, INVEN_AUX, TRUE);
  725.       msg_print(strcat(prt1, prt2));
  726.     }
  727.     }
  728.   if (scr_state != 0)
  729.     {
  730.       /* make sure player sees last message */
  731.       msg_print(" ");
  732.       clear_screen(0, 0);
  733.       prt("You are currently using -", 0, 0);
  734.       show_equip(0);
  735.     }
  736. }
  737.  
  738.  
  739. /* Comprehensive function block to handle all inventory    -RAK-    */
  740. /* and equipment routines.  Five kinds of calls can take place.  */
  741. /* Note that "?" is a special call for other routines to display */
  742. /* only a portion of the inventory, and take no other action.    */
  743. int inven_command(command, r1, r2)
  744. char command;
  745. int r1, r2;
  746. {
  747.   register int com_val, inven;
  748.   register int exit_flag, test_flag;
  749.  
  750.   /* Main logic for INVEN_COMMAND            -RAK-    */
  751.   inven = FALSE;
  752.   exit_flag = FALSE;
  753.   scr_state = 0;
  754.   do
  755.     {
  756.       switch(command)
  757.     {
  758.     case 'i':          /* Inventory     */
  759.       if (inven_ctr == 0)
  760.         msg_print("You are not carrying anything.");
  761.       else if (scr_state != 1)
  762.         {     /* Sets scr_state to 1           */
  763.           clear_screen(0, 0);
  764.           prt("You are currently carrying -", 0, 0);
  765.           show_inven(0, inven_ctr-1);
  766.         }
  767.       break;
  768.     case 'e':         /* Equipment     */
  769.       if (equip_ctr == 0)
  770.         msg_print("You are not using any equipment.");
  771.       else if (scr_state != 2)
  772.         {     /* Sets scr_state to 2           */
  773.           clear_screen(0, 0);
  774.           prt("You are currently using -", 0, 0);
  775.           show_equip(0);
  776.         }
  777.       break;
  778.     case 't':         /* Take off      */
  779.       if (equip_ctr == 0)
  780.         msg_print("You are not using any equipment.");
  781.       else if (inven_ctr > 21)
  782.         msg_print("You will have to drop something first.");
  783.       else
  784.         unwear();   /* May set scr_state to 2        */
  785.       break;
  786.     case 'w':         /* Wear/wield    */
  787.       if (inven_ctr == 0)
  788.         msg_print("You are not carrying anything.");
  789.       else
  790.         wear();     /* May set scr_state to 1        */
  791.       break;
  792.     case 'x':
  793.       if (inventory[INVEN_WIELD].tval != 0)
  794.         switch_weapon();
  795.       else if (inventory[INVEN_AUX].tval != 0)
  796.         switch_weapon();
  797.       else
  798.         msg_print("But you are wielding no weapons.");
  799.       break;
  800.       /* Special function for other routines                   */
  801.     case '?':  /* Displays part inven, returns  */
  802.       show_inven(r1, r2);
  803.       scr_state = 0;     /* Clear screen state    */
  804.       break;
  805.       /* Nonsense command                                      */
  806.     default:
  807.       break;
  808.     }
  809.       if (scr_state > 0)
  810.     {
  811.       prt(
  812.     "<e>quip, <i>inven, <t>ake-off, <w>ear/wield, e<x>change, or ESC to exit.",
  813.       23, 1);
  814.       test_flag = FALSE;
  815.       do
  816.         {
  817.           inkey(&command);
  818.           com_val = (command);
  819.           switch(com_val)
  820.         {
  821.         case 0: case 27: case 32:
  822.           /* Exit from module      */
  823.           exit_flag = TRUE;
  824.           test_flag = TRUE;
  825.           break;
  826.         default:
  827.           switch(command)      /* Module commands       */
  828.             {
  829.             case 'e': test_flag = TRUE; break;
  830.             case 'i': test_flag = TRUE; break;
  831.             case 't': test_flag = TRUE; break;
  832.             case 'w': test_flag = TRUE; break;
  833.             case 'x': test_flag = TRUE; break;
  834.             case '?': break;      /* Trap special feature  */
  835.             default:  break; /* Nonsense command      */
  836.             }
  837.         }
  838.         }
  839.       while (!test_flag);
  840.       prt("", 23, 0);   /* clear the line containing command list */
  841.     }
  842.       else
  843.     exit_flag = TRUE;
  844.     }
  845.   while (!exit_flag);
  846.   if (scr_state > 0)          /* If true, must redraw screen   */
  847.     inven = TRUE;
  848.   return(inven);
  849. }
  850.  
  851.  
  852. /* Get the ID of an item and return the CTR value of it    -RAK-    */
  853. int get_item(com_val, pmt, redraw, i, j)
  854. int *com_val;
  855. char *pmt;
  856. int *redraw;
  857. int i, j;
  858. {
  859.   char command;
  860.   vtype out_val;
  861.   register int test_flag, item;
  862.  
  863.   item = FALSE;
  864.   *com_val = 0;
  865.   if (inven_ctr > 0)
  866.     {
  867.       (void) sprintf(out_val,
  868.              "(Items %c-%c, * for inventory list, ESC to exit) %s",
  869.           i+97, j+97, pmt);
  870.       test_flag = FALSE;
  871.       prt(out_val, 0, 0);
  872.       do
  873.     {
  874.       inkey(&command);
  875.       *com_val = (command);
  876.       switch(*com_val)
  877.         {
  878.         case 0: case 27:
  879.           test_flag = TRUE;
  880.           reset_flag = TRUE;
  881.           break;
  882.         case 42:
  883.           clear_screen(1, 0);
  884.           (void) inven_command('?', i, j);
  885.           *redraw = TRUE;
  886.           break;
  887.         default:
  888.           *com_val -= 97;
  889.           if ((*com_val >= i) &&
  890.           (*com_val <= j))
  891.         {
  892.           test_flag = TRUE;
  893.           item = TRUE;
  894.         }
  895.           break;
  896.         }
  897.     }
  898.       while (!test_flag);
  899.       erase_line(MSG_LINE, 0);
  900.     }
  901.   else
  902.     msg_print("You are not carrying anything.");
  903.   return(item);
  904. }
  905.  
  906. /* I may have written the town level code, but I'm not exactly   */
  907. /* proud of it.  Adding the stores required some real slucky     */
  908. /* hooks which I have not had time to re-think.          -RAK-   */
  909.  
  910.  
  911. /* Calculates current boundaries                -RAK-    */
  912. panel_bounds()
  913. {
  914.   panel_row_min = panel_row*(SCREEN_HEIGHT/2);
  915.   panel_row_max = panel_row_min + SCREEN_HEIGHT - 1;
  916.   panel_row_prt = panel_row_min - 1;
  917.   panel_col_min = panel_col*(SCREEN_WIDTH/2);
  918.   panel_col_max = panel_col_min + SCREEN_WIDTH - 1;
  919. /* the value 13 puts one blank space between the stats and the map, leaving
  920.      the last column empty
  921.    the value 14 puts two blank spaces between the stats and the map, and
  922.      ends up printing in the last column
  923.    I think 14 gives a better display, but some curses wreak havoc when try to
  924.    print characters in the last column, hence the BUGGY_CURSES ifdef */
  925. #ifdef BUGGY_CURSES
  926.   panel_col_prt = panel_col_min - 13;
  927. #else
  928.   panel_col_prt = panel_col_min - 14;
  929. #endif
  930. }
  931.  
  932.  
  933. /* Given an row (y) and col (x), this routine detects  -RAK-    */
  934. /* when a move off the screen has occurred and figures new borders*/
  935. int get_panel(y, x)
  936. int y, x;
  937. {
  938.   register int prow, pcol;
  939.   register int panel;
  940.  
  941.   prow = panel_row;
  942.   pcol = panel_col;
  943.   if ((y < panel_row_min + 2) || (y > panel_row_max - 2))
  944.     {
  945.       prow = ((y - 2)/(SCREEN_HEIGHT/2));
  946.       if (prow > max_panel_rows)
  947.     prow = max_panel_rows;
  948.     }
  949.   if ((x < panel_col_min + 3) || (x > panel_col_max - 3))
  950.     {
  951.       pcol = ((x - 3)/(SCREEN_WIDTH/2));
  952.       if (pcol > max_panel_cols)
  953.     pcol = max_panel_cols;
  954.     }
  955.   if ((prow != panel_row) || (pcol != panel_col) || (!cave_flag))
  956.     {
  957.       panel_row = prow;
  958.       panel_col = pcol;
  959.       panel_bounds();
  960.       panel = TRUE;
  961.       cave_flag = TRUE;
  962.       /* stop movement if any */
  963.       if (find_flag)
  964.     find_flag = FALSE;  /* no need to call move_light () */
  965.     }
  966.   else
  967.     panel = FALSE;
  968.   return(panel);
  969. }
  970.  
  971.  
  972. /* Tests a given point to see if it is within the screen -RAK-    */
  973. /* boundaries.                                                    */
  974. int panel_contains(y, x)
  975. int y, x;
  976. {
  977.   register int panel;
  978.  
  979.   if ((y >= panel_row_min) && (y <= panel_row_max))
  980.     if ((x >= panel_col_min) && (x <= panel_col_max))
  981.       panel = TRUE;
  982.     else
  983.       panel = FALSE;
  984.   else
  985.     panel = FALSE;
  986.   return(panel);
  987. }
  988.  
  989.  
  990. /* Returns true if player has no light            -RAK-    */
  991. int no_light()
  992. {
  993.   register int light;
  994.   register cave_type *c_ptr;
  995.  
  996.   light = FALSE;
  997.   c_ptr = &cave[char_row][char_col];
  998.     if (!c_ptr->tl)
  999.       if (!c_ptr->pl)
  1000.     light = TRUE;
  1001.   return(light);
  1002. }
  1003.  
  1004.  
  1005. /* map rogue_like direction commands into numbers */
  1006. int map_roguedir(comval)
  1007. register int *comval;
  1008. {
  1009.   switch(*comval)
  1010.     {
  1011.     case 'h':
  1012.       *comval = '4';
  1013.       return(4);
  1014.     case 'y':
  1015.       *comval = '7';
  1016.       return(7);
  1017.     case 'k':
  1018.       *comval = '8';
  1019.       return(8);
  1020.     case 'u':
  1021.       *comval = '9';
  1022.       return(9);
  1023.     case 'l':
  1024.       *comval = '6';
  1025.       return(6);
  1026.     case 'n':
  1027.       *comval = '3';
  1028.       return(3);
  1029.     case 'j':
  1030.       *comval = '2';
  1031.       return(2);
  1032.     case 'b':
  1033.       *comval = '1';
  1034.       return(1);
  1035.     }
  1036.   return(*comval - 48);
  1037. }
  1038.  
  1039.  
  1040.  
  1041. /* Prompts for a direction                -RAK-    */
  1042. int get_dir(prompt, dir, com_val, y, x)
  1043. char *prompt;
  1044. int *dir, *com_val, *y, *x;
  1045. {
  1046.   int flag;
  1047.   char command;
  1048.   int res;
  1049.  
  1050.   flag = FALSE;
  1051.   do
  1052.     {
  1053.       if (get_com(prompt, &command))
  1054.     {
  1055.       *com_val = (command);
  1056.       if (key_bindings == ORIGINAL)
  1057.         *dir = *com_val - 48;
  1058.       else   /* rogue_like bindings */
  1059.         *dir = map_roguedir(com_val);
  1060.       /* Note that "5" is not a valid direction        */
  1061.       if ((*dir >= 1) && (*dir <= 9) && (*dir != 5))
  1062.         {
  1063.           (void) move(*dir, y, x);
  1064.           flag = TRUE;
  1065.           res = TRUE;
  1066.         }
  1067.     }
  1068.       else
  1069.     {
  1070.       reset_flag = TRUE;
  1071.       res = FALSE;
  1072.       flag = TRUE;
  1073.     }
  1074.     }
  1075.   while (!flag);
  1076.   return(res);
  1077. }
  1078.  
  1079.  
  1080. /* Moves creature record from one space to another    -RAK-    */
  1081. move_rec(y1, x1, y2, x2)
  1082. register int y1, x1, y2, x2;
  1083. {
  1084.   if ((y1 != y2) || (x1 != x2))
  1085.     {
  1086.       cave[y2][x2].cptr = cave[y1][x1].cptr;
  1087.       cave[y1][x1].cptr = 0;
  1088.       }
  1089. }
  1090.  
  1091.  
  1092. find_light(y1, x1, y2, x2)
  1093. int y1, x1, y2, x2;
  1094. {
  1095.   register int i, j, k, l;
  1096.  
  1097.   for (i = y1; i <= y2; i++)
  1098.     for (j = x1; j <= x2; j++)
  1099.       if ((cave[i][j].fval == 1) || (cave[i][j].fval == 2))
  1100.     {
  1101.       for (k = i-1; k <= i+1; k++)
  1102.         for (l = j-1; l <= j+1; l++)
  1103.           cave[k][l].pl = TRUE;
  1104.       cave[i][j].fval = 2;
  1105.     }
  1106. }
  1107.  
  1108.  
  1109. /* Room is lit, make it appear                -RAK-    */
  1110. light_room(y, x)
  1111. int y, x;
  1112. {
  1113.   register cave_type *c_ptr;
  1114.   register int i, j;
  1115.   int tmp1, tmp2;
  1116.   int start_row, end_row;
  1117.   register int start_col, end_col;
  1118.   int ypos, xpos;
  1119.   vtype floor_str, tmp_str;
  1120.  
  1121.   tmp1 = (SCREEN_HEIGHT/2);
  1122.   tmp2 = (SCREEN_WIDTH /2);
  1123.   start_row = (y/tmp1)*tmp1;
  1124.   start_col = (x/tmp2)*tmp2;
  1125.   end_row = start_row + tmp1 - 1;
  1126.   end_col = start_col + tmp2 - 1;
  1127.   find_light(start_row, start_col, end_row, end_col);
  1128.   for (i = start_row; i <= end_row; i++)
  1129.     {
  1130.       floor_str[0] = '\0';
  1131.       ypos = i;
  1132.       for (j = start_col; j <= end_col; j++)
  1133.     {
  1134.       c_ptr = &cave[i][j];
  1135.       if ((c_ptr->pl) || (c_ptr->fm))
  1136.         {
  1137.           if (strlen(floor_str) == 0)
  1138.         xpos = j;
  1139.           loc_symbol(i, j, tmp_str);
  1140.           tmp_str[1] = '\0';
  1141.           (void) strcat(floor_str, tmp_str);
  1142.         }
  1143.       else
  1144.         if (strlen(floor_str) > 0)
  1145.           {
  1146.         print(floor_str, ypos, xpos);
  1147.         floor_str[0] = '\0';
  1148.           }
  1149.     }
  1150.       if (strlen(floor_str) > 0)
  1151.     print(floor_str, ypos, xpos);
  1152.     }
  1153. }
  1154.  
  1155.  
  1156. /* Lights up given location                -RAK-    */
  1157. lite_spot(y, x)
  1158. register int y, x;
  1159. {
  1160.   char temp[2];
  1161.  
  1162.   temp[1] = '\0';
  1163.   if (panel_contains(y, x))
  1164.     {
  1165.       loc_symbol(y, x, temp);
  1166.       print(temp, y, x);
  1167.       }
  1168. }
  1169.  
  1170.  
  1171. /* Blanks out given location                -RAK-    */
  1172. unlite_spot(y, x)
  1173. register int y, x;
  1174. {
  1175.   if (panel_contains(y, x))
  1176.     print(" ", y, x);
  1177. }
  1178.  
  1179.  
  1180. /* Minimum of a maximum                -RAK-    */
  1181. int minmax(x, y, z)
  1182. register int x, y, z;
  1183. {
  1184.   register int max;
  1185.  
  1186.   max = ( y > x ? y : x) + 1;
  1187.   return((max > z ? z : max));
  1188. }
  1189.  
  1190. /* Maximum of a minimum                -RAK-    */
  1191. int maxmin(x, y, z)
  1192. register int x, y, z;
  1193. {
  1194.   register int min;
  1195.  
  1196.   min = (x > y ? y : x) - 1;
  1197.   return((min > z ? min : z));
  1198. }
  1199.  
  1200.  
  1201. /* Given two sets of points,  draw the block        */
  1202. draw_block(y1, x1, y2, x2)
  1203. int y1, x1, y2, x2;
  1204. {
  1205.   register cave_type *c_ptr;
  1206.   register int i, j;
  1207.   int xpos;
  1208.   int topp, bott, left, righ;
  1209.   int new_topp, new_bott, new_left, new_righ;
  1210.   vtype floor_str, save_str;
  1211.   char tmp_char[2];
  1212.   int flag;
  1213.  
  1214.   tmp_char[1] = '\0';    /* This is supposed to be a one */
  1215.   /* From uppermost to bottom most lines player was on...  */
  1216.   /* Points are guaranteed to be on the screen (I hope...) */
  1217.   topp = maxmin(y1, y2, panel_row_min);
  1218.   bott = minmax(y1, y2, panel_row_max);
  1219.   left = maxmin(x1, x2, panel_col_min);
  1220.   righ = minmax(x1, x2, panel_col_max);
  1221.   new_topp = y2 - 1;     /* Margins for new things to appear*/
  1222.   new_bott = y2 + 1;
  1223.   new_left = x2 - 1;
  1224.   new_righ = x2 + 1;
  1225.   for (i = topp; i <= bott; i++)
  1226.     {
  1227.       floor_str[0] = '\0';    /* Null out print string         */
  1228.       xpos      = -1;
  1229.       save_str[0] = '\0';
  1230.       for (j = left; j <= righ; j++)   /* Leftmost to rightmost do*/
  1231.     {
  1232.       c_ptr = &cave[i][j];
  1233.       if ((c_ptr->pl) || (c_ptr->fm))
  1234.         if (((i==y1) && (j==x1)) || ((i==y2) && (j==x2)))
  1235.           flag = TRUE;
  1236.         else
  1237.           flag = FALSE;
  1238.       else
  1239.         {
  1240.           flag = TRUE;
  1241.           if (((i >= new_topp) && (i <= new_bott)) &&
  1242.           ((j >= new_left) && (j <= new_righ)))
  1243.         {
  1244.           if (c_ptr->tl)
  1245.             if (((c_ptr->fval >= 10) && (c_ptr->fval <= 12)) ||
  1246.             (c_ptr->fval == 15))
  1247.               c_ptr->pl = TRUE;
  1248.             else if (c_ptr->tptr != 0)
  1249.               if ((t_list[c_ptr->tptr].tval >= 102) &&
  1250.               (t_list[c_ptr->tptr].tval <= 110) &&
  1251.               (t_list[c_ptr->tptr].tval != 106))
  1252.             if (!c_ptr->fm)
  1253.               c_ptr->fm = TRUE;
  1254.         }
  1255.         }
  1256.       if ((c_ptr->pl) || (c_ptr->tl) || (c_ptr->fm))
  1257.         loc_symbol(i, j, tmp_char);
  1258.       else
  1259.         tmp_char[0] = ' ';
  1260.       if (py.flags.image > 0)
  1261.         if (randint(12) == 1)
  1262.           tmp_char[0] = (randint(95) + 31);
  1263.       if (flag)
  1264.         {
  1265.           if (xpos < 0)  xpos = j;
  1266.           if (strlen(save_str) > 0)
  1267.         {
  1268.           (void) strcat(floor_str, save_str);
  1269.           save_str[0] = '\0';
  1270.         }
  1271.           (void) strcat(floor_str, tmp_char);
  1272.         }
  1273.       else if (xpos >= 0)
  1274.         (void) strcat(save_str, tmp_char);
  1275.     }
  1276.       if (xpos >= 0)
  1277.     {
  1278.       print(floor_str, i, xpos);
  1279.     }
  1280.     }
  1281. }
  1282.  
  1283.  
  1284. /* Normal movement                    */
  1285. sub1_move_light(y1, x1, y2, x2)
  1286. register int x1, x2;
  1287. int y1, y2;
  1288. {
  1289.   register int i, j;
  1290.  
  1291.   light_flag = TRUE;
  1292.   for (i = y1-1; i <= y1+1; i++)       /* Turn off lamp light   */
  1293.     for (j = x1-1; j <= x1+1; j++)
  1294.       cave[i][j].tl = FALSE;
  1295.   for (i = y2-1; i <= y2+1; i++)
  1296.     for (j = x2-1; j <= x2+1; j++)
  1297.       cave[i][j].tl = TRUE;
  1298.   draw_block(y1, x1, y2, x2);        /* Redraw area           */
  1299. }
  1300.  
  1301. /* When FIND_FLAG,  light only permanent features     */
  1302. sub2_move_light(y1, x1, y2, x2)
  1303. int y1, x1, y2, x2;
  1304. {
  1305.   register int i, j;
  1306.   int xpos;
  1307.   vtype floor_str, save_str;
  1308.   char tmp_char[2];
  1309.   int flag;
  1310.   register cave_type *c_ptr;
  1311.  
  1312.   tmp_char[1] = '\0';
  1313.   if (light_flag)
  1314.     {
  1315.       for (i = y1-1; i <= y1+1; i++)
  1316.     for (j = x1-1; j <= x1+1; j++)
  1317.       cave[i][j].tl = FALSE;
  1318.       draw_block(y1, x1, y1, x1);
  1319.       light_flag = FALSE;
  1320.     }
  1321.   for (i = y2-1; i <= y2+1; i++)
  1322.     {
  1323.       floor_str[0] = '\0';
  1324.       save_str[0] = '\0';
  1325.       xpos = 0;
  1326.       for (j = x2-1; j <= x2+1; j++)
  1327.     {
  1328.       c_ptr = &cave[i][j];
  1329.       flag = FALSE;
  1330.       if ((!c_ptr->fm) && (!c_ptr->pl))
  1331.         {
  1332.           tmp_char[0] = ' ';
  1333.           if (player_light)
  1334.         if (((c_ptr->fval >= 10) && (c_ptr->fval <= 12)) ||
  1335.             (c_ptr->fval == 15))
  1336.           {
  1337.             c_ptr->pl = TRUE; /* Turn on perm light    */
  1338.             loc_symbol(i, j, tmp_char);
  1339.             flag = TRUE;
  1340.           }
  1341.         else
  1342.           if (c_ptr->tptr != 0)
  1343.               if ((t_list[c_ptr->tptr].tval >= 102) &&
  1344.               (t_list[c_ptr->tptr].tval <= 110) &&
  1345.               (t_list[c_ptr->tptr].tval != 106))
  1346.               {
  1347.             c_ptr->fm = TRUE;     /* Turn on field marker  */
  1348.             loc_symbol(i, j, tmp_char);
  1349.             flag = TRUE;
  1350.               }
  1351.         }
  1352.       else
  1353.         loc_symbol(i, j, tmp_char);
  1354.       if (flag)
  1355.         {
  1356.           if (xpos == 0)  xpos = j;
  1357.           if (strlen(save_str) > 0)
  1358.         {
  1359.           (void) strcat(floor_str, save_str);
  1360.           save_str[0] = '\0';
  1361.         }
  1362.           (void) strcat(floor_str, tmp_char);
  1363.         }
  1364.       else if (xpos > 0)
  1365.         (void) strcat(save_str, tmp_char);
  1366.     }
  1367.       if (xpos > 0)
  1368.     {
  1369.       j = i;
  1370.       print(floor_str, j, xpos);
  1371.     }
  1372.     }
  1373. }
  1374.  
  1375. /* When blinded,  move only the player symbol...        */
  1376. sub3_move_light(y1, x1, y2, x2)
  1377. register int x1, y1;
  1378. int x2, y2;
  1379. {
  1380.   register int i, j;
  1381.  
  1382.   if (light_flag)
  1383.     {
  1384.       for (i = y1-1; i <= y1+1; i++)
  1385.     for (j = x1-1; j <= x1+1; j++)
  1386.       cave[i][j].tl = FALSE;
  1387.       light_flag = FALSE;
  1388.     }
  1389.   print(" ", y1, x1);
  1390.   print("@", y2, x2);
  1391. }
  1392.  
  1393. /* With no light,  movement becomes involved...        */
  1394. sub4_move_light(y1, x1, y2, x2)
  1395. register int y1, x1;
  1396. int y2, x2;
  1397. {
  1398.   register int i, j;
  1399.  
  1400.   light_flag = TRUE;
  1401.   if (cave[y1][x1].tl)
  1402.     {
  1403.       for (i = y1-1; i <= y1+1; i++)
  1404.     for (j = x1-1; j <= x1+1; j++)
  1405.       {
  1406.         cave[i][j].tl = FALSE;
  1407.         if (test_light(i, j))
  1408.           lite_spot(i, j);
  1409.         else
  1410.           unlite_spot(i, j);
  1411.       }
  1412.     }
  1413.   else if (test_light(y1, x1))
  1414.     lite_spot(y1, x1);
  1415.   else
  1416.     unlite_spot(y1, x1);
  1417.   print("@", y2, x2);
  1418. }
  1419.  
  1420. /* Package for moving the character's light about the screen     */
  1421. /* Three cases : Normal,  Finding, and Blind              -RAK-   */
  1422. move_light(y1, x1, y2, x2)
  1423. int y1, x1, y2, x2;
  1424. {
  1425.   if (py.flags.blind > 0)
  1426.     sub3_move_light(y1, x1, y2, x2);
  1427.   else if (find_flag)
  1428.     sub2_move_light(y1, x1, y2, x2);
  1429.   else if (!player_light)
  1430.     sub4_move_light(y1, x1, y2, x2);
  1431.   else
  1432.     sub1_move_light(y1, x1, y2, x2);
  1433. }
  1434.  
  1435.  
  1436. /* Returns random co-ordinates                -RAK-    */
  1437. new_spot(y, x)
  1438. register int *y, *x;
  1439. {
  1440.   do
  1441.     {
  1442.       *y = randint(cur_height) - 1;
  1443.       *x = randint(cur_width) - 1;
  1444.     }
  1445.   while ((!cave[*y][*x].fopen) || (cave[*y][*x].cptr != 0) ||
  1446.        (cave[*y][*x].tptr != 0));
  1447. }
  1448.  
  1449.  
  1450. /* Search Mode enhancement                -RAK-    */
  1451. search_on()
  1452. {
  1453.   search_flag = TRUE;
  1454.   change_speed(1);
  1455.   py.flags.status |= 0x00000100;
  1456.   prt_search();
  1457.   py.flags.food_digested++;
  1458. }
  1459.  
  1460. search_off()
  1461. {
  1462.   search_flag = FALSE;
  1463.   find_flag = FALSE;
  1464.   move_light (char_row, char_col, char_row, char_col);
  1465.   change_speed(-1);
  1466.   py.flags.status &= 0xFFFFFEFF;
  1467.   prt_search();
  1468.   py.flags.food_digested--;
  1469. }
  1470.  
  1471.  
  1472. /* Resting allows a player to safely restore his hp    -RAK-    */
  1473. rest()
  1474. {
  1475.   int rest_num;
  1476.   vtype rest_str;
  1477.  
  1478.   prt("Rest for how long? ", 0, 0);
  1479.   rest_num = 0;
  1480.   if (get_string(rest_str, 0, 19, 10))
  1481.     (void) sscanf(rest_str, "%d", &rest_num);
  1482.   if (rest_num > 0)
  1483.     {
  1484.       if (search_flag)
  1485.     search_off();
  1486.       py.flags.rest = rest_num;
  1487.       py.flags.status |= 0x00000200;
  1488.       prt_rest();
  1489.       py.flags.food_digested--;
  1490. #ifdef MSDOS
  1491.       msg_print("Press any key to stop resting...");
  1492. #else
  1493.       msg_print("Press ^C to wake up...");
  1494. #endif
  1495.       put_qio();
  1496.     }
  1497.   else
  1498.     {
  1499.       erase_line(MSG_LINE, 0);
  1500.       reset_flag = TRUE;
  1501.     }
  1502. }
  1503.  
  1504. rest_off()
  1505. {
  1506.   py.flags.rest = 0;
  1507.   py.flags.status &= 0xFFFFFDFF;
  1508.   erase_line(0, 0);
  1509.   prt_rest();
  1510.   py.flags.food_digested++;
  1511. }
  1512.  
  1513.  
  1514. /* Attacker's level and plusses,  defender's AC        -RAK-    */
  1515. int test_hit(bth, level, pth, ac)
  1516. int bth, level, pth, ac;
  1517. {
  1518.   register int i;
  1519.   int test;
  1520.  
  1521.   if (search_flag)
  1522.     search_off();
  1523.   if (py.flags.rest > 0)
  1524.     rest_off();
  1525.   i = bth + level*BTH_LEV_ADJ + pth*BTH_PLUS_ADJ;
  1526.   /* pth could be less than 0 if player wielding weapon too heavy for him */
  1527.   if ((i > 0) && (randint(i) > ac))               /* Normal hit            */
  1528.     test = TRUE;
  1529.   else if (randint(20) == 1)           /* Always hit 1/20       */
  1530.     test = TRUE;
  1531.   else                                    /* Missed                */
  1532.     {
  1533.       if (i <= 0)
  1534.     msg_print("You have trouble swinging such a heavy weapon.");
  1535.       test = FALSE;
  1536.     }
  1537.   return(test);
  1538. }
  1539.  
  1540.  
  1541. /* Decreases players hit points and sets death flag if necessary*/
  1542. /*                                                       -RAK-   */
  1543. take_hit(damage, hit_from)
  1544. int damage;
  1545. char *hit_from;
  1546. {
  1547.   if (py.flags.invuln > 0)  damage = 0;
  1548.   py.misc.chp -= (double)damage;
  1549.   if (search_flag)  search_off();
  1550.   if (py.flags.rest > 0)  rest_off();
  1551.   if (find_flag)
  1552.     {
  1553.       find_flag = FALSE;
  1554.       move_light (char_row, char_col, char_row, char_col);
  1555.     }
  1556.   flush();
  1557.   if (py.misc.chp <= -1)
  1558.     {
  1559.       if (!death)
  1560.     {             /* Hee,  hee... Ain't I mean?     */
  1561.       death = TRUE;
  1562.       (void) strcpy(died_from, hit_from);
  1563.       total_winner = FALSE;
  1564.     }
  1565.       moria_flag = TRUE;
  1566.     }
  1567.   else
  1568.     prt_chp();
  1569. }
  1570.  
  1571.  
  1572. /* Given speed,  returns number of moves this turn.    -RAK-    */
  1573. /* NOTE: Player must always move at least once per iteration,     */
  1574. /*       a slowed player is handled by moving monsters faster    */
  1575. int movement_rate(speed)
  1576. int speed;
  1577. {
  1578.   if (speed > 0)
  1579.     {
  1580.       if (py.flags.rest > 0)
  1581.     return 1;
  1582.       else
  1583.     return speed;
  1584.     }
  1585.   else
  1586.     {
  1587.       /* speed must be negative here */
  1588.       return ((turn % (2 - speed)) == 0);
  1589. /*    if ((turn % (2 - speed)) == 0)
  1590.     return 1;
  1591.       else
  1592.     return 0;  */
  1593.     }
  1594. }
  1595.  
  1596.  
  1597. /* Regenerate hit points                 -RAK-    */
  1598. regenhp(percent)
  1599. double percent;
  1600. {
  1601.   register struct misc *p_ptr;
  1602.  
  1603.   p_ptr = &py.misc;
  1604.   p_ptr->chp += p_ptr->mhp*percent + PLAYER_REGEN_HPBASE;
  1605. }
  1606.  
  1607.  
  1608. /* Regenerate mana points                -RAK-    */
  1609. regenmana(percent)
  1610. double percent;
  1611. {
  1612.   register struct misc *p_ptr;
  1613.  
  1614.   p_ptr = &py.misc;
  1615.   p_ptr->cmana += p_ptr->mana*percent + PLAYER_REGEN_MNBASE;
  1616. }
  1617.  
  1618.  
  1619. /* Change a trap from invisible to visible        -RAK-    */
  1620. /* Note: Secret doors are handled here                           */
  1621. change_trap(y, x)
  1622. register int y, x;
  1623. {
  1624.   register int k;
  1625.   register cave_type *c_ptr;
  1626.  
  1627.   c_ptr = &cave[y][x];
  1628.   if ((t_list[c_ptr->tptr].tval == 101) || (t_list[c_ptr->tptr].tval == 109))
  1629.     {
  1630.       k = c_ptr->tptr;
  1631.       /* subtract one, since zeroth item has subval of one */
  1632.       place_trap(y, x, 2, t_list[k].subval-1);
  1633.       pusht(k);
  1634.       lite_spot(y, x);
  1635.     }
  1636. }
  1637.  
  1638.  
  1639. /* Searches for hidden things...             -RAK-    */
  1640. search(y, x, chance)
  1641. int y, x, chance;
  1642. {
  1643.   register int i, j;
  1644.   register cave_type *c_ptr;
  1645.   register treasure_type *t_ptr;
  1646.   register struct flags *p_ptr;
  1647.   vtype tmp_str;
  1648.  
  1649.   p_ptr = &py.flags;
  1650.   if (p_ptr->confused+p_ptr->blind > 0)
  1651.     chance = chance / 10.0;
  1652.   else if (no_light())
  1653.     chance = chance / 5.0;
  1654.   for (i = (y - 1); i <= (y + 1); i++)
  1655.     for (j = (x - 1); j <= (x + 1); j++)
  1656.       if (in_bounds(i, j))
  1657.     if ((i != y) || (j != x))
  1658.       if (randint(100) < chance)
  1659.         {
  1660.           c_ptr = &cave[i][j];
  1661.           /* Search for hidden objects             */
  1662.           if (c_ptr->tptr != 0)
  1663.         {
  1664.           t_ptr = &t_list[c_ptr->tptr];
  1665.           /* Trap on floor?                */
  1666.           if (t_ptr->tval == 101)
  1667.             {
  1668.               (void) sprintf(tmp_str,"You have found %s.",t_ptr->name);
  1669.               msg_print(tmp_str);
  1670.               change_trap(i, j);
  1671.               if (find_flag)
  1672.             {
  1673.               find_flag = FALSE;
  1674.               move_light (char_row, char_col, char_row, char_col);
  1675.             }
  1676.             }
  1677.           /* Secret door?                  */
  1678.           else if (t_ptr->tval == 109)
  1679.             {
  1680.               msg_print("You have found a secret door.");
  1681.               c_ptr->fval = corr_floor2.ftval;
  1682.               change_trap(i, j);
  1683.               if (find_flag)
  1684.             {
  1685.               find_flag = FALSE;
  1686.               move_light (char_row, char_col, char_row, char_col);
  1687.             }
  1688.             }
  1689.           /* Chest is trapped?             */
  1690.           else if (t_ptr->tval == 2)
  1691.             {
  1692.               /* mask out the treasure bits */
  1693.               if ((t_ptr->flags & 0x00FFFFFF) > 1)
  1694.             if (index(t_ptr->name, '^') != 0)
  1695.               {
  1696.                 known2(t_ptr->name);
  1697.              msg_print("You have discovered a trap on the chest!");
  1698.               }
  1699.             else
  1700.               {
  1701.                 msg_print("The chest is trapped!");
  1702.               }
  1703.             }
  1704.         }
  1705.         }
  1706. }
  1707.  
  1708.  
  1709. /* Turns off Find_flag if something interesting appears    -RAK-    */
  1710. /* BUG: Does not handle corridor/room corners, but I didn't want */
  1711. /*      to add a lot of checking for such a minor detail         */
  1712. void area_affect(dir, y, x)
  1713. int dir, y, x;
  1714. {
  1715.   int z[3];
  1716.   register int i;
  1717.   int row, col;
  1718.   register cave_type *c_ptr;
  1719.   monster_type *m_ptr;
  1720.  
  1721.   if (cave[y][x].fval == 4)
  1722.     {
  1723.       i = 0;
  1724.       if (next_to4(y, x, 4, 5, 6) > 2)
  1725.     {
  1726.       find_flag = FALSE;  /* no need to call move_light () */
  1727.       return;
  1728.     }
  1729.     }
  1730.   if ((find_flag) && (py.flags.blind < 1))
  1731.     {
  1732.       switch(dir)
  1733.     {
  1734.     case 1:
  1735.       z[0] = 4;
  1736.       z[1] = 1;
  1737.       z[2] = 3;
  1738.       break;
  1739.     case 2:
  1740.       z[0] = 4;
  1741.       z[1] = 2;
  1742.       z[2] = 6;
  1743.       break;
  1744.     case 3:
  1745.       z[0] = 2;
  1746.       z[1] = 3;
  1747.       z[2] = 6;
  1748.       break;
  1749.     case 4:
  1750.       z[0] = 8;
  1751.       z[1] = 4;
  1752.       z[2] = 2;
  1753.       break;
  1754.     case 6:
  1755.       z[0] = 2;
  1756.       z[1] = 6;
  1757.       z[2] = 8;
  1758.       break;
  1759.     case 7:
  1760.       z[0] = 8;
  1761.       z[1] = 7;
  1762.       z[2] = 4;
  1763.       break;
  1764.     case 8:
  1765.       z[0] = 4;
  1766.       z[1] = 8;
  1767.       z[2] = 6;
  1768.       break;
  1769.     case 9:
  1770.       z[0] = 8;
  1771.       z[1] = 9;
  1772.       z[2] = 6;
  1773.       break;
  1774.     }
  1775.       for (i = 0; i < 3; i++)
  1776.     {
  1777.       row = y;
  1778.       col = x;
  1779.       if (move(z[i], &row, &col))
  1780.         {
  1781.           c_ptr = &cave[row][col];
  1782.           /* Empty doorways        */
  1783.           if (c_ptr->fval == 5)
  1784.         {
  1785.           find_flag = FALSE;  /* no need to call move_light () */
  1786.           return;
  1787.         }
  1788.           /* Objects player can see*/
  1789.           /* Including doors       */
  1790.           if (find_flag)
  1791.         if (player_light)
  1792.           {
  1793.             if (c_ptr->tptr != 0)
  1794.               if ((t_list[c_ptr->tptr].tval != 101) &&
  1795.               (t_list[c_ptr->tptr].tval != 109))
  1796.             {
  1797.               find_flag = FALSE;  /* no need to call move_light */
  1798.               return;
  1799.             }
  1800.           }
  1801.         else if ((c_ptr->tl) || (c_ptr->pl) || (c_ptr->fm))
  1802.           if (c_ptr->tptr != 0)
  1803.             if ((t_list[c_ptr->tptr].tval != 101) &&
  1804.             (t_list[c_ptr->tptr].tval != 109))
  1805.               {
  1806.             find_flag = FALSE;  /* no need to call move_light */
  1807.             return;
  1808.               }
  1809.           /* Creatures             */
  1810.           if (find_flag)
  1811.         if ((c_ptr->tl) || (c_ptr->pl) || (player_light))
  1812.           if (c_ptr->cptr > 1)
  1813.             {
  1814.               m_ptr = &m_list[c_ptr->cptr];
  1815.               if (m_ptr->ml)
  1816.             {
  1817.               find_flag = FALSE;  /* no need to call move_light */
  1818.               return;
  1819.             }
  1820.             }
  1821.         }
  1822.     }
  1823.     }
  1824.   return;
  1825. }
  1826.  
  1827.  
  1828. /* Picks new direction when in find mode         -RAK-    */
  1829. int pick_dir(dir)
  1830. int dir;
  1831. {
  1832.   int z[2];
  1833.   register int i, pick;
  1834.   int y, x;
  1835.  
  1836.   if ((find_flag) && (next_to4(char_row, char_col, 4, 5, -1) == 2))
  1837.     {
  1838.       switch(dir)
  1839.     {
  1840.     case 1:
  1841.       z[0] = 2;
  1842.       z[1] = 4;
  1843.       break;
  1844.     case 2:
  1845.       z[0] = 4;
  1846.       z[1] = 6;
  1847.       break;
  1848.     case 3:
  1849.       z[0] = 2;
  1850.       z[1] = 6;
  1851.       break;
  1852.     case 4:
  1853.       z[0] = 2;
  1854.       z[1] = 8;
  1855.       break;
  1856.     case 6:
  1857.       z[0] = 2;
  1858.       z[1] = 8;
  1859.       break;
  1860.     case 7:
  1861.       z[0] = 4;
  1862.       z[1] = 8;
  1863.       break;
  1864.     case 8:
  1865.       z[0] = 4;
  1866.       z[1] = 6;
  1867.       break;
  1868.     case 9:
  1869.       z[0] = 6;
  1870.       z[1] = 8;
  1871.       break;
  1872.     }
  1873.       pick = FALSE;
  1874.       for (i = 0; i < 2; i++)
  1875.     {
  1876.       y = char_row;
  1877.       x = char_col;
  1878.       if (move(z[i], &y, &x))
  1879.         if (cave[y][x].fopen)
  1880.           {
  1881.         pick = TRUE;
  1882.         global_com_val = z[i] + 48;
  1883.         }
  1884.     }
  1885.     }
  1886.   else
  1887.     {
  1888.       pick = FALSE;
  1889.     }
  1890.   return(pick);
  1891. }
  1892.  
  1893.  
  1894. /* AC gets worse                     -RAK-    */
  1895. /* Note: This routine affects magical AC bonuses so that stores   */
  1896. /*       can detect the damage.                                  */
  1897. int minus_ac(typ_dam)
  1898. bitset_t typ_dam;
  1899. {
  1900.   register int i, j;
  1901.   int tmp[6];
  1902.   int minus;
  1903.   register treasure_type *i_ptr;
  1904.   bigvtype out_val, tmp_str;
  1905.  
  1906.   i = 0;
  1907.   if (inventory[INVEN_BODY].tval != 0)
  1908.     {
  1909.       tmp[i] = INVEN_BODY;
  1910.       i++;
  1911.     }
  1912.   if (inventory[INVEN_ARM].tval != 0)
  1913.     {
  1914.       tmp[i] = INVEN_ARM;
  1915.       i++;
  1916.     }
  1917.   if (inventory[INVEN_OUTER].tval != 0)
  1918.     {
  1919.       tmp[i] = INVEN_OUTER;
  1920.       i++;
  1921.     }
  1922.   if (inventory[INVEN_HANDS].tval != 0)
  1923.     {
  1924.       tmp[i] = INVEN_HANDS;
  1925.       i++;
  1926.     }
  1927.   if (inventory[INVEN_HEAD].tval != 0)
  1928.     {
  1929.       tmp[i] = INVEN_HEAD;
  1930.       i++;
  1931.     }
  1932.   /* also affect boots */
  1933.   if (inventory[INVEN_FEET].tval != 0)
  1934.     {
  1935.       tmp[i] = INVEN_FEET;
  1936.       i++;
  1937.     }
  1938.   minus = FALSE;
  1939.   if (i > 0)
  1940.     {
  1941.       j = tmp[randint(i) - 1];
  1942.       i_ptr = &inventory[j];
  1943.       if (i_ptr->flags & typ_dam)
  1944.     {
  1945.       objdes(tmp_str, j, FALSE);
  1946.       (void) sprintf(out_val, "Your %s resists damage!", tmp_str);
  1947.       msg_print(out_val);
  1948.       minus = TRUE;
  1949.     }
  1950.       else if ((i_ptr->ac+i_ptr->toac) > 0)
  1951.     {
  1952.       objdes(tmp_str, j, FALSE);
  1953.       (void) sprintf(out_val, "Your %s is damaged!", tmp_str);
  1954.       msg_print(out_val);
  1955.       i_ptr->toac--;
  1956.       py_bonuses(blank_treasure, 0);
  1957.       minus = TRUE;
  1958.     }
  1959.     }
  1960.   return(minus);
  1961. }
  1962.  
  1963.  
  1964. /* Corrode the unsuspecting person's armor               -RAK-   */
  1965. corrode_gas(kb_str)
  1966. char *kb_str;
  1967. {
  1968.   int set_corrodes();
  1969.  
  1970.   if (!minus_ac((bitset_t) 0x00100000))
  1971.     take_hit(randint(8), kb_str);
  1972.   print_stat |= 0x0040;
  1973.   if (inven_damage(set_corrodes, 5) > 0)
  1974.     msg_print("There is an acrid smell coming from your pack.");
  1975. }
  1976.  
  1977.  
  1978. /* Poison gas the idiot...                -RAK-    */
  1979. poison_gas(dam, kb_str)
  1980. int dam;
  1981. char *kb_str;
  1982. {
  1983.   take_hit(dam, kb_str);
  1984.   print_stat |= 0x0040;
  1985.   py.flags.poisoned += 12 + randint(dam);
  1986. }
  1987.  
  1988.  
  1989. /* Burn the fool up...                    -RAK-    */
  1990. fire_dam(dam, kb_str)
  1991. int dam;
  1992. char *kb_str;
  1993. {
  1994.   int set_flammable();
  1995.  
  1996.   if (py.flags.fire_resist)
  1997.     dam = dam / 3;
  1998.   if (py.flags.resist_heat > 0)
  1999.     dam = dam / 3;
  2000.   take_hit(dam, kb_str);
  2001.   print_stat |= 0x0080;
  2002.   if (inven_damage(set_flammable, 3) > 0)
  2003.     msg_print("There is smoke coming from your pack!");
  2004. }
  2005.  
  2006.  
  2007. /* Freeze him to death...                -RAK-    */
  2008. cold_dam(dam, kb_str)
  2009. int dam;
  2010. char *kb_str;
  2011. {
  2012.   int set_frost_destroy();
  2013.  
  2014.   if (py.flags.cold_resist)
  2015.     dam = dam / 3;
  2016.   if (py.flags.resist_cold > 0)
  2017.     dam = dam / 3;
  2018.   take_hit(dam, kb_str);
  2019.   print_stat |= 0x0080;
  2020.   if (inven_damage(set_frost_destroy, 5) > 0)
  2021.     msg_print("Something shatters inside your pack!");
  2022. }
  2023.  
  2024.  
  2025. /* Lightning bolt the sucker away...            -RAK-    */
  2026. light_dam(dam, kb_str)
  2027. int dam;
  2028. char *kb_str;
  2029. {
  2030.   if (py.flags.lght_resist)
  2031.     take_hit((dam / 3), kb_str);
  2032.   else
  2033.     take_hit(dam, kb_str);
  2034.   print_stat |= 0x0080;
  2035. }
  2036.  
  2037.  
  2038. /* Throw acid on the hapless victim            -RAK-    */
  2039. acid_dam(dam, kb_str)
  2040. int dam;
  2041. char *kb_str;
  2042. {
  2043.   int flag;
  2044.   int set_acid_affect();
  2045.  
  2046.   flag = 0;
  2047.   if (minus_ac((bitset_t) 0x00100000))
  2048.     flag = 1;
  2049.   if (py.flags.acid_resist)
  2050.     flag += 2;
  2051.   switch(flag)
  2052.     {
  2053.     case 0: take_hit(dam, kb_str);       break;
  2054.     case 1: take_hit((dam / 2), kb_str); break;
  2055.     case 2: take_hit((dam / 3), kb_str); break;
  2056.     case 3: take_hit((dam / 4), kb_str); break;
  2057.     }
  2058.   print_stat |= 0x00C0;
  2059.   if (inven_damage(set_acid_affect, 3) > 0)
  2060.     msg_print("There is an acrid smell coming from your pack!");
  2061. }
  2062.