OSDN Git Service

Suppress gcc warning
[hengband/hengband.git] / src / artifact.c
index 3595542..ad5a8bd 100644 (file)
@@ -184,6 +184,122 @@ void one_ability(object_type *o_ptr)
        }
 }
 
+/*
+ * Choose one random activation
+ */
+void one_activation(object_type *o_ptr)
+{
+       int type = 0;
+       int chance = 0;
+
+       while (randint1(100) >= chance)
+       {
+               type = randint1(255);
+               switch (type)
+               {
+                       case ACT_SUNLIGHT:
+                       case ACT_BO_MISS_1:
+                       case ACT_BA_POIS_1:
+                       case ACT_BO_ELEC_1:
+                       case ACT_BO_ACID_1:
+                       case ACT_BO_COLD_1:
+                       case ACT_BO_FIRE_1:
+                       case ACT_CONFUSE:
+                       case ACT_SLEEP:
+                       case ACT_QUAKE:
+                       case ACT_CURE_LW:
+                       case ACT_CURE_MW:
+                       case ACT_CURE_POISON:
+                       case ACT_BERSERK:
+                       case ACT_LIGHT:
+                       case ACT_MAP_LIGHT:
+                       case ACT_DEST_DOOR:
+                       case ACT_STONE_MUD:
+                       case ACT_TELEPORT:
+                               chance = 101;
+                               break;
+                       case ACT_BA_COLD_1:
+                       case ACT_BA_FIRE_1:
+                       case ACT_DRAIN_1:
+                       case ACT_TELE_AWAY:
+                       case ACT_ESP:
+                       case ACT_RESIST_ALL:
+                       case ACT_DETECT_ALL:
+                       case ACT_RECALL:
+                       case ACT_SATIATE:
+                       case ACT_RECHARGE:
+                               chance = 85;
+                               break;
+                       case ACT_TERROR:
+                       case ACT_PROT_EVIL:
+                       case ACT_ID_PLAIN:
+                               chance = 75;
+                               break;
+                       case ACT_DRAIN_2:
+                       case ACT_VAMPIRE_1:
+                       case ACT_BO_MISS_2:
+                       case ACT_BA_FIRE_2:
+                       case ACT_REST_LIFE:
+                               chance = 66;
+                               break;
+                       case ACT_BA_FIRE_3:
+                       case ACT_BA_COLD_3:
+                       case ACT_BA_ELEC_3:
+                       case ACT_WHIRLWIND:
+                       case ACT_VAMPIRE_2:
+                       case ACT_CHARM_ANIMAL:
+                               chance = 50;
+                               break;
+                       case ACT_SUMMON_ANIMAL:
+                               chance = 40;
+                               break;
+                       case ACT_DISP_EVIL:
+                       case ACT_BA_MISS_3:
+                       case ACT_DISP_GOOD:
+                       case ACT_BANISH_EVIL:
+                       case ACT_GENOCIDE:
+                       case ACT_MASS_GENO:
+                       case ACT_CHARM_UNDEAD:
+                       case ACT_CHARM_OTHER:
+                       case ACT_SUMMON_PHANTOM:
+                       case ACT_REST_ALL:
+                       case ACT_RUNE_EXPLO:
+                               chance = 33;
+                               break;
+                       case ACT_CALL_CHAOS:
+                       case ACT_ROCKET:
+                       case ACT_CHARM_ANIMALS:
+                       case ACT_CHARM_OTHERS:
+                       case ACT_SUMMON_ELEMENTAL:
+                       case ACT_CURE_700:
+                       case ACT_SPEED:
+                       case ACT_ID_FULL:
+                       case ACT_RUNE_PROT:
+                               chance = 25;
+                               break;
+                       case ACT_CURE_1000:
+                       case ACT_XTRA_SPEED:
+                       case ACT_DETECT_XTRA:
+                       case ACT_DIM_DOOR:
+                               chance = 10;
+                               break;
+                       case ACT_SUMMON_UNDEAD:
+                       case ACT_SUMMON_DEMON:
+                       case ACT_WRAITH:
+                       case ACT_INVULN:
+                       case ACT_ALCHEMY:
+                               chance = 5;
+                               break;
+                       default:
+                               chance = 0;
+               }
+       }
+
+       /* A type was chosen... */
+       o_ptr->xtra2 = type;
+       add_flag(o_ptr->art_flags, TR_ACTIVATE);
+       o_ptr->timeout = 0;
+}
 
 static void curse_artifact(object_type * o_ptr)
 {
@@ -1435,107 +1551,10 @@ static void give_activation_power(object_type *o_ptr)
                        break;
        }
 
