Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function LoggerGonnaLog(all_bps)
- for id, bp in all_bps do
- if table.find(bp.Categories, 'SELECTABLE') then
- --Define start table
- local ThreatTable = {
- AirThreatLevel = 0,
- EconomyThreatLevel = 0,
- SubThreatLevel = 0,
- SurfaceThreatLevel = 0,
- --These are temporary to be merged into the others after calculations
- HealthThreat = 0,
- ShieldThreat = 0,
- PersonalShieldThreat = 0,
- UnknownWeaponThreat = 0,
- }
- --define base health and shield values
- if bp.Defense.MaxHealth then
- ThreatTable.HealthThreat = bp.Defense.MaxHealth * 0.01
- end
- if bp.Defense.Shield then
- local shield = bp.Defense.Shield
- local shieldarea = (shield.ShieldSize or 0) * (shield.ShieldSize or 0) * math.pi
- local skirtarea = (bp.Physics.SkirtSizeX or 3) * (bp.Physics.SkirtSizeY or 3)
- if table.find(bp.Display.Abilities,'<LOC ability_personalshield>Personal Shield') or shieldarea < skirtarea then
- ThreatTable.PersonalShieldThreat = (shield.ShieldMaxHealth or 0) * 0.01
- else
- ThreatTable.ShieldThreat = ((shieldarea - skirtarea) * (shield.ShieldMaxHealth or 0) * (shield.ShieldRegenRate or 1)) / 250000000
- end
- end
- --Define eco production values
- if bp.Economy.ProductionPerSecondMass then
- --Mass prod + 5% of health
- ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.ProductionPerSecondMass * 10 + (ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat) * 5
- end
- if bp.Economy.ProductionPerSecondEnergy then
- --Energy prod + 1% of health
- ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.ProductionPerSecondEnergy * 0.1 + ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat
- end
- --0 off the personal health values if we alreaady used them
- if bp.Economy.ProductionPerSecondMass or bp.Economy.ProductionPerSecondEnergy then
- ThreatTable.HealthThreat = 0
- ThreatTable.PersonalShieldThreat = 0
- end
- --Calculate for build rates, ignore things that only upgrade
- if bp.Economy.BuildRate and (bp.Economy.BuildableCategory[1] != bp.General.UpgradesTo and not bp.Economy.BuildableCategory[2]) then
- --non-mass producing energy production units that can build get off easy on the health calculation. Engineering reactor, we're looking at you
- if bp.Physics.MotionType == 'RULEUMT_None' then
- ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.BuildRate * 2 + (ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat) * 2
- else
- ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.BuildRate + (ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat) * 3
- end
- end
- --0 off the personal health values if we alreaady used them
- if bp.Economy.BuildRate and (bp.Economy.BuildableCategory[1] != bp.General.UpgradesTo and not bp.Economy.BuildableCategory[2]) then
- ThreatTable.HealthThreat = 0
- ThreatTable.PersonalShieldThreat = 0
- end
- --Calculate for storage values.
- if bp.Economy.StorageMass then
- ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.StorageMass * 0.01 + ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat
- end
- if bp.Economy.StorageEnergy then
- ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.StorageEnergy * 0.001 + ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat
- end
- --0 off the personal health values if we alreaady used them
- if bp.Economy.StorageMass or bp.Economy.StorageEnergy then
- ThreatTable.HealthThreat = 0
- ThreatTable.PersonalShieldThreat = 0
- end
- --Wepins
- if bp.Weapon then
- for i, weapon in bp.Weapon do
- if weapon.RangeCategory == 'UWRC_AntiAir' or weapon.TargetRestrictOnlyAllow == 'AIR' or string.find(weapon.WeaponCategory or 'nope', 'Anti Air') then
- ThreatTable.AirThreatLevel = ThreatTable.AirThreatLevel + CalculatedDPS(weapon) / 10
- elseif weapon.RangeCategory == 'UWRC_AntiNavy' or string.find(weapon.WeaponCategory or 'nope', 'Anti Navy') then
- ThreatTable.SubThreatLevel = ThreatTable.SubThreatLevel + CalculatedDPS(weapon) / 10
- elseif weapon.RangeCategory == 'UWRC_DirectFire' or string.find(weapon.WeaponCategory or 'nope', 'Direct Fire') then
- ThreatTable.SurfaceThreatLevel = ThreatTable.SurfaceThreatLevel + CalculatedDPS(weapon) / 10
- elseif weapon.RangeCategory == 'UWRC_IndirectFire' or string.find(weapon.WeaponCategory or 'nope', 'Artillery') then
- --Range cutoff for artillery being considered eco and surface threat is 100
- local wepDPS = CalculatedDPS(weapon)
- if weapon.MinRadius and weapon.MinRadius >= 100 then
- ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + wepDPS * 2.35
- elseif weapon.MaxRadius and weapon.MaxRadius <= 100 then
- ThreatTable.SurfaceThreatLevel = ThreatTable.SurfaceThreatLevel + wepDPS * 0.65
- else
- local distr = (100 - (weapon.MinRadius or 0)) / (weapon.MaxRadius - (weapon.MinRadius or 0))
- ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + wepDPS * (1 - distr) * 2.35
- ThreatTable.SurfaceThreatLevel = ThreatTable.SurfaceThreatLevel + wepDPS * distr * 0.65
- end
- else
- ThreatTable.UnknownWeaponThreat = ThreatTable.UnknownWeaponThreat + CalculatedDPS(weapon)
- end
- --LOG(id .. " - " .. LOC(bp.General.UnitName or bp.Description) .. ' -- ' .. (weapon.DisplayName or '<Unnamed weapon>') .. ' ' .. weapon.RangeCategory .. " DPS: " .. CalculatedDPS(weapon))
- end
- end
- local checkthreat = 0
- for k, v in { 'AirThreatLevel', 'EconomyThreatLevel', 'SubThreatLevel', 'SurfaceThreatLevel',} do
- checkthreat = checkthreat + ThreatTable[v]
- end
- if checkthreat == 0 and ThreatTable.UnknownWeaponThreat then
- --If we have no idea what it is still, it has threat equal to its unkown weapon DPS.
- ThreatTable.EconomyThreatLevel = ThreatTable.UnknownWeaponThreat
- ThreatTable.UnknownWeaponThreat = 0
- elseif checkthreat == 0 and bp.Economy.MaintenanceConsumptionPerSecondEnergy and bp.Economy.MaintenanceConsumptionPerSecondEnergy > 0 then
- --If we STILL have no idea what it's threat is, and it uses power, its obviously doing something fucky, so we'll use that.
- ThreatTable.EconomyThreatLevel = bp.Economy.MaintenanceConsumptionPerSecondEnergy * 0.0175
- end
- for i, v in ThreatTable do
- if v == 0 then
- ThreatTable[i] = nil
- end
- end
- LOG(id .. ' threat table =')
- LOG(repr(ThreatTable))
- end
- end
- end
Add Comment
Please, Sign In to add comment