home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / mor4873s.lzh / MAGIC.C < prev    next >
C/C++ Source or Header  |  1988-11-01  |  6KB  |  229 lines

  1. #include "constant.h"
  2. #include "config.h"
  3. #include "types.h"
  4. #include "externs.h"
  5.  
  6.  
  7. /* Throw a magic spell                    -RAK-    */
  8. cast()
  9. {
  10.   int i, j, item_val, dir;
  11.   int choice, chance, result;
  12.   int dumy, y_dumy, x_dumy;
  13.   int redraw;
  14.   register struct flags *f_ptr;
  15.   register struct misc *p_ptr;
  16.   register treasure_type *i_ptr;
  17.   register spell_type *m_ptr;
  18.  
  19.   reset_flag = TRUE;
  20.   if (py.flags.blind > 0)
  21.     msg_print("You can't see to read your spell book!");
  22.   else if (no_light())
  23.     msg_print("You have no light to read by.");
  24.   else if (py.flags.confused > 0)
  25.     msg_print("You are too confused...");
  26.   else if (class[py.misc.pclass].mspell)
  27.     if (inven_ctr > 0)
  28.       {
  29.      if (find_range(90, -1, &i, &j))
  30.       {
  31.         redraw = FALSE;
  32.         if (get_item(&item_val, "Use which spell-book?",
  33.              &redraw, i, j))
  34.           {
  35.         if ((result = cast_spell("Cast which spell?", item_val,
  36.                    &choice, &chance, &redraw)) == TRUE)
  37.           {
  38.             m_ptr = &magic_spell[py.misc.pclass][choice];
  39.             reset_flag = FALSE;
  40.         
  41.             if (randint(100) < chance)
  42.               msg_print("You failed to get the spell off!");
  43.             else         
  44.               {
  45.              y_dumy = char_row;
  46.              x_dumy = char_col;
  47.              /* Spells...  */
  48.             choice++;
  49.             switch(choice)         
  50.               {
  51.               case 1:
  52.                 if (get_dir("Which direction?", &dir,     
  53.                     &dumy, &y_dumy, &x_dumy))     
  54.                   fire_bolt(0, dir, char_row, char_col,
  55.                     damroll("2d6")+1, "Magic Missile");
  56.                 break;
  57.               case 2:
  58.                 (void) detect_monsters();
  59.                 break;
  60.               case 3:
  61.                 teleport(10);
  62.                 break;
  63.               case 4:
  64.                 (void) light_area(char_row, char_col);
  65.                 break;
  66.               case 5:
  67.                 (void) hp_player(damroll("4d4"), "a magic spell.");
  68.                 break;
  69.               case 6:
  70.                 (void) detect_sdoor();
  71.                 (void) detect_trap();
  72.                 break;
  73.               case 7:
  74.                 if (get_dir("Which direction?", &dir,
  75.                     &dumy, &y_dumy, &x_dumy))     
  76.                   fire_ball(2, dir, char_row, char_col, 9,
  77.                     "Stinking Cloud");
  78.                 break;
  79.               case 8:
  80.                 if (get_dir("Which direction?", &dir,
  81.                     &dumy, &y_dumy, &x_dumy))
  82.                   (void) confuse_monster(dir, char_row, char_col);
  83.                 break;
  84.               case 9:
  85.                 if (get_dir("Which direction?", &dir,
  86.                     &dumy, &y_dumy, &x_dumy))
  87.                   fire_bolt(1, dir, char_row, char_col,
  88.                     damroll("3d8")+1, "Lightning Bolt");
  89.                 break;
  90.               case 10:
  91.                 (void) td_destroy();
  92.                 break;
  93.               case 11:
  94.                 if (get_dir("Which direction?", &dir,
  95.                     &dumy, &y_dumy, &x_dumy))
  96.                   (void) sleep_monster(dir, char_row, char_col);
  97.                 break;
  98.               case 12:
  99.                 (void) cure_poison();
  100.                 break;
  101.               case 13:
  102.                 teleport((int)(py.misc.lev*5));
  103.                 break;
  104.               case 14:
  105.                 for (i = 22; i < INVEN_MAX; i++)
  106.                   {
  107.                  i_ptr = &inventory[i];
  108.                  i_ptr->flags = (i_ptr->flags & 0x7FFFFFFF);
  109.                   }
  110.                 break;
  111.               case 15:
  112.                 if (get_dir("Which direction?", &dir,
  113.                     &dumy, &y_dumy, &x_dumy))
  114.                    fire_bolt(4, dir, char_row, char_col,
  115.                      damroll("4d8")+1, "Frost Bolt");
  116.                  break;
  117.                case 16:
  118.                  if (get_dir("Which direction?", &dir,
  119.                      &dumy, &y_dumy, &x_dumy))      
  120.                   (void) wall_to_mud(dir, char_row, char_col);
  121.                  break;
  122.                case 17:
  123.                  (void) create_food();
  124.                  break;
  125.                case 18:
  126.                  (void) recharge(20);
  127.                  break;
  128.                case 19:
  129.                  (void) sleep_monsters1(char_row, char_col);
  130.                  break;
  131.                case 20:
  132.                  if (get_dir("Which direction?", &dir,
  133.                      &dumy, &y_dumy, &x_dumy))      
  134.                   (void) poly_monster(dir, char_row, char_col);
  135.                  break;
  136.                case 21:
  137.                  (void) ident_spell();
  138.                  break;
  139.                case 22:
  140.                   (void) sleep_monsters2();
  141.                  break;
  142.                case 23:
  143.                  if (get_dir("Which direction?", &dir,
  144.                     &dumy, &y_dumy, &x_dumy))      
  145.                   fire_bolt(5, dir, char_row, char_col,      
  146.                     damroll("6d8")+1, "Fire Bolt");
  147.                  break;
  148.                case 24:
  149.                  if (get_dir("Which direction?", &dir,      
  150.                     &dumy, &y_dumy, &x_dumy))
  151.                   (void)speed_monster(dir, char_row, char_col, -1);
  152.                  break;
  153.               case 25:
  154.                  if (get_dir("Which direction?", &dir,
  155.                     &dumy, &y_dumy, &x_dumy))      
  156.                   fire_ball(4, dir, char_row, char_col, 33,
  157.                     "Frost Ball");
  158.                  break;
  159.                case 26:
  160.                  (void) recharge(60);
  161.                  break;
  162.                case 27:
  163.                  if (get_dir("Which direction?", &dir,
  164.                      &dumy, &y_dumy, &x_dumy))
  165.                   (void) teleport_monster(dir, char_row, char_col);
  166.                  break;
  167.                case 28:
  168.                  f_ptr = &py.flags;
  169.                  f_ptr->fast += randint(20) + py.misc.lev;
  170.                  break;
  171.                case 29:
  172.                  if (get_dir("Which direction?", &dir,
  173.                      &dumy, &y_dumy, &x_dumy))      
  174.                   fire_ball(5, dir, char_row, char_col, 49,
  175.                     "Fire Ball");
  176.                  break;
  177.                case 30:
  178.                  (void) destroy_area(char_row, char_col);
  179.                  break;
  180.                case 31:
  181.                  (void) genocide();
  182.                default:
  183.                  break;
  184.                }
  185.              /* End of spells...                              */
  186.             if (!reset_flag)              
  187.               {
  188.                  p_ptr = &py.misc;
  189.                  p_ptr->exp += m_ptr->sexp;
  190.                  prt_experience();
  191.                  m_ptr->sexp = 0;
  192.                }
  193.                }
  194.              p_ptr = &py.misc;
  195.              if (!reset_flag)
  196.               {
  197.              if (m_ptr->smana > p_ptr->cmana)
  198.               {
  199.                  msg_print("You faint from the effort!");
  200.                  py.flags.paralysis =
  201.                   randint(5*(int)(m_ptr->smana-(int)p_ptr->cmana));
  202.                  p_ptr->cmana = 0.0;
  203.                  if (randint(3) == 1)
  204.                   {
  205.                  msg_print("You have damaged your health!");
  206.                  py.stats.ccon = de_statp(py.stats.ccon);
  207.                  prt_constitution();
  208.                    }
  209.                }
  210.              else
  211.               p_ptr->cmana -= (double)m_ptr->smana;
  212.              prt_cmana();
  213.                }
  214.            }
  215.         else if (result == -1)
  216.           msg_print("You don't know any spells in that book.");
  217.            }
  218.          else
  219.           if (redraw)  draw_cave();
  220.        }
  221.      else
  222.       msg_print("But you are not carrying any spell-books!");
  223.       }
  224.     else
  225.       msg_print("But you are not carrying any spell-books!");
  226.   else
  227.     msg_print("You can't cast spells!");
  228. }
  229.