OSDN Git Service

Merge pull request #806 from iks3/fix-giveup-quest-and-record-time
[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 "grid/grid.h"
6 #include "info-reader/fixed-map-parser.h"
7 #include "market/building-util.h"
8 #include "monster-race/monster-race.h"
9 #include "monster-race/race-flags1.h"
10 #include "monster/monster-list.h"
11 #include "system/floor-type-definition.h"
12 #include "system/system-variables.h"
13 #include "term/screen-processor.h"
14 #include "term/term-color-types.h"
15 #include "view/display-messages.h"
16
17 /*!
18  * @brief クエスト情報を処理しつつ取得する。/ Process and get quest information
19  * @param player_ptr プレーヤーへの参照ポインタ
20  * @param questnum クエストのID
21  * @param do_init クエストの開始処理か(TRUE)、結果処理か(FALSE)
22  * @return なし
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 = static_cast<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  * @return なし
50  */
51 void print_questinfo(player_type *player_ptr, IDX 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  * @return なし
69  */
70 void castle_quest(player_type *player_ptr)
71 {
72     clear_bldg(4, 18);
73     QUEST_IDX q_index = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].special;
74
75     if (!q_index) {
76         put_str(_("今のところクエストはありません。", "I don't have a quest for you at the moment."), 8, 0);
77         return;
78     }
79
80     quest_type *q_ptr;
81     q_ptr = &quest[q_index];
82     if (q_ptr->status == QUEST_STATUS_COMPLETED) {
83         q_ptr->status = QUEST_STATUS_REWARDED;
84         print_questinfo(player_ptr, q_index, FALSE);
85         reinit_wilderness = TRUE;
86         return;
87     }
88
89     if (q_ptr->status == QUEST_STATUS_TAKEN) {
90         put_str(_("あなたは現在のクエストを終了させていません!", "You have not completed your current quest yet!"), 8, 0);
91         put_str(_("CTRL-Qを使えばクエストの状態がチェックできます。", "Use CTRL-Q to check the status of your quest."), 9, 0);
92
93         get_questinfo(player_ptr, q_index, true);
94         put_str(format(_("現在のクエスト「%s」", "Current quest is '%s'."), q_ptr->name), 11, 0);
95
96         if (q_ptr->type != QUEST_TYPE_KILL_LEVEL || q_ptr->dungeon == 0) {
97             put_str(_("クエストを終わらせたら戻って来て下さい。", "Return when you have completed your quest."), 12, 0);
98             return;
99         }
100
101         put_str(_("このクエストは放棄することができます。", "You can give up this quest."), 12, 0);
102
103         if (!get_check(_("二度と受けられなくなりますが放棄しますか?", "Are you sure to give up this quest?")))
104             return;
105
106         clear_bldg(4, 18);
107         msg_print(_("放棄しました。", "You gave up."));
108         msg_print(NULL);
109         record_quest_final_status(q_ptr, player_ptr->lev, QUEST_STATUS_FAILED);
110     }
111
112     if (q_ptr->status == QUEST_STATUS_FAILED) {
113         print_questinfo(player_ptr, q_index, FALSE);
114         q_ptr->status = QUEST_STATUS_FAILED_DONE;
115         reinit_wilderness = TRUE;
116         return;
117     }
118
119     if (q_ptr->status != QUEST_STATUS_UNTAKEN)
120         return;
121
122     q_ptr->status = QUEST_STATUS_TAKEN;
123     reinit_wilderness = TRUE;
124     if (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL) {
125         print_questinfo(player_ptr, q_index, TRUE);
126         return;
127     }
128
129     if (q_ptr->r_idx == 0) {
130         q_ptr->r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 4 + randint1(6), 0);
131     }
132
133     monster_race *r_ptr;
134     r_ptr = &r_info[q_ptr->r_idx];
135     while ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->rarity != 1)) {
136         q_ptr->r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 4 + randint1(6), 0);
137         r_ptr = &r_info[q_ptr->r_idx];
138     }
139
140     if (q_ptr->max_num == 0) {
141         if (randint1(10) > 7)
142             q_ptr->max_num = 1;
143         else
144             q_ptr->max_num = randint1(3) + 1;
145     }
146
147     q_ptr->cur_num = 0;
148     concptr name = r_ptr->name.c_str();
149 #ifdef JP
150     msg_format("クエスト: %sを %d体倒す", name, q_ptr->max_num);
151 #else
152     msg_format("Your quest: kill %d %s", q_ptr->max_num, name);
153 #endif
154     print_questinfo(player_ptr, q_index, TRUE);
155 }