# File: object_power.txt


# === Understanding object_power.txt ===

# name: calculation name
# type: type (tval) of item the calculation applies to; if none, then all types
# item: individual item the calculation applies to
# dice: value of the calculation. Damage dice are used and evaluated; if dice
#       and sides are present, they are treated as maximised
# expr: expression for the value (dice) calculation
# operation: how the calculated value is applied to power, or to a previous
#            calculated value
# iterate: if this is present, the calculation is done once for each value of
#          the indicated type (modifier, flag, etc)
# apply-to: if present, which previous value to apply the current value to; if
#           this is not present, the current value is applied to the total
#           object power

# For calculating the power of any individual object, there are two passes
# through these calculations.
#
# On the first pass, all individual calculations are made and stored, and any
# calculations with an apply-to field get applied to that field (which must
# be the name of an *earlier* calculation).
#
# On the second pass all the calculations with no apply-to field are combined
# according to their operation field to form an overall power.


# to-dam gets a 5/2 multiplier
name:to damage power
dice:$P
expr:P:OBJ_POWER_TO_DAM:* 5 / 2
operation:add

# PWMAngband: to-dam over 40 not allowed
name:to damage inhibitor
dice:$P
expr:P:OBJ_POWER_TO_DAM:- 40 * 20000
operation:add if positive

# non-weapon to dam gets an additional 5 multiplier
name:nonweapon to damage power
type:horn
type:digger
type:boots
type:gloves
type:helm
type:crown
type:shield
type:cloak
type:soft armour
type:hard armour
type:dragon armour
type:light
type:amulet
type:ring
dice:$P
expr:P:OBJ_POWER_TO_DAM:* 5
operation:add

# dice power is a bit of a hack - the base is dice x (sides + 1), or 48 for
# assumed damage for non-weapons with slays or brands or + blows, might or shots
name:dice power
dice:$P
expr:P:OBJ_POWER_DICE:* 5 / 4
operation:add

# assumed ammo damage power for slings
name:ammo damage power - slings
item:bow:Sling
dice:25
operation:add

# assumed ammo damage power for bows
name:ammo damage power - bows
item:bow:Short Bow
item:bow:Long Bow
dice:30
operation:add

# assumed ammo damage power for crossbows
name:ammo damage power - crossbows
item:bow:Light Crossbow
item:bow:Heavy Crossbow
dice:35
operation:add

# bonus for ego ammo
name:ego ammo bonus
type:shot
type:arrow
type:bolt
dice:$P
expr:P:OBJ_POWER_IS_EGO:* 45 / 2
operation:add

# throwing power multiplier for rocks
name:throwing multiplier
type:rock
dice:2
operation:multiply

# launcher power multiplier for shots
name:sling multiplier
type:shot
dice:4
operation:multiply

# launcher power multiplier for arrows
name:bow multiplier
type:arrow
dice:5
operation:multiply

# launcher power multiplier for bolts
name:crossbow multiplier
type:bolt
dice:7
operation:multiply

# rescale ammo to reflect only one hit per round
name:ammo rescale divisor
type:rock
type:shot
type:arrow
type:bolt
dice:10
operation:divide

# more than 2 extra blows not allowed
name:extra blows inhibitor
dice:$P
expr:P:OBJ_POWER_EXTRA_BLOWS:- 2 * 20000
operation:add if positive

# 5 is assumed max blows
name:extra blows multiplier
dice:$P
expr:P:OBJ_POWER_EXTRA_BLOWS:+ 5
operation:multiply

# now divide by max blows
name:extra blows divisor
dice:5
operation:divide

# assume nonweapon damage; 15 is a fudge, 5/2 is standard per damage point 
name:extra blows bonus
dice:$P
expr:P:OBJ_POWER_EXTRA_BLOWS:* 15 * 5 / 2
operation:add

# PWMAngband: more than 2 extra shots not allowed (was 3)
name:extra shots inhibitor
dice:$P
expr:P:OBJ_POWER_EXTRA_SHOTS:- 2 * 20000
operation:add if positive

# extra shots is a straight 1 + number multiplier
name:extra shots multiplier
dice:$P
expr:P:OBJ_POWER_EXTRA_SHOTS:+ 1
operation:multiply

# more than 2 extra might not allowed
name:extra might inhibitor
dice:$P
expr:P:OBJ_POWER_EXTRA_MIGHT:- 2 * 20000
operation:add if positive

# extra might is a multiplier, made up of bonus + bow pval (or 1 if not a bow)
name:extra might multiplier
dice:$P+1d$Q
expr:P:OBJ_POWER_EXTRA_MIGHT:+ 0
expr:Q:OBJ_POWER_BOW_MULTIPLIER:+ 0
operation:multiply

