1 #include "core/object-compressor.h"
2 #include "core/player-redraw-types.h"
3 #include "core/window-redrawer.h"
4 #include "floor/floor-object.h"
6 #include "object-hook/hook-checker.h"
7 #include "object-hook/hook-enchant.h"
8 #include "object/object-generator.h"
9 #include "object/object-kind.h"
10 #include "system/floor-type-definition.h"
11 #include "system/monster-type-definition.h"
12 #include "system/object-type-definition.h"
13 #include "view/display-messages.h"
16 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
17 * Move an object from index i1 to index i2 in the object list
18 * @param i1 整理したい配列の始点
19 * @param i2 整理したい配列の終点
22 static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX i2)
28 for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++) {
29 o_ptr = &floor_ptr->o_list[i];
33 if (o_ptr->next_o_idx == i1)
34 o_ptr->next_o_idx = i2;
37 o_ptr = &floor_ptr->o_list[i1];
39 if (object_is_held_monster(o_ptr)) {
41 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
42 if (m_ptr->hold_o_idx == i1)
43 m_ptr->hold_o_idx = i2;
45 POSITION y = o_ptr->iy;
46 POSITION x = o_ptr->ix;
48 g_ptr = &floor_ptr->grid_array[y][x];
49 if (g_ptr->o_idx == i1)
53 floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
58 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
59 * Compact and Reorder the object list.
60 * @param player_ptr プレーヤーへの参照ポインタ
61 * @param size 最低でも減らしたいオブジェクト数の水準
65 * This function can be very dangerous, use with caution!\n
67 * When actually "compacting" objects, we base the saving throw on a\n
68 * combination of object level, distance from player, and current\n
71 * After "compacting" (if needed), we "reorder" the objects into a more\n
72 * compact order, and we reset the allocation info, and the "live" array.\n
74 void compact_objects(player_type *player_ptr, int size)
78 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
79 player_ptr->redraw |= PR_MAP;
80 player_ptr->window |= PW_OVERHEAD | PW_DUNGEON;
83 floor_type *floor_ptr = player_ptr->current_floor_ptr;
84 for (int num = 0, cnt = 1; num < size; cnt++) {
85 int cur_lev = 5 * cnt;
86 int cur_dis = 5 * (20 - cnt);
87 for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++) {
88 o_ptr = &floor_ptr->o_list[i];
90 if (!object_is_valid(o_ptr) || (k_info[o_ptr->k_idx].level > cur_lev))
94 if (object_is_held_monster(o_ptr)) {
96 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
100 if (randint0(100) < 90)
107 if ((cur_dis > 0) && (distance(player_ptr->y, player_ptr->x, y, x) < cur_dis))
111 if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) && (cnt < 1000))
114 if (randint0(100) < chance)
117 delete_object_idx(player_ptr, i);
122 for (OBJECT_IDX i = floor_ptr->o_max - 1; i >= 1; i--) {
123 o_ptr = &floor_ptr->o_list[i];
127 compact_objects_aux(floor_ptr, floor_ptr->o_max - 1, i);