OSDN Git Service

add type casting for fprintf
[hengband/hengband.git] / src / mind.c
index fd7c083..33e9921 100644 (file)
@@ -1,15 +1,15 @@
 /* File: mind.c */
 
-/* Purpose: Mindcrafter code */
-
 /*
- * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
+ * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
  *
- * This software may be copied and distributed for educational, research, and
- * not for profit purposes provided that this copyright and statement are
- * included in all such copies.
+ * This software may be copied and distributed for educational, research,
+ * and not for profit purposes provided that this copyright and statement
+ * are included in all such copies.  Other copyrights may also apply.
  */
 
+/* Purpose: Mindcrafter code */
+
 #include "angband.h"
 #include "mindtips.h"
 
@@ -322,9 +322,9 @@ void mindcraft_info(char *p, int use_mind, int power)
        case 11: sprintf(p, " %s%dd6", s_dam, plev / 2);  break;
        case 12: sprintf(p, " %sd%d+%d", s_dam, plev * 3, plev * 3); break;
 #ifdef JP
-       case 13: sprintf(p, " ¹ÔÆ°:%d²ó", (p_ptr->csp + 100-p_ptr->energy_need - 50)/100); break;
+       case 13: sprintf(p, " ¹ÔÆ°:%ld²ó", (long int)(p_ptr->csp + 100-p_ptr->energy_need - 50)/100); break;
 #else
-       case 13: sprintf(p, " %d acts.", (p_ptr->csp + 100-p_ptr->energy_need - 50)/100); break;
+       case 13: sprintf(p, " %ld acts.", (p_ptr->csp + 100-p_ptr->energy_need - 50)/100); break;
 #endif
        }
       break;
@@ -347,7 +347,7 @@ void mindcraft_info(char *p, int use_mind, int power)
          case 8:  sprintf(p, " %s10d6+%d", s_dam, plev * 3 / 2 + boost * 3 / 5); break;
          case 9:  break;
 #ifdef JP
-         case 10: sprintf(p, " ºÇÂç%dɤ", 1+boost/100); break;
+         case 10: sprintf(p, " ºÇÂç%dÂÎ", 1+boost/100); break;
 #else
          case 10: sprintf(p, " max %d", 1+boost/100); break;
 #endif
@@ -524,15 +524,18 @@ void mindcraft_info(char *p, int use_mind, int power)
 
 #ifdef ALLOW_REPEAT /* TNB */
 
-      /* Get the spell, if available */
-      if (repeat_pull(sn))
+       /* Get the spell, if available */
+       if (repeat_pull(sn))
        {
-         /* Verify the spell */
-         if (mind_ptr->info[*sn].min_lev <= plev)
-           {
-             /* Success */
-             return (TRUE);
-           }
+               /* Hack -- If requested INVEN_FORCE(1111), pull again */
+               if (*sn == INVEN_FORCE) repeat_pull(sn);
+
+               /* Verify the spell */
+               if (mind_ptr->info[*sn].min_lev <= plev)
+               {
+                       /* Success */
+                       return (TRUE);
+               }
        }
 
 #endif /* ALLOW_REPEAT -- TNB */
@@ -568,15 +571,15 @@ void mindcraft_info(char *p, int use_mind, int power)
 #else
                (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) Use which %s? ",
 #endif
-               p, I2A(0), I2A(num - 1), p);
+               p, I2A(0), I2A(num - 1), p);
        }
 
        if (use_menu && !only_browse) screen_save();
        /* Get a spell from the user */
 
