OSDN Git Service

[Refactor] monster_idxと0との比較を関数化する
authordis- <dis.rogue@gmail.com>
Sat, 3 Feb 2024 14:47:21 +0000 (23:47 +0900)
committerdis- <dis.rogue@gmail.com>
Sun, 3 Mar 2024 05:03:45 +0000 (14:03 +0900)
単純な処理ではあるが、playerのindexを示す0がマジックナンバーになっていて可読性を損っている。
関数化して一見して処理が分かるようにする。

73 files changed:
src/action/movement-execution.cpp
src/action/mutation-execution.cpp
src/action/run-execution.cpp
src/action/travel-execution.cpp
src/blue-magic/blue-magic-caster.cpp
src/cmd-action/cmd-mane.cpp
src/cmd-action/cmd-open-close.cpp
src/cmd-action/cmd-others.cpp
src/cmd-action/cmd-pet.cpp
src/cmd-action/cmd-tunnel.cpp
src/combat/shoot.cpp
src/effect/effect-feature.cpp
src/effect/effect-item.cpp
src/effect/effect-monster-curse.cpp
src/effect/effect-monster-oldies.cpp
src/effect/effect-monster-spirit.cpp
src/effect/effect-monster-switcher.cpp
src/effect/effect-monster-util.cpp
src/effect/effect-monster.cpp
src/effect/effect-player-spirit.cpp
src/effect/effect-player.cpp
src/effect/effect-processor.cpp
src/floor/floor-streams.cpp
src/floor/object-allocator.cpp
src/floor/wild.cpp
src/grid/feature.cpp
src/grid/grid.cpp
src/io/cursor.cpp
src/mind/mind-berserker.cpp
src/mind/mind-elementalist.cpp
src/mind/mind-force-trainer.cpp
src/mind/mind-ninja.cpp
src/mind/mind-warrior.cpp
src/mind/monk-attack.cpp
src/monster-attack/monster-attack-processor.cpp
src/monster-floor/monster-move.cpp
src/monster-floor/monster-remover.cpp
src/monster-floor/monster-summon.cpp
src/monster-floor/one-monster-placer.cpp
src/monster/monster-info.cpp
src/monster/monster-list.cpp
src/monster/monster-processor.cpp
src/monster/monster-update.cpp
src/monster/monster-util.cpp
src/monster/monster-util.h
src/mspell/mspell-checker.cpp
src/mspell/mspell-judgement.cpp
src/mutation/mutation-techniques.cpp
src/object-use/throw-execution.cpp
src/object/warning.cpp
src/pet/pet-fall-off.cpp
src/player-attack/player-attack.cpp
src/player/player-status.cpp
src/racial/racial-vampire.cpp
src/realm/realm-hex.cpp
src/realm/realm-hissatsu.cpp
src/room/vault-builder.cpp
src/spell-class/spells-mirror-master.cpp
src/spell-kind/earthquake.cpp
src/spell-kind/spells-floor.cpp
src/spell-kind/spells-lite.cpp
src/spell-kind/spells-teleport.cpp
src/spell-realm/spells-chaos.cpp
src/spell-realm/spells-crusade.cpp
src/spell/spells-status.cpp
src/spell/spells-summon.cpp
src/target/projection-path-calculator.cpp
src/target/target-describer.cpp
src/target/target-preparation.cpp
src/util/sort.cpp
src/view/display-map.cpp
src/window/display-sub-windows.cpp
src/world/world-turn-processor.cpp

index 3cd219d..6b40e73 100644 (file)
@@ -26,6 +26,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "mutation/mutation-flag-types.h"
 #include "object/warning.h"
 #include "player-base/player-class.h"