# slay power is dice power multiplied by best slay
name:slay power
dice:$Pd$Q
expr:P:OBJ_POWER_DICE:* 5 / 4
expr:Q:OBJ_POWER_BEST_SLAY:- 100
operation:add

# slay power is 100 times the damage effect, so we need to divide
name:slay power divisor
dice:100
operation:divide
apply-to:slay power

# now a whole lot of bitty slay bonuses, which probably need rationalising

# SLAY_SLAY is number of slays squared
name:slay slay bonus
dice:$Pd$Q
expr:P:OBJ_POWER_DICE:* 5 / 4
expr:Q:OBJ_POWER_SLAY_SLAY:+ 0
operation:add

name:slay slay divisor
dice:25
operation:divide
apply-to:slay slay bonus

# BRAND_BRAND is number of brands squared
name:brand brand bonus
dice:$Pd$Q
expr:P:OBJ_POWER_DICE:* 5 / 4
expr:Q:OBJ_POWER_BRAND_BRAND:* 2
operation:add

name:brand brand divisor
dice:25
operation:divide
apply-to:brand brand bonus

# SLAY_BRAND is number of slays times number of brands
name:slay brand bonus
dice:$Pd$Q
expr:P:OBJ_POWER_DICE:* 5 / 4
expr:Q:OBJ_POWER_SLAY_BRAND:+ 0
operation:add

name:slay brand divisor
dice:25
operation:divide
apply-to:slay brand bonus

# KILL_KILL is number of *slay*s squared
name:kill kill bonus
dice:$Pd$Q
expr:P:OBJ_POWER_DICE:* 5 / 4
expr:Q:OBJ_POWER_KILL_KILL:* 3
operation:add

name:kill kill divisor
dice:25
operation:divide
apply-to:kill kill bonus

name:all slays bonus
dice:$P
expr:P:OBJ_POWER_ALL_SLAYS:* 10
operation:add

name:all brands bonus
dice:$P
expr:P:OBJ_POWER_ALL_BRANDS:* 20
operation:add

name:all kills bonus
dice:$P
expr:P:OBJ_POWER_ALL_KILLS:* 20
operation:add

# Rescale bow power to reflect lack of multiple blows
name:launcher rescale divisor
type:bow
dice:5
operation:divide

# 3/2 power per point to-hit
name:to hit power
dice:$P
expr:P:OBJ_POWER_TO_HIT:* 3 / 2
operation:add

# PWMAngband: to-hit over 40 not allowed
name:to hit inhibitor
dice:$P
expr:P:OBJ_POWER_TO_HIT:- 40 * 20000
operation:add if positive

# PWMAngband: armor and items with AC get a flat 1 power
name:base armor power
dice:$P
expr:P:OBJ_POWER_BASE_AC:+ 0
operation:add

# AC is multiplied by 15 / 2 and by total armor, and divided by weight + 1
name:armor power
dice:$Pd$Q
expr:P:OBJ_POWER_AC:* 750
expr:Q:OBJ_POWER_TOTAL_ARMOR:+ 0
operation:add

# weight is a minimum of 2 pounds to avoid issues with ultra-light armor
name:armor power divisor
dice:$P
expr:P:OBJ_POWER_WEIGHT:+ 10 * 100
operation:divide
apply-to:armor power

# to-armor is power, plus bonuses over 25 and 35
name:to armor power
dice:$P
expr:P:OBJ_POWER_TO_ARMOR:+ 0
operation:add

name:to armor bonus
dice:$P
expr:P:OBJ_POWER_TO_ARMOR:- 25 * 2
operation:add if positive

name:to armor extra bonus
dice:$P
expr:P:OBJ_POWER_TO_ARMOR:- 35 * 4
operation:add if positive

# to armor over 55 not allowed
name:to armor inhibitor
dice:$P
expr:P:OBJ_POWER_TO_ARMOR:- 55 * 20000
operation:add if positive

# jewelry gets a flat 4 power
name:jewelry power
type:amulet
type:ring
dice:4
operation:add

# PWMAngband: tools get a flat 5 power
name:tool power
type:horn
type:digger
dice:5
operation:add

# modifiers have a power and a type-dependent multiplier
name:total modifier power
dice:$P
expr:P:OBJ_POWER_MODIFIER:+ 0
operation:add
iterate:modifier

name:modifier power
dice:$P
expr:P:OBJ_POWER_MOD_POWER:+ 0
operation:multiply
iterate:modifier
apply-to:total modifier power

name:modifier type multiplier
dice:$P
expr:P:OBJ_POWER_MOD_TYPE_MULT:+ 0
operation:multiply
iterate:modifier
apply-to:total modifier power

# PWMAngband: new value to stay closer to original ability power (was -70)
name:total modifier bonus
dice:-39
operation:square and add if positive