-        choice= (always_show_list || use_menu) ? ESCAPE:1 ;
-        while (!flag)
-        {
+       choice= (always_show_list || use_menu) ? ESCAPE:1 ;
+       while (!flag)
+       {
                if(choice==ESCAPE) choice = ' '; 
                else if( !get_com(out_val, &choice, TRUE) )break;
 
@@ -588,7 +591,6 @@ void mindcraft_info(char *p, int use_mind, int power)
                                {
                                        if (!only_browse) screen_load();
                                        return (FALSE);
-                                       break;
                                }
 
                                case '8':
@@ -807,14 +809,10 @@ put_str(format("Lv   %s   Fail Info", ((use_mind == MIND_BERSERKER) || (use_mind
        if (redraw && !only_browse) screen_load();
 
        /* Show choices */
-       if (show_choices)
-       {
-               /* Update */
-               p_ptr->window |= (PW_SPELL);
+       p_ptr->window |= (PW_SPELL);
 
-               /* Window stuff */
-               window_stuff();
-       }
+       /* Window stuff */
+       window_stuff();
 
        /* Abort if needed */
        if (!flag) return (FALSE);
@@ -851,7 +849,7 @@ static bool cast_mindcrafter_spell(int spell)
                {
                        chg_virtue(V_KNOWLEDGE, 1);
                        chg_virtue(V_ENLIGHTEN, 1);
-                       wiz_lite(FALSE, FALSE);
+                       wiz_lite(FALSE);
                }
                else if (plev > 19)
                        map_area(DETECT_RAD_MAP);
@@ -891,11 +889,11 @@ if (!b) msg_print("
                break;
        case 2:
                /* Minor displace */
-               teleport_player(10);
+               teleport_player(10, 0L);
                break;
        case 3:
                /* Major displace */
-               teleport_player(plev * 5);
+               teleport_player(plev * 5, 0L);
                break;
        case 4:
                /* Domination */
@@ -932,7 +930,6 @@ if (!b) msg_print("
                        return psychometry();
                else
                        return ident_spell(FALSE);
-               break;
        case 8:
                /* Mindwave */
 #ifdef JP
@@ -956,7 +953,7 @@ msg_print("
                 * Only heal when Adrenalin Channeling is not active. We check
                 * that by checking if the player isn't fast and 'heroed' atm.
                 */
-               if (!p_ptr->fast || !p_ptr->hero)
+               if (!IS_FAST() || !IS_HERO())
                {
                        hp_player(plev);
                }
@@ -1059,7 +1056,7 @@ static bool cast_force_spell(int spell)
                (void)lite_area(damroll(2, (plev / 2)), (plev / 10) + 1);
                break;
        case 2:
-               set_tim_ffall(randint1(30) + 30 + boost / 5, FALSE);
+               set_tim_levitation(randint1(30) + 30 + boost / 5, FALSE);
                break;
        case 3:
                project_length = plev / 8 + 3;
@@ -1114,11 +1111,12 @@ static bool cast_force_spell(int spell)
                        int oy = y, ox = x;
                        int m_idx = cave[y][x].m_idx;
                        monster_type *m_ptr = &m_list[m_idx];
+                       monster_race *r_ptr = &r_info[m_ptr->r_idx];
                        char m_name[80];
 
                        monster_desc(m_name, m_ptr, 0);
 
-                       if (randint1(r_info[m_ptr->r_idx].level * 3 / 2) > randint0(dam / 2) + dam/2)
+                       if (randint1(r_ptr->level * 3 / 2) > randint0(dam / 2) + dam/2)
                        {
 #ifdef JP
                                msg_format("%s¤ÏÈô¤Ð¤µ¤ì¤Ê¤«¤Ã¤¿¡£", m_name);
@@ -1154,6 +1152,9 @@ static bool cast_force_spell(int spell)
                                        update_mon(m_idx, TRUE);
                                        lite_spot(oy, ox);
                                        lite_spot(ty, tx);
+
+                                       if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
+                                               p_ptr->update |= (PU_MON_LITE);
                                }
                        }
                }
@@ -1165,44 +1166,14 @@ static bool cast_force_spell(int spell)
                break;
        case 9:
        {
-               monster_type *m_ptr;
-               char m_name[80];
+               int m_idx;
 
                if (!target_set(TARGET_KILL)) return FALSE;
-               if (!cave[target_row][target_col].m_idx) break;
-               if (!los(py, px, target_row, target_col)) break;
-               m_ptr = &m_list[cave[target_row][target_col].m_idx];
-               monster_desc(m_name, m_ptr, 0);
-               if (m_ptr->invulner)
-               {
-                       m_ptr->invulner = 0;
-#ifdef JP
-msg_format("%s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ï¤Ê¤¤¡£", m_name);
-#else
-                       msg_format("%^s is no longer invulnerable.", m_name);
-#endif
-               }
-               if (m_ptr->fast)
-               {
-                       m_ptr->fast = 0;
-#ifdef JP
-msg_format("%s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
-#else
-                       msg_format("%^s is no longer fast.", m_name);
-#endif
-               }
-               if (m_ptr->slow)
-               {
-                       m_ptr->slow = 0;
-#ifdef JP
-msg_format("%s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
-#else
-                       msg_format("%^s is no longer slow.", m_name);
-#endif
-               }
-               p_ptr->redraw |= (PR_HEALTH);
-               if (p_ptr->riding == cave[target_row][target_col].m_idx) p_ptr->redraw |= (PR_UHEALTH);
-
+               m_idx = cave[target_row][target_col].m_idx;
+               if (!m_idx) break;
+               if (!player_has_los_bold(target_row, target_col)) break;
+               if (!projectable(py, px, target_row, target_col)) break;
+               dispel_monster_status(m_idx);
                break;
        }
        case 10:
@@ -1298,7 +1269,7 @@ static bool cast_mirror_spell(int spell)
        /* drip of light */
        case 1:
          if( number_of_mirrors() < 4 + plev/10 ){
-           warding_mirror();
+           place_mirror();
          }
          else {
 #ifdef JP
@@ -1319,7 +1290,7 @@ msg_format("There are too many mirrors to control!");
          break;
        /* warped mirror */
        case 3:
-         teleport_player(10);
+         teleport_player(10, 0L);
          break;
        /* mirror of light */
        case 4:
@@ -1327,7 +1298,7 @@ msg_format("There are too many mirrors to control!");
          break;
        /* mirror of wandering */
        case 5:
-         teleport_player(plev * 5);
+         teleport_player(plev * 5, 0L);
          break;
        /* robe of dust */
        case 6:
@@ -1404,11 +1375,11 @@ msg_format("There are too many mirrors to control!");
 #else
          msg_print("Go through the world of mirror...");
 #endif
-         return dimension_door();
+         return mirror_tunnel();
+
        /* mirror of recall */
        case 17:
-         if(!word_of_recall())return FALSE;
-         break;
+               return word_of_recall();
        /* multi-shadow */
        case 18:
          set_multishadow(6+randint1(6),FALSE);
@@ -1484,48 +1455,18 @@ static bool cast_berserk_spell(int spell)
 
                py_attack(y, x, 0);
 
-               if (!player_can_enter(cave[y][x].feat) || is_trap(cave[y][x].feat))
+               if (!player_can_enter(cave[y][x].feat, 0) || is_trap(cave[y][x].feat))
                        break;
 
                y += ddy[dir];
                x += ddx[dir];
 
-               if (player_can_enter(cave[y][x].feat) && !is_trap(cave[y][x].feat) && !cave[y][x].m_idx)
+               if (player_can_enter(cave[y][x].feat, 0) && !is_trap(cave[y][x].feat) && !cave[y][x].m_idx)
                {
-                       int oy, ox;
-
                        msg_print(NULL);
 
-                       /* Save the old location */
-                       oy = py;
-                       ox = px;
-
                        /* Move the player */
-                       py = y;
-                       px = x;
-
-                       forget_flow();
-
-                       /* Redraw the old spot */
-                       lite_spot(oy, ox);
-
-                       /* Redraw the new spot */
-                       lite_spot(py, px);
-
-                       /* Check for new panel (redraw map) */
-                       verify_panel();
-
-                       /* Update stuff */
-                       p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW);
-
-                       /* Update the monsters */
-                       p_ptr->update |= (PU_DISTANCE);
-
-                       /* Window stuff */
-                       p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
-
-                       /* Handle stuff XXX XXX XXX */
-                       handle_stuff();
+                       (void)move_player_effect(y, x, MPE_FORGET_FLOW | MPE_HANDLE_STUFF | MPE_DONT_PICKUP);
                }
                break;
        }
@@ -1555,7 +1496,7 @@ static bool cast_berserk_spell(int spell)
                        m_ptr = &m_list[c_ptr->m_idx];
 
                        /* Hack -- attack monsters */
-                       if (c_ptr->m_idx && (m_ptr->ml || cave_floor_bold(y, x)))
+                       if (c_ptr->m_idx && (m_ptr->ml || cave_have_flag_bold(y, x, FF_PROJECT)))
                                py_attack(y, x, 0);
                }
                break;
@@ -1592,7 +1533,7 @@ static bool cast_ninja_spell(int spell)
        case 1:
                if (plev > 44)
                {
-                       wiz_lite(FALSE, TRUE);
+                       wiz_lite(TRUE);
                }
                detect_monsters_normal(DETECT_RAD_DEFAULT);
                if (plev > 4)
@@ -1608,9 +1549,7 @@ static bool cast_ninja_spell(int spell)
                break;
        case 2:
        {
-               teleport_player(10);
-               if (cave[py][px].info & (CAVE_GLOW | CAVE_MNLT)) set_superstealth(FALSE);
-               else if (p_ptr->cur_lite <= 0) set_superstealth(TRUE);
+               teleport_player(10, 0L);
                break;
        }
        case 3:
@@ -1630,9 +1569,7 @@ static bool cast_ninja_spell(int spell)
        }
        case 4:
        {
-               teleport_player(p_ptr->lev*5);
-               if (cave[py][px].info & (CAVE_GLOW | CAVE_MNLT)) set_superstealth(FALSE);
-               else if (p_ptr->cur_lite <= 0) set_superstealth(TRUE);
+               teleport_player(p_ptr->lev * 5, 0L);
                break;
        }
        case 5:
@@ -1651,9 +1588,7 @@ msg_print("
 #endif
                        else
                        {
-                               teleport_player(30);
-                               if (cave[py][px].info & (CAVE_GLOW | CAVE_MNLT)) set_superstealth(FALSE);
-                               else if (p_ptr->cur_lite <= 0) set_superstealth(TRUE);
+                               teleport_player(30, 0L);
                        }
                }
                else
@@ -1676,23 +1611,16 @@ msg_print("
        }
        case 7:
                return ident_spell(FALSE);
-               break;
        case 8:
-               set_tim_ffall(randint1(20) + 20, FALSE);
+               set_tim_levitation(randint1(20) + 20, FALSE);
                break;
        case 9:
                fire_ball(GF_FIRE, 0, 50+plev, plev/10+2);
-               teleport_player(30);
-               if (cave[py][px].info & (CAVE_GLOW | CAVE_MNLT)) set_superstealth(FALSE);
-               else if (p_ptr->cur_lite <= 0) set_superstealth(TRUE);
+               teleport_player(30, 0L);
                set_oppose_fire(plev, FALSE);
                break;
        case 10:
-               project_length = 5;
-               if (!get_aim_dir(&dir)) return FALSE;
-               project_hook(GF_ATTACK, dir, HISSATSU_NYUSIN, PROJECT_STOP | PROJECT_KILL);
-
-               break;
+               return rush_attack(NULL);
        case 11:
        {
                int i;
@@ -1736,7 +1664,9 @@ msg_print("
                if (!target_set(TARGET_KILL)) return FALSE;
                m_idx = cave[target_row][target_col].m_idx;
                if (!m_idx) break;
+               if (m_idx == p_ptr->riding) break;
                if (!player_has_los_bold(target_row, target_col)) break;
+               if (!projectable(py, px, target_row, target_col)) break;
                m_ptr = &m_list[m_idx];
                monster_desc(m_name, m_ptr, 0);
 #ifdef JP
@@ -1755,8 +1685,7 @@ msg_print("
 
                        if (in_bounds(ny, nx) && cave_empty_bold(ny, nx) &&
                            !(c_ptr->info & CAVE_OBJECT) &&
-                           !(c_ptr->feat >= FEAT_PATTERN_START &&
-                             c_ptr->feat <= FEAT_PATTERN_XTRA2))
+                               !pattern_tile(ny, nx))
                        {
                                ty = ny;
                                tx = nx;
@@ -1765,7 +1694,7 @@ msg_print("
                /* Update the old location */
                cave[target_row][target_col].m_idx = 0;
 
-               /* Update the new location */
+               /* Update the new location */
                cave[ty][tx].m_idx = m_idx;
 
                /* Move the monster */
@@ -1773,7 +1702,7 @@ msg_print("
                m_ptr->fx = tx;
 
                /* Wake the monster up */
-               m_ptr->csleep = 0;
+               (void)set_monster_csleep(m_idx, 0);
 
                /* Update the monster (new location) */
                update_mon(m_idx, TRUE);
@@ -1784,7 +1713,17 @@ msg_print("
                /* Redraw the new grid */
                lite_spot(ty, tx);
 
-               p_ptr->update |= (PU_MON_LITE);
+               if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
+                       p_ptr->update |= (PU_MON_LITE);
+
+               if (m_ptr->ml)
+               {
+                       /* Auto-Recall if possible and visible */
+                       if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
+
+                       /* Track a new monster */
+                       health_track(m_idx);
+               }
 
                break;
        }
@@ -1814,9 +1753,7 @@ msg_print("
                fire_ball(GF_POIS, 0, 75+plev*2/3, plev/5+2);
                fire_ball(GF_OLD_DRAIN, 0, 75+plev*2/3, plev/5+2);
                fire_ball(GF_CONFUSION, 0, 75+plev*2/3, plev/5+2);
-               teleport_player(30);
-               if (cave[py][px].info & (CAVE_GLOW | CAVE_MNLT)) set_superstealth(FALSE);
-               else if (p_ptr->cur_lite <= 0) set_superstealth(TRUE);
+               teleport_player(30, 0L);
                break;
        case 18:
        {
@@ -1828,11 +1765,11 @@ msg_print("
                        int typ = one_in_(2) ? GF_FIRE : one_in_(3) ? GF_NETHER : GF_PLASMA;
                        int attempts = 1000;
 
-                       while(attempts--)
+                       while (attempts--)
                        {
                                scatter(&y, &x, py, px, 4, 0);
 
-                               if ((y != py) || (x != px)) break;
+                               if (!player_bold(y, x)) break;
                        }
                        project(0, 0, y, x, damroll(6 + plev / 8, 10), typ,
                                (PROJECT_BEAM | PROJECT_THRU | PROJECT_GRID | PROJECT_KILL), -1);
@@ -2075,7 +2012,7 @@ msg_format("%s
                                        msg_print("Your mind unleashes its power in an uncontrollable storm!");
 #endif
 
-                                       project(1, 2 + plev / 10, py, px, plev * 2,
+                                       project(PROJECT_WHO_UNCTRL_POWER, 2 + plev / 10, py, px, plev * 2,
                                                GF_MANA, PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID | PROJECT_ITEM, -1);
                                        p_ptr->csp = MAX(0, p_ptr->csp - plev * MAX(1, plev / 10));
                                }
@@ -2092,8 +2029,7 @@ msg_print("
 #else
                                        msg_print("Weird visions seem to dance before your eyes...");
 #endif
-                                       teleport_player(10);
-                                       
+                                       teleport_player(10, TELEPORT_PASSIVE);
                                }
                                else if (b < 96)
                                {
@@ -2114,7 +2050,7 @@ msg_format("%s
                                        msg_print("Your mind unleashes its power in an uncontrollable storm!");
 #endif
 
-                                       project(1, 2 + plev / 10, py, px, plev * 2,
+                                       project(PROJECT_WHO_UNCTRL_POWER, 2 + plev / 10, py, px, plev * 2,
                                                GF_MANA, PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID | PROJECT_ITEM, -1);
                                        p_ptr->csp = MAX(0, p_ptr->csp - plev * MAX(1, plev / 10));
                                }
@@ -2167,7 +2103,7 @@ msg_format("%s
        /* teleport from mirror costs small energy */
        if( on_mirror && p_ptr->pclass == CLASS_MIRROR_MASTER )
        {
-         if( n==2 || n==4 || n==6 || n==15 )energy_use = 50;
+         if( n==3 || n==5 || n==7 || n==16 )energy_use = 50;
        }
 
        if ((use_mind == MIND_BERSERKER) || (use_mind == MIND_NINJUTSU))
@@ -2282,7 +2218,7 @@ void do_cmd_mind_browse(void)
                Term_erase(12, 17, 255);
                Term_erase(12, 16, 255);
 
-               roff_to_buf( mind_tips[use_mind][n],62,temp);
+               roff_to_buf(mind_tips[use_mind][n], 62, temp, sizeof(temp));
                for(j=0, line = 17;temp[j];j+=(1+strlen(&temp[j])))
                {
                        prt(&temp[j], line, 15);
@@ -2300,6 +2236,4 @@ void do_cmd_mind_browse(void)
                  (void)inkey();
                }
        }
-
-       screen_load();
 }