-       while (!type || (randint1(100) >= chance))
+       if (!type || (randint1(100) >= chance))
        {
-               type = randint1(255);
-               switch (type)
-               {
-                       case ACT_SUNLIGHT:
-                       case ACT_BO_MISS_1:
-                       case ACT_BA_POIS_1:
-                       case ACT_BO_ELEC_1:
-                       case ACT_BO_ACID_1:
-                       case ACT_BO_COLD_1:
-                       case ACT_BO_FIRE_1:
-                       case ACT_CONFUSE:
-                       case ACT_SLEEP:
-                       case ACT_QUAKE:
-                       case ACT_CURE_LW:
-                       case ACT_CURE_MW:
-                       case ACT_CURE_POISON:
-                       case ACT_BERSERK:
-                       case ACT_LIGHT:
-                       case ACT_MAP_LIGHT:
-                       case ACT_DEST_DOOR:
-                       case ACT_STONE_MUD:
-                       case ACT_TELEPORT:
-                               chance = 101;
-                               break;
-                       case ACT_BA_COLD_1:
-                       case ACT_BA_FIRE_1:
-                       case ACT_DRAIN_1:
-                       case ACT_TELE_AWAY:
-                       case ACT_ESP:
-                       case ACT_RESIST_ALL:
-                       case ACT_DETECT_ALL:
-                       case ACT_RECALL:
-                       case ACT_SATIATE:
-                       case ACT_RECHARGE:
-                               chance = 85;
-                               break;
-                       case ACT_TERROR:
-                       case ACT_PROT_EVIL:
-                       case ACT_ID_PLAIN:
-                               chance = 75;
-                               break;
-                       case ACT_DRAIN_2:
-                       case ACT_VAMPIRE_1:
-                       case ACT_BO_MISS_2:
-                       case ACT_BA_FIRE_2:
-                       case ACT_REST_LIFE:
-                               chance = 66;
-                               break;
-                       case ACT_BA_FIRE_3:
-                       case ACT_BA_COLD_3:
-                       case ACT_BA_ELEC_3:
-                       case ACT_WHIRLWIND:
-                       case ACT_VAMPIRE_2:
-                       case ACT_CHARM_ANIMAL:
-                               chance = 50;
-                               break;
-                       case ACT_SUMMON_ANIMAL:
-                               chance = 40;
-                               break;
-                       case ACT_DISP_EVIL:
-                       case ACT_BA_MISS_3:
-                       case ACT_DISP_GOOD:
-                       case ACT_BANISH_EVIL:
-                       case ACT_GENOCIDE:
-                       case ACT_MASS_GENO:
-                       case ACT_CHARM_UNDEAD:
-                       case ACT_CHARM_OTHER:
-                       case ACT_SUMMON_PHANTOM:
-                       case ACT_REST_ALL:
-                       case ACT_RUNE_EXPLO:
-                               chance = 33;
-                               break;
-                       case ACT_CALL_CHAOS:
-                       case ACT_ROCKET:
-                       case ACT_CHARM_ANIMALS:
-                       case ACT_CHARM_OTHERS:
-                       case ACT_SUMMON_ELEMENTAL:
-                       case ACT_CURE_700:
-                       case ACT_SPEED:
-                       case ACT_ID_FULL:
-                       case ACT_RUNE_PROT:
-                               chance = 25;
-                               break;
-                       case ACT_CURE_1000:
-                       case ACT_XTRA_SPEED:
-                       case ACT_DETECT_XTRA:
-                       case ACT_DIM_DOOR:
-                               chance = 10;
-                               break;
-                       case ACT_SUMMON_UNDEAD:
-                       case ACT_SUMMON_DEMON:
-                       case ACT_WRAITH:
-                       case ACT_INVULN:
-                       case ACT_ALCHEMY:
-                               chance = 5;
-                               break;
-                       default:
-                               chance = 0;
-               }
+               one_activation(o_ptr);
+               return;
        }
 
        /* A type was chosen... */
@@ -1924,6 +1943,9 @@ bool create_artifact(object_type *o_ptr, bool a_scroll)
                /* Mark the item as fully known */
                o_ptr->ident |= (IDENT_MENTAL);
 
+               /* For being treated as random artifact in screen_object() */
+               o_ptr->art_name = quark_add("");
+
                (void)screen_object(o_ptr, 0L);
 
                if (!get_string(ask_msg, dummy_name, sizeof dummy_name)
@@ -1975,12 +1997,53 @@ bool create_artifact(object_type *o_ptr, bool a_scroll)
 }
 
 
