OSDN Git Service

Merge branch 'feature/english-correction' into develop
[hengband/hengband.git] / src / io / write-diary.c
index 58bddcc..a1daf85 100644 (file)
@@ -5,16 +5,46 @@
  */
 
 #include "io/write-diary.h"
-#include "core.h"
-#include "quest.h"
-#include "files.h"
-#include "dungeon.h"
-#include "dungeon-file.h"
-#include "world.h"
+#include "dungeon/dungeon.h"
+#include "dungeon/quest.h"
+#include "info-reader/fixed-map-parser.h"
+#include "io/files-util.h"
+#include "market/arena-info-table.h"
+#include "monster-race/monster-race.h"
+#include "system/floor-type-definition.h"
+#include "system/system-variables.h"
+#include "util/angband-files.h"
+#include "view/display-messages.h"
+#include "world/world.h"
 
 // todo *抹殺* したい…
 bool write_level;
 
+#ifdef JP
+#else
+/*!
+ * @brief Return suffix of ordinal number
+ * @param num number
+ * @return pointer of suffix string.
+ */
+concptr get_ordinal_number_suffix(int num)
+{
+       num = ABS(num) % 100;
+       switch (num % 10)
+       {
+       case 1:
+               return (num == 11) ? "th" : "st";
+       case 2:
+               return (num == 12) ? "th" : "nd";
+       case 3:
+               return (num == 13) ? "th" : "rd";
+       default:
+               return "th";
+       }
+}
+#endif
+
+
 /*!
  * todo files.c に移すことも検討する?
  * @brief 日記ファイルを開く
@@ -22,15 +52,14 @@ bool write_level;
  * @param disable_diary 日記への追加を無効化する場合TRUE
  * @return ファイルがあったらTRUE、なかったらFALSE
  */
