OSDN Git Service

[Refactor] #37353 bool型の返り値に付いていたカッコを除去 / Removed parenthesis from 'return (TRUE...
[hengband/hengband.git] / src / util.c
index 5913bf0..c85fa8b 100644 (file)
 /* Purpose: Angband utilities -BEN- */
 
 #include "angband.h"
+#include "core.h"
+#include "term.h"
 #include "util.h"
+#include "files.h"
 #include "monsterrace-hook.h"
 #include "view-mainwindow.h"
 #include "quest.h"
 #include "floor.h"
 #include "world.h"
+#include "cmd-dump.h"
+#include "japanese.h"
+#include "player-class.h"
 
+/*!
+ * 10進数から16進数への変換テーブル /
+ * Global array for converting numbers to uppercase hecidecimal digit
+ * This array can also be used to convert a number to an octal digit
+ */
+const char hexsym[16] =
+{
+       '0', '1', '2', '3', '4', '5', '6', '7',
+       '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
+};
+
+/*
+ * Keymaps for each "mode" associated with each keypress.
+ */
+concptr keymap_act[KEYMAP_MODES][256];
+
+/*
+ * The next "free" index to use
+ */
+u32b message__next;
+
+/*
+ * The index of the oldest message (none yet)
+ */
+u32b message__last;
+
+/*
+ * The next "free" offset
+ */
+u32b message__head;
+
+/*
+ * The offset to the oldest used char (none yet)
+ */
+u32b message__tail;
+
+/*
+ * The array of offsets, by index [MESSAGE_MAX]
+ */
+u32b *message__ptr;
+
+/*
+ * The array of chars, by offset [MESSAGE_BUF]
+ */
+char *message__buf;
+
+bool msg_flag;                 /* Used in msg_print() for "buffering" */
+
+/*
+ * Number of active macros.
+ */
+s16b macro__num;
+
+/*
+ * Array of macro patterns [MACRO_MAX]
+ */
+concptr *macro__pat;
+
+/*
+ * Array of macro actions [MACRO_MAX]
+ */
+concptr *macro__act;
+
+/*
+ * Array of macro types [MACRO_MAX]
+ */
+bool *macro__cmd;
+
+/*
+ * Current macro action [1024]
+ */
+char *macro__buf;
+
+bool get_com_no_macros = FALSE;        /* Expand macros in "get_com" or not */
+
+bool inkey_base;               /* See the "inkey()" function */
+bool inkey_xtra;               /* See the "inkey()" function */
+bool inkey_scan;               /* See the "inkey()" function */
+bool inkey_flag;               /* See the "inkey()" function */
+
+bool use_menu;
+
+pos_list tmp_pos;
+
+/*
+ * The number of quarks
+ */
+STR_OFFSET quark__num;
+
+/*
+ * The pointers to the quarks [QUARK_MAX]
+ */
+concptr *quark__str;
 
 static int num_more = 0;
 
 /* Save macro trigger string for use in inkey_special() */
 static char inkey_macro_trigger_string[1024];
 
+int max_macrotrigger = 0; /*!< 現在登録中のマクロ(トリガー)の数 */
+concptr macro_template = NULL; /*!< Angband設定ファイルのT: タグ情報から読み込んだ長いTコードを処理するために利用する文字列ポインタ */
+concptr macro_modifier_chr; /*!< &x# で指定されるマクロトリガーに関する情報を記録する文字列ポインタ */
+concptr macro_modifier_name[MAX_MACRO_MOD]; /*!< マクロ上で取り扱う特殊キーを文字列上で表現するためのフォーマットを記録した文字列ポインタ配列 */
+concptr macro_trigger_name[MAX_MACRO_TRIG]; /*!< マクロのトリガーコード */
+concptr macro_trigger_keycode[2][MAX_MACRO_TRIG];  /*!< マクロの内容 */
+
+s16b command_cmd;              /* Current "Angband Command" */
+COMMAND_ARG command_arg;       /*!< 各種コマンドの汎用的な引数として扱う / Gives argument of current command */
+COMMAND_NUM command_rep;       /*!< 各種コマンドの汎用的なリピート数として扱う / Gives repetition of current command */
+DIRECTION command_dir;         /*!< 各種コマンドの汎用的な方向値処理として扱う/ Gives direction of current command */
+s16b command_see;              /* See "object1.c" */
+s16b command_wrk;              /* See "object1.c" */
+TERM_LEN command_gap = 999;         /* See "object1.c" */
+s16b command_new;              /* Command chaining from inven/equip view */
+
+
+
 #if 0
 #ifndef HAS_STRICMP
 
