From 5ab5d2af033e0e6c5b4788292959ef41fc7e83cd Mon Sep 17 00:00:00 2001 From: Hourier Date: Sat, 18 Jan 2020 16:36:47 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#38997=20monster2.c=20=E3=81=AE?= =?utf8?q?=E6=95=B4=E5=BD=A2=20/=20Reshaped=20monster2.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/monster2.c | 962 ++++++++++++++++++++++++++------------------------------- 1 file changed, 445 insertions(+), 517 deletions(-) diff --git a/src/monster2.c b/src/monster2.c index 1bcbdcb07..f82d52490 100644 --- a/src/monster2.c +++ b/src/monster2.c @@ -45,6 +45,7 @@ #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */ #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */ +#define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */ MONSTER_IDX hack_m_idx = 0; /* Hack -- see "process_monsters()" */ MONSTER_IDX hack_m_idx_ii = 0; @@ -86,11 +87,10 @@ monster_race *real_r_ptr(monster_type *m_ptr) return &r_info[real_r_idx(m_ptr)]; } + MONRACE_IDX real_r_idx(monster_type *m_ptr) { monster_race *r_ptr = &r_info[m_ptr->r_idx]; - - /* Extract real race */ if (m_ptr->mflag2 & MFLAG2_CHAMELEON) { if (r_ptr->flags1 & RF1_UNIQUE) @@ -98,10 +98,8 @@ MONRACE_IDX real_r_idx(monster_type *m_ptr) else return MON_CHAMELEON; } - else - { - return m_ptr->r_idx; - } + + return m_ptr->r_idx; } @@ -115,14 +113,12 @@ MONRACE_IDX real_r_idx(monster_type *m_ptr) */ void delete_monster_idx(MONSTER_IDX i) { - POSITION x, y; floor_type *floor_ptr = p_ptr->current_floor_ptr; monster_type *m_ptr = &floor_ptr->m_list[i]; monster_race *r_ptr = &r_info[m_ptr->r_idx]; - OBJECT_IDX this_o_idx, next_o_idx = 0; - y = m_ptr->fy; - x = m_ptr->fx; + POSITION y = m_ptr->fy; + POSITION x = m_ptr->fx; /* Hack -- Reduce the racial counter */ real_r_ptr(m_ptr)->cur_num--; @@ -151,25 +147,17 @@ void delete_monster_idx(MONSTER_IDX i) /* Monster is gone */ floor_ptr->grid_array[y][x].m_idx = 0; - for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) + OBJECT_IDX next_o_idx = 0; + for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) { object_type *o_ptr; o_ptr = &floor_ptr->o_list[this_o_idx]; next_o_idx = o_ptr->next_o_idx; - - /* - * o_ptr->held_m_idx is needed in delete_object_idx() - * to prevent calling lite_spot() - */ - delete_object_idx(floor_ptr, this_o_idx); } (void)WIPE(m_ptr, monster_type); - - /* Count monsters */ floor_ptr->m_cnt--; - lite_spot(y, x); if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) { @@ -187,29 +175,25 @@ void delete_monster_idx(MONSTER_IDX i) */ static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTER_IDX i2) { - POSITION y, x; - int i; - grid_type *g_ptr; - monster_type *m_ptr; - OBJECT_IDX this_o_idx, next_o_idx = 0; - - /* Do nothing */ if (i1 == i2) return; /* Old monster */ floor_type *floor_ptr = player_ptr->current_floor_ptr; + monster_type *m_ptr; m_ptr = &floor_ptr->m_list[i1]; - y = m_ptr->fy; - x = m_ptr->fx; + POSITION y = m_ptr->fy; + POSITION x = m_ptr->fx; /* Cave grid */ + grid_type *g_ptr; g_ptr = &floor_ptr->grid_array[y][x]; g_ptr->m_idx = i2; /* Repair objects being carried by monster */ - for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) + OBJECT_IDX next_o_idx = 0; + for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) { object_type *o_ptr; o_ptr = &floor_ptr->o_list[this_o_idx]; @@ -235,7 +219,7 @@ static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTE /* Hack -- Update parent index */ if (is_pet(m_ptr)) { - for (i = 1; i < floor_ptr->m_max; i++) + for (int i = 1; i < floor_ptr->m_max; i++) { monster_type *m2_ptr = &floor_ptr->m_list[i]; @@ -250,7 +234,7 @@ static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTE /* Wipe the hole */ (void)WIPE(&floor_ptr->m_list[i1], monster_type); - for (i = 0; i < MAX_MTIMED; i++) + for (int i = 0; i < MAX_MTIMED; i++) { int mproc_idx = get_mproc_idx(floor_ptr, i1, i); if (mproc_idx >= 0) floor_ptr->mproc_list[i][mproc_idx] = i2; @@ -275,25 +259,20 @@ static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTE */ void compact_monsters(player_type *player_ptr, int size) { - MONSTER_IDX i; - int num, cnt; - int cur_lev, cur_dis, chance; - - /* Message (only if compacting) */ if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters...")); /* Compact at least 'size' objects */ floor_type *floor_ptr = player_ptr->current_floor_ptr; - for (num = 0, cnt = 1; num < size; cnt++) + for (int num = 0, cnt = 1; num < size; cnt++) { /* Get more vicious each iteration */ - cur_lev = 5 * cnt; + int cur_lev = 5 * cnt; /* Get closer each iteration */ - cur_dis = 5 * (20 - cnt); + int cur_dis = 5 * (20 - cnt); /* Check all the monsters */ - for (i = 1; i < floor_ptr->m_max; i++) + for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++) { monster_type *m_ptr = &floor_ptr->m_list[i]; @@ -311,7 +290,7 @@ void compact_monsters(player_type *player_ptr, int size) if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue; /* Saving throw chance */ - chance = 90; + int chance = 90; /* Only compact "Quest" Monsters in emergencies */ if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100; @@ -330,26 +309,16 @@ void compact_monsters(player_type *player_ptr, int size) } delete_monster_idx(i); - - /* Count the monster */ num++; } } - /* Excise dead monsters (backwards!) */ - for (i = floor_ptr->m_max - 1; i >= 1; i--) + for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--) { - /* Get the i'th monster */ monster_type *m_ptr = &floor_ptr->m_list[i]; - - /* Skip real monsters */ if (m_ptr->r_idx) continue; - - /* Move last monster into open hole */ compact_monsters_aux(player_ptr, floor_ptr->m_max - 1, i); - - /* Compress "floor_ptr->m_max" */ floor_ptr->m_max--; } } @@ -366,8 +335,6 @@ void compact_monsters(player_type *player_ptr, int size) */ void wipe_monsters_list(player_type *player_ptr) { - int i; - /* Hack -- if Banor or Lupart dies, stay another dead */ if (!r_info[MON_BANORLUPART].max_num) { @@ -376,20 +343,23 @@ void wipe_monsters_list(player_type *player_ptr) r_info[MON_BANOR].max_num = 0; r_info[MON_BANOR].r_pkills++; r_info[MON_BANOR].r_akills++; - if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++; + if (r_info[MON_BANOR].r_tkills < MAX_SHORT) + r_info[MON_BANOR].r_tkills++; } + if (r_info[MON_LUPART].max_num) { r_info[MON_LUPART].max_num = 0; r_info[MON_LUPART].r_pkills++; r_info[MON_LUPART].r_akills++; - if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++; + if (r_info[MON_LUPART].r_tkills < MAX_SHORT) + r_info[MON_LUPART].r_tkills++; } } /* Delete all the monsters */ floor_type *floor_ptr = player_ptr->current_floor_ptr; - for (i = floor_ptr->m_max - 1; i >= 1; i--) + for (int i = floor_ptr->m_max - 1; i >= 1; i--) { monster_type *m_ptr = &floor_ptr->m_list[i]; if (!monster_is_valid(m_ptr)) continue; @@ -408,7 +378,7 @@ void wipe_monsters_list(player_type *player_ptr) */ /* Hack -- Wipe the racial counter of all monster races */ - for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0; + for (int i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0; /* Reset "floor_ptr->m_max" */ floor_ptr->m_max = 1; @@ -417,16 +387,12 @@ void wipe_monsters_list(player_type *player_ptr) floor_ptr->m_cnt = 0; /* Reset "floor_ptr->mproc_max[]" */ - for (i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0; + for (int i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0; - /* Hack -- reset "reproducer" count */ floor_ptr->num_repro = 0; - - /* Hack -- no more target */ target_who = 0; player_ptr->pet_t_m_idx = 0; player_ptr->riding_t_m_idx = 0; - health_track(player_ptr, 0); } @@ -440,45 +406,28 @@ void wipe_monsters_list(player_type *player_ptr) */ MONSTER_IDX m_pop(player_type *player_ptr) { - MONSTER_IDX i; - /* Normal allocation */ floor_type *floor_ptr = player_ptr->current_floor_ptr; if (floor_ptr->m_max < current_world_ptr->max_m_idx) { - /* Access the next hole */ - i = floor_ptr->m_max; - - /* Expand the array */ + MONSTER_IDX i = floor_ptr->m_max; floor_ptr->m_max++; - - /* Count monsters */ floor_ptr->m_cnt++; - - /* Return the index */ - return (i); + return i; } /* Recycle dead monsters */ - for (i = 1; i < floor_ptr->m_max; i++) + for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++) { monster_type *m_ptr; m_ptr = &floor_ptr->m_list[i]; - - /* Skip live monsters */ if (m_ptr->r_idx) continue; - - /* Count monsters */ floor_ptr->m_cnt++; - - /* Use this monster */ - return (i); + return i; } /* Warn the player (except during dungeon creation) */ if (current_world_ptr->character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!")); - - /* Try not to crash */ return 0; } @@ -516,62 +465,62 @@ static bool summon_unique_okay = FALSE; static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_idx, MONRACE_IDX r_idx) { monster_race *r_ptr = &r_info[r_idx]; - int okay = FALSE; + bool is_match = FALSE; /* Check our requirements */ switch (summon_specific_type) { case SUMMON_ANT: { - okay = (r_ptr->d_char == 'a'); + is_match = (r_ptr->d_char == 'a'); break; } case SUMMON_SPIDER: { - okay = (r_ptr->d_char == 'S'); + is_match = (r_ptr->d_char == 'S'); break; } case SUMMON_HOUND: { - okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z')); + is_match = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z')); break; } case SUMMON_HYDRA: { - okay = (r_ptr->d_char == 'M'); + is_match = (r_ptr->d_char == 'M'); break; } case SUMMON_ANGEL: { - okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD))); + is_match = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD))); break; } case SUMMON_DEMON: { - okay = (r_ptr->flags3 & RF3_DEMON); + is_match = (r_ptr->flags3 & RF3_DEMON); break; } case SUMMON_UNDEAD: { - okay = (r_ptr->flags3 & RF3_UNDEAD); + is_match = (r_ptr->flags3 & RF3_UNDEAD); break; } case SUMMON_DRAGON: { - okay = (r_ptr->flags3 & RF3_DRAGON); + is_match = (r_ptr->flags3 & RF3_DRAGON); break; } case SUMMON_HI_UNDEAD: { - okay = ((r_ptr->d_char == 'L') || + is_match = ((r_ptr->d_char == 'L') || (r_ptr->d_char == 'V') || (r_ptr->d_char == 'W')); break; @@ -579,13 +528,13 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id case SUMMON_HI_DRAGON: { - okay = (r_ptr->d_char == 'D'); + is_match = (r_ptr->d_char == 'D'); break; } case SUMMON_HI_DEMON: { - okay = (((r_ptr->d_char == 'U') || + is_match = (((r_ptr->d_char == 'U') || (r_ptr->d_char == 'H') || (r_ptr->d_char == 'B')) && (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE; @@ -594,41 +543,41 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id case SUMMON_AMBERITES: { - okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE; + is_match = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE; break; } case SUMMON_UNIQUE: { - okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE; + is_match = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE; break; } case SUMMON_MOLD: { - okay = (r_ptr->d_char == 'm'); + is_match = (r_ptr->d_char == 'm'); break; } case SUMMON_BAT: { - okay = (r_ptr->d_char == 'b'); + is_match = (r_ptr->d_char == 'b'); break; } case SUMMON_QUYLTHULG: { - okay = (r_ptr->d_char == 'Q'); + is_match = (r_ptr->d_char == 'Q'); break; } case SUMMON_COIN_MIMIC: { - okay = (r_ptr->d_char == '$'); + is_match = (r_ptr->d_char == '$'); break; } case SUMMON_MIMIC: { - okay = ((r_ptr->d_char == '!') || + is_match = ((r_ptr->d_char == '!') || (r_ptr->d_char == '?') || (r_ptr->d_char == '=') || (r_ptr->d_char == '$') || @@ -638,13 +587,13 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id case SUMMON_GOLEM: { - okay = (r_ptr->d_char == 'g'); + is_match = (r_ptr->d_char == 'g'); break; } case SUMMON_CYBER: { - okay = ((r_ptr->d_char == 'U') && + is_match = ((r_ptr->d_char == 'U') && (r_ptr->flags4 & RF4_ROCKET)); break; } @@ -661,25 +610,25 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id summon_kin_type = get_summon_symbol_from_player(player_ptr); } - okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE)); + is_match = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE)); break; } case SUMMON_DAWN: { - okay = (r_idx == MON_DAWN); + is_match = (r_idx == MON_DAWN); break; } case SUMMON_ANIMAL: { - okay = (r_ptr->flags3 & (RF3_ANIMAL)); + is_match = (r_ptr->flags3 & (RF3_ANIMAL)); break; } case SUMMON_ANIMAL_RANGER: { - okay = ((r_ptr->flags3 & (RF3_ANIMAL)) && + is_match = ((r_ptr->flags3 & (RF3_ANIMAL)) && (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) && !(r_ptr->flags3 & (RF3_DRAGON)) && !(r_ptr->flags3 & (RF3_EVIL)) && @@ -692,49 +641,49 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id case SUMMON_HI_DRAGON_LIVING: { - okay = ((r_ptr->d_char == 'D') && monster_living(r_idx)); + is_match = ((r_ptr->d_char == 'D') && monster_living(r_idx)); break; } case SUMMON_LIVING: { - okay = monster_living(r_idx); + is_match = monster_living(r_idx); break; } case SUMMON_PHANTOM: { - okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W); + is_match = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W); break; } case SUMMON_BLUE_HORROR: { - okay = (r_idx == MON_BLUE_HORROR); + is_match = (r_idx == MON_BLUE_HORROR); break; } case SUMMON_ELEMENTAL: { - okay = (r_ptr->d_char == 'E'); + is_match = (r_ptr->d_char == 'E'); break; } case SUMMON_VORTEX: { - okay = (r_ptr->d_char == 'v'); + is_match = (r_ptr->d_char == 'v'); break; } case SUMMON_HYBRID: { - okay = (r_ptr->d_char == 'H'); + is_match = (r_ptr->d_char == 'H'); break; } case SUMMON_BIRD: { - okay = (r_ptr->d_char == 'B'); + is_match = (r_ptr->d_char == 'B'); break; } @@ -742,7 +691,7 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id { int i; for (i = 0; i < 4; i++) - if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE; + if (r_ptr->blow[i].method == RBM_EXPLODE) is_match = TRUE; break; } @@ -751,32 +700,32 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id int i; for (i = 0; i < 4; i++) - if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE; - okay = (okay && monster_living(r_idx)); + if (r_ptr->blow[i].method == RBM_EXPLODE) is_match = TRUE; + is_match = (is_match && monster_living(r_idx)); break; } case SUMMON_MANES: { - okay = (r_idx == MON_MANES); + is_match = (r_idx == MON_MANES); break; } case SUMMON_LOUSE: { - okay = (r_idx == MON_LOUSE); + is_match = (r_idx == MON_LOUSE); break; } case SUMMON_GUARDIANS: { - okay = (r_ptr->flags7 & RF7_GUARDIAN); + is_match = (r_ptr->flags7 & RF7_GUARDIAN); break; } case SUMMON_KNIGHTS: { - okay = ((r_idx == MON_NOV_PALADIN) || + is_match = ((r_idx == MON_NOV_PALADIN) || (r_idx == MON_NOV_PALADIN_G) || (r_idx == MON_PALADIN) || (r_idx == MON_W_KNIGHT) || @@ -787,7 +736,7 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id case SUMMON_EAGLES: { - okay = (r_ptr->d_char == 'B' && + is_match = (r_ptr->d_char == 'B' && (r_ptr->flags8 & RF8_WILD_MOUNTAIN) && (r_ptr->flags8 & RF8_WILD_ONLY)); break; @@ -795,25 +744,25 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id case SUMMON_PIRANHAS: { - okay = (r_idx == MON_PIRANHA); + is_match = (r_idx == MON_PIRANHA); break; } case SUMMON_ARMAGE_GOOD: { - okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD)); + is_match = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD)); break; } case SUMMON_ARMAGE_EVIL: { - okay = ((r_ptr->flags3 & RF3_DEMON) || + is_match = ((r_ptr->flags3 & RF3_DEMON) || (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL))); break; } } - /* Since okay is int, "return (okay);" is not correct. */ - return (bool)(okay ? TRUE : FALSE); + + return is_match; } /*! @@ -823,7 +772,6 @@ static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_id */ static int chameleon_change_m_idx = 0; - /*! * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留 * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters. @@ -836,7 +784,6 @@ static bool restrict_monster_to_dungeon(player_type *player_ptr, MONRACE_IDX r_i DUNGEON_IDX d_idx = player_ptr->dungeon_idx; dungeon_type *d_ptr = &d_info[d_idx]; monster_race *r_ptr = &r_info[r_idx]; - byte a; if (d_ptr->flags1 & DF1_CHAMELEON) { @@ -872,121 +819,147 @@ static bool restrict_monster_to_dungeon(player_type *player_ptr, MONRACE_IDX r_i if (d_ptr->special_div >= 64) return TRUE; if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE; + byte a; switch (d_ptr->mode) { case DUNGEON_MODE_AND: + { if (d_ptr->mflags1) { if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1) return FALSE; } + if (d_ptr->mflags2) { if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2) return FALSE; } + if (d_ptr->mflags3) { if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3) return FALSE; } + if (d_ptr->mflags4) { if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4) return FALSE; } + if (d_ptr->m_a_ability_flags1) { if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1) return FALSE; } + if (d_ptr->m_a_ability_flags2) { if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2) return FALSE; } + if (d_ptr->mflags7) { if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7) return FALSE; } + if (d_ptr->mflags8) { if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8) return FALSE; } + if (d_ptr->mflags9) { if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9) return FALSE; } + if (d_ptr->mflagsr) { if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr) return FALSE; } + for (a = 0; a < 5; a++) if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE; return TRUE; + } case DUNGEON_MODE_NAND: + { if (d_ptr->mflags1) { if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1) return TRUE; } + if (d_ptr->mflags2) { if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2) return TRUE; } + if (d_ptr->mflags3) { if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3) return TRUE; } + if (d_ptr->mflags4) { if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4) return TRUE; } + if (d_ptr->m_a_ability_flags1) { if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1) return TRUE; } + if (d_ptr->m_a_ability_flags2) { if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2) return TRUE; } + if (d_ptr->mflags7) { if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7) return TRUE; } + if (d_ptr->mflags8) { if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8) return TRUE; } + if (d_ptr->mflags9) { if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9) return TRUE; } + if (d_ptr->mflagsr) { if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr) return TRUE; } + for (a = 0; a < 5; a++) if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE; return FALSE; + } case DUNGEON_MODE_OR: + { if (r_ptr->flags1 & d_ptr->mflags1) return TRUE; if (r_ptr->flags2 & d_ptr->mflags2) return TRUE; if (r_ptr->flags3 & d_ptr->mflags3) return TRUE; @@ -1001,8 +974,10 @@ static bool restrict_monster_to_dungeon(player_type *player_ptr, MONRACE_IDX r_i if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE; return FALSE; + } case DUNGEON_MODE_NOR: + { if (r_ptr->flags1 & d_ptr->mflags1) return FALSE; if (r_ptr->flags2 & d_ptr->mflags2) return FALSE; if (r_ptr->flags3 & d_ptr->mflags3) return FALSE; @@ -1018,6 +993,7 @@ static bool restrict_monster_to_dungeon(player_type *player_ptr, MONRACE_IDX r_i return TRUE; } + } return TRUE; } @@ -1037,8 +1013,6 @@ monsterrace_hook_type get_mon_num2_hook; */ errr get_mon_num_prep(player_type *player_ptr, monsterrace_hook_type monster_hook, monsterrace_hook_type monster_hook2) { - int i; - /* Todo: Check the hooks for non-changes */ /* Set the new hooks */ @@ -1047,7 +1021,7 @@ errr get_mon_num_prep(player_type *player_ptr, monsterrace_hook_type monster_hoo /* Scan the allocation table */ floor_type *floor_ptr = player_ptr->current_floor_ptr; - for (i = 0; i < alloc_race_size; i++) + for (int i = 0; i < alloc_race_size; i++) { monster_race *r_ptr; @@ -1090,7 +1064,6 @@ errr get_mon_num_prep(player_type *player_ptr, monsterrace_hook_type monster_hoo } } - /* Success */ return 0; } @@ -1124,42 +1097,31 @@ errr get_mon_num_prep(player_type *player_ptr, monsterrace_hook_type monster_hoo */ MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level) { - int i, j, p; - MONRACE_IDX r_idx; - long value, total; - monster_race *r_ptr; - alloc_entry *table = alloc_race_table; - - int pls_kakuritu, pls_level; int delay = mysqrt(level * 10000L) + 400L; - pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10))); - pls_level = MIN(NASTY_MON_PLUS_MAX, 3 + current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10)); + int reinforcement_possibility = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10))); + int reinforcement_level = MIN(NASTY_MON_PLUS_MAX, 3 + current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10)); if (d_info[player_ptr->dungeon_idx].flags1 & DF1_MAZE) { - pls_kakuritu = MIN(pls_kakuritu / 2, pls_kakuritu - 10); - if (pls_kakuritu < 2) pls_kakuritu = 2; - pls_level += 2; + reinforcement_possibility = MIN(reinforcement_possibility / 2, reinforcement_possibility - 10); + if (reinforcement_possibility < 2) reinforcement_possibility = 2; + reinforcement_level += 2; level += 3; } /* Boost the level */ if (!player_ptr->phase_out && !(d_info[player_ptr->dungeon_idx].flags1 & DF1_BEGINNER)) { - /* Nightmare mode allows more out-of depth monsters */ - if (ironman_nightmare && !randint0(pls_kakuritu)) + if (ironman_nightmare && !randint0(reinforcement_possibility)) { - /* What a bizarre calculation */ level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH)); } else { - /* Occasional "nasty" monster */ - if (!randint0(pls_kakuritu)) + if (!randint0(reinforcement_possibility)) { - /* Pick a level bonus */ - level += pls_level; + level += reinforcement_level; } } } @@ -1167,11 +1129,11 @@ MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level) if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1; if (level < 0) level = 0; - /* Reset total */ - total = 0L; + long total = 0L; /* Process probabilities */ - for (i = 0; i < alloc_race_size; i++) + alloc_entry *table = alloc_race_table; + for (int i = 0; i < alloc_race_size; i++) { /* Monsters are sorted by depth */ if (table[i].level > level) break; @@ -1180,9 +1142,10 @@ MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level) table[i].prob3 = 0; /* Access the "r_idx" of the chosen monster */ - r_idx = table[i].index; + MONRACE_IDX r_idx = table[i].index; /* Access the actual race */ + monster_race *r_ptr; r_ptr = &r_info[r_idx]; if (!player_ptr->phase_out && !chameleon_change_m_idx) @@ -1219,67 +1182,68 @@ MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level) if (total <= 0) return 0; /* Pick a monster */ - value = randint0(total); + long value = randint0(total); - /* Find the monster */ - for (i = 0; i < alloc_race_size; i++) + int found_count = 0; + for (int i = 0; i < alloc_race_size; i++) { - /* Found the entry */ if (value < table[i].prob3) break; - - /* Decrement */ value = value - table[i].prob3; + found_count++; } /* Power boost */ - p = randint0(100); + int p = randint0(100); /* Try for a "harder" monster once (50%) or twice (10%) */ if (p < 60) { /* Save old */ - j = i; + int j = found_count; /* Pick a monster */ value = randint0(total); /* Find the monster */ - for (i = 0; i < alloc_race_size; i++) + for (found_count = 0; found_count < alloc_race_size; found_count++) { /* Found the entry */ - if (value < table[i].prob3) break; + if (value < table[found_count].prob3) break; /* Decrement */ - value = value - table[i].prob3; + value = value - table[found_count].prob3; } /* Keep the "best" one */ - if (table[i].level < table[j].level) i = j; + if (table[found_count].level < table[j].level) + found_count = j; } /* Try for a "harder" monster twice (10%) */ if (p < 10) { /* Save old */ - j = i; + int j = found_count; /* Pick a monster */ value = randint0(total); /* Find the monster */ - for (i = 0; i < alloc_race_size; i++) + for (found_count = 0; found_count < alloc_race_size; found_count++) { /* Found the entry */ - if (value < table[i].prob3) break; + if (value < table[found_count].prob3) break; /* Decrement */ - value = value - table[i].prob3; + value = value - table[found_count].prob3; } /* Keep the "best" one */ - if (table[i].level < table[j].level) i = j; + if (table[found_count].level < table[j].level) + found_count = j; } - return (table[i].index); + + return (table[found_count].index); } @@ -1338,22 +1302,15 @@ MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level) */ void monster_desc(player_type *player_ptr, char *desc, monster_type *m_ptr, BIT_FLAGS mode) { - concptr res; - monster_race *r_ptr; - - concptr name; - char buf[128]; - GAME_TEXT silly_name[1024]; - bool seen, pron; - bool named = FALSE; - + monster_race *r_ptr; r_ptr = &r_info[m_ptr->ap_r_idx]; /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */ - if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name); - else name = (r_name + r_ptr->name); + concptr name = (mode & MD_TRUE_NAME) ? (r_name + real_r_ptr(m_ptr)->name) : (r_name + r_ptr->name); /* Are we hallucinating? (Idea from Nethack...) */ + GAME_TEXT silly_name[1024]; + bool named = FALSE; if (player_ptr->image && !(mode & MD_IGNORE_HALLU)) { if (one_in_(2)) @@ -1379,11 +1336,10 @@ void monster_desc(player_type *player_ptr, char *desc, monster_type *m_ptr, BIT_ } /* Can we "see" it (exists + forced, or visible + not unforced) */ - seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml))); + bool seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml))); /* Sexed Pronouns (seen and allowed, or unseen and allowed) */ - pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN)))); - + bool pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN)))); /* First, try using pronouns, or describing hidden monsters */ floor_type *floor_ptr = player_ptr->current_floor_ptr; @@ -1401,12 +1357,11 @@ void monster_desc(player_type *player_ptr, char *desc, monster_type *m_ptr, BIT_ /* Assume simple result */ - res = _("何か", "it"); + concptr res = _("何か", "it"); /* Brute force: split on the possibilities */ switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE))) { - /* Neuter, or unknown */ #ifdef JP case 0x00: res = "何か"; break; case 0x00 + (MD_OBJECTIVE) : res = "何か"; break; @@ -1428,7 +1383,6 @@ void monster_desc(player_type *player_ptr, char *desc, monster_type *m_ptr, BIT_ #endif - /* Male (assume human if vague) */ #ifdef JP case 0x10: res = "彼"; break; case 0x10 + (MD_OBJECTIVE) : res = "彼"; break; @@ -1450,7 +1404,6 @@ void monster_desc(player_type *player_ptr, char *desc, monster_type *m_ptr, BIT_ #endif - /* Female (assume human if vague) */ #ifdef JP case 0x20: res = "彼女"; break; case 0x20 + (MD_OBJECTIVE) : res = "彼女"; break; @@ -1474,146 +1427,148 @@ void monster_desc(player_type *player_ptr, char *desc, monster_type *m_ptr, BIT_ /* Copy the result */ (void)strcpy(desc, res); + return; } - /* Handle visible monsters, "reflexive" request */ - else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE)) + if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE)) { /* The monster is visible, so use its gender */ if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, _("彼女自身", "herself")); else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, _("彼自身", "himself")); else strcpy(desc, _("それ自身", "itself")); + return; } - /* Handle all other visible monster requests */ - else + /* Tanuki? */ + if (is_pet(m_ptr) && !is_original_ap(m_ptr)) { - /* Tanuki? */ - if (is_pet(m_ptr) && !is_original_ap(m_ptr)) - { #ifdef JP - char *t; - strcpy(buf, name); - t = buf; - while (strncmp(t, "』", 2) && *t) t++; - if (*t) - { - *t = '\0'; - (void)sprintf(desc, "%s?』", buf); - } - else - (void)sprintf(desc, "%s?", name); -#else - (void)sprintf(desc, "%s?", name); -#endif + char *t; + char buf[128]; + strcpy(buf, name); + t = buf; + while (strncmp(t, "』", 2) && *t) t++; + if (*t) + { + *t = '\0'; + (void)sprintf(desc, "%s?』", buf); } else - - /* It could be a Unique */ - if ((r_ptr->flags1 & RF1_UNIQUE) && !(player_ptr->image && !(mode & MD_IGNORE_HALLU))) + (void)sprintf(desc, "%s?", name); +#else + (void)sprintf(desc, "%s?", name); +#endif + } + else + { + /* It could be a Unique */ + if ((r_ptr->flags1 & RF1_UNIQUE) && !(player_ptr->image && !(mode & MD_IGNORE_HALLU))) + { + /* Start with the name (thus nominative and objective) */ + if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME)) { - /* Start with the name (thus nominative and objective) */ - if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME)) - { #ifdef JP - char *t; - strcpy(buf, name); - t = buf; - while (strncmp(t, "』", 2) && *t) t++; - if (*t) - { - *t = '\0'; - (void)sprintf(desc, "%s?』", buf); - } - else - (void)sprintf(desc, "%s?", name); + char *t; + char buf[128]; + strcpy(buf, name); + t = buf; + while (strncmp(t, "』", 2) && *t) t++; + if (*t) + { + *t = '\0'; + (void)sprintf(desc, "%s?』", buf); + } + else + (void)sprintf(desc, "%s?", name); #else - (void)sprintf(desc, "%s?", name); + (void)sprintf(desc, "%s?", name); #endif - } + } - /* Inside monster arena, and it is not your mount */ - else if (player_ptr->phase_out && - !(player_ptr->riding && (&floor_ptr->m_list[player_ptr->riding] == m_ptr))) - { - /* It is a fake unique monster */ - (void)sprintf(desc, _("%sもどき", "fake %s"), name); - } + /* Inside monster arena, and it is not your mount */ + else if (player_ptr->phase_out && + !(player_ptr->riding && (&floor_ptr->m_list[player_ptr->riding] == m_ptr))) + { + /* It is a fake unique monster */ + (void)sprintf(desc, _("%sもどき", "fake %s"), name); + } - else - { - (void)strcpy(desc, name); - } + else + { + (void)strcpy(desc, name); } + } /* It could be an indefinite monster */ - else if (mode & MD_INDEF_VISIBLE) - { - /* XXX Check plurality for "some" */ + else if (mode & MD_INDEF_VISIBLE) + { + /* XXX Check plurality for "some" */ - /* Indefinite monsters need an indefinite article */ + /* Indefinite monsters need an indefinite article */ #ifdef JP - (void)strcpy(desc, ""); + (void)strcpy(desc, ""); #else - (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a "); + (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a "); #endif - (void)strcat(desc, name); - } + (void)strcat(desc, name); + } /* It could be a normal, definite, monster */ + else + { + /* Definite monsters need a definite article */ + if (is_pet(m_ptr)) + (void)strcpy(desc, _("あなたの", "your ")); else - { - /* Definite monsters need a definite article */ - if (is_pet(m_ptr)) - (void)strcpy(desc, _("あなたの", "your ")); - else - (void)strcpy(desc, _("", "the ")); - - (void)strcat(desc, name); - } + (void)strcpy(desc, _("", "the ")); - if (m_ptr->nickname) - { - sprintf(buf, _("「%s」", " called %s"), quark_str(m_ptr->nickname)); - strcat(desc, buf); + (void)strcat(desc, name); } + } - if (player_ptr->riding && (&floor_ptr->m_list[player_ptr->riding] == m_ptr)) - { - strcat(desc, _("(乗馬中)", "(riding)")); - } + if (m_ptr->nickname) + { + char buf[128]; + sprintf(buf, _("「%s」", " called %s"), quark_str(m_ptr->nickname)); + strcat(desc, buf); + } + + if (player_ptr->riding && (&floor_ptr->m_list[player_ptr->riding] == m_ptr)) + { + strcat(desc, _("(乗馬中)", "(riding)")); + } - if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON)) + if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON)) + { + if (r_ptr->flags1 & RF1_UNIQUE) { - if (r_ptr->flags1 & RF1_UNIQUE) - { - strcat(desc, _("(カメレオンの王)", "(Chameleon Lord)")); - } - else - { - strcat(desc, _("(カメレオン)", "(Chameleon)")); - } + strcat(desc, _("(カメレオンの王)", "(Chameleon Lord)")); } - - if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr)) + else { - strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name)); + strcat(desc, _("(カメレオン)", "(Chameleon)")); } + } - /* Handle the Possessive as a special afterthought */ - if (mode & MD_POSSESSIVE) - { - /* XXX Check for trailing "s" */ + if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr)) + { + strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name)); + } - /* Simply append "apostrophe" and "s" */ - (void)strcat(desc, _("の", "'s")); - } + /* Handle the Possessive as a special afterthought */ + if (mode & MD_POSSESSIVE) + { + /* XXX Check for trailing "s" */ + + /* Simply append "apostrophe" and "s" */ + (void)strcat(desc, _("の", "'s")); } } + /*! * @brief モンスターIDを取り、モンスター名をm_nameに代入する / * @param player_ptr プレーヤーへの参照ポインタ @@ -1637,17 +1592,15 @@ void monster_name(player_type *player_ptr, MONSTER_IDX m_idx, char* m_name) */ int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx) { - monster_race *r_ptr = &r_info[r_idx]; - int i, n = 0; - byte tmp_byte; - /* Maximal info about awareness */ + int n = 0; + monster_race *r_ptr = &r_info[r_idx]; if (r_ptr->r_wake != MAX_UCHAR) n++; if (r_ptr->r_ignore != MAX_UCHAR) n++; r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR; /* Observe "maximal" attacks */ - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { /* Examine "actual" blows */ if (r_ptr->blow[i].effect || r_ptr->blow[i].method) @@ -1659,7 +1612,7 @@ int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx) } /* Maximal drops */ - tmp_byte = + byte tmp_byte = (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) + ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) + ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) + @@ -1684,7 +1637,7 @@ int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx) r_ptr->r_cast_spell = MAX_UCHAR; /* Count unknown flags */ - for (i = 0; i < 32; i++) + for (int i = 0; i < 32; i++) { if (!(r_ptr->r_flags1 & (1L << i)) && (r_ptr->flags1 & (1L << i))) n++; @@ -1700,8 +1653,6 @@ int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx) (r_ptr->a_ability_flags2 & (1L << i))) n++; if (!(r_ptr->r_flagsr & (1L << i)) && (r_ptr->flagsr & (1L << i))) n++; - - /* r_flags7 is actually unused */ } /* Know all the flags */ @@ -1713,9 +1664,6 @@ int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx) r_ptr->r_flags6 = r_ptr->a_ability_flags2; r_ptr->r_flagsr = r_ptr->flagsr; - /* r_flags7 is actually unused */ - /* r_ptr->r_flags7 = r_ptr->flags7; */ - /* Know about evolution */ if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++; r_ptr->r_xtra1 |= MR1_SINKA; @@ -1726,7 +1674,6 @@ int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx) player_ptr->window |= (PW_MONSTER); } - /* Return the number of new flags learnt */ return n; } @@ -1752,7 +1699,6 @@ int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx) void lore_treasure(player_type *player_ptr, MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold) { monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx]; - monster_race *r_ptr = &r_info[m_ptr->r_idx]; /* If the monster doesn't have original appearance, don't note */ @@ -1843,7 +1789,6 @@ void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full) bool do_disturb = disturb_move; - POSITION d; POSITION fy = m_ptr->fy; POSITION fx = m_ptr->fx; @@ -1865,7 +1810,7 @@ void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full) do_disturb = TRUE; } - /* Compute distance */ + POSITION distance; if (full) { /* Distance components */ @@ -1873,31 +1818,31 @@ void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full) int dx = (subject_ptr->x > fx) ? (subject_ptr->x - fx) : (fx - subject_ptr->x); /* Approximate distance */ - d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1)); + distance = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1)); /* Restrict distance */ - if (d > 255) d = 255; + if (distance > 255) distance = 255; - if (!d) d = 1; + if (!distance) distance = 1; /* Save the distance */ - m_ptr->cdis = d; + m_ptr->cdis = distance; } /* Extract distance */ else { /* Extract the distance */ - d = m_ptr->cdis; + distance = m_ptr->cdis; } /* Detected */ if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE; /* Nearby */ - if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT)) + if (distance <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT)) { - if (!in_darkness || (d <= MAX_SIGHT / 4)) + if (!in_darkness || (distance <= MAX_SIGHT / 4)) { if (subject_ptr->special_defense & KATA_MUSOU) { @@ -2047,7 +1992,7 @@ void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full) } /* Use "infravision" */ - if (d <= subject_ptr->see_infra) + if (distance <= subject_ptr->see_infra) { /* Handle "cold blooded" monsters */ if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD) @@ -2100,7 +2045,6 @@ void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full) } } - /* The monster is now visible */ if (flag) { @@ -2182,24 +2126,22 @@ void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full) disturb(subject_ptr, TRUE, TRUE); } } + + return; } /* The monster is not easily visible */ - else - { - /* Change */ - if (m_ptr->mflag & (MFLAG_VIEW)) - { - /* Mark as not easily visible */ - m_ptr->mflag &= ~(MFLAG_VIEW); + /* Change */ + if (!(m_ptr->mflag & (MFLAG_VIEW))) return; - /* Disturb on disappearance */ - if (do_disturb) - { - if (disturb_pets || is_hostile(m_ptr)) - disturb(subject_ptr, TRUE, TRUE); - } - } + /* Mark as not easily visible */ + m_ptr->mflag &= ~(MFLAG_VIEW); + + /* Disturb on disappearance */ + if (do_disturb) + { + if (disturb_pets || is_hostile(m_ptr)) + disturb(subject_ptr, TRUE, TRUE); } } @@ -2212,11 +2154,9 @@ void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full) */ void update_monsters(player_type *player_ptr, bool full) { - MONSTER_IDX i; - /* Update each (live) monster */ floor_type *floor_ptr = player_ptr->current_floor_ptr; - for (i = 1; i < floor_ptr->m_max; i++) + for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++) { monster_type *m_ptr = &floor_ptr->m_list[i]; if (!monster_is_valid(m_ptr)) continue; @@ -2265,6 +2205,7 @@ static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx) return TRUE; } + /*! * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留 * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留 @@ -2306,6 +2247,7 @@ static bool monster_hook_chameleon(MONRACE_IDX r_idx) return (*(get_monster_hook(p_ptr)))(r_idx); } + /*! * @brief モンスターの変身処理 * @param player_ptr プレーヤーへの参照ポインタ @@ -2316,19 +2258,17 @@ static bool monster_hook_chameleon(MONRACE_IDX r_idx) */ void choose_new_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx) { - int oldmaxhp; floor_type *floor_ptr = player_ptr->current_floor_ptr; monster_type *m_ptr = &floor_ptr->m_list[m_idx]; monster_race *r_ptr; - char old_m_name[MAX_NLEN]; - bool old_unique = FALSE; - int old_r_idx = m_ptr->r_idx; + bool old_unique = FALSE; if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE) old_unique = TRUE; if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K; r_ptr = &r_info[r_idx]; + char old_m_name[MAX_NLEN]; monster_desc(player_ptr, old_m_name, m_ptr, 0); if (!r_idx) @@ -2362,6 +2302,7 @@ void choose_new_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool born, M update_monster(player_ptr, m_idx, FALSE); lite_spot(m_ptr->fy, m_ptr->fx); + int old_r_idx = m_ptr->r_idx; if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) || (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))) player_ptr->update |= (PU_MON_LITE); @@ -2390,7 +2331,7 @@ void choose_new_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool born, M /* Extract the monster base speed */ m_ptr->mspeed = get_mspeed(player_ptr, r_ptr); - oldmaxhp = m_ptr->max_maxhp; + int oldmaxhp = m_ptr->max_maxhp; /* Assign maximal hitpoints */ if (r_ptr->flags1 & RF1_FORCE_MAXHP) { @@ -2411,8 +2352,6 @@ void choose_new_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool born, M m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp; if (m_ptr->maxhp < 1) m_ptr->maxhp = 1; m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp; - - /* reset dealt_damage */ m_ptr->dealt_damage = 0; } @@ -2449,10 +2388,6 @@ static bool monster_hook_tanuki(MONRACE_IDX r_idx) static MONRACE_IDX initial_r_appearance(player_type *player_ptr, MONRACE_IDX r_idx, BIT_FLAGS generate_mode) { floor_type *floor_ptr = player_ptr->current_floor_ptr; - int attempts = 1000; - MONRACE_IDX ap_r_idx; - DEPTH min = MIN(floor_ptr->base_level - 5, 50); - if (player_ptr->pseikaku == SEIKAKU_CHARGEMAN && !(generate_mode & (PM_MULTIPLY | PM_KAGE))) { if (floor_ptr->base_level == 0 || @@ -2464,9 +2399,11 @@ static MONRACE_IDX initial_r_appearance(player_type *player_ptr, MONRACE_IDX r_i get_mon_num_prep(player_ptr, monster_hook_tanuki, NULL); + int attempts = 1000; + DEPTH min = MIN(floor_ptr->base_level - 5, 50); while (--attempts) { - ap_r_idx = get_mon_num(player_ptr, floor_ptr->base_level + 10); + MONRACE_IDX ap_r_idx = get_mon_num(player_ptr, floor_ptr->base_level + 10); if (r_info[ap_r_idx].level >= min) return ap_r_idx; } @@ -2528,12 +2465,10 @@ SPEED get_mspeed(player_type *player_ptr, monster_race *r_ptr) static bool place_monster_one(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode) { floor_type *floor_ptr = player_ptr->current_floor_ptr; - grid_type *g_ptr = &floor_ptr->grid_array[y][x]; - monster_type *m_ptr; - monster_race *r_ptr = &r_info[r_idx]; - concptr name = (r_name + r_ptr->name); - - int cmi; + grid_type *g_ptr = &floor_ptr->grid_array[y][x]; + monster_type *m_ptr; + monster_race *r_ptr = &r_info[r_idx]; + concptr name = (r_name + r_ptr->name); /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */ if (player_ptr->wild_mode) return FALSE; @@ -2675,7 +2610,7 @@ static bool place_monster_one(player_type *player_ptr, MONSTER_IDX who, POSITION m_ptr->current_floor_ptr = floor_ptr; /* No "timed status" yet */ - for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0; + for (int cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0; /* Unknown distance */ m_ptr->cdis = 0; @@ -2860,42 +2795,37 @@ static bool place_monster_one(player_type *player_ptr, MONSTER_IDX who, POSITION } } - if (is_explosive_rune_grid(g_ptr)) + if (!is_explosive_rune_grid(g_ptr)) return TRUE; + + /* Break the ward */ + if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level) { - /* Break the ward */ - if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level) - { - /* Describe observable breakage */ - if (g_ptr->info & CAVE_MARK) - { - msg_print(_("ルーンが爆発した!", "The rune explodes!")); - project(player_ptr, 0, 2, y, x, 2 * (player_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1); - } - } - else + /* Describe observable breakage */ + if (g_ptr->info & CAVE_MARK) { - msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed.")); + msg_print(_("ルーンが爆発した!", "The rune explodes!")); + project(player_ptr, 0, 2, y, x, 2 * (player_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1); } + } + else + { + msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed.")); + } - /* Forget the rune */ - g_ptr->info &= ~(CAVE_MARK); + /* Forget the rune */ + g_ptr->info &= ~(CAVE_MARK); - /* Break the rune */ - g_ptr->info &= ~(CAVE_OBJECT); - g_ptr->mimic = 0; + /* Break the rune */ + g_ptr->info &= ~(CAVE_OBJECT); + g_ptr->mimic = 0; - note_spot(y, x); - lite_spot(y, x); - } + note_spot(y, x); + lite_spot(y, x); - /* Success */ return TRUE; } - -#define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */ - /*! * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster * @param player_ptr プレーヤーへの参照ポインタ @@ -2913,19 +2843,18 @@ static bool mon_scatter(player_type *player_ptr, MONRACE_IDX r_idx, POSITION *yp POSITION place_x[MON_SCAT_MAXD]; POSITION place_y[MON_SCAT_MAXD]; int num[MON_SCAT_MAXD]; - int i; - POSITION nx, ny; if (max_dist >= MON_SCAT_MAXD) return FALSE; + int i; for (i = 0; i < MON_SCAT_MAXD; i++) num[i] = 0; floor_type *floor_ptr = player_ptr->current_floor_ptr; - for (nx = x - max_dist; nx <= x + max_dist; nx++) + for (POSITION nx = x - max_dist; nx <= x + max_dist; nx++) { - for (ny = y - max_dist; ny <= y + max_dist; ny++) + for (POSITION ny = y - max_dist; ny <= y + max_dist; ny++) { /* Ignore annoying locations */ if (!in_bounds(floor_ptr, ny, nx)) continue; @@ -2990,21 +2919,11 @@ static bool mon_scatter(player_type *player_ptr, MONRACE_IDX r_idx, POSITION *yp static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode) { monster_race *r_ptr = &r_info[r_idx]; - - int n, i; - int total = 0, extra = 0; - - int hack_n = 0; - - POSITION hack_y[GROUP_MAX]; - POSITION hack_x[GROUP_MAX]; - - - /* Pick a group size */ - total = randint1(10); + int total = randint1(10); /* Hard monsters, small groups */ floor_type *floor_ptr = player_ptr->current_floor_ptr; + int extra = 0; if (r_ptr->level > floor_ptr->dun_level) { extra = r_ptr->level - floor_ptr->dun_level; @@ -3032,19 +2951,21 @@ static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITI /* Start on the monster */ - hack_n = 1; + int hack_n = 1; + POSITION hack_x[GROUP_MAX]; hack_x[0] = x; + POSITION hack_y[GROUP_MAX]; hack_y[0] = y; /* Puddle monsters, breadth first, up to total */ - for (n = 0; (n < hack_n) && (hack_n < total); n++) + for (int n = 0; (n < hack_n) && (hack_n < total); n++) { /* Grab the location */ POSITION hx = hack_x[n]; POSITION hy = hack_y[n]; /* Check each direction, up to total */ - for (i = 0; (i < 8) && (hack_n < total); i++) + for (int i = 0; (i < 8) && (hack_n < total); i++) { POSITION mx, my; @@ -3064,11 +2985,10 @@ static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITI } } - - /* Success */ return TRUE; } + /*! * @var place_monster_idx * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type @@ -3094,7 +3014,6 @@ static bool place_monster_can_escort(MONRACE_IDX r_idx) { monster_race *r_ptr = &r_info[place_monster_idx]; monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[place_monster_m_idx]; - monster_race *z_ptr = &r_info[r_idx]; /* Hack - Escorts have to have the same dungeon flag */ @@ -3154,8 +3073,7 @@ static bool place_monster_can_escort(MONRACE_IDX r_idx) */ bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode) { - int i, j, n; - monster_race *r_ptr = &r_info[r_idx]; + monster_race *r_ptr = &r_info[r_idx]; if (!(mode & PM_NO_KAGE) && one_in_(333)) mode |= PM_KAGE; @@ -3169,11 +3087,11 @@ bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POS place_monster_m_idx = hack_m_idx_ii; /* Reinforcement */ - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { if (!r_ptr->reinforce_id[i]) break; - n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]); - for (j = 0; j < n; j++) + int n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]); + for (int j = 0; j < n; j++) { POSITION nx, ny, d = 7; scatter(player_ptr, &ny, &nx, y, x, d, 0); @@ -3189,47 +3107,46 @@ bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POS } /* Escorts for certain monsters */ - if (r_ptr->flags1 & (RF1_ESCORT)) - { - /* Set the escort index */ - place_monster_idx = r_idx; + if (!(r_ptr->flags1 & (RF1_ESCORT))) return TRUE; - /* Try to place several "escorts" */ - for (i = 0; i < 32; i++) - { - POSITION nx, ny, d = 3; - MONRACE_IDX z; + /* Set the escort index */ + place_monster_idx = r_idx; - /* Pick a location */ - scatter(player_ptr, &ny, &nx, y, x, d, 0); + /* Try to place several "escorts" */ + for (int i = 0; i < 32; i++) + { + POSITION nx, ny, d = 3; + MONRACE_IDX z; + + /* Pick a location */ + scatter(player_ptr, &ny, &nx, y, x, d, 0); - /* Require empty grids */ - if (!cave_empty_bold2(player_ptr->current_floor_ptr, ny, nx)) continue; - get_mon_num_prep(player_ptr, place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx)); + /* Require empty grids */ + if (!cave_empty_bold2(player_ptr->current_floor_ptr, ny, nx)) continue; + get_mon_num_prep(player_ptr, place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx)); - /* Pick a random race */ - z = get_mon_num(player_ptr, r_ptr->level); + /* Pick a random race */ + z = get_mon_num(player_ptr, r_ptr->level); - /* Handle failure */ - if (!z) break; + /* Handle failure */ + if (!z) break; - /* Place a single escort */ - (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, z, mode); + /* Place a single escort */ + (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, z, mode); - /* Place a "group" of escorts if needed */ - if ((r_info[z].flags1 & RF1_FRIENDS) || - (r_ptr->flags1 & RF1_ESCORTS)) - { - /* Place a group of monsters */ - (void)place_monster_group(player_ptr, place_monster_m_idx, ny, nx, z, mode); - } + /* Place a "group" of escorts if needed */ + if ((r_info[z].flags1 & RF1_FRIENDS) || + (r_ptr->flags1 & RF1_ESCORTS)) + { + /* Place a group of monsters */ + (void)place_monster_group(player_ptr, place_monster_m_idx, ny, nx, z, mode); } } - /* Success */ return TRUE; } + /*! * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location * @param player_ptr プレーヤーへの参照ポインタ @@ -3255,6 +3172,7 @@ bool place_monster(player_type *player_ptr, POSITION y, POSITION x, BIT_FLAGS mo return FALSE; } + /*! * @brief 指定地点に1種類のモンスター種族による群れを生成する * @param player_ptr プレーヤーへの参照ポインタ @@ -3264,15 +3182,12 @@ bool place_monster(player_type *player_ptr, POSITION y, POSITION x, BIT_FLAGS mo */ bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x) { - monster_race *r_ptr = NULL; - MONRACE_IDX r_idx = 0; - MONSTER_IDX m_idx; - int attempts = 1000; - POSITION cy = y; - POSITION cx = x; get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x)); floor_type *floor_ptr = player_ptr->current_floor_ptr; + MONRACE_IDX r_idx = 0; + int attempts = 1000; + monster_race *r_ptr = NULL; while (--attempts) { /* Pick a monster */ @@ -3288,6 +3203,7 @@ bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x) if (r_idx == MON_HAGURE) continue; break; } + if (attempts < 1) return FALSE; attempts = 1000; @@ -3300,10 +3216,12 @@ bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x) if (attempts < 1) return FALSE; - m_idx = floor_ptr->grid_array[y][x].m_idx; + MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx; if (floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[floor_ptr->m_list[m_idx].r_idx]; + POSITION cy = y; + POSITION cx = x; for (attempts = randint1(10) + 5; attempts; attempts--) { scatter(player_ptr, &cy, &cx, y, x, 5, 0); @@ -3329,34 +3247,38 @@ bool alloc_guardian(player_type *player_ptr, bool def_val) MONRACE_IDX guardian = d_info[player_ptr->dungeon_idx].final_guardian; floor_type *floor_ptr = player_ptr->current_floor_ptr; - if (guardian && (d_info[player_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num)) + bool is_guardian_applicable = guardian > 0; + is_guardian_applicable &= d_info[player_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level; + is_guardian_applicable &= r_info[guardian].cur_num < r_info[guardian].max_num; + if (!is_guardian_applicable) return def_val; + + int try_count = 4000; + while (try_count) { - POSITION oy; - POSITION ox; - int try_count = 4000; + /* Get a random spot */ + POSITION oy = randint1(floor_ptr->height - 4) + 2; + POSITION ox = randint1(floor_ptr->width - 4) + 2; - /* Find a good position */ - while (try_count) + /* Is it a good spot ? */ + if (!cave_empty_bold2(floor_ptr, oy, ox)) { - /* Get a random spot */ - oy = randint1(floor_ptr->height - 4) + 2; - ox = randint1(floor_ptr->width - 4) + 2; - - /* Is it a good spot ? */ - if (cave_empty_bold2(floor_ptr, oy, ox) && monster_can_cross_terrain(floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0)) - { - /* Place the guardian */ - if (place_monster_aux(player_ptr, 0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE; - } + try_count++; + continue; + } - /* One less try count */ - try_count--; + if (!monster_can_cross_terrain(floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0)) + { + try_count++; + continue; } - return FALSE; + if (place_monster_aux(player_ptr, 0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) + return TRUE; + + try_count--; } - return def_val; + return FALSE; } @@ -3372,14 +3294,13 @@ bool alloc_guardian(player_type *player_ptr, bool def_val) */ bool alloc_monster(player_type *player_ptr, POSITION dis, BIT_FLAGS mode) { - POSITION y = 0, x = 0; - int attempts_left = 10000; - /* Put the Guardian */ if (alloc_guardian(player_ptr, FALSE)) return TRUE; /* Find a legal, distant, unoccupied, space */ floor_type *floor_ptr = player_ptr->current_floor_ptr; + POSITION y = 0, x = 0; + int attempts_left = 10000; while (attempts_left--) { /* Pick a location */ @@ -3511,12 +3432,10 @@ static bool summon_specific_okay(MONRACE_IDX r_idx) */ bool summon_specific(player_type *player_ptr, MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode) { - POSITION x, y; - MONRACE_IDX r_idx; - floor_type *floor_ptr = player_ptr->current_floor_ptr; if (floor_ptr->inside_arena) return FALSE; + POSITION x, y; if (!mon_scatter(player_ptr, 0, &y, &x, y1, x1, 2)) return FALSE; /* Save the summoner */ @@ -3529,7 +3448,7 @@ bool summon_specific(player_type *player_ptr, MONSTER_IDX who, POSITION y1, POSI get_mon_num_prep(player_ptr, summon_specific_okay, get_monster_hook2(player_ptr, y, x)); /* Pick a monster, using the level calculation */ - r_idx = get_mon_num(player_ptr, (floor_ptr->dun_level + lev) / 2 + 5); + MONRACE_IDX r_idx = get_mon_num(player_ptr, (floor_ptr->dun_level + lev) / 2 + 5); /* Handle failure */ if (!r_idx) @@ -3566,12 +3485,10 @@ bool summon_specific(player_type *player_ptr, MONSTER_IDX who, POSITION y1, POSI */ bool summon_named_creature(player_type *player_ptr, MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode) { - POSITION x, y; - /* if (!r_idx) return; */ - /* Prevent illegal monsters */ if (r_idx >= max_r_idx) return FALSE; + POSITION x, y; if (player_ptr->current_floor_ptr->inside_arena) return FALSE; if (!mon_scatter(player_ptr, r_idx, &y, &x, oy, ox, 2)) return FALSE; @@ -3596,7 +3513,6 @@ bool multiply_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool clone, BI floor_type *floor_ptr = player_ptr->current_floor_ptr; monster_type *m_ptr = &floor_ptr->m_list[m_idx]; POSITION y, x; - if (!mon_scatter(player_ptr, m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1)) return FALSE; @@ -3645,7 +3561,6 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) return; } - /* Note -- subtle fix -CFT */ newhp = m_ptr->hp; oldhp = newhp + dam; tmp = (newhp * 100L) / oldhp; @@ -3661,6 +3576,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは身もだえした。", m_name); else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name); else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name); + return; #else if (percentage > 95) msg_format("%^s barely notices.", m_name); else if (percentage > 75) msg_format("%^s flinches.", m_name); @@ -3669,10 +3585,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s writhes about.", m_name); else if (percentage > 10) msg_format("%^s writhes in agony.", m_name); else msg_format("%^s jerks limply.", m_name); + return; #endif } - else if (my_strchr("l", r_ptr->d_char)) // Fish + if (my_strchr("l", r_ptr->d_char)) // Fish { #ifdef JP if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name); @@ -3682,6 +3599,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは身もだえした。", m_name); else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name); else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name); + return; #else if (percentage > 95) msg_format("%^s barely notices.", m_name); else if (percentage > 75) msg_format("%^s flinches.", m_name); @@ -3690,10 +3608,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s writhes about.", m_name); else if (percentage > 10) msg_format("%^s writhes in agony.", m_name); else msg_format("%^s jerks limply.", m_name); + return; #endif } - else if (my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs + if (my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs { #ifdef JP if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name); @@ -3703,6 +3622,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sはうめいた。", m_name); else if (percentage > 10) msg_format("%^sは躊躇した。", m_name); else msg_format("%^sはくしゃくしゃになった。", m_name); + return; #else if (percentage > 95) msg_format("%^s ignores the attack.", m_name); else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name); @@ -3711,10 +3631,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s grunts.", m_name); else if (percentage > 10) msg_format("%^s hesitates.", m_name); else msg_format("%^s crumples.", m_name); + return; #endif } - else if (my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics + if (my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics { #ifdef JP if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name); @@ -3724,6 +3645,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは身もだえした。", m_name); else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name); else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name); + return; #else if (percentage > 95) msg_format("%^s barely notices.", m_name); else if (percentage > 75) msg_format("%^s hisses.", m_name); @@ -3732,10 +3654,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s writhes about.", m_name); else if (percentage > 10) msg_format("%^s writhes in agony.", m_name); else msg_format("%^s jerks limply.", m_name); + return; #endif } - else if (my_strchr("f", r_ptr->d_char)) + if (my_strchr("f", r_ptr->d_char)) { #ifdef JP if (percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name); @@ -3745,6 +3668,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name); else if (percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name); else msg_format("%sは哀れな鳴き声を出した。", m_name); + return; #else if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name); else if (percentage > 75) msg_format("%^s roars.", m_name); @@ -3753,10 +3677,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s mewls in pain.", m_name); else if (percentage > 10) msg_format("%^s hisses in agony.", m_name); else msg_format("%^s mewls pitifully.", m_name); + return; #endif } - else if (my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders + if (my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders { #ifdef JP if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name); @@ -3766,6 +3691,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name); else if (percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name); else msg_format("%^sはピクピクひきつった。", m_name); + return; #else if (percentage > 95) msg_format("%^s ignores the attack.", m_name); else if (percentage > 75) msg_format("%^s chitters.", m_name); @@ -3774,10 +3700,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s jerks in pain.", m_name); else if (percentage > 10) msg_format("%^s jerks in agony.", m_name); else msg_format("%^s twitches.", m_name); + return; #endif } - else if (my_strchr("B", r_ptr->d_char)) // Birds + if (my_strchr("B", r_ptr->d_char)) // Birds { #ifdef JP if (percentage > 95) msg_format("%^sはさえずった。", m_name); @@ -3787,6 +3714,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは苦しんだ。", m_name); else if (percentage > 10) msg_format("%^sはのたうち回った。", m_name); else msg_format("%^sはキーキーと鳴き叫んだ。", m_name); + return; #else if (percentage > 95) msg_format("%^s chirps.", m_name); else if (percentage > 75) msg_format("%^s twitters.", m_name); @@ -3795,10 +3723,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s jeers.", m_name); else if (percentage > 10) msg_format("%^s flutters about.", m_name); else msg_format("%^s squeaks.", m_name); + return; #endif } - else if (my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead + if (my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead { #ifdef JP if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name); @@ -3808,6 +3737,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは痛みに吠えた。", m_name); else if (percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name); else msg_format("%^sは弱々しくうなった。", m_name); + return; #else if (percentage > 95) msg_format("%^s ignores the attack.", m_name); else if (percentage > 75) msg_format("%^s flinches.", m_name); @@ -3816,10 +3746,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s roars with pain.", m_name); else if (percentage > 10) msg_format("%^s gasps.", m_name); else msg_format("%^s snarls feebly.", m_name); + return; #endif } - else if (my_strchr("s", r_ptr->d_char)) // Skeletons + if (my_strchr("s", r_ptr->d_char)) // Skeletons { #ifdef JP if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name); @@ -3829,6 +3760,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sはカタカタ言った。", m_name); else if (percentage > 10) msg_format("%^sはよろめいた。", m_name); else msg_format("%^sはガタガタ言った。", m_name); + return; #else if (percentage > 95) msg_format("%^s ignores the attack.", m_name); else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name); @@ -3837,10 +3769,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s rattles.", m_name); else if (percentage > 10) msg_format("%^s staggers.", m_name); else msg_format("%^s clatters.", m_name); + return; #endif } - else if (my_strchr("z", r_ptr->d_char)) // Zombies + if (my_strchr("z", r_ptr->d_char)) // Zombies { #ifdef JP if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name); @@ -3850,6 +3783,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは躊躇した。", m_name); else if (percentage > 10) msg_format("%^sはうなった。", m_name); else msg_format("%^sはよろめいた。", m_name); + return; #else if (percentage > 95) msg_format("%^s ignores the attack.", m_name); else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name); @@ -3858,10 +3792,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s hesitates.", m_name); else if (percentage > 10) msg_format("%^s grunts.", m_name); else msg_format("%^s staggers.", m_name); + return; #endif } - else if (my_strchr("G", r_ptr->d_char)) // Ghosts + if (my_strchr("G", r_ptr->d_char)) // Ghosts { #ifdef JP if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name); @@ -3871,6 +3806,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは吠えた。", m_name); else if (percentage > 10) msg_format("%sは弱々しくうめいた。", m_name); else msg_format("%^sはかすかにうめいた。", m_name); + return; #else if (percentage > 95) msg_format("%^s ignores the attack.", m_name); else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name); @@ -3879,10 +3815,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s howls.", m_name); else if (percentage > 10) msg_format("%^s moans softly.", m_name); else msg_format("%^s sighs.", m_name); + return; #endif } - else if (my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds + if (my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds { #ifdef JP if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name); @@ -3892,6 +3829,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name); else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name); else msg_format("%^sは弱々しく吠えた。", m_name); + return; #else if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name); else if (percentage > 75) msg_format("%^s snarls with pain.", m_name); @@ -3900,10 +3838,11 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s howls in agony.", m_name); else if (percentage > 10) msg_format("%^s writhes in agony.", m_name); else msg_format("%^s yelps feebly.", m_name); + return; #endif } - else if (my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek) + if (my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek) { #ifdef JP if (percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name); @@ -3913,6 +3852,7 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name); else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name); else msg_format("%^sは弱々しく叫んだ。", m_name); + return; #else if (percentage > 95) msg_format("%^s ignores the attack.", m_name); else if (percentage > 75) msg_format("%^s grunts with pain.", m_name); @@ -3921,29 +3861,27 @@ void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam) else if (percentage > 20) msg_format("%^s shrieks in agony.", m_name); else if (percentage > 10) msg_format("%^s writhes in agony.", m_name); else msg_format("%^s cries out feebly.", m_name); + return; #endif } - else // Another type of creatures (shrug,cry,scream) - { #ifdef JP - if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name); - else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name); - else if (percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name); - else if (percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name); - else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name); - else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name); - else msg_format("%^sは弱々しく叫んだ。", m_name); + if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name); + else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name); + else if (percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name); + else if (percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name); + else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name); + else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name); + else msg_format("%^sは弱々しく叫んだ。", m_name); #else - if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name); - else if (percentage > 75) msg_format("%^s grunts with pain.", m_name); - else if (percentage > 50) msg_format("%^s cries out in pain.", m_name); - else if (percentage > 35) msg_format("%^s screams in pain.", m_name); - else if (percentage > 20) msg_format("%^s screams in agony.", m_name); - else if (percentage > 10) msg_format("%^s writhes in agony.", m_name); - else msg_format("%^s cries out feebly.", m_name); + if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name); + else if (percentage > 75) msg_format("%^s grunts with pain.", m_name); + else if (percentage > 50) msg_format("%^s cries out in pain.", m_name); + else if (percentage > 35) msg_format("%^s screams in pain.", m_name); + else if (percentage > 20) msg_format("%^s screams in agony.", m_name); + else if (percentage > 10) msg_format("%^s writhes in agony.", m_name); + else msg_format("%^s cries out feebly.", m_name); #endif - } } @@ -4067,34 +4005,28 @@ void update_smart_learn(player_type *player_ptr, MONSTER_IDX m_idx, int what) */ void monster_drop_carried_objects(player_type *player_ptr, monster_type *m_ptr) { - OBJECT_IDX this_o_idx, next_o_idx = 0; - object_type forge; - object_type *o_ptr; - object_type *q_ptr; - /* Drop objects being carried */ floor_type *floor_ptr = player_ptr->current_floor_ptr; - for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) + OBJECT_IDX next_o_idx = 0; + for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) { + object_type forge; + object_type *o_ptr; + object_type *q_ptr; o_ptr = &floor_ptr->o_list[this_o_idx]; next_o_idx = o_ptr->next_o_idx; q_ptr = &forge; object_copy(q_ptr, o_ptr); - - /* Forget monster */ q_ptr->held_m_idx = 0; - delete_object_idx(floor_ptr, this_o_idx); - - /* Drop it */ (void)drop_near(player_ptr, q_ptr, -1, m_ptr->fy, m_ptr->fx); } - /* Forget objects */ m_ptr->hold_o_idx = 0; } + /*! * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留 * @brief 指定したモンスターに隣接しているモンスターの数を返す。 @@ -4109,17 +4041,13 @@ int get_monster_crowd_number(player_type *player_ptr, MONSTER_IDX m_idx) monster_type *m_ptr = &floor_ptr->m_list[m_idx]; POSITION my = m_ptr->fy; POSITION mx = m_ptr->fx; - int i; int count = 0; - - for (i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { int ay = my + ddy_ddd[i]; int ax = mx + ddx_ddd[i]; if (!in_bounds(floor_ptr, ay, ax)) continue; - - /* Count number of monsters */ if (floor_ptr->grid_array[ay][ax].m_idx > 0) count++; } -- 2.11.0