OSDN Git Service

[Refactor] #864 Separated player_type struct from player-type.h to player-type-defini...
[hengbandforosx/hengbandosx.git] / src / cmd-item / cmd-usestaff.cpp
1 #include "cmd-item/cmd-usestaff.h"
2 #include "action/action-limited.h"
3 #include "core/player-update-types.h"
4 #include "core/window-redrawer.h"
5 #include "floor/floor-object.h"
6 #include "game-option/disturbance-options.h"
7 #include "inventory/inventory-object.h"
8 #include "inventory/player-inventory.h"
9 #include "main/sound-definitions-table.h"
10 #include "main/sound-of-music.h"
11 #include "monster-floor/monster-summon.h"
12 #include "monster-floor/place-monster-types.h"
13 #include "object-enchant/special-object-flags.h"
14 #include "object/item-use-flags.h"
15 #include "object/object-generator.h"
16 #include "object/object-info.h"
17 #include "object/object-kind.h"
18 #include "perception/object-perception.h"
19 #include "player/attack-defense-types.h"
20 #include "player-info/avatar.h"
21 #include "player/player-class.h"
22 #include "player/player-race-types.h"
23 #include "player/player-race.h"
24 #include "player/player-status.h"
25 #include "player/player-status-flags.h"
26 #include "player/special-defense-types.h"
27 #include "spell-kind/earthquake.h"
28 #include "spell-kind/spells-curse-removal.h"
29 #include "spell-kind/spells-detection.h"
30 #include "spell-kind/spells-floor.h"
31 #include "spell-kind/spells-genocide.h"
32 #include "spell-kind/spells-lite.h"
33 #include "spell-kind/spells-neighbor.h"
34 #include "spell-kind/spells-perception.h"
35 #include "spell-kind/spells-sight.h"
36 #include "spell-kind/spells-teleport.h"
37 #include "spell/spells-staff-only.h"
38 #include "spell/spells-status.h"
39 #include "spell/spells-summon.h"
40 #include "spell/summon-types.h"
41 #include "status/action-setter.h"
42 #include "status/bad-status-setter.h"
43 #include "status/base-status.h"
44 #include "status/buff-setter.h"
45 #include "status/experience.h"
46 #include "status/shape-changer.h"
47 #include "sv-definition/sv-staff-types.h"
48 #include "system/floor-type-definition.h"
49 #include "system/object-type-definition.h"
50 #include "system/player-type-definition.h"
51 #include "util/bit-flags-calculator.h"
52 #include "term/screen-processor.h"
53 #include "view/display-messages.h"
54 #include "view/object-describer.h"
55
56 /*!
57  * @brief 杖の効果を発動する
58  * @param creature_ptr プレーヤーへの参照ポインタ
59  * @param sval オブジェクトのsval
60  * @param use_charge 使用回数を消費したかどうかを返す参照ポインタ
61  * @param powerful 強力発動上の処理ならばTRUE
62  * @param magic 魔道具術上の処理ならばTRUE
63  * @param known 判明済ならばTRUE
64  * @return 発動により効果内容が確定したならばTRUEを返す
65  */
66 int staff_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, bool *use_charge, bool powerful, bool magic, bool known)
67 {
68     int k;
69     bool ident = FALSE;
70     PLAYER_LEVEL lev = powerful ? creature_ptr->lev * 2 : creature_ptr->lev;
71     POSITION detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
72
73     /* Analyze the staff */
74     switch (sval) {
75     case SV_STAFF_DARKNESS: {
76         if (!has_resist_blind(creature_ptr) && !has_resist_dark(creature_ptr)) {
77             if (set_blind(creature_ptr, creature_ptr->blind + 3 + randint1(5)))
78                 ident = TRUE;
79         }
80         if (unlite_area(creature_ptr, 10, (powerful ? 6 : 3)))
81             ident = TRUE;
82         break;
83     }
84
85     case SV_STAFF_SLOWNESS: {
86         if (set_slow(creature_ptr, creature_ptr->slow + randint1(30) + 15, FALSE))
87             ident = TRUE;
88         break;
89     }
90
91     case SV_STAFF_HASTE_MONSTERS: {
92         if (speed_monsters(creature_ptr))
93             ident = TRUE;
94         break;
95     }
96
97     case SV_STAFF_SUMMONING: {
98         const int times = randint1(powerful ? 8 : 4);
99         for (k = 0; k < times; k++) {
100             if (summon_specific(creature_ptr, 0, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, SUMMON_NONE,
101                     (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET))) {
102                 ident = TRUE;
103             }
104         }
105         break;
106     }
107
108     case SV_STAFF_TELEPORTATION: {
109         teleport_player(creature_ptr, (powerful ? 150 : 100), 0L);
110         ident = TRUE;
111         break;
112     }
113
114     case SV_STAFF_IDENTIFY: {
115         if (powerful) {
116             if (!identify_fully(creature_ptr, FALSE, TV_NONE))
117                 *use_charge = FALSE;
118         } else {
119             if (!ident_spell(creature_ptr, FALSE, TV_NONE))
120                 *use_charge = FALSE;
121         }
122         ident = TRUE;
123         break;
124     }
125
126     case SV_STAFF_REMOVE_CURSE: {
127         bool result = (powerful ? remove_all_curse(creature_ptr) : remove_curse(creature_ptr)) != 0;
128         if (result) {
129             ident = TRUE;
130         }
131         break;
132     }
133
134     case SV_STAFF_STARLITE:
135         ident = starlight(creature_ptr, magic);
136         break;
137
138     case SV_STAFF_LITE: {
139         if (lite_area(creature_ptr, damroll(2, 8), (powerful ? 4 : 2)))
140             ident = TRUE;
141         break;
142     }
143
144     case SV_STAFF_MAPPING: {
145         map_area(creature_ptr, powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
146         ident = TRUE;
147         break;
148     }
149
150     case SV_STAFF_DETECT_GOLD: {
151         if (detect_treasure(creature_ptr, detect_rad))
152             ident = TRUE;
153         if (detect_objects_gold(creature_ptr, detect_rad))
154             ident = TRUE;
155         break;
156     }
157
158     case SV_STAFF_DETECT_ITEM: {
159         if (detect_objects_normal(creature_ptr, detect_rad))
160             ident = TRUE;
161         break;
162     }
163
164     case SV_STAFF_DETECT_TRAP: {
165         if (detect_traps(creature_ptr, detect_rad, known))
166             ident = TRUE;
167         break;
168     }
169
170     case SV_STAFF_DETECT_DOOR: {
171         if (detect_doors(creature_ptr, detect_rad))
172             ident = TRUE;
173         if (detect_stairs(creature_ptr, detect_rad))
174             ident = TRUE;
175         break;
176     }
177
178     case SV_STAFF_DETECT_INVIS: {
179         if (detect_monsters_invis(creature_ptr, detect_rad))
180             ident = TRUE;
181         break;
182     }
183
184     case SV_STAFF_DETECT_EVIL: {
185         if (detect_monsters_evil(creature_ptr, detect_rad))
186             ident = TRUE;
187         break;
188     }
189
190     case SV_STAFF_CURE_LIGHT: {
191         ident = cure_light_wounds(creature_ptr, (powerful ? 4 : 2), 8);
192         break;
193     }
194
195     case SV_STAFF_CURING: {
196         ident = true_healing(creature_ptr, 0);
197         if (set_shero(creature_ptr, 0, TRUE))
198             ident = TRUE;
199         break;
200     }
201
202     case SV_STAFF_HEALING: {
203         if (cure_critical_wounds(creature_ptr, powerful ? 500 : 300))
204             ident = TRUE;
205         break;
206     }
207
208     case SV_STAFF_THE_MAGI: {
209         if (do_res_stat(creature_ptr, A_INT))
210             ident = TRUE;
211         ident |= restore_mana(creature_ptr, FALSE);
212         if (set_shero(creature_ptr, 0, TRUE))
213             ident = TRUE;
214         break;
215     }
216
217     case SV_STAFF_SLEEP_MONSTERS: {
218         if (sleep_monsters(creature_ptr, lev))
219             ident = TRUE;
220         break;
221     }
222
223     case SV_STAFF_SLOW_MONSTERS: {
224         if (slow_monsters(creature_ptr, lev))
225             ident = TRUE;
226         break;
227     }
228
229     case SV_STAFF_SPEED: {
230         if (set_fast(creature_ptr, randint1(30) + (powerful ? 30 : 15), FALSE))
231             ident = TRUE;
232         break;
233     }
234
235     case SV_STAFF_PROBING: {
236         ident = probing(creature_ptr);
237         break;
238     }
239
240     case SV_STAFF_DISPEL_EVIL: {
241         ident = dispel_evil(creature_ptr, powerful ? 120 : 80);
242         break;
243     }
244
245     case SV_STAFF_POWER: {
246         ident = dispel_monsters(creature_ptr, powerful ? 225 : 150);
247         break;
248     }
249
250     case SV_STAFF_HOLINESS: {
251         ident = cleansing_nova(creature_ptr, magic, powerful);
252         break;
253     }
254
255     case SV_STAFF_GENOCIDE: {
256         ident = symbol_genocide(creature_ptr, (magic ? lev + 50 : 200), TRUE);
257         break;
258     }
259
260     case SV_STAFF_EARTHQUAKES: {
261         if (earthquake(creature_ptr, creature_ptr->y, creature_ptr->x, (powerful ? 15 : 10), 0))
262             ident = TRUE;
263         else
264             msg_print(_("ダンジョンが揺れた。", "The dungeon trembles."));
265
266         break;
267     }
268
269     case SV_STAFF_DESTRUCTION: {
270         ident = destroy_area(creature_ptr, creature_ptr->y, creature_ptr->x, (powerful ? 18 : 13) + randint0(5), FALSE);
271         break;
272     }
273
274     case SV_STAFF_ANIMATE_DEAD: {
275         ident = animate_dead(creature_ptr, 0, creature_ptr->y, creature_ptr->x);
276         break;
277     }
278
279     case SV_STAFF_MSTORM: {
280         ident = unleash_mana_storm(creature_ptr, powerful);
281         break;
282     }
283
284     case SV_STAFF_NOTHING: {
285         msg_print(_("何も起らなかった。", "Nothing happens."));
286         if (is_specific_player_race(creature_ptr, RACE_SKELETON) || is_specific_player_race(creature_ptr, RACE_GOLEM)
287             || is_specific_player_race(creature_ptr, RACE_ZOMBIE) || is_specific_player_race(creature_ptr, RACE_SPECTRE))
288             msg_print(_("もったいない事をしたような気がする。食べ物は大切にしなくては。", "What a waste.  It's your food!"));
289         break;
290     }
291     }
292     return ident;
293 }
294
295 /*!
296  * @brief 杖を使うコマンドのサブルーチン /
297  * Use a staff.                 -RAK-
298  * @param item 使うオブジェクトの所持品ID
299  * @return なし
300  * @details
301  * One charge of one staff disappears.
302  * Hack -- staffs of identify can be "cancelled".
303  */
304 void exe_use_staff(player_type *creature_ptr, INVENTORY_IDX item)
305 {
306     int ident, chance, lev;
307     object_type *o_ptr;
308
309     /* Hack -- let staffs of identify get aborted */
310     bool use_charge = TRUE;
311
312     o_ptr = ref_item(creature_ptr, item);
313
314     /* Mega-Hack -- refuse to use a pile from the ground */
315     if ((item < 0) && (o_ptr->number > 1)) {
316         msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
317         return;
318     }
319
320     take_turn(creature_ptr, 100);
321
322     lev = k_info[o_ptr->k_idx].level;
323     if (lev > 50)
324         lev = 50 + (lev - 50) / 2;
325
326     /* Base chance of success */
327     chance = creature_ptr->skill_dev;
328
329     /* Confusion hurts skill */
330     if (creature_ptr->confused)
331         chance = chance / 2;
332
333     /* Hight level objects are harder */
334     chance = chance - lev;
335
336     /* Give everyone a (slight) chance */
337     if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1)) {
338         chance = USE_DEVICE;
339     }
340
341     if (cmd_limit_time_walk(creature_ptr))
342         return;
343
344     /* Roll for usage */
345     if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (creature_ptr->pclass == CLASS_BERSERKER)) {
346         if (flush_failure)
347             flush();
348         msg_print(_("杖をうまく使えなかった。", "You failed to use the staff properly."));
349         sound(SOUND_FAIL);
350         return;
351     }
352
353     /* Notice empty staffs */
354     if (o_ptr->pval <= 0) {
355         if (flush_failure)
356             flush();
357         msg_print(_("この杖にはもう魔力が残っていない。", "The staff has no charges left."));
358         o_ptr->ident |= (IDENT_EMPTY);
359         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
360         creature_ptr->window_flags |= (PW_INVEN);
361
362         return;
363     }
364
365     sound(SOUND_ZAP);
366
367     ident = staff_effect(creature_ptr, o_ptr->sval, &use_charge, FALSE, FALSE, object_is_aware(o_ptr));
368
369     if (!(object_is_aware(o_ptr))) {
370         chg_virtue(creature_ptr, V_PATIENCE, -1);
371         chg_virtue(creature_ptr, V_CHANCE, 1);
372         chg_virtue(creature_ptr, V_KNOWLEDGE, -1);
373     }
374
375     /*
376      * Temporarily remove the flags for updating the inventory so
377      * gain_exp() does not reorder the inventory before the charge
378      * is deducted from the staff.
379      */
380     BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (creature_ptr->update & PU_AUTODESTROY));
381     reset_bits(creature_ptr->update, PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
382
383     /* Tried the item */
384     object_tried(o_ptr);
385
386     /* An identification was made */
387     if (ident && !object_is_aware(o_ptr)) {
388         object_aware(creature_ptr, o_ptr);
389         gain_exp(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
390     }
391
392     set_bits(creature_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
393     set_bits(creature_ptr->update, inventory_flags);
394
395     /* Hack -- some uses are "free" */
396     if (!use_charge)
397         return;
398
399     /* Use a single charge */
400     o_ptr->pval--;
401
402     /* XXX Hack -- unstack if necessary */
403     if ((item >= 0) && (o_ptr->number > 1)) {
404         object_type forge;
405         object_type *q_ptr;
406         q_ptr = &forge;
407         object_copy(q_ptr, o_ptr);
408
409         /* Modify quantity */
410         q_ptr->number = 1;
411
412         /* Restore the charges */
413         o_ptr->pval++;
414
415         /* Unstack the used item */
416         o_ptr->number--;
417         item = store_item_to_inventory(creature_ptr, q_ptr);
418
419         msg_print(_("杖をまとめなおした。", "You unstack your staff."));
420     }
421
422     /* Describe charges in the pack */
423     if (item >= 0) {
424         inven_item_charges(creature_ptr, item);
425     }
426
427     /* Describe charges on the floor */
428     else {
429         floor_item_charges(creature_ptr->current_floor_ptr, 0 - item);
430     }
431 }
432
433 /*!
434  * @brief 杖を使うコマンドのメインルーチン /
435  * @return なし
436  */
437 void do_cmd_use_staff(player_type *creature_ptr)
438 {
439     OBJECT_IDX item;
440     concptr q, s;
441
442     if (creature_ptr->wild_mode) {
443         return;
444     }
445
446     if (cmd_limit_arena(creature_ptr))
447         return;
448
449     if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN)) {
450         set_action(creature_ptr, ACTION_NONE);
451     }
452
453     q = _("どの杖を使いますか? ", "Use which staff? ");
454     s = _("使える杖がない。", "You have no staff to use.");
455     if (!choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_STAFF))
456         return;
457
458     exe_use_staff(creature_ptr, item);
459 }