OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Fix-saved-floor-exceed' into...
[hengband/hengband.git] / src / load / inventory-loader.c
1 #include "load/inventory-loader.h"
2 #include "inventory/inventory-slot-types.h"
3 #include "load/item-loader.h"
4 #include "load/load-util.h"
5 #include "object/object-generator.h"
6 #include "object/object-mark-types.h"
7 #include "system/object-type-definition.h"
8
9 /*!
10  * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
11  * @param player_ptr プレーヤーへの参照ポインタ
12  * @return なし
13  * @details
14  * Note that the inventory changed in Angband 2.7.4.  Two extra
15  * pack slots were added and the equipment was rearranged.  Note
16  * that these two features combine when parsing old save-files, in
17  * which items from the old "aux" slot are "carried", perhaps into
18  * one of the two new "inventory" slots.
19  *
20  * Note that the inventory is "re-sorted" later by "dungeon()".
21  */
22 static errr rd_inventory(player_type *player_ptr)
23 {
24     player_ptr->inven_cnt = 0;
25     player_ptr->equip_cnt = 0;
26
27     if (player_ptr->inventory_list != NULL)
28         C_WIPE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
29     C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
30
31     int slot = 0;
32     while (TRUE) {
33         u16b n;
34         rd_u16b(&n);
35
36         if (n == 0xFFFF)
37             break;
38         object_type forge;
39         object_type *q_ptr;
40         q_ptr = &forge;
41         object_wipe(q_ptr);
42
43         rd_item(player_ptr, q_ptr);
44         if (!q_ptr->k_idx)
45             return (53);
46
47         if (n >= INVEN_MAIN_HAND) {
48             q_ptr->marked |= OM_TOUCHED;
49             object_copy(&player_ptr->inventory_list[n], q_ptr);
50             player_ptr->equip_cnt++;
51             continue;
52         }
53
54         if (player_ptr->inven_cnt == INVEN_PACK) {
55             load_note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
56             return (54);
57         }
58
59         n = slot++;
60         q_ptr->marked |= OM_TOUCHED;
61         object_copy(&player_ptr->inventory_list[n], q_ptr);
62         player_ptr->inven_cnt++;
63     }
64
65     return 0;
66 }
67
68 errr load_inventory(player_type *creature_ptr)
69 {
70     byte tmp8u;
71     for (int i = 0; i < 64; i++) {
72         rd_byte(&tmp8u);
73         creature_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
74     }
75
76     if (!rd_inventory(creature_ptr))
77         return 0;
78
79     load_note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
80     return 21;
81 }