@@ -304,8 +421,13 @@ static errr path_temp(char *buf, int max)
 
 #endif
 
-/*
- * Create a new path by appending a file (or directory) to a path.
+/*!
+ * @brief ファイル入出力のためのパス生成する。/ Create a new path by appending a file (or directory) to a path.
+ * @param buf ファイルのフルを返すバッファ
+ * @param max bufのサイズ
+ * @param path ファイルパス
+ * @param file ファイル名
+ * @return エラーコード(ただし常に0を返す)
  *
  * This requires no special processing on simple machines, except
  * for verifying the size of the filename, but note the ability to
@@ -425,8 +547,6 @@ FILE *my_fopen_temp(char *buf, int max)
 {
        /* Generate a temporary filename */
        if (path_temp(buf, max)) return (NULL);
-
-       /* Open the file */
        return (my_fopen(buf, "w"));
 }
 
@@ -1678,92 +1798,89 @@ errr play_music(int type, int val)
 /*
  * Hack -- Select floor music.
  */
-void select_floor_music(void)
+void select_floor_music(player_type *player_ptr)
 {
-       int i;
-       /* No sound */
        if (!use_music) return;
 
-       if(p_ptr->ambush_flag)
+       if (player_ptr->ambush_flag)
        {
-               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_AMBUSH);
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_AMBUSH)) return;
+       } 
+
+       if(player_ptr->wild_mode)
+       {
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WILD)) return;
        }
 
-       if(p_ptr->wild_mode)
+       if(player_ptr->current_floor_ptr->inside_arena)
        {
-               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WILD);
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_ARENA)) return;
        }
 
-       if(p_ptr->inside_arena)
+       if(player_ptr->phase_out)
        {
-               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_ARENA);
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BATTLE)) return;
        }
 
-       if(p_ptr->inside_battle)
+       if(player_ptr->current_floor_ptr->inside_quest)
        {
-               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BATTLE);
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_QUEST, player_ptr->current_floor_ptr->inside_quest)) return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST)) return;
        }
 
-       if(p_ptr->inside_quest)
+       if(player_ptr->dungeon_idx)
        {
-               if(play_music(TERM_XTRA_MUSIC_QUEST, p_ptr->inside_quest))
+               if (player_ptr->feeling == 2)
                {
-                       play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST);
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL2)) return;
                }
-               return;
-       }
-
-       for(i = 0; i < max_q_idx; i++)
-       { // TODO マクロで類似条件を統合すること
-               if(quest[i].status == QUEST_STATUS_TAKEN &&
-                       (quest[i].type == QUEST_TYPE_KILL_LEVEL || quest[i].type == QUEST_TYPE_RANDOM) &&
-                        quest[i].level == current_floor_ptr->dun_level && p_ptr->dungeon_idx == quest[i].dungeon)
+               else if (player_ptr->feeling >= 3 && player_ptr->feeling <= 5)
                {
-                       if(play_music(TERM_XTRA_MUSIC_QUEST, i)) 
-                       {
-                               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST);
-                       }
-                       return;
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL1)) return;
                }
-       }
-
-       if(p_ptr->dungeon_idx)
-       {
-               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, p_ptr->dungeon_idx))
+                       if (!play_music(TERM_XTRA_MUSIC_DUNGEON, player_ptr->dungeon_idx)) return;
+
+                       if (player_ptr->current_floor_ptr->dun_level < 40)
                        {
-                               if(current_floor_ptr->dun_level < 40) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_LOW);
-                               else if(current_floor_ptr->dun_level < 80) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_MED);
-                               else play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_HIGH);
+                               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_LOW)) return;
+                       }
+                       else if (player_ptr->current_floor_ptr->dun_level < 80)
+                       {
+                               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_MED)) return;
+                       }
+                       else
+                       {
+                               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_HIGH)) return;
                        }
                }
-               return;
        }
 
-       if(p_ptr->town_num)
+       if(player_ptr->town_num)
        {
-               if(play_music(TERM_XTRA_MUSIC_TOWN, p_ptr->town_num))
-               {
-                       play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_TOWN);
-               }
+               if (!play_music(TERM_XTRA_MUSIC_TOWN, player_ptr->town_num)) return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_TOWN)) return;
                return;
        }
 
