1 #include "monster/monster-compaction.h"
2 #include "core/stuff-handler.h"
3 #include "game-option/play-record-options.h"
5 #include "io/write-diary.h"
6 #include "monster-floor/monster-remover.h"
7 #include "monster-race/monster-race.h"
8 #include "monster-race/race-flags1.h"
9 #include "monster/monster-describer.h"
10 #include "monster/monster-description-types.h"
11 #include "monster/monster-info.h"
12 #include "monster/monster-status.h"
13 #include "system/floor-type-definition.h"
14 #include "system/monster-type-definition.h"
15 #include "system/object-type-definition.h"
16 #include "target/target-checker.h"
17 #include "view/display-messages.h"
20 * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
21 * @param player_ptr プレーヤーへの参照ポインタ
26 static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTER_IDX i2)
31 floor_type *floor_ptr = player_ptr->current_floor_ptr;
33 m_ptr = &floor_ptr->m_list[i1];
35 POSITION y = m_ptr->fy;
36 POSITION x = m_ptr->fx;
38 g_ptr = &floor_ptr->grid_array[y][x];
41 OBJECT_IDX next_o_idx = 0;
42 for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) {
44 o_ptr = &floor_ptr->o_list[this_o_idx];
45 next_o_idx = o_ptr->next_o_idx;
46 o_ptr->held_m_idx = i2;
52 if (player_ptr->pet_t_m_idx == i1)
53 player_ptr->pet_t_m_idx = i2;
54 if (player_ptr->riding_t_m_idx == i1)
55 player_ptr->riding_t_m_idx = i2;
57 if (player_ptr->riding == i1)
58 player_ptr->riding = i2;
60 if (player_ptr->health_who == i1)
61 health_track(player_ptr, i2);
64 for (int i = 1; i < floor_ptr->m_max; i++) {
65 monster_type *m2_ptr = &floor_ptr->m_list[i];
67 if (m2_ptr->parent_m_idx == i1)
68 m2_ptr->parent_m_idx = i2;
72 (void)COPY(&floor_ptr->m_list[i2], &floor_ptr->m_list[i1], monster_type);
73 (void)WIPE(&floor_ptr->m_list[i1], monster_type);
75 for (int i = 0; i < MAX_MTIMED; i++) {
76 int mproc_idx = get_mproc_idx(floor_ptr, i1, i);
78 floor_ptr->mproc_list[i][mproc_idx] = i2;
83 * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
84 * @param player_ptr プレーヤーへの参照ポインタ
85 * @param size 圧縮後のモンスター件数目標
88 * This function can be very dangerous, use with caution!
90 * When actually "compacting" monsters, we base the saving throw
91 * on a combination of monster level, distance from player, and
92 * current "desperation".
94 * After "compacting" (if needed), we "reorder" the monsters into a more
95 * compact order, and we reset the allocation info, and the "live" array.
97 void compact_monsters(player_type *player_ptr, int size)
100 msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
102 /* Compact at least 'size' objects */
103 floor_type *floor_ptr = player_ptr->current_floor_ptr;
104 for (int num = 0, cnt = 1; num < size; cnt++) {
105 int cur_lev = 5 * cnt;
106 int cur_dis = 5 * (20 - cnt);
107 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++) {
108 monster_type *m_ptr = &floor_ptr->m_list[i];
109 monster_race *r_ptr = &r_info[m_ptr->r_idx];
110 if (!monster_is_valid(m_ptr))
112 if (r_ptr->level > cur_lev)
114 if (i == player_ptr->riding)
116 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis))
120 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000))
123 if (r_ptr->flags1 & (RF1_UNIQUE))
126 if (randint0(100) < chance)
129 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname) {
130 GAME_TEXT m_name[MAX_NLEN];
131 monster_desc(player_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
132 exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
135 delete_monster_idx(player_ptr, i);
140 /* Excise dead monsters (backwards!) */
141 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--) {
142 monster_type *m_ptr = &floor_ptr->m_list[i];
145 compact_monsters_aux(player_ptr, floor_ptr->m_max - 1, i);