OSDN Git Service

[Refactor] #38862 Moved object*.c/h to object/
[hengband/hengband.git] / src / cmd / cmd-read.c
index b1b9857..cfa79ac 100644 (file)
@@ -8,9 +8,10 @@
 
 #include "angband.h"
 #include "util.h"
+#include "main/sound-definitions-table.h"
 
-#include "object-flavor.h"
-#include "object-hook.h"
+#include "object/object-flavor.h"
+#include "object/object-hook.h"
 #include "artifact.h"
 #include "avatar.h"
 #include "player-status.h"
 #include "player-effects.h"
 #include "player-inventory.h"
 #include "rumor.h"
-#include "realm-hex.h"
+#include "realm/realm-hex.h"
 
-#include "spells.h"
 #include "spells-object.h"
 #include "spells-floor.h"
 #include "spells-summon.h"
 #include "spells-status.h"
 
-#include "cmd-basic.h"
+#include "cmd/cmd-basic.h"
+#include "core/show-file.h"
 #include "files.h"
-#include "floor.h"
-#include "objectkind.h"
-#include "realm-song.h"
-#include "view-mainwindow.h"
+#include "floor/floor.h"
+#include "object/object-kind.h"
+#include "view/display-main-window.h"
+#include "spell/spells-type.h"
+#include "spell/spells2.h"
+#include "spell/spells3.h"
 
 /*!
  * @brief 巻物を読むコマンドのサブルーチン
  * Read a scroll (from the pack or floor).
+ * @param creature_ptr プレーヤーへの参照ポインタ
  * @param item 読むオブジェクトの所持品ID
  * @param known 判明済ならばTRUE
  * @return なし
@@ -86,14 +90,14 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                        {
                                (void)set_blind(creature_ptr, creature_ptr->blind + 3 + randint1(5));
                        }
-                       if (unlite_area(10, 3)) ident = TRUE;
+                       if (unlite_area(creature_ptr, 10, 3)) ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_AGGRAVATE_MONSTER:
                {
                        msg_print(_("カン高くうなる様な音が辺りを覆った。", "There is a high pitched humming noise."));
-                       aggravate_monsters(0);
+                       aggravate_monsters(creature_ptr, 0);
                        ident = TRUE;
                        break;
                }
@@ -113,7 +117,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                                if (has_melee_weapon(creature_ptr, INVEN_LARM) && one_in_(2)) k = INVEN_LARM;
                        }
                        else if (has_melee_weapon(creature_ptr, INVEN_LARM)) k = INVEN_LARM;
-                       if (k && curse_weapon(FALSE, k)) ident = TRUE;
+                       if (k && curse_weapon_object(creature_ptr, FALSE, &creature_ptr->inventory_list[k])) ident = TRUE;
                        break;
                }
 
@@ -121,7 +125,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                {
                        for (k = 0; k < randint1(3); k++)
                        {
-                               if (summon_specific(0, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
+                               if (summon_specific(creature_ptr, 0, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
                                {
                                        ident = TRUE;
                                }
@@ -133,7 +137,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                {
                        for (k = 0; k < randint1(3); k++)
                        {
-                               if (summon_specific(0, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, SUMMON_UNDEAD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
+                               if (summon_specific(creature_ptr, 0, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, SUMMON_UNDEAD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
                                {
                                        ident = TRUE;
                                }
@@ -143,7 +147,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_SUMMON_PET:
                {
-                       if (summon_specific(-1, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_FORCE_PET)))
+                       if (summon_specific(creature_ptr, -1, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_FORCE_PET)))
                        {
                                ident = TRUE;
                        }
@@ -152,7 +156,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_SUMMON_KIN:
                {
-                       if (summon_kin_player(creature_ptr->lev, creature_ptr->y, creature_ptr->x, (PM_FORCE_PET | PM_ALLOW_GROUP)))
+                       if (summon_kin_player(creature_ptr, creature_ptr->lev, creature_ptr->y, creature_ptr->x, (PM_FORCE_PET | PM_ALLOW_GROUP)))
                        {
                                ident = TRUE;
                        }
@@ -161,20 +165,20 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_TRAP_CREATION:
                {
-                       if (trap_creation(creature_ptr->y, creature_ptr->x)) ident = TRUE;
+                       if (trap_creation(creature_ptr, creature_ptr->y, creature_ptr->x)) ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_PHASE_DOOR:
                {
-                       teleport_player(creature_ptr, 10, 0L);
+                       teleport_player(creature_ptr, 10, TELEPORT_SPONTANEOUS);
                        ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_TELEPORT:
                {
-                       teleport_player(creature_ptr, 100, 0L);
+                       teleport_player(creature_ptr, 100, TELEPORT_SPONTANEOUS);
                        ident = TRUE;
                        break;
                }
@@ -195,14 +199,14 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_IDENTIFY:
                {
-                       if (!ident_spell(creature_ptr, FALSE)) used_up = FALSE;
+                       if (!ident_spell(creature_ptr, FALSE, 0)) used_up = FALSE;
                        ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_STAR_IDENTIFY:
                {
-                       if (!identify_fully(FALSE)) used_up = FALSE;
+                       if (!identify_fully(creature_ptr, FALSE, 0)) used_up = FALSE;
                        ident = TRUE;
                        break;
                }
@@ -228,41 +232,41 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                case SV_SCROLL_ENCHANT_ARMOR:
                {
                        ident = TRUE;
-                       if (!enchant_spell(0, 0, 1)) used_up = FALSE;
+                       if (!enchant_spell(creature_ptr, 0, 0, 1)) used_up = FALSE;
                        break;
                }
 
                case SV_SCROLL_ENCHANT_WEAPON_TO_HIT:
                {
-                       if (!enchant_spell(1, 0, 0)) used_up = FALSE;
+                       if (!enchant_spell(creature_ptr, 1, 0, 0)) used_up = FALSE;
                        ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_ENCHANT_WEAPON_TO_DAM:
                {
-                       if (!enchant_spell(0, 1, 0)) used_up = FALSE;
+                       if (!enchant_spell(creature_ptr, 0, 1, 0)) used_up = FALSE;
                        ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_STAR_ENCHANT_ARMOR:
                {
-                       if (!enchant_spell(0, 0, randint1(3) + 2)) used_up = FALSE;
+                       if (!enchant_spell(creature_ptr, 0, 0, randint1(3) + 2)) used_up = FALSE;
                        ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_STAR_ENCHANT_WEAPON:
                {
-                       if (!enchant_spell(randint1(3), randint1(3), 0)) used_up = FALSE;
+                       if (!enchant_spell(creature_ptr, randint1(3), randint1(3), 0)) used_up = FALSE;
                        ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_RECHARGING:
                {
-                       if (!recharge(130)) used_up = FALSE;
+                       if (!recharge(creature_ptr, 130)) used_up = FALSE;
                        ident = TRUE;
                        break;
                }
@@ -276,7 +280,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_LIGHT:
                {
-                       if (lite_area(damroll(2, 8), 2)) ident = TRUE;
+                       if (lite_area(creature_ptr, damroll(2, 8), 2)) ident = TRUE;
                        break;
                }
 
@@ -289,33 +293,33 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_DETECT_GOLD:
                {
-                       if (detect_treasure(DETECT_RAD_DEFAULT)) ident = TRUE;
-                       if (detect_objects_gold(DETECT_RAD_DEFAULT)) ident = TRUE;
+                       if (detect_treasure(creature_ptr, DETECT_RAD_DEFAULT)) ident = TRUE;
+                       if (detect_objects_gold(creature_ptr, DETECT_RAD_DEFAULT)) ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_DETECT_ITEM:
                {
-                       if (detect_objects_normal(DETECT_RAD_DEFAULT)) ident = TRUE;
+                       if (detect_objects_normal(creature_ptr, DETECT_RAD_DEFAULT)) ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_DETECT_TRAP:
                {
-                       if (detect_traps(DETECT_RAD_DEFAULT, known)) ident = TRUE;
+                       if (detect_traps(creature_ptr, DETECT_RAD_DEFAULT, known)) ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_DETECT_DOOR:
                {
-                       if (detect_doors(DETECT_RAD_DEFAULT)) ident = TRUE;
-                       if (detect_stairs(DETECT_RAD_DEFAULT)) ident = TRUE;
+                       if (detect_doors(creature_ptr, DETECT_RAD_DEFAULT)) ident = TRUE;
+                       if (detect_stairs(creature_ptr, DETECT_RAD_DEFAULT)) ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_DETECT_INVIS:
                {
-                       if (detect_monsters_invis(DETECT_RAD_DEFAULT)) ident = TRUE;
+                       if (detect_monsters_invis(creature_ptr, DETECT_RAD_DEFAULT)) ident = TRUE;
                        break;
                }
 
@@ -371,13 +375,13 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_TRAP_DOOR_DESTRUCTION:
                {
-                       if (destroy_doors_touch()) ident = TRUE;
+                       if (destroy_doors_touch(creature_ptr)) ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_STAR_DESTRUCTION:
                {
-                       if (destroy_area(creature_ptr->current_floor_ptr, creature_ptr->y, creature_ptr->x, 13 + randint0(5), FALSE))
+                       if (destroy_area(creature_ptr, creature_ptr->y, creature_ptr->x, 13 + randint0(5), FALSE))
                                ident = TRUE;
                        else
                                msg_print(_("ダンジョンが揺れた...", "The dungeon trembles..."));
@@ -387,7 +391,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_DISPEL_UNDEAD:
                {
-                       if (dispel_undead(80)) ident = TRUE;
+                       if (dispel_undead(creature_ptr, 80)) ident = TRUE;
                        break;
                }
 
@@ -430,14 +434,14 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
 
                case SV_SCROLL_ACQUIREMENT:
                {
-                       acquirement(creature_ptr->y, creature_ptr->x, 1, TRUE, FALSE, FALSE);
+                       acquirement(creature_ptr, creature_ptr->y, creature_ptr->x, 1, TRUE, FALSE, FALSE);
                        ident = TRUE;
                        break;
                }
 
                case SV_SCROLL_STAR_ACQUIREMENT:
                {
-                       acquirement(creature_ptr->y, creature_ptr->x, randint1(2) + 1, TRUE, FALSE, FALSE);
+                       acquirement(creature_ptr, creature_ptr->y, creature_ptr->x, randint1(2) + 1, TRUE, FALSE, FALSE);
                        ident = TRUE;
                        break;
                }
@@ -447,7 +451,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                {
                        fire_ball(creature_ptr, GF_FIRE, 0, 666, 4);
                        /* Note: "Double" damage since it is centered on the player ... */
