Guest User

Untitled

a guest
May 19th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. -- ColeTraitScript
  2. -- Author: Vicevirtuoso
  3. -- DateCreated: 4/20/2014 8:40:39 PM
  4. --------------------------------------------------------------
  5.  
  6. include('COHSharedFunctions.lua');
  7.  
  8. local iPraetoria = GameInfoTypes.CIVILIZATION_PRAETORIA
  9.  
  10. local iBAF = GameInfoTypes.BUILDING_PRAETORIA_BAF
  11.  
  12. local iMindwashed = GameInfoTypes.SPECIALIST_MINDWASHED
  13.  
  14. local tHTFPromotions = {}
  15.  
  16. for promotion in GameInfo.UnitPromotions() do
  17. if promotion.AdjacentDamageWhenKilled > 0 then
  18. tHTFPromotions[promotion.ID] = promotion.AdjacentDamageWhenKilled
  19. end
  20. end
  21.  
  22. function StrengthFromVictoryPoints(iPlayer)
  23. if iPlayer < GameDefines.MAX_MAJOR_CIVS and tTraits[iPlayer].VictoryPointsPerStrengthPoint > 0 then
  24. local pPlayer = Players[iPlayer]
  25. local iScore = pPlayer:GetScore()
  26. local iStrengthBonus = math.floor(iScore / tTraits[iPlayer].VictoryPointsPerStrengthPoint)
  27. for pUnit in pPlayer:Units() do
  28. if pUnit:IsCombatUnit() then
  29. pUnit:SetBaseCombatStrength(GameInfo.Units[pUnit:GetUnitType()].Combat + iStrengthBonus)
  30. end
  31. end
  32. end
  33. end
  34.  
  35. GameEvents.PlayerDoTurn.Add(StrengthFromVictoryPoints)
  36.  
  37. --Variables stored between the following two functions.
  38. local iHTFDamageToDeal = 0;
  39. local pHTFPlot;
  40.  
  41. --When a unit dies, find out if it had promotions which damage adjacent units on death.
  42. function OnCanSaveUnitTheHarderTheyFall(iPlayer, iUnitID)
  43. local pPlayer = Players[iPlayer]
  44. local pUnit = pPlayer:GetUnitByID(iUnitID)
  45. for iPromotionID, iDamageThisPromotion in pairs(tHTFPromotions) do
  46. if pUnit:IsHasPromotion(iPromotionID) then
  47. iHTFDamageToDeal = iHTFDamageToDeal + iDamageThisPromotion
  48. end
  49. end
  50. if iHTFDamageToDeal > 0 then
  51. pHTFPlot = pUnit:GetPlot()
  52. end
  53. dprint("Damage to deal: " ..iHTFDamageToDeal)
  54. end
  55.  
  56. GameEvents.CanSaveUnit.Add(OnCanSaveUnitTheHarderTheyFall)
  57.  
  58.  
  59. --Now we make the unit actually do the damage. Only works if the above function gave proper values to the variables.
  60. function TheHarderTheyFall(iKiller, iPlayer, iUnitType)
  61. if iHTFDamageToDeal > 0 and pHTFPlot then
  62. local pPlayer = Players[iPlayer]
  63. for i = 0, pHTFPlot:GetNumUnits() - 1 do
  64. local pUnit = pHTFPlot:GetUnit(i)
  65. local pEnemyUnitOwner = Players[pUnit:GetOwner()]
  66. if Teams[pEnemyUnitOwner:GetTeam()]:IsAtWar(pPlayer:GetTeam()) then
  67. pUnit:ChangeDamage(iHTFDamageToDeal, iKiller)
  68. if pUnit:GetOwner() == Game:GetActivePlayer() then
  69. Events.GameplayAlertMessage(Locale.ConvertTextKey("TXT_KEY_ALERT_HTF_DAMAGE", Locale.ConvertTextKey(GameInfo.Units[iUnitType].Description), iHTFDamageToDeal, pUnit:GetName()))
  70. end
  71. end
  72. end
  73. local direction_types = {
  74. DirectionTypes.DIRECTION_NORTHEAST,
  75. DirectionTypes.DIRECTION_EAST,
  76. DirectionTypes.DIRECTION_SOUTHEAST,
  77. DirectionTypes.DIRECTION_SOUTHWEST,
  78. DirectionTypes.DIRECTION_WEST,
  79. DirectionTypes.DIRECTION_NORTHWEST
  80. }
  81. for a, direction in ipairs(direction_types) do
  82. local pNextPlot = Map.PlotDirection(pHTFPlot:GetX(), pHTFPlot:GetY(), direction)
  83. if pNextPlot ~= nil then
  84. if pNextPlot:IsUnit() then
  85. for i = 0, pNextPlot:GetNumUnits() - 1 do
  86. local pUnit = pNextPlot:GetUnit(i)
  87. local pEnemyUnitOwner = Players[pUnit:GetOwner()]
  88. if Teams[pEnemyUnitOwner:GetTeam()]:IsAtWar(pPlayer:GetTeam()) then
  89. pUnit:ChangeDamage(iHTFDamageToDeal, iKiller)
  90. if pUnit:GetOwner() == Game:GetActivePlayer() then
  91. Events.GameplayAlertMessage(Locale.ConvertTextKey("TXT_KEY_ALERT_HTF_DAMAGE", Locale.ConvertTextKey(GameInfo.Units[iUnitType].Description), iHTFDamageToDeal, pUnit:GetName()))
  92. end
  93. end
  94. end
  95. end
  96. end
  97. end
  98. end
  99. iHTFDamageToDeal = 0
  100. pHTFPlot = nil
  101. end
  102.  
  103. GameEvents.UnitKilledInCombat.Add(TheHarderTheyFall)
Advertisement
Add Comment
Please, Sign In to add comment