OSDN Git Service

[Refactor] #2807 Renamed monster-race-definition.h to monster-race-info.h
[hengbandforosx/hengbandosx.git] / src / market / building-quest.cpp
1 #include "market/building-quest.h"
2 #include "cmd-building/cmd-building.h"
3 #include "core/asking-player.h"
4 #include "dungeon/quest.h"
5 #include "info-reader/fixed-map-parser.h"
6 #include "market/building-util.h"
7 #include "monster-race/monster-race.h"
8 #include "monster-race/race-flags1.h"
9 #include "monster/monster-list.h"
10 #include "system/floor-type-definition.h"
11 #include "system/grid-type-definition.h"
12 #include "system/monster-race-info.h"
13 #include "system/player-type-definition.h"
14 #include "term/screen-processor.h"
15 #include "term/term-color-types.h"
16 #include "view/display-messages.h"
17
18 /*!
19  * @brief クエスト情報を処理しつつ取得する。/ Process and get quest information
20  * @param player_ptr プレイヤーへの参照ポインタ
21  * @param questnum クエストのID
22  * @param do_init クエストの開始処理か(true)、結果処理か(FALSE)
23  */
24 static void get_questinfo(PlayerType *player_ptr, QuestId questnum, bool do_init)
25 {
26     for (int i = 0; i < 10; i++) {
27         quest_text[i][0] = '\0';
28     }
29
30     quest_text_line = 0;
31
32     auto *floor_ptr = player_ptr->current_floor_ptr;
33     QuestId old_quest = floor_ptr->quest_number;
34     floor_ptr->quest_number = questnum;
35
36     init_flags = INIT_SHOW_TEXT;
37     if (do_init) {
38         init_flags = i2enum<init_flags_type>(init_flags | INIT_ASSIGN);
39     }
40
41     parse_fixed_map(player_ptr, QUEST_DEFINITION_LIST, 0, 0, 0, 0);
42     floor_ptr->quest_number = old_quest;
43 }
44
45 /*!
46  * @brief クエスト情報を処理しつつ表示する。/ Process and display quest information
47  * @param player_ptr プレイヤーへの参照ポインタ
48  * @param questnum クエストのID
49  * @param do_init クエストの開始処理か(true)、結果処理か(FALSE)
50  */
51 void print_questinfo(PlayerType *player_ptr, QuestId questnum, bool do_init)
52 {
53     get_questinfo(player_ptr, questnum, do_init);
54
55     const auto &quest_list = QuestList::get_instance();
56     const auto *q_ptr = &quest_list[questnum];
57     GAME_TEXT tmp_str[80];
58     sprintf(tmp_str, _("クエスト情報 (危険度: %d 階相当)", "Quest Information (Danger level: %d)"), (int)q_ptr->level);
59     prt(tmp_str, 5, 0);
60     prt(q_ptr->name, 7, 0);
61
62     for (int i = 0; i < 10; i++) {
63         c_put_str(TERM_YELLOW, quest_text[i], i + 8, 0);
64     }
65 }
66
67 /*!
68  * @brief クエスト処理のメインルーチン / Request a quest from the Lord.
69  * @param player_ptr プレイヤーへの参照ポインタ
70  */
71 void castle_quest(PlayerType *player_ptr)
72 {
73     clear_bldg(4, 18);
74     QuestId q_index = i2enum<QuestId>(player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special);
75
76     if (!inside_quest(q_index)) {
77         put_str(_("今のところクエストはありません。", "I don't have a quest for you at the moment."), 8, 0);
78         return;
79     }
80
81     auto &quest_list = QuestList::get_instance();
82     auto *q_ptr = &quest_list[q_index];
83     if (q_ptr->status == QuestStatusType::COMPLETED) {
84         q_ptr->status = QuestStatusType::REWARDED;
85         print_questinfo(player_ptr, q_index, false);
86         reinit_wilderness = true;
87         return;
88     }
89
90     if (q_ptr->status == QuestStatusType::TAKEN) {
91         put_str(_("あなたは現在のクエストを終了させていません!", "You have not completed your current quest yet!"), 8, 0);
92         put_str(_("CTRL-Qを使えばクエストの状態がチェックできます。", "Use CTRL-Q to check the status of your quest."), 9, 0);
93
94         get_questinfo(player_ptr, q_index, false);
95         put_str(format(_("現在のクエスト「%s」", "Current quest is '%s'."), q_ptr->name), 11, 0);
96
97         if (q_ptr->type != QuestKindType::KILL_LEVEL || q_ptr->dungeon == 0) {
98             put_str(_("クエストを終わらせたら戻って来て下さい。", "Return when you have completed your quest."), 12, 0);
99             return;
100         }
101
102         put_str(_("このクエストは放棄することができます。", "You can give up this quest."), 12, 0);
103
104         if (!get_check(_("二度と受けられなくなりますが放棄しますか?", "Are you sure to give up this quest? "))) {
105             return;
106         }
107
108         clear_bldg(4, 18);
109         msg_print(_("放棄しました。", "You gave up."));
110         msg_print(nullptr);
111         record_quest_final_status(q_ptr, player_ptr->lev, QuestStatusType::FAILED);
112     }
113
114     if (q_ptr->status == QuestStatusType::FAILED) {
115         print_questinfo(player_ptr, q_index, false);
116         q_ptr->status = QuestStatusType::FAILED_DONE;
117         reinit_wilderness = true;
118         return;
119     }
120
121     if (q_ptr->status != QuestStatusType::UNTAKEN) {
122         return;
123     }
124
125     q_ptr->status = QuestStatusType::TAKEN;
126     reinit_wilderness = true;
127     print_questinfo(player_ptr, q_index, true);
128 }