OSDN Git Service

Rewrite activation code
authorhabu <habu@0568b783-4c39-0410-ac80-bf13821ea2a2>
Mon, 4 Feb 2013 10:21:02 +0000 (10:21 +0000)
committerhabu <habu@0568b783-4c39-0410-ac80-bf13821ea2a2>
Mon, 4 Feb 2013 10:21:02 +0000 (10:21 +0000)
Now only random artifacts use xtra2 of object_type as activation
index. Others use act_idx member of a_info, e_info, k_info.

src/artifact.c
src/cmd6.c
src/externs.h
src/object1.c
src/object2.c
src/wizard1.c

index 928d287..1c1fd5a 100644 (file)
@@ -1924,6 +1924,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 +1978,31 @@ 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)
+{
+       if (object_is_fixed_artifact(o_ptr))
+       {
+               return a_info[o_ptr->name1].act_idx;
+       }
+       if (object_is_ego(o_ptr))
+       {
+               return e_info[o_ptr->name2].act_idx;
+       }
+       if (!object_is_random_artifact(o_ptr))
+       {
+               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 +2054,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:
                {
@@ -3866,23 +3892,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 +3908,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 +3922,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 +4069,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);
index 7756ae1..a06cd43 100644 (file)
@@ -4009,16 +4009,11 @@ static void do_cmd_activate_aux(int item)
 
        /* Hack -- use artifact level instead */
        if (object_is_fixed_artifact(o_ptr)) lev = a_info[o_ptr->name1].level;
-       else if (o_ptr->art_name)
+       else if (object_is_random_artifact(o_ptr))
        {
-               int i;
-               for (i = 0; activation_info[i].flag != NULL; i++)
-               {
-                       if (activation_info[i].index == o_ptr->xtra2)
-                       {
-                               lev = activation_info[i].level;
-                               break;
-                       }
+               const activation_type* const act_ptr = find_activation_info(o_ptr);
+               if (act_ptr) {
+                       lev = act_ptr->level;
                }
        }
        else if (((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) && o_ptr->name2) lev = e_info[o_ptr->name2].level;
@@ -4144,23 +4139,8 @@ static void do_cmd_activate_aux(int item)
                }
        }
 
-       /* Paranoia - Set activation index for older save data */
-       if (object_is_fixed_artifact(o_ptr))
-       {
-               if (!o_ptr->xtra2) o_ptr->xtra2 = a_info[o_ptr->name1].act_idx;
-       }
-       else if (object_is_ego(o_ptr))
-       {
-               if (!o_ptr->xtra2) o_ptr->xtra2 = e_info[o_ptr->name2].act_idx;
-       }
-       else
-       {
-               if (!o_ptr->xtra2) o_ptr->xtra2 = k_info[o_ptr->k_idx].act_idx;
-       }
-
        /* Activate object */
-       /* if (o_ptr->xtra2 && (object_is_artifact(o_ptr) || object_is_ego(o_ptr))) */
-       if (o_ptr->xtra2)
+       if (activation_index(o_ptr))
        {
                (void)activate_random_artifact(o_ptr);
 
index 2840615..f8b922e 100644 (file)
@@ -1522,8 +1522,9 @@ extern void one_low_esp(object_type *o_ptr);
 extern void one_resistance(object_type *o_ptr);
 extern void one_ability(object_type *o_ptr);
 extern bool create_artifact(object_type *o_ptr, bool a_scroll);
+extern int activation_index(object_type *o_ptr);
 extern bool activate_random_artifact(object_type * o_ptr);
-extern const activation_type* find_activation_info(const object_type *o_ptr);
+extern const activation_type* find_activation_info(object_type *o_ptr);
 extern void get_bloody_moon_flags(object_type *o_ptr);
 extern void random_artifact_resistance(object_type * o_ptr, artifact_type *a_ptr);
 extern bool create_named_art(int a_idx, int y, int x);
index 181f3df..1964eba 100644 (file)
@@ -360,14 +360,14 @@ static cptr item_activation_aux(object_type *o_ptr)
        cptr desc;
        char timeout[32];
        int constant, dice;
-       const activation_type* act_ptr = find_activation_info(o_ptr);
+       const activation_type* const act_ptr = find_activation_info(o_ptr);
 
        if (!act_ptr) return _("̤ÄêµÁ", "something undefined");
 
        desc = act_ptr->desc;
 
        /* Overwrite description if it is special */
-       switch (o_ptr->xtra2) {
+       switch (act_ptr->index) {
        case ACT_BR_FIRE:
                if ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_FLAMES))
                        desc = _("²Ð±ê¤Î¥Ö¥ì¥¹ (200) ¤È²Ð¤Ø¤ÎÂÑÀ­", "breath of fire (200) and resist fire");
@@ -409,7 +409,7 @@ static cptr item_activation_aux(object_type *o_ptr)
                strcpy(timeout, _("¤¤¤Ä¤Ç¤â", "every turn"));
        } else if (constant < 0) {
                /* Activations that have special timeout */
-               switch (o_ptr->xtra2) {
+               switch (act_ptr->index) {
                case ACT_BR_FIRE:
                        sprintf(timeout, _("%d ¥¿¡¼¥óËè", "every %d turns"),
                                ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_FLAMES)) ? 200 : 250);
@@ -508,23 +508,8 @@ cptr item_activation(object_type *o_ptr)
                }
        }
 
-       /* Paranoia - Set activation index for older save data */
-       if (object_is_fixed_artifact(o_ptr))
-       {
-               if (!o_ptr->xtra2) o_ptr->xtra2 = a_info[o_ptr->name1].act_idx;
-       }
-       else if (object_is_ego(o_ptr))
-       {
-               if (!o_ptr->xtra2) o_ptr->xtra2 = e_info[o_ptr->name2].act_idx;
-       }
-       else
-       {
-               if (!o_ptr->xtra2) o_ptr->xtra2 = k_info[o_ptr->k_idx].act_idx;
-       }
-
        /* Get an explain of an activation */
-       /* if ((object_is_artifact(o_ptr) || object_is_ego(o_ptr)) && (o_ptr->xtra2)) */
-       if (o_ptr->xtra2)
+       if (activation_index(o_ptr))
        {
                return item_activation_aux(o_ptr);
        }
index 424dd1a..6c1e60d 100644 (file)
@@ -1036,14 +1036,9 @@ s32b flag_cost(object_type *o_ptr, int plusses)
        /* Also, give some extra for activatable powers... */
        if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
        {
-               int i;
-               for (i = 0; activation_info[i].flag != NULL; i++)
-               {
-                       if (activation_info[i].index == o_ptr->xtra2)
-                       {
-                               total += activation_info[i].value;
-                               break;
-                       }
+               const activation_type* const act_ptr = find_activation_info(o_ptr);
+               if (act_ptr) {
+                       total += act_ptr->value;
                }
        }
 
index e154bc2..7b79cbc 100644 (file)
@@ -1625,7 +1625,6 @@ static bool make_fake_artifact(object_type *o_ptr, int name1)
        o_ptr->to_h = a_ptr->to_h;
        o_ptr->to_d = a_ptr->to_d;
        o_ptr->weight = a_ptr->weight;
-       o_ptr->xtra2 = a_ptr->act_idx;
 
        /* Success */
        return (TRUE);