-const activation_type* find_activation_info(const object_type *o_ptr)
+int activation_index(object_type *o_ptr)
+{
+       /* Give priority to weaponsmith's essential activations */
+       if (object_is_smith(o_ptr))
+       {
+               switch (o_ptr->xtra3-1)
+               {
+               case ESSENCE_TMP_RES_ACID: return ACT_RESIST_ACID;
+               case ESSENCE_TMP_RES_ELEC: return ACT_RESIST_ELEC;
+               case ESSENCE_TMP_RES_FIRE: return ACT_RESIST_FIRE;
+               case ESSENCE_TMP_RES_COLD: return ACT_RESIST_COLD;
+               case TR_IMPACT: return ACT_QUAKE;
+               }
+       }
+
+       if (object_is_fixed_artifact(o_ptr))
+       {
+               if (have_flag(a_info[o_ptr->name1].flags, TR_ACTIVATE))
+               {
+                       return a_info[o_ptr->name1].act_idx;
+               }
+       }
+       if (object_is_ego(o_ptr))
+       {
+               if (have_flag(e_info[o_ptr->name2].flags, TR_ACTIVATE))
+               {
+                       return e_info[o_ptr->name2].act_idx;
+               }
+       }
+       if (!object_is_random_artifact(o_ptr))
+       {
+               if (have_flag(k_info[o_ptr->k_idx].flags, TR_ACTIVATE))
+               {
+                       return k_info[o_ptr->k_idx].act_idx;
+               }
+       }
+
+       return o_ptr->xtra2;
+}
+
+const activation_type* find_activation_info(object_type *o_ptr)
 {
+       const int index = activation_index(o_ptr);
        const activation_type* p;
 
        for (p = activation_info; p->flag != NULL; ++ p) {
-               if (p->index == o_ptr->xtra2)
+               if (p->index == index)
                {
                        return p;
                }
@@ -2032,13 +2095,17 @@ bool activate_random_artifact(object_type *o_ptr)
        int plev = p_ptr->lev;
        int k, dir, dummy = 0;
        cptr name = k_name + k_info[o_ptr->k_idx].name;
-       const activation_type* act_ptr;
+       const activation_type* const act_ptr = find_activation_info(o_ptr);
 
        /* Paranoia */
-       if (!o_ptr->xtra2) return FALSE;
+       if (!act_ptr) {
+               /* Maybe forgot adding information to activation_info table ? */
+               msg_print("Activation information is not found.");
+               return FALSE;
+       }
 
        /* Activate for attack */
-       switch (o_ptr->xtra2)
+       switch (act_ptr->index)
        {
                case ACT_SUNLIGHT:
                {
@@ -2048,7 +2115,7 @@ bool activate_random_artifact(object_type *o_ptr)
 #else
                        msg_print("A line of sunlight appears.");
 #endif
-                       (void)lite_line(dir);
+                       (void)lite_line(dir, damroll(6, 8));
                        break;
                }
 
@@ -3319,7 +3386,7 @@ bool activate_random_artifact(object_type *o_ptr)
                        msg_print("It pulsates...");
 #endif
                        if (!get_aim_dir(&dir)) return FALSE;
-                       wall_to_mud(dir);
+                       wall_to_mud(dir, 20 + randint1(30));
                        break;
                }
 
@@ -3651,7 +3718,7 @@ bool activate_random_artifact(object_type *o_ptr)
                        o_ptr = &o_list[o_idx];
 
                        object_desc(o_name, o_ptr, OD_NAME_ONLY);
-                       msg_format(_("%s¤ò椮¼Î¤Æ¤¿¡£", "You cast off %d."), o_name);
+                       msg_format(_("%s¤ò椮¼Î¤Æ¤¿¡£", "You cast off %s."), o_name);
 
                        /* Get effects */
                        msg_print(_("¡Ödz¤¨¾å¤¬¤ì²¶¤Î¾®±§Ã衪¡×", "You say, 'Burn up my cosmo!"));
@@ -3866,23 +3933,15 @@ bool activate_random_artifact(object_type *o_ptr)
                default:
                {
 #ifdef JP
-                       msg_format("Unknown activation effect: %d.", o_ptr->xtra2);
+                       msg_format("Unknown activation effect: %d.", act_ptr->index);
 #else
-                       msg_format("Unknown activation effect: %d.", o_ptr->xtra2);
+                       msg_format("Unknown activation effect: %d.", act_ptr->index);
 #endif
                        return FALSE;
                }
        }
 
        /* Set activation timeout */
-       act_ptr = find_activation_info(o_ptr);
-
-       if (!act_ptr) {
-               /* Maybe forgot adding information to activation_info table ? */
-               msg_format("Activation information is not found: %d.", o_ptr->xtra2);
-               return FALSE;
-       }
-
        if (act_ptr->timeout.constant >= 0) {
                o_ptr->timeout = act_ptr->timeout.constant;
                if (act_ptr->timeout.dice > 0) {
@@ -3890,7 +3949,7 @@ bool activate_random_artifact(object_type *o_ptr)
                }
        } else {
                /* Activations that have special timeout */
-               switch (o_ptr->xtra2) {
+               switch (act_ptr->index) {
                case ACT_BR_FIRE:
                        o_ptr->timeout = ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_FLAMES)) ? 200 : 250;
                        break;
@@ -3904,7 +3963,7 @@ bool activate_random_artifact(object_type *o_ptr)
                        /* Nothing to do */
                        break;
                default:
-                       msg_format("Special timeout is not implemented: %d.", o_ptr->xtra2);
+                       msg_format("Special timeout is not implemented: %d.", act_ptr->index);
                        return FALSE;
                }
        }
@@ -4051,7 +4110,6 @@ bool create_named_art(int a_idx, int y, int x)
        q_ptr->to_h = a_ptr->to_h;
        q_ptr->to_d = a_ptr->to_d;
        q_ptr->weight = a_ptr->weight;
-       q_ptr->xtra2 = a_ptr->act_idx;
 
        /* Hack -- extract the "cursed" flag */
        if (a_ptr->gen_flags & TRG_CURSED) q_ptr->curse_flags |= (TRC_CURSED);