OSDN Git Service

[WIP] [Refactor] #39963 Separated spells2.h from spells1.h
[hengband/hengband.git] / src / cmd / cmd-zapwand.c
index 8249086..67b64c2 100644 (file)
@@ -1,22 +1,25 @@
 #include "angband.h"
 #include "util.h"
+#include "main/sound-definitions-table.h"
 
 #include "avatar.h"
-#include "spells.h"
+#include "spell/spells-type.h"
 #include "spells-status.h"
 #include "player-status.h"
 #include "player-effects.h"
 #include "player-class.h"
 #include "player-inventory.h"
-#include "objectkind.h"
+#include "object/object-kind.h"
 #include "object-hook.h"
 #include "cmd-basic.h"
 #include "floor.h"
 #include "targeting.h"
-#include "view-mainwindow.h"
+#include "view/display-main-window.h"
+#include "spell/spells2.h"
 
 /*!
 * @brief 魔法棒の効果を発動する
+* @param creature_ptr プレーヤーへの参照ポインタ
 * @param sval オブジェクトのsval
 * @param dir 発動の方向ID
 * @param powerful 強力発動上の処理ならばTRUE
@@ -58,47 +61,47 @@ bool wand_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, DIRECTION
                case SV_WAND_HEAL_MONSTER:
                {
                        HIT_POINT dam = damroll((powerful ? 20 : 10), 10);
-                       if (heal_monster(dir, dam)) ident = TRUE;
+                       if (heal_monster(creature_ptr, dir, dam)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_HASTE_MONSTER:
                {
-                       if (speed_monster(dir, lev)) ident = TRUE;
+                       if (speed_monster(creature_ptr, dir, lev)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_CLONE_MONSTER:
                {
-                       if (clone_monster(dir)) ident = TRUE;
+                       if (clone_monster(creature_ptr, dir)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_TELEPORT_AWAY:
                {
                        int distance = MAX_SIGHT * (powerful ? 8 : 5);
-                       if (teleport_monster(dir, distance)) ident = TRUE;
+                       if (teleport_monster(creature_ptr, dir, distance)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_DISARMING:
                {
-                       if (disarm_trap(dir)) ident = TRUE;
-                       if (powerful && disarm_traps_touch()) ident = TRUE;
+                       if (disarm_trap(creature_ptr, dir)) ident = TRUE;
+                       if (powerful && disarm_traps_touch(creature_ptr)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_TRAP_DOOR_DEST:
                {
-                       if (destroy_door(dir)) ident = TRUE;
-                       if (powerful && destroy_doors_touch()) ident = TRUE;
+                       if (destroy_door(creature_ptr, dir)) ident = TRUE;
+                       if (powerful && destroy_doors_touch(creature_ptr)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_STONE_TO_MUD:
                {
                        HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
-                       if (wall_to_mud(dir, dam)) ident = TRUE;
+                       if (wall_to_mud(creature_ptr, dir, dam)) ident = TRUE;
                        break;
                }
 
@@ -106,44 +109,44 @@ bool wand_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, DIRECTION
                {
                        HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
                        msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
-                       (void)lite_line(dir, dam);
+                       (void)lite_line(creature_ptr, dir, dam);
                        ident = TRUE;
                        break;
                }
 
                case SV_WAND_SLEEP_MONSTER:
                {
-                       if (sleep_monster(dir, lev)) ident = TRUE;
+                       if (sleep_monster(creature_ptr, dir, lev)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_SLOW_MONSTER:
                {
-                       if (slow_monster(dir, lev)) ident = TRUE;
+                       if (slow_monster(creature_ptr, dir, lev)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_CONFUSE_MONSTER:
                {
-                       if (confuse_monster(dir, lev)) ident = TRUE;
+                       if (confuse_monster(creature_ptr, dir, lev)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_FEAR_MONSTER:
                {
-                       if (fear_monster(dir, lev)) ident = TRUE;
+                       if (fear_monster(creature_ptr, dir, lev)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_HYPODYNAMIA:
                {
-                       if (hypodynamic_bolt(dir, 80 + lev)) ident = TRUE;
+                       if (hypodynamic_bolt(creature_ptr, dir, 80 + lev)) ident = TRUE;
                        break;
                }
 
                case SV_WAND_POLYMORPH:
                {
-                       if (poly_monster(dir, lev)) ident = TRUE;
+                       if (poly_monster(creature_ptr, dir, lev)) ident = TRUE;
                        break;
                }
 
@@ -156,35 +159,35 @@ bool wand_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, DIRECTION
 
                case SV_WAND_MAGIC_MISSILE:
                {
-                       fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
+                       fire_bolt_or_beam(creature_ptr, 20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
                        ident = TRUE;
                        break;
                }
 
                case SV_WAND_ACID_BOLT:
                {
-                       fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
+                       fire_bolt_or_beam(creature_ptr, 20, GF_ACID, dir, damroll(6 + lev / 7, 8));
                        ident = TRUE;
                        break;
                }
 
                case SV_WAND_CHARM_MONSTER:
                {
-                       if (charm_monster(dir, MAX(20, lev)))
+                       if (charm_monster(creature_ptr, dir, MAX(20, lev)))
                                ident = TRUE;
                        break;
                }
 
                case SV_WAND_FIRE_BOLT:
                {
-                       fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
+                       fire_bolt_or_beam(creature_ptr, 20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
                        ident = TRUE;
                        break;
                }
 
                case SV_WAND_COLD_BOLT:
                {
-                       fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
+                       fire_bolt_or_beam(creature_ptr, 20, GF_COLD, dir, damroll(5 + lev / 8, 8));
                        ident = TRUE;
                        break;
                }
@@ -284,7 +287,7 @@ bool wand_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, DIRECTION
                case SV_WAND_ROCKETS:
                {
                        msg_print(_("ロケットを発射した!", "You launch a rocket!"));
-                       fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
+                       fire_rocket(creature_ptr, GF_ROCKET, dir, 250 + lev * 3, rad);
                        ident = TRUE;
                        break;
                }
@@ -298,7 +301,7 @@ bool wand_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, DIRECTION
 
                case SV_WAND_GENOCIDE:
                {
-                       fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
+                       fire_ball_hide(creature_ptr, GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
                        ident = TRUE;
                        break;
                }
@@ -335,7 +338,7 @@ void exe_aim_wand(player_type *creature_ptr, INVENTORY_IDX item)
        object_type *o_ptr;
        bool old_target_pet = target_pet;
 
-       o_ptr = REF_ITEM(creature_ptr, p_ptr->current_floor_ptr, item);
+       o_ptr = REF_ITEM(creature_ptr, creature_ptr->current_floor_ptr, item);
 
        /* Mega-Hack -- refuse to aim a pile from the ground */
        if ((item < 0) && (o_ptr->number > 1))
