OSDN Git Service

[Refactor] #2523 PlayerType::poisoned をPlayerPoison の呼び出しに差し替えた
[hengbandforosx/hengbandosx.git] / src / cmd-building / cmd-inn.cpp
1 #include "cmd-building/cmd-inn.h"
2 #include "cmd-item/cmd-magiceat.h"
3 #include "core/turn-compensator.h"
4 #include "game-option/birth-options.h"
5 #include "io/write-diary.h"
6 #include "market/bounty.h"
7 #include "market/building-actions-table.h"
8 #include "player-base/player-class.h"
9 #include "player-base/player-race.h"
10 #include "player-info/magic-eater-data-type.h"
11 #include "player-info/race-info.h"
12 #include "player-info/race-types.h"
13 #include "player/digestion-processor.h"
14 #include "player/eldritch-horror.h"
15 #include "status/bad-status-setter.h"
16 #include "store/rumor.h"
17 #include "system/player-type-definition.h"
18 #include "timed-effect/player-cut.h"
19 #include "timed-effect/player-poison.h"
20 #include "timed-effect/player-stun.h"
21 #include "timed-effect/timed-effects.h"
22 #include "view/display-messages.h"
23 #include "world/world.h"
24
25 /*!
26  * @brief 宿屋で食事を摂る
27  * @param player_ptr プレイヤーへの参照ポインタ
28  * @return 満腹ならFALSE、そうでないならTRUE
29  */
30 static bool buy_food(PlayerType *player_ptr)
31 {
32     if (player_ptr->food >= PY_FOOD_FULL) {
33         msg_print(_("今は満腹だ。", "You are full now."));
34         return false;
35     }
36
37     msg_print(_("バーテンはいくらかの食べ物とビールをくれた。", "The barkeep gives you some gruel and a beer."));
38     (void)set_food(player_ptr, PY_FOOD_MAX - 1);
39     return true;
40 }
41
42 /*!
43  * @brief 健康体しか宿屋に泊めない処理
44  * @param player_ptr プレイヤーへの参照ポインタ
45  * @return 毒でも切り傷でもないならTRUE、そうでないならFALSE
46  */
47 static bool is_healthy_stay(PlayerType *player_ptr)
48 {
49     const auto effects = player_ptr->effects();
50     if (!effects->poison()->is_poisoned() && !effects->cut()->is_cut()) {
51         return true;
52     }
53
54     msg_print(_("あなたに必要なのは部屋ではなく、治療者です。", "You need a healer, not a room."));
55     msg_print(nullptr);
56     msg_print(_("すみません、でもうちで誰かに死なれちゃ困りますんで。", "Sorry, but I don't want anyone dying in here."));
57     return false;
58 }
59
60 #ifdef JP
61 static bool is_player_undead(PlayerType *player_ptr)
62 {
63     return PlayerRace(player_ptr, true).life() == PlayerRaceLifeType::UNDEAD;
64 }
65 #endif
66
67 /*!
68  * @brief 宿屋に泊まったことを日記に残す
69  * @param player_ptr プレイヤーへの参照ポインタ
70  * @param prev_hour 宿屋に入った直後のゲーム内時刻
71  */
72 static void write_diary_stay_inn(PlayerType *player_ptr, int prev_hour)
73 {
74     if ((prev_hour >= 6) && (prev_hour < 18)) {
75         concptr stay_message = _(is_player_undead(player_ptr) ? "宿屋に泊まった。" : "日が暮れるまで宿屋で過ごした。", "stayed during the day at the inn.");
76         exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, stay_message);
77         return;
78     }
79
80     concptr stay_message = _(is_player_undead(player_ptr) ? "夜が明けるまで宿屋で過ごした。" : "宿屋に泊まった。", "stayed overnight at the inn.");
81     exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, stay_message);
82 }
83
84 /*!
85  * @brief 宿泊によってゲーム内ターンを経過させる
86  * @param なし
87  */
88 static void pass_game_turn_by_stay(void)
89 {
90     int32_t oldturn = w_ptr->game_turn;
91     w_ptr->game_turn = (w_ptr->game_turn / (TURNS_PER_TICK * TOWN_DAWN / 2) + 1) * (TURNS_PER_TICK * TOWN_DAWN / 2);
92     if (w_ptr->dungeon_turn >= w_ptr->dungeon_turn_limit) {
93         return;
94     }
95
96     w_ptr->dungeon_turn += std::min<int>((w_ptr->game_turn - oldturn), TURNS_PER_TICK * 250) * INN_DUNGEON_TURN_ADJ;
97     if (w_ptr->dungeon_turn > w_ptr->dungeon_turn_limit) {
98         w_ptr->dungeon_turn = w_ptr->dungeon_turn_limit;
99     }
100 }
101
102 /*!
103  * @brief 悪夢モードなら悪夢を見せる
104  * @param player_ptr プレイヤーへの参照ポインタ
105  * @return 悪夢モードならばTRUE
106  */
107 static bool has_a_nightmare(PlayerType *player_ptr)
108 {
109     if (!ironman_nightmare) {
110         return false;
111     }
112
113     msg_print(_("眠りに就くと恐ろしい光景が心をよぎった。", "Horrible visions flit through your mind as you sleep."));
114
115     while (true) {
116         sanity_blast(player_ptr, nullptr, false);
117         if (!one_in_(3)) {
118             break;
119         }
120     }
121
122     msg_print(_("あなたは絶叫して目を覚ました。", "You awake screaming."));
123     exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("悪夢にうなされてよく眠れなかった。", "had a nightmare."));
124     return true;
125 }
126
127 /*!
128  * @brief 体調を元に戻す
129  * @param player_ptr プレイヤーへの参照ポインタ
130  */
131 static void back_to_health(PlayerType *player_ptr)
132 {
133     BadStatusSetter bss(player_ptr);
134     (void)bss.blindness(0);
135     (void)bss.confusion(0);
136     player_ptr->effects()->stun()->reset();
137     player_ptr->chp = player_ptr->mhp;
138     player_ptr->csp = player_ptr->msp;
139 }
140
141 /*!
142  * @brief 魔道具術師の取り込んだ魔法をすべて完全に回復した状態にする
143  * @param player_ptr プレイヤーへの参照ポインタ
144  */
145 static void charge_magic_eating_energy(PlayerType *player_ptr)
146 {
147     auto magic_eater_data = PlayerClass(player_ptr).get_specific_data<magic_eater_data_type>();
148     if (!magic_eater_data) {
149         return;
150     }
151
152     for (auto tval : { ItemKindType::STAFF, ItemKindType::WAND }) {
153         for (auto &item : magic_eater_data->get_item_group(tval)) {
154             item.charge = item.count * EATER_CHARGE;
155         }
156     }
157     for (auto &item : magic_eater_data->get_item_group(ItemKindType::ROD)) {
158         item.charge = 0;
159     }
160 }
161
162 /*!
163  * @brief リフレッシュ結果を画面に表示する
164  * @param player_ptr プレイヤーへの参照ポインタ
165  * @param prev_hour 宿屋に入った直後のゲーム内時刻
166  */
167 static void display_stay_result(PlayerType *player_ptr, int prev_hour)
168 {
169     if ((prev_hour >= 6) && (prev_hour < 18)) {
170 #if JP
171         char refresh_message_jp[50];
172         sprintf(refresh_message_jp, "%s%s%s", "あなたはリフレッシュして目覚め、", is_player_undead(player_ptr) ? "夜" : "夕方", "を迎えた。");
173         msg_print(refresh_message_jp);
174 #else
175         msg_print("You awake refreshed for the evening.");
176 #endif
177         concptr awake_message = _(is_player_undead(player_ptr) ? "すがすがしい夜を迎えた。" : "夕方を迎えた。", "awoke refreshed.");
178         exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, awake_message);
179         return;
180     }
181
182     msg_print(_("あなたはリフレッシュして目覚め、新たな日を迎えた。", "You awake refreshed for the new day."));
183     concptr awake_message = _(is_player_undead(player_ptr) ? "すがすがしい朝を迎えた。" : "朝を迎えた。", "awoke refreshed.");
184     exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, awake_message);
185 }
186
187 /*!
188  * @brief 宿屋への宿泊実行処理
189  * @param player_ptr プレイヤーへの参照ポインタ
190  * @return 泊まれたらTRUE
191  */
192 static bool stay_inn(PlayerType *player_ptr)
193 {
194     if (!is_healthy_stay(player_ptr)) {
195         return false;
196     }
197
198     int prev_day, prev_hour, prev_min;
199     extract_day_hour_min(player_ptr, &prev_day, &prev_hour, &prev_min);
200     write_diary_stay_inn(player_ptr, prev_hour);
201
202     pass_game_turn_by_stay();
203     prevent_turn_overflow(player_ptr);
204
205     if ((prev_hour >= 18) && (prev_hour <= 23)) {
206         determine_daily_bounty(player_ptr, false); /* Update daily bounty */
207         exe_write_diary(player_ptr, DIARY_DIALY, 0, nullptr);
208     }
209
210     player_ptr->chp = player_ptr->mhp;
211     if (has_a_nightmare(player_ptr)) {
212         return true;
213     }
214
215     back_to_health(player_ptr);
216     charge_magic_eating_energy(player_ptr);
217
218     display_stay_result(player_ptr, prev_hour);
219     return true;
220 }
221
222 /*!
223  * @brief 宿屋を利用する
224  * @param player_ptr プレイヤーへの参照ポインタ
225  * @param cmd 宿屋の利用施設ID
226  * @return 施設の利用が実際に行われたらTRUE
227  * @details inn commands
228  * Note that resting for the night was a perfect way to avoid player
229  * ghosts in the town *if* you could only make it to the inn in time (-:
230  * Now that the ghosts are temporarily disabled in 2.8.X, this function
231  * will not be that useful.  I will keep it in the hopes the player
232  * ghost code does become a reality again. Does help to avoid filthy urchins.
233  * Resting at night is also a quick way to restock stores -KMW-
234  * @todo 悪夢を見る前後に全回復しているが、何か意図がある?
235  */
236 bool inn_comm(PlayerType *player_ptr, int cmd)
237 {
238     switch (cmd) {
239     case BACT_FOOD:
240         return buy_food(player_ptr);
241     case BACT_REST:
242         return stay_inn(player_ptr);
243     case BACT_RUMORS:
244         display_rumor(player_ptr, true);
245         return true;
246     default:
247         //!< @todo リファクタリング前のコードもTRUEだった、FALSEにすべきでは.
248         return true;
249     }
250 }