-       if(!current_floor_ptr->dun_level)
+       if(!player_ptr->current_floor_ptr->dun_level)
        {
-               if(p_ptr->lev >= 45) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD3);
-               else if(p_ptr->lev >= 25) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD2);
-               else play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD1);
-               return;
+               if (player_ptr->lev >= 45)
+               {
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD3)) return;
+               }
+               else if (player_ptr->lev >= 25)
+               {
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD2)) return;
+               }
+               else
+               {
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD1)) return;
+               }
        }
        
+       play_music(TERM_XTRA_MUSIC_MUTE, 0);
 }
 
 
@@ -2040,7 +2157,7 @@ char (*inkey_hack)(int flush_first) = NULL;
  * is only requested (via "Term_inkey()") when "angband_term[0]" is active.
  *
  * Mega-Hack -- This function is used as the entry point for clearing the
- * "signal_count" variable, and of the "character_saved" variable.
+ * "signal_count" variable, and of the "current_world_ptr->character_saved" variable.
  *
  * Hack -- Note the use of "inkey_next" to allow "keymaps" to be processed.
  *
@@ -2105,7 +2222,7 @@ char inkey(void)
        (void)Term_get_cursor(&v);
 
        /* Show the cursor if waiting, except sometimes in "command" mode */
-       if (!inkey_scan && (!inkey_flag || hilite_player || character_icky))
+       if (!inkey_scan && (!inkey_flag || hilite_player || current_world_ptr->character_icky))
        {
                /* Show the cursor */
                (void)Term_set_cursor(1);
@@ -2140,7 +2257,7 @@ char inkey(void)
                        Term_activate(angband_term[0]);
 
                        /* Mega-Hack -- reset saved flag */
-                       character_saved = FALSE;
+                       current_world_ptr->character_saved = FALSE;
 
                        /* Mega-Hack -- reset signal counter */
                        signal_count = 0;
@@ -2828,7 +2945,7 @@ void msg_print(concptr msg)
        n = strlen(buf);
 
        /* Memorize the message */
-       if (character_generated) message_add(buf);
+       if (current_world_ptr->character_generated) message_add(buf);
 
        /* Analyze the buffer */
        t = buf;
@@ -2892,7 +3009,7 @@ void msg_print(concptr msg)
                msg_flush(split + 1);
 
                /* Memorize the piece */
-               /* if (character_generated) message_add(t); */
+               /* if (current_world_ptr->character_generated) message_add(t); */
 
                /* Restore the split character */
                t[split] = oops;
@@ -2908,10 +3025,10 @@ void msg_print(concptr msg)
        Term_putstr(p, 0, n, TERM_WHITE, t);
 
        /* Memorize the tail */
-       /* if (character_generated) message_add(t); */
+       /* if (current_world_ptr->character_generated) message_add(t); */
 
        p_ptr->window |= (PW_MESSAGE);
-       update_output();
+       update_output(p_ptr);
 
        /* Remember the message */
        msg_flag = TRUE;
@@ -2927,6 +3044,7 @@ void msg_print(concptr msg)
        if (fresh_message) Term_fresh();
 }
 
+
 void msg_print_wizard(int cheat_type, concptr msg)
 {
        if (!cheat_room && cheat_type == CHEAT_DUNGEON) return;
@@ -2941,11 +3059,12 @@ void msg_print_wizard(int cheat_type, concptr msg)
 
        if (cheat_diary_output)
        {
-               do_cmd_write_nikki(NIKKI_WIZARD_LOG, 0, buf);
+               exe_write_diary(p_ptr, NIKKI_WIZARD_LOG, 0, buf);
        }
 
 }
 
+
 /*
  * Hack -- prevent "accidents" in "screen_save()" or "screen_load()"
  */
@@ -2957,7 +3076,7 @@ static int screen_depth = 0;
  *
  * This function must match exactly one call to "screen_load()".
  */
-void screen_save(void)
+void screen_save()
 {
        /* Hack -- Flush messages */
        msg_print(NULL);
@@ -2966,7 +3085,7 @@ void screen_save(void)
        if (screen_depth++ == 0) Term_save();
 
        /* Increase "icky" depth */
-       character_icky++;
+       current_world_ptr->character_icky++;
 }
 
 
@@ -2975,7 +3094,7 @@ void screen_save(void)
  *
  * This function must match exactly one call to "screen_save()".
  */
