OSDN Git Service

[Refactor] #37353 bool型の返り値に付いていたカッコを除去 / Removed parenthesis from 'return (TRUE...
[hengband/hengband.git] / src / util.c
index 392f505..c85fa8b 100644 (file)
@@ -11,6 +11,8 @@
 /* Purpose: Angband utilities -BEN- */
 
 #include "angband.h"
+#include "core.h"
+#include "term.h"
 #include "util.h"
 #include "files.h"
 #include "monsterrace-hook.h"
@@ -20,6 +22,7 @@
 #include "world.h"
 #include "cmd-dump.h"
 #include "japanese.h"
+#include "player-class.h"
 
 /*!
  * 10進数から16進数への変換テーブル /
@@ -32,6 +35,10 @@ const char hexsym[16] =
        '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
@@ -63,6 +70,8 @@ u32b *message__ptr;
  */
 char *message__buf;
 
+bool msg_flag;                 /* Used in msg_print() for "buffering" */
+
 /*
  * Number of active macros.
  */
@@ -88,12 +97,27 @@ bool *macro__cmd;
  */
 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() */
@@ -106,6 +130,17 @@ 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
 
@@ -386,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
@@ -507,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"));
 }
 
@@ -1760,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 (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_LOW)) return;
+                       }
+                       else if (player_ptr->current_floor_ptr->dun_level < 80)
                        {
-                               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_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);
 }
 
 
@@ -2993,7 +3028,7 @@ void msg_print(concptr msg)
        /* 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;
@@ -3009,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;
@@ -3023,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()"
  */
@@ -3039,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);
@@ -3057,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);
@@ -3119,7 +3156,6 @@ void msg_format_wizard(int cheat_type, concptr fmt, ...)
 }
 
 
-
 /*
  * Display a string on the screen using an attribute.
  *
@@ -3696,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)
        {
@@ -3730,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 */
@@ -3815,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;
 }
 
 
@@ -3871,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 */
@@ -4306,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;
                                        }
@@ -4735,10 +4770,10 @@ bool is_a_vowel(int ch)
        case 'I':
        case 'O':
        case 'U':
-               return (TRUE);
+               return TRUE;
        }
 
-       return (FALSE);
+       return FALSE;
 }
 
 
@@ -4762,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 = "";
@@ -4794,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;
 }
 
 
@@ -4884,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)