OSDN Git Service

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