OSDN Git Service

Merge pull request #3532 from sikabane-works/release/3.0.0.87-alpha
[hengbandforosx/hengbandosx.git] / src / market / building-initializer.cpp
1 #include "market/building-initializer.h"
2 #include "floor/floor-town.h"
3 #include "io/files-util.h"
4 #include "object/object-kind-hook.h"
5 #include "player-info/class-types.h"
6 #include "store/articles-on-sale.h"
7 #include "store/store-owners.h"
8 #include "store/store-util.h"
9 #include "store/store.h"
10 #include "system/angband.h"
11 #include "system/baseitem-info.h"
12 #include "system/building-type-definition.h"
13 #include "system/item-entity.h"
14 #include "util/angband-files.h"
15 #include <filesystem>
16 #include <set>
17 #include <vector>
18
19 /*!
20  * @brief ユニークな町の数を数える
21  * @return ユニークな町の数
22  * @details 町定義ファイル名の先頭2文字は番号であることを利用してカウントする.
23  * 辺境の地を表すファイルは(01_*.txt) は3つあるのでユニークではない. また町番号は1から始まるので最後に加算する.
24  */
25 static int count_town_numbers()
26 {
27     const auto &path = path_build(ANGBAND_DIR_EDIT, "towns");
28     std::set<std::string> unique_towns;
29     for (const auto &entry : std::filesystem::directory_iterator(path)) {
30         const auto &filename = entry.path().filename().string();
31         if (!filename.ends_with(".txt")) {
32             continue;
33         }
34
35         unique_towns.insert(filename.substr(0, 2));
36     }
37
38     return unique_towns.size() + 1;
39 }
40
41 /*!
42  * @brief 町情報読み込みのメインルーチン /
43  * Initialize town array
44  * @details 「我が家を拡張する」オプションのON/OFFとは無関係に、ON時の容量を確保しておく.
45  */
46 void init_towns(void)
47 {
48     const auto town_numbers = count_town_numbers();
49     towns_info = std::vector<town_type>(town_numbers);
50     for (auto i = 1; i < town_numbers; i++) {
51         auto &town = towns_info[i];
52         for (auto sst : STORE_SALE_TYPE_LIST) {
53             auto *store_ptr = &town.stores[sst];
54             if ((i > 1) && (sst == StoreSaleType::MUSEUM || sst == StoreSaleType::HOME)) {
55                 continue;
56             }
57
58             store_ptr->stock_size = store_get_stock_max(sst);
59             store_ptr->stock = std::make_unique<ItemEntity[]>(store_ptr->stock_size);
60             if ((sst == StoreSaleType::BLACK) || (sst == StoreSaleType::HOME) || (sst == StoreSaleType::MUSEUM)) {
61                 continue;
62             }
63
64             for (const auto &baseitem : store_regular_sale_table.at(sst)) {
65                 auto bi_id = lookup_baseitem_id(baseitem);
66                 store_ptr->regular.push_back(bi_id);
67             }
68
69             for (const auto &baseitem : store_sale_table.at(sst)) {
70                 auto bi_id = lookup_baseitem_id(baseitem);
71                 store_ptr->table.push_back(bi_id);
72             }
73         }
74     }
75 }
76
77 /*!
78  * @brief 店情報初期化のメインルーチン /
79  * Initialize buildings
80  */
81 void init_buildings(void)
82 {
83     for (auto i = 0; i < MAX_BUILDINGS; i++) {
84         buildings[i].name[0] = '\0';
85         buildings[i].owner_name[0] = '\0';
86         buildings[i].owner_race[0] = '\0';
87         for (auto j = 0; j < 8; j++) {
88             buildings[i].act_names[j][0] = '\0';
89             buildings[i].member_costs[j] = 0;
90             buildings[i].other_costs[j] = 0;
91             buildings[i].letters[j] = 0;
92             buildings[i].actions[j] = 0;
93             buildings[i].action_restr[j] = 0;
94         }
95
96         buildings[i].member_class.assign(PLAYER_CLASS_TYPE_MAX, static_cast<short>(PlayerClassType::WARRIOR));
97         buildings[i].member_race.assign(MAX_RACES, static_cast<short>(PlayerRaceType::HUMAN));
98         buildings[i].member_realm.assign(MAX_MAGIC + 1, 0);
99     }
100 }