Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ColeTraitScript
- -- Author: Vicevirtuoso
- -- DateCreated: 4/20/2014 8:40:39 PM
- --------------------------------------------------------------
- include('COHSharedFunctions.lua');
- local iPraetoria = GameInfoTypes.CIVILIZATION_PRAETORIA
- local iBAF = GameInfoTypes.BUILDING_PRAETORIA_BAF
- local iMindwashed = GameInfoTypes.SPECIALIST_MINDWASHED
- local tHTFPromotions = {}
- for promotion in GameInfo.UnitPromotions() do
- if promotion.AdjacentDamageWhenKilled > 0 then
- tHTFPromotions[promotion.ID] = promotion.AdjacentDamageWhenKilled
- end
- end
- function StrengthFromVictoryPoints(iPlayer)
- if iPlayer < GameDefines.MAX_MAJOR_CIVS and tTraits[iPlayer].VictoryPointsPerStrengthPoint > 0 then
- local pPlayer = Players[iPlayer]
- local iScore = pPlayer:GetScore()
- local iStrengthBonus = math.floor(iScore / tTraits[iPlayer].VictoryPointsPerStrengthPoint)
- for pUnit in pPlayer:Units() do
- if pUnit:IsCombatUnit() then
- pUnit:SetBaseCombatStrength(GameInfo.Units[pUnit:GetUnitType()].Combat + iStrengthBonus)
- end
- end
- end
- end
- GameEvents.PlayerDoTurn.Add(StrengthFromVictoryPoints)
- --Variables stored between the following two functions.
- local iHTFDamageToDeal = 0;
- local pHTFPlot;
- --When a unit dies, find out if it had promotions which damage adjacent units on death.
- function OnCanSaveUnitTheHarderTheyFall(iPlayer, iUnitID)
- local pPlayer = Players[iPlayer]
- local pUnit = pPlayer:GetUnitByID(iUnitID)
- for iPromotionID, iDamageThisPromotion in pairs(tHTFPromotions) do
- if pUnit:IsHasPromotion(iPromotionID) then
- iHTFDamageToDeal = iHTFDamageToDeal + iDamageThisPromotion
- end
- end
- if iHTFDamageToDeal > 0 then
- pHTFPlot = pUnit:GetPlot()
- end
- dprint("Damage to deal: " ..iHTFDamageToDeal)
- end
- GameEvents.CanSaveUnit.Add(OnCanSaveUnitTheHarderTheyFall)
- --Now we make the unit actually do the damage. Only works if the above function gave proper values to the variables.
- function TheHarderTheyFall(iKiller, iPlayer, iUnitType)
- if iHTFDamageToDeal > 0 and pHTFPlot then
- local pPlayer = Players[iPlayer]
- for i = 0, pHTFPlot:GetNumUnits() - 1 do
- local pUnit = pHTFPlot:GetUnit(i)
- local pEnemyUnitOwner = Players[pUnit:GetOwner()]
- if Teams[pEnemyUnitOwner:GetTeam()]:IsAtWar(pPlayer:GetTeam()) then
- pUnit:ChangeDamage(iHTFDamageToDeal, iKiller)
- if pUnit:GetOwner() == Game:GetActivePlayer() then
- Events.GameplayAlertMessage(Locale.ConvertTextKey("TXT_KEY_ALERT_HTF_DAMAGE", Locale.ConvertTextKey(GameInfo.Units[iUnitType].Description), iHTFDamageToDeal, pUnit:GetName()))
- end
- end
- end
- local direction_types = {
- DirectionTypes.DIRECTION_NORTHEAST,
- DirectionTypes.DIRECTION_EAST,
- DirectionTypes.DIRECTION_SOUTHEAST,
- DirectionTypes.DIRECTION_SOUTHWEST,
- DirectionTypes.DIRECTION_WEST,
- DirectionTypes.DIRECTION_NORTHWEST
- }
- for a, direction in ipairs(direction_types) do
- local pNextPlot = Map.PlotDirection(pHTFPlot:GetX(), pHTFPlot:GetY(), direction)
- if pNextPlot ~= nil then
- if pNextPlot:IsUnit() then
- for i = 0, pNextPlot:GetNumUnits() - 1 do
- local pUnit = pNextPlot:GetUnit(i)
- local pEnemyUnitOwner = Players[pUnit:GetOwner()]
- if Teams[pEnemyUnitOwner:GetTeam()]:IsAtWar(pPlayer:GetTeam()) then
- pUnit:ChangeDamage(iHTFDamageToDeal, iKiller)
- if pUnit:GetOwner() == Game:GetActivePlayer() then
- Events.GameplayAlertMessage(Locale.ConvertTextKey("TXT_KEY_ALERT_HTF_DAMAGE", Locale.ConvertTextKey(GameInfo.Units[iUnitType].Description), iHTFDamageToDeal, pUnit:GetName()))
- end
- end
- end
- end
- end
- end
- end
- iHTFDamageToDeal = 0
- pHTFPlot = nil
- end
- GameEvents.UnitKilledInCombat.Add(TheHarderTheyFall)
Advertisement
Add Comment
Please, Sign In to add comment