OSDN Git Service

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