library UpgradeUnit initializer init
globals
private hashtable hash
integer array MeleeDmgUpg
integer array MeleeArmUpg
integer array RangeDmgUpg
integer array RangeArmUpg
endglobals
private function main takes nothing returns boolean
local unit u = GetTrainedUnit()
local integer uType = GetUnitTypeId(u)
local integer city = OwningCity[GetUnitUserData(GetTriggerUnit())]
local integer damage
set damage = LoadInteger(hash, GetUnitTypeId(u), StringHash("Damage"))
call BJDebugMsg(I2S(uType) + " damage: " + I2S(damage)) // works!
call BJDebugMsg("City: " + I2S(city)) // works!
if (IsUnitIdType(uType, UNIT_TYPE_MELEE_ATTACKER) == true ) then
if (MeleeDmgUpg[city] > 0) then
set damage = LoadInteger(hash, GetUnitTypeId(u), StringHash("Damage"))
//call SetUnitAbilityLevel(u, 'xxxx', 0)
endif
if (MeleeArmUpg[city] > 0) then
call SetUnitAbilityLevel(u, 'uArm', (MeleeArmUpg[city] + 1))
endif
elseif (IsUnitIdType(uType, UNIT_TYPE_RANGED_ATTACKER) == true) then
if (RangeDmgUpg[city] > 0) then
set damage = LoadInteger(hash, GetUnitTypeId(u), StringHash("Damage"))
//call SetUnitAbilityLevel(u, 'xxxx', 0)
endif
if (RangeArmUpg[city] > 0) then
call SetUnitAbilityLevel(u, 'uArm', (RangeArmUpg[city] + 1))
endif
set u = null
endif
return false
endfunction
private function save takes integer db, integer nod, integer spd, integer ut returns nothing
local integer dmg = ((nod + db) + (nod*spd+db))/2
// Either use this
call SaveInteger(hash, ut, StringHash("Damage"), dmg)
// ... or this
call SaveInteger(hash, ut, StringHash("DamageBase"), db)
call SaveInteger(hash, ut, StringHash("NumberOfDice"), nod)
call SaveInteger(hash, ut, StringHash("SidesPerDice"), spd)
endfunction
private function init takes nothing returns nothing
local integer uType
local integer DamageBase
local integer NumberOfDice
local integer SidesPerDice
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerAddCondition( t, Condition( function main))
set t = null
// Save Damage of Unit Types
set hash = InitHashtable()
set uType = 'hfoo' // Footman
set DamageBase = 11
set NumberOfDice = 1
set SidesPerDice = 2
call save(DamageBase, NumberOfDice, SidesPerDice, uType)
set uType = 'hmil'
set DamageBase = 11
set NumberOfDice = 1
set SidesPerDice = 2
call save(DamageBase, NumberOfDice, SidesPerDice, uType)
endfunction
endlibrary