Guest User

Untitled

a guest
Apr 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.73 KB | None | 0 0
  1. function LoggerGonnaLog(all_bps)
  2. for id, bp in all_bps do
  3. if table.find(bp.Categories, 'SELECTABLE') then
  4. --Define start table
  5. local ThreatTable = {
  6. AirThreatLevel = 0,
  7. EconomyThreatLevel = 0,
  8. SubThreatLevel = 0,
  9. SurfaceThreatLevel = 0,
  10. --These are temporary to be merged into the others after calculations
  11. HealthThreat = 0,
  12. ShieldThreat = 0,
  13. PersonalShieldThreat = 0,
  14. UnknownWeaponThreat = 0,
  15. }
  16. --define base health and shield values
  17. if bp.Defense.MaxHealth then
  18. ThreatTable.HealthThreat = bp.Defense.MaxHealth * 0.01
  19. end
  20. if bp.Defense.Shield then
  21. local shield = bp.Defense.Shield
  22. local shieldarea = (shield.ShieldSize or 0) * (shield.ShieldSize or 0) * math.pi
  23. local skirtarea = (bp.Physics.SkirtSizeX or 3) * (bp.Physics.SkirtSizeY or 3)
  24. if table.find(bp.Display.Abilities,'<LOC ability_personalshield>Personal Shield') or shieldarea < skirtarea then
  25. ThreatTable.PersonalShieldThreat = (shield.ShieldMaxHealth or 0) * 0.01
  26. else
  27. ThreatTable.ShieldThreat = ((shieldarea - skirtarea) * (shield.ShieldMaxHealth or 0) * (shield.ShieldRegenRate or 1)) / 250000000
  28. end
  29. end
  30. --Define eco production values
  31. if bp.Economy.ProductionPerSecondMass then
  32. --Mass prod + 5% of health
  33. ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.ProductionPerSecondMass * 10 + (ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat) * 5
  34. end
  35. if bp.Economy.ProductionPerSecondEnergy then
  36. --Energy prod + 1% of health
  37. ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.ProductionPerSecondEnergy * 0.1 + ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat
  38. end
  39. --0 off the personal health values if we alreaady used them
  40. if bp.Economy.ProductionPerSecondMass or bp.Economy.ProductionPerSecondEnergy then
  41. ThreatTable.HealthThreat = 0
  42. ThreatTable.PersonalShieldThreat = 0
  43. end
  44.  
  45. --Calculate for build rates, ignore things that only upgrade
  46. if bp.Economy.BuildRate and (bp.Economy.BuildableCategory[1] != bp.General.UpgradesTo and not bp.Economy.BuildableCategory[2]) then
  47. --non-mass producing energy production units that can build get off easy on the health calculation. Engineering reactor, we're looking at you
  48. if bp.Physics.MotionType == 'RULEUMT_None' then
  49. ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.BuildRate * 2 + (ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat) * 2
  50. else
  51. ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.BuildRate + (ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat) * 3
  52. end
  53. end
  54. --0 off the personal health values if we alreaady used them
  55. if bp.Economy.BuildRate and (bp.Economy.BuildableCategory[1] != bp.General.UpgradesTo and not bp.Economy.BuildableCategory[2]) then
  56. ThreatTable.HealthThreat = 0
  57. ThreatTable.PersonalShieldThreat = 0
  58. end
  59.  
  60. --Calculate for storage values.
  61. if bp.Economy.StorageMass then
  62. ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.StorageMass * 0.01 + ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat
  63. end
  64. if bp.Economy.StorageEnergy then
  65. ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + bp.Economy.StorageEnergy * 0.001 + ThreatTable.HealthThreat + ThreatTable.PersonalShieldThreat
  66. end
  67. --0 off the personal health values if we alreaady used them
  68. if bp.Economy.StorageMass or bp.Economy.StorageEnergy then
  69. ThreatTable.HealthThreat = 0
  70. ThreatTable.PersonalShieldThreat = 0
  71. end
  72.  
  73. --Wepins
  74. if bp.Weapon then
  75. for i, weapon in bp.Weapon do
  76. if weapon.RangeCategory == 'UWRC_AntiAir' or weapon.TargetRestrictOnlyAllow == 'AIR' or string.find(weapon.WeaponCategory or 'nope', 'Anti Air') then
  77. ThreatTable.AirThreatLevel = ThreatTable.AirThreatLevel + CalculatedDPS(weapon) / 10
  78. elseif weapon.RangeCategory == 'UWRC_AntiNavy' or string.find(weapon.WeaponCategory or 'nope', 'Anti Navy') then
  79. ThreatTable.SubThreatLevel = ThreatTable.SubThreatLevel + CalculatedDPS(weapon) / 10
  80. elseif weapon.RangeCategory == 'UWRC_DirectFire' or string.find(weapon.WeaponCategory or 'nope', 'Direct Fire') then
  81. ThreatTable.SurfaceThreatLevel = ThreatTable.SurfaceThreatLevel + CalculatedDPS(weapon) / 10
  82. elseif weapon.RangeCategory == 'UWRC_IndirectFire' or string.find(weapon.WeaponCategory or 'nope', 'Artillery') then
  83. --Range cutoff for artillery being considered eco and surface threat is 100
  84. local wepDPS = CalculatedDPS(weapon)
  85. if weapon.MinRadius and weapon.MinRadius >= 100 then
  86. ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + wepDPS * 2.35
  87. elseif weapon.MaxRadius and weapon.MaxRadius <= 100 then
  88. ThreatTable.SurfaceThreatLevel = ThreatTable.SurfaceThreatLevel + wepDPS * 0.65
  89. else
  90. local distr = (100 - (weapon.MinRadius or 0)) / (weapon.MaxRadius - (weapon.MinRadius or 0))
  91. ThreatTable.EconomyThreatLevel = ThreatTable.EconomyThreatLevel + wepDPS * (1 - distr) * 2.35
  92. ThreatTable.SurfaceThreatLevel = ThreatTable.SurfaceThreatLevel + wepDPS * distr * 0.65
  93. end
  94. else
  95. ThreatTable.UnknownWeaponThreat = ThreatTable.UnknownWeaponThreat + CalculatedDPS(weapon)
  96. end
  97. --LOG(id .. " - " .. LOC(bp.General.UnitName or bp.Description) .. ' -- ' .. (weapon.DisplayName or '<Unnamed weapon>') .. ' ' .. weapon.RangeCategory .. " DPS: " .. CalculatedDPS(weapon))
  98. end
  99. end
  100.  
  101. local checkthreat = 0
  102. for k, v in { 'AirThreatLevel', 'EconomyThreatLevel', 'SubThreatLevel', 'SurfaceThreatLevel',} do
  103. checkthreat = checkthreat + ThreatTable[v]
  104. end
  105. if checkthreat == 0 and ThreatTable.UnknownWeaponThreat then
  106. --If we have no idea what it is still, it has threat equal to its unkown weapon DPS.
  107. ThreatTable.EconomyThreatLevel = ThreatTable.UnknownWeaponThreat
  108. ThreatTable.UnknownWeaponThreat = 0
  109. elseif checkthreat == 0 and bp.Economy.MaintenanceConsumptionPerSecondEnergy and bp.Economy.MaintenanceConsumptionPerSecondEnergy > 0 then
  110. --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.
  111. ThreatTable.EconomyThreatLevel = bp.Economy.MaintenanceConsumptionPerSecondEnergy * 0.0175
  112. end
  113. for i, v in ThreatTable do
  114. if v == 0 then
  115. ThreatTable[i] = nil
  116. end
  117. end
  118. LOG(id .. ' threat table =')
  119. LOG(repr(ThreatTable))
  120. end
  121. end
  122. end
Add Comment
Please, Sign In to add comment