ForbodingAngel

Untitled

Mar 1st, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. function gadget:GetInfo()
  2. return {
  3. name = "Weapon Tech Levels",
  4. desc = "Makes certain weapons better after technologies are unlocked",
  5. author = "Anarchid",
  6. date = "28th February 2014",
  7. license = "GNU GPL, v2 or later",
  8. layer = -1,
  9. enabled = false,
  10. }
  11. end
  12.  
  13. -- Entire gadget is synced
  14. if not gadgetHandler:IsSyncedCode() then
  15. return
  16. end
  17.  
  18. -- list of upgrade class names to tech levels, automatically initialized from weapondef customparam "upgradeClass"
  19. local upgrades = {}
  20.  
  21. -- table to contain each team's current level in each tech. Ideally should be somehow available to widgets, for example via TeamRulesParams.
  22. -- however, rulesparams cannot have tables, so the table would have to be serialized... cba atm.
  23. local teamUpgradeLevels = {}
  24.  
  25. function gadget:Initialize()
  26.  
  27. -- filter distinct upgrade classes from all weapondef customparams
  28. for i=1,#WeaponDefs do
  29. local wd = WeaponDefs[i]
  30. if wd.customParams then
  31. local class = wd.customParams.upgradeClass;
  32. if class then
  33. if not upgrades[class] then upgrades[class] = true end
  34. end
  35. end
  36. end
  37.  
  38. -- assign zero tech level in each tech to each team
  39. local teams = Spring.GetTeamList()
  40. for i=1, #teams do
  41. teamUpgradeLevels[team] = {}
  42. for upgrade,_ in pairs(upgrades) do
  43. teamUpgradeLevels[team][upgrade] = 0;
  44. end
  45. end
  46. end
  47.  
  48.  
  49. -- Currently upgrades are units like any other. This is simply the easiest way to do them.
  50. -- If you want to do it any other way, just call GG.UpgradeComplete on your appropriate event.
  51. function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
  52. local ud = UnitDefs[unitDefID];
  53. if ud.customParams then
  54. local tech = ud.customParams.upgradeTech;
  55. local level = tonumber(ud.customParams.upgradeLevel);
  56. if tech and level then
  57. GG.UpgradeComplete(tech, level, teamID);
  58. end
  59. end
  60. end
  61.  
  62. function GG.UpgradeComplete(techName, level, teamID)
  63. level = math.max(teamUpgradeLevels[teamID][techName], level);
  64. teamUpgradeLevels[teamID][techName] = level;
  65. end
  66.  
  67. function gadget:UnitPreDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponDefID, attackerID, attackerDefID, attackerTeam)
  68. local wd = WeaponDefs[weaponDefID];
  69. local weaponTech = wd.customParams.upgradeClass or false;
  70.  
  71. if (weapontech) then
  72. local techModifier = (teamUpgradeLevels[attackerTeam][weaponTech] or 0);
  73. Spring.Echo (techModifier)
  74. damage = damage + damage*techModifier;
  75. paralyzer = paralyzer + paralyzer*techModifier;
  76. end
  77.  
  78. return damage;
  79. end
Advertisement
Add Comment
Please, Sign In to add comment