OSDN Git Service

#37287 #37353 (2.2.0.89) 型の置換を継続中。 / Ongoing type replacement.
[hengband/hengband.git] / src / util.c
index 2fdb8b1..f3f85d4 100644 (file)
@@ -287,7 +287,7 @@ static errr path_temp(char *buf, int max)
        if (!s) return (-1);
 
        /* Format to length */
-#ifndef WIN32
+#if !defined(WIN32) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
        (void)strnfmt(buf, max, "%s", s);
 #else
        (void)strnfmt(buf, max, ".%s", s);
@@ -503,7 +503,7 @@ errr my_fgets(FILE *fff, char *buf, huge n)
                        }
 #endif
                        /* Handle printables */
-                       else if (isprint(*s))
+                       else if (isprint((unsigned char)*s))
                        {
                                /* Copy */
                                buf[i++] = *s;
@@ -1715,18 +1715,24 @@ errr play_music(int type, int val)
        if (!use_music) return 1;
 
        /* Make a sound (if allowed) */
-       return Term_xtra(type , val);
+       return Term_xtra(type, val);
 }
 
 /*
  * Hack -- Select floor music.
  */
-void select_floor_music()
+void select_floor_music(void)
 {
        int i;
        /* No sound */
        if (!use_music) return;
 
+       if(ambush_flag)
+       {
+               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_AMBUSH);
+               return;
+       }
+
        if(p_ptr->wild_mode)
        {
                play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WILD);
@@ -1770,11 +1776,11 @@ void select_floor_music()
 
        if(dungeon_type)
        {
-               if(play_music(TERM_XTRA_MUSIC_DUNGEON, dungeon_type))
+               if(p_ptr->feeling == 2) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL2);
+               else if(p_ptr->feeling >= 3 && p_ptr->feeling <= 5) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL1);
+               else
                {
-                       if(p_ptr->feeling == 2) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL2);
-                       else if(p_ptr->feeling >= 3 && p_ptr->feeling <= 5) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL1);
-                       else
+                       if(play_music(TERM_XTRA_MUSIC_DUNGEON, dungeon_type))
                        {
                                if(dun_level < 40) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_LOW);
                                else if(dun_level < 80) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_MED);
@@ -2413,10 +2419,11 @@ cptr quark_str(s16b i)
 
 
 
-/*
- * How many messages are "available"?
+/*!
+ * @brief 保存中の過去ゲームメッセージの数を返す。 / How many messages are "available"?
+ * @return 残っているメッセージの数
  */
-s16b message_num(void)
+s32b message_num(void)
 {
        int last, next, n;
 
@@ -2435,14 +2442,15 @@ s16b message_num(void)
 }
 
 
-
-/*
- * Recall the "text" of a saved message
+/*!
+ * @brief 過去のゲームメッセージを返す。 / Recall the "text" of a saved message
+ * @params age メッセージの世代
+ * @return メッセージの文字列ポインタ
  */
 cptr message_str(int age)
 {
-       s16b x;
-       s16b o;
+       s32b x;
+       s32b o;
        cptr s;
 
        /* Forgotten messages have no text */
@@ -2462,15 +2470,16 @@ cptr message_str(int age)
 }
 
 
