OSDN Git Service

Merge pull request #1588 from habu1010/feature/c-make-defeat-file-rw-buffer
[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     //! @todo std::make_shared の配列対応版は C++20 から
27     player_ptr->inventory_list = std::shared_ptr<object_type[]>{ new object_type[INVEN_TOTAL] };
28
29     int slot = 0;
30     while (true) {
31         uint16_t n;
32         rd_u16b(&n);
33
34         if (n == 0xFFFF)
35             break;
36         object_type forge;
37         object_type *q_ptr;
38         q_ptr = &forge;
39         q_ptr->wipe();
40
41         rd_item(q_ptr);
42         if (!q_ptr->k_idx)
43             return (53);
44
45         if (n >= INVEN_MAIN_HAND) {
46             q_ptr->marked |= OM_TOUCHED;
47             (&player_ptr->inventory_list[n])->copy_from(q_ptr);
48             player_ptr->equip_cnt++;
49             continue;
50         }
51
52         if (player_ptr->inven_cnt == INVEN_PACK) {
53             load_note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory"));
54             return (54);
55         }
56
57         n = slot++;
58         q_ptr->marked |= OM_TOUCHED;
59         (&player_ptr->inventory_list[n])->copy_from(q_ptr);
60         player_ptr->inven_cnt++;
61     }
62
63     return 0;
64 }
65
66 errr load_inventory(player_type *player_ptr)
67 {
68     byte tmp8u;
69     for (int i = 0; i < 64; i++) {
70         rd_byte(&tmp8u);
71         player_ptr->spell_order[i] = (SPELL_IDX)tmp8u;
72     }
73
74     if (!rd_inventory(player_ptr))
75         return 0;
76
77     load_note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
78     return 21;
79 }