-                       if (!(IS_OPPOSE_FIRE() || creature_ptr->resist_fire || creature_ptr->immune_fire))
+                       if (!(is_oppose_fire(creature_ptr) || creature_ptr->resist_fire || creature_ptr->immune_fire))
                                take_hit(creature_ptr, DAMAGE_NOESCAPE, 50+randint1(50), _("炎の巻物", "a Scroll of Fire"), -1);
 
                        ident = TRUE;
@@ -458,7 +462,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                case SV_SCROLL_ICE:
                {
                        fire_ball(creature_ptr, GF_ICE, 0, 777, 4);
-                       if (!(IS_OPPOSE_COLD() || creature_ptr->resist_cold || creature_ptr->immune_cold))
+                       if (!(is_oppose_cold(creature_ptr) || creature_ptr->resist_cold || creature_ptr->immune_cold))
                                take_hit(creature_ptr, DAMAGE_NOESCAPE, 100+randint1(100), _("氷の巻物", "a Scroll of Ice"), -1);
 
                        ident = TRUE;
@@ -479,7 +483,7 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                {
                        msg_print(_("巻物にはメッセージが書かれている:", "There is message on the scroll. It says:"));
                        msg_print(NULL);
-                       display_rumor(TRUE);
+                       display_rumor(creature_ptr, TRUE);
                        msg_print(NULL);
                        msg_print(_("巻物は煙を立てて消え去った!", "The scroll disappears in a puff of smoke!"));
 
@@ -490,28 +494,28 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                case SV_SCROLL_ARTIFACT:
                {
                        ident = TRUE;
-                       if (!artifact_scroll()) used_up = FALSE;
+                       if (!artifact_scroll(creature_ptr)) used_up = FALSE;
                        break;
                }
 
                case SV_SCROLL_RESET_RECALL:
                {
                        ident = TRUE;
-                       if (!reset_recall()) used_up = FALSE;
+                       if (!reset_recall(creature_ptr)) used_up = FALSE;
                        break;
                }
 
                case SV_SCROLL_AMUSEMENT:
                {
                        ident = TRUE;
-                       amusement(creature_ptr->y, creature_ptr->x, 1, FALSE);
+                       amusement(creature_ptr, creature_ptr->y, creature_ptr->x, 1, FALSE);
                        break;
                }
 
                case SV_SCROLL_STAR_AMUSEMENT:
                {
                        ident = TRUE;
-                       amusement(creature_ptr->y, creature_ptr->x,  randint1(2) + 1, FALSE);
+                       amusement(creature_ptr, creature_ptr->y, creature_ptr->x,  randint1(2) + 1, FALSE);
                        break;
                }
        }
@@ -543,17 +547,24 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
                q=format("book-%d_jp.txt",o_ptr->sval);
 
                /* Display object description */
-               object_desc(o_name, o_ptr, OD_NAME_ONLY);
+               object_desc(creature_ptr, o_name, o_ptr, OD_NAME_ONLY);
                path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, q);
 
                /* Peruse the help file */
