OSDN Git Service

Replace sprintf() with std::string and/or format(). Does part of the work of resolvi...
[hengbandforosx/hengbandosx.git] / src / market / building-quest.cpp
index 4fde3da..eeaa304 100644 (file)
@@ -9,10 +9,11 @@
 #include "monster/monster-list.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
-#include "system/monster-race-definition.h"
+#include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
+#include "term/z-form.h"
 #include "view/display-messages.h"
 
 /*!
@@ -29,15 +30,16 @@ static void get_questinfo(PlayerType *player_ptr, QuestId questnum, bool do_init
 
     quest_text_line = 0;
 
-    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    auto *floor_ptr = player_ptr->current_floor_ptr;
     QuestId old_quest = floor_ptr->quest_number;
     floor_ptr->quest_number = questnum;
 
     init_flags = INIT_SHOW_TEXT;
-    if (do_init)
+    if (do_init) {
         init_flags = i2enum<init_flags_type>(init_flags | INIT_ASSIGN);
+    }
 
-    parse_fixed_map(player_ptr, "q_info.txt", 0, 0, 0, 0);
+    parse_fixed_map(player_ptr, QUEST_DEFINITION_LIST, 0, 0, 0, 0);
     floor_ptr->quest_number = old_quest;
 }
 
@@ -47,14 +49,14 @@ static void get_questinfo(PlayerType *player_ptr, QuestId questnum, bool do_init
  * @param questnum クエストのID
  * @param do_init クエストの開始処理か(true)、結果処理か(FALSE)
  */
-void print_questinfo(PlayerType *player_ptr, QuestId questnum, bool do_init)
+static void print_questinfo(PlayerType *player_ptr, QuestId questnum, bool do_init)
 {
     get_questinfo(player_ptr, questnum, do_init);
 
-    GAME_TEXT tmp_str[80];
-    sprintf(tmp_str, _("クエスト情報 (危険度: %d 階相当)", "Quest Information (Danger level: %d)"), (int)quest[enum2i(questnum)].level);
-    prt(tmp_str, 5, 0);
-    prt(quest[enum2i(questnum)].name, 7, 0);
+    const auto &quest_list = QuestList::get_instance();
+    const auto *q_ptr = &quest_list[questnum];
+    prt(format(_("クエスト情報 (危険度: %d 階相当)", "Quest Information (Danger level: %d)"), (int)q_ptr->level), 5, 0);
+    prt(q_ptr->name, 7, 0);
 
     for (int i = 0; i < 10; i++) {
         c_put_str(TERM_YELLOW, quest_text[i], i + 8, 0);
@@ -75,8 +77,8 @@ void castle_quest(PlayerType *player_ptr)
         return;
     }
 
-    quest_type *q_ptr;
-    q_ptr = &quest[enum2i(q_index)];
+    auto &quest_list = QuestList::get_instance();
+    auto *q_ptr = &quest_list[q_index];
     if (q_ptr->status == QuestStatusType::COMPLETED) {
         q_ptr->status = QuestStatusType::REWARDED;
         print_questinfo(player_ptr, q_index, false);
@@ -98,8 +100,9 @@ void castle_quest(PlayerType *player_ptr)
 
         put_str(_("このクエストは放棄することができます。", "You can give up this quest."), 12, 0);
 
-        if (!get_check(_("二度と受けられなくなりますが放棄しますか?", "Are you sure to give up this quest? ")))
+        if (!get_check(_("二度と受けられなくなりますが放棄しますか?", "Are you sure to give up this quest? "))) {
             return;
+        }
 
         clear_bldg(4, 18);
         msg_print(_("放棄しました。", "You gave up."));
@@ -114,40 +117,11 @@ void castle_quest(PlayerType *player_ptr)
         return;
     }
 
-    if (q_ptr->status != QuestStatusType::UNTAKEN)
+    if (q_ptr->status != QuestStatusType::UNTAKEN) {
         return;
+    }
 
     q_ptr->status = QuestStatusType::TAKEN;
     reinit_wilderness = true;
-    if (q_ptr->type != QuestKindType::KILL_ANY_LEVEL) {
-        print_questinfo(player_ptr, q_index, true);
-        return;
-    }
-
-    if (q_ptr->r_idx == 0) {
-        q_ptr->r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 4 + randint1(6), 0);
-    }
-
-    monster_race *r_ptr;
-    r_ptr = &r_info[q_ptr->r_idx];
-    while ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->rarity != 1)) {
-        q_ptr->r_idx = get_mon_num(player_ptr, 0, q_ptr->level + 4 + randint1(6), 0);
-        r_ptr = &r_info[q_ptr->r_idx];
-    }
-
-    if (q_ptr->max_num == 0) {
-        if (randint1(10) > 7)
-            q_ptr->max_num = 1;
-        else
-            q_ptr->max_num = randint1(3) + 1;
-    }
-
-    q_ptr->cur_num = 0;
-    concptr name = r_ptr->name.c_str();
-#ifdef JP
-    msg_format("クエスト: %sを %d体倒す", name, q_ptr->max_num);
-#else
-    msg_format("Your quest: kill %d %s", q_ptr->max_num, name);
-#endif
     print_questinfo(player_ptr, q_index, true);
 }