@@ -349,7 +352,7 @@ void exe_aim_wand(player_type *creature_ptr, INVENTORY_IDX item)
        if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
                || o_ptr->sval == SV_WAND_HASTE_MONSTER))
                target_pet = TRUE;
-       if (!get_aim_dir(&dir))
+       if (!get_aim_dir(creature_ptr, &dir))
        {
                target_pet = old_target_pet;
                return;
@@ -403,7 +406,14 @@ void exe_aim_wand(player_type *creature_ptr, INVENTORY_IDX item)
        sound(SOUND_ZAP);
 
        ident = wand_effect(creature_ptr, o_ptr->sval, dir, FALSE, FALSE);
-       creature_ptr->update |= (PU_COMBINE | PU_REORDER);
+       
+       /*
+        * Temporarily remove the flags for updating the inventory so
+        * gain_exp() does not reorder the inventory before the charge
+        * is deducted from the wand.
+        */
+       BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (creature_ptr->update & PU_AUTODESTROY));
+       creature_ptr->update &= ~(PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
 
        if (!(object_is_aware(o_ptr)))
        {
@@ -418,27 +428,23 @@ void exe_aim_wand(player_type *creature_ptr, INVENTORY_IDX item)
        /* Apply identification */
        if (ident && !object_is_aware(o_ptr))
        {
-               object_aware(o_ptr);
+               object_aware(creature_ptr, o_ptr);
                gain_exp(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
        }
 
        creature_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
-
+       creature_ptr->update |= inventory_flags;
 
        /* Use a single charge */
        o_ptr->pval--;
 
-       /* Describe the charges in the pack */
        if (item >= 0)
        {
-               inven_item_charges(item);
+               inven_item_charges(creature_ptr, item);
+               return;
        }
 
-       /* Describe the charges on the floor */
-       else
-       {
-               floor_item_charges(0 - item);
-       }
+       floor_item_charges(creature_ptr->current_floor_ptr, 0 - item);
 }
 
 /*!
@@ -459,7 +465,7 @@ void do_cmd_aim_wand(player_type *creature_ptr)
 
        q = _("どの魔法棒で狙いますか? ", "Aim which wand? ");
        s = _("使える魔法棒がない。", "You have no wand to aim.");
-       if (!choose_object(p_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_WAND)) return;
+       if (!choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_WAND)) return;
 
        exe_aim_wand(creature_ptr, item);
 }