-
Notifications
You must be signed in to change notification settings - Fork 22
/
autopick-destroyer.cpp
162 lines (142 loc) · 4.6 KB
/
autopick-destroyer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*!
* @brief 自動破壊の実行
* @date 2020/04/25
* @author Hourier
*/
#include "autopick/autopick-destroyer.h"
#include "autopick/autopick-methods-table.h"
#include "autopick/autopick-util.h"
#include "core/disturbance.h"
#include "core/player-update-types.h"
#include "flavor/flavor-describer.h"
#include "game-option/auto-destruction-options.h"
#include "game-option/input-options.h"
#include "monster-race/monster-race.h"
#include "object-enchant/object-ego.h"
#include "object-enchant/special-object-flags.h"
#include "object-hook/hook-expendable.h"
#include "object-hook/hook-quest.h"
#include "object-hook/hook-weapon.h"
#include "object/object-mark-types.h"
#include "object/object-value.h"
#include "object/tval-types.h"
#include "perception/object-perception.h"
#include "player-base/player-class.h"
#include "player-base/player-race.h"
#include "player-info/race-types.h"
#include "sv-definition/sv-other-types.h"
#include "sv-definition/sv-wand-types.h"
#include "system/item-entity.h"
#include "system/monster-race-info.h"
#include "system/player-type-definition.h"
#include "util/string-processor.h"
#include "view/display-messages.h"
/*!
* @brief クラス依存のアイテム破壊を調べる
* @param player_ptr プレイヤーへの参照ポインタ
* @param o_ptr アイテムへの参照ポインタ
* @return 特別なクラス、かつそのクラス特有のアイテムであればFALSE、それ以外はTRUE
*/
static bool is_leave_special_item(PlayerType *player_ptr, ItemEntity *o_ptr)
{
if (!leave_special) {
return true;
}
PlayerClass pc(player_ptr);
const auto &bi_key = o_ptr->bi_key;
const auto tval = bi_key.tval();
if (PlayerRace(player_ptr).equals(PlayerRaceType::BALROG)) {
auto r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
if (bi_key == BaseitemKey(ItemKindType::CORPSE, SV_CORPSE) && angband_strchr("pht", monraces_info[r_idx].d_char)) {
return false;
}
} else if (pc.equals(PlayerClassType::ARCHER)) {
if ((tval == ItemKindType::SKELETON) || (bi_key == BaseitemKey(ItemKindType::CORPSE, SV_SKELETON))) {
return false;
}
} else if (pc.equals(PlayerClassType::NINJA)) {
if (tval == ItemKindType::LITE && o_ptr->ego_idx == EgoType::LITE_DARKNESS && o_ptr->is_known()) {
return false;
}
} else if (pc.is_tamer()) {
if (bi_key == BaseitemKey(ItemKindType::WAND, SV_WAND_HEAL_MONSTER) && o_ptr->is_aware()) {
return false;
}
}
return true;
}
/*!
* @brief Automatically destroy items in this grid.
*/
static bool is_opt_confirm_destroy(PlayerType *player_ptr, ItemEntity *o_ptr)
{
if (!destroy_items) {
return false;
}
if (leave_worth) {
if (o_ptr->get_price() > 0) {
return false;
}
}
if (leave_equip) {
if (o_ptr->is_weapon_armour_ammo()) {
return false;
}
}
const auto tval = o_ptr->bi_key.tval();
if (leave_chest) {
if ((tval == ItemKindType::CHEST) && o_ptr->pval) {
return false;
}
}
if (leave_wanted) {
if (object_is_bounty(player_ptr, o_ptr)) {
return false;
}
}
if (leave_corpse) {
if (tval == ItemKindType::CORPSE) {
return false;
}
}
if (leave_junk) {
if ((tval == ItemKindType::SKELETON) || (tval == ItemKindType::BOTTLE) || (tval == ItemKindType::JUNK) || (tval == ItemKindType::STATUE)) {
return false;
}
}
if (!is_leave_special_item(player_ptr, o_ptr)) {
return false;
}
if (tval == ItemKindType::GOLD) {
return false;
}
return true;
}
void auto_destroy_item(PlayerType *player_ptr, ItemEntity *o_ptr, int autopick_idx)
{
bool destroy = false;
if (is_opt_confirm_destroy(player_ptr, o_ptr)) {
destroy = true;
}
if (autopick_idx >= 0 && !(autopick_list[autopick_idx].action & DO_AUTODESTROY)) {
destroy = false;
}
if (!always_pickup) {
if (autopick_idx >= 0 && (autopick_list[autopick_idx].action & DO_AUTODESTROY)) {
destroy = true;
}
}
if (!destroy) {
return;
}
disturb(player_ptr, false, false);
if (!can_player_destroy_object(player_ptr, o_ptr)) {
GAME_TEXT o_name[MAX_NLEN];
describe_flavor(player_ptr, o_name, o_ptr, 0);
msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
return;
}
autopick_last_destroyed_object = *o_ptr;
o_ptr->marked.set(OmType::AUTODESTROY);
player_ptr->update |= PU_AUTODESTROY;
}