1 #include "monster/monster-compaction.h"
2 #include "core/stuff-handler.h"
3 #include "game-option/play-record-options.h"
4 #include "io/write-diary.h"
5 #include "monster-floor/monster-remover.h"
6 #include "monster-race/monster-race.h"
7 #include "monster-race/race-flags1.h"
8 #include "monster/monster-describer.h"
9 #include "monster/monster-description-types.h"
10 #include "monster/monster-info.h"
11 #include "monster/monster-status.h"
12 #include "system/floor-type-definition.h"
13 #include "system/grid-type-definition.h"
14 #include "system/item-entity.h"
15 #include "system/monster-race-definition.h"
16 #include "system/monster-type-definition.h"
17 #include "system/player-type-definition.h"
18 #include "target/target-checker.h"
19 #include "view/display-messages.h"
22 * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
23 * @param player_ptr プレイヤーへの参照ポインタ
27 static void compact_monsters_aux(PlayerType *player_ptr, MONSTER_IDX i1, MONSTER_IDX i2)
33 auto *floor_ptr = player_ptr->current_floor_ptr;
35 m_ptr = &floor_ptr->m_list[i1];
37 POSITION y = m_ptr->fy;
38 POSITION x = m_ptr->fx;
40 g_ptr = &floor_ptr->grid_array[y][x];
43 for (const auto this_o_idx : m_ptr->hold_o_idx_list) {
45 o_ptr = &floor_ptr->o_list[this_o_idx];
46 o_ptr->held_m_idx = i2;
49 if (target_who == i1) {
53 if (player_ptr->pet_t_m_idx == i1) {
54 player_ptr->pet_t_m_idx = i2;
56 if (player_ptr->riding_t_m_idx == i1) {
57 player_ptr->riding_t_m_idx = i2;
60 if (player_ptr->riding == i1) {
61 player_ptr->riding = i2;
64 if (player_ptr->health_who == i1) {
65 health_track(player_ptr, i2);
68 if (m_ptr->is_pet()) {
69 for (int i = 1; i < floor_ptr->m_max; i++) {
70 MonsterEntity *m2_ptr = &floor_ptr->m_list[i];
72 if (m2_ptr->parent_m_idx == i1) {
73 m2_ptr->parent_m_idx = i2;
78 floor_ptr->m_list[i2] = floor_ptr->m_list[i1];
79 floor_ptr->m_list[i1] = {};
81 for (int i = 0; i < MAX_MTIMED; i++) {
82 int mproc_idx = get_mproc_idx(floor_ptr, i1, i);
84 floor_ptr->mproc_list[i][mproc_idx] = i2;
90 * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
91 * @param player_ptr プレイヤーへの参照ポインタ
92 * @param size 圧縮後のモンスター件数目標
94 * This function can be very dangerous, use with caution!
96 * When actually "compacting" monsters, we base the saving throw
97 * on a combination of monster level, distance from player, and
98 * current "desperation".
100 * After "compacting" (if needed), we "reorder" the monsters into a more
101 * compact order, and we reset the allocation info, and the "live" array.
103 void compact_monsters(PlayerType *player_ptr, int size)
106 msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
109 /* Compact at least 'size' objects */
110 auto *floor_ptr = player_ptr->current_floor_ptr;
111 for (int num = 0, cnt = 1; num < size; cnt++) {
112 int cur_lev = 5 * cnt;
113 int cur_dis = 5 * (20 - cnt);
114 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++) {
115 auto *m_ptr = &floor_ptr->m_list[i];
116 auto *r_ptr = &monraces_info[m_ptr->r_idx];
117 if (!m_ptr->is_valid()) {
120 if (r_ptr->level > cur_lev) {
123 if (i == player_ptr->riding) {
126 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) {
131 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) {
135 if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) {
139 if (randint0(100) < chance) {
143 if (record_named_pet && m_ptr->is_pet() && m_ptr->nickname) {
144 GAME_TEXT m_name[MAX_NLEN];
145 monster_desc(player_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
146 exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
149 delete_monster_idx(player_ptr, i);
154 /* Excise dead monsters (backwards!) */
155 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--) {
156 auto *m_ptr = &floor_ptr->m_list[i];
157 if (MonsterRace(m_ptr->r_idx).is_valid()) {
160 compact_monsters_aux(player_ptr, floor_ptr->m_max - 1, i);