@@ -165,7 +166,7 @@ void exe_movement(PlayerType *player_ptr, DIRECTION dir, bool do_pickup, bool br
     std::string m_name;
     bool can_move = true;
     bool do_past = false;
-    if (grid.m_idx && (m_ptr->ml || p_can_enter || p_can_kill_walls)) {
+    if (is_monster(grid.m_idx) && (m_ptr->ml || p_can_enter || p_can_kill_walls)) {
         auto *r_ptr = &m_ptr->get_monrace();
         auto effects = player_ptr->effects();
         auto is_stunned = effects->stun()->is_stunned();
index ead0e92..ec33cb4 100644 (file)
@@ -23,6 +23,7 @@
 #include "monster/monster-description-types.h"
 #include "monster/monster-flag-types.h"
 #include "monster/monster-info.h"
+#include "monster/monster-util.h"
 #include "mutation/mutation-flag-types.h"
 #include "mutation/mutation-techniques.h"
 #include "object-enchant/item-feeling.h"
@@ -247,7 +248,7 @@ bool exe_mutation_power(PlayerType *player_ptr, PlayerMutationType power)
         const auto y = player_ptr->y + ddy[dir];
         const auto x = player_ptr->x + ddx[dir];
         const auto &grid = floor.grid_array[y][x];
-        if (!grid.m_idx) {
+        if (!is_monster(grid.m_idx)) {
             msg_print(_("邪悪な存在を感じとれません!", "You sense no evil there!"));
             return true;
         }
@@ -287,7 +288,7 @@ bool exe_mutation_power(PlayerType *player_ptr, PlayerMutationType power)
         const auto y = player_ptr->y + ddy[dir];
         const auto x = player_ptr->x + ddx[dir];
         auto &grid = floor.grid_array[y][x];
-        if (!grid.m_idx) {
+        if (!is_monster(grid.m_idx)) {
             msg_print(_("あなたは何もない場所で手を振った。", "You wave your hands in the air."));
             return true;
         }
index ac8a6cc..1cdd49a 100644 (file)
@@ -13,6 +13,7 @@
 #include "grid/grid.h"
 #include "main/sound-definitions-table.h"
 #include "main/sound-of-music.h"
+#include "monster/monster-util.h"
 #include "object/object-mark-types.h"
 #include "player-status/player-energy.h"
 #include "player/player-status-flags.h"
@@ -226,7 +227,7 @@ static bool run_test(PlayerType *player_ptr)
         int new_dir = cycle[chome[prev_dir] + i];
         const Pos2D pos(player_ptr->y + ddy[new_dir], player_ptr->x + ddx[new_dir]);
         const auto &grid = floor.get_grid(pos);
-        if (grid.m_idx) {
+        if (is_monster(grid.m_idx)) {
             const auto &monster = floor.m_list[grid.m_idx];
             if (monster.ml) {
                 return true;
index c785ff6..28f681c 100644 (file)
@@ -13,6 +13,7 @@
 #include "game-option/special-options.h"
 #include "grid/feature.h"
 #include "grid/grid.h"
+#include "monster/monster-util.h"
 #include "player-status/player-energy.h"
 #include "player/player-move.h"
 #include "system/floor-type-definition.h"
@@ -61,7 +62,7 @@ static DIRECTION travel_test(PlayerType *player_ptr, DIRECTION prev_dir)
         POSITION row = player_ptr->y + ddy[dir];
         POSITION col = player_ptr->x + ddx[dir];
         g_ptr = &floor_ptr->grid_array[row][col];
-        if (g_ptr->m_idx) {
+        if (is_monster(g_ptr->m_idx)) {
             auto *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
             if (m_ptr->ml) {
                 return 0;
index 52b7d84..aeb1d16 100644 (file)
@@ -18,6 +18,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-info.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "mspell/mspell-damage-calculator.h"
 #include "spell-kind/spells-launcher.h"
 #include "spell-kind/spells-lite.h"
@@ -99,7 +100,7 @@ static std::optional<std::string> exe_blue_teleport_back(PlayerType *player_ptr)
     const auto &floor = *player_ptr->current_floor_ptr;
     const Pos2D pos(target_row, target_col);
     const auto &grid = floor.get_grid(pos);
-    if ((grid.m_idx == 0) || !grid.has_los() || !projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) {
+    if (!is_monster(grid.m_idx) || !grid.has_los() || !projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) {
         return std::nullopt;
     }
 
index 10d0f6c..6d77417 100644 (file)
@@ -34,6 +34,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-processor.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "mspell/monster-power-table.h"
 #include "player-base/player-class.h"
 #include "player-info/mane-data-type.h"
@@ -960,7 +961,7 @@ static bool use_mane(PlayerType *player_ptr, MonsterAbilityType spell)
         const auto &floor = *player_ptr->current_floor_ptr;
         const Pos2D pos(target_row, target_col);
         const auto &grid_target = floor.get_grid(pos);
-        auto should_teleport = grid_target.m_idx == 0;
+        auto should_teleport = !is_monster(grid_target.m_idx);
         should_teleport &= grid_target.has_los();
         should_teleport &= projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col);
         if (!should_teleport) {
index f359ec5..a15a588 100644 (file)
@@ -11,6 +11,7 @@
 #include "inventory/inventory-object.h"
 #include "inventory/inventory-slot-types.h"
 #include "io/input-key-requester.h"
+#include "monster/monster-util.h"
 #include "object/tval-types.h"
 #include "player-base/player-class.h"
 #include "player-info/samurai-data-type.h"
@@ -130,7 +131,7 @@ void do_cmd_open(PlayerType *player_ptr)
         const auto o_idx = chest_check(player_ptr->current_floor_ptr, pos, false);
         if (grid.get_terrain_mimic().flags.has_not(TerrainCharacteristics::OPEN) && !o_idx) {
             msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
-        } else if (grid.m_idx && player_ptr->riding != grid.m_idx) {
+        } else if (is_monster(grid.m_idx) && player_ptr->riding != grid.m_idx) {
             PlayerEnergy(player_ptr).set_player_turn_energy(100);
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
             do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
@@ -179,7 +180,7 @@ void do_cmd_close(PlayerType *player_ptr)
         const auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
         if (grid.get_terrain_mimic().flags.has_not(TerrainCharacteristics::CLOSE)) {
             msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
-        } else if (grid.m_idx) {
+        } else if (is_monster(grid.m_idx)) {
             PlayerEnergy(player_ptr).set_player_turn_energy(100);
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
             do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
@@ -231,7 +232,7 @@ void do_cmd_disarm(PlayerType *player_ptr)
         const auto o_idx = chest_check(player_ptr->current_floor_ptr, pos, true);
         if (!is_trap(player_ptr, feat) && !o_idx) {
             msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
-        } else if (grid.m_idx && player_ptr->riding != grid.m_idx) {
+        } else if (is_monster(grid.m_idx) && player_ptr->riding != grid.m_idx) {
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
             do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
         } else if (o_idx) {
@@ -284,7 +285,7 @@ void do_cmd_bash(PlayerType *player_ptr)
         const Grid &grid = player_ptr->current_floor_ptr->get_grid(pos);
         if (grid.get_terrain_mimic().flags.has_not(TerrainCharacteristics::BASH)) {
             msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
-        } else if (grid.m_idx) {
+        } else if (is_monster(grid.m_idx)) {
             PlayerEnergy(player_ptr).set_player_turn_energy(100);
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
             do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
@@ -355,7 +356,7 @@ void do_cmd_spike(PlayerType *player_ptr)
         msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
     } else if (!get_spike(player_ptr, &i_idx)) {
         msg_print(_("くさびを持っていない!", "You have no spikes!"));
-    } else if (grid.m_idx) {
+    } else if (is_monster(grid.m_idx)) {
         PlayerEnergy(player_ptr).set_player_turn_energy(100);
         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
         do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
index b856e5b..06397f9 100644 (file)
@@ -23,6 +23,7 @@
 #include "io/write-diary.h"
 #include "main/music-definitions-table.h"
 #include "main/sound-of-music.h"
+#include "monster/monster-util.h"
 #include "player-base/player-class.h"
 #include "player-info/samurai-data-type.h"
 #include "player-status/player-energy.h"
@@ -71,7 +72,7 @@ static bool exe_alter(PlayerType *player_ptr)
     const auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
     const auto &terrain = grid.get_terrain_mimic();
     PlayerEnergy(player_ptr).set_player_turn_energy(100);
-    if (grid.m_idx) {
+    if (is_monster(grid.m_idx)) {
         do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
         return false;
     }
index 6df2010..0806dc3 100644 (file)
@@ -28,6 +28,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "monster/smart-learn-types.h"
 #include "object-hook/hook-weapon.h"
 #include "pet/pet-util.h"
@@ -218,7 +219,7 @@ bool do_cmd_riding(PlayerType *player_ptr, bool force)
             return false;
         }
 
-        if (grid.m_idx) {
+        if (is_monster(grid.m_idx)) {
             PlayerEnergy(player_ptr).set_player_turn_energy(100);
 
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
@@ -237,7 +238,7 @@ bool do_cmd_riding(PlayerType *player_ptr, bool force)
 
         const auto *m_ptr = &player_ptr->current_floor_ptr->m_list[grid.m_idx];
 
-        if (!grid.m_idx || !m_ptr->ml) {
+        if (!is_monster(grid.m_idx) || !m_ptr->ml) {
             msg_print(_("その場所にはモンスターはいません。", "There is no monster here."));
             return false;
         }
@@ -326,7 +327,7 @@ static void do_name_pet(PlayerType *player_ptr)
     target_pet = old_target_pet;
     auto &floor = *player_ptr->current_floor_ptr;
     const auto &grid = floor.grid_array[target_row][target_col];
-    if (grid.m_idx == 0) {
+    if (!is_monster(grid.m_idx)) {
         return;
     }
 
@@ -703,7 +704,7 @@ void do_cmd_pet(PlayerType *player_ptr)
             player_ptr->pet_t_m_idx = 0;
         } else {
             auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[target_row][target_col];
-            if (g_ptr->m_idx && (player_ptr->current_floor_ptr->m_list[g_ptr->m_idx].ml)) {
+            if (is_monster(g_ptr->m_idx) && (player_ptr->current_floor_ptr->m_list[g_ptr->m_idx].ml)) {
                 player_ptr->pet_t_m_idx = player_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx;
                 player_ptr->pet_follow_distance = PET_DESTROY_DIST;
             } else {
index 98c0246..9f42b58 100644 (file)
@@ -5,6 +5,7 @@
 #include "floor/geometry.h"
 #include "grid/grid.h"
 #include "io/input-key-requester.h"
+#include "monster/monster-util.h"
 #include "player-base/player-class.h"
 #include "player-info/samurai-data-type.h"
 #include "player-status/player-energy.h"
@@ -56,7 +57,7 @@ void do_cmd_tunnel(PlayerType *player_ptr)
         msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
     } else if (terrain_mimic.flags.has_not(TerrainCharacteristics::TUNNEL)) {
         msg_print(_("そこは掘れない。", "You can't tunnel through that."));
-    } else if (grid.m_idx) {
+    } else if (is_monster(grid.m_idx)) {
         PlayerEnergy(player_ptr).set_player_turn_energy(100);
         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
         do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
index e43032b..322160c 100644 (file)
@@ -38,6 +38,7 @@
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "object/object-broken.h"
 #include "object/object-info.h"
 #include "object/object-mark-types.h"
@@ -632,7 +633,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX i_idx, ItemEntity *j_ptr, SP
             if (snipe_type == SP_KILL_WALL) {
                 g_ptr = &floor_ptr->grid_array[ny][nx];
 
-                if (g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK) && !g_ptr->m_idx) {
+                if (g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK) && !is_monster(g_ptr->m_idx)) {
                     if (any_bits(g_ptr->info, (CAVE_MARK))) {
                         msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
                     }
@@ -655,7 +656,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX i_idx, ItemEntity *j_ptr, SP
             }
 
             /* Stopped by walls/doors */
-            if (!cave_has_flag_bold(floor_ptr, ny, nx, TerrainCharacteristics::PROJECT) && !floor_ptr->grid_array[ny][nx].m_idx) {
+            if (!cave_has_flag_bold(floor_ptr, ny, nx, TerrainCharacteristics::PROJECT) && !is_monster(floor_ptr->grid_array[ny][nx].m_idx)) {
                 break;
             }
 
@@ -714,7 +715,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX i_idx, ItemEntity *j_ptr, SP
             y = ny;
 
             /* Monster here, Try to hit it */
-            if (floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(floor_ptr->grid_array[y][x].m_idx)) {
                 sound(SOUND_SHOOT_HIT);
                 Grid *c_mon_ptr = &floor_ptr->grid_array[y][x];
 
index eac6133..884bea7 100644 (file)
@@ -12,6 +12,7 @@
 #include "mind/mind-elementalist.h"
 #include "mind/mind-ninja.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "player/special-defense-types.h"
 #include "room/door-definition.h"
 #include "spell-class/spells-mirror-master.h"
@@ -77,7 +78,7 @@ bool affect_feature(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POS
     auto obvious = false;
     auto known = grid.has_los();
 
-    src_idx = src_idx ? src_idx : 0;
+    src_idx = is_monster(src_idx) ? src_idx : 0;
     dam = (dam + r) / (r + 1);
 
     if (terrain.flags.has(TerrainCharacteristics::TREE)) {
@@ -354,7 +355,7 @@ bool affect_feature(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POS
         if (player_can_see_bold(player_ptr, y, x)) {
             obvious = true;
         }
-        if (grid.m_idx) {
+        if (is_monster(grid.m_idx)) {
             update_monster(player_ptr, grid.m_idx, false);
         }
 
@@ -407,7 +408,7 @@ bool affect_feature(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POS
         if (player_can_see_bold(player_ptr, y, x)) {
             obvious = true;
         }
-        if (grid.m_idx) {
+        if (is_monster(grid.m_idx)) {
             update_monster(player_ptr, grid.m_idx, false);
         }
 
index 0cbef02..8a90d2c 100644 (file)
@@ -7,6 +7,7 @@
 #include "monster-floor/monster-summon.h"
 #include "monster-floor/place-monster-types.h"
 #include "monster/monster-info.h"
+#include "monster/monster-util.h"
 #include "object-enchant/tr-types.h"
 #include "object-hook/hook-expendable.h"
 #include "object/object-broken.h"
@@ -42,7 +43,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI
 
     auto is_item_affected = false;
     const auto known = grid.has_los();
-    src_idx = src_idx ? src_idx : 0;
+    src_idx = is_monster(src_idx) ? src_idx : 0;
     dam = (dam + r) / (r + 1);
     std::set<OBJECT_IDX> processed_list;
     for (auto it = grid.o_idx_list.begin(); it != grid.o_idx_list.end();) {
@@ -227,7 +228,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI
             }
 
             BIT_FLAGS mode = 0L;
-            if (!src_idx || player_ptr->current_floor_ptr->m_list[src_idx].is_pet()) {
+            if (is_monster(src_idx) || player_ptr->current_floor_ptr->m_list[src_idx].is_pet()) {
                 mode |= PM_FORCE_PET;
             }
 
index 9d6f375..dd0e275 100644 (file)
@@ -2,6 +2,7 @@
 #include "effect/effect-monster-util.h"
 #include "monster-race/monster-race.h"
 #include "monster-race/race-indice-types.h"
+#include "monster/monster-util.h"
 #include "system/monster-entity.h"
 #include "system/monster-race-info.h"
 #include "view/display-messages.h"
@@ -11,7 +12,7 @@ ProcessResult effect_monster_curse_1(EffectMonster *em_ptr)
     if (em_ptr->seen) {
         em_ptr->obvious = true;
     }
-    if (!em_ptr->src_idx) {
+    if (is_player(em_ptr->src_idx)) {
         msg_format(_("%sを指差して呪いをかけた。", "You point at %s and curse."), em_ptr->m_name);
     }
     if (randint0(100 + (em_ptr->caster_lev / 2)) < (em_ptr->r_ptr->level + 35)) {
@@ -27,7 +28,7 @@ ProcessResult effect_monster_curse_2(EffectMonster *em_ptr)
     if (em_ptr->seen) {
         em_ptr->obvious = true;
     }
-    if (!em_ptr->src_idx) {
+    if (is_player(em_ptr->src_idx)) {
         msg_format(_("%sを指差して恐ろしげに呪いをかけた。", "You point at %s and curse horribly."), em_ptr->m_name);
     }
 
@@ -44,7 +45,7 @@ ProcessResult effect_monster_curse_3(EffectMonster *em_ptr)
     if (em_ptr->seen) {
         em_ptr->obvious = true;
     }
-    if (!em_ptr->src_idx) {
+    if (is_player(em_ptr->src_idx)) {
         msg_format(_("%sを指差し、恐ろしげに呪文を唱えた!", "You point at %s, incanting terribly!"), em_ptr->m_name);
     }
 
@@ -61,13 +62,13 @@ ProcessResult effect_monster_curse_4(EffectMonster *em_ptr)
     if (em_ptr->seen) {
         em_ptr->obvious = true;
     }
-    if (!em_ptr->src_idx) {
+    if (is_player(em_ptr->src_idx)) {
         msg_format(_("%sの秘孔を突いて、「お前は既に死んでいる」と叫んだ。",
                        "You point at %s, screaming the word, 'DIE!'."),
             em_ptr->m_name);
     }
 
-    if ((randint0(100 + (em_ptr->caster_lev / 2)) < (em_ptr->r_ptr->level + 35)) && ((em_ptr->src_idx <= 0) || (em_ptr->m_caster_ptr->r_idx != MonsterRaceId::KENSHIROU))) {
+    if ((randint0(100 + (em_ptr->caster_lev / 2)) < (em_ptr->r_ptr->level + 35)) && (!is_monster(em_ptr->src_idx) || (em_ptr->m_caster_ptr->r_idx != MonsterRaceId::KENSHIROU))) {
         em_ptr->note = _("には効果がなかった。", " is unaffected.");
         em_ptr->dam = 0;
     }
index d21fe55..d3c33eb 100644 (file)
@@ -7,6 +7,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
 #include "system/monster-entity.h"
@@ -100,7 +101,7 @@ ProcessResult effect_monster_star_heal(PlayerType *player_ptr, EffectMonster *em
 // who == 0ならばプレイヤーなので、それの判定.
 static void effect_monster_old_heal_check_player(PlayerType *player_ptr, EffectMonster *em_ptr)
 {
-    if (em_ptr->src_idx != 0) {
+    if (is_monster(em_ptr->src_idx)) {
         return;
     }
 
@@ -170,7 +171,7 @@ ProcessResult effect_monster_old_heal(PlayerType *player_ptr, EffectMonster *em_
     effect_monster_old_heal_check_player(player_ptr, em_ptr);
     if (em_ptr->m_ptr->r_idx == MonsterRaceId::LEPER) {
         em_ptr->heal_leper = true;
-        if (!em_ptr->src_idx) {
+        if (is_player(em_ptr->src_idx)) {
             chg_virtue(player_ptr, Virtue::COMPASSION, 5);
         }
     }
@@ -199,7 +200,7 @@ ProcessResult effect_monster_old_speed(PlayerType *player_ptr, EffectMonster *em
         em_ptr->note = _("の動きが速くなった。", " starts moving faster.");
     }
 
-    if (!em_ptr->src_idx) {
+    if (is_player(em_ptr->src_idx)) {
         if (em_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) {
             chg_virtue(player_ptr, Virtue::INDIVIDUALISM, 1);
         }
index 06f001e..e56f372 100644 (file)
@@ -7,6 +7,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "system/grid-type-definition.h"
 #include "system/monster-entity.h"
 #include "system/monster-race-info.h"
@@ -32,7 +33,7 @@ ProcessResult effect_monster_drain_mana(PlayerType *player_ptr, EffectMonster *e
         return ProcessResult::PROCESS_CONTINUE;
     }
 
-    if (em_ptr->src_idx <= 0) {
+    if (!is_monster(em_ptr->src_idx)) {
         msg_format(_("%sから精神エネルギーを吸いとった。", "You draw psychic energy from %s."), em_ptr->m_name);
         (void)hp_player(player_ptr, em_ptr->dam);
         em_ptr->dam = 0;
@@ -72,7 +73,7 @@ ProcessResult effect_monster_mind_blast(PlayerType *player_ptr, EffectMonster *e
     if (em_ptr->seen) {
         em_ptr->obvious = true;
     }
-    if (!em_ptr->src_idx) {
+    if (is_player(em_ptr->src_idx)) {
         msg_format(_("%sをじっと睨んだ。", "You gaze intently at %s."), em_ptr->m_name);
     }
 
@@ -105,7 +106,7 @@ ProcessResult effect_monster_mind_blast(PlayerType *player_ptr, EffectMonster *e
         em_ptr->note = _("は精神攻撃を食らった。", " is blasted by psionic energy.");
         em_ptr->note_dies = _("の精神は崩壊し、肉体は抜け殻となった。", " collapses, a mindless husk.");
 
-        if (em_ptr->src_idx > 0) {
+        if (is_monster(em_ptr->src_idx)) {
             em_ptr->do_conf = randint0(4) + 4;
         } else {
             em_ptr->do_conf = randint0(8) + 8;
@@ -120,7 +121,7 @@ ProcessResult effect_monster_brain_smash(PlayerType *player_ptr, EffectMonster *
     if (em_ptr->seen) {
         em_ptr->obvious = true;
     }
-    if (!em_ptr->src_idx) {
+    if (is_player(em_ptr->src_idx)) {
         msg_format(_("%sをじっと睨んだ。", "You gaze intently at %s."), em_ptr->m_name);
     }
 
@@ -154,7 +155,7 @@ ProcessResult effect_monster_brain_smash(PlayerType *player_ptr, EffectMonster *
     } else {
         em_ptr->note = _("は精神攻撃を食らった。", " is blasted by psionic energy.");
         em_ptr->note_dies = _("の精神は崩壊し、肉体は抜け殻となった。", " collapses, a mindless husk.");
-        if (em_ptr->src_idx > 0) {
+        if (is_monster(em_ptr->src_idx)) {
             em_ptr->do_conf = randint0(4) + 4;
             em_ptr->do_stun = randint0(4) + 4;
         } else {
index bf6c3a1..0aa16a0 100644 (file)
@@ -26,6 +26,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "player/player-damage.h"
 #include "spell-kind/spells-genocide.h"
 #include "system/grid-type-definition.h"
@@ -136,8 +137,8 @@ ProcessResult effect_monster_hand_doom(EffectMonster *em_ptr)
         return ProcessResult::PROCESS_CONTINUE;
     }
 
-    if ((em_ptr->src_idx > 0) ? ((em_ptr->caster_lev + randint1(em_ptr->dam)) > (em_ptr->r_ptr->level + 10 + randint1(20)))
-                          : (((em_ptr->caster_lev / 2) + randint1(em_ptr->dam)) > (em_ptr->r_ptr->level + randint1(200)))) {
+    if (is_monster(em_ptr->src_idx) ? ((em_ptr->caster_lev + randint1(em_ptr->dam)) > (em_ptr->r_ptr->level + 10 + randint1(20)))
+                                    : (((em_ptr->caster_lev / 2) + randint1(em_ptr->dam)) > (em_ptr->r_ptr->level + randint1(200)))) {
         em_ptr->dam = ((40 + randint1(20)) * em_ptr->m_ptr->hp) / 100;
         if (em_ptr->m_ptr->hp < em_ptr->dam) {
             em_ptr->dam = em_ptr->m_ptr->hp - 1;
@@ -264,7 +265,7 @@ ProcessResult effect_monster_genocide(PlayerType *player_ptr, EffectMonster *em_
     }
 
     std::string_view spell_name(_("モンスター消滅", "Genocide One"));
-    if (genocide_aux(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam, !em_ptr->src_idx, (em_ptr->r_ptr->level + 1) / 2, spell_name.data())) {
+    if (genocide_aux(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam, is_player(em_ptr->src_idx), (em_ptr->r_ptr->level + 1) / 2, spell_name.data())) {
         if (em_ptr->seen_msg) {
             msg_format(_("%sは消滅した!", "%s^ disappeared!"), em_ptr->m_name);
         }
@@ -278,7 +279,7 @@ ProcessResult effect_monster_genocide(PlayerType *player_ptr, EffectMonster *em_
 
 ProcessResult effect_monster_photo(PlayerType *player_ptr, EffectMonster *em_ptr)
 {
-    if (!em_ptr->src_idx) {
+    if (is_player(em_ptr->src_idx)) {
         msg_format(_("%sを写真に撮った。", "You take a photograph of %s."), em_ptr->m_name);
     }
 
index ddf5924..6b8c8f3 100644 (file)
@@ -11,6 +11,7 @@
 #include "monster-race/monster-race.h"
 #include "monster/monster-info.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "system/angband-system.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
@@ -44,12 +45,12 @@ EffectMonster::EffectMonster(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITI
     auto *floor_ptr = player_ptr->current_floor_ptr;
     this->g_ptr = &floor_ptr->grid_array[this->y][this->x];
     this->m_ptr = &floor_ptr->m_list[this->g_ptr->m_idx];
-    this->m_caster_ptr = (this->src_idx > 0) ? &floor_ptr->m_list[this->src_idx] : nullptr;
+    this->m_caster_ptr = is_monster(this->src_idx) ? &floor_ptr->m_list[this->src_idx] : nullptr;
     this->r_ptr = &this->m_ptr->get_monrace();
     this->seen = this->m_ptr->ml;
     this->seen_msg = is_seen(player_ptr, this->m_ptr);
     this->slept = this->m_ptr->is_asleep();
     this->known = (this->m_ptr->cdis <= MAX_PLAYER_SIGHT) || AngbandSystem::get_instance().is_phase_out();
     this->note_dies = this->m_ptr->get_died_message();
-    this->caster_lev = (this->src_idx > 0) ? this->m_caster_ptr->get_monrace().level : (player_ptr->lev * 2);
+    this->caster_lev = is_monster(this->src_idx) ? this->m_caster_ptr->get_monrace().level : (player_ptr->lev * 2);
 }
index 7b4eea4..527cc98 100644 (file)
@@ -35,6 +35,7 @@
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "object-enchant/special-object-flags.h"
 #include "object/object-kind-hook.h"
 #include "spell-kind/blood-curse.h"
  */
 static ProcessResult is_affective(PlayerType *player_ptr, EffectMonster *em_ptr)
 {
-    if (!em_ptr->g_ptr->m_idx) {
+    if (!is_monster(em_ptr->g_ptr->m_idx)) {
         return ProcessResult::PROCESS_FALSE;
     }
-    if (em_ptr->src_idx && (em_ptr->g_ptr->m_idx == em_ptr->src_idx)) {
+    if (is_monster(em_ptr->src_idx) && (em_ptr->g_ptr->m_idx == em_ptr->src_idx)) {
         return ProcessResult::PROCESS_FALSE;
     }
     if (sukekaku && ((em_ptr->m_ptr->r_idx == MonsterRaceId::SUKE) || (em_ptr->m_ptr->r_idx == MonsterRaceId::KAKU))) {
@@ -75,7 +76,7 @@ static ProcessResult is_affective(PlayerType *player_ptr, EffectMonster *em_ptr)
     if (em_ptr->m_ptr->hp < 0) {
         return ProcessResult::PROCESS_FALSE;
     }
-    if (em_ptr->src_idx || em_ptr->g_ptr->m_idx != player_ptr->riding) {
+    if (is_monster(em_ptr->src_idx) || em_ptr->g_ptr->m_idx != player_ptr->riding) {
         return ProcessResult::PROCESS_TRUE;
     }
 
@@ -188,7 +189,7 @@ static void effect_damage_killed_pet(PlayerType *player_ptr, EffectMonster *em_p
         }
     }
 
-    if (em_ptr->src_idx > 0) {
+    if (is_monster(em_ptr->src_idx)) {
         monster_gain_exp(player_ptr, em_ptr->src_idx, em_ptr->m_ptr->r_idx);
     }
 
@@ -232,7 +233,7 @@ static void effect_damage_makes_sleep(PlayerType *player_ptr, EffectMonster *em_
  */
 static bool deal_effect_damage_from_monster(PlayerType *player_ptr, EffectMonster *em_ptr)
 {
-    if (em_ptr->src_idx <= 0) {
+    if (!is_monster(em_ptr->src_idx)) {
         return false;
     }
 
@@ -364,7 +365,7 @@ static void deal_effect_damage_to_monster(PlayerType *player_ptr, EffectMonster
  */
 static void effect_makes_change_virtues(PlayerType *player_ptr, EffectMonster *em_ptr)
 {
-    if ((em_ptr->src_idx > 0) || !em_ptr->slept) {
+    if (is_monster(em_ptr->src_idx) || !em_ptr->slept) {
         return;
     }
 
@@ -394,7 +395,7 @@ static void affected_monster_prevents_bad_status(PlayerType *player_ptr, EffectM
     auto should_alive = r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
     should_alive |= r_ptr->misc_flags.has(MonsterMiscType::QUESTOR);
     should_alive |= r_ptr->population_flags.has(MonsterPopulationType::NAZGUL);
-    if (should_alive && !AngbandSystem::get_instance().is_phase_out() && (em_ptr->src_idx > 0) && (em_ptr->dam > em_ptr->m_ptr->hp)) {
+    if (should_alive && !AngbandSystem::get_instance().is_phase_out() && is_monster(em_ptr->src_idx) && (em_ptr->dam > em_ptr->m_ptr->hp)) {
         em_ptr->dam = em_ptr->m_ptr->hp;
     }
 }
@@ -549,11 +550,11 @@ static void effect_damage_makes_teleport(PlayerType *player_ptr, EffectMonster *
 
     em_ptr->note = _("が消え去った!", " disappears!");
 
-    if (!em_ptr->src_idx) {
+    if (is_monster(em_ptr->src_idx)) {
         chg_virtue(player_ptr, Virtue::VALOUR, -1);
     }
 
-    teleport_flags tflag = i2enum<teleport_flags>((!em_ptr->src_idx ? TELEPORT_DEC_VALOUR : TELEPORT_SPONTANEOUS) | TELEPORT_PASSIVE);
+    teleport_flags tflag = i2enum<teleport_flags>((is_monster(em_ptr->src_idx) ? TELEPORT_DEC_VALOUR : TELEPORT_SPONTANEOUS) | TELEPORT_PASSIVE);
     teleport_away(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->do_dist, tflag);
 
     em_ptr->y = em_ptr->m_ptr->fy;
@@ -642,7 +643,7 @@ static void postprocess_by_effected_pet(PlayerType *player_ptr, EffectMonster *e
         return;
     }
 
-    if (em_ptr->src_idx == 0) {
+    if (is_player(em_ptr->src_idx)) {
         if (!(em_ptr->flag & PROJECT_NO_HANGEKI)) {
             set_target(m_ptr, monster_target_y, monster_target_x);
         }
@@ -651,7 +652,7 @@ static void postprocess_by_effected_pet(PlayerType *player_ptr, EffectMonster *e
     }
 
     const auto &m_caster_ref = *em_ptr->m_caster_ptr;
-    if ((em_ptr->src_idx > 0) && m_caster_ref.is_pet() && !player_ptr->is_located_at({ m_ptr->target_y, m_ptr->target_x })) {
+    if (is_monster(em_ptr->src_idx) && m_caster_ref.is_pet() && !player_ptr->is_located_at({ m_ptr->target_y, m_ptr->target_x })) {
         set_target(m_ptr, m_caster_ref.fy, m_caster_ref.fx);
     }
 }
index 9562983..9cd46ee 100644 (file)
@@ -3,6 +3,7 @@
 #include "core/window-redrawer.h"
 #include "effect/effect-player.h"
 #include "mind/mind-mirror-master.h"
+#include "monster/monster-util.h"
 #include "player/player-damage.h"
 #include "player/player-status-flags.h"
 #include "status/bad-status-setter.h"
@@ -26,7 +27,7 @@ void effect_player_drain_mana(PlayerType *player_ptr, EffectPlayerType *ep_ptr)
         return;
     }
 
-    if (ep_ptr->src_idx > 0) {
+    if (is_monster(ep_ptr->src_idx)) {
         msg_format(_("%s^に精神エネルギーを吸い取られてしまった!", "%s^ draws psychic energy from you!"), ep_ptr->m_name);
     } else {
         msg_print(_("精神エネルギーを吸い取られてしまった!", "Your psychic energy is drained!"));
@@ -48,7 +49,7 @@ void effect_player_drain_mana(PlayerType *player_ptr, EffectPlayerType *ep_ptr)
     };
     rfu.set_flags(flags);
 
-    if ((ep_ptr->src_idx <= 0) || (ep_ptr->m_ptr->hp >= ep_ptr->m_ptr->maxhp)) {
+    if (!is_monster(ep_ptr->src_idx) || (ep_ptr->m_ptr->hp >= ep_ptr->m_ptr->maxhp)) {
         ep_ptr->dam = 0;
         return;
     }
index 8e41b00..62eb94e 100644 (file)
@@ -19,6 +19,7 @@
 #include "monster-race/monster-race.h"
 #include "monster/monster-describer.h"
 #include "monster/monster-description-types.h"
+#include "monster/monster-util.h"
 #include "player-base/player-class.h"
 #include "player-info/samurai-data-type.h"
 #include "player/player-status-flags.h"
@@ -92,7 +93,7 @@ static bool process_bolt_reflection(PlayerType *player_ptr, EffectPlayerType *ep
     msg_print(mes);
     POSITION t_y;
     POSITION t_x;
-    if (ep_ptr->src_idx > 0) {
+    if (is_monster(ep_ptr->src_idx)) {
         auto *floor_ptr = player_ptr->current_floor_ptr;
         auto *m_ptr = &floor_ptr->m_list[ep_ptr->src_idx];
         do {
@@ -131,13 +132,13 @@ static ProcessResult check_continue_player_effect(PlayerType *player_ptr, Effect
 
     auto is_effective = ep_ptr->dam > 0;
     is_effective &= randint0(55) < (player_ptr->lev * 3 / 5 + 20);
-    is_effective &= ep_ptr->src_idx > 0;
+    is_effective &= is_monster(ep_ptr->src_idx);
     is_effective &= ep_ptr->src_idx != player_ptr->riding;
     if (is_effective && kawarimi(player_ptr, true)) {
         return ProcessResult::PROCESS_FALSE;
     }
 
-    if ((ep_ptr->src_idx == 0) || (ep_ptr->src_idx == player_ptr->riding)) {
+    if (is_player(ep_ptr->src_idx) || (ep_ptr->src_idx == player_ptr->riding)) {
         return ProcessResult::PROCESS_FALSE;
     }
 
@@ -156,7 +157,7 @@ static ProcessResult check_continue_player_effect(PlayerType *player_ptr, Effect
  */
 static void describe_effect_source(PlayerType *player_ptr, EffectPlayerType *ep_ptr, concptr src_name)
 {
-    if (ep_ptr->src_idx > 0) {
+    if (is_monster(ep_ptr->src_idx)) {
         ep_ptr->m_ptr = &player_ptr->current_floor_ptr->m_list[ep_ptr->src_idx];
         ep_ptr->rlev = ep_ptr->m_ptr->get_monrace().level >= 1 ? ep_ptr->m_ptr->get_monrace().level : 1;
         angband_strcpy(ep_ptr->m_name, monster_desc(player_ptr, ep_ptr->m_ptr, 0), sizeof(ep_ptr->m_name));
@@ -211,7 +212,7 @@ bool affect_player(MONSTER_IDX src_idx, PlayerType *player_ptr, concptr src_name
     switch_effects_player(player_ptr, ep_ptr);
 
     SpellHex(player_ptr).store_vengeful_damage(ep_ptr->get_damage);
-    if ((player_ptr->tim_eyeeye || SpellHex(player_ptr).is_spelling_specific(HEX_EYE_FOR_EYE)) && (ep_ptr->get_damage > 0) && !player_ptr->is_dead && (ep_ptr->src_idx > 0)) {
+    if ((player_ptr->tim_eyeeye || SpellHex(player_ptr).is_spelling_specific(HEX_EYE_FOR_EYE)) && (ep_ptr->get_damage > 0) && !player_ptr->is_dead && is_monster(ep_ptr->src_idx)) {
         const auto m_name_self = monster_desc(player_ptr, ep_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE);
         msg_print(_(format("攻撃が%s自身を傷つけた!", ep_ptr->m_name), format("The attack of %s has wounded %s!", ep_ptr->m_name, m_name_self.data())));
         (*project)(player_ptr, 0, 0, ep_ptr->m_ptr->fy, ep_ptr->m_ptr->fx, ep_ptr->get_damage, AttributeType::MISSILE, PROJECT_KILL, std::nullopt);
index 4c733fc..8a1ce74 100644 (file)
@@ -23,6 +23,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-description-types.h"
 #include "monster/monster-info.h"
+#include "monster/monster-util.h"
 #include "pet/pet-fall-off.h"
 #include "player/player-status.h"
 #include "spell-class/spells-mirror-master.h"
@@ -81,10 +82,10 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
     if (any_bits(flag, PROJECT_JUMP)) {
         x1 = target_x;
         y1 = target_y;
-    } else if (src_idx <= 0) {
+    } else if (!is_monster(src_idx)) {
         x1 = player_ptr->x;
         y1 = player_ptr->y;
-    } else if (src_idx > 0) {
+    } else if (is_monster(src_idx)) {
         x1 = player_ptr->current_floor_ptr->m_list[src_idx].fx;
         y1 = player_ptr->current_floor_ptr->m_list[src_idx].fy;
     } else {
@@ -305,8 +306,8 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
     update_creature(player_ptr);
 
     if (flag & PROJECT_KILL) {
-        see_s_msg = (src_idx > 0) ? is_seen(player_ptr, &player_ptr->current_floor_ptr->m_list[src_idx])
-                                  : (!src_idx ? true : (player_can_see_bold(player_ptr, y1, x1) && projectable(player_ptr, player_ptr->y, player_ptr->x, y1, x1)));
+        see_s_msg = is_monster(src_idx) ? is_seen(player_ptr, &player_ptr->current_floor_ptr->m_list[src_idx])
+                                        : (is_player(src_idx) ? true : (player_can_see_bold(player_ptr, y1, x1) && projectable(player_ptr, player_ptr->y, player_ptr->x, y1, x1)));
     }
 
     if (flag & (PROJECT_GRID)) {
@@ -393,7 +394,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
                         } else {
                             msg_print(_("攻撃は跳ね返った!", "The attack bounces!"));
                         }
-                    } else if (src_idx <= 0) {
+                    } else if (!is_monster(src_idx)) {
                         sound(SOUND_REFLECT);
                     }
 
@@ -482,7 +483,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
         if (!src_idx && (project_m_n == 1) && none_bits(flag, PROJECT_JUMP)) {
             const Pos2D pos_project(project_m_y, project_m_x);
             const auto &grid = floor.get_grid(pos_project);
-            if (grid.m_idx > 0) {
+            if (is_monster(grid.m_idx)) {
                 auto &monster = floor.m_list[grid.m_idx];
                 if (monster.ml) {
                     if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
@@ -548,7 +549,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
             }
 
             std::string who_name;
-            if (src_idx > 0) {
+            if (is_monster(src_idx)) {
                 who_name = monster_desc(player_ptr, &floor.m_list[src_idx], MD_WRONGDOER_NAME);
             }
 
index 5fe95d8..ba21e4c 100644 (file)
@@ -28,6 +28,7 @@
 #include "grid/grid.h"
 #include "monster-race/monster-race.h"
 #include "monster/monster-info.h"
+#include "monster/monster-util.h"
 #include "room/lake-types.h"
 #include "spell-kind/spells-floor.h"
 #include "system/artifact-type-definition.h"
@@ -343,7 +344,7 @@ void build_streamer(PlayerType *player_ptr, FEAT_IDX feat, int chance)
             }
 
             auto *r_ptr = &monraces_info[floor.m_list[grid.m_idx].r_idx];
-            if (grid.m_idx && !(streamer.flags.has(TerrainCharacteristics::PLACE) && monster_can_cross_terrain(player_ptr, feat, r_ptr, 0))) {
+            if (is_monster(grid.m_idx) && !(streamer.flags.has(TerrainCharacteristics::PLACE) && monster_can_cross_terrain(player_ptr, feat, r_ptr, 0))) {
                 /* Delete the monster (if any) */
                 delete_monster(player_ptr, pos.y, pos.x);
             }
index 4670c32..37d23ee 100644 (file)
@@ -11,6 +11,7 @@
 #include "grid/object-placer.h"
 #include "grid/trap.h"
 #include "monster-race/monster-race.h"
+#include "monster/monster-util.h"
 #include "system/dungeon-info.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
@@ -62,7 +63,7 @@ static bool alloc_stairs_aux(PlayerType *player_ptr, POSITION y, POSITION x, int
 {
     auto *floor_ptr = player_ptr->current_floor_ptr;
     auto *g_ptr = &floor_ptr->grid_array[y][x];
-    if (!g_ptr->is_floor() || pattern_tile(floor_ptr, y, x) || !g_ptr->o_idx_list.empty() || (g_ptr->m_idx != 0) || next_to_walls(floor_ptr, y, x) < walls) {
+    if (!g_ptr->is_floor() || pattern_tile(floor_ptr, y, x) || !g_ptr->o_idx_list.empty() || is_monster(g_ptr->m_idx) || next_to_walls(floor_ptr, y, x) < walls) {
         return false;
     }
 
@@ -194,7 +195,7 @@ void alloc_object(PlayerType *player_ptr, dap_type set, dungeon_allocation_type
             x = randint0(floor_ptr->width);
             const Pos2D pos(y, x);
             const auto &grid = floor_ptr->get_grid(pos);
-            if (!grid.is_floor() || !grid.o_idx_list.empty() || grid.m_idx) {
+            if (!grid.is_floor() || !grid.o_idx_list.empty() || is_monster(grid.m_idx)) {
                 continue;
             }
 
index fef6bb4..ce05c42 100644 (file)
@@ -551,7 +551,7 @@ void wilderness_gen(PlayerType *player_ptr)
                     continue;
                 }
 
-                if (grid.m_idx != 0) {
+                if (is_monster(grid.m_idx)) {
                     delete_monster_idx(player_ptr, grid.m_idx);
                 }
 
@@ -569,7 +569,7 @@ void wilderness_gen(PlayerType *player_ptr)
                     continue;
                 }
 
-                if (grid.m_idx != 0) {
+                if (is_monster(grid.m_idx)) {
                     delete_monster_idx(player_ptr, grid.m_idx);
                 }
 
index 589efca..17fbd40 100644 (file)
@@ -7,6 +7,7 @@
 #include "grid/lighting-colors-table.h"
 #include "mind/mind-ninja.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "player/special-defense-types.h"
 #include "room/door-definition.h"
 #include "system/dungeon-info.h"
@@ -234,7 +235,7 @@ void cave_set_feat(PlayerType *player_ptr, POSITION y, POSITION x, FEAT_IDX feat
         g_ptr->info &= ~(CAVE_MARK);
     }
 
-    if (g_ptr->m_idx) {
+    if (is_monster(g_ptr->m_idx)) {
         update_monster(player_ptr, g_ptr->m_idx, false);
     }
 
@@ -264,7 +265,7 @@ void cave_set_feat(PlayerType *player_ptr, POSITION y, POSITION x, FEAT_IDX feat
         auto *cc_ptr = &floor_ptr->grid_array[yy][xx];
         cc_ptr->info |= CAVE_GLOW;
         if (cc_ptr->is_view()) {
-            if (cc_ptr->m_idx) {
+            if (is_monster(cc_ptr->m_idx)) {
                 update_monster(player_ptr, cc_ptr->m_idx, false);
             }
 
index c645386..7f31d25 100644 (file)
@@ -37,6 +37,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "object/item-tester-hooker.h"
 #include "object/object-mark-types.h"
 #include "player-info/class-info.h"
@@ -84,7 +85,7 @@ bool new_player_spot(PlayerType *player_ptr)
         const auto &grid = player_ptr->current_floor_ptr->get_grid({ y, x });
 
         /* Must be a "naked" floor grid */
-        if (grid.m_idx) {
+        if (is_monster(grid.m_idx)) {
             continue;
         }
         if (floor.is_in_dungeon()) {
@@ -184,7 +185,7 @@ static void update_local_illumination_aux(PlayerType *player_ptr, int y, int x)
         return;
     }
 
-    if (grid.m_idx > 0) {
+    if (is_monster(grid.m_idx)) {
         update_monster(player_ptr, grid.m_idx, false);
     }
 
@@ -849,7 +850,7 @@ bool cave_monster_teleportable_bold(PlayerType *player_ptr, MONSTER_IDX m_idx, P
         return false;
     }
 
-    if (grid.m_idx && (grid.m_idx != m_idx)) {
+    if (is_monster(grid.m_idx) && (grid.m_idx != m_idx)) {
         return false;
     }
     if (player_ptr->is_located_at(pos)) {
@@ -896,7 +897,7 @@ bool cave_player_teleportable_bold(PlayerType *player_ptr, POSITION y, POSITION
         return false;
     }
 
-    if (grid.m_idx && (grid.m_idx != player_ptr->riding)) {
+    if (is_monster(grid.m_idx) && (grid.m_idx != player_ptr->riding)) {
         return false;
     }
 
@@ -1060,7 +1061,7 @@ void place_grid(PlayerType *player_ptr, Grid *g_ptr, grid_bold_type gb_type)
         return;
     }
 
-    if (g_ptr->m_idx > 0) {
+    if (is_monster(g_ptr->m_idx)) {
         delete_monster_idx(player_ptr, g_ptr->m_idx);
     }
 }
index 01aaba3..4e625bf 100644 (file)
@@ -7,6 +7,7 @@
 #include "game-option/special-options.h"
 #include "grid/feature.h"
 #include "io/screen-util.h"
+#include "monster/monster-util.h"
 #include "player/player-status.h"
 #include "system/angband-system.h"
 #include "system/floor-type-definition.h"
@@ -57,7 +58,7 @@ void print_path(PlayerType *player_ptr, POSITION y, POSITION x)
             TERM_COLOR ta = default_color;
             auto tc = '*';
 
-            if (g_ptr->m_idx && floor_ptr->m_list[g_ptr->m_idx].ml) {
+            if (is_monster(g_ptr->m_idx) && floor_ptr->m_list[g_ptr->m_idx].ml) {
                 map_info(player_ptr, ny, nx, &a, &c, &ta, &tc);
 
                 if (!is_ascii_graphics(a)) {
index 3a78390..908e777 100644 (file)
@@ -6,6 +6,7 @@
 #include "grid/feature.h"
 #include "grid/grid.h"
 #include "mind/mind-numbers.h"
+#include "monster/monster-util.h"
 #include "player-attack/player-attack.h"
 #include "player/player-move.h"
 #include "spell-kind/earthquake.h"
@@ -42,7 +43,7 @@ bool cast_berserk_spell(PlayerType *player_ptr, MindBerserkerType spell)
 
         y = player_ptr->y + ddy[dir];
         x = player_ptr->x + ddx[dir];
-        if (!player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+        if (!is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
             msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
             return false;
         }
@@ -54,7 +55,7 @@ bool cast_berserk_spell(PlayerType *player_ptr, MindBerserkerType spell)
 
         y += ddy[dir];
         x += ddx[dir];
-        if (player_can_enter(player_ptr, player_ptr->current_floor_ptr->grid_array[y][x].feat, 0) && !is_trap(player_ptr, player_ptr->current_floor_ptr->grid_array[y][x].feat) && !player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+        if (player_can_enter(player_ptr, player_ptr->current_floor_ptr->grid_array[y][x].feat, 0) && !is_trap(player_ptr, player_ptr->current_floor_ptr->grid_array[y][x].feat) && !is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
             msg_print(nullptr);
             (void)move_player_effect(player_ptr, y, x, MPE_FORGET_FLOW | MPE_HANDLE_STUFF | MPE_DONT_PICKUP);
         }
index 3051e57..88f5be0 100644 (file)
@@ -35,6 +35,7 @@
 #include "monster-race/race-brightness-flags.h"
 #include "monster-race/race-flags-resistance.h"
 #include "monster/monster-describer.h"
+#include "monster/monster-util.h"
 #include "player-base/player-class.h"
 #include "player-info/equipment-info.h"
 #include "player-status/player-energy.h"
@@ -1063,7 +1064,7 @@ ProcessResult effect_monster_elemental_genocide(PlayerType *player_ptr, EffectMo
         return ProcessResult::PROCESS_TRUE;
     }
 
-    if (genocide_aux(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam, !em_ptr->src_idx, (em_ptr->r_ptr->level + 1) / 2, _("モンスター消滅", "Genocide One"))) {
+    if (genocide_aux(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam, is_player(em_ptr->src_idx), (em_ptr->r_ptr->level + 1) / 2, _("モンスター消滅", "Genocide One"))) {
         if (em_ptr->seen_msg) {
             msg_format(_("%sは消滅した!", "%s^ disappeared!"), em_ptr->m_name);
         }
index cb4b304..5edf278 100644 (file)
@@ -17,6 +17,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "pet/pet-util.h"
 #include "player-base/player-class.h"
 #include "player-info/equipment-info.h"
@@ -211,7 +212,7 @@ bool shock_power(PlayerType *player_ptr)
     PLAYER_LEVEL plev = player_ptr->lev;
     int dam = damroll(8 + ((plev - 5) / 4) + boost / 12, 8);
     fire_beam(player_ptr, AttributeType::MISSILE, dir, dam);
-    if (!player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+    if (!is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
         return true;
     }
 
index 8a8944b..8987d10 100644 (file)
@@ -23,6 +23,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "object-enchant/trc-types.h"
 #include "object/object-kind-hook.h"
 #include "player-attack/player-attack.h"
@@ -179,7 +180,7 @@ bool rush_attack(PlayerType *player_ptr, bool *mdeath)
             continue;
         }
 
-        if (!grid_new.m_idx) {
+        if (!is_monster(grid_new.m_idx)) {
             if (tm_idx) {
                 msg_print(_("失敗!", "Failed!"));
             } else {
index a8ef612..497b230 100644 (file)
@@ -1,6 +1,7 @@
 #include "mind/mind-warrior.h"
 #include "cmd-action/cmd-attack.h"
 #include "floor/geometry.h"
+#include "monster/monster-util.h"
 #include "spell-kind/spells-teleport.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
@@ -21,7 +22,7 @@ bool hit_and_away(PlayerType *player_ptr)
     }
     POSITION y = player_ptr->y + ddy[dir];
     POSITION x = player_ptr->x + ddx[dir];
-    if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+    if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
         do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
         if (randint0(player_ptr->skill_dis) < 7) {
             msg_print(_("うまく逃げられなかった。", "You failed to run away."));
@@ -53,7 +54,7 @@ bool sword_dancing(PlayerType *player_ptr)
         g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
 
         /* Hack -- attack monsters */
-        if (g_ptr->m_idx) {
+        if (is_monster(g_ptr->m_idx)) {
             do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
         } else {
             msg_print(_("攻撃が空をきった。", "You attack the empty air."));
index e95a359..c9f5530 100644 (file)
@@ -18,6 +18,7 @@
 #include "monster-race/monster-race.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "player-attack/player-attack.h"
 #include "player-base/player-class.h"
 #include "player-info/monk-data-type.h"
@@ -272,7 +273,7 @@ bool double_attack(PlayerType *player_ptr)
     }
     POSITION y = player_ptr->y + ddy[dir];
     POSITION x = player_ptr->x + ddx[dir];
-    if (!player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+    if (!is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
         msg_print(_("その方向にはモンスターはいません。", "You don't see any monster in this direction"));
         msg_print(nullptr);
         return true;
@@ -287,7 +288,7 @@ bool double_attack(PlayerType *player_ptr)
     }
 
     do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
-    if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+    if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
         handle_stuff(player_ptr);
         do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
     }
index 4f1afc8..c7d5685 100644 (file)
@@ -14,6 +14,7 @@
 #include "monster/monster-processor-util.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "system/dungeon-info.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
@@ -122,7 +123,7 @@ static bool exe_monster_attack_to_monster(PlayerType *player_ptr, MONSTER_IDX m_
  */
 bool process_monster_attack_to_monster(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, Grid *g_ptr, bool can_cross)
 {
-    if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) {
+    if (!turn_flags_ptr->do_move || !is_monster(g_ptr->m_idx)) {
         return false;
     }
 
index be9a8b1..e2909dd 100644 (file)
@@ -27,6 +27,7 @@
 #include "monster/monster-processor-util.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "pet/pet-util.h"
 #include "player/player-status-flags.h"
 #include "system/angband-system.h"
@@ -66,7 +67,7 @@ static bool process_wall(PlayerType *player_ptr, turn_flags *turn_flags_ptr, con
         return true;
     }
 
-    if (grid.m_idx > 0) {
+    if (is_monster(grid.m_idx)) {
         turn_flags_ptr->do_move = true;
         return true;
     }
index a58f780..f3085f1 100644 (file)
@@ -9,6 +9,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
 #include "system/item-entity.h"
@@ -158,7 +159,7 @@ void delete_monster(PlayerType *player_ptr, POSITION y, POSITION x)
     }
 
     g_ptr = &floor_ptr->grid_array[y][x];
-    if (g_ptr->m_idx) {
+    if (is_monster(g_ptr->m_idx)) {
         delete_monster_idx(player_ptr, g_ptr->m_idx);
     }
 }
index f86fa39..c33bd1c 100644 (file)
@@ -161,7 +161,7 @@ bool summon_specific(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION y1, P
     summon_specific_type = SUMMON_NONE;
 
     bool notice = false;
-    if (src_idx <= 0) {
+    if (!is_monster(src_idx)) {
         notice = true;
     } else {
         auto *m_ptr = &player_ptr->current_floor_ptr->m_list[src_idx];
index 6354613..d4552d3 100644 (file)
@@ -169,7 +169,7 @@ static bool check_quest_placeable(const FloorType &floor, MonsterRaceId r_idx)
     int number_mon = 0;
     for (int i2 = 0; i2 < floor.width; ++i2) {
         for (int j2 = 0; j2 < floor.height; j2++) {
-            auto quest_monster = (floor.grid_array[j2][i2].m_idx > 0);
+            auto quest_monster = is_monster(floor.grid_array[j2][i2].m_idx);
             quest_monster &= (floor.m_list[floor.grid_array[j2][i2].m_idx].r_idx == q_ptr->r_idx);
             if (quest_monster) {
                 number_mon++;
@@ -285,7 +285,7 @@ bool place_monster_one(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION y,
 
     g_ptr->m_idx = m_pop(&floor);
     hack_m_idx_ii = g_ptr->m_idx;
-    if (!g_ptr->m_idx) {
+    if (!is_monster(g_ptr->m_idx)) {
         return false;
     }
 
@@ -296,14 +296,14 @@ bool place_monster_one(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION y,
 
     m_ptr->mflag.clear();
     m_ptr->mflag2.clear();
-    if (any_bits(mode, PM_MULTIPLY) && (src_idx > 0) && !floor.m_list[src_idx].is_original_ap()) {
+    if (any_bits(mode, PM_MULTIPLY) && is_monster(src_idx) && !floor.m_list[src_idx].is_original_ap()) {
         m_ptr->ap_r_idx = floor.m_list[src_idx].ap_r_idx;
         if (floor.m_list[src_idx].mflag2.has(MonsterConstantFlagType::KAGE)) {
             m_ptr->mflag2.set(MonsterConstantFlagType::KAGE);
         }
     }
 
-    if ((src_idx > 0) && r_ptr->kind_flags.has_none_of(alignment_mask)) {
+    if (is_monster(src_idx) && r_ptr->kind_flags.has_none_of(alignment_mask)) {
         m_ptr->sub_align = floor.m_list[src_idx].sub_align;
     } else {
         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
@@ -328,7 +328,7 @@ bool place_monster_one(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION y,
     m_ptr->nickname.clear();
     m_ptr->exp = 0;
 
-    if (src_idx > 0 && floor.m_list[src_idx].is_pet()) {
+    if (is_monster(src_idx) && floor.m_list[src_idx].is_pet()) {
         set_bits(mode, PM_FORCE_PET);
         m_ptr->parent_m_idx = src_idx;
     } else {
@@ -339,7 +339,7 @@ bool place_monster_one(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION y,
         choose_new_monster(player_ptr, g_ptr->m_idx, true, MonsterRace::empty_id());
         r_ptr = &m_ptr->get_monrace();
         m_ptr->mflag2.set(MonsterConstantFlagType::CHAMELEON);
-        if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE) && (src_idx <= 0)) {
+        if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE) && (!is_monster(src_idx))) {
             m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
         }
     } else if (any_bits(mode, PM_KAGE) && none_bits(mode, PM_FORCE_PET)) {
@@ -358,7 +358,7 @@ bool place_monster_one(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION y,
     m_ptr->ml = false;
     if (any_bits(mode, PM_FORCE_PET)) {
         set_pet(player_ptr, m_ptr);
-    } else if (((src_idx == 0) && r_ptr->behavior_flags.has(MonsterBehaviorType::FRIENDLY)) || is_friendly_idx(player_ptr, src_idx) || any_bits(mode, PM_FORCE_FRIENDLY)) {
+    } else if ((is_player(src_idx) && r_ptr->behavior_flags.has(MonsterBehaviorType::FRIENDLY)) || is_friendly_idx(player_ptr, src_idx) || any_bits(mode, PM_FORCE_FRIENDLY)) {
         if (!monster_has_hostile_align(player_ptr, nullptr, 0, -1, r_ptr) && !player_ptr->current_floor_ptr->inside_arena) {
             set_friendly(m_ptr);
         }
index 2093605..23d7f28 100644 (file)
@@ -19,6 +19,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-flag-types.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "monster/smart-learn-types.h"
 #include "player/player-status-flags.h"
 #include "system/floor-type-definition.h"
@@ -147,7 +148,7 @@ bool monster_can_enter(PlayerType *player_ptr, POSITION y, POSITION x, MonsterRa
     if (player_ptr->is_located_at(pos)) {
         return false;
     }
-    if (grid.m_idx) {
+    if (is_monster(grid.m_idx)) {
         return false;
     }
 
index 0b57d33..5964101 100644 (file)
@@ -449,7 +449,7 @@ int get_monster_crowd_number(FloorType *floor_ptr, MONSTER_IDX m_idx)
         if (!in_bounds(floor_ptr, ay, ax)) {
             continue;
         }
-        if (floor_ptr->grid_array[ay][ax].m_idx > 0) {
+        if (is_monster(floor_ptr->grid_array[ay][ax].m_idx)) {
             count++;
         }
     }
index bc5a627..fe4b056 100644 (file)
@@ -452,7 +452,7 @@ bool decide_monster_multiplication(PlayerType *player_ptr, MONSTER_IDX m_idx, PO
                 continue;
             }
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 k++;
             }
         }
index b4cea80..6213f4d 100644 (file)
@@ -21,6 +21,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-processor-util.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "monster/smart-learn-types.h"
 #include "player-base/player-class.h"
 #include "player-info/samurai-data-type.h"
@@ -77,7 +78,7 @@ bool update_riding_monster(PlayerType *player_ptr, turn_flags *turn_flags_ptr, M
     }
 
     player_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
-    if (g_ptr->m_idx) {
+    if (is_monster(g_ptr->m_idx)) {
         y_ptr->fy = oy;
         y_ptr->fx = ox;
         update_monster(player_ptr, g_ptr->m_idx, true);
index a5f4813..7e1bb9f 100644 (file)
@@ -361,3 +361,13 @@ errr get_mon_num_prep_bounty(PlayerType *player_ptr)
 {
     return do_get_mon_num_prep(player_ptr, nullptr, nullptr, false);
 }
+
+bool is_player(MONSTER_IDX m_idx)
+{
+    return m_idx == 0;
+}
+
+bool is_monster(MONSTER_IDX m_idx)
+{
+    return m_idx > 0;
+}
index e2459a2..ccb7a2e 100644 (file)
@@ -16,3 +16,5 @@ monsterrace_hook_type get_monster_hook(PlayerType *player_ptr);
 monsterrace_hook_type get_monster_hook2(PlayerType *player_ptr, POSITION y, POSITION x);
 errr get_mon_num_prep(PlayerType *player_ptr, monsterrace_hook_type hook1, monsterrace_hook_type hook2);
 errr get_mon_num_prep_bounty(PlayerType *player_ptr);
+bool is_player(MONSTER_IDX m_idx);
+bool is_monster(MONSTER_IDX m_idx);
index 5ea31d7..4564337 100644 (file)
@@ -29,6 +29,7 @@
 #include "monster/monster-flag-types.h"
 #include "monster/monster-info.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "mspell/assign-monster-spell.h"
 #include "mspell/improper-mspell-remover.h"
 #include "mspell/mspell-judgement.h"
@@ -166,7 +167,7 @@ bool clean_shot(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, P
     for (const auto &[y, x] : grid_g) {
         const Pos2D pos(y, x);
         const auto &grid = floor_ptr->get_grid(pos);
-        if ((grid.m_idx > 0) && (y != y2 || x != x2)) {
+        if (is_monster(grid.m_idx) && (y != y2 || x != x2)) {
             auto *m_ptr = &floor_ptr->m_list[grid.m_idx];
             if (is_friend == m_ptr->is_pet()) {
                 return false;
index 623c91a..a577a0f 100644 (file)
@@ -20,6 +20,7 @@
 #include "monster-race/monster-race.h"
 #include "monster-race/race-flags-resistance.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "player-base/player-class.h"
 #include "player-base/player-race.h"
 #include "player-info/race-info.h"
@@ -65,7 +66,7 @@ bool direct_beam(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2,
         const auto &grid = floor.get_grid(pos);
         if (y == y2 && x == x2) {
             hit2 = true;
-        } else if (is_friend && grid.m_idx > 0 && !m_ptr->is_hostile_to_melee(floor.m_list[grid.m_idx])) {
+        } else if (is_friend && is_monster(grid.m_idx) && !m_ptr->is_hostile_to_melee(floor.m_list[grid.m_idx])) {
             return false;
         }
 
index b3f916b..9b1a3da 100644 (file)
@@ -9,6 +9,7 @@
 #include "floor/geometry.h"
 #include "grid/grid.h"
 #include "monster/monster-info.h"
+#include "monster/monster-util.h"
 #include "player/digestion-processor.h"
 #include "player/player-move.h"
 #include "player/player-status.h"
@@ -43,7 +44,7 @@ bool eat_rock(PlayerType *player_ptr)
         msg_print(_("この地形は食べられない。", "You cannot eat this feature."));
     } else if (terrain.flags.has(TerrainCharacteristics::PERMANENT)) {
         msg_format(_("いてっ!この%sはあなたの歯より硬い!", "Ouch!  This %s is harder than your teeth!"), terrain_mimic.name.data());
-    } else if (grid.m_idx) {
+    } else if (is_monster(grid.m_idx)) {
         const auto &monster = player_ptr->current_floor_ptr->m_list[grid.m_idx];
         msg_print(_("何かが邪魔しています!", "There's something in the way!"));
         if (!monster.ml || !monster.is_pet()) {
index f813ef2..5dd0109 100644 (file)
@@ -38,6 +38,7 @@
 #include "monster/monster-pain-describer.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "object-enchant/tr-types.h"
 #include "object-hook/hook-expendable.h"
 #include "object-hook/hook-weapon.h"
@@ -263,7 +264,7 @@ void ObjectThrowEntity::display_potion_throw()
 
     auto *floor_ptr = this->player_ptr->current_floor_ptr;
     auto *angry_m_ptr = &floor_ptr->m_list[floor_ptr->grid_array[this->y][this->x].m_idx];
-    if ((floor_ptr->grid_array[this->y][this->x].m_idx == 0) || !angry_m_ptr->is_friendly() || angry_m_ptr->is_invulnerable()) {
+    if (!is_monster(floor_ptr->grid_array[this->y][this->x].m_idx) || !angry_m_ptr->is_friendly() || angry_m_ptr->is_invulnerable()) {
         this->do_drop = false;
         return;
     }
index 04657e5..db46865 100644 (file)
@@ -17,6 +17,7 @@
 #include "monster-race/race-indice-types.h"
 #include "monster/monster-info.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "mspell/mspell-damage-calculator.h"
 #include "mutation/mutation-flag-types.h"
 #include "object-enchant/tr-types.h"
@@ -366,7 +367,7 @@ bool process_warning(PlayerType *player_ptr, POSITION xx, POSITION yy)
 
             const auto *g_ptr = &floor.grid_array[my][mx];
 
-            if (!g_ptr->m_idx) {
+            if (!is_monster(g_ptr->m_idx)) {
                 continue;
             }
 
index ce0be87..81940cd 100644 (file)
@@ -13,6 +13,7 @@
 #include "monster-attack/monster-attack-player.h"
 #include "monster-race/monster-race.h"
 #include "monster/monster-describer.h"
+#include "monster/monster-util.h"
 #include "pet/pet-util.h"
 #include "player-base/player-class.h"
 #include "player/player-damage.h"
@@ -111,7 +112,7 @@ bool process_fall_off_horse(PlayerType *player_ptr, int dam, bool force)
             Grid *g_ptr;
             g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
 
-            if (g_ptr->m_idx) {
+            if (is_monster(g_ptr->m_idx)) {
                 continue;
             }
 
index 8a2225d..09ee54d 100644 (file)
@@ -28,6 +28,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "object-enchant/tr-types.h"
 #include "object-enchant/vorpal-weapon.h"
 #include "object-hook/hook-weapon.h"
@@ -519,7 +520,7 @@ static void cause_earthquake(PlayerType *player_ptr, player_attack_type *pa_ptr,
     }
 
     earthquake(player_ptr, player_ptr->y, player_ptr->x, 10, 0);
-    if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx == 0) {
+    if (!is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
         *(pa_ptr->mdeath) = true;
     }
 }
@@ -612,7 +613,7 @@ void massacre(PlayerType *player_ptr)
         POSITION x = player_ptr->x + ddx_ddd[dir];
         g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
         m_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
-        if (g_ptr->m_idx && (m_ptr->ml || cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, TerrainCharacteristics::PROJECT))) {
+        if (is_monster(g_ptr->m_idx) && (m_ptr->ml || cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, TerrainCharacteristics::PROJECT))) {
             do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
         }
     }
index 9be0c5c..2044ba9 100644 (file)
@@ -34,6 +34,7 @@
 #include "monster-race/monster-race-hook.h"
 #include "monster-race/monster-race.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "monster/smart-learn-types.h"
 #include "mutation/mutation-calculator.h"
 #include "mutation/mutation-flag-types.h"
@@ -173,7 +174,7 @@ static void delayed_visual_update(PlayerType *player_ptr)
         }
 
         lite_spot(player_ptr, y, x);
-        if (g_ptr->m_idx) {
+        if (is_monster(g_ptr->m_idx)) {
             update_monster(player_ptr, g_ptr->m_idx, false);
         }
 
@@ -2816,7 +2817,7 @@ bool player_has_no_spellbooks(PlayerType *player_ptr)
  */
 bool player_place(PlayerType *player_ptr, POSITION y, POSITION x)
 {
-    if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx != 0) {
+    if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
         return false;
     }
 
index 9c1974a..f220da4 100644 (file)
@@ -2,6 +2,7 @@
 #include "dungeon/dungeon-flag-types.h"
 #include "floor/geometry.h"
 #include "hpmp/hp-mp-processor.h"
+#include "monster/monster-util.h"
 #include "player/digestion-processor.h"
 #include "player/player-status.h"
 #include "spell-kind/spells-specific-bolt.h"
@@ -29,7 +30,7 @@ bool vampirism(PlayerType *player_ptr)
     POSITION x = player_ptr->x + ddx[dir];
     const auto *g_ptr = &floor.grid_array[y][x];
     stop_mouth(player_ptr);
-    if (!(g_ptr->m_idx)) {
+    if (!is_monster(g_ptr->m_idx)) {
         msg_print(_("何もない場所に噛みついた!", "You bite into thin air!"));
         return false;
     }
index 18a3351..0f6bfad 100644 (file)
@@ -20,6 +20,7 @@
 #include "inventory/inventory-slot-types.h"
 #include "io/input-key-requester.h"
 #include "monster-race/monster-race.h"
+#include "monster/monster-util.h"
 #include "object-enchant/object-curse.h"
 #include "object-enchant/tr-types.h"
 #include "object-enchant/trc-types.h"
@@ -841,7 +842,7 @@ std::optional<std::string> do_hex_spell(PlayerType *player_ptr, spell_hex_type s
                     if (dir == 5) {
                         continue;
                     }
-                    if (floor_ptr->grid_array[dy][dx].m_idx) {
+                    if (is_monster(floor_ptr->grid_array[dy][dx].m_idx)) {
                         flag = true;
                     }
                 }
index 714b278..a494202 100644 (file)
@@ -26,6 +26,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-info.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "object-enchant/tr-types.h"
 #include "player-info/equipment-info.h"
 #include "player/player-damage.h"
@@ -122,7 +123,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
 
             y = player_ptr->y + ddy_cdd[cdir];
             x = player_ptr->x + ddx_cdd[cdir];
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
             } else {
                 msg_print(_("攻撃は空を切った。", "You attack the empty air."));
@@ -130,7 +131,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
 
             y = player_ptr->y + ddy_cdd[(cdir + 7) % 8];
             x = player_ptr->x + ddx_cdd[(cdir + 7) % 8];
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
             } else {
                 msg_print(_("攻撃は空を切った。", "You attack the empty air."));
@@ -138,7 +139,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
 
             y = player_ptr->y + ddy_cdd[(cdir + 1) % 8];
             x = player_ptr->x + ddx_cdd[(cdir + 1) % 8];
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
             } else {
                 msg_print(_("攻撃は空を切った。", "You attack the empty air."));
@@ -183,7 +184,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_FIRE);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -226,7 +227,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_MINEUCHI);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -283,7 +284,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
 
             const auto *floor_ptr = player_ptr->current_floor_ptr;
             const auto &grid = floor_ptr->grid_array[y][x];
-            if (!grid.m_idx) {
+            if (!is_monster(grid.m_idx)) {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
                 return std::nullopt;
             }
@@ -324,7 +325,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_POISON);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -355,7 +356,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_ZANMA);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -386,7 +387,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             x = player_ptr->x + ddx[dir];
 
             const auto &floor = *player_ptr->current_floor_ptr;
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -395,7 +396,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             if (floor.get_dungeon_definition().flags.has(DungeonFeatureType::NO_MELEE)) {
                 return "";
             }
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 int i;
                 POSITION ty = y, tx = x;
                 POSITION oy = y, ox = x;
@@ -475,7 +476,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_HAGAN);
             }
 
@@ -511,7 +512,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_COLD);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -542,7 +543,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_KYUSHO);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -572,7 +573,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_MAJIN);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -603,7 +604,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_SUTEMI);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -634,7 +635,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_ELEC);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -678,7 +679,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
                 x = player_ptr->x + ddx_ddd[dir];
                 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
                 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
-                if ((g_ptr->m_idx == 0) || (!m_ptr->ml && !cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, TerrainCharacteristics::PROJECT))) {
+                if (!is_monster(g_ptr->m_idx) || (!m_ptr->ml && !cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, TerrainCharacteristics::PROJECT))) {
                     continue;
                 }
 
@@ -714,7 +715,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_QUAKE);
             } else {
                 earthquake(player_ptr, player_ptr->y, player_ptr->x, 10, 0);
@@ -814,7 +815,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
                 x = player_ptr->x + ddx[dir];
                 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
 
-                if (g_ptr->m_idx) {
+                if (is_monster(g_ptr->m_idx)) {
                     do_cmd_attack(player_ptr, y, x, HISSATSU_3DAN);
                 } else {
                     msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -826,7 +827,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
                 }
 
                 /* Monster is dead? */
-                if (!g_ptr->m_idx) {
+                if (!is_monster(g_ptr->m_idx)) {
                     break;
                 }
 
@@ -896,7 +897,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_DRAIN);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
@@ -1012,9 +1013,9 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
-                if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+                if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                     handle_stuff(player_ptr);
                     do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
                 }
@@ -1107,7 +1108,7 @@ std::optional<std::string> do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s
             y = player_ptr->y + ddy[dir];
             x = player_ptr->x + ddx[dir];
 
-            if (player_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
                 do_cmd_attack(player_ptr, y, x, HISSATSU_UNDEAD);
             } else {
                 msg_print(_("その方向にはモンスターはいません。", "There is no monster."));
index 546b081..2b8fe48 100644 (file)
@@ -8,6 +8,7 @@
 #include "grid/trap.h"
 #include "monster-floor/monster-generator.h"
 #include "monster-floor/place-monster-types.h"
+#include "monster/monster-util.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
 #include "system/player-type-definition.h"
@@ -27,7 +28,7 @@ static bool player_grid(PlayerType *player_ptr, Grid *g_ptr)
 static bool is_cave_empty_grid(PlayerType *player_ptr, Grid *g_ptr)
 {
     bool is_empty_grid = g_ptr->cave_has_flag(TerrainCharacteristics::PLACE);
-    is_empty_grid &= g_ptr->m_idx == 0;
+    is_empty_grid &= !is_monster(g_ptr->m_idx);
     is_empty_grid &= !player_grid(player_ptr, g_ptr);
     return is_empty_grid;
 }
@@ -139,7 +140,7 @@ static void vault_trap_aux(FloorType *floor_ptr, POSITION y, POSITION x, POSITIO
         }
 
         g_ptr = &floor_ptr->grid_array[y1][x1];
-        if (!g_ptr->is_floor() || !g_ptr->o_idx_list.empty() || g_ptr->m_idx) {
+        if (!g_ptr->is_floor() || !g_ptr->o_idx_list.empty() || is_monster(g_ptr->m_idx)) {
             continue;
         }
 
index cfd3920..02e83b2 100644 (file)
@@ -24,6 +24,7 @@
 #include "io/cursor.h"
 #include "io/screen-util.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "pet/pet-util.h"
 #include "spell-kind/spells-teleport.h"
 #include "system/angband-system.h"
@@ -62,7 +63,7 @@ void SpellsMirrorMaster::remove_mirror(int y, int x)
             reset_bits(g_ptr->info, CAVE_MARK);
         }
 
-        if (g_ptr->m_idx) {
+        if (is_monster(g_ptr->m_idx)) {
             update_monster(this->player_ptr, g_ptr->m_idx, false);
         }
 
@@ -196,7 +197,7 @@ void SpellsMirrorMaster::seal_of_mirror(const int dam)
                 continue;
             }
 
-            if (g_ref.m_idx == 0) {
+            if (!is_monster(g_ref.m_idx)) {
                 this->remove_mirror(y, x);
             }
         }
@@ -334,7 +335,7 @@ void SpellsMirrorMaster::project_seeker_ray(int target_x, int target_y, int dam)
             }
             const auto &grid = floor.grid_array[project_m_y][project_m_x];
             const auto &monster = floor.m_list[grid.m_idx];
-            if (project_m_n == 1 && grid.m_idx > 0 && monster.ml) {
+            if (project_m_n == 1 && is_monster(grid.m_idx) && monster.ml) {
                 if (!this->player_ptr->effects()->hallucination()->is_hallucinated()) {
                     monster_race_track(this->player_ptr, monster.ap_r_idx);
                 }
@@ -431,7 +432,7 @@ static bool activate_super_ray_effect(PlayerType *player_ptr, int y, int x, int
     const auto *floor_ptr = player_ptr->current_floor_ptr;
     const auto *g_ptr = &floor_ptr->grid_array[project_m_y][project_m_x];
     const auto *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
-    if (project_m_n == 1 && g_ptr->m_idx > 0 && m_ptr->ml) {
+    if (project_m_n == 1 && is_monster(g_ptr->m_idx) && m_ptr->ml) {
         if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
             monster_race_track(player_ptr, m_ptr->ap_r_idx);
         }
index 530361a..6076cc0 100644 (file)
@@ -20,6 +20,7 @@
 #include "monster/monster-info.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "monster/smart-learn-types.h"
 #include "player/player-damage.h"
 #include "player/player-move.h"
@@ -110,7 +111,7 @@ bool earthquake(PlayerType *player_ptr, POSITION cy, POSITION cx, POSITION r, MO
                 continue;
             }
 
-            if (floor_ptr->grid_array[y][x].m_idx) {
+            if (is_monster(floor_ptr->grid_array[y][x].m_idx)) {
                 continue;
             }
 
@@ -178,7 +179,7 @@ bool earthquake(PlayerType *player_ptr, POSITION cy, POSITION cx, POSITION r, MO
                 continue;
             }
 
-            if (!grid.m_idx) {
+            if (!is_monster(grid.m_idx)) {
                 continue;
             }
 
@@ -218,7 +219,7 @@ bool earthquake(PlayerType *player_ptr, POSITION cy, POSITION cx, POSITION r, MO
                         continue;
                     }
 
-                    if (grid_neighbor.m_idx) {
+                    if (is_monster(grid_neighbor.m_idx)) {
                         continue;
                     }
 
@@ -249,7 +250,7 @@ bool earthquake(PlayerType *player_ptr, POSITION cy, POSITION cx, POSITION r, MO
                     msg_format(_("%s^は岩石に埋もれてしまった!", "%s^ is embedded in the rock!"), m_name.data());
                 }
 
-                if (grid.m_idx) {
+                if (is_monster(grid.m_idx)) {
                     const auto &m_ref = floor_ptr->m_list[grid.m_idx];
                     if (record_named_pet && m_ref.is_named_pet()) {
                         const auto m2_name = monster_desc(player_ptr, m_ptr, MD_INDEF_VISIBLE);
index d922de3..cc6be08 100644 (file)
@@ -33,6 +33,7 @@
 #include "monster/monster-description-types.h"
 #include "monster/monster-info.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "monster/smart-learn-types.h"
 #include "object-enchant/special-object-flags.h"
 #include "object/object-mark-types.h"
@@ -335,7 +336,7 @@ bool destroy_area(PlayerType *player_ptr, const POSITION y1, const POSITION x1,
                 continue;
             }
 
-            if (grid.m_idx) {
+            if (is_monster(grid.m_idx)) {
                 auto &monster = floor.m_list[grid.m_idx];
                 auto &monrace = monster.get_monrace();
 
index f43e7d3..72c7272 100644 (file)
@@ -14,6 +14,7 @@
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "player/special-defense-types.h"
 #include "spell-kind/spells-launcher.h"
 #include "system/angband-system.h"
@@ -62,7 +63,7 @@ static void cave_temp_room_lite(PlayerType *player_ptr, const std::vector<Pos2D>
         auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
         g_ptr->info &= ~(CAVE_TEMP);
         g_ptr->info |= (CAVE_GLOW);
-        if (g_ptr->m_idx) {
+        if (is_monster(g_ptr->m_idx)) {
             PERCENTAGE chance = 25;
             auto *m_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
             auto *r_ptr = &m_ptr->get_monrace();
@@ -132,7 +133,7 @@ static void cave_temp_room_unlite(PlayerType *player_ptr, const std::vector<Pos2
             note_spot(player_ptr, point.y, point.x);
         }
 
-        if (grid.m_idx) {
+        if (is_monster(grid.m_idx)) {
             update_monster(player_ptr, grid.m_idx, false);
         }
 
index 4830184..e4546c7 100644 (file)
@@ -26,6 +26,7 @@
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
+#include "monster/monster-util.h"
 #include "mutation/mutation-flag-types.h"
 #include "object-enchant/tr-types.h"
 #include "player-base/player-class.h"
@@ -71,7 +72,7 @@ bool teleport_swap(PlayerType *player_ptr, DIRECTION dir)
 
     Grid *g_ptr;
     g_ptr = &player_ptr->current_floor_ptr->grid_array[ty][tx];
-    if (!g_ptr->m_idx || (g_ptr->m_idx == player_ptr->riding)) {
+    if (!is_monster(g_ptr->m_idx) || (g_ptr->m_idx == player_ptr->riding)) {
         msg_print(_("それとは場所を交換できません。", "You can't trade places with that!"));
         return false;
     }
@@ -514,7 +515,7 @@ void teleport_player_to(PlayerType *player_ptr, POSITION ny, POSITION nx, telepo
 
         bool is_anywhere = w_ptr->wizard;
         is_anywhere &= (mode & TELEPORT_PASSIVE) == 0;
-        is_anywhere &= (player_ptr->current_floor_ptr->grid_array[y][x].m_idx > 0) || player_ptr->current_floor_ptr->grid_array[y][x].m_idx == player_ptr->riding;
+        is_anywhere &= is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx) || player_ptr->current_floor_ptr->grid_array[y][x].m_idx == player_ptr->riding;
         if (is_anywhere) {
             break;
         }
index 72984ac..060d47e 100644 (file)
@@ -11,6 +11,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "player-info/class-info.h"
 #include "player/player-damage.h"
 #include "spell-kind/spells-floor.h"
@@ -162,7 +163,7 @@ bool vanish_dungeon(PlayerType *player_ptr)
             const auto &terrrain = grid.get_terrain();
             grid.info &= ~(CAVE_ROOM | CAVE_ICKY);
             const auto &monster = floor.m_list[grid.m_idx];
-            if (grid.m_idx && monster.is_asleep()) {
+            if (is_monster(grid.m_idx) && monster.is_asleep()) {
                 (void)set_monster_csleep(player_ptr, grid.m_idx, 0);
                 if (monster.ml) {
                     const auto m_name = monster_desc(player_ptr, &monster, 0);
index b91a5ff..8cac7cc 100644 (file)
@@ -14,6 +14,7 @@
 #include "floor/geometry.h"
 #include "game-option/disturbance-options.h"
 #include "grid/feature-flag-types.h"
+#include "monster/monster-util.h"
 #include "spell-realm/spells-crusade.h"
 #include "spell/range-calc.h"
 #include "system/angband-system.h"
@@ -61,7 +62,7 @@ bool cast_wrath_of_the_god(PlayerType *player_ptr, int dam, POSITION rad)
         if (!cave_has_flag_bold(&floor, pos_to.y, pos_to.x, TerrainCharacteristics::PROJECT)) {
             break;
         }
-        if ((dir != 5) && floor.get_grid(pos_to).m_idx != 0) {
+        if ((dir != 5) && is_monster(floor.get_grid(pos_to).m_idx)) {
             break;
         }
 
index 5a5c84f..5051c60 100644 (file)
@@ -25,6 +25,7 @@
 #include "main/sound-of-music.h"
 #include "mind/mind-force-trainer.h"
 #include "monster/monster-describer.h"
+#include "monster/monster-util.h"
 #include "object/object-kind-hook.h"
 #include "player-base/player-class.h"
 #include "player-info/class-info.h"
@@ -546,7 +547,7 @@ bool fishing(PlayerType *player_ptr)
         return false;
     }
 
-    if (floor_ptr->grid_array[y][x].m_idx) {
+    if (is_monster(floor_ptr->grid_array[y][x].m_idx)) {
         const auto m_name = monster_desc(player_ptr, &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx], 0);
         msg_format(_("%sが邪魔だ!", "%s^ is standing in your way."), m_name.data());
         PlayerEnergy(player_ptr).reset_player_turn();
index 290dc3e..121ea9c 100644 (file)
@@ -12,6 +12,7 @@
 #include "monster-race/race-indice-types.h"
 #include "monster/monster-info.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "monster/smart-learn-types.h"
 #include "object/item-tester-hooker.h"
 #include "object/item-use-flags.h"
@@ -270,7 +271,7 @@ int summon_cyber(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION y, POSITI
     /* Summoned by a monster */
     BIT_FLAGS mode = PM_ALLOW_GROUP;
     auto *floor_ptr = player_ptr->current_floor_ptr;
-    if (src_idx > 0) {
+    if (is_monster(src_idx)) {
         auto *m_ptr = &floor_ptr->m_list[src_idx];
         if (m_ptr->is_pet()) {
             mode |= PM_FORCE_PET;
index b406800..f3125f8 100644 (file)
@@ -3,6 +3,7 @@
 #include "effect/spells-effect-util.h"
 #include "floor/cave.h"
 #include "grid/feature-flag-types.h"
+#include "monster/monster-util.h"
 #include "spell-class/spells-mirror-master.h"
 #include "system/angband-system.h"
 #include "system/floor-type-definition.h"
@@ -123,7 +124,7 @@ static bool project_stop(PlayerType *player_ptr, projection_path_type *pp_ptr)
         }
     }
 
-    if (any_bits(pp_ptr->flag, PROJECT_STOP) && !pp_ptr->position->empty() && (player_ptr->is_located_at(pos) || grid.m_idx != 0)) {
+    if (any_bits(pp_ptr->flag, PROJECT_STOP) && !pp_ptr->position->empty() && (player_ptr->is_located_at(pos) || is_monster(grid.m_idx))) {
         return true;
     }
 
index 07effd7..79e2181 100644 (file)
@@ -20,6 +20,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-description-types.h"
 #include "monster/monster-flag-types.h"
+#include "monster/monster-util.h"
 #include "object/item-tester-hooker.h"
 #include "object/object-mark-types.h"
 #include "player-base/player-race.h"
@@ -270,7 +271,7 @@ static bool within_char_util(const short input)
 
 static short describe_grid(PlayerType *player_ptr, GridExamination *ge_ptr)
 {
-    if ((ge_ptr->g_ptr->m_idx == 0) || !player_ptr->current_floor_ptr->m_list[ge_ptr->g_ptr->m_idx].ml) {
+    if (!is_monster(ge_ptr->g_ptr->m_idx) || !player_ptr->current_floor_ptr->m_list[ge_ptr->g_ptr->m_idx].ml) {
         return CONTINUOUS_DESCRIPTION;
     }
 
index b21b3ab..9990e51 100644 (file)
@@ -6,6 +6,7 @@
 #include "monster/monster-flag-types.h"
 #include "monster/monster-info.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "object/object-mark-types.h"
 #include "system/angband-system.h"
 #include "system/floor-type-definition.h"
@@ -86,7 +87,7 @@ static bool target_set_accept(PlayerType *player_ptr, const Pos2D &pos)
     }
 
     const auto &grid = floor.get_grid(pos);
-    if (grid.m_idx) {
+    if (is_monster(grid.m_idx)) {
         auto &monster = floor.m_list[grid.m_idx];
         if (monster.ml) {
             return true;
index 8a46d24..f472b03 100644 (file)
@@ -4,6 +4,7 @@
 #include "grid/grid.h"
 #include "monster-race/monster-race.h"
 #include "monster/monster-flag-types.h"
+#include "monster/monster-util.h"
 #include "system/artifact-type-definition.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
@@ -137,14 +138,14 @@ bool ang_sort_comp_importance(PlayerType *player_ptr, vptr u, vptr v, int a, int
 
     /* Extract monster race */
     MonsterRaceInfo *ap_r_ptr_a;
-    if (grid_a.m_idx && monster_a.ml) {
+    if (is_monster(grid_a.m_idx) && monster_a.ml) {
         ap_r_ptr_a = &monster_a.get_appearance_monrace();
     } else {
         ap_r_ptr_a = nullptr;
     }
 
     MonsterRaceInfo *ap_r_ptr_b;
-    if (grid_b.m_idx && monster_b.ml) {
+    if (is_monster(grid_b.m_idx) && monster_b.ml) {
         ap_r_ptr_b = &monster_b.get_appearance_monrace();
     } else {
         ap_r_ptr_b = nullptr;
index a3ccfb7..0ed47c3 100644 (file)
@@ -9,6 +9,7 @@
 #include "grid/feature.h"
 #include "grid/grid.h"
 #include "monster-race/monster-race.h"
+#include "monster/monster-util.h"
 #include "object/object-info.h"
 #include "object/object-mark-types.h"
 #include "system/baseitem-info.h"
@@ -301,7 +302,7 @@ void map_info(PlayerType *player_ptr, POSITION y, POSITION x, TERM_COLOR *ap, ch
         break;
     }
 
-    if (grid.m_idx && display_autopick != 0) {
+    if (is_monster(grid.m_idx) && display_autopick != 0) {
         set_term_color(player_ptr, y, x, ap, cp);
         return;
     }
index 5d544a0..1b7f6c7 100644 (file)
@@ -16,6 +16,7 @@
 #include "monster-race/monster-race.h"
 #include "monster/monster-describer.h"
 #include "monster/monster-description-types.h"
+#include "monster/monster-util.h"
 #include "object/item-tester-hooker.h"
 #include "object/object-info.h"
 #include "player-base/player-class.h"
@@ -527,7 +528,7 @@ void fix_object(PlayerType *player_ptr)
  */
 static const MonsterEntity *monster_on_floor_items(FloorType *floor_ptr, const Grid *g_ptr)
 {
-    if (g_ptr->m_idx == 0) {
+    if (!is_monster(g_ptr->m_idx)) {
         return nullptr;
     }
 
index 3ea111d..91644b0 100644 (file)
@@ -22,6 +22,7 @@
 #include "monster-floor/monster-summon.h"
 #include "monster/monster-describer.h"
 #include "monster/monster-status.h"
+#include "monster/monster-util.h"
 #include "mutation/mutation-processor.h"
 #include "object/lite-processor.h"
 #include "perception/simple-perception.h"
@@ -146,7 +147,7 @@ void WorldTurnProcessor::process_monster_arena()
     for (auto x = 0; x < floor_ptr->width; ++x) {
         for (auto y = 0; y < floor_ptr->height; y++) {
             auto *g_ptr = &floor_ptr->grid_array[y][x];
-            if ((g_ptr->m_idx > 0) && (g_ptr->m_idx != this->player_ptr->riding)) {
+            if (is_monster(g_ptr->m_idx) && (g_ptr->m_idx != this->player_ptr->riding)) {
                 number_mon++;
                 win_m_idx = g_ptr->m_idx;
             }