forked from hengband/hengband
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activation-execution.cpp
276 lines (240 loc) · 8.54 KB
/
activation-execution.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*!
* @file activation-execution.cpp
* @brief アイテムの発動実行定義
*/
#include "action/activation-execution.h"
#include "action/action-limited.h"
#include "artifact/artifact-info.h"
#include "artifact/random-art-effects.h"
#include "core/window-redrawer.h"
#include "effect/attribute-types.h"
#include "effect/spells-effect-util.h"
#include "flavor/flavor-describer.h"
#include "flavor/object-flavor-types.h"
#include "floor/geometry.h"
#include "game-option/disturbance-options.h"
#include "game-option/input-options.h"
#include "main/sound-definitions-table.h"
#include "main/sound-of-music.h"
#include "monster-floor/monster-generator.h"
#include "monster-floor/place-monster-types.h"
#include "monster-race/monster-race.h"
#include "monster/monster-info.h"
#include "monster/monster-util.h"
#include "object-activation/activation-switcher.h"
#include "object-activation/activation-util.h"
#include "object-enchant/activation-info-table.h"
#include "object-enchant/object-ego.h"
#include "object/object-info.h"
#include "player-base/player-class.h"
#include "player-status/player-energy.h"
#include "racial/racial-android.h"
#include "specific-object/monster-ball.h"
#include "spell-kind/spells-launcher.h"
#include "spell-kind/spells-teleport.h"
#include "spell-realm/spells-hex.h"
#include "spell-realm/spells-song.h"
#include "sv-definition/sv-lite-types.h"
#include "sv-definition/sv-ring-types.h"
#include "system/artifact-type-definition.h"
#include "system/baseitem-info.h"
#include "system/floor-type-definition.h"
#include "system/item-entity.h"
#include "system/monster-entity.h"
#include "system/player-type-definition.h"
#include "target/target-getter.h"
#include "term/screen-processor.h"
#include "timed-effect/player-confusion.h"
#include "timed-effect/timed-effects.h"
#include "util/quarks.h"
#include "util/sort.h"
#include "view/display-messages.h"
#include "world/world.h"
static void decide_activation_level(ae_type *ae_ptr)
{
if (ae_ptr->o_ptr->is_fixed_artifact()) {
ae_ptr->lev = artifacts_info.at(ae_ptr->o_ptr->fixed_artifact_idx).level;
return;
}
if (ae_ptr->o_ptr->is_random_artifact()) {
auto act_ptr = find_activation_info(ae_ptr->o_ptr);
if (act_ptr.has_value()) {
ae_ptr->lev = act_ptr.value()->level;
}
return;
}
const auto tval = ae_ptr->o_ptr->bi_key.tval();
if (((tval == ItemKindType::RING) || (tval == ItemKindType::AMULET)) && ae_ptr->o_ptr->is_ego()) {
ae_ptr->lev = egos_info[ae_ptr->o_ptr->ego_idx].level;
}
}
static void decide_chance_fail(PlayerType *player_ptr, ae_type *ae_ptr)
{
ae_ptr->chance = player_ptr->skill_dev;
if (player_ptr->effects()->confusion()->is_confused()) {
ae_ptr->chance = ae_ptr->chance / 2;
}
ae_ptr->fail = ae_ptr->lev + 5;
if (ae_ptr->chance > ae_ptr->fail) {
ae_ptr->fail -= (ae_ptr->chance - ae_ptr->fail) * 2;
} else {
ae_ptr->chance -= (ae_ptr->fail - ae_ptr->chance) * 2;
}
if (ae_ptr->fail < USE_DEVICE) {
ae_ptr->fail = USE_DEVICE;
}
if (ae_ptr->chance < USE_DEVICE) {
ae_ptr->chance = USE_DEVICE;
}
}
static void decide_activation_success(PlayerType *player_ptr, ae_type *ae_ptr)
{
if (PlayerClass(player_ptr).equals(PlayerClassType::BERSERKER)) {
ae_ptr->success = false;
return;
}
if (ae_ptr->chance > ae_ptr->fail) {
ae_ptr->success = randint0(ae_ptr->chance * 2) >= ae_ptr->fail;
return;
}
ae_ptr->success = randint0(ae_ptr->fail * 2) < ae_ptr->chance;
}
static bool check_activation_success(ae_type *ae_ptr)
{
if (ae_ptr->success) {
return true;
}
if (flush_failure) {
flush();
}
msg_print(_("うまく始動させることができなかった。", "You failed to activate it properly."));
sound(SOUND_FAIL);
return false;
}
static bool check_activation_conditions(PlayerType *player_ptr, ae_type *ae_ptr)
{
if (!check_activation_success(ae_ptr)) {
return false;
}
if (ae_ptr->o_ptr->timeout) {
msg_print(_("それは微かに音を立て、輝き、消えた...", "It whines, glows and fades..."));
return false;
}
if (ae_ptr->o_ptr->is_fuel() && (ae_ptr->o_ptr->fuel == 0)) {
msg_print(_("燃料がない。", "It has no fuel."));
PlayerEnergy(player_ptr).reset_player_turn();
return false;
}
return true;
}
/*!
* @brief アイテムの発動効果を処理する。
* @param player_ptr プレイヤーへの参照ポインタ
* @param o_ptr 対象のオブジェクト構造体ポインタ
* @return 発動実行の是非を返す。
*/
static bool activate_artifact(PlayerType *player_ptr, ItemEntity *o_ptr)
{
auto tmp_act_ptr = find_activation_info(o_ptr);
if (!tmp_act_ptr.has_value()) {
msg_print("Activation information is not found.");
return false;
}
auto *act_ptr = tmp_act_ptr.value();
GAME_TEXT name[MAX_NLEN];
describe_flavor(player_ptr, name, o_ptr, OD_NAME_ONLY | OD_OMIT_PREFIX | OD_BASE_NAME);
if (!switch_activation(player_ptr, &o_ptr, act_ptr, name)) {
return false;
}
if (act_ptr->timeout.constant >= 0) {
o_ptr->timeout = (int16_t)act_ptr->timeout.constant;
if (act_ptr->timeout.dice > 0) {
o_ptr->timeout += randint1(act_ptr->timeout.dice);
}
return true;
}
switch (act_ptr->index) {
case RandomArtActType::BR_FIRE:
o_ptr->timeout = o_ptr->bi_key == BaseitemKey(ItemKindType::RING, SV_RING_FLAMES) ? 200 : 250;
return true;
case RandomArtActType::BR_COLD:
o_ptr->timeout = o_ptr->bi_key == BaseitemKey(ItemKindType::RING, SV_RING_ICE) ? 200 : 250;
return true;
case RandomArtActType::TERROR:
o_ptr->timeout = 3 * (player_ptr->lev + 10);
return true;
case RandomArtActType::MURAMASA:
return true;
default:
msg_format("Special timeout is not implemented: %d.", act_ptr->index);
return false;
}
}
static bool activate_whistle(PlayerType *player_ptr, ae_type *ae_ptr)
{
if (ae_ptr->o_ptr->bi_key.tval() != ItemKindType::WHISTLE) {
return false;
}
if (music_singing_any(player_ptr)) {
stop_singing(player_ptr);
}
if (SpellHex(player_ptr).is_spelling_any()) {
(void)SpellHex(player_ptr).stop_all_spells();
}
std::vector<MONSTER_IDX> who;
for (MONSTER_IDX pet_ctr = player_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--) {
const auto &m_ref = player_ptr->current_floor_ptr->m_list[pet_ctr];
if (m_ref.is_pet() && (player_ptr->riding != pet_ctr)) {
who.push_back(pet_ctr);
}
}
uint16_t dummy_why;
ang_sort(player_ptr, who.data(), &dummy_why, who.size(), ang_sort_comp_pet, ang_sort_swap_hook);
for (auto pet_ctr : who) {
teleport_monster_to(player_ptr, pet_ctr, player_ptr->y, player_ptr->x, 100, TELEPORT_PASSIVE);
}
ae_ptr->o_ptr->timeout = 100 + randint1(100);
return true;
}
/*!
* @brief 装備を発動するコマンドのサブルーチン /
* Activate a wielded object. Wielded objects never stack.
* And even if they did, activatable objects never stack.
* @param item 発動するオブジェクトの所持品ID
* @details
* <pre>
* Currently, only (some) artifacts, and Dragon Scale Mail, can be activated.
* But one could, for example, easily make an activatable "Ring of Plasma".
* Note that it always takes a turn to activate an artifact, even if
* the user hits "escape" at the "direction" prompt.
* </pre>
*/
void exe_activate(PlayerType *player_ptr, INVENTORY_IDX item)
{
PlayerEnergy(player_ptr).set_player_turn_energy(100);
ae_type tmp_ae;
ae_type *ae_ptr = initialize_ae_type(player_ptr, &tmp_ae, item);
decide_activation_level(ae_ptr);
decide_chance_fail(player_ptr, ae_ptr);
if (cmd_limit_time_walk(player_ptr)) {
return;
}
decide_activation_success(player_ptr, ae_ptr);
if (!check_activation_conditions(player_ptr, ae_ptr)) {
return;
}
msg_print(_("始動させた...", "You activate it..."));
sound(SOUND_ZAP);
if (activation_index(ae_ptr->o_ptr) > RandomArtActType::NONE) {
(void)activate_artifact(player_ptr, ae_ptr->o_ptr);
player_ptr->window_flags |= PW_INVEN | PW_EQUIP;
return;
}
if (activate_whistle(player_ptr, ae_ptr)) {
return;
}
if (exe_monster_capture(player_ptr, ae_ptr)) {
return;
}
msg_print(_("おっと、このアイテムは始動できない。", "Oops. That object cannot be activated."));
}