OSDN Git Service

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