name:modifier bonus
dice:$Pd$Q
expr:P:OBJ_POWER_MODIFIER:+ 0
expr:Q:OBJ_POWER_MOD_MULT:+ 0
operation:add
iterate:modifier
apply-to:total modifier bonus

# PWMAngband: new value to stay closer to original ability power (was 16)
name:modifier bonus divisor
dice:19
operation:divide
apply-to:total modifier bonus

name:total modifier inhibitor
dice:-249
operation:add if positive

name:modifier inhibitor
dice:$Pd$Q
expr:P:OBJ_POWER_MODIFIER:+ 0
expr:Q:OBJ_POWER_MOD_MULT:+ 0
operation:add
iterate:modifier
apply-to:total modifier inhibitor

name:modifier inhibitor multiplier
dice:20000
operation:multiply
apply-to:total modifier inhibitor

name:flag power
dice:$Pd$Q
expr:P:OBJ_POWER_FLAG_POWER:+ 0
expr:Q:OBJ_POWER_FLAG_TYPE_MULT:+ 0
operation:add
iterate:flag

name:multiple sustain bonus
dice:$Pd$Q
expr:P:OBJ_POWER_NUM_SUSTAINS:+ 0
expr:Q:OBJ_POWER_NUM_SUSTAINS:+ 0
operation:add

name:all sustain bonus
dice:$P
expr:P:OBJ_POWER_ALL_SUSTAINS:* 10
operation:add

name:multiple protect bonus
dice:$Pd$Q
expr:P:OBJ_POWER_NUM_PROTECTS:+ 0
expr:Q:OBJ_POWER_NUM_PROTECTS:* 3
operation:add

name:all protect bonus
dice:$P
expr:P:OBJ_POWER_ALL_PROTECTS:* 15
operation:add

name:multiple misc ability bonus
dice:$Pd$Q
expr:P:OBJ_POWER_NUM_MISC:+ 0
expr:Q:OBJ_POWER_NUM_MISC:+ 0
operation:add

name:all misc ability bonus
dice:$P
expr:P:OBJ_POWER_ALL_MISC:* 25
operation:add

name:multiple ESP flag ability bonus
dice:$Pd$Q
expr:P:OBJ_POWER_NUM_ESP:+ 0
expr:Q:OBJ_POWER_NUM_ESP:+ 0
operation:add

name:all ESP flag bonus
dice:$P
expr:P:OBJ_POWER_ALL_ESP:* 25
operation:add

name:ignore power
dice:$P
expr:P:OBJ_POWER_IGNORE:+ 0
iterate:ignore
operation:add

name:vulnerability power
dice:$P
expr:P:OBJ_POWER_VULN:+ 0
iterate:vulnerability
operation:add

name:resistance power
dice:$P
expr:P:OBJ_POWER_RESIST:+ 0
iterate:resistance
operation:add

name:immunity power
dice:$P
expr:P:OBJ_POWER_IMM:+ 0
iterate:immunity
operation:add

name:multiple base resists bonus
dice:$Pd$Q
expr:P:OBJ_POWER_NUM_BASE_RES:+ 0
expr:Q:OBJ_POWER_NUM_BASE_RES:+ 0
operation:add

name:all base resists bonus
dice:$P
expr:P:OBJ_POWER_ALL_BASE_RES:* 10
operation:add

name:multiple high resists bonus
dice:$Pd$Q
expr:P:OBJ_POWER_NUM_HIGH_RES:+ 0
expr:Q:OBJ_POWER_NUM_HIGH_RES:* 2
operation:add

name:all high resists bonus
dice:$P
expr:P:OBJ_POWER_ALL_HIGH_RES:* 10
operation:add

name:multiple extra high resists bonus
dice:$Pd$Q
expr:P:OBJ_POWER_NUM_XHIGH_RES:+ 0
expr:Q:OBJ_POWER_NUM_XHIGH_RES:* 2
operation:add

name:all extra high resists bonus
dice:$P
expr:P:OBJ_POWER_ALL_XHIGH_RES:* 10
operation:add

name:multiple immunities bonus
dice:$Pd$Q
expr:P:OBJ_POWER_NUM_IMM:+ 0
expr:Q:OBJ_POWER_NUM_IMM:* 6
operation:add

name:all immunities bonus (inhibiting)
dice:$P
expr:P:OBJ_POWER_ALL_IMM:* 20000
operation:add

# this is a base power for activation for wearables, or effect for consumables
name:effect power
dice:$P
expr:P:OBJ_POWER_EFFECT_POWER:+ 0
operation:add

name:curse power
dice:$P
expr:P:OBJ_POWER_CURSE_POWER:+ 0
operation:add