OSDN Git Service

[Refactor] #38844 inventory を player_type 構造体に inventory_list に改名して取り込み (コメントの修正は後日)
[hengband/hengband.git] / src / wizard1.c
index d58ad2f..6d128fe 100644 (file)
  */
 
 #include "angband.h"
+#include "util.h"
+
+#include "artifact.h"
+#include "sort.h"
+#include "store.h"
+#include "monster.h"
+#include "object-flavor.h"
+#include "object-hook.h"
 
 
 #ifdef ALLOW_SPOILERS
@@ -29,7 +37,7 @@ static FILE *fff = NULL;
  * @param r_ptr モンスター種族の構造体ポインタ
  * @return シンボル職の記述名
  */
-static cptr attr_to_text(monster_race *r_ptr)
+static concptr attr_to_text(monster_race *r_ptr)
 {
 #ifdef JP000
        if (r_ptr->flags1 & RF1_ATTR_CLEAR)    return "透明な";
@@ -95,7 +103,7 @@ static cptr attr_to_text(monster_race *r_ptr)
 typedef struct
 {
        OBJECT_TYPE_VALUE tval;
-       cptr name;
+       concptr name;
 } grouper;
 
 
@@ -285,7 +293,7 @@ static void kind_info(char *buf, char *dam, char *wgt, char *chance, DEPTH *lev,
  * @param fname ファイル名
  * @return なし
  */
-static void spoil_obj_desc(cptr fname)
+static void spoil_obj_desc(concptr fname)
 {
        int i, k, s, t, n = 0, group_start = 0;
 
@@ -517,7 +525,7 @@ typedef struct flag_desc flag_desc;
 struct flag_desc
 {
        const int flag;
-       cptr const desc;
+       concptr const desc;
 };
 
 
@@ -858,7 +866,7 @@ typedef struct
         *
         * This list includes extra attacks, for simplicity.
         */
-       cptr pval_affects[N_ELEMENTS(stat_flags_desc) - 1 +
+       concptr pval_affects[N_ELEMENTS(stat_flags_desc) - 1 +
                          N_ELEMENTS(pval_flags1_desc) + 1];
 
 } pval_info_type;
@@ -881,22 +889,22 @@ typedef struct
        pval_info_type pval_info;
 
        /* A list of an object's slaying preferences */
-       cptr slays[N_ELEMENTS(slay_flags_desc) + 1];
+       concptr slays[N_ELEMENTS(slay_flags_desc) + 1];
 
        /* A list if an object's elemental brands */
-       cptr brands[N_ELEMENTS(brand_flags_desc) + 1];
+       concptr brands[N_ELEMENTS(brand_flags_desc) + 1];
 
        /* A list of immunities granted by an object */
-       cptr immunities[N_ELEMENTS(immune_flags_desc) + 1];
+       concptr immunities[N_ELEMENTS(immune_flags_desc) + 1];
 
        /* A list of resistances granted by an object */
-       cptr resistances[N_ELEMENTS(resist_flags_desc) + 1];
+       concptr resistances[N_ELEMENTS(resist_flags_desc) + 1];
 
        /* A list of stats sustained by an object */
-       cptr sustains[N_ELEMENTS(sustain_flags_desc)  - 1 + 1];
+       concptr sustains[N_ELEMENTS(sustain_flags_desc)  - 1 + 1];
 
        /* A list of various magical qualities an object may have */
-       cptr misc_magic[N_ELEMENTS(misc_flags2_desc) + N_ELEMENTS(misc_flags3_desc)
+       concptr misc_magic[N_ELEMENTS(misc_flags2_desc) + N_ELEMENTS(misc_flags3_desc)
                        + 1       /* Permanent Light */
                        + 1       /* TY curse */
                        + 1       /* type of curse */
@@ -906,7 +914,7 @@ typedef struct
        char addition[80];
 
        /* A string describing an artifact's activation */
-       cptr activation;
+       concptr activation;
 
        /* "Level 20, Rarity 30, 3.0 lbs, 20000 Gold" */
        char misc_desc[80];
@@ -944,7 +952,7 @@ static void spoiler_blanklines(int n)
  * @param str 出力したい文字列
  * @return なし
  */
-static void spoiler_underline(cptr str)
+static void spoiler_underline(concptr str)
 {
        fprintf(fff, "%s\n", str);
        spoiler_out_n_chars(strlen(str), '-');
@@ -972,9 +980,9 @@ static void spoiler_underline(cptr str)
  * The possibly updated description pointer is returned.
  * </pre>
  */
-static cptr *spoiler_flag_aux(const BIT_FLAGS art_flags[TR_FLAG_SIZE],
+static concptr *spoiler_flag_aux(const BIT_FLAGS art_flags[TR_FLAG_SIZE],
                              const flag_desc *flag_ptr,
-                             cptr *desc_ptr, const int n_elmnts)
+                             concptr *desc_ptr, const int n_elmnts)
 {
        int i;
 
@@ -1016,7 +1024,7 @@ static void analyze_pval(object_type *o_ptr, pval_info_type *pi_ptr)
 {
        BIT_FLAGS flgs[TR_FLAG_SIZE];
 
-       cptr *affects_list;
+       concptr *affects_list;
 
        /* If pval == 0, there is nothing to do. */
        if (!o_ptr->pval)
@@ -1066,7 +1074,7 @@ static void analyze_pval(object_type *o_ptr, pval_info_type *pi_ptr)
  * @param slay_list 種族スレイ構造体の参照ポインタ
  * @return なし
  */
-static void analyze_slay(object_type *o_ptr, cptr *slay_list)
+static void analyze_slay(object_type *o_ptr, concptr *slay_list)
 {
        BIT_FLAGS flgs[TR_FLAG_SIZE];
 
@@ -1087,7 +1095,7 @@ static void analyze_slay(object_type *o_ptr, cptr *slay_list)
  * @param brand_list 属性ブランド構造体の参照ポインタ
  * @return なし
  */
-static void analyze_brand(object_type *o_ptr, cptr *brand_list)
+static void analyze_brand(object_type *o_ptr, concptr *brand_list)
 {
        BIT_FLAGS flgs[TR_FLAG_SIZE];
 
@@ -1108,7 +1116,7 @@ static void analyze_brand(object_type *o_ptr, cptr *brand_list)
  * @param resist_list 通常耐性構造体の参照ポインタ
  * @return なし
  */
-static void analyze_resist(object_type *o_ptr, cptr *resist_list)
+static void analyze_resist(object_type *o_ptr, concptr *resist_list)
 {
        BIT_FLAGS flgs[TR_FLAG_SIZE];
 
@@ -1129,7 +1137,7 @@ static void analyze_resist(object_type *o_ptr, cptr *resist_list)
  * @param immune_list 免疫構造体の参照ポインタ
  * @return なし
  */
-static void analyze_immune(object_type *o_ptr, cptr *immune_list)
+static void analyze_immune(object_type *o_ptr, concptr *immune_list)
 {
        BIT_FLAGS flgs[TR_FLAG_SIZE];
 
@@ -1150,7 +1158,7 @@ static void analyze_immune(object_type *o_ptr, cptr *immune_list)
  * @param sustain_list 維持特性構造体の参照ポインタ
  * @return なし
  */
-static void analyze_sustains(object_type *o_ptr, cptr *sustain_list)
+static void analyze_sustains(object_type *o_ptr, concptr *sustain_list)
 {
        BIT_FLAGS flgs[TR_FLAG_SIZE];
 
@@ -1187,7 +1195,7 @@ static void analyze_sustains(object_type *o_ptr, cptr *sustain_list)
  * @param misc_list その他の特性構造体の参照ポインタ
  * @return なし
  */
-static void analyze_misc_magic(object_type *o_ptr, cptr *misc_list)
+static void analyze_misc_magic(object_type *o_ptr, concptr *misc_list)
 {
        BIT_FLAGS flgs[TR_FLAG_SIZE];
        POSITION rad;
@@ -1400,7 +1408,7 @@ static void print_header(void)
  * @param separator フラグ表示の区切り記号
  * @return なし
  */
-static void spoiler_outlist(cptr header, cptr *list, char separator)
+static void spoiler_outlist(concptr header, concptr *list, char separator)
 {
        int line_len, buf_len;
        char line[MAX_LINE_LEN+1], buf[80];
@@ -1557,7 +1565,6 @@ static bool make_fake_artifact(object_type *o_ptr, IDX name1)
 
        if (!i) return (FALSE);
 
-       /* Create the artifact */
        object_prep(o_ptr, i);
 
        /* Save the name */
@@ -1584,7 +1591,7 @@ static bool make_fake_artifact(object_type *o_ptr, IDX name1)
  * @param fname 生成ファイル名
  * @return なし
  */
-static void spoil_artifact(cptr fname)
+static void spoil_artifact(concptr fname)
 {
        int i;
        IDX j;
@@ -1661,12 +1668,12 @@ static void spoil_artifact(cptr fname)
  * @param fname 生成ファイル名
  * @return なし
  */
-static void spoil_mon_desc(cptr fname)
+static void spoil_mon_desc(concptr fname)
 {
        int i, n = 0;
 
        u16b why = 2;
-       s16b *who;
+       MONRACE_IDX *who;
 
        char buf[1024];
 
@@ -1694,7 +1701,7 @@ static void spoil_mon_desc(cptr fname)
        }
 
        /* Allocate the "who" array */
-       C_MAKE(who, max_r_idx, s16b);
+       C_MAKE(who, max_r_idx, MONRACE_IDX);
 
        /* Dump the header */
        fprintf(fff, "Monster Spoilers for Hengband Version %d.%d.%d\n",
@@ -1717,19 +1724,15 @@ static void spoil_mon_desc(cptr fname)
                if (r_ptr->name) who[n++] = (s16b)i;
        }
 
-       /* Select the sort method */
-       ang_sort_comp = ang_sort_comp_hook;
-       ang_sort_swap = ang_sort_swap_hook;
-
        /* Sort the array by dungeon depth of monsters */
-       ang_sort(who, &why, n);
+       ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
 
        /* Scan again */
        for (i = 0; i < n; i++)
        {
                monster_race *r_ptr = &r_info[who[i]];
 
-               cptr name = (r_name + r_ptr->name);
+               concptr name = (r_name + r_ptr->name);
                if (r_ptr->flags7 & (RF7_KAGE)) continue;
 
                /* Get the "name" */
@@ -1748,14 +1751,12 @@ static void spoil_mon_desc(cptr fname)
                        sprintf(nam, _("    %s", "The %s"), name);
                }
 
-
                /* Level */
                sprintf(lev, "%d", (int)r_ptr->level);
 
                /* Rarity */
                sprintf(rar, "%d", (int)r_ptr->rarity);
 
-               /* Speed */
                if (r_ptr->speed >= 110)
                {
                        sprintf(spd, "+%d", (r_ptr->speed - 110));
@@ -1826,9 +1827,9 @@ static void spoil_mon_desc(cptr fname)
  * @param str 文字列参照ポインタ
  * @return なし
  */
-static void spoil_out(cptr str)
+static void spoil_out(concptr str)
 {
-       cptr r;
+       concptr r;
 
        /* Line buffer */
        static char roff_buf[256];
@@ -1912,9 +1913,9 @@ static void spoil_out(cptr str)
 #ifdef JP
                                bool k_flag_local;
                                bool iskanji_flag_local = FALSE;
-                               cptr tail = str + (k_flag ? 2 : 1);
+                               concptr tail = str + (k_flag ? 2 : 1);
 #else
-                               cptr tail = str + 1;
+                               concptr tail = str + 1;
 #endif
 
                                for (; *tail; tail++)
@@ -1994,7 +1995,7 @@ static void spoil_out(cptr str)
  * @param str 文字列参照ポインタ
  * @return なし
  */
-static void roff_func(TERM_COLOR attr, cptr str)
+static void roff_func(TERM_COLOR attr, concptr str)
 {
        /* Unused */
        (void)attr;
@@ -2009,14 +2010,14 @@ static void roff_func(TERM_COLOR attr, cptr str)
  * @param fname ファイル名
  * @return なし
  */
-static void spoil_mon_info(cptr fname)
+static void spoil_mon_info(concptr fname)
 {
        char buf[1024];
        int i, l, n = 0;
        BIT_FLAGS flags1;
 
        u16b why = 2;
-       s16b *who;
+       MONRACE_IDX *who;
 
        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
@@ -2042,7 +2043,7 @@ static void spoil_mon_info(cptr fname)
        spoil_out("------------------------------------------\n\n");
 
        /* Allocate the "who" array */
-       C_MAKE(who, max_r_idx, s16b);
+       C_MAKE(who, max_r_idx, MONRACE_IDX);
 
        /* Scan the monsters */
        for (i = 1; i < max_r_idx; i++)
@@ -2053,13 +2054,7 @@ static void spoil_mon_info(cptr fname)
                if (r_ptr->name) who[n++] = (s16b)i;
        }
 
-       /* Select the sort method */
-       ang_sort_comp = ang_sort_comp_hook;
-       ang_sort_swap = ang_sort_swap_hook;
-
-       /* Sort the array by dungeon depth of monsters */
-       ang_sort(who, &why, n);
-
+       ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
 
        /*
         * List all monsters in order
@@ -2117,7 +2112,6 @@ static void spoil_mon_info(cptr fname)
                sprintf(buf, "Rar:%d  ", r_ptr->rarity);
                spoil_out(buf);
 
-               /* Speed */
                if (r_ptr->speed >= 110)
                {
                        sprintf(buf, "Spd:+%d  ", (r_ptr->speed - 110));
@@ -2220,74 +2214,13 @@ static bool is_partial_tree(int *tree, int *partial_tree)
        return FALSE;
 }
 
-
-/*!
- * @brief 進化ツリーをソートするためモンスター種族の判定関数 / 
- * Sorting hook -- Comp function
- * @param u 進化木構造データ
- * @param v 未使用
- * @param a 比較したいモンスター種族ID1
- * @param b 比較したいモンスター種族ID2
- * @return 2が大きければTRUEを返す
- */
-static bool ang_sort_comp_evol_tree(vptr u, vptr v, int a, int b)
-{
-       int **evol_tree = (int **)u;
-
-       int w1 = evol_tree[a][0];
-       int w2 = evol_tree[b][0];
-       monster_race *r1_ptr = &r_info[w1];
-       monster_race *r2_ptr = &r_info[w2];
-
-       /* Unused */
-       (void)v;
-
-       /* Used tree first */
-       if (w1 && !w2) return TRUE;
-       if (!w1 && w2) return FALSE;
-
-       /* Sort by monster level */
-       if (r1_ptr->level < r2_ptr->level) return TRUE;
-       if (r1_ptr->level > r2_ptr->level) return FALSE;
-
-       /* Sort by monster experience */
-       if (r1_ptr->mexp < r2_ptr->mexp) return TRUE;
-       if (r1_ptr->mexp > r2_ptr->mexp) return FALSE;
-
-       /* Compare indexes */
-       return w1 <= w2;
-}
-
-/*!
- * @brief 進化ツリーをソートするため木構造のスワップ関数 / 
- * Sorting hook -- Swap function
- * @param u 進化木構造データ
- * @param v 未使用
- * @param a スワップしたい木構造1
- * @param b スワップしたい木構造2
- * @return 2が大きければTRUEを返す
- */
-static void ang_sort_swap_evol_tree(vptr u, vptr v, int a, int b)
-{
-       int **evol_tree = (int **)u;
-       int *holder;
-
-       /* Unused */
-       (void)v;
-
-       /* Swap */
-       holder = evol_tree[a];
-       evol_tree[a] = evol_tree[b];
-       evol_tree[b] = holder;
-}
-
 /*!
  * @brief 進化ツリーをスポイラー出力するメインルーチン / 
  * Print monsters' evolution information to file
  * @param fname 出力ファイル名
  * @return なし
  */
-static void spoil_mon_evol(cptr fname)
+static void spoil_mon_evol(concptr fname)
 {
        char buf[1024];
        monster_race *r_ptr;
@@ -2366,13 +2299,7 @@ static void spoil_mon_evol(cptr fname)
        }
 
        /* Step 3: Sort the evolution trees */
-
-       /* Select the sort method */
-       ang_sort_comp = ang_sort_comp_evol_tree;
-       ang_sort_swap = ang_sort_swap_evol_tree;
-
-       /* Sort the array */
-       ang_sort(evol_tree, NULL, max_r_idx);
+       ang_sort(evol_tree, NULL, max_r_idx, ang_sort_comp_evol_tree, ang_sort_swap_evol_tree);
 
        /* Step 4: Print the evolution trees */
        for (i = 0; i < max_r_idx; i++)
@@ -2595,7 +2522,7 @@ static void spoil_random_artifact_aux(object_type *o_ptr, int i)
  * @param fname 出力ファイル名
  * @return なし
  */
-void spoil_random_artifact(cptr fname)
+void spoil_random_artifact(concptr fname)
 {
        int i,j;
 
@@ -2629,19 +2556,19 @@ void spoil_random_artifact(cptr fname)
                /* random artifacts wielding */
                for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
                {
-                       q_ptr = &inventory[i];
+                       q_ptr = &p_ptr->inventory_list[i];
                        spoil_random_artifact_aux(q_ptr, j);
                }
 
-               /* random artifacts in inventory */
+               /* random artifacts in p_ptr->inventory_list */
                for (i = 0; i < INVEN_PACK; i++)
                {
-                       q_ptr = &inventory[i];
+                       q_ptr = &p_ptr->inventory_list[i];
                        spoil_random_artifact_aux(q_ptr, j);
                }
 
                /* random artifacts in home */
-               st_ptr = &town[1].store[STORE_HOME];
+               st_ptr = &town_info[1].store[STORE_HOME];
                for (i = 0; i < st_ptr->stock_num; i++)
                {
                        q_ptr = &st_ptr->stock[i];
@@ -2649,7 +2576,7 @@ void spoil_random_artifact(cptr fname)
                }
 
                /* random artifacts in museum */
-               st_ptr = &town[1].store[STORE_MUSEUM];
+               st_ptr = &town_info[1].store[STORE_MUSEUM];
                for (i = 0; i < st_ptr->stock_num; i++)
                {
                        q_ptr = &st_ptr->stock[i];