#include "system/object-type-definition.h"
#include "system/player-type-definition.h"
#include "util/object-sort.h"
+#include <stdint.h>
/*!
* @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
*/
static void home_carry_load(player_type *player_ptr, store_type *store_ptr, object_type *o_ptr)
{
- for (int i = 0; i < store_ptr->stock_num; i++) {
- object_type *j_ptr;
- j_ptr = &store_ptr->stock[i];
- if (!object_similar(j_ptr, o_ptr))
+ for (auto i = 0; i < store_ptr->stock_num; i++) {
+ auto *j_ptr = &store_ptr->stock[i];
+ if (!object_similar(j_ptr, o_ptr)) {
continue;
+ }
object_absorb(j_ptr, o_ptr);
return;
}
- if (store_ptr->stock_num >= store_get_stock_max(StoreSaleType::HOME))
+ if (store_ptr->stock_num >= store_get_stock_max(StoreSaleType::HOME)) {
return;
+ }
- int32_t value = object_value(o_ptr);
+ auto value = object_value(o_ptr);
int slot;
for (slot = 0; slot < store_ptr->stock_num; slot++) {
if (object_sort_comp(player_ptr, o_ptr, value, &store_ptr->stock[slot]))
break;
}
- for (int i = store_ptr->stock_num; i > slot; i--) {
+ for (auto i = store_ptr->stock_num; i > slot; i--) {
store_ptr->stock[i] = store_ptr->stock[i - 1];
}
* @param store_number 店舗ID
* @return エラーID
*/
-static errr rd_store(player_type *player_ptr, int town_number, int store_number)
+static void rd_store(player_type *player_ptr, int town_number, int store_number)
{
store_type *store_ptr;
- bool sort = false;
+ auto sort = false;
if (h_older_than(0, 3, 3) && (i2enum<StoreSaleType>(store_number) == StoreSaleType::HOME)) {
store_ptr = &town_info[1].store[store_number];
- if (store_ptr->stock_num)
+ if (store_ptr->stock_num) {
sort = true;
+ }
} else {
store_ptr = &town_info[town_number].store[store_number];
}
- int16_t inven_num;
store_ptr->store_open = rd_s32b();
store_ptr->insult_cur = rd_s16b();
store_ptr->owner = rd_byte();
+
+ int16_t inven_num;
if (h_older_than(1, 0, 4)) {
inven_num = rd_byte();
} else {
store_ptr->good_buy = rd_s16b();
store_ptr->bad_buy = rd_s16b();
-
store_ptr->last_visit = rd_s32b();
auto item_loader = ItemLoaderFactory::get_item_loader();
object_type item;
item_loader->rd_item(&item);
auto stock_max = store_get_stock_max(i2enum<StoreSaleType>(store_number));
- if (store_ptr->stock_num >= stock_max)
+ if (store_ptr->stock_num >= stock_max) {
continue;
+ }
if (sort) {
home_carry_load(player_ptr, store_ptr, &item);
} else {
int k = store_ptr->stock_num++;
- (&store_ptr->stock[k])->copy_from(&item);
+ store_ptr->stock[k].copy_from(&item);
}
}
-
- return 0;
}
/*!
* @param player_ptr プレイヤー情報への参照ポインタ(未使用)
* @return 読み込み終わったら0、失敗したら22
*/
-errr load_store(player_type *player_ptr)
+void load_store(player_type *player_ptr)
{
- (void)player_ptr;
-
- int town_count = rd_u16b();
- int store_count = rd_u16b();
-
- for (int town_idx = 1; town_idx < town_count; town_idx++)
- for (int store_idx = 0; store_idx < store_count; store_idx++)
- if (rd_store(player_ptr, town_idx, store_idx))
- return 22;
-
- return 0;
+ int16_t town_count = rd_u16b();
+ int16_t store_count = rd_u16b();
+ for (int16_t town_idx = 1; town_idx < town_count; town_idx++) {
+ for (int16_t store_idx = 0; store_idx < store_count; store_idx++) {
+ rd_store(player_ptr, town_idx, store_idx);
+ }
+ }
}