-
-/*
- * Add a new message, with great efficiency
+/*!
+ * @brief ゲームメッセージをログに追加する。 / Add a new message, with great efficiency
+ * @params str 保存したいメッセージ
+ * @return なし
  */
 void message_add(cptr str)
 {
        int i, k, x, m, n;
 
-       char u[1024];
+       char u[4096];
        char splitted1[81];
        cptr splitted2;
 
@@ -2485,39 +2494,37 @@ void message_add(cptr str)
        /* Important Hack -- Ignore "long" messages */
        if (n >= MESSAGE_BUF / 4) return;
 
-       /* extra step -- split the message if n>80.   (added by Mogami) */
+       /* extra step -- split the message if n>80.(added by Mogami) */
        if (n > 80) {
 #ifdef JP
-         cptr t = str;
-
-         for (n = 0; n < 80; n++, t++)
-           if(iskanji(*t)) {
-             t++;
-             n++;
-           }
-         if (n == 81) n = 79; /* 最後の文字が漢字半分 */
+               cptr t = str;
+
+               for (n = 0; n < 80; n++, t++)
+               {
+                       if(iskanji(*t)) {
+                               t++;
+                               n++;
+                       }
+               }
+               if (n == 81) n = 79; /* 最後の文字が漢字半分 */
 #else
-         for (n = 80; n > 60; n--)
-                 if (str[n] == ' ') break;
-         if (n == 60)
-                 n = 80;
+               for (n = 80; n > 60; n--)
+                       if (str[n] == ' ') break;
+               if (n == 60) n = 80;
 #endif
-         splitted2 = str + n;
-         strncpy(splitted1, str ,n);
-         splitted1[n] = '\0';
-         str = splitted1;
+               splitted2 = str + n;
+               strncpy(splitted1, str ,n);
+               splitted1[n] = '\0';
+               str = splitted1;
        } else {
-         splitted2 = NULL;
+               splitted2 = NULL;
        }
 
-       /*** Step 2 -- Attempt to optimize ***/
+       /*** Step 2 -- 最適化の試行 / Attempt to optimize ***/
 
        /* Limit number of messages to check */
        m = message_num();
-
        k = m / 4;
-
-       /* Limit number of messages to check */
        if (k > MESSAGE_MAX / 32) k = MESSAGE_MAX / 32;
 
        /* Check previous message */
@@ -2543,8 +2550,8 @@ void message_add(cptr str)
 
                /* Find multiple */
 #ifdef JP
- for (t = buf; *t && (*t != '<' || (*(t+1) != 'x' )); t++) 
-     if( iskanji(*t))t++;
              for (t = buf; *t && (*t != '<' || (*(t+1) != 'x' )); t++) 
+                       if(iskanji(*t))t++;
 #else
                for (t = buf; *t && (*t != '<'); t++);
 #endif
@@ -2592,8 +2599,7 @@ void message_add(cptr str)
        /* Check the last few messages (if any to count) */
        for (i = message__next; k; k--)
        {
-               u16b q;
-
+               int q;
                cptr old;
 
                /* Back up and wrap if needed */
@@ -2732,7 +2738,7 @@ void message_add(cptr str)
        message__head += n + 1;
 
        /* recursively add splitted message (added by Mogami) */
- end_of_message_add:
+end_of_message_add:
        if (splitted2 != NULL)
          message_add(splitted2);
 }
@@ -2821,11 +2827,8 @@ static void msg_flush(int x)
 void msg_print(cptr msg)
 {
        static int p = 0;
-
        int n;
-
        char *t;
-
        char buf[1024];
 
        if (world_monster) return;
@@ -2837,7 +2840,7 @@ void msg_print(cptr msg)
                p = 0;
        }
 
-       /* Message Length */
+       /* Original Message Length */
        n = (msg ? strlen(msg) : 0);
 
        /* Hack -- flush when requested or needed */
@@ -2853,20 +2856,27 @@ void msg_print(cptr msg)
                p = 0;
        }
 
-
        /* No message */
        if (!msg) return;
 
        /* Paranoia */
        if (n > 1000) return;
 
+       /* Copy it */
+       if (!cheat_turn)
+       {
+               strcpy(buf, msg);
+       }
+       else
+       {
+               sprintf(buf, ("T:%d - %s"), turn, msg);
+       }
 
-       /* Memorize the message */
-       if (character_generated) message_add(msg);
-
+       /* New Message Length */
+       n = (buf ? strlen(buf) : 0);
 
-       /* Copy it */
-       strcpy(buf, msg);
+       /* Memorize the message */
+       if (character_generated) message_add(buf);
 
        /* Analyze the buffer */
        t = buf;
@@ -2942,7 +2952,6 @@ void msg_print(cptr msg)
                t += split; n -= split;
        }
 
-
        /* Display the tail of the message */
        Term_putstr(p, 0, n, TERM_WHITE, t);
 