-void screen_load(void)
+void screen_load()
 {
        /* Hack -- Flush messages */
        msg_print(NULL);
@@ -2984,7 +3103,7 @@ void screen_load(void)
        if (--screen_depth == 0) Term_load();
 
        /* Decrease "icky" depth */
-       character_icky--;
+       current_world_ptr->character_icky--;
 }
 
 
@@ -3037,7 +3156,6 @@ void msg_format_wizard(int cheat_type, concptr fmt, ...)
 }
 
 
-
 /*
  * Display a string on the screen using an attribute.
  *
@@ -3614,15 +3732,15 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode)
        if (auto_more)
        {
                p_ptr->window |= PW_MESSAGE;
-               handle_stuff();
+               handle_stuff(p_ptr);
                num_more = 0;
        }
+
        msg_print(NULL);
 
        if (!rogue_like_commands)
                mode &= ~CHECK_OKAY_CANCEL;
 
-
        /* Hack -- Build a "useful" prompt */
        if (mode & CHECK_OKAY_CANCEL)
        {
@@ -3648,7 +3766,7 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode)
                /* HACK : Add the line to message buffer */
                message_add(buf);
                p_ptr->window |= (PW_MESSAGE);
-               handle_stuff();
+               handle_stuff(p_ptr);
        }
 
        /* Get an acceptable answer */
@@ -3733,11 +3851,11 @@ bool get_com(concptr prompt, char *command, bool z_escape)
        prt("", 0, 0);
 
        /* Handle "cancel" */
-       if (*command == ESCAPE) return (FALSE);
-       if (z_escape && ((*command == 'z') || (*command == 'Z'))) return (FALSE);
+       if (*command == ESCAPE) return FALSE;
+       if (z_escape && ((*command == 'z') || (*command == 'Z'))) return FALSE;
 
        /* Success */
-       return (TRUE);
+       return TRUE;
 }
 
 
@@ -3789,7 +3907,6 @@ QUANTITY get_quantity(concptr prompt, QUANTITY max)
        /* Build a prompt if needed */
        if (!prompt)
        {
-               /* Build a prompt */
                sprintf(tmp, _("いくつですか (1-%d): ", "Quantity (1-%d): "), max);
 
                /* Use that prompt */
@@ -4224,7 +4341,7 @@ static char inkey_from_menu(void)
                                        if (p_ptr->pclass == special_menu_info[hoge].jouken_naiyou) menu_name = special_menu_info[hoge].name;
                                        break;
                                case MENU_WILD:
-                                       if (!current_floor_ptr->dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
+                                       if (!p_ptr->current_floor_ptr->dun_level && !p_ptr->current_floor_ptr->inside_arena && !p_ptr->current_floor_ptr->inside_quest)
                                        {
                                                if ((byte)p_ptr->wild_mode == special_menu_info[hoge].jouken_naiyou) menu_name = special_menu_info[hoge].name;
                                        }
@@ -4593,7 +4710,7 @@ void request_command(int shopping)
        {
                concptr s;
 
-               object_type *o_ptr = &inventory[i];
+               object_type *o_ptr = &p_ptr->inventory_list[i];
                if (!o_ptr->k_idx) continue;
 
                /* No inscription */
@@ -4653,10 +4770,10 @@ bool is_a_vowel(int ch)
        case 'I':
        case 'O':
        case 'U':
-               return (TRUE);
+               return TRUE;
        }
 
-       return (FALSE);
+       return FALSE;
 }
 
 
@@ -4680,7 +4797,7 @@ static bool insert_str(char *buf, concptr target, concptr insert)
        buf = my_strstr(buf, target);
 
        /* No target found */
-       if (!buf) return (FALSE);
+       if (!buf) return FALSE;
 
        /* Be sure we have an insertion string */
        if (!insert) insert = "";
@@ -4712,7 +4829,7 @@ static bool insert_str(char *buf, concptr target, concptr insert)
        for (i = 0; i < i_len; ++i) buf[i] = insert[i];
 
        /* Successful operation */
-       return (TRUE);
+       return TRUE;
 }
 
 
@@ -4802,13 +4919,13 @@ void repeat_push(COMMAND_CODE what)
 bool repeat_pull(COMMAND_CODE *what)
 {
        /* All out of keys */
-       if (repeat__idx == repeat__cnt) return (FALSE);
+       if (repeat__idx == repeat__cnt) return FALSE;
 
        /* Grab the next key, advance */
        *what = repeat__key[repeat__idx++];
 
        /* Success */
-       return (TRUE);
+       return TRUE;
 }
 
 void repeat_check(void)