OSDN Git Service

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