OSDN Git Service

[Refactor] #40571 Separated target-types.h
[hengband/hengband.git] / src / spell-kind / spells-world.c
1 #include "spell-kind/spells-world.h"
2 #include "cmd-io/cmd-save.h"
3 #include "core/asking-player.h"
4 #include "core/player-redraw-types.h"
5 #include "dungeon/dungeon.h"
6 #include "dungeon/quest.h"
7 #include "floor/cave.h"
8 #include "floor/floor-save.h"
9 #include "floor/floor-town.h"
10 #include "floor/floor.h"
11 #include "floor/geometry.h"
12 #include "floor/wild.h"
13 #include "game-option/birth-options.h"
14 #include "game-option/play-record-options.h"
15 #include "game-option/special-options.h"
16 #include "grid/grid.h"
17 #include "io/input-key-acceptor.h"
18 #include "io/write-diary.h"
19 #include "main/sound-definitions-table.h"
20 #include "main/sound-of-music.h"
21 #include "market/building-util.h"
22 #include "monster-floor/monster-remover.h"
23 #include "monster-race/monster-race.h"
24 #include "monster-race/race-flags-resistance.h"
25 #include "monster-race/race-flags1.h"
26 #include "monster/monster-describer.h"
27 #include "monster/monster-description-types.h"
28 #include "monster/monster-info.h"
29 #include "system/floor-type-definition.h"
30 #include "system/monster-type-definition.h"
31 #include "target/target-types.h"
32 #include "target/targeting.h"
33 #include "term/screen-processor.h"
34 #include "util/int-char-converter.h"
35 #include "view/display-messages.h"
36 #include "world/world.h"
37
38 /*!
39  * todo 変数名が実態と合っているかどうかは要確認
40  * テレポート・レベルが効かないモンスターであるかどうかを判定する
41  * @param caster_ptr プレーヤーへの参照ポインタ
42  * @param idx テレポート・レベル対象のモンスター
43  */
44 bool is_teleport_level_ineffective(player_type *caster_ptr, MONSTER_IDX idx)
45 {
46     floor_type *floor_ptr = caster_ptr->current_floor_ptr;
47     bool is_special_floor
48         = floor_ptr->inside_arena || caster_ptr->phase_out || (floor_ptr->inside_quest && !random_quest_number(caster_ptr, floor_ptr->dun_level));
49     bool is_invalid_floor = idx <= 0;
50     is_invalid_floor &= quest_number(caster_ptr, floor_ptr->dun_level) || (floor_ptr->dun_level >= d_info[caster_ptr->dungeon_idx].maxdepth);
51     is_invalid_floor &= caster_ptr->current_floor_ptr->dun_level >= 1;
52     is_invalid_floor &= ironman_downward;
53     return is_special_floor || is_invalid_floor;
54 }
55
56 /*!
57  * todo cmd-save.h への依存あり。コールバックで何とかしたい
58  * @brief プレイヤー及びモンスターをレベルテレポートさせる /
59  * Teleport the player one level up or down (random when legal)
60  * @param creature_ptr プレーヤーへの参照ポインタ
61  * @param m_idx テレポートの対象となるモンスターID(0ならばプレイヤー) / If m_idx <= 0, target is player.
62  * @return なし
63  */
64 void teleport_level(player_type *creature_ptr, MONSTER_IDX m_idx)
65 {
66     GAME_TEXT m_name[160];
67     bool see_m = TRUE;
68     if (m_idx <= 0) {
69         strcpy(m_name, _("あなた", "you"));
70     } else {
71         monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
72         monster_desc(creature_ptr, m_name, m_ptr, 0);
73         see_m = is_seen(creature_ptr, m_ptr);
74     }
75
76     if (is_teleport_level_ineffective(creature_ptr, m_idx)) {
77         if (see_m)
78             msg_print(_("効果がなかった。", "There is no effect."));
79         return;
80     }
81
82     if ((m_idx <= 0) && creature_ptr->anti_tele) {
83         msg_print(_("不思議な力がテレポートを防いだ!", "A mysterious force prevents you from teleporting!"));
84         return;
85     }
86
87     bool go_up;
88     if (randint0(100) < 50)
89         go_up = TRUE;
90     else
91         go_up = FALSE;
92
93     if ((m_idx <= 0) && current_world_ptr->wizard) {
94         if (get_check("Force to go up? "))
95             go_up = TRUE;
96         else if (get_check("Force to go down? "))
97             go_up = FALSE;
98     }
99
100     if ((ironman_downward && (m_idx <= 0)) || (creature_ptr->current_floor_ptr->dun_level <= d_info[creature_ptr->dungeon_idx].mindepth)) {
101 #ifdef JP
102         if (see_m)
103             msg_format("%^sは床を突き破って沈んでいく。", m_name);
104 #else
105         if (see_m)
106             msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
107 #endif
108         if (m_idx <= 0) {
109             if (!creature_ptr->current_floor_ptr->dun_level) {
110                 creature_ptr->dungeon_idx = ironman_downward ? DUNGEON_ANGBAND : creature_ptr->recall_dungeon;
111                 creature_ptr->oldpy = creature_ptr->y;
112                 creature_ptr->oldpx = creature_ptr->x;
113             }
114
115             if (record_stair)
116                 exe_write_diary(creature_ptr, DIARY_TELEPORT_LEVEL, 1, NULL);
117
118             if (autosave_l)
119                 do_cmd_save_game(creature_ptr, TRUE);
120
121             if (!creature_ptr->current_floor_ptr->dun_level) {
122                 creature_ptr->current_floor_ptr->dun_level = d_info[creature_ptr->dungeon_idx].mindepth;
123                 prepare_change_floor_mode(creature_ptr, CFM_RAND_PLACE);
124             } else {
125                 prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
126             }
127
128             creature_ptr->leaving = TRUE;
129         }
130     } else if (quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level)
131         || (creature_ptr->current_floor_ptr->dun_level >= d_info[creature_ptr->dungeon_idx].maxdepth)) {
132 #ifdef JP
133         if (see_m)
134             msg_format("%^sは天井を突き破って宙へ浮いていく。", m_name);
135 #else
136         if (see_m)
137             msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
138 #endif
139
140         if (m_idx <= 0) {
141             if (record_stair)
142                 exe_write_diary(creature_ptr, DIARY_TELEPORT_LEVEL, -1, NULL);
143
144             if (autosave_l)
145                 do_cmd_save_game(creature_ptr, TRUE);
146
147             prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
148
149             leave_quest_check(creature_ptr);
150             creature_ptr->current_floor_ptr->inside_quest = 0;
151             creature_ptr->leaving = TRUE;
152         }
153     } else if (go_up) {
154 #ifdef JP
155         if (see_m)
156             msg_format("%^sは天井を突き破って宙へ浮いていく。", m_name);
157 #else
158         if (see_m)
159             msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
160 #endif
161
162         if (m_idx <= 0) {
163             if (record_stair)
164                 exe_write_diary(creature_ptr, DIARY_TELEPORT_LEVEL, -1, NULL);
165
166             if (autosave_l)
167                 do_cmd_save_game(creature_ptr, TRUE);
168
169             prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
170             creature_ptr->leaving = TRUE;
171         }
172     } else {
173 #ifdef JP
174         if (see_m)
175             msg_format("%^sは床を突き破って沈んでいく。", m_name);
176 #else
177         if (see_m)
178             msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
179 #endif
180
181         if (m_idx <= 0) {
182             if (record_stair)
183                 exe_write_diary(creature_ptr, DIARY_TELEPORT_LEVEL, 1, NULL);
184             if (autosave_l)
185                 do_cmd_save_game(creature_ptr, TRUE);
186
187             prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
188             creature_ptr->leaving = TRUE;
189         }
190     }
191
192     if (m_idx <= 0) {
193         sound(SOUND_TPLEVEL);
194         return;
195     }
196
197     monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
198     check_quest_completion(creature_ptr, m_ptr);
199     if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname) {
200         char m2_name[MAX_NLEN];
201
202         monster_desc(creature_ptr, m2_name, m_ptr, MD_INDEF_VISIBLE);
203         exe_write_diary(creature_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_TELE_LEVEL, m2_name);
204     }
205
206     delete_monster_idx(creature_ptr, m_idx);
207     sound(SOUND_TPLEVEL);
208 }
209
210 bool teleport_level_other(player_type *caster_ptr)
211 {
212     if (!target_set(caster_ptr, TARGET_KILL))
213         return FALSE;
214     MONSTER_IDX target_m_idx = caster_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx;
215     if (!target_m_idx)
216         return TRUE;
217     if (!player_has_los_bold(caster_ptr, target_row, target_col))
218         return TRUE;
219     if (!projectable(caster_ptr, caster_ptr->y, caster_ptr->x, target_row, target_col))
220         return TRUE;
221
222     monster_type *m_ptr;
223     monster_race *r_ptr;
224     m_ptr = &caster_ptr->current_floor_ptr->m_list[target_m_idx];
225     r_ptr = &r_info[m_ptr->r_idx];
226     GAME_TEXT m_name[MAX_NLEN];
227     monster_desc(caster_ptr, m_name, m_ptr, 0);
228     msg_format(_("%^sの足を指さした。", "You gesture at %^s's feet."), m_name);
229
230     if ((r_ptr->flagsr & (RFR_EFF_RES_NEXU_MASK | RFR_RES_TELE)) || (r_ptr->flags1 & RF1_QUESTOR)
231         || (r_ptr->level + randint1(50) > caster_ptr->lev + randint1(60))) {
232         msg_format(_("しかし効果がなかった!", "%^s is unaffected!"), m_name);
233     } else {
234         teleport_level(caster_ptr, target_m_idx);
235     }
236
237     return TRUE;
238 }
239
240 /*!
241  * @brief 町間のテレポートを行うメインルーチン
242  * @param caster_ptr プレーヤーへの参照ポインタ
243  * @return テレポート処理を決定したか否か
244  */
245 bool tele_town(player_type *caster_ptr)
246 {
247     if (caster_ptr->current_floor_ptr->dun_level) {
248         msg_print(_("この魔法は地上でしか使えない!", "This spell can only be used on the surface!"));
249         return FALSE;
250     }
251
252     if (caster_ptr->current_floor_ptr->inside_arena || caster_ptr->phase_out) {
253         msg_print(_("この魔法は外でしか使えない!", "This spell can only be used outside!"));
254         return FALSE;
255     }
256
257     screen_save();
258     clear_bldg(4, 10);
259
260     int i;
261     int num = 0;
262     for (i = 1; i < max_towns; i++) {
263         char buf[80];
264
265         if ((i == NO_TOWN) || (i == SECRET_TOWN) || (i == caster_ptr->town_num) || !(caster_ptr->visit & (1L << (i - 1))))
266             continue;
267
268         sprintf(buf, "%c) %-20s", I2A(i - 1), town_info[i].name);
269         prt(buf, 5 + i, 5);
270         num++;
271     }
272
273     if (num == 0) {
274         msg_print(_("まだ行けるところがない。", "You have not yet visited any town."));
275         msg_print(NULL);
276         screen_load();
277         return FALSE;
278     }
279
280     prt(_("どこに行きますか:", "Where do you want to go: "), 0, 0);
281     while (TRUE) {
282         i = inkey();
283
284         if (i == ESCAPE) {
285             screen_load();
286             return FALSE;
287         }
288
289         else if ((i < 'a') || (i > ('a' + max_towns - 2)))
290             continue;
291         else if (((i - 'a' + 1) == caster_ptr->town_num) || ((i - 'a' + 1) == NO_TOWN) || ((i - 'a' + 1) == SECRET_TOWN)
292             || !(caster_ptr->visit & (1L << (i - 'a'))))
293             continue;
294         break;
295     }
296
297     for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++) {
298         for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++) {
299             if (wilderness[y][x].town == (i - 'a' + 1)) {
300                 caster_ptr->wilderness_y = y;
301                 caster_ptr->wilderness_x = x;
302             }
303         }
304     }
305
306     caster_ptr->leaving = TRUE;
307     caster_ptr->leave_bldg = TRUE;
308     caster_ptr->teleport_town = TRUE;
309     screen_load();
310     return TRUE;
311 }
312
313 /*!
314  * @brief 現実変容処理
315  * @param caster_ptr プレーヤーへの参照ポインタ
316  * @return なし
317  */
318 void reserve_alter_reality(player_type *caster_ptr)
319 {
320     if (caster_ptr->current_floor_ptr->inside_arena || ironman_downward) {
321         msg_print(_("何も起こらなかった。", "Nothing happens."));
322         return;
323     }
324
325     if (caster_ptr->alter_reality) {
326         caster_ptr->alter_reality = 0;
327         msg_print(_("景色が元に戻った...", "The view around you returns to normal..."));
328         caster_ptr->redraw |= PR_STATUS;
329         return;
330     }
331
332     TIME_EFFECT turns = randint0(21) + 15;
333     caster_ptr->alter_reality = turns;
334     msg_print(_("回りの景色が変わり始めた...", "The view around you begins to change..."));
335     caster_ptr->redraw |= PR_STATUS;
336 }
337
338 /*!
339  * @brief プレイヤーの帰還発動及び中止処理 /
340  * Recall the player to town or dungeon
341  * @param creature_ptr プレーヤーへの参照ポインタ
342  * @param turns 発動までのターン数
343  * @return 常にTRUEを返す
344  */
345 bool recall_player(player_type *creature_ptr, TIME_EFFECT turns)
346 {
347     /*
348      * TODO: Recall the player to the last
349      * visited town when in the wilderness
350      */
351     if (creature_ptr->current_floor_ptr->inside_arena || ironman_downward) {
352         msg_print(_("何も起こらなかった。", "Nothing happens."));
353         return TRUE;
354     }
355
356     bool is_special_floor = creature_ptr->current_floor_ptr->dun_level > 0;
357     is_special_floor &= max_dlv[creature_ptr->dungeon_idx] > creature_ptr->current_floor_ptr->dun_level;
358     is_special_floor &= !creature_ptr->current_floor_ptr->inside_quest;
359     is_special_floor &= !creature_ptr->word_recall;
360     if (is_special_floor) {
361         if (get_check(_("ここは最深到達階より浅い階です。この階に戻って来ますか? ", "Reset recall depth? "))) {
362             max_dlv[creature_ptr->dungeon_idx] = creature_ptr->current_floor_ptr->dun_level;
363             if (record_maxdepth)
364                 exe_write_diary(creature_ptr, DIARY_TRUMP, creature_ptr->dungeon_idx, _("帰還のときに", "when recalled from dungeon"));
365         }
366     }
367
368     if (creature_ptr->word_recall) {
369         creature_ptr->word_recall = 0;
370         msg_print(_("張りつめた大気が流れ去った...", "A tension leaves the air around you..."));
371         creature_ptr->redraw |= (PR_STATUS);
372         return TRUE;
373     }
374
375     if (!creature_ptr->current_floor_ptr->dun_level) {
376         DUNGEON_IDX select_dungeon;
377         select_dungeon = choose_dungeon(_("に帰還", "recall"), 2, 14);
378         if (!select_dungeon)
379             return FALSE;
380         creature_ptr->recall_dungeon = select_dungeon;
381     }
382
383     creature_ptr->word_recall = turns;
384     msg_print(_("回りの大気が張りつめてきた...", "The air about you becomes charged..."));
385     creature_ptr->redraw |= (PR_STATUS);
386     return TRUE;
387 }
388
389 bool free_level_recall(player_type *creature_ptr)
390 {
391     DUNGEON_IDX select_dungeon = choose_dungeon(_("にテレポート", "teleport"), 4, 0);
392     if (!select_dungeon)
393         return FALSE;
394
395     DEPTH max_depth = d_info[select_dungeon].maxdepth;
396     if (select_dungeon == DUNGEON_ANGBAND) {
397         if (quest[QUEST_OBERON].status != QUEST_STATUS_FINISHED)
398             max_depth = 98;
399         else if (quest[QUEST_SERPENT].status != QUEST_STATUS_FINISHED)
400             max_depth = 99;
401     }
402
403     QUANTITY amt = get_quantity(
404         format(_("%sの何階にテレポートしますか?", "Teleport to which level of %s? "), d_name + d_info[select_dungeon].name), (QUANTITY)max_depth);
405     if (amt <= 0) {
406         return FALSE;
407     }
408
409     creature_ptr->word_recall = 1;
410     creature_ptr->recall_dungeon = select_dungeon;
411     max_dlv[creature_ptr->recall_dungeon]
412         = ((amt > d_info[select_dungeon].maxdepth) ? d_info[select_dungeon].maxdepth
413                                                    : ((amt < d_info[select_dungeon].mindepth) ? d_info[select_dungeon].mindepth : amt));
414     if (record_maxdepth)
415         exe_write_diary(creature_ptr, DIARY_TRUMP, select_dungeon, _("トランプタワーで", "at Trump Tower"));
416
417     msg_print(_("回りの大気が張りつめてきた...", "The air about you becomes charged..."));
418
419     creature_ptr->redraw |= PR_STATUS;
420     return TRUE;
421 }
422
423 /*!
424  * @brief フロア・リセット処理
425  * @param caster_ptr プレーヤーへの参照ポインタ
426  * @return リセット処理が実際に行われたらTRUEを返す
427  */
428 bool reset_recall(player_type *caster_ptr)
429 {
430     int select_dungeon, dummy = 0;
431     char ppp[80];
432     char tmp_val[160];
433
434     select_dungeon = choose_dungeon(_("をセット", "reset"), 2, 14);
435     if (ironman_downward) {
436         msg_print(_("何も起こらなかった。", "Nothing happens."));
437         return TRUE;
438     }
439
440     if (!select_dungeon)
441         return FALSE;
442     sprintf(ppp, _("何階にセットしますか (%d-%d):", "Reset to which level (%d-%d): "), (int)d_info[select_dungeon].mindepth, (int)max_dlv[select_dungeon]);
443     sprintf(tmp_val, "%d", (int)MAX(caster_ptr->current_floor_ptr->dun_level, 1));
444
445     if (!get_string(ppp, tmp_val, 10)) {
446         return FALSE;
447     }
448
449     dummy = atoi(tmp_val);
450     if (dummy < 1)
451         dummy = 1;
452     if (dummy > max_dlv[select_dungeon])
453         dummy = max_dlv[select_dungeon];
454     if (dummy < d_info[select_dungeon].mindepth)
455         dummy = d_info[select_dungeon].mindepth;
456
457     max_dlv[select_dungeon] = dummy;
458
459     if (record_maxdepth)
460         exe_write_diary(caster_ptr, DIARY_TRUMP, select_dungeon, _("フロア・リセットで", "using a scroll of reset recall"));
461 #ifdef JP
462     msg_format("%sの帰還レベルを %d 階にセット。", d_name + d_info[select_dungeon].name, dummy, dummy * 50);
463 #else
464     msg_format("Recall depth set to level %d (%d').", dummy, dummy * 50);
465 #endif
466     return TRUE;
467 }