1 #include "store/home.h"
2 #include "floor/floor-town.h"
3 #include "game-option/birth-options.h"
4 #include "game-option/game-play-options.h"
5 #include "object/object-stack.h"
6 #include "object/object-value.h"
7 #include "object/object-generator.h"
8 #include "player/avatar.h"
9 #include "store/store-util.h"
10 #include "util/object-sort.h"
13 * @brief 我が家にオブジェクトを加える /
14 * Add the item "o_ptr" to the inventory of the "Home"
15 * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
19 * In all cases, return the slot (or -1) where the object was placed
20 * Note that this is a hacked up version of "store_item_to_inventory()".
21 * Also note that it may not correctly "adapt" to "knowledge" bacoming
22 * known, the player may have to pick stuff up and drop it again.
25 int home_carry(player_type *player_ptr, object_type *o_ptr)
27 bool old_stack_force_notes = stack_force_notes;
28 bool old_stack_force_costs = stack_force_costs;
29 if (cur_store_num != STORE_HOME) {
30 stack_force_notes = FALSE;
31 stack_force_costs = FALSE;
34 for (int slot = 0; slot < st_ptr->stock_num; slot++) {
36 j_ptr = &st_ptr->stock[slot];
37 if (object_similar(j_ptr, o_ptr)) {
38 object_absorb(j_ptr, o_ptr);
39 if (cur_store_num != STORE_HOME) {
40 stack_force_notes = old_stack_force_notes;
41 stack_force_costs = old_stack_force_costs;
48 if (cur_store_num != STORE_HOME) {
49 stack_force_notes = old_stack_force_notes;
50 stack_force_costs = old_stack_force_costs;
55 * 隠し機能: オプション powerup_home が設定されていると
58 if ((cur_store_num != STORE_HOME) || (powerup_home == TRUE)) {
59 if (st_ptr->stock_num >= st_ptr->stock_size) {
63 if (st_ptr->stock_num >= ((st_ptr->stock_size) / 10)) {
68 PRICE value = object_value(player_ptr, o_ptr);
70 for (slot = 0; slot < st_ptr->stock_num; slot++)
71 if (object_sort_comp(player_ptr, o_ptr, value, &st_ptr->stock[slot]))
74 for (int i = st_ptr->stock_num; i > slot; i--)
75 st_ptr->stock[i] = st_ptr->stock[i - 1];
78 st_ptr->stock[slot] = *o_ptr;
79 chg_virtue(player_ptr, V_SACRIFICE, -1);
80 (void)combine_and_reorder_home(player_ptr, cur_store_num);
84 static bool exe_combine_store_items(object_type *o_ptr, object_type *j_ptr, const int max_num, const int i, bool *combined)
86 if (o_ptr->number + j_ptr->number <= max_num)
89 object_absorb(j_ptr, o_ptr);
92 for (k = i; k < st_ptr->stock_num; k++)
93 st_ptr->stock[k] = st_ptr->stock[k + 1];
95 object_wipe(&st_ptr->stock[k]);
100 static void sweep_reorder_store_item(object_type *o_ptr, const int i, bool *combined)
102 for (int j = 0; j < i; j++) {
104 j_ptr = &st_ptr->stock[j];
108 int max_num = object_similar_part(j_ptr, o_ptr);
109 if (max_num == 0 || j_ptr->number >= max_num)
112 if (exe_combine_store_items(o_ptr, j_ptr, max_num, i, combined))
115 ITEM_NUMBER old_num = o_ptr->number;
116 ITEM_NUMBER remain = j_ptr->number + o_ptr->number - max_num;
117 object_absorb(j_ptr, o_ptr);
118 o_ptr->number = remain;
119 if (o_ptr->tval == TV_ROD) {
120 o_ptr->pval = o_ptr->pval * remain / old_num;
121 o_ptr->timeout = o_ptr->timeout * remain / old_num;
122 } else if (o_ptr->tval == TV_WAND) {
123 o_ptr->pval = o_ptr->pval * remain / old_num;
131 static void exe_reorder_store_item(player_type *player_ptr, bool *flag)
133 for (int i = 0; i < st_ptr->stock_num; i++) {
135 o_ptr = &st_ptr->stock[i];
139 s32b o_value = object_value(player_ptr, o_ptr);
141 for (j = 0; j < st_ptr->stock_num; j++)
142 if (object_sort_comp(player_ptr, o_ptr, o_value, &st_ptr->stock[j]))
152 object_copy(j_ptr, &st_ptr->stock[i]);
153 for (int k = i; k > j; k--)
154 object_copy(&st_ptr->stock[k], &st_ptr->stock[k - 1]);
156 object_copy(&st_ptr->stock[j], j_ptr);
161 * @brief 現在の町の指定された店舗のアイテムを整理する /
162 * Combine and reorder items in store.
163 * @param store_num 店舗ID
164 * @return 実際に整理が行われたならばTRUEを返す。
166 bool combine_and_reorder_home(player_type *player_ptr, const int store_num)
168 bool old_stack_force_notes = stack_force_notes;
169 bool old_stack_force_costs = stack_force_costs;
170 store_type *old_st_ptr = st_ptr;
171 st_ptr = &town_info[1].store[store_num];
173 if (store_num != STORE_HOME) {
174 stack_force_notes = FALSE;
175 stack_force_costs = FALSE;
178 bool combined = TRUE;
181 for (int i = st_ptr->stock_num - 1; i > 0; i--) {
183 o_ptr = &st_ptr->stock[i];
187 sweep_reorder_store_item(o_ptr, i, &combined);
193 exe_reorder_store_item(player_ptr, &flag);
195 if (store_num != STORE_HOME) {
196 stack_force_notes = old_stack_force_notes;
197 stack_force_costs = old_stack_force_costs;