So, uh, can anyone have a looksie at this here script I wrote and see if there's anything odd? I'm not going to be that confident in this business until I write ~5 or 6 of them...
[c-- Gives power level of selected unit. Type "popup" for popup announcement.
local selectedUnit = dfhack.gui.getSelectedUnit(silent)
local arg = ...
function isWinded(unit)
if unit.counters.winded > 0 then return true end
return false
end
function isStunned(unit)
if unit.counters.stunned > 0 then return true end
return false
end
function isUnconscious(unit)
if unit.counters.unconscious > 0 then return true end
return false
end
function isParalyzed(unit)
if unit.counters2.paralysis > 0 then return true end
return false
end
function getExhaustion(unit)
local exhaustion = 1
if unit.counters2.exhaustion~=0 then
exhaustion = 1000/unit.counters2.exhaustion
if exhaustion>1 then exhaustion = 1 end
else unit.counters2.exhaustion=1
return exhaustion
end
return 1
end
function getBoost(unit)
return unit.counters.soldier_mood
end
--power levels should account for disabilities and such
--I have to declare the individual skill's numbers, including these here makes the program easier to read
local MELEE_COMBAT = 99
local WRESTLING = 102
local GRASP_STRIKE = 104
local STANCE_STRIKE = 105
local BITE = 103
local THROW = 55
local RANGED_COMBAT = 101
if df.isnull(selectedUnit) then
qerror('Need to select a unit.')
end
--blood_max appears to be the creature's body size divided by 10; the power level calculation relies on body size divided by 1000, so divided by 100 it is. blood_count refers to current blood amount, and it, when full, is equal to blood_max.
local strength = selectedUnit.body.physical_attrs.STRENGTH.value/3550
local agility = selectedUnit.body.physical_attrs.AGILITY.value/3550
local endurance = selectedUnit.body.physical_attrs.ENDURANCE.value/1000
local toughness = selectedUnit.body.physical_attrs.TOUGHNESS.value/2250
local spatialsense = selectedUnit.status.current_soul.mental_attrs.SPATIAL_SENSE.value/1500
local kinestheticsense = selectedUnit.status.current_soul.mental_attrs.KINESTHETIC_SENSE.value/1000
local willpower = selectedUnit.status.current_soul.mental_attrs.WILLPOWER.value/1000
local exhaustion = getExhaustion(selectedUnit)
local bodysize = selectedUnit.body.blood_count/100
local fighting = dfhack.units.getEffectiveSkill(selectedUnit, MELEE_COMBAT)*1000
local wrestling = dfhack.units.getEffectiveSkill(selectedUnit, WRESTLING)*1000
local grasp_strike = dfhack.units.getEffectiveSkill(selectedUnit, GRASP_STRIKE)*1000
local stance_strike = dfhack.units.getEffectiveSkill(selectedUnit, STANCE_STRIKE)*1000
local biting = dfhack.units.getEffectiveSkill(selectedUnit, BITE)*1000
local ki = dfhack.units.getEffectiveSkill(selectedUnit, THROW)*1000 + dfhack.units.getEffectiveSkill(selectedUnit, RANGED_COMBAT)*1000
local powerlevel = bodysize*bodysize*strength*agility*endurance*toughness*spatialsense*kinestheticsense*willpower*exhaustion+fighting+wrestling+grasp_strike+stance_strike+biting+ki
if getBoost(selectedUnit)==0 then powerlevel=powerlevel*1.5 end
if getBoost(selectedUnit)==1 then powerlevel=powerlevel*2 end
if getBoost(selectedUnit)==2 then powerlevel=powerlevel*1.3 end
if isWinded(selectedUnit) then powerlevel=powerlevel/1.2 end
if isStunned(selectedUnit) then powerlevel=powerlevel/1.5 end
if isParalyzed(selectedUnit) then powerlevel=powerlevel/5 end
if isUnconscious(selectedUnit) then powerlevel=powerlevel/10 end
if arg == "popup" or arg == "Popup" then
dfhack.gui.showPopupAnnouncement("The scouter says " .. math.floor(powerlevel) .. "!",11)
else dfhack.gui.showAnnouncement("The scouter says " .. math.floor(powerlevel) .. "!",11)
end