OSDN Git Service

[Refactor] #39068 エンバグを修正しつつ,add_essence() の item_tester_tval グローバル参照をローカル引数に収める.
[hengband/hengband.git] / src / snipe.c
index 462da5a..73c7ac1 100644 (file)
@@ -7,6 +7,15 @@
  */
 
 #include "angband.h"
+#include "core.h"
+#include "util.h"
+#include "term.h"
+
+#include "player-status.h"
+#include "cmd-basic.h"
+#include "snipe.h"
+#include "monsterrace.h"
+#include "view-mainwindow.h"
 
 #define MAX_SNIPE_POWERS 16
 
@@ -16,13 +25,13 @@ typedef struct snipe_power snipe_power;
 /*! スナイパー技能情報の構造体 */
 struct snipe_power
 {
-       int     min_lev;
-       int     mana_cost;
-       const char *name;
+       PLAYER_LEVEL min_lev;
+       MANA_POINT mana_cost;
+       concptr name;
 };
 
 /*! スナイパー技能の解説メッセージ */
-static cptr const snipe_tips[MAX_SNIPE_POWERS] =
+static concptr const snipe_tips[MAX_SNIPE_POWERS] =
 {
 #ifdef JP
        "精神を集中する。射撃の威力、精度が上がり、高度な射撃術が使用できるようになる。",
@@ -111,16 +120,10 @@ static bool snipe_concentrate(void)
        if ((int)p_ptr->concent < (2 + (p_ptr->lev + 5) / 10)) p_ptr->concent++;
 
        msg_format(_("集中した。(集中度 %d)", "You concentrate deeply. (lvl %d)"), p_ptr->concent);
-       reset_concent = FALSE;
-
-       /* Recalculate bonuses */
-       p_ptr->update |= (PU_BONUS);
+       p_ptr->reset_concent = FALSE;
 
+       p_ptr->update |= (PU_BONUS | PU_MONSTERS);
        p_ptr->redraw |= (PR_STATUS);
-
-       /* Update the monsters */
-       p_ptr->update |= (PU_MONSTERS);
-
        return (TRUE);
 }
 
@@ -137,15 +140,10 @@ void reset_concentration(bool msg)
        }
 
        p_ptr->concent = 0;
-       reset_concent = FALSE;
-
-       /* Recalculate bonuses */
-       p_ptr->update |= (PU_BONUS);
+       p_ptr->reset_concent = FALSE;
 
+       p_ptr->update |= (PU_BONUS | PU_MONSTERS);
        p_ptr->redraw |= (PR_STATUS);
-
-       /* Update the monsters */
-       p_ptr->update |= (PU_MONSTERS);
 }
 
 /*! 
@@ -167,24 +165,18 @@ int boost_concentration_damage(int tdam)
  */
 void display_snipe_list(void)
 {
-       int             i;
-       int             y = 1;
-       int             x = 1;
-       int             plev = p_ptr->lev;
+       int i;
+       TERM_LEN y = 1;
+       TERM_LEN x = 1;
+       PLAYER_LEVEL plev = p_ptr->lev;
        snipe_power     spell;
        char            psi_desc[80];
 
        /* Display a list of spells */
        prt("", y, x);
-#ifdef JP
-       put_str("名前", y, x + 5);
-       put_str("Lv   MP", y, x + 35);
-#else
-       put_str("Name", y, x + 5);
-       put_str("Lv Mana", y, x + 35);
-#endif
+       put_str(_("名前", "Name"), y, x + 5);
+       put_str(_("Lv   MP", "Lv Mana"), y, x + 35);
 
-       /* Dump the spells */
        for (i = 0; i < MAX_SNIPE_POWERS; i++)
        {
                /* Access the available spell */
@@ -192,7 +184,6 @@ void display_snipe_list(void)
                if (spell.min_lev > plev) continue;
                if (spell.mana_cost > (int)p_ptr->concent) continue;
 
-               /* Dump the spell */
                sprintf(psi_desc, "  %c) %-30s%2d %4d",
                        I2A(i), spell.name, spell.min_lev, spell.mana_cost);
 
@@ -220,22 +211,20 @@ void display_snipe_list(void)
  * when you run it. It's probably easy to fix but I haven't tried,\n
  * sorry.\n
  */
-static int get_snipe_power(int *sn, bool only_browse)
+static int get_snipe_power(COMMAND_CODE *sn, bool only_browse)
 {
-       int             i;
+       COMMAND_CODE i;
        int             num = 0;
-       int             y = 1;
-       int             x = 20;
-       int             plev = p_ptr->lev;
+       TERM_LEN y = 1;
+       TERM_LEN x = 20;
+       PLAYER_LEVEL plev = p_ptr->lev;
        int             ask;
        char            choice;
        char            out_val[160];
-       cptr            p = _("射撃術", "power");
+       concptr            p = _("射撃術", "power");
        snipe_power     spell;
        bool            flag, redraw;
 
-#ifdef ALLOW_REPEAT /* TNB */
-
        repeat_push(*sn);
 
        /* Assume cancelled */
@@ -253,8 +242,6 @@ static int get_snipe_power(int *sn, bool only_browse)
                }
        }
 
-#endif /* ALLOW_REPEAT -- TNB */
-
        /* Nothing chosen yet */
        flag = FALSE;
 
@@ -284,7 +271,6 @@ static int get_snipe_power(int *sn, bool only_browse)
                                        p, I2A(0), I2A(num), p);
        }
 
-       /* Get a spell from the user */
        choice = always_show_list ? ESCAPE : 1;
        while (!flag)
        {
@@ -298,22 +284,13 @@ static int get_snipe_power(int *sn, bool only_browse)
                        if (!redraw)
                        {
                                char psi_desc[80];
-
-                               /* Show list */
                                redraw = TRUE;
-
-                               /* Save the screen */
                                if (!only_browse) screen_save();
 
                                /* Display a list of spells */
                                prt("", y, x);
-#ifdef JP
-                               put_str("名前", y, x + 5);
-                               if (only_browse) put_str("Lv   集中度", y, x + 35);
-#else
-                               put_str("Name", y, x + 5);
-                               if (only_browse) put_str("Lv Pow", y, x + 35);
-#endif
+                               put_str(_("名前", "Name"), y, x + 5);
+                               if (only_browse) put_str(_("Lv   集中度", "Lv Pow"), y, x + 35);
 
                                /* Dump the spells */
                                for (i = 0; i < MAX_SNIPE_POWERS; i++)
@@ -343,8 +320,6 @@ static int get_snipe_power(int *sn, bool only_browse)
                        {
                                /* Hide list */
                                redraw = FALSE;
-
-                               /* Restore the screen */
                                if (!only_browse) screen_load();
                        }
 
@@ -356,7 +331,7 @@ static int get_snipe_power(int *sn, bool only_browse)
                ask = isupper(choice);
 
                /* Lowercase */
-               if (ask) choice = tolower(choice);
+               if (ask) choice = (char)tolower(choice);
 
                /* Extract request */
                i = (islower(choice) ? A2I(choice) : -1);
@@ -387,15 +362,10 @@ static int get_snipe_power(int *sn, bool only_browse)
                /* Stop the loop */
                flag = TRUE;
        }
-
-       /* Restore the screen */
        if (redraw && !only_browse) screen_load();
 
-       /* Show choices */
        p_ptr->window |= (PW_SPELL);
-
-       /* Window stuff */
-       window_stuff();
+       handle_stuff();
 
        /* Abort if needed */
        if (!flag) return (FALSE);
@@ -403,12 +373,8 @@ static int get_snipe_power(int *sn, bool only_browse)
        /* Save the choice */
        (*sn) = i;
 
-#ifdef ALLOW_REPEAT /* TNB */
-
        repeat_push(*sn);
 
-#endif /* ALLOW_REPEAT -- TNB */
-
        /* Success */
        return (TRUE);
 }
@@ -420,7 +386,7 @@ static int get_snipe_power(int *sn, bool only_browse)
  * @param m_ptr 目標となるモンスターの構造体参照ポインタ
  * @return スレイの倍率(/10倍)
  */
-int tot_dam_aux_snipe(int mult, monster_type *m_ptr)
+MULTIPLY tot_dam_aux_snipe(MULTIPLY mult, monster_type *m_ptr, SPELL_IDX snipe_type)
 {
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
        bool seen = is_seen(m_ptr);
@@ -430,7 +396,7 @@ int tot_dam_aux_snipe(int mult, monster_type *m_ptr)
        case SP_LITE:
                if (r_ptr->flags3 & (RF3_HURT_LITE))
                {
-                       int n = 20 + p_ptr->concent;
+                       MULTIPLY n = 20 + p_ptr->concent;
                        if (seen) r_ptr->r_flags3 |= (RF3_HURT_LITE);
                        if (mult < n) mult = n;
                }
@@ -442,7 +408,7 @@ int tot_dam_aux_snipe(int mult, monster_type *m_ptr)
                }
                else
                {
-                       int n = 15 + (p_ptr->concent * 3);
+                       MULTIPLY n = 15 + (p_ptr->concent * 3);
                        if (mult < n) mult = n;
                }
                break;
@@ -453,7 +419,7 @@ int tot_dam_aux_snipe(int mult, monster_type *m_ptr)
                }
                else
                {
-                       int n = 15 + (p_ptr->concent * 3);
+                       MULTIPLY n = 15 + (p_ptr->concent * 3);
                        if (mult < n) mult = n;
                }
                break;
@@ -464,20 +430,20 @@ int tot_dam_aux_snipe(int mult, monster_type *m_ptr)
                }
                else
                {
-                       int n = 18 + (p_ptr->concent * 4);
+                       MULTIPLY n = 18 + (p_ptr->concent * 4);
                        if (mult < n) mult = n;
                }
                break;
        case SP_KILL_WALL:
                if (r_ptr->flags3 & RF3_HURT_ROCK)
                {
-                       int n = 15 + (p_ptr->concent * 2);
+                       MULTIPLY n = 15 + (p_ptr->concent * 2);
                        if (seen) r_ptr->r_flags3 |= RF3_HURT_ROCK;
                        if (mult < n) mult = n;
                }
                else if (r_ptr->flags3 & RF3_NONLIVING)
                {
-                       int n = 15 + (p_ptr->concent * 2);
+                       MULTIPLY n = 15 + (p_ptr->concent * 2);
                        if (seen) r_ptr->r_flags3 |= RF3_NONLIVING;
                        if (mult < n) mult = n;
                }
@@ -485,7 +451,7 @@ int tot_dam_aux_snipe(int mult, monster_type *m_ptr)
        case SP_EVILNESS:
                if (r_ptr->flags3 & RF3_GOOD)
                {
-                       int n = 15 + (p_ptr->concent * 4);
+                       MULTIPLY n = 15 + (p_ptr->concent * 4);
                        if (seen) r_ptr->r_flags3 |= RF3_GOOD;
                        if (mult < n) mult = n;
                }
@@ -493,7 +459,7 @@ int tot_dam_aux_snipe(int mult, monster_type *m_ptr)
        case SP_HOLYNESS:
                if (r_ptr->flags3 & RF3_EVIL)
                {
-                       int n = 12 + (p_ptr->concent * 3);
+                       MULTIPLY n = 12 + (p_ptr->concent * 3);
                        if (seen) r_ptr->r_flags3 |= RF3_EVIL;
                        if (r_ptr->flags3 & (RF3_HURT_LITE))
                        {
@@ -520,7 +486,8 @@ int tot_dam_aux_snipe(int mult, monster_type *m_ptr)
  */
 static bool cast_sniper_spell(int spell)
 {
-       object_type *o_ptr = &inventory[INVEN_BOW];
+       object_type *o_ptr = &p_ptr->inventory_list[INVEN_BOW];
+       SPELL_IDX snipe_type = SP_NONE;
 
        if (o_ptr->tval != TV_BOW)
        {
@@ -533,7 +500,7 @@ static bool cast_sniper_spell(int spell)
        {
        case 0: /* Concentration */
                if (!snipe_concentrate()) return (FALSE);
-               p_ptr->energy_use = 100;
+               take_turn(p_ptr, 100);
                return (TRUE);
        case 1: snipe_type = SP_LITE; break;
        case 2: snipe_type = SP_AWAY; break;
@@ -555,10 +522,9 @@ static bool cast_sniper_spell(int spell)
        }
 
        command_cmd = 'f';
-       do_cmd_fire();
-       snipe_type = 0;
+       do_cmd_fire(snipe_type);
 
-       return (is_fired);
+       return (p_ptr->is_fired);
 }
 
 /*!
@@ -567,48 +533,20 @@ static bool cast_sniper_spell(int spell)
  */
 void do_cmd_snipe(void)
 {
-       int             n = 0;
-       bool            cast;
-
-
-       /* not if confused */
-       if (p_ptr->confused)
-       {
-               msg_print(_("混乱していて集中できない!", "You are too confused!"));
-               return;
-       }
+       COMMAND_CODE n = 0;
+       bool cast;
 
-       /* not if hullucinated */
-       if (p_ptr->image)
-       {
-               msg_print(_("幻覚が見えて集中できない!", "You are too hallucinated!"));
-               return;
-       }
-
-       /* not if stuned */
-       if (p_ptr->stun)
-       {
-               msg_print(_("頭が朦朧としていて集中できない!", "You are too stuned!"));
-               return;
-       }
+       if(cmd_limit_confused(p_ptr)) return;
+       if(cmd_limit_image(p_ptr)) return;
+       if(cmd_limit_stun(p_ptr)) return;
 
-       /* get power */
        if (!get_snipe_power(&n, FALSE)) return;
 
        sound(SOUND_SHOOT);
-
-       /* Cast the spell */
        cast = cast_sniper_spell(n);
 
        if (!cast) return;
-#if 0
-       /* Take a turn */
-       p_ptr->energy_use = 100;
-#endif
-       /* Redraw mana */
        p_ptr->redraw |= (PR_HP | PR_MANA);
-
-       /* Window stuff */
        p_ptr->window |= (PW_PLAYER);
        p_ptr->window |= (PW_SPELL);
 }
@@ -619,7 +557,7 @@ void do_cmd_snipe(void)
  */
 void do_cmd_snipe_browse(void)
 {
-       int n = 0;
+       COMMAND_CODE n = 0;
        int j, line;
        char temp[62 * 4];
 
@@ -627,7 +565,6 @@ void do_cmd_snipe_browse(void)
 
        while(1)
        {
-               /* get power */
                if (!get_snipe_power(&n, TRUE))
                {
                        screen_load();