-               (void)show_file(TRUE, buf, o_name, 0, 0);
+               (void)show_file(creature_ptr, TRUE, buf, o_name, 0, 0);
                screen_load();
 
                used_up=FALSE;
        }
 
-       creature_ptr->update |= (PU_COMBINE | PU_REORDER);
+       /*
+        * Store what may have to be updated for the inventory (including
+        * autodestroy if set by something else).  Then turn off those flags
+        * so that updates triggered by calling gain_exp() below do not
+        * rearrange the inventory before destroying the scroll in the pack.
+        */
+       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)))
        {
@@ -568,12 +579,12 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
        /* An identification was made */
        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;
 
        /* Hack -- allow certain scrolls to be "preserved" */
        if (!used_up)
@@ -582,9 +593,10 @@ void exe_read(player_type *creature_ptr, INVENTORY_IDX item, bool known)
        }
 
        sound(SOUND_SCROLL);
-       vary_item(item, -1);
+       vary_item(creature_ptr, item, -1);
 }
 
+
 /*!
  * @brief 読むコマンドのメインルーチン /
  * Eat some food (from the pack or floor)
@@ -617,7 +629,7 @@ void do_cmd_read_scroll(player_type *creature_ptr)
        q = _("どの巻物を読みますか? ", "Read which scroll? ");
        s = _("読める巻物がない。", "You have no scrolls to read.");
 
-       o_ptr = choose_object(p_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
+       o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
        if (!o_ptr) return;
 
        /* Read the scroll */