@@ -2963,11 +2972,28 @@ void msg_print(cptr msg)
        p += n + 1;
 #endif
 
-
        /* Optional refresh */
        if (fresh_message) Term_fresh();
 }
 
+void msg_print_wizard(int cheat_type, cptr msg)
+{
+       if (!cheat_room && cheat_type == CHEAT_DUNGEON) return;
+       if (!cheat_peek && cheat_type == CHEAT_OBJECT) return;
+       if (!cheat_hear && cheat_type == CHEAT_MONSTER) return;
+       if (!cheat_xtra && cheat_type == CHEAT_MISC) return;
+
+       cptr cheat_mes[] = {"ITEM", "MONS", "DUNG", "MISC"};
+       char buf[1024];
+       sprintf(buf, "WIZ-%s:%s", cheat_mes[cheat_type], msg);
+       msg_print(buf);
+
+       if (cheat_diary_output)
+       {
+               do_cmd_write_nikki(NIKKI_WIZARD_LOG, 0, buf);
+       }
+
+}
 
 /*
  * Hack -- prevent "accidents" in "screen_save()" or "screen_load()"
@@ -3033,6 +3059,32 @@ void msg_format(cptr fmt, ...)
        msg_print(buf);
 }
 
+/*
+ * Display a formatted message, using "vstrnfmt()" and "msg_print()".
+ */
+void msg_format_wizard(int cheat_type, cptr fmt, ...)
+{
+       if(!cheat_room && cheat_type == CHEAT_DUNGEON) return;
+       if(!cheat_peek && cheat_type == CHEAT_OBJECT) return;
+       if(!cheat_hear && cheat_type == CHEAT_MONSTER) return;
+       if(!cheat_xtra && cheat_type == CHEAT_MISC) return;
+
+       va_list vp;
+       char buf[1024];
+
+       /* Begin the Varargs Stuff */
+       va_start(vp, fmt);
+
+       /* Format the args, save the length */
+       (void)vstrnfmt(buf, 1024, fmt, vp);
+
+       /* End the Varargs Stuff */
+       va_end(vp);
+
+       /* Display */
+       msg_print_wizard(cheat_type, buf);
+}
+
 
 
 /*
@@ -3753,7 +3805,7 @@ bool get_com(cptr prompt, char *command, bool z_escape)
 s16b get_quantity(cptr prompt, int max)
 {
        bool res;
-       int amt;
+       COMMAND_CODE amt;
        char tmp[80];
        char buf[80];
 
@@ -4197,7 +4249,7 @@ static char inkey_from_menu(void)
        int menu = 0;
        bool kisuu;
 
-       if (py - panel_row_min > 10) basey = 2;
+       if (p_ptr->y - panel_row_min > 10) basey = 2;
        else basey = 13;
        basex = 15;
 
@@ -4251,7 +4303,7 @@ static char inkey_from_menu(void)
                put_str(_("》", "> "),basey + 1 + num / 2, basex + 2 + (num % 2) * 24);
 
                /* Place the cursor on the player */
-               move_cursor_relative(py, px);
+               move_cursor_relative(p_ptr->y, p_ptr->x);
 
                /* Get a command */
                sub_cmd = inkey();
@@ -4813,7 +4865,7 @@ static int repeat__idx = 0;
 static int repeat__key[REPEAT_MAX];
 
 
-void repeat_push(int what)
+void repeat_push(COMMAND_CODE what)
 {
        /* Too many keys */
        if (repeat__cnt == REPEAT_MAX) return;
@@ -4826,7 +4878,7 @@ void repeat_push(int what)
 }
 
 
-bool repeat_pull(int *what)
+bool repeat_pull(COMMAND_CODE *what)
 {
        /* All out of keys */
        if (repeat__idx == repeat__cnt) return (FALSE);
@@ -4840,7 +4892,7 @@ bool repeat_pull(int *what)
 
 void repeat_check(void)
 {
-       int             what;
+       COMMAND_CODE what;
 
        /* Ignore some commands */
        if (command_cmd == ESCAPE) return;