-static bool open_diary_file(FILE *fff, bool *disable_diary)
+static bool open_diary_file(FILE **fff, bool *disable_diary)
 {
        GAME_TEXT file_name[MAX_NLEN];
        sprintf(file_name, _("playrecord-%s.txt", "playrec-%s.txt"), savefile_base);
        char buf[1024];
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
-       FILE_TYPE(FILE_TYPE_TEXT);
-       fff = my_fopen(buf, "a");
-       if (fff) return TRUE;
+       *fff = angband_fopen(buf, "a");
+       if (*fff) return TRUE;
 
        msg_format(_("%s を開くことができませんでした。プレイ記録を一時停止します。", "Failed to open %s. Play-Record is disabled temporarily."), buf);
        msg_format(NULL);
@@ -40,6 +69,37 @@ static bool open_diary_file(FILE *fff, bool *disable_diary)
 
 
 /*!
+ * @brief フロア情報を日記に追加する
+ * @param creature_ptr プレーヤーへの参照ポインタ
+ * @return クエストID
+ */
+static QUEST_IDX write_floor(player_type *creature_ptr, concptr *note_level, char *note_level_buf)
+{
+       floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+       QUEST_IDX q_idx = quest_number(creature_ptr, floor_ptr->dun_level);
+       if (!write_level) return q_idx;
+
+       if (floor_ptr->inside_arena)
+               *note_level = _("アリーナ:", "Arena:");
+       else if (!floor_ptr->dun_level)
+               *note_level = _("地上:", "Surface:");
+       else if (q_idx && (is_fixed_quest_idx(q_idx) && !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
+               *note_level = _("クエスト:", "Quest:");
+       else
+       {
+#ifdef JP
+               sprintf(note_level_buf, "%d階(%s):", (int)floor_ptr->dun_level, d_name + d_info[creature_ptr->dungeon_idx].name);
+#else
+               sprintf(note_level_buf, "%s L%d:", d_name + d_info[creature_ptr->dungeon_idx].name, (int)floor_ptr->dun_level);
+#endif
+               *note_level = note_level_buf;
+       }
+
+       return q_idx;
+}
+
+
+/*!
  * @brief ペットに関する日記を追加する
  * @param fff 日記ファイル
  * @param num 日記へ追加する内容番号
@@ -128,35 +188,16 @@ errr exe_write_diary(player_type *creature_ptr, int type, int num, concptr note)
                QUEST_IDX old_quest = creature_ptr->current_floor_ptr->inside_quest;
                creature_ptr->current_floor_ptr->inside_quest = (quest[num].type == QUEST_TYPE_RANDOM) ? 0 : num;
                init_flags = INIT_NAME_ONLY;
-               process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
+               parse_fixed_map(creature_ptr, "q_info.txt", 0, 0, 0, 0);
                creature_ptr->current_floor_ptr->inside_quest = old_quest;
        }
 
        FILE *fff = NULL;
-       if (!open_diary_file(fff, &disable_diary)) return -1;
+       if (!open_diary_file(&fff, &disable_diary)) return -1;
 
-       QUEST_IDX q_idx = quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level);
        concptr note_level = "";
-       if (write_level)
-       {
-               if (creature_ptr->current_floor_ptr->inside_arena)
-                       note_level = _("アリーナ:", "Arane:");
-               else if (!creature_ptr->current_floor_ptr->dun_level)
-                       note_level = _("地上:", "Surface:");
-               else if (q_idx && (is_fixed_quest_idx(q_idx)
-                       && !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
-                       note_level = _("クエスト:", "Quest:");
-               else
-               {
-                       char note_level_buf[40];
-#ifdef JP
-                       sprintf(note_level_buf, "%d階(%s):", (int)creature_ptr->current_floor_ptr->dun_level, d_name + d_info[creature_ptr->dungeon_idx].name);
-#else
-                       sprintf(note_level_buf, "%s L%d:", d_name + d_info[creature_ptr->dungeon_idx].name, (int)creature_ptr->current_floor_ptr->dun_level);
-#endif
-                       note_level = note_level_buf;
-               }
-       }
+    char note_level_buf[40];
+       QUEST_IDX q_idx = write_floor(creature_ptr, &note_level, note_level_buf);
 
        bool do_level = TRUE;
        switch (type)
@@ -211,7 +252,7 @@ errr exe_write_diary(player_type *creature_ptr, int type, int num, concptr note)
                if (quest[num].flags & QUEST_FLAG_SILENT) break;
 
                fprintf(fff, _(" %2d:%02d %20s クエスト「%s」から命からがら逃げ帰った。\n",
-                       " %2d:%02d %20s run away from quest '%s'.\n"), hour, min, note_level, quest[num].name);
+                       " %2d:%02d %20s ran away from quest '%s'.\n"), hour, min, note_level, quest[num].name);
                break;
        }
        case DIARY_RAND_QUEST_C:
@@ -278,7 +319,7 @@ errr exe_write_diary(player_type *creature_ptr, int type, int num, concptr note)
        }
        case DIARY_TELEPORT_LEVEL:
        {
-               fprintf(fff, _(" %2d:%02d %20s レベル・テレポートで脱出した。\n", " %2d:%02d %20s Got out using teleport level.\n"),
+               fprintf(fff, _(" %2d:%02d %20s レベル・テレポートで脱出した。\n", " %2d:%02d %20s got out using teleport level.\n"),
                        hour, min, note_level);
                break;
        }
@@ -325,7 +366,7 @@ errr exe_write_diary(player_type *creature_ptr, int type, int num, concptr note)
                        ? _("地上", "the surface")
                        : format(_("%d階(%s)", "level %d of %s"), creature_ptr->current_floor_ptr->dun_level, d_name + d_info[creature_ptr->dungeon_idx].name);
                fprintf(fff, _(" %2d:%02d %20s %sへとウィザード・テレポートで移動した。\n",
-                       " %2d:%02d %20s wizard-teleport to %s.\n"), hour, min, note_level, to);
+                       " %2d:%02d %20s wizard-teleported to %s.\n"), hour, min, note_level, to);
                break;
        }
        case DIARY_PAT_TELE:
@@ -366,7 +407,7 @@ errr exe_write_diary(player_type *creature_ptr, int type, int num, concptr note)
                break;
        }
 
-       my_fclose(fff);
+       angband_fclose(fff);
        if (do_level) write_level = FALSE;
 
        return 0;