Changeset 1000

Show
Ignore:
Timestamp:
10/01/08 03:07:19 (3 months ago)
Author:
takkaria
Message:

(#498) Make it so that the object information screen prints the correct average damage always, by feeding the object examined through the normal calculation routines.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/object/obj-info.c

    r999 r1000  
    361361        if (weapon) 
    362362        { 
    363                 int blows = calc_blows(o_ptr); 
    364  
    365                 if (f1 & (TR1_BLOWS)) blows += o_ptr->pval; 
     363                /* 
     364                 * Get the player's hypothetical state, were they to be 
     365                 * wielding this item. 
     366                 */ 
     367                player_state state; 
     368                object_type inven[INVEN_TOTAL]; 
     369 
     370                memcpy(inven, inventory, INVEN_TOTAL * sizeof(object_type)); 
     371                inven[INVEN_WIELD] = *o_ptr; 
     372 
     373                calc_bonuses(inven, &state); 
     374 
    366375 
    367376                dam = ((o_ptr->ds + 1) * o_ptr->dd * 5); 
    368  
    369                 xtra_dam = (p_ptr->state.to_d * 10); 
    370                 if (object_known_p(o_ptr)) 
    371                         xtra_dam += (o_ptr->to_d * 10); 
     377                xtra_dam = state.dis_to_d * 10; 
    372378 
    373379                /* Warn about heavy weapons */ 
    374                 if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] < o_ptr->weight / 10) 
    375                 { 
     380                if (adj_str_hold[state.stat_ind[A_STR]] < o_ptr->weight / 10) 
    376381                        text_out_c(TERM_L_RED, "You are too weak to use this weapon effectively!\n"); 
    377                         blows = 1; 
    378                 } 
    379382 
    380383                text_out("With this weapon, you would currently get "); 
    381                 text_out_c(TERM_L_GREEN, format("%d ", blows)); 
    382                 if (blows > 1) 
     384                text_out_c(TERM_L_GREEN, format("%d ", state.num_blow)); 
     385                if (state.num_blow > 1) 
    383386                        text_out("blows per round.  Each blow will do an average damage of "); 
    384387                else 
  • trunk/src/player/calcs.c

    r999 r1000  
    510510 * Calculate the blows a player would get, in current condition, wielding "o_ptr". 
    511511 */ 
    512 int calc_blows(const object_type *o_ptr
     512static int calc_blows(const object_type *o_ptr, player_state *state
    513513{ 
    514514        int blows; 
    515         int str_index1, str_index2, dex_index1, dex_index2
     515        int str_index, dex_index
    516516        int div; 
    517  
    518         object_type *j_ptr = &inventory[INVEN_WIELD]; 
    519517 
    520518        /* Enforce a minimum "weight" (tenth pounds) */ 
    521519        div = ((o_ptr->weight < cp_ptr->min_weight) ? cp_ptr->min_weight : o_ptr->weight); 
    522520 
    523         /* If we're wielding this weapon, use the current stats */ 
    524         if (o_ptr == j_ptr) 
    525         { 
    526                 str_index1 = p_ptr->state.stat_ind[A_STR]; 
    527                 dex_index1 = p_ptr->state.stat_ind[A_DEX]; 
    528         } 
    529         else 
    530         { 
    531                 /* Recalculate bonuses as if we were wielding this weapon */ 
    532  
    533                 int str_change = 0, dex_change = 0; 
    534                 int new_str = p_ptr->state.stat_use[A_STR]; 
    535                 int new_dex = p_ptr->state.stat_use[A_DEX]; 
    536  
    537                 /* object_type *j_ptr = &inventory[INVEN_WIELD]; */ 
    538  
    539                 u32b jf1, jf2, jf3; 
    540                 u32b of1, of2, of3; 
    541  
    542                 /* Examine the wielded weapon */ 
    543                 object_flags(j_ptr, &jf1, &jf2, &jf3); 
    544                 if (jf1 & (TR1_STR)) str_change -= j_ptr->pval; 
    545                 if (jf1 & (TR1_DEX)) dex_change -= j_ptr->pval; 
    546  
    547                 /* Examine the weapon in the pack*/ 
    548                 object_flags(o_ptr, &of1, &of2, &of3); 
    549                 if (of1 & (TR1_STR)) str_change += o_ptr->pval; 
    550                 if (of1 & (TR1_DEX)) dex_change += o_ptr->pval; 
    551  
    552                 new_str = modify_stat_value(new_str, str_change); 
    553                 new_dex = modify_stat_value(new_dex, dex_change); 
    554  
    555                 if (new_str <= 18) 
    556                         str_index1 = new_str - 3; 
    557                 else if (new_str <= 18+219) 
    558                         str_index1 = (15 + (new_str - 18) / 10); 
    559                 else 
    560                         str_index1 = 37; 
    561  
    562                 if (new_dex <= 18) 
    563                         dex_index1 = new_dex - 3; 
    564                 else if (new_dex <= 18+219) 
    565                         dex_index1 = (15 + (new_dex - 18) / 10); 
    566                 else 
    567                         dex_index1 = 37; 
    568         } 
    569  
    570  
    571521        /* Get the strength vs weight */ 
    572         str_index2 = (adj_str_blow[str_index1] * cp_ptr->att_multiply / div); 
     522        str_index = adj_str_blow[p_ptr->state.stat_ind[A_STR]] * 
     523                        cp_ptr->att_multiply / div; 
    573524 
    574525        /* Maximal value */ 
    575         if (str_index2 > 11) str_index2 = 11; 
     526        if (str_index > 11) str_index = 11; 
    576527 
    577528        /* Index by dexterity */ 
    578         dex_index2 = MIN(adj_dex_blow[dex_index1], 11); 
     529        dex_index = MIN(adj_dex_blow[p_ptr->state.stat_ind[A_DEX]], 11); 
    579530 
    580531        /* Use the blows table */ 
    581         blows = MIN(blows_table[str_index2][dex_index2], cp_ptr->max_attacks); 
     532        blows = MIN(blows_table[str_index][dex_index], cp_ptr->max_attacks); 
    582533 
    583534        /* Require at least one blow */ 
     
    589540 * Computes current weight limit. 
    590541 */ 
    591 static int weight_limit(void
     542static int weight_limit(player_state *state
    592543{ 
    593544        int i; 
    594545 
    595546        /* Weight limit based only on strength */ 
    596         i = adj_str_wgt[p_ptr->state.stat_ind[A_STR]] * 100; 
     547        i = adj_str_wgt[state->stat_ind[A_STR]] * 100; 
    597548 
    598549        /* Return the result */ 
     
    619570 * are actually added in later, at the appropriate place. 
    620571 */ 
    621 static void calc_bonuses(object_type inventory[], player_state *state) 
     572void calc_bonuses(object_type inventory[], player_state *state) 
    622573{ 
    623574        int i, j, hold; 
     
    956907 
    957908        /* Extract the "weight limit" (in tenth pounds) */ 
    958         i = weight_limit(); 
     909        i = weight_limit(state); 
    959910 
    960911        /* Apply "encumbrance" from weight */ 
     
    11451096        { 
    11461097                /* Calculate number of blows */ 
    1147                 state->num_blow = calc_blows(o_ptr) + extra_blows; 
     1098                state->num_blow = calc_blows(o_ptr, state) + extra_blows; 
    11481099 
    11491100                /* Boost digging skill by weapon weight */ 
  • trunk/src/player/player.h

    r996 r1000  
    11/* calcs.c */ 
    2 int calc_blows(const object_type *o_ptr); 
     2void calc_bonuses(object_type inventory[], player_state *state); 
    33void notice_stuff(void); 
    44void update_stuff(void);