home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / umoria / part03 / spells.c < prev   
C/C++ Source or Header  |  1987-11-04  |  51KB  |  2,471 lines

  1. #include <stdio.h>
  2. #ifdef USG
  3. #include <string.h>
  4. #else
  5. #include <strings.h>
  6. #endif
  7.  
  8. #include "constants.h"
  9. #include "types.h"
  10. #include "externs.h"
  11.  
  12. #ifdef sun   /* correct SUN stupidity in the stdio.h file */
  13. char *sprintf();
  14. #endif
  15.  
  16. extern char cur_char2();
  17.  
  18. /* Following are spell procedure/functions            -RAK-    */
  19. /* These routines are commonly used in the scroll, potion, wands, and    */
  20. /* staves routines, and are occasionally called from other areas.         */
  21. /* Now included are creature spells also...                      -RAK    */
  22.  
  23. /* Sleep creatures adjacent to player            -RAK-    */
  24. int sleep_monsters1(y, x)
  25. int y, x;
  26. {
  27.   int i, j;
  28.   cave_type *c_ptr;
  29.   monster_type *m_ptr;
  30.   creature_type *r_ptr;
  31.   int sleep;
  32.   vtype out_val;
  33.  
  34.   sleep = FALSE;
  35.   for (i = y-1; i <= y+1; i++)
  36.     for (j = x-1; j <= x+1; j++)
  37.       {
  38.     c_ptr = &cave[i][j];
  39.     if (c_ptr->cptr > 1) 
  40.       {
  41.         m_ptr = &m_list[c_ptr->cptr];
  42.         r_ptr = &c_list[m_ptr->mptr];
  43.  
  44.         sleep = TRUE;
  45.         if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  46.         (0x1000 & r_ptr->cdefense))
  47.           {
  48.         (void) sprintf(out_val, "The %s is unaffected.", r_ptr->name);
  49.         msg_print(out_val);
  50.           }
  51.         else
  52.           {
  53.         (void) sprintf(out_val, "The %s falls asleep.", r_ptr->name);
  54.         msg_print(out_val);
  55.         m_ptr->csleep = 500;
  56.           }
  57.       }
  58.       }
  59.   return(sleep);
  60. }
  61.  
  62. /* Detect any monsters on the current panel        -RAK-    */
  63. int detect_treasure()
  64. {
  65.   int i, j;
  66.   int detect;
  67.   cave_type *c_ptr;
  68.  
  69.   detect = FALSE;
  70.   for (i = panel_row_min; i <= panel_row_max; i++)
  71.     for (j = panel_col_min; j <= panel_col_max; j++)
  72.       {
  73.     c_ptr = &cave[i][j];
  74.     if (c_ptr->tptr != 0) 
  75.       if (t_list[c_ptr->tptr].tval == 100) 
  76.         if (!test_light(i, j)) 
  77.           {
  78.         lite_spot(i, j);
  79.         c_ptr->tl = TRUE;
  80.         detect = TRUE;
  81.           }
  82.       }
  83.   return(detect);
  84. }
  85.  
  86.  
  87. /* Detect all objects on the current panel        -RAK-    */
  88. int detect_object()
  89. {
  90.   int i, j;
  91.   int detect;
  92.   cave_type *c_ptr;
  93.  
  94.   detect = FALSE;
  95.   for (i = panel_row_min; i <= panel_row_max; i++)
  96.     for (j = panel_col_min; j <= panel_col_max; j++)
  97.       {
  98.     c_ptr = &cave[i][j];
  99.     if (c_ptr->tptr != 0) 
  100.       if (t_list[c_ptr->tptr].tval < 100) 
  101.         if (!test_light(i, j)) 
  102.           {
  103.         lite_spot(i, j);
  104.         c_ptr->tl = TRUE;
  105.         detect = TRUE;
  106.           }
  107.       }
  108.   return(detect);
  109. }
  110.  
  111.  
  112. /* Locates and displays traps on current panel        -RAK-    */
  113. int detect_trap()
  114. {
  115.   int i, j;
  116.   int detect;
  117.   cave_type *c_ptr;
  118.   treasure_type *t_ptr;
  119.  
  120.   detect = FALSE;
  121.   for (i = panel_row_min; i <= panel_row_max; i++)
  122.     for (j = panel_col_min; j <= panel_col_max; j++)
  123.       {
  124.     c_ptr = &cave[i][j];
  125.     if (c_ptr->tptr != 0) 
  126.       if (t_list[c_ptr->tptr].tval == 101) 
  127.         {
  128.           change_trap(i, j);
  129.           c_ptr->fm = TRUE;
  130.           detect = TRUE;
  131.         }
  132.       else if (t_list[c_ptr->tptr].tval == 2) 
  133.         {
  134.           t_ptr = &t_list[c_ptr->tptr];
  135.           known2(t_ptr->name);
  136.         }
  137.       }
  138.   return(detect);
  139. }
  140.  
  141.  
  142. /* Locates and displays all secret doors on current panel -RAK-    */
  143. int detect_sdoor()
  144. {
  145.   int i, j;
  146.   int detect;
  147.   cave_type *c_ptr;
  148.   
  149.   detect = FALSE;
  150.   for (i = panel_row_min; i <= panel_row_max; i++)
  151.     for (j = panel_col_min; j <= panel_col_max; j++)
  152.       {
  153.     c_ptr = &cave[i][j];
  154.     if (c_ptr->tptr != 0) 
  155.       /* Secret doors  */
  156.       if (t_list[c_ptr->tptr].tval == 109) 
  157.         {
  158.           c_ptr->fval = corr_floor3.ftval;
  159.           change_trap(i, j);
  160.           c_ptr->fm = TRUE;
  161.           detect = TRUE;
  162.         }
  163.     /* Staircases    */
  164.       else if ((t_list[c_ptr->tptr].tval == 107) || 
  165.            (t_list[c_ptr->tptr].tval == 108)) 
  166.         if (!c_ptr->fm) 
  167.           {
  168.         c_ptr->fm = TRUE;
  169.         lite_spot(i, j);
  170.         detect = TRUE;
  171.           }
  172.       }
  173.   return(detect);
  174. }
  175.  
  176.  
  177. /* Locates and displays all invisible creatures on current panel -RAK-*/
  178. int detect_invisible()
  179. {
  180.   int i;
  181.   int flag;
  182.   char tmp_str[2];
  183.   monster_type *m_ptr;
  184.  
  185.   flag = FALSE;
  186.   i = muptr;
  187.   while (i > 0)
  188.     {
  189.       m_ptr = &m_list[i];
  190.       if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx)) 
  191.     if (0x10000 & c_list[m_ptr->mptr].cmove)
  192.       {
  193.         m_ptr->ml = TRUE;
  194.         tmp_str[0] = c_list[m_ptr->mptr].cchar;
  195.         tmp_str[1] = '\0';
  196.         print(tmp_str, (int)m_ptr->fy, (int)m_ptr->fx);
  197.         flag = TRUE;
  198.       }
  199.       i = m_list[i].nptr;
  200.     }
  201.   if (flag) 
  202.     {
  203.       msg_print("You sense the presence of invisible creatures!");
  204.       msg_print(" ");
  205.       msg_flag = FALSE;
  206.     }
  207.   return(flag);
  208. }
  209.  
  210.  
  211. /* Light an area: 1.  If corridor  light immediate area -RAK-*/
  212. /*                2.  If room  light entire room.            */
  213. int light_area(y, x)
  214. int y, x;
  215. {
  216.   int i, j;
  217.   int light;
  218.  
  219.   msg_print("You are surrounded by a white light.");
  220.   light = TRUE;
  221.   if (((cave[y][x].fval == 1) || (cave[y][x].fval == 2)) && (dun_level > 0)) 
  222.     light_room(y, x);
  223.   else
  224.     for (i = y-1; i <= y+1; i++)
  225.       for (j = x-1; j <=  x+1; j++)
  226.     if (in_bounds(i, j)) 
  227.       {
  228.         if (!test_light(i, j)) 
  229.           lite_spot(i, j);
  230.         cave[i][j].pl = TRUE;
  231.       }
  232.   return(light);
  233. }
  234.  
  235.  
  236. /* Darken an area, opposite of light area        -RAK-    */
  237. int unlight_area(y, x)
  238. int y, x;
  239. {
  240.   int i, j, k, tmp1, tmp2;
  241.   int start_row, start_col;
  242.   int end_row, end_col;
  243.   int flag;
  244.   int unlight;
  245.   cave_type *c_ptr;
  246.   vtype out_val;
  247.  
  248.   flag = FALSE;
  249.   if (((cave[y][x].fval == 1) || (cave[y][x].fval == 2)) && (dun_level > 0)) 
  250.     {
  251.       tmp1 = (SCREEN_HEIGHT/2);
  252.       tmp2 = (SCREEN_WIDTH /2);
  253.       start_row = (y/tmp1)*tmp1 + 1;
  254.       start_col = (x/tmp2)*tmp2 + 1;
  255.       end_row = start_row + tmp1 - 1;
  256.       end_col = start_col + tmp2 - 1;
  257.       for (i = start_row; i <= end_row; i++)
  258.     {
  259.       out_val[0] = '\0';
  260.       k = 0;
  261.       for (j = start_col; j <= end_col; j++)
  262.         {
  263.           c_ptr = &cave[i][j];
  264.           if ((c_ptr->fval == 1) || (c_ptr->fval == 2))
  265.         {
  266.           c_ptr->pl = FALSE;
  267.           c_ptr->fval = 1;
  268.           if (!test_light(i, j)) 
  269.             {
  270.               if (k == 0) 
  271.             k = j;
  272.               (void) strcat(out_val, " ");
  273.             }
  274.           else if (k > 0) 
  275.             {
  276.               flag = TRUE;
  277.               print(out_val, i, k);
  278.               out_val[0] = '\0';
  279.               k = 0;
  280.             }
  281.         }
  282.           else if (k > 0) 
  283.         {
  284.           flag = TRUE;
  285.           print(out_val, i, k);
  286.           out_val[0] = '\0';
  287.           k = 0;
  288.         }
  289.           if (k > 0) 
  290.         {
  291.           flag = TRUE;
  292.           print(out_val, i, k);
  293.         }
  294.         }
  295.     }
  296.     }
  297.   else
  298.     for (i = y-1; i <= y+1; i++)
  299.       for (j = x-1; j <= x+1; j++)
  300.     if (in_bounds(i, j)) 
  301.       {
  302.         c_ptr = &cave[i][j];
  303.         if ((c_ptr->fval == 4) || (c_ptr->fval == 5) || (c_ptr->fval ==6)) 
  304.           if (c_ptr->pl) 
  305.         {
  306.           c_ptr->pl = FALSE;
  307.           flag = TRUE;
  308.         }
  309.         if (flag) 
  310.           {
  311.         msg_print("Darkness surrounds you...");
  312.         unlight = TRUE;
  313.           }
  314.       }
  315.     else
  316.       unlight = FALSE;
  317.   return(unlight);
  318. }
  319.  
  320.  
  321. /* Map the current area plus some            -RAK-    */
  322. int map_area()
  323. {
  324.   int i, j, k, l, m, n, i7, i8;
  325.   int map;
  326.   cave_type *c_ptr;
  327.  
  328.   map = TRUE;
  329.   i = panel_row_min - randint(10);
  330.   j = panel_row_max + randint(10);
  331.   k = panel_col_min - randint(20);
  332.   l = panel_col_max + randint(20);
  333.   for (m = i; m <= j; m++)
  334.     for (n = k; n <= l; n++)
  335.       if (in_bounds(m, n)) 
  336.     if (set_floor(cave[m][n].fval))
  337.       for (i7 = m-1; i7 <= m+1; i7++)
  338.         for (i8 = n-1; i8 <= n+1; i8++)
  339.           {
  340.         c_ptr = &cave[i7][i8];
  341.         if (((c_ptr->fval >= 10) && (c_ptr->fval <= 12)) ||
  342.             (c_ptr->fval == 15))
  343.           c_ptr->pl = TRUE;
  344.         else if (c_ptr->tptr != 0) 
  345.           if ((t_list[c_ptr->tptr].tval >= 102) && 
  346.               (t_list[c_ptr->tptr].tval <= 110) && 
  347.               (t_list[c_ptr->tptr].tval != 106))
  348.             c_ptr->fm = TRUE;
  349.           }
  350.   prt_map();
  351.   return(map);
  352. }
  353.  
  354.  
  355. /* Identify an object                    -RAK-    */
  356. int ident_spell()
  357. {
  358.   int item_val;
  359.   vtype out_val, tmp_str;
  360.   int redraw;
  361.   int ident;
  362.   treasure_type *i_ptr;
  363.   
  364.   ident = FALSE;
  365.   redraw = FALSE;
  366.   if (get_item(&item_val, "Item you wish identified?",
  367.            &redraw, 0, inven_ctr-1))
  368.     {
  369.       i_ptr = &inventory[item_val];
  370.       ident = TRUE;
  371.       identify(inventory[item_val]);
  372.       known2(i_ptr->name);
  373.       objdes(tmp_str, item_val, TRUE);
  374.       (void) sprintf(out_val, "%c%c %s", item_val+97, cur_char2(item_val),
  375.              tmp_str);
  376.       msg_print(out_val);
  377.     }
  378.   if (redraw) 
  379.     {
  380.       msg_print(" ");
  381.       draw_cave();
  382.     }
  383.   return(ident);
  384. }
  385.  
  386.  
  387. /* Get all the monsters on the level pissed off...    -RAK-    */
  388. int aggravate_monster  (dis_affect)
  389. int dis_affect;
  390. {
  391.   int i;
  392.   int aggravate;
  393.   monster_type *m_ptr;
  394.  
  395.   aggravate = TRUE;
  396.   i = muptr;
  397.   while (i > 0)
  398.     {
  399.       m_ptr = &m_list[i];
  400.       m_ptr->csleep = 0;
  401.       if (m_ptr->cdis <= dis_affect) 
  402.     if (m_ptr->cspeed < 2) 
  403.       m_ptr->cspeed++;
  404.       i = m_list[i].nptr;
  405.     }
  406.   return(aggravate);
  407. }
  408.  
  409.  
  410. /* Surround the fool with traps (chuckle)        -RAK-    */
  411. int trap_creation()
  412. {
  413.   int i, j;
  414.   int trap;
  415.   cave_type *c_ptr;
  416.  
  417.   trap = TRUE;
  418.   for (i = char_row-1; i <= char_row+1; i++)
  419.     for (j = char_col-1; j <= char_col+1; j++)
  420.       {
  421.     c_ptr = &cave[i][j];
  422.     if (set_floor(c_ptr->fval))
  423.       {
  424.         if (c_ptr->tptr != 0) 
  425.           (void) delete_object(i, j);
  426.         place_trap(i, j, 1, randint(MAX_TRAPA)-1);
  427.       }
  428.       }
  429.   return(trap);
  430. }
  431.  
  432.  
  433. /* Surround the player with doors...            -RAK-    */
  434. int door_creation()
  435. {
  436.   int i, j, k;
  437.   int door;
  438.   cave_type *c_ptr;
  439.   
  440.   door = TRUE;
  441.   for (i = char_row-1; i <= char_row+1; i++)
  442.     for (j = char_col-1; j <=  char_col+1; j++)
  443.       if ((i != char_row) || (j != char_col)) 
  444.     {
  445.       c_ptr = &cave[i][j];
  446.       if (set_floor(c_ptr->fval))
  447.         {
  448.           popt(&k);
  449.           if (c_ptr->tptr != 0) 
  450.         (void) delete_object(i, j);
  451.           c_ptr->fopen = FALSE;
  452.           c_ptr->tptr = k;
  453.           t_list[k] = door_list[1];
  454.           if (test_light(i, j)) 
  455.         lite_spot(i, j);
  456.         }
  457.     }
  458.   return(door);
  459. }
  460.  
  461.  
  462. /* Destroys any adjacent door(s)/trap(s)         -RAK-    */
  463. int td_destroy()
  464. {
  465.   int i, j;
  466.   int destroy;
  467.   cave_type *c_ptr;
  468.   
  469.   destroy = FALSE;
  470.   for (i = char_row-1; i <= char_row+1; i++)
  471.     for (j = char_col-1; j <= char_col+1; j++)
  472.       {
  473.     c_ptr = &cave[i][j];
  474.     if (c_ptr->tptr != 0) 
  475.       {
  476.         if (((t_list[c_ptr->tptr].tval >= 101) &&
  477.          (t_list[c_ptr->tptr].tval <= 105) &&
  478.          (t_list[c_ptr->tptr].tval != 103)) ||
  479.         (t_list[c_ptr->tptr].tval == 109))
  480.           {
  481.         if (delete_object(i, j)) 
  482.           destroy = TRUE;
  483.           }
  484.         else if (t_list[c_ptr->tptr].tval == 2)
  485.           /* destroy traps on chest and unlock */
  486.           t_list[c_ptr->tptr].flags &= 0xFF000000;
  487.       }
  488.       }
  489.   return(destroy);
  490. }
  491.  
  492.  
  493. /* Display all creatures on the current panel        -RAK-    */
  494. int detect_monsters()
  495. {
  496.   int i;
  497.   int flag;
  498.   int detect;
  499.   char tmp_str[2];
  500.   monster_type *m_ptr;
  501.  
  502.   flag = FALSE;
  503.   i = muptr;
  504.   while (i > 0)
  505.     {
  506.       m_ptr = &m_list[i];
  507.       if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx)) 
  508.     if ((0x10000 & c_list[m_ptr->mptr].cmove) == 0) 
  509.       {
  510.         m_ptr->ml = TRUE;
  511.         tmp_str[0] = c_list[m_ptr->mptr].cchar;
  512.         tmp_str[1] = '\0';
  513.         print(tmp_str, (int)m_ptr->fy, (int)m_ptr->fx);
  514.         flag = TRUE;
  515.       }
  516.       i = m_list[i].nptr;
  517.     }
  518.   if (flag) 
  519.     {
  520.       msg_print("You sense the presence of monsters!");
  521.       msg_print(" ");
  522.       msg_flag = FALSE;
  523.       detect = TRUE;
  524.     }
  525.   detect = flag;
  526.   return(detect);
  527. }
  528.  
  529.  
  530. /* Leave a line of light in given dir, blue light can sometimes    */
  531. /* hurt creatures...                                     -RAK-   */
  532. light_line(dir, y, x)
  533. int dir, y, x;
  534. {
  535.   int i;
  536.   cave_type *c_ptr;
  537.   monster_type *m_ptr;
  538.   creature_type *r_ptr;
  539.   vtype out_val;
  540.  
  541.   while (cave[y][x].fopen)
  542.     {
  543.       c_ptr = &cave[y][x];
  544.       if (panel_contains(y, x)) 
  545.     {
  546.       if ((!c_ptr->tl) && (!c_ptr->pl))
  547.         if (c_ptr->fval == 2) 
  548.           light_room(y, x);
  549.         else
  550.           lite_spot(y, x);
  551.       if (c_ptr->cptr > 1) 
  552.         {
  553.           m_ptr = &m_list[c_ptr->cptr];
  554.           r_ptr = &c_list[m_ptr->mptr];
  555.           if (0x0100 & r_ptr->cdefense)
  556.         {
  557.           (void) sprintf(out_val, "The %s wails out in pain!",
  558.                  r_ptr->name);
  559.           msg_print(out_val);
  560.           i = mon_take_hit((int)c_ptr->cptr, damroll("2d8"));
  561.           if (i > 0) 
  562.             {
  563.               (void) sprintf(out_val, "The %s dies in a fit of agony.",
  564.                   r_ptr->name);
  565.               msg_print(out_val);
  566.             }
  567.         }
  568.         }
  569.       c_ptr->pl = TRUE;
  570.     }
  571.       (void) move(dir, &y, &x);
  572.     }
  573. }
  574.  
  575.  
  576. /* Light line in all directions                -RAK-    */
  577. int starlite(y, x)
  578. int y, x;
  579. {
  580.   int i;
  581.  
  582.   msg_print("The end of the staff bursts into a blue shimmering light.");
  583.   for (i = 1; i <= 9; i++)
  584.     if (i != 5) 
  585.       light_line(i, y, x);
  586.   return(TRUE);
  587. }
  588.  
  589.  
  590. /* Disarms all traps/chests in a given direction     -RAK-    */
  591. int disarm_all(dir, y, x)
  592. int dir, y, x;
  593. {
  594.   int i, oldy, oldx;
  595.   int disarm;
  596.   cave_type *c_ptr;
  597.   treasure_type *t_ptr;
  598.   char *string;
  599.   
  600.   disarm = FALSE;
  601.   do
  602.     {
  603.       c_ptr = &cave[y][x];
  604.       if (c_ptr->tptr != 0) 
  605.     {
  606.       t_ptr = &t_list[c_ptr->tptr];
  607.       if ((t_ptr->tval == 101) || (t_ptr->tval == 102)) 
  608.         {
  609.           if (delete_object(y, x)) 
  610.         disarm = TRUE;
  611.         }
  612.       else if (t_ptr->tval == 105) 
  613.         {
  614.           t_ptr->p1 = 0;
  615.         }
  616.       else if (t_ptr->tval == 109) 
  617.         {
  618.           c_ptr->fval = corr_floor3.ftval;
  619.           change_trap(y, x);
  620.           c_ptr->fm = TRUE;
  621.           disarm = TRUE;
  622.         }
  623.       else if (t_ptr->tval == 2) 
  624.         if (t_ptr->flags != 0) 
  625.           {
  626.         msg_print("Click!");
  627.         t_ptr->flags = 0;
  628.         disarm = TRUE;
  629.         string = index(t_ptr->name, '(');
  630.         if (string)
  631.           i = strlen(t_ptr->name) - strlen(string);
  632.         else
  633.           i = -1;
  634.         if (i >= 0) 
  635.           t_ptr->name[i] = '\0';
  636.         (void) strcat(t_ptr->name, " (Unlocked)");
  637.         known2(t_ptr->name);
  638.           }
  639.     }
  640.       oldy = y;
  641.       oldx = x;
  642.       (void) move(dir, &y, &x);
  643.     }
  644.   while (cave[oldy][oldx].fopen);
  645.   return(disarm);
  646. }
  647.  
  648.  
  649. /* Return flags for given type area affect        -RAK-    */
  650. get_flags(typ, weapon_type, harm_type, destroy)
  651. int typ;
  652. int *weapon_type, *harm_type;
  653. int (**destroy)();
  654. {
  655.   int set_null(), set_fire_destroy(), set_frost_destroy();
  656.   int set_acid_destroy(), set_lightning_destroy();
  657.  
  658.   switch(typ)
  659.     {
  660.     case 1:      /* Lightning     */
  661.       *weapon_type = 0x00080000;
  662.       *harm_type   = 0x0100;
  663.       *destroy     = set_lightning_destroy;
  664.       break;
  665.     case 2:      /* Poison Gas    */
  666.       *weapon_type = 0x00100000;
  667.       *harm_type   = 0x0040;
  668.       *destroy     = set_null;
  669.       break;
  670.     case 3:      /* Acid          */
  671.       *weapon_type = 0x00200000;
  672.       *harm_type   = 0x0080;
  673.       *destroy     = set_acid_destroy;
  674.       break;
  675.     case 4:      /* Frost         */
  676.       *weapon_type = 0x00400000;
  677.       *harm_type   = 0x0010;
  678.       *destroy     = set_frost_destroy;
  679.       break;
  680.     case 5:      /* Fire          */
  681.       *weapon_type = 0x00800000;
  682.       *harm_type   = 0x0020;
  683.       *destroy     = set_fire_destroy;
  684.       break;
  685.     case 6:      /* Holy Orb      */
  686.       *weapon_type = 0x00000000;
  687.       *harm_type   = 0x0004;
  688.       *destroy     = set_null;
  689.       break;
  690.     default:
  691.       *weapon_type = 0;
  692.       *harm_type   = 0;
  693.       *destroy     = set_null;
  694.     }
  695. }
  696.  
  697.  
  698. /* Shoot a bolt in a given direction            -RAK-    */
  699. int fire_bolt(typ, dir, y, x, dam, bolt_typ)
  700. int typ, dir, y, x, dam;
  701. ctype bolt_typ;
  702. {
  703.   int i, oldy, oldx, dist;
  704.   int weapon_type, harm_type;
  705.   int flag;
  706.   int (*dummy)();
  707.   cave_type *c_ptr;
  708.   monster_type *m_ptr;
  709.   creature_type *r_ptr;
  710.   vtype out_val;
  711.   char tmp_str[2];
  712.  
  713.   flag = FALSE;
  714.   get_flags(typ, &weapon_type, &harm_type, &dummy);
  715.   oldy = y;
  716.   oldx = x;
  717.   dist = 0;
  718.   do
  719.     {
  720.       (void) move(dir, &y, &x);
  721.       if (test_light(oldy, oldx)) 
  722.     lite_spot(oldy, oldx);
  723.       else
  724.     unlite_spot(oldy, oldx);
  725.       dist++;
  726.       if (dist > OBJ_BOLT_RANGE) 
  727.     flag = TRUE;
  728.       else
  729.     {
  730.       c_ptr = &cave[y][x];
  731.       if (c_ptr->fopen) 
  732.         {
  733.           if (c_ptr->cptr > 1) 
  734.         {
  735.           flag = TRUE;
  736.           m_ptr = &m_list[c_ptr->cptr];
  737.           r_ptr = &c_list[m_ptr->mptr];
  738.           (void) sprintf(out_val, "The %s strikes the %s.", bolt_typ,
  739.               r_ptr->name);
  740.           msg_print(out_val);
  741.           if (harm_type & r_ptr->cdefense)
  742.             dam = dam*2;
  743.           else if (weapon_type & r_ptr->spells)
  744.             dam = (dam/4.0);
  745.           i = mon_take_hit((int)c_ptr->cptr, dam);
  746.           if (i > 0) 
  747.             {
  748.               (void) sprintf(out_val, "The %s dies in a fit of agony.",
  749.                   c_list[i].name);
  750.               msg_print(out_val);
  751.             }
  752.           else
  753.             {
  754.               if (panel_contains(y, x)) 
  755.             {
  756.               tmp_str[0] = c_list[m_ptr->mptr].cchar;
  757.               tmp_str[1] = '\0';
  758.               print(tmp_str, y, x);
  759.               m_list[c_ptr->cptr].ml = TRUE;
  760.             }
  761.             }
  762.         }
  763.           else if (panel_contains(y, x)) 
  764.         print("*", y, x);
  765.         }
  766.       else
  767.         flag = TRUE;
  768.     }
  769.       oldy = y;
  770.       oldx = x;
  771.     }
  772.   while (!flag);
  773. }
  774.  
  775.  
  776. /* Shoot a ball in a given direction.  Note that balls have an    */
  777. /* area affect....                                       -RAK-   */
  778. int fire_ball(typ, dir, y, x, dam_hp, descrip)
  779. int typ, dir, y, x, dam_hp;
  780. ctype descrip;
  781. {
  782.   int i, j, k;
  783.   int dam, max_dis, thit, tkill;
  784.   int oldy, oldx, dist;
  785.   int weapon_type, harm_type;
  786.   int flag;
  787.   int (*destroy)();
  788.   cave_type *c_ptr;
  789.   monster_type *m_ptr;
  790.   creature_type *r_ptr;
  791.   vtype out_val;
  792.   char tmp_str[2];
  793.  
  794.   thit   = 0;
  795.   tkill  = 0;
  796.   max_dis = 2;
  797.   get_flags(typ, &weapon_type, &harm_type, &destroy);
  798.   flag = FALSE;
  799.   oldy = y;
  800.   oldx = x;
  801.   dist = 0;
  802.   do
  803.     {
  804.       (void) move(dir, &y, &x);
  805.       dist++;
  806.       if (test_light(oldy, oldx)) 
  807.     lite_spot(oldy, oldx);
  808.       else
  809.     unlite_spot(oldy, oldx);
  810.       if (dist > OBJ_BOLT_RANGE) 
  811.     flag = TRUE;
  812.       else
  813.     {
  814.       c_ptr = &cave[y][x];
  815.       if ((!c_ptr->fopen) || (c_ptr->cptr > 1)) 
  816.         {
  817.           flag = TRUE;
  818.           if (!c_ptr->fopen) 
  819.         {
  820.           y = oldy;
  821.           x = oldx;
  822.         }
  823.           /* The ball hits and explodes...                 */
  824.           /* The explosion...                      */
  825.           for (i = y-max_dis; i <= y+max_dis; i++)
  826.         for (j = x-max_dis; j <= x+max_dis; j++)
  827.           if (in_bounds(i, j)) 
  828.             if (distance(y, x, i, j) <= max_dis) 
  829.               if (los(y, x, i, j))     /* FIXED BUG V4.5        */
  830.             {
  831.               c_ptr = &cave[i][j];
  832.               if (c_ptr->tptr != 0) 
  833.                 if (destroy(t_list[c_ptr->tptr].tval))
  834.                   (void) delete_object(i, j);
  835.               if (c_ptr->fopen) 
  836.                 {
  837.                   if (panel_contains(i, j))  print("*", i, j);
  838.                   if (c_ptr->cptr > 1) 
  839.                 {
  840.                   m_ptr = &m_list[c_ptr->cptr];
  841.                   r_ptr = &c_list[m_ptr->mptr];
  842.                   thit++;
  843.                   dam = dam_hp;
  844.                   if (harm_type & r_ptr->cdefense)
  845.                     dam = dam*2;
  846.                   else if (weapon_type & r_ptr->spells)
  847.                     dam = dam / 4;
  848.                   dam = (dam/(distance(i, j, y, x)+1));
  849.                   k = mon_take_hit((int)c_ptr->cptr, dam);
  850.                   if (k > 0) 
  851.                     tkill++;
  852.                   else
  853.                     {
  854.                       if (panel_contains(i, j)) 
  855.                     {
  856.                       tmp_str[0] = r_ptr->cchar;
  857.                       tmp_str[1] = '\0';
  858.                       print(tmp_str, i, j);
  859.                       m_ptr->ml = TRUE;
  860.                     }
  861.                     }
  862.                 }
  863.                 }
  864.             }
  865.           for (i = (y - 2); i <= (y + 2); i++)
  866.         for (j = (x - 2); j <= (x + 2); j++)
  867.           if (in_bounds(i, j)) 
  868.             if (panel_contains(i, j)) 
  869.               if (distance(y, x, i, j) <= max_dis) 
  870.             {
  871.               c_ptr = &cave[i][j];
  872.               if (test_light(i, j)) 
  873.                 lite_spot(i, j);
  874.               else if (c_ptr->cptr == 1) 
  875.                 lite_spot(i, j);
  876.               else if (c_ptr->cptr > 1) 
  877.                 if (m_list[c_ptr->cptr].ml) 
  878.                   lite_spot(i, j);
  879.                 else
  880.                   unlite_spot(i, j);
  881.               else
  882.                 unlite_spot(i, j);
  883.             }
  884.           /* End  explosion...                     */
  885.           if (thit == 1) 
  886.         {
  887.           (void) sprintf(out_val,
  888.                  "The %s envelopes a creature!",
  889.                  descrip);
  890.           msg_print(out_val);
  891.         }
  892.           else if (thit > 1) 
  893.         {
  894.           (void) sprintf(out_val,
  895.                  "The %s envelopes several creatures!",
  896.                  descrip);
  897.           msg_print(out_val);
  898.         }
  899.           if (tkill == 1) 
  900.         msg_print("There is a scream of agony!");
  901.           else if (tkill > 1) 
  902.         msg_print("There are several screams of agony!");
  903.           /* End ball hitting...                   */
  904.         }
  905.       else if (panel_contains(y, x)) 
  906.         print("*", y, x);
  907.       oldy = y;
  908.       oldx = x;
  909.     }
  910.     }
  911.   while (!flag);
  912. }
  913.  
  914.  
  915. /* Breath weapon works like a fire_ball, but affects the player. */
  916. /* Note the area affect....                              -RAK-   */
  917. breath(typ, y, x, dam_hp, ddesc)
  918. int typ, y, x, dam_hp;
  919. char *ddesc;
  920. {
  921.   int i, j;
  922.   int dam, max_dis;
  923.   int weapon_type, harm_type;
  924.   int (*destroy)();
  925.   cave_type *c_ptr;
  926.   monster_type *m_ptr;
  927.   creature_type *r_ptr;
  928.  
  929.   max_dis = 2;
  930.   get_flags(typ, &weapon_type, &harm_type, &destroy);
  931.   for (i = y-2; i <= y+2; i++)
  932.     for (j = x-2; j <= x+2; j++)
  933.       if (in_bounds(i, j)) 
  934.     if (distance(y, x, i, j) <= max_dis) 
  935.       {
  936.         c_ptr = &cave[i][j];
  937.         if (c_ptr->tptr != 0) 
  938.           if (destroy(t_list[c_ptr->tptr].tval))
  939.         (void) delete_object(i, j);
  940.         if (c_ptr->fopen) 
  941.           {
  942.         if (panel_contains(i, j)) 
  943.           print("*", i, j);
  944.         if (c_ptr->cptr > 1) 
  945.           {
  946.             m_ptr = &m_list[c_ptr->cptr];
  947.             r_ptr = &c_list[m_ptr->mptr];
  948.             dam = dam_hp;
  949.             if (harm_type & r_ptr->cdefense)
  950.               dam = dam*2;
  951.             else if (weapon_type & r_ptr->spells)
  952.               dam = (dam/4.0);
  953.             dam = (dam/(distance(i, j, y, x)+1));
  954.             m_ptr->hp = m_ptr->hp - dam;
  955.             m_ptr->csleep = 0;
  956.             if (m_ptr->hp < 0) 
  957.               {
  958.             monster_death((int)m_ptr->fy, (int)m_ptr->fx,
  959.                       r_ptr->cmove);
  960.             delete_monster((int)c_ptr->cptr);
  961.               }
  962.           }
  963.         else if (c_ptr->cptr == 1) 
  964.           {
  965.             dam = (dam_hp/(distance(i, j, y, x)+1));
  966.             /* let's do at least one point of damage */
  967.                     /* prevents randint(0) problem with poison_gas, also */
  968.                     if (dam == 0)
  969.                       dam = 1;
  970.             switch(typ)
  971.               {
  972.               case 1: light_dam(dam, ddesc); break;
  973.               case 2: poison_gas(dam, ddesc); break;
  974.               case 3: acid_dam(dam, ddesc); break;
  975.               case 4: cold_dam(dam, ddesc); break;
  976.               case 5: fire_dam(dam, ddesc); break;
  977.               }
  978.           }
  979.           }
  980.       }
  981.   for (i = (y - 2); i <= (y + 2); i++)
  982.     for (j = (x - 2); j <= (x + 2); j++)
  983.       if (in_bounds(i, j)) 
  984.     if (panel_contains(i, j)) 
  985.       if (distance(y, x, i, j) <= max_dis) 
  986.         {
  987.           c_ptr = &cave[i][j];
  988.           if (test_light(i, j)) 
  989.         lite_spot(i, j);
  990.           else if (c_ptr->cptr == 1) 
  991.         lite_spot(i, j);
  992.           else if (c_ptr->cptr > 1) 
  993.         if (m_list[c_ptr->cptr].ml) 
  994.           lite_spot(i, j);
  995.         else
  996.           unlite_spot(i, j);
  997.           else
  998.         unlite_spot(i, j);
  999.         }
  1000. }
  1001.  
  1002.  
  1003. /* Recharge a wand, staff, or rod.  Sometimes the item breaks. -RAK-*/
  1004. int recharge(num)
  1005. int num;
  1006. {
  1007.   int item_val;
  1008.   int redraw;
  1009.   int res;
  1010.   treasure_type *i_ptr;
  1011.  
  1012.   res = FALSE;
  1013.   redraw = FALSE;
  1014.   if (get_item(&item_val, "Recharge which item?", &redraw, 0, inven_ctr-1)) 
  1015.     {
  1016.       i_ptr = &inventory[item_val];
  1017.       if ((i_ptr->tval == 55) || (i_ptr->tval == 60) || (i_ptr->tval == 65))
  1018.     /* recharge I = recharge(20) = 1/6 failure */
  1019.     /* recharge II = recharge(60) = 1/10 failure */
  1020.     if (randint((num + 40)/10) == 1)
  1021.       {
  1022.         res = TRUE;
  1023.         msg_print("There is a bright flash of light...");
  1024.         inven_destroy(item_val);
  1025.       }
  1026.     else
  1027.       {
  1028.         res = TRUE;
  1029.         num = (num/(i_ptr->level+2)) + 1;
  1030.         i_ptr->p1 += 2 + randint(num);
  1031.         if (index(i_ptr->name, '^') == 0) 
  1032.           insert_str(i_ptr->name, " (%P1", "^ (%P1");
  1033.       }
  1034.       if (redraw) 
  1035.     {
  1036.       msg_print(" ");
  1037.       draw_cave();
  1038.     }
  1039.     }
  1040.   return(res);
  1041. }
  1042.  
  1043.  
  1044. /* Increase or decrease a creatures hit points        -RAK-    */
  1045. int hp_monster(dir, y, x, dam)
  1046. int dir, y, x, dam;
  1047. {
  1048.   int i;
  1049.   int flag;
  1050.   int monster;
  1051.   cave_type *c_ptr;
  1052.   monster_type *m_ptr;
  1053.   creature_type *r_ptr;
  1054.   vtype out_val;
  1055.  
  1056.   monster = FALSE;
  1057.   flag = FALSE;
  1058.   do
  1059.     {
  1060.       (void) move(dir, &y, &x);
  1061.       c_ptr = &cave[y][x];
  1062.       if (c_ptr->fopen) 
  1063.     {
  1064.       if (c_ptr->cptr > 1) 
  1065.         {
  1066.           flag = TRUE;
  1067.           m_ptr = &m_list[c_ptr->cptr];
  1068.           r_ptr = &c_list[m_ptr->mptr];
  1069.           monster = TRUE;
  1070.           i = mon_take_hit((int)c_ptr->cptr, dam);
  1071.           if (i > 0) 
  1072.         {
  1073.           (void) sprintf(out_val, "The %s dies in a fit of agony.",
  1074.               c_list[i].name);
  1075.           msg_print(out_val);
  1076.         }
  1077.           else
  1078.         {
  1079.           if (dam > 0)
  1080.             {
  1081.               (void) sprintf(out_val, "The %s screams in agony.",
  1082.                      r_ptr->name);
  1083.               msg_print(out_val);
  1084.             }
  1085.         }
  1086.         }
  1087.     }
  1088.       else
  1089.     flag = TRUE;
  1090.     }
  1091.   while (!flag);
  1092.   return(monster);
  1093. }
  1094.  
  1095.  
  1096. /* Drains life; note it must be living...        -RAK-    */
  1097. int drain_life(dir, y, x)
  1098. int dir, y, x;
  1099. {
  1100.   int i;
  1101.   int flag;
  1102.   int drain;
  1103.   cave_type *c_ptr;
  1104.   monster_type *m_ptr;
  1105.   creature_type *r_ptr;
  1106.   vtype out_val;
  1107.  
  1108.   drain = FALSE;
  1109.   flag = FALSE;
  1110.   do
  1111.     {
  1112.       (void) move(dir, &y, &x);
  1113.       c_ptr = &cave[y][x];
  1114.       if (c_ptr->fopen) 
  1115.     {
  1116.       if (c_ptr->cptr > 1) 
  1117.         {
  1118.           flag = TRUE;
  1119.           m_ptr = &m_list[c_ptr->cptr];
  1120.           r_ptr = &c_list[m_ptr->mptr];
  1121.           if ((r_ptr->cdefense & 0x0008) == 0) 
  1122.         {
  1123.           drain = TRUE;
  1124.           i = mon_take_hit((int)c_ptr->cptr, 50);
  1125.           if (i > 0) 
  1126.             {
  1127.               (void) sprintf(out_val, "The %s dies in a fit of agony.",
  1128.                   c_list[i].name);
  1129.               msg_print(out_val);
  1130.             }
  1131.           else
  1132.             {
  1133.               (void) sprintf(out_val, "The %s screams in agony.",
  1134.                   r_ptr->name);
  1135.               msg_print(out_val);
  1136.             }
  1137.         }
  1138.         }
  1139.       else
  1140.         flag = TRUE;
  1141.     }
  1142.     }
  1143.   while (!flag);
  1144.   return(drain);
  1145. }
  1146.  
  1147.  
  1148. /* Increase or decrease a creatures speed        -RAK-    */
  1149. /* NOTE: cannot slow a winning creature (BALROG)                 */
  1150. int speed_monster(dir, y, x, spd)
  1151. int dir, y, x, spd;
  1152. {
  1153.   int speed;
  1154.   int flag;
  1155.   cave_type *c_ptr;
  1156.   monster_type *m_ptr;
  1157.   creature_type *r_ptr;
  1158.   vtype out_val;
  1159.  
  1160.   speed = FALSE;
  1161.   flag = FALSE;
  1162.   do
  1163.     {
  1164.       (void) move(dir, &y, &x);
  1165.       c_ptr = &cave[y][x];
  1166.       if (c_ptr->fopen) 
  1167.     {
  1168.       if (c_ptr->cptr > 1) 
  1169.         {
  1170.           flag = TRUE;
  1171.           m_ptr = &m_list[c_ptr->cptr];
  1172.           r_ptr = &c_list[m_ptr->mptr];
  1173.           if (spd > 0) 
  1174.         {
  1175.           m_ptr->cspeed += spd;
  1176.           m_ptr->csleep = 0;
  1177.         }
  1178.           else if (randint(MAX_MONS_LEVEL) > r_ptr->level) 
  1179.         {
  1180.           m_ptr->cspeed += spd;
  1181.           m_ptr->csleep = 0;
  1182.         }
  1183.           else
  1184.         {
  1185.           (void) sprintf(out_val, "The %s is unaffected.",
  1186.                  r_ptr->name);
  1187.           msg_print(out_val);
  1188.           speed = TRUE;
  1189.         }
  1190.         }
  1191.       else
  1192.         flag = TRUE;
  1193.     }
  1194.     }
  1195.   while (!flag);
  1196.   return(speed);
  1197. }
  1198.  
  1199.  
  1200. /* Confuse a creature                    -RAK-    */
  1201. int confuse_monster(dir, y, x)
  1202. int dir, y, x;
  1203. {
  1204.   int flag;
  1205.   int confuse;
  1206.   cave_type *c_ptr;
  1207.   monster_type *m_ptr;
  1208.   creature_type *r_ptr;
  1209.   vtype out_val;
  1210.  
  1211.   confuse = FALSE;
  1212.   flag = FALSE;
  1213.   do
  1214.     {
  1215.       (void) move(dir, &y, &x);
  1216.       c_ptr = &cave[y][x];
  1217.       if (c_ptr->fopen) 
  1218.     {
  1219.       if (c_ptr->cptr > 1) 
  1220.         {
  1221.           m_ptr = &m_list[c_ptr->cptr];
  1222.           r_ptr = &c_list[m_ptr->mptr];
  1223.           confuse = TRUE;
  1224.           flag = TRUE;
  1225.           if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  1226.           (0x1000 & r_ptr->cdefense))
  1227.         {
  1228.           (void) sprintf(out_val, "The %s is unaffected.",
  1229.                  r_ptr->name);
  1230.           msg_print(out_val);
  1231.         }
  1232.           else
  1233.         {
  1234.           m_ptr->confused = TRUE;
  1235.           m_ptr->csleep = 0;
  1236.           (void) sprintf(out_val, "The %s appears confused.",
  1237.                  r_ptr->name);
  1238.           msg_print(out_val);
  1239.         }
  1240.         }
  1241.     }
  1242.       else
  1243.     flag = TRUE;
  1244.     }
  1245.   while (!flag);
  1246.   return(confuse);
  1247. }
  1248.  
  1249.  
  1250. /* Sleep a creature...                    -RAK-    */
  1251. int sleep_monster(dir, y, x)
  1252. int dir, y, x;
  1253. {
  1254.   int flag;
  1255.   int sleep;
  1256.   cave_type *c_ptr;
  1257.   monster_type *m_ptr;
  1258.   creature_type *r_ptr;
  1259.   vtype out_val;
  1260.  
  1261.   sleep = FALSE;
  1262.   flag = FALSE;
  1263.   do
  1264.     {
  1265.       (void) move(dir, &y, &x);
  1266.       c_ptr = &cave[y][x];
  1267.       if (c_ptr->fopen) 
  1268.     {
  1269.       if (c_ptr->cptr > 1) 
  1270.         {
  1271.           m_ptr = &m_list[c_ptr->cptr];
  1272.           r_ptr = &c_list[m_ptr->mptr];
  1273.           sleep = TRUE;
  1274.           flag = TRUE;
  1275.           if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  1276.           (0x1000 & r_ptr->cdefense))
  1277.         {
  1278.           (void) sprintf(out_val, "The %s is unaffected.",
  1279.                  r_ptr->name);
  1280.           msg_print(out_val);
  1281.         }
  1282.           else
  1283.         {
  1284.           m_ptr->csleep = 500;
  1285.           (void) sprintf(out_val, "The %s falls asleep.", r_ptr->name);
  1286.           msg_print(out_val);
  1287.         }
  1288.         }
  1289.     }
  1290.       else
  1291.     flag = TRUE;
  1292.     }
  1293.   while (!flag);
  1294.   return(sleep);
  1295. }
  1296.  
  1297.  
  1298. /* Turn stone to mud, delete wall....            -RAK-    */
  1299. int wall_to_mud(dir, y, x)
  1300. int dir, y, x;
  1301. {
  1302.   int i;
  1303.   vtype out_val, tmp_str;
  1304.   int flag;
  1305.   int wall;
  1306.   cave_type *c_ptr;
  1307.   monster_type *m_ptr;
  1308.   creature_type *r_ptr;
  1309.  
  1310.   wall = FALSE;
  1311.   flag = FALSE;
  1312.   do
  1313.     {
  1314.       (void) move(dir, &y, &x);
  1315.       c_ptr = &cave[y][x];
  1316.       if (in_bounds(y, x)) 
  1317.     {
  1318.       if ((c_ptr->fval >= 10) && (c_ptr->fval <= 12))
  1319.         {
  1320.           flag = TRUE;
  1321.           (void) twall(y, x, 1, 0);
  1322.           if (test_light(y, x)) 
  1323.         {
  1324.           msg_print("The wall turns into mud.");
  1325.           wall = TRUE;
  1326.         }
  1327.         }
  1328.       else if ((c_ptr->tptr != 0) && (!c_ptr->fopen)) 
  1329.         {
  1330.           flag = TRUE;
  1331.           if (panel_contains(y, x)) 
  1332.         if (test_light(y, x)) 
  1333.           {
  1334.             inventory[INVEN_MAX] = t_list[c_ptr->tptr];
  1335.             objdes(tmp_str, INVEN_MAX, FALSE);
  1336.             (void) sprintf(out_val, "The %s turns into mud.", tmp_str);
  1337.             msg_print(out_val);
  1338.             wall = TRUE;
  1339.           }
  1340.           (void) delete_object(y, x);
  1341.         }
  1342.       if (c_ptr->cptr > 1) 
  1343.         {
  1344.           m_ptr = &m_list[c_ptr->cptr];
  1345.           r_ptr = &c_list[m_ptr->mptr];
  1346.           if (0x0200 & r_ptr->cdefense)
  1347.         {
  1348.           i = mon_take_hit((int)c_ptr->cptr, 100);
  1349.           flag = TRUE;
  1350.           if (m_ptr->ml) 
  1351.             if (i > 0) 
  1352.               {
  1353.             (void) sprintf(out_val,
  1354.                        "The %s dies in a fit of agony.",
  1355.                        r_ptr->name);
  1356.             msg_print(out_val);
  1357.               }
  1358.             else
  1359.               {
  1360.             (void) sprintf(out_val, "The %s wails out in pain!",
  1361.                 r_ptr->name);
  1362.             msg_print(out_val);
  1363.               }
  1364.         }
  1365.         }
  1366.     }
  1367.       else
  1368.     flag = TRUE;
  1369.     }
  1370.   while (!flag);
  1371.   return(wall);
  1372. }
  1373.  
  1374.  
  1375. /* Destroy all traps and doors in a given direction    -RAK-    */
  1376. int td_destroy2(dir, y, x)
  1377. int dir, y, x;
  1378. {
  1379.   int destroy2;
  1380.   cave_type *c_ptr;
  1381.   treasure_type *t_ptr;
  1382.  
  1383.   destroy2 = FALSE;
  1384.   do
  1385.     {
  1386.       (void) move(dir, &y, &x);
  1387.       c_ptr = &cave[y][x];
  1388.       if (c_ptr->tptr != 0) 
  1389.     {
  1390.       t_ptr = &t_list[c_ptr->tptr];
  1391.       if ((t_ptr->tval == 2) || (t_ptr->tval == 101) ||
  1392.           (t_ptr->tval == 102) || (t_ptr->tval == 104) ||
  1393.           (t_ptr->tval == 105) || (t_ptr->tval == 109))
  1394.         {
  1395.           if (delete_object(y, x)) 
  1396.         {
  1397.           msg_print("There is a bright flash of light!");
  1398.           c_ptr->fopen = TRUE;
  1399.           destroy2 = TRUE;
  1400.         }
  1401.         }
  1402.     }
  1403.     }
  1404.   while (cave[y][x].fopen);
  1405.   return(destroy2);
  1406. }
  1407.  
  1408.  
  1409. /* Polymorph a monster                    -RAK-    */
  1410. /* NOTE: cannot polymorph a winning creature (BALROG)            */
  1411. int poly_monster(dir, y, x)
  1412. int dir, y, x;
  1413. {
  1414.   int dist;
  1415.   int flag;
  1416.   int poly;
  1417.   cave_type *c_ptr;
  1418.   creature_type *r_ptr;
  1419.   vtype out_val;
  1420.  
  1421.   poly = FALSE;
  1422.   flag = FALSE;
  1423.   dist = 0;
  1424.   do
  1425.     {
  1426.       (void) move(dir, &y, &x);
  1427.       dist++;
  1428.       if (dist <= OBJ_BOLT_RANGE) 
  1429.     {
  1430.       c_ptr = &cave[y][x];
  1431.       if (c_ptr->fopen) 
  1432.         {
  1433.           if (c_ptr->cptr > 1) 
  1434.         {
  1435.           r_ptr = &c_list[m_list[c_ptr->cptr].mptr];
  1436.           if (randint(MAX_MONS_LEVEL) > r_ptr->level) 
  1437.             {
  1438.               flag = TRUE;
  1439.               delete_monster((int)c_ptr->cptr);
  1440.               place_monster(y, x, 
  1441.               randint(m_level[MAX_MONS_LEVEL]) - 1 + m_level[0],
  1442.                     FALSE);
  1443.               if (panel_contains(y, x)) 
  1444.             if (test_light(y, x)) 
  1445.               poly = TRUE;
  1446.             }
  1447.           else
  1448.             {
  1449.               (void) sprintf(out_val, "The %s is unaffected.",
  1450.                      r_ptr->name);
  1451.               msg_print(out_val);
  1452.             }
  1453.         }
  1454.           else
  1455.         flag = TRUE;
  1456.         }
  1457.     }
  1458.       else
  1459.     flag = TRUE;
  1460.     }
  1461.   while (!flag);
  1462.   return(poly);
  1463. }
  1464.  
  1465.  
  1466. /* Create a wall...                    -RAK-    */
  1467. int build_wall(dir, y, x)
  1468. int dir, y, x;
  1469. {
  1470.   int i;
  1471.   int build;
  1472.   cave_type *c_ptr;
  1473.  
  1474.   build = FALSE;
  1475.   i = 0;
  1476.   (void) move(dir, &y, &x);
  1477.   while ((cave[y][x].fopen) && (i < 10))
  1478.     {
  1479.       c_ptr = &cave[y][x];
  1480.       if (c_ptr->tptr != 0) 
  1481.     (void) delete_object(y, x);
  1482.       if (c_ptr->cptr > 1) 
  1483.     /* what happens to this monster ? */
  1484.     (void) mon_take_hit((int)c_ptr->cptr, damroll("2d8"));
  1485.       c_ptr->fval  = rock_wall2.ftval;
  1486.       c_ptr->fopen = rock_wall2.ftopen;
  1487.       c_ptr->fm = FALSE;
  1488.       if (test_light(y, x)) 
  1489.     lite_spot(y, x);
  1490.       i++;
  1491.       build = TRUE;
  1492.       (void) move(dir, &y, &x);
  1493.     }
  1494.   return(build);
  1495. }
  1496.  
  1497.  
  1498. /* Replicate a creature                    -RAK-    */
  1499. int clone_monster(dir, y, x)
  1500. int dir, y, x;
  1501. {
  1502.   int flag;
  1503.   int clone;
  1504.   cave_type *c_ptr;
  1505.  
  1506.   flag = FALSE;
  1507.   clone = FALSE;
  1508.   do
  1509.     {
  1510.       (void) move(dir, &y, &x);
  1511.       c_ptr = &cave[y][x];
  1512.       if (c_ptr->cptr > 1) 
  1513.     {
  1514.       multiply_monster(y, x, (int)m_list[c_ptr->cptr].mptr, FALSE);
  1515.       if (panel_contains(y, x)) 
  1516.         if (m_list[c_ptr->cptr].ml) 
  1517.           clone = TRUE;
  1518.       flag = TRUE;
  1519.     }
  1520.     }
  1521.   while ((cave[y][x].fopen) && (!flag));
  1522.   return(clone);
  1523. }
  1524.  
  1525.  
  1526. /* Move the creature record to a new location        -RAK-    */
  1527. teleport_away(monptr, dis)
  1528. int monptr, dis;
  1529. {
  1530.   int yn, xn, ctr;
  1531.   monster_type *m_ptr;
  1532.  
  1533.   m_ptr = &m_list[monptr];
  1534.   ctr = 0;
  1535.   do
  1536.     {
  1537.       do
  1538.     {
  1539.       yn = m_ptr->fy + (randint(2*dis+1) - (dis + 1));
  1540.       xn = m_ptr->fx + (randint(2*dis+1) - (dis + 1));
  1541.     }
  1542.       while (!in_bounds(yn, xn));
  1543.       ctr++;
  1544.       if (ctr > 9) 
  1545.     {
  1546.       ctr = 0;
  1547.       dis += 5;
  1548.     }
  1549.     }
  1550.   while ((!cave[yn][xn].fopen) || (cave[yn][xn].cptr != 0));
  1551.   move_rec((int)m_ptr->fy, (int)m_ptr->fx, yn, xn);
  1552.   if (test_light((int)m_ptr->fy, (int)m_ptr->fx)) 
  1553.     lite_spot((int)m_ptr->fy, (int)m_ptr->fx);
  1554.   m_ptr->fy = yn;
  1555.   m_ptr->fx = xn;
  1556.   m_ptr->ml = FALSE;
  1557. }
  1558.  
  1559.  
  1560. /* Teleport player to spell casting creature        -RAK-    */
  1561. teleport_to(ny, nx)
  1562. int ny, nx;
  1563. {
  1564.   int dis, ctr, y, x, i, j;
  1565.   cave_type *c_ptr;
  1566.  
  1567.   dis = 1;
  1568.   ctr = 0;
  1569.   do
  1570.     {
  1571.       y = ny + (randint(2*dis+1) - (dis + 1));
  1572.       x = nx + (randint(2*dis+1) - (dis + 1));
  1573.       ctr++;
  1574.       if (ctr > 9) 
  1575.     {
  1576.       ctr = 0;
  1577.       dis = dis + 1;
  1578.     }
  1579.     }
  1580.   while ((!cave[y][x].fopen) || (cave[y][x].cptr >= 2));
  1581.   move_rec(char_row, char_col, y, x);
  1582.   for (i = char_row-1; i <= char_row+1; i++)
  1583.     for (j = char_col-1; j <= char_col+1; j++)
  1584.       {
  1585.     c_ptr = &cave[i][j];
  1586.     c_ptr->tl = FALSE;
  1587.     if (!test_light(i, j)) 
  1588.       unlite_spot(i, j);
  1589.       }
  1590.   if (test_light(char_row, char_col)) 
  1591.     lite_spot(char_row, char_col);
  1592.   char_row = y;
  1593.   char_col = x;
  1594.   move_char(5);
  1595.   creatures(FALSE);
  1596. }
  1597.  
  1598.  
  1599. /* Teleport all creatures in a given direction away    -RAK-    */
  1600. int teleport_monster(dir, y, x)
  1601. int dir, y, x;
  1602. {
  1603.   int flag;
  1604.   int teleport;
  1605.   cave_type *c_ptr;
  1606.  
  1607.   flag = FALSE;
  1608.   teleport = FALSE;
  1609.   do
  1610.     {
  1611.       (void) move(dir, &y, &x);
  1612.       c_ptr = &cave[y][x];
  1613.       if (c_ptr->cptr > 1) 
  1614.     {
  1615.       teleport_away((int)c_ptr->cptr, MAX_SIGHT);
  1616.       teleport = TRUE;
  1617.     }
  1618.     }
  1619.   while ((cave[y][x].fopen) && (!flag));
  1620.   return(teleport);
  1621. }
  1622.  
  1623.  
  1624. /* Delete all creatures within max_sight distance    -RAK-    */
  1625. /* NOTE : Winning creatures cannot be genocided                  */
  1626. int mass_genocide()
  1627. {
  1628.   int i, j;
  1629.   int genocide;
  1630.   monster_type *m_ptr;
  1631.   creature_type *r_ptr;
  1632.  
  1633.   genocide = FALSE;
  1634.   i = muptr;
  1635.   while (i > 0)
  1636.     {
  1637.       m_ptr = &m_list[i];
  1638.       r_ptr = &c_list[m_ptr->mptr];
  1639.       j = m_ptr->nptr;
  1640.       if (m_ptr->cdis <= MAX_SIGHT) 
  1641.     if ((r_ptr->cdefense & 0x80000000) == 0) 
  1642.       {
  1643.         delete_monster(i);
  1644.         genocide = TRUE;
  1645.       }
  1646.       i = j;
  1647.     }
  1648.   return(genocide);
  1649. }
  1650.  
  1651.  
  1652. /* Delete all creatures of a given type from level.    -RAK-    */
  1653. /* This does not keep creatures of type from appearing later.    */
  1654. /* NOTE : Winning creatures that are genocided will be considered*/
  1655. /*        as teleporting to another level.  Genocide will NOT win*/
  1656. /*        the game...                                            */
  1657. int genocide()
  1658. {
  1659.   int i, j;
  1660.   char typ;
  1661.   monster_type *m_ptr;
  1662.   creature_type *r_ptr;
  1663.   vtype out_val;
  1664.  
  1665.   i = muptr;
  1666.   if (get_com("Which type of creature do wish exterminated?", &typ)) 
  1667.     while (i > 0)
  1668.       {
  1669.     m_ptr = &m_list[i];
  1670.     r_ptr = &c_list[m_ptr->mptr];
  1671.     j = m_ptr->nptr;
  1672.     if (typ == c_list[m_ptr->mptr].cchar) 
  1673.       if ((r_ptr->cdefense & 0x80000000) == 0) 
  1674.         delete_monster(i);
  1675.       else
  1676.         {
  1677.           (void) sprintf(out_val, "The %s is unaffected.", r_ptr->name);
  1678.           msg_print(out_val);
  1679.         }
  1680.     i = j;
  1681.       }
  1682.   return(TRUE);
  1683. }
  1684.  
  1685.  
  1686. /* Change speed of any creature player can see....    -RAK-    */
  1687. /* NOTE: cannot slow a winning creature (BALROG)                 */
  1688. int speed_monsters(spd)
  1689. int spd;
  1690. {
  1691.   int i, j;
  1692.   int speed;
  1693.   monster_type *m_ptr;
  1694.   creature_type *r_ptr;
  1695.   vtype out_val;
  1696.  
  1697.   i = muptr;
  1698.   speed = FALSE;
  1699.   while (i > 0)
  1700.     {
  1701.       m_ptr = &m_list[i];
  1702.       j = m_ptr->nptr;
  1703.       if (m_ptr->ml) 
  1704.     {
  1705.       r_ptr = &c_list[m_ptr->mptr];
  1706.       if (spd > 0) 
  1707.         {
  1708.           m_ptr->cspeed += spd;
  1709.           m_ptr->csleep = 0;
  1710.           speed = TRUE;
  1711.         }
  1712.       else if (randint(MAX_MONS_LEVEL) > r_ptr->level) 
  1713.         {
  1714.           m_ptr->cspeed += spd;
  1715.           m_ptr->csleep = 0;
  1716.           speed = TRUE;
  1717.         }
  1718.       else
  1719.         {
  1720.           (void) sprintf(out_val, "The %s is unaffected.", r_ptr->name);
  1721.           msg_print(out_val);
  1722.         }
  1723.     }
  1724.       i = j;
  1725.     }
  1726.   return(speed);
  1727. }
  1728.  
  1729.  
  1730. /* Sleep any creature that player can see        -RAK-    */
  1731. int sleep_monsters2()
  1732. {
  1733.   int i, j;
  1734.   int sleep;
  1735.   monster_type *m_ptr;
  1736.   creature_type *r_ptr;
  1737.   vtype out_val;
  1738.  
  1739.   i = muptr;
  1740.   sleep = FALSE;
  1741.   while (i > 0)
  1742.     {
  1743.       m_ptr = &m_list[i];
  1744.       r_ptr = &c_list[m_ptr->mptr];
  1745.       j = m_ptr->nptr;
  1746.       sleep = TRUE;
  1747.       if (m_ptr->ml) 
  1748.     {
  1749.       if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  1750.           (0x1000 & r_ptr->cdefense))
  1751.         {
  1752.           (void) sprintf(out_val, "The %s is unaffected.", r_ptr->name);
  1753.           msg_print(out_val);
  1754.         }
  1755.       else
  1756.         m_ptr->csleep = 500;
  1757.     }
  1758.       i = j;
  1759.     }
  1760.   return(sleep);
  1761. }
  1762.  
  1763.  
  1764. /* Polymorph any creature that player can see...     -RAK-    */
  1765. /* NOTE: cannot polymorph a winning creature (BALROG)            */
  1766. int mass_poly()
  1767. {
  1768.   int i, j, y, x;
  1769.   int mass;
  1770.   monster_type *m_ptr;
  1771.   creature_type *r_ptr;
  1772.  
  1773.   i = muptr;
  1774.   mass = FALSE;
  1775.   while (i > 0)
  1776.     {
  1777.       m_ptr = &m_list[i];
  1778.       j = m_ptr->nptr;
  1779.       if (m_ptr->cdis < MAX_SIGHT) 
  1780.     {
  1781.       r_ptr = &c_list[m_ptr->mptr];
  1782.       if ((r_ptr->cdefense & 0x80000000) == 0) 
  1783.         {
  1784.           y = m_ptr->fy;
  1785.           x = m_ptr->fx;
  1786.           delete_monster(i);
  1787.           place_monster(y, x, randint(m_level[MAX_MONS_LEVEL]) - 1
  1788.                 + m_level[0], FALSE);
  1789.           mass = TRUE;
  1790.         }
  1791.     }
  1792.       i = j;
  1793.     }
  1794.   return(mass);
  1795. }
  1796.  
  1797.  
  1798. /* Display evil creatures on current panel        -RAK-    */
  1799. int detect_evil()
  1800. {
  1801.   int i;
  1802.   int flag;
  1803.   monster_type *m_ptr;
  1804.   char temp_str[2];
  1805.  
  1806.   flag = FALSE;
  1807.   i = muptr;
  1808.   while (i > 0)
  1809.     {
  1810.       m_ptr = &m_list[i];
  1811.       if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx)) 
  1812.     if (0x0004 & c_list[m_ptr->mptr].cdefense)
  1813.       {
  1814.         m_ptr->ml = TRUE;
  1815.         temp_str[0] = c_list[m_ptr->mptr].cchar;
  1816.         temp_str[1] = '\0';
  1817.         print(temp_str, (int)m_ptr->fy, (int)m_ptr->fx);
  1818.         flag = TRUE;
  1819.       }
  1820.       i = m_list[i].nptr;
  1821.     }
  1822.   if (flag) 
  1823.     {
  1824.       msg_print("You sense the presence of evil!");
  1825.       msg_print(" ");
  1826.       msg_flag = FALSE;
  1827.     }
  1828.   return(flag);
  1829. }
  1830.  
  1831.  
  1832. /* Change players hit points in some manner        -RAK-    */
  1833. int hp_player(num, kind)
  1834. int num;
  1835. char *kind;
  1836. {
  1837.   int res;
  1838.   struct misc *m_ptr;
  1839.  
  1840.   res = FALSE;
  1841.   m_ptr = &py.misc;
  1842.   if (num < 0) 
  1843.     {
  1844.       take_hit(num, kind);
  1845.       if (m_ptr->chp < 0) 
  1846.     msg_print("You feel your life slipping away!");
  1847.       res = TRUE;
  1848.     }
  1849.   else if (m_ptr->chp < m_ptr->mhp) 
  1850.     {
  1851.       m_ptr->chp += (double)num;
  1852.       if (m_ptr->chp > m_ptr->mhp) 
  1853.     m_ptr->chp = (double)m_ptr->mhp;
  1854.       prt_chp();
  1855.       switch(num/5)
  1856.     {
  1857.     case 0:
  1858.       msg_print("You feel a little better.");
  1859.       break;
  1860.     case 1: case 2:
  1861.       msg_print("You feel better.");
  1862.       break;
  1863.     case 3: case 4: case 5: case 6:
  1864.       msg_print("You feel much better.");
  1865.       break;
  1866.     default:
  1867.       msg_print("You feel very good.");
  1868.       break;
  1869.     }
  1870.       res = TRUE;
  1871.     }
  1872.   return(res);
  1873. }
  1874.  
  1875.  
  1876. /* Cure players confusion                -RAK-    */
  1877. int cure_confusion()
  1878. {
  1879.   int cure;
  1880.   struct flags *f_ptr;
  1881.  
  1882.   cure = FALSE;
  1883.   f_ptr = &py.flags;
  1884.   if (f_ptr->confused > 1) 
  1885.     {
  1886.       f_ptr->confused = 1;
  1887.       cure = TRUE;
  1888.     }
  1889.   return(cure);
  1890. }
  1891.  
  1892.  
  1893. /* Cure players blindness                -RAK-    */
  1894. int cure_blindness()
  1895. {
  1896.   int cure;
  1897.   struct flags *f_ptr;
  1898.  
  1899.   cure = FALSE;
  1900.   f_ptr = &py.flags;
  1901.   if (f_ptr->blind > 1) 
  1902.     {
  1903.       f_ptr->blind = 1;
  1904.       cure = TRUE;
  1905.     }
  1906.   return(cure);
  1907. }
  1908.  
  1909.  
  1910. /* Cure poisoning                    -RAK-    */
  1911. int cure_poison()
  1912. {
  1913.   int cure;
  1914.   struct flags *f_ptr;
  1915.  
  1916.   cure = FALSE;
  1917.   f_ptr = &py.flags;
  1918.   if (f_ptr->poisoned > 1) 
  1919.     {
  1920.       f_ptr->poisoned = 1;
  1921.       cure = TRUE;
  1922.     }
  1923.   return(cure);
  1924. }
  1925.  
  1926.  
  1927. /* Cure the players fear                 -RAK-    */
  1928. int remove_fear()
  1929. {
  1930.   int remove;
  1931.   struct flags *f_ptr;
  1932.  
  1933.   remove = FALSE;
  1934.   f_ptr = &py.flags;
  1935.   if (f_ptr->afraid > 1) 
  1936.     {
  1937.       f_ptr->afraid = 1;
  1938.       remove = TRUE;
  1939.     }
  1940.   return(remove);
  1941. }
  1942.  
  1943.  
  1944. /* This is a fun one.  In a given block, pick some walls and    */
  1945. /* turn them into open spots.  Pick some open spots and turn     */
  1946. /* them into walls.  An "Earthquake" effect...           -RAK-   */
  1947. int earthquake()
  1948. {
  1949.   int i, j;
  1950.   cave_type *c_ptr;
  1951.  
  1952.   for (i = char_row-8; i <= char_row+8; i++)
  1953.     for (j = char_col-8; j <= char_col+8; j++)
  1954.       if ((i != char_row) || (j != char_col)) 
  1955.     if (in_bounds(i, j)) 
  1956.       if (randint(8) == 1) 
  1957.         {
  1958.           c_ptr = &cave[i][j];
  1959.           if (c_ptr->tptr != 0) 
  1960.         (void) delete_object(i, j);
  1961.           if (c_ptr->cptr > 1) 
  1962.         /* what happens to this monster ? */
  1963.         (void) mon_take_hit((int)c_ptr->cptr, damroll("2d8"));
  1964.           if ((c_ptr->fval >= 10) && (c_ptr->fval <= 12))
  1965.         {
  1966.           if (next_to4(i, j, 1, 2, -1) > 0) 
  1967.             {
  1968.               c_ptr->fval  = corr_floor2.ftval;
  1969.               c_ptr->fopen = corr_floor2.ftopen;
  1970.             }
  1971.           else
  1972.             {
  1973.               c_ptr->fval  = corr_floor1.ftval;
  1974.               c_ptr->fopen = corr_floor1.ftopen;
  1975.             }
  1976.           if (test_light(i, j))
  1977.             unlite_spot(i, j);
  1978.           c_ptr->pl = FALSE;
  1979.           c_ptr->fm = FALSE;
  1980.           if (c_ptr->tl)
  1981.             lite_spot(i, j);
  1982.         }
  1983.           else if (set_floor(c_ptr->fval))
  1984.         {
  1985.           switch(randint(10))
  1986.             {
  1987.             case 1: case 2: case 3: case 4: case 5:
  1988.               c_ptr->fval  = rock_wall3.ftval;
  1989.               c_ptr->fopen = rock_wall3.ftopen;
  1990.               break;
  1991.             case 6: case 7: case 8:
  1992.               c_ptr->fval  = rock_wall2.ftval;
  1993.               c_ptr->fopen = rock_wall2.ftopen;
  1994.               break;
  1995.             case 9: case 10:
  1996.               c_ptr->fval  = rock_wall1.ftval;
  1997.               c_ptr->fopen = rock_wall1.ftopen;
  1998.               break;
  1999.             }
  2000.           c_ptr->fm = FALSE;
  2001.         }
  2002.           if (test_light(i, j)) 
  2003.         lite_spot(i, j);
  2004.         }
  2005.   return(TRUE);
  2006. }
  2007.  
  2008.  
  2009. /* Evil creatures don't like this...                     -RAK-   */
  2010. int protect_evil()
  2011. {
  2012.   struct flags *f_ptr;
  2013.  
  2014.   f_ptr = &py.flags;
  2015.   f_ptr->protevil += randint(25) + 3*py.misc.lev;
  2016.   return(TRUE);
  2017. }
  2018.  
  2019.  
  2020. /* Create some high quality mush for the player.     -RAK-    */
  2021. int create_food()
  2022. {
  2023.   cave_type *c_ptr;
  2024.  
  2025.   c_ptr = &cave[char_row][char_col];
  2026.   if (c_ptr->tptr != 0) 
  2027.     (void) delete_object(char_row, char_col);
  2028.   place_object(char_row, char_col);
  2029.   t_list[c_ptr->tptr] = mush;
  2030.   return(TRUE);
  2031. }
  2032.  
  2033.  
  2034. /* Attempts to destroy a type of creature.  Success depends on    */
  2035. /* the creatures level VS. the player's level            -RAK-   */
  2036. int dispell_creature(cflag, damage)
  2037. int cflag;
  2038. int damage;
  2039. {
  2040.   int i, m_next;
  2041.   vtype out_val;
  2042.   monster_type *m_ptr;
  2043.   creature_type *r_ptr;
  2044.   struct misc *p_ptr;
  2045.   int dispel;
  2046.  
  2047.   i = muptr;
  2048.   dispel = FALSE;
  2049.   while (i > 0)
  2050.     {
  2051.       m_next = m_list[i].nptr;
  2052.       m_ptr = &m_list[i];
  2053.       if (m_ptr->ml) 
  2054.     if (cflag & c_list[m_ptr->mptr].cdefense)
  2055.       {
  2056.         m_ptr->hp -= randint(damage);
  2057.         m_ptr->csleep = 0;
  2058.         if (m_ptr->hp < 0) 
  2059.           {
  2060.         (void) sprintf(out_val, "The %s dissolves!",
  2061.                    c_list[m_ptr->mptr].name);
  2062.         msg_print(out_val);
  2063.         monster_death((int)m_ptr->fy, (int)m_ptr->fx,
  2064.                   c_list[m_ptr->mptr].cmove);
  2065.         r_ptr = &c_list[m_ptr->mptr];
  2066.         p_ptr = &py.misc;
  2067.         p_ptr->exp += ((r_ptr->mexp*(r_ptr->level/p_ptr->lev)) + 0.5);
  2068.         delete_monster(i);
  2069.           }
  2070.         else
  2071.           {
  2072.         (void) sprintf(out_val, "The %s shudders.",
  2073.                    c_list[m_ptr->mptr].name);
  2074.         msg_print(out_val);
  2075.           }
  2076.         dispel = TRUE;
  2077.       }
  2078.       i = m_next;
  2079.     }
  2080.   return(dispel);
  2081. }
  2082.  
  2083.  
  2084. /* Attempt to turn (confuse) undead creatures...     -RAK-    */
  2085. int turn_undead()
  2086. {
  2087.   int i;
  2088.   int turn_und;
  2089.   monster_type *m_ptr;
  2090.   vtype out_val;
  2091.  
  2092.   i = muptr;
  2093.   turn_und = FALSE;
  2094.   while (i > 0)
  2095.     {
  2096.       m_ptr = &m_list[i];
  2097.       if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx)) 
  2098.     if (m_ptr->ml) 
  2099.       if (0x0008 & c_list[m_ptr->mptr].cdefense)
  2100.         {
  2101.           if (((py.misc.lev+1) > c_list[m_ptr->mptr].level) ||
  2102.           (randint(5) == 1)) 
  2103.         {
  2104.           (void) sprintf(out_val, "The %s runs frantically!",
  2105.               c_list[m_ptr->mptr].name);
  2106.           msg_print(out_val);
  2107.           m_ptr->confused = TRUE;
  2108.         }
  2109.           else
  2110.         {
  2111.           (void) sprintf(out_val, "The %s is unaffected.",
  2112.               c_list[m_ptr->mptr].name);
  2113.           msg_print(out_val);
  2114.         }
  2115.           turn_und = TRUE;
  2116.         }
  2117.       i = m_list[i].nptr;
  2118.     }
  2119.   return(turn_und);
  2120. }
  2121.  
  2122.  
  2123. /* Leave a glyph of warding... Creatures will not pass over! -RAK-*/
  2124. int warding_glyph()
  2125. {
  2126.   int i;
  2127.   cave_type *c_ptr;
  2128.  
  2129.   c_ptr = &cave[char_row][char_col];
  2130.   if (c_ptr->tptr == 0) 
  2131.     {
  2132.       popt(&i);
  2133.       c_ptr->tptr = i;
  2134.       t_list[i] = scare_monster;
  2135.     }
  2136.   return(TRUE);
  2137. }
  2138.  
  2139.  
  2140. /* Lose a strength point.                -RAK-    */
  2141. int lose_str()
  2142. {
  2143.   if (!py.flags.sustain_str) 
  2144.     {
  2145.       py.stats.cstr = de_statp(py.stats.cstr);
  2146.       msg_print("You feel very sick.");
  2147.       prt_strength();
  2148.     }
  2149.   else
  2150.     msg_print("You feel sick for a moment,  it passes.");
  2151.   return(TRUE);
  2152. }
  2153.  
  2154.  
  2155. /* Lose an intelligence point.                -RAK-    */
  2156. int lose_int()
  2157. {
  2158.   if (!py.flags.sustain_int) 
  2159.     {
  2160.       py.stats.cint = de_statp(py.stats.cint);
  2161.       msg_print("You become very dizzy.");
  2162.       prt_intelligence();
  2163.     }
  2164.   else
  2165.     msg_print("You become dizzy for a moment,  it passes.");
  2166.   return(TRUE);
  2167. }
  2168.  
  2169.  
  2170. /* Lose a wisdom point.                    -RAK-    */
  2171. int lose_wis()
  2172. {
  2173.   if (!py.flags.sustain_wis) 
  2174.     {
  2175.       py.stats.cwis = de_statp(py.stats.cwis);
  2176.       msg_print("You feel very naive.");
  2177.       prt_wisdom();
  2178.     }
  2179.   else
  2180.     msg_print("You feel naive for a moment,  it passes.");
  2181.   return(TRUE);
  2182. }
  2183.  
  2184.  
  2185. /* Lose a dexterity point.                -RAK-    */
  2186. int lose_dex()
  2187. {
  2188.   if (!py.flags.sustain_dex) 
  2189.     {
  2190.       py.stats.cdex = de_statp(py.stats.cdex);
  2191.       msg_print("You feel very sore.");
  2192.       prt_dexterity();
  2193.     }
  2194.   else
  2195.     msg_print("You feel sore for a moment,  it passes.");
  2196.   return(TRUE);
  2197. }
  2198.  
  2199.  
  2200. /* Lose a constitution point.                -RAK-    */
  2201. int lose_con()
  2202. {
  2203.   if (!py.flags.sustain_con) 
  2204.     {
  2205.       py.stats.ccon = de_statp(py.stats.ccon);
  2206.       msg_print("You feel very sick.");
  2207.       prt_constitution();
  2208.     }
  2209.   else
  2210.     msg_print("You feel sick for a moment,  it passes.");
  2211.   return(TRUE);
  2212. }
  2213.  
  2214.  
  2215. /* Lose a charisma point.                -RAK-    */
  2216. int lose_chr()
  2217. {
  2218.   if (!py.flags.sustain_chr) 
  2219.     {
  2220.       py.stats.cchr = de_statp(py.stats.cchr);
  2221.       msg_print("Your skin starts to itch.");
  2222.       prt_charisma();
  2223.     }
  2224.   else
  2225.     msg_print("Your skin starts to itch, but feels better now.");
  2226.   return(TRUE);
  2227. }
  2228.  
  2229.  
  2230. /* Lose experience                    -RAK-    */
  2231. lose_exp(amount)
  2232. int amount;
  2233. {
  2234.   int i, j;
  2235.   int av_hp, lose_hp;
  2236.   int av_mn, lose_mn;
  2237.   int flag;
  2238.   struct misc *m_ptr;
  2239.   class_type *c_ptr;
  2240.  
  2241.   m_ptr = &py.misc;
  2242.   if (amount > m_ptr->exp) 
  2243.     m_ptr->exp = 0;
  2244.   else
  2245.     m_ptr->exp -= amount;
  2246.   i = 1;
  2247.   while ((player_exp[i]*m_ptr->expfact) <= m_ptr->exp)
  2248.     i++;
  2249.   j = m_ptr->lev - i;
  2250.   while (j > 0)
  2251.     {
  2252.       av_hp = (m_ptr->mhp/m_ptr->lev) + 1;
  2253.       av_mn = (m_ptr->mana/m_ptr->lev) + 1;
  2254.       m_ptr->lev--;
  2255.       j--;
  2256.       lose_hp = randint(av_hp*2-1);
  2257.       lose_mn = randint(av_mn*2-1);
  2258.       m_ptr->mhp  -= lose_hp;
  2259.       m_ptr->mana -= lose_mn;
  2260.       if (m_ptr->mhp  < 1)  m_ptr->mhp  = 1;
  2261.       if (m_ptr->mana < 0)  m_ptr->mana = 0;
  2262.       c_ptr = &class[m_ptr->pclass];
  2263.       if ((c_ptr->mspell) || (c_ptr->pspell)) 
  2264.     {
  2265.       i = 32;
  2266.       flag = FALSE;
  2267.       do
  2268.         {
  2269.           i--;
  2270.           if (magic_spell[m_ptr->pclass][i].learned) 
  2271.         flag = TRUE;
  2272.         }
  2273.       while ((!flag) && (i >= 2));
  2274.       if (flag) 
  2275.         {
  2276.           magic_spell[m_ptr->pclass][i].learned = FALSE;
  2277.           if (c_ptr->mspell) 
  2278.         msg_print("You have forgotten a magic spell!");
  2279.           else
  2280.         msg_print("You have forgotten a prayer!");
  2281.         }
  2282.     }
  2283.     }
  2284.   if (m_ptr->chp > m_ptr->mhp)
  2285.     m_ptr->chp = (double)m_ptr->mhp;
  2286.   if (m_ptr->cmana > m_ptr->mana)
  2287.     m_ptr->cmana = (double)m_ptr->mana;
  2288.   (void) strcpy(m_ptr->title, player_title[m_ptr->pclass][m_ptr->lev-1]);
  2289.   prt_experience();
  2290.   prt_mhp();
  2291.   prt_chp();
  2292.   prt_cmana();
  2293.   prt_level();
  2294.   prt_title();
  2295. }
  2296.  
  2297.  
  2298. /* Slow Poison                        -RAK-    */
  2299. int slow_poison()
  2300. {
  2301.   int slow;
  2302.   struct flags *f_ptr;
  2303.  
  2304.   slow = FALSE;
  2305.   f_ptr = &py.flags;
  2306.   if (f_ptr->poisoned > 0) 
  2307.     {
  2308.       f_ptr->poisoned /= 2.0;
  2309.       if (f_ptr->poisoned < 1)  f_ptr->poisoned = 1;
  2310.       slow = TRUE;
  2311.       msg_print("The effects of the poison has been reduced.");
  2312.     }
  2313.   return(slow);
  2314. }
  2315.  
  2316.  
  2317. /* Bless                         -RAK-    */
  2318. int bless(amount)
  2319. int amount;
  2320. {
  2321.   py.flags.blessed += amount;
  2322.   return(TRUE);
  2323. }
  2324.  
  2325.  
  2326. /* Detect Invisible for period of time            -RAK-    */
  2327. detect_inv2(amount)
  2328. int amount;
  2329. {
  2330.   py.flags.detect_inv += amount;
  2331. }
  2332.  
  2333.  
  2334. replace_spot(y, x, typ)
  2335. int y, x, typ;
  2336. {
  2337.   cave_type *c_ptr;
  2338.  
  2339.   c_ptr = &cave[y][x];
  2340.   switch(typ)
  2341.     {
  2342.     case 1: case 2: case 3:
  2343.       c_ptr->fval  = corr_floor1.ftval;
  2344.       c_ptr->fopen = corr_floor1.ftopen;
  2345.       break;
  2346.     case 4: case 7: case 10:
  2347.       c_ptr->fval  = rock_wall1.ftval;
  2348.       c_ptr->fopen = rock_wall1.ftopen;
  2349.       break;
  2350.     case 5: case 8: case 11:
  2351.       c_ptr->fval  = rock_wall2.ftval;
  2352.       c_ptr->fopen = rock_wall2.ftopen;
  2353.       break;
  2354.     case 6: case 9: case 12:
  2355.       c_ptr->fval  = rock_wall3.ftval;
  2356.       c_ptr->fopen = rock_wall3.ftopen;
  2357.       break;
  2358.     }
  2359.   c_ptr->pl = FALSE;
  2360.   c_ptr->fm = FALSE;
  2361.   if (c_ptr->tptr != 0) 
  2362.     (void) delete_object(y, x);
  2363.   if (c_ptr->cptr > 1) 
  2364.     delete_monster((int)c_ptr->cptr);
  2365. }
  2366.  
  2367.  
  2368. /* The spell of destruction...                -RAK-    */
  2369. /* NOTE : Winning creatures that are deleted will be considered  */
  2370. /*        as teleporting to another level.  This will NOT win the*/
  2371. /*        game...                                                */
  2372. int destroy_area(y, x)
  2373. int y, x;
  2374. {
  2375.   int i, j, k;
  2376.  
  2377.   if (dun_level > 0) 
  2378.     {
  2379.       for (i = (y-15); i <= (y+15); i++)
  2380.     for (j = (x-15); j <= (x+15); j++)
  2381.       if (in_bounds(i, j)) 
  2382.         if (cave[i][j].fval != 15) 
  2383.           {
  2384.         k = distance(i, j, y, x);
  2385.         if (k < 13) 
  2386.           replace_spot(i, j, randint(6));
  2387.         else if (k < 16) 
  2388.           replace_spot(i, j, randint(9));
  2389.           }
  2390.     }
  2391.   msg_print("There is a searing blast of light!");
  2392.   py.flags.blind += 10 + randint(10);
  2393.   return(TRUE);
  2394. }
  2395.  
  2396.  
  2397. /* Enchants a plus onto an item...            -RAK-    */
  2398. int enchant(plusses)
  2399. worlint *plusses;
  2400. {
  2401.   int chance;
  2402.   int res;
  2403.  
  2404.   chance = 0;
  2405.   res = FALSE;
  2406.   if (*plusses > 0) 
  2407.     switch(*plusses)
  2408.       {
  2409.       case 1:  chance = 040; break;
  2410.       case 2:  chance = 100; break;
  2411.       case 3:  chance = 200; break;
  2412.       case 4:  chance = 400; break;
  2413.       case 5:  chance = 600; break;
  2414.       case 6:  chance = 700; break;
  2415.       case 7:  chance = 800; break;
  2416.       case 8:  chance = 900; break;
  2417.       case 9:  chance = 950; break;
  2418.       default: chance = 995; break;
  2419.       }
  2420.   if (randint(1000) > chance) 
  2421.     {
  2422.       *plusses += 1;
  2423.       res = TRUE;
  2424.     }
  2425.   return(res);
  2426. }
  2427.  
  2428.  
  2429. /* Removes curses from items in inventory        -RAK-    */
  2430. int remove_curse()
  2431. {
  2432.   int i;
  2433.   int remove;
  2434.   treasure_type *i_ptr;
  2435.  
  2436.   remove = FALSE;
  2437.   for (i = 22; i <= 31; i++)
  2438.     {
  2439.       i_ptr = &inventory[i];
  2440.       if (0x80000000 & i_ptr->flags)
  2441.     {
  2442.       i_ptr->flags &= 0x7FFFFFFF;
  2443.       py_bonuses(blank_treasure, 0);
  2444.       remove = TRUE;
  2445.     }
  2446.     }
  2447.   return(remove);
  2448. }
  2449.  
  2450.  
  2451. /* Restores any drained experience            -RAK-    */
  2452. int restore_level()
  2453. {
  2454.   int restore;
  2455.   struct misc *m_ptr;
  2456.   
  2457.   restore = FALSE;
  2458.   m_ptr = &py.misc;
  2459.   if (m_ptr->max_exp > m_ptr->exp) 
  2460.     {
  2461.       restore = TRUE;
  2462.       msg_print("You feel your life energies returning...");
  2463.       while (m_ptr->exp < m_ptr->max_exp)
  2464.     {
  2465.       m_ptr->exp = m_ptr->max_exp;
  2466.       prt_experience();
  2467.     }
  2468.     }
  2469.   return(restore);
  2470. }
  2471.