OSDN Git Service

[Refactor] #37353 spells-floor.c/h 追加。 / Add spells-floor.c/h.
[hengband/hengband.git] / src / dungeon.c
index a6c5250..c88b4d2 100644 (file)
@@ -27,6 +27,8 @@
 #include "store.h"
 #include "spells-summon.h"
 #include "spells-object.h"
+#include "spells-status.h"
+#include "spells-floor.h"
 #include "monsterrace-hook.h"
 #include "world.h"
 #include "mutation.h"
 #include "artifact.h"
 #include "avatar.h"
 #include "player-status.h"
+#include "cmd-spell.h"
+#include "realm-hex.h"
+#include "object-hook.h"
+#include "wild.h"
+
 
 static bool load = TRUE; /*!<ロード処理中の分岐フラグ*/
 static int wild_regen = 20; /*!<広域マップ移動時の自然回復処理カウンタ(広域マップ1マス毎に20回処理を基本とする)*/
@@ -536,7 +543,7 @@ static void pattern_teleport(void)
                        min_level = dun_level;
 
                /* Maximum level */
-               if (dungeon_type == DUNGEON_ANGBAND)
+               if (p_ptr->dungeon_idx == DUNGEON_ANGBAND)
                {
                        if (dun_level > 100)
                                max_level = MAX_DEPTH - 1;
@@ -545,8 +552,8 @@ static void pattern_teleport(void)
                }
                else
                {
-                       max_level = d_info[dungeon_type].maxdepth;
-                       min_level = d_info[dungeon_type].mindepth;
+                       max_level = d_info[p_ptr->dungeon_idx].maxdepth;
+                       min_level = d_info[p_ptr->dungeon_idx].mindepth;
                }
 
                /* Prompt */
@@ -590,7 +597,7 @@ static void pattern_teleport(void)
        if (record_stair) do_cmd_write_nikki(NIKKI_PAT_TELE, 0, NULL);
 
        p_ptr->inside_quest = 0;
-       p_ptr->energy_use = 0;
+       free_turn(p_ptr);
 
        /*
         * Clear all saved floors
@@ -610,7 +617,7 @@ static void wreck_the_pattern(void)
 {
        int to_ruin = 0;
        POSITION r_y, r_x;
-       int pattern_type = f_info[cave[p_ptr->y][p_ptr->x].feat].subtype;
+       int pattern_type = f_info[grid_array[p_ptr->y][p_ptr->x].feat].subtype;
 
        if (pattern_type == PATTERN_TILE_WRECKED)
        {
@@ -629,7 +636,7 @@ static void wreck_the_pattern(void)
                scatter(&r_y, &r_x, p_ptr->y, p_ptr->x, 4, 0);
 
                if (pattern_tile(r_y, r_x) &&
-                   (f_info[cave[r_y][r_x].feat].subtype != PATTERN_TILE_WRECKED))
+                   (f_info[grid_array[r_y][r_x].feat].subtype != PATTERN_TILE_WRECKED))
                {
                        cave_set_feat(r_y, r_x, feat_pattern_corrupted);
                }
@@ -654,7 +661,7 @@ static bool pattern_effect(void)
                wreck_the_pattern();
        }
 
-       pattern_type = f_info[cave[p_ptr->y][p_ptr->x].feat].subtype;
+       pattern_type = f_info[grid_array[p_ptr->y][p_ptr->x].feat].subtype;
 
        switch (pattern_type)
        {
@@ -1174,7 +1181,7 @@ static void check_music(void)
 
        if (p_ptr->anti_magic)
        {
-               stop_singing();
+               stop_singing(p_ptr);
                return;
        }
 
@@ -1189,7 +1196,7 @@ static void check_music(void)
 
        if (s64b_cmp(p_ptr->csp, p_ptr->csp_frac, need_mana, need_mana_frac) < 0)
        {
-               stop_singing();
+               stop_singing(p_ptr);
                return;
        }
        else
@@ -1365,7 +1372,7 @@ static void process_world_aux_digestion(void)
  */
 static void process_world_aux_hp_and_sp(void)
 {
-       feature_type *f_ptr = &f_info[cave[p_ptr->y][p_ptr->x].feat];
+       feature_type *f_ptr = &f_info[grid_array[p_ptr->y][p_ptr->x].feat];
        bool cave_no_regen = FALSE;
        int upkeep_factor = 0;
 
@@ -1432,7 +1439,7 @@ static void process_world_aux_hp_and_sp(void)
        {
                if (!dun_level && !p_ptr->resist_lite && !IS_INVULN() && is_daytime())
                {
-                       if ((cave[p_ptr->y][p_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
+                       if ((grid_array[p_ptr->y][p_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
                        {
                                msg_print(_("日光があなたのアンデッドの肉体を焼き焦がした!", "The sun's rays scorch your undead flesh!"));
                                take_hit(DAMAGE_NOESCAPE, 1, _("日光", "sunlight"), -1);
@@ -1487,11 +1494,11 @@ static void process_world_aux_hp_and_sp(void)
                        {
                                msg_print(_("熱で火傷した!", "The heat burns you!"));
                                take_hit(DAMAGE_NOESCAPE, damage, format(_("%sの上に浮遊したダメージ", "flying over %s"), 
-                                                               f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name), -1);
+                                                               f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name), -1);
                        }
                        else
                        {
-                               concptr name = f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name;
+                               concptr name = f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name;
                                msg_format(_("%sで火傷した!", "The %s burns you!"), name);
                                take_hit(DAMAGE_NOESCAPE, damage, name, -1);
                        }
@@ -1525,11 +1532,11 @@ static void process_world_aux_hp_and_sp(void)
                        {
                                msg_print(_("冷気に覆われた!", "The cold engulfs you!"));
                                take_hit(DAMAGE_NOESCAPE, damage, format(_("%sの上に浮遊したダメージ", "flying over %s"),
-                                       f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name), -1);
+                                       f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name), -1);
                        }
                        else
                        {
-                               concptr name = f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name;
+                               concptr name = f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name;
                                msg_format(_("%sに凍えた!", "The %s frostbites you!"), name);
                                take_hit(DAMAGE_NOESCAPE, damage, name, -1);
                        }
@@ -1563,11 +1570,11 @@ static void process_world_aux_hp_and_sp(void)
                        {
                                msg_print(_("電撃を受けた!", "The electric shocks you!"));
                                take_hit(DAMAGE_NOESCAPE, damage, format(_("%sの上に浮遊したダメージ", "flying over %s"),
-                                       f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name), -1);
+                                       f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name), -1);
                        }
                        else
                        {
-                               concptr name = f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name;
+                               concptr name = f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name;
                                msg_format(_("%sに感電した!", "The %s shocks you!"), name);
                                take_hit(DAMAGE_NOESCAPE, damage, name, -1);
                        }
@@ -1601,11 +1608,11 @@ static void process_world_aux_hp_and_sp(void)
                        {
                                msg_print(_("酸が飛び散った!", "The acid melt you!"));
                                take_hit(DAMAGE_NOESCAPE, damage, format(_("%sの上に浮遊したダメージ", "flying over %s"),
-                                       f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name), -1);
+                                       f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name), -1);
                        }
                        else
                        {
-                               concptr name = f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name;
+                               concptr name = f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name;
                                msg_format(_("%sに溶かされた!", "The %s melts you!"), name);
                                take_hit(DAMAGE_NOESCAPE, damage, name, -1);
                        }
@@ -1639,12 +1646,12 @@ static void process_world_aux_hp_and_sp(void)
                        {
                                msg_print(_("毒気を吸い込んだ!", "The gas poisons you!"));
                                take_hit(DAMAGE_NOESCAPE, damage, format(_("%sの上に浮遊したダメージ", "flying over %s"),
-                                       f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name), -1);
+                                       f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name), -1);
                                if (p_ptr->resist_pois) (void)set_poisoned(p_ptr->poisoned + 1);
                        }
                        else
                        {
-                               concptr name = f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name;
+                               concptr name = f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name;
                                msg_format(_("%sに毒された!", "The %s poisons you!"), name);
                                take_hit(DAMAGE_NOESCAPE, damage, name, -1);
                                if (p_ptr->resist_pois) (void)set_poisoned(p_ptr->poisoned + 3);
@@ -2361,7 +2368,7 @@ static void process_world_aux_mutation(void)
                msg_print(NULL);
 
                /* Absorb light from the current possition */
-               if ((cave[p_ptr->y][p_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
+               if ((grid_array[p_ptr->y][p_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
                {
                        hp_player(10);
                }
@@ -2504,7 +2511,7 @@ static void process_world_aux_mutation(void)
                msg_print(_("胃が痙攣し、食事を失った!", "Your stomach roils, and you lose your lunch!"));
                msg_print(NULL);
                set_food(PY_FOOD_WEAK);
-               if (music_singing_any()) stop_singing();
+               if (music_singing_any()) stop_singing(p_ptr);
                if (hex_spelling_any()) stop_hex_spell_all();
        }
 
@@ -2998,12 +3005,12 @@ static void process_world_aux_movement(void)
                        {
                                msg_print(_("上に引っ張りあげられる感じがする!", "You feel yourself yanked upwards!"));
 
-                               if (dungeon_type) p_ptr->recall_dungeon = dungeon_type;
+                               if (p_ptr->dungeon_idx) p_ptr->recall_dungeon = p_ptr->dungeon_idx;
                                if (record_stair)
                                        do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
 
                                dun_level = 0;
-                               dungeon_type = 0;
+                               p_ptr->dungeon_idx = 0;
 
                                leave_quest_check();
                                leave_tower_check();
@@ -3016,17 +3023,17 @@ static void process_world_aux_movement(void)
                        {
                                msg_print(_("下に引きずり降ろされる感じがする!", "You feel yourself yanked downwards!"));
 
-                               dungeon_type = p_ptr->recall_dungeon;
+                               p_ptr->dungeon_idx = p_ptr->recall_dungeon;
 
                                if (record_stair)
                                        do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
 
                                /* New depth */
-                               dun_level = max_dlv[dungeon_type];
+                               dun_level = max_dlv[p_ptr->dungeon_idx];
                                if (dun_level < 1) dun_level = 1;
 
                                /* Nightmare mode makes recall more dangerous */
-                               if (ironman_nightmare && !randint0(666) && (dungeon_type == DUNGEON_ANGBAND))
+                               if (ironman_nightmare && !randint0(666) && (p_ptr->dungeon_idx == DUNGEON_ANGBAND))
                                {
                                        if (dun_level < 50)
                                        {
@@ -3038,7 +3045,7 @@ static void process_world_aux_movement(void)
                                        }
                                        else if (dun_level > 100)
                                        {
-                                               dun_level = d_info[dungeon_type].maxdepth - 1;
+                                               dun_level = d_info[p_ptr->dungeon_idx].maxdepth - 1;
                                        }
                                }
 
@@ -3064,7 +3071,7 @@ static void process_world_aux_movement(void)
                                /* Leaving */
                                p_ptr->leaving = TRUE;
 
-                               if (dungeon_type == DUNGEON_ANGBAND)
+                               if (p_ptr->dungeon_idx == DUNGEON_ANGBAND)
                                {
                                        int i;
 
@@ -3156,7 +3163,7 @@ static int get_monster_crowd_number(MONSTER_IDX m_idx)
                if (!in_bounds(ay, ax)) continue;
 
                /* Count number of monsters */
-               if (cave[ay][ax].m_idx > 0) count++;
+               if (grid_array[ay][ax].m_idx > 0) count++;
        }
 
        return count;
@@ -3381,10 +3388,10 @@ static void process_world(void)
        update_dungeon_feeling();
 
        /* 帰還無しモード時のレベルテレポバグ対策 / Fix for level teleport bugs on ironman_downward.*/
-       if (ironman_downward && (dungeon_type != DUNGEON_ANGBAND && dungeon_type != 0))
+       if (ironman_downward && (p_ptr->dungeon_idx != DUNGEON_ANGBAND && p_ptr->dungeon_idx != 0))
        {
                dun_level = 0;
-               dungeon_type = 0;
+               p_ptr->dungeon_idx = 0;
                prepare_change_floor_mode(CFM_FIRST_FLOOR | CFM_RAND_PLACE);
                p_ptr->inside_arena = FALSE;
                p_ptr->wild_mode = FALSE;
@@ -3402,12 +3409,12 @@ static void process_world(void)
                for (i2 = 0; i2 < cur_wid; ++i2)
                        for (j2 = 0; j2 < cur_hgt; j2++)
                        {
-                               cave_type *c_ptr = &cave[j2][i2];
+                               grid_type *g_ptr = &grid_array[j2][i2];
 
-                               if ((c_ptr->m_idx > 0) && (c_ptr->m_idx != p_ptr->riding))
+                               if ((g_ptr->m_idx > 0) && (g_ptr->m_idx != p_ptr->riding))
                                {
                                        number_mon++;
-                                       win_m_idx = c_ptr->m_idx;
+                                       win_m_idx = g_ptr->m_idx;
                                }
                        }
 
@@ -3573,7 +3580,7 @@ static void process_world(void)
        /*** Process the monsters ***/
 
        /* Check for creature generation. */
-       if (one_in_(d_info[dungeon_type].max_m_alloc_chance) &&
+       if (one_in_(d_info[p_ptr->dungeon_idx].max_m_alloc_chance) &&
            !p_ptr->inside_arena && !p_ptr->inside_quest && !p_ptr->inside_battle)
        {
                /* Make a new monster */
@@ -3655,7 +3662,7 @@ static void process_world(void)
                                change_wild_mode();
 
                                /* Give first move to monsters */
-                               p_ptr->energy_use = 100;
+                               take_turn(p_ptr, 100);
 
                                /* HACk -- set the encouter flag for the wilderness generation */
                                generate_encounter = TRUE;
@@ -4195,7 +4202,7 @@ static void process_command(void)
                                {
                                        msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
                                }
-                               else if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
+                               else if (dun_level && (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
                                {
                                        msg_print(_("ダンジョンが魔法を吸収した!", "The dungeon absorbs all attempted magic!"));
                                        msg_print(NULL);
@@ -4217,12 +4224,12 @@ static void process_command(void)
                                                which_power = _("祈り", "prayer");
 
                                        msg_format(_("反魔法バリアが%sを邪魔した!", "An anti-magic shell disrupts your %s!"), which_power);
-                                       p_ptr->energy_use = 0;
+                                       free_turn(p_ptr);
                                }
                                else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
                                {
                                        msg_format(_("狂戦士化していて頭が回らない!", "You cannot think directly!"));
-                                       p_ptr->energy_use = 0;
+                                       free_turn(p_ptr);
                                }
                                else
                                {
@@ -4811,7 +4818,7 @@ static void process_player(void)
                                if (place_monster_aux(0, y, x, r_idx, PM_NO_KAGE))
                                {
                                        GAME_TEXT m_name[MAX_NLEN];
-                                       monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
+                                       monster_desc(m_name, &m_list[grid_array[y][x].m_idx], 0);
                                        msg_format(_("%sが釣れた!", "You have a good catch!"), m_name);
                                        success = TRUE;
                                }
@@ -4978,7 +4985,7 @@ static void process_player(void)
                if (!command_new) command_see = FALSE;
 
                /* Assume free turn */
-               p_ptr->energy_use = 0;
+               free_turn(p_ptr);
 
                if (p_ptr->inside_battle)
                {
@@ -4994,7 +5001,7 @@ static void process_player(void)
                /* Paralyzed or Knocked Out */
                else if (p_ptr->paralyzed || (p_ptr->stun >= 100))
                {
-                       p_ptr->energy_use = 100;
+                       take_turn(p_ptr, 100);
                }
 
                /* Resting */
@@ -5010,13 +5017,13 @@ static void process_player(void)
                                p_ptr->redraw |= (PR_STATE);
                        }
 
-                       p_ptr->energy_use = 100;
+                       take_turn(p_ptr, 100);
                }
 
                /* Fishing */
                else if (p_ptr->action == ACTION_FISH)
                {
-                       p_ptr->energy_use = 100;
+                       take_turn(p_ptr, 100);
                }
 
                /* Running */
@@ -5080,7 +5087,7 @@ static void process_player(void)
                if (p_ptr->energy_use)
                {
                        /* Use some energy */
-                       if (world_player || p_ptr->energy_use > 400)
+                       if (p_ptr->timewalk || p_ptr->energy_use > 400)
                        {
                                /* The Randomness is irrelevant */
                                p_ptr->energy_need += p_ptr->energy_use * TURNS_PER_TICK / 10;
@@ -5208,7 +5215,7 @@ static void process_player(void)
                                p_ptr->redraw |= (PR_STATE);
                        }
 
-                       if (world_player && (p_ptr->energy_need > - 1000))
+                       if (p_ptr->timewalk && (p_ptr->energy_need > - 1000))
                        {
 
                                p_ptr->redraw |= (PR_MAP);
@@ -5218,7 +5225,7 @@ static void process_player(void)
 
                                msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
                                msg_print(NULL);
-                               world_player = FALSE;
+                               p_ptr->timewalk = FALSE;
                                p_ptr->energy_need = ENERGY_NEED();
 
                                /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
@@ -5229,7 +5236,7 @@ static void process_player(void)
                /* Hack -- notice death */
                if (!p_ptr->playing || p_ptr->is_dead)
                {
-                       world_player = FALSE;
+                       p_ptr->timewalk = FALSE;
                        break;
                }
 
@@ -5318,9 +5325,9 @@ static void dungeon(bool load_game)
 
 
        /* Track maximum dungeon level (if not in quest -KMW-) */
-       if ((max_dlv[dungeon_type] < dun_level) && !p_ptr->inside_quest)
+       if ((max_dlv[p_ptr->dungeon_idx] < dun_level) && !p_ptr->inside_quest)
        {
-               max_dlv[dungeon_type] = dun_level;
+               max_dlv[p_ptr->dungeon_idx] = dun_level;
                if (record_maxdepth) do_cmd_write_nikki(NIKKI_MAXDEAPTH, dun_level, NULL);
        }
 
@@ -5387,22 +5394,22 @@ static void dungeon(bool load_game)
        if (!p_ptr->playing || p_ptr->is_dead) return;
 
        /* Print quest message if appropriate */
-       if (!p_ptr->inside_quest && (dungeon_type == DUNGEON_ANGBAND))
+       if (!p_ptr->inside_quest && (p_ptr->dungeon_idx == DUNGEON_ANGBAND))
        {
                quest_discovery(random_quest_number(dun_level));
                p_ptr->inside_quest = random_quest_number(dun_level);
        }
-       if ((dun_level == d_info[dungeon_type].maxdepth) && d_info[dungeon_type].final_guardian)
+       if ((dun_level == d_info[p_ptr->dungeon_idx].maxdepth) && d_info[p_ptr->dungeon_idx].final_guardian)
        {
-               if (r_info[d_info[dungeon_type].final_guardian].max_num)
+               if (r_info[d_info[p_ptr->dungeon_idx].final_guardian].max_num)
 #ifdef JP
                        msg_format("この階には%sの主である%sが棲んでいる。",
-                                  d_name+d_info[dungeon_type].name, 
-                                  r_name+r_info[d_info[dungeon_type].final_guardian].name);
+                                  d_name+d_info[p_ptr->dungeon_idx].name, 
+                                  r_name+r_info[d_info[p_ptr->dungeon_idx].final_guardian].name);
 #else
                        msg_format("%^s lives in this level as the keeper of %s.",
-                                          r_name+r_info[d_info[dungeon_type].final_guardian].name, 
-                                          d_name+d_info[dungeon_type].name);
+                                          r_name+r_info[d_info[p_ptr->dungeon_idx].final_guardian].name, 
+                                          d_name+d_info[p_ptr->dungeon_idx].name);
 #endif
        }
 
@@ -5963,7 +5970,7 @@ void play_game(bool new_game)
                s_info[p_ptr->pclass].w_max[TV_HAFTED-TV_WEAPON_BEGIN][SV_WHIP] = WEAPON_EXP_MASTER;
 
        /* Fill the arrays of floors and walls in the good proportions */
-       set_floor_and_wall(dungeon_type);
+       set_floor_and_wall(p_ptr->dungeon_idx);
 
        /* Flavor the objects */
        flavor_init();
@@ -6136,7 +6143,7 @@ void play_game(bool new_game)
                /* Handle "quit and save" */
                if (!p_ptr->playing && !p_ptr->is_dead) break;
 
-               /* Erase the old cave */
+               /* Erase the old grid_array */
                wipe_o_list();
                if (!p_ptr->is_dead) wipe_m_list();
 
@@ -6239,7 +6246,7 @@ void prevent_turn_overflow(void)
        {
                for (j = 0; j < MAX_STORES; j++)
                {
-                       store_type *st_ptr = &town[i].store[j];
+                       store_type *st_ptr = &town_info[i].store[j];
 
                        if (st_ptr->last_visit > -10L * TURNS_PER_TICK * STORE_TICKS)
                        {