OSDN Git Service

[Refactor] #1710 Definitions QUEST_STATUS_* to enum class QuestStatusType
[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-definition.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(player_type *player_ptr, IDX 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     floor_type *floor_ptr = player_ptr->current_floor_ptr;
33     QUEST_IDX old_quest = floor_ptr->inside_quest;
34     floor_ptr->inside_quest = 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     parse_fixed_map(player_ptr, "q_info.txt", 0, 0, 0, 0);
41     floor_ptr->inside_quest = old_quest;
42 }
43
44 /*!
45  * @brief クエスト情報を処理しつつ表示する。/ Process and display quest information
46  * @param player_ptr プレイヤーへの参照ポインタ
47  * @param questnum クエストのID
48  * @param do_init クエストの開始処理か(true)、結果処理か(FALSE)
49  */
50 void print_questinfo(player_type *player_ptr, IDX questnum, bool do_init)
51 {
52     get_questinfo(player_ptr, questnum, do_init);
53
54     GAME_TEXT tmp_str[80];
55     sprintf(tmp_str, _("クエスト情報 (危険度: %d 階相当)", "Quest Information (Danger level: %d)"), (int)quest[questnum].level);
56     prt(tmp_str, 5, 0);
57     prt(quest[questnum].name, 7, 0);
58
59     for (int i = 0; i < 10; i++) {
60         c_put_str(TERM_YELLOW, quest_text[i], i + 8, 0);
61     }
62 }
63
64 /*!
65  * @brief クエスト処理のメインルーチン / Request a quest from the Lord.
66  * @param player_ptr プレイヤーへの参照ポインタ
67  */
68 void castle_quest(player_type *player_ptr)
69 {
70     clear_bldg(4, 18);
71     QUEST_IDX q_index = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special;
72
73     if (!q_index) {
74         put_str(_("今のところクエストはありません。", "I don't have a quest for you at the moment."), 8, 0);
75         return;
76     }
77
78     quest_type *q_ptr;
79     q_ptr = &quest[q_index];
80     if (q_ptr->status == QuestStatusType::COMPLETED) {
81         q_ptr->status = QuestStatusType::REWARDED;
82         print_questinfo(player_ptr, q_index, false);
83         reinit_wilderness = true;
84         return;
85     }
86
87     if (q_ptr->status == QuestStatusType::TAKEN) {
88         put_str(_("あなたは現在のクエストを終了させていません!", "You have not completed your current quest yet!"), 8, 0);
89         put_str(_("CTRL-Qを使えばクエストの状態がチェックできます。", "Use CTRL-Q to check the status of your quest."), 9, 0);
90
91         get_questinfo(player_ptr, q_index, false);
92         put_str(format(_("現在のクエスト「%s」", "Current quest is '%s'."), q_ptr->name), 11, 0);
93
94         if (q_ptr->type != QUEST_TYPE_KILL_LEVEL || q_ptr->dungeon == 0) {
95             put_str(_("クエストを終わらせたら戻って来て下さい。", "Return when you have completed your quest."), 12, 0);
96             return;
97         }
98
99         put_str(_("このクエストは放棄することができます。", "You can give up this quest."), 12, 0);
100
101         if (!get_check(_("二度と受けられなくなりますが放棄しますか?", "Are you sure to give up this quest? ")))
102             return;
103
104         clear_bldg(4, 18);
105         msg_print(_("放棄しました。", "You gave up."));
106         msg_print(nullptr);
107         record_quest_final_status(q_ptr, player_ptr->lev, QuestStatusType::FAILED);
108     }
109
110     if (q_ptr->status == QuestStatusType::FAILED) {
111         print_questinfo(player_ptr, q_index, false);
112         q_ptr->status = QuestStatusType::FAILED_DONE;
113         reinit_wilderness = true;
114         return;
115     }
116
117     if (q_ptr->status != QuestStatusType::UNTAKEN)
118         return;
119
120     q_ptr->status = QuestStatusType::TAKEN;
121     reinit_wilderness = true;
122     if (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL) {
123         print_questinfo(player_ptr, q_index, true);
124         return;
125     }
126
127     if (q_ptr->r_idx == 0) {
128         q_ptr->r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 4 + randint1(6), 0);
129     }
130
131     monster_race *r_ptr;
132     r_ptr = &r_info[q_ptr->r_idx];
133     while ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->rarity != 1)) {
134         q_ptr->r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 4 + randint1(6), 0);
135         r_ptr = &r_info[q_ptr->r_idx];
136     }
137
138     if (q_ptr->max_num == 0) {
139         if (randint1(10) > 7)
140             q_ptr->max_num = 1;
141         else
142             q_ptr->max_num = randint1(3) + 1;
143     }
144
145     q_ptr->cur_num = 0;
146     concptr name = r_ptr->name.c_str();
147 #ifdef JP
148     msg_format("クエスト: %sを %d体倒す", name, q_ptr->max_num);
149 #else
150     msg_format("Your quest: kill %d %s", q_ptr->max_num, name);
151 #endif
152     print_questinfo(player_ptr, q_index, true);
153 }