1 #include "store/home.h"
2 #include "avatar/avatar.h"
3 #include "floor/floor-town.h"
4 #include "game-option/birth-options.h"
5 #include "game-option/game-play-options.h"
6 #include "object/object-stack.h"
7 #include "object/object-value.h"
8 #include "object/tval-types.h"
9 #include "store/store-util.h"
10 #include "system/object-type-definition.h"
11 #include "system/player-type-definition.h"
12 #include "util/object-sort.h"
15 * @brief 我が家にオブジェクトを加える /
16 * Add the item "o_ptr" to the inventory of the "Home"
17 * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
21 * In all cases, return the slot (or -1) where the object was placed
22 * Note that this is a hacked up version of "store_item_to_inventory()".
23 * Also note that it may not correctly "adapt" to "knowledge" bacoming
24 * known, the player may have to pick stuff up and drop it again.
27 int home_carry(PlayerType *player_ptr, ObjectType *o_ptr, StoreSaleType store_num)
29 bool old_stack_force_notes = stack_force_notes;
30 bool old_stack_force_costs = stack_force_costs;
31 if (store_num != StoreSaleType::HOME) {
32 stack_force_notes = false;
33 stack_force_costs = false;
36 for (int slot = 0; slot < st_ptr->stock_num; slot++) {
38 j_ptr = &st_ptr->stock[slot];
39 if (object_similar(j_ptr, o_ptr)) {
40 object_absorb(j_ptr, o_ptr);
41 if (store_num != StoreSaleType::HOME) {
42 stack_force_notes = old_stack_force_notes;
43 stack_force_costs = old_stack_force_costs;
50 if (store_num != StoreSaleType::HOME) {
51 stack_force_notes = old_stack_force_notes;
52 stack_force_costs = old_stack_force_costs;
57 * 隠し機能: オプション powerup_home が設定されていると
60 if ((store_num != StoreSaleType::HOME) || powerup_home) {
61 if (st_ptr->stock_num >= st_ptr->stock_size) {
65 if (st_ptr->stock_num >= ((st_ptr->stock_size) / 10)) {
70 PRICE value = object_value(o_ptr);
72 for (slot = 0; slot < st_ptr->stock_num; slot++) {
73 if (object_sort_comp(player_ptr, o_ptr, value, &st_ptr->stock[slot])) {
78 for (int i = st_ptr->stock_num; i > slot; i--) {
79 st_ptr->stock[i] = st_ptr->stock[i - 1];
83 st_ptr->stock[slot] = *o_ptr;
84 chg_virtue(player_ptr, V_SACRIFICE, -1);
85 (void)combine_and_reorder_home(player_ptr, store_num);
89 static bool exe_combine_store_items(ObjectType *o_ptr, ObjectType *j_ptr, const int max_num, const int i, bool *combined)
91 if (o_ptr->number + j_ptr->number > max_num) {
95 object_absorb(j_ptr, o_ptr);
98 for (k = i; k < st_ptr->stock_num; k++) {
99 st_ptr->stock[k] = st_ptr->stock[k + 1];
102 (&st_ptr->stock[k])->wipe();
107 static void sweep_reorder_store_item(ObjectType *o_ptr, const int i, bool *combined)
109 for (int j = 0; j < i; j++) {
111 j_ptr = &st_ptr->stock[j];
116 int max_num = object_similar_part(j_ptr, o_ptr);
117 if (max_num == 0 || j_ptr->number >= max_num) {
121 if (exe_combine_store_items(o_ptr, j_ptr, max_num, i, combined)) {
125 ITEM_NUMBER old_num = o_ptr->number;
126 ITEM_NUMBER remain = j_ptr->number + o_ptr->number - max_num;
127 object_absorb(j_ptr, o_ptr);
128 o_ptr->number = remain;
129 if (o_ptr->tval == ItemKindType::ROD) {
130 o_ptr->pval = o_ptr->pval * remain / old_num;
131 o_ptr->timeout = o_ptr->timeout * remain / old_num;
132 } else if (o_ptr->tval == ItemKindType::WAND) {
133 o_ptr->pval = o_ptr->pval * remain / old_num;
141 static void exe_reorder_store_item(PlayerType *player_ptr, bool *flag)
143 for (int i = 0; i < st_ptr->stock_num; i++) {
145 o_ptr = &st_ptr->stock[i];
150 int32_t o_value = object_value(o_ptr);
152 for (j = 0; j < st_ptr->stock_num; j++) {
153 if (object_sort_comp(player_ptr, o_ptr, o_value, &st_ptr->stock[j])) {
166 j_ptr->copy_from(&st_ptr->stock[i]);
167 for (int k = i; k > j; k--) {
168 (&st_ptr->stock[k])->copy_from(&st_ptr->stock[k - 1]);
171 (&st_ptr->stock[j])->copy_from(j_ptr);
176 * @brief 現在の町の指定された店舗のアイテムを整理する /
177 * Combine and reorder items in store.
178 * @param store_num 店舗ID
179 * @return 実際に整理が行われたならばTRUEを返す。
181 bool combine_and_reorder_home(PlayerType *player_ptr, const StoreSaleType store_num)
183 bool old_stack_force_notes = stack_force_notes;
184 bool old_stack_force_costs = stack_force_costs;
185 store_type *old_st_ptr = st_ptr;
186 st_ptr = &town_info[1].store[enum2i(store_num)];
188 if (store_num != StoreSaleType::HOME) {
189 stack_force_notes = false;
190 stack_force_costs = false;
193 bool combined = true;
196 for (int i = st_ptr->stock_num - 1; i > 0; i--) {
198 o_ptr = &st_ptr->stock[i];
203 sweep_reorder_store_item(o_ptr, i, &combined);
209 exe_reorder_store_item(player_ptr, &flag);
211 if (store_num != StoreSaleType::HOME) {
212 stack_force_notes = old_stack_force_notes;
213 stack_force_costs = old_stack_force_costs;