Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --==========================================================================================================================
- -- VARIABLES
- --==========================================================================================================================
- -- DB stuff
- ----------------------------------------------------------------------------------------------------------------------------
- local promotionRedDevilAfterRandom = GameInfoTypes["PROMOTION_DMS_RED_DEVIL_AFTERRANDOM"]
- local promotionRedDevil = GameInfoTypes["PROMOTION_DMS_RED_DEVIL"]
- ----------------------------------------------------------------------------------------------------------------------------
- -- Adjustables
- ----------------------------------------------------------------------------------------------------------------------------
- local splashDamageRange = 1
- local splashDamageUnitAmount = 15
- local splashDamageCityAmount = 15
- ----------------------------------------------------------------------------------------------------------------------------
- -- debug
- ----------------------------------------------------------------------------------------------------------------------------
- local printDebug = true
- ----------------------------------------------------------------------------------------------------------------------------
- -- other stuff
- ----------------------------------------------------------------------------------------------------------------------------
- local activePlayer = Game.GetActivePlayer()
- local mathMin = math.min
- ----------------------------------------------------------------------------------------------------------------------------
- -- GameEvents / Events
- ----------------------------------------------------------------------------------------------------------------------------
- local UnitPrekill = GameEvents.UnitPrekill.Add
- local PlayerDoTurn = GameEvents.PlayerDoTurn.Add
- local SerialEventUnitSetDamage = Events.SerialEventUnitSetDamage.Add
- --==========================================================================================================================
- -- DEBUG
- --==========================================================================================================================
- -- DMS_Print
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Print(str)
- if printDebug == false then return end
- return print(str)
- end
- --==========================================================================================================================
- -- FUNCTIONS
- --==========================================================================================================================
- -- DMS_Biafra_UU_IsRedDevil
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Biafra_UU_IsRedDevil(plot)
- local numUnits = plot:GetNumUnits()
- local unit = "NONE"
- if numUnits == 0 then DMS_Print("DMS_Biafra_UU_IsRedDevil: no units found on plot (" .. plot:GetX() .. ", " .. plot:GetY() .. ")..") return false end
- for i = 0, numUnits - 1 do
- local unit = plot:GetUnit(i)
- if unit ~= nil and unit ~= -1 then
- DMS_Print("DMS_Biafra_UU_IsRedDevil: found unit (" .. unit:GetName() .. ") on plot (" .. plot:GetX() .. ", " .. plot:GetY() .. ")..")
- if unit:IsHasPromotion(promotionRedDevilAfterRandom) then
- DMS_Print("DMS_Biafra_UU_IsRedDevil: unit has RedDevilAfterRandom promotion, return info to DMS_Biafra_UU_CombatListener..")
- return unit, true
- end
- end
- end
- DMS_Print("DMS_Biafra_UU_IsRedDevil: no unit or no unit with RedDevilAfterRandom promotion found, return info to DMS_Biafra_UU_CombatListener..")
- return unit, false
- end
- ----------------------------------------------------------------------------------------------------------------------------
- -- DMS_Biafra_UU_SplashDamageUnit
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Biafra_UU_SplashDamageUnit(player, unit, plot)
- local numUnits = plot:GetNumUnits()
- if numUnits == 0 then return end
- DMS_Print("DMS_Biafra_UU_SplashDamageUnit: plot (" .. plot:GetX() .. ", " .. plot:GetY() .. ") has unit to be 'splash damaged'..")
- for i = 0, numUnits - 1 do
- local plotUnit = plot:GetUnit(i)
- if plotUnit ~= nil and plotUnit ~= -1 then
- DMS_Print("DMS_Biafra_UU_SplashDamageUnit: unit (" .. unit:GetName() .. ") is owned by player " .. Players[unit:GetOwner()]:GetCivilizationShortDescription() .. "..")
- if unit ~= plotUnit then
- local damage = mathMin(plotUnit:GetMaxHitPoints() - plotUnit:GetDamage(), splashDamageUnitAmount)
- plotUnit:ChangeDamage(damage)
- DMS_Print("DMS_Biafra_UU_SplashDamageUnit: damage dealt is: " .. damage .. "..")
- else
- DMS_Print("DMS_Biafra_UU_SplashDamageUnit: unit (" .. unit:GetName() .. ") is actually the unit performing the splash attack, return..")
- end
- end
- end
- end
- ----------------------------------------------------------------------------------------------------------------------------
- -- DMS_Biafra_UU_SplashDamageCities
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Biafra_UU_SplashDamageCities(player, plot)
- if not plot:IsCity() then return end
- DMS_Print("DMS_Biafra_UU_SplashDamageCities: plot (" .. plot:GetX() .. ", " .. plot:GetY() .. ") has city to be 'splash damaged'..")
- local city = plot:GetPlotCity()
- if city == nil or city == -1 then return end
- DMS_Print("DMS_Biafra_UU_SplashDamageCities: city (" .. city:GetName() .. ") is owned by player " .. Players[city:GetOwner()]:GetCivilizationShortDescription() .. "..")
- local damage = mathMin(city:GetMaxHitPoints() - city:GetDamage(), splashDamageCityAmount)
- city:ChangeDamage(damage)
- DMS_Print("DMS_Biafra_UU_SplashDamageCities: damage dealt is: " .. damage .. "..")
- end
- ----------------------------------------------------------------------------------------------------------------------------
- -- DMS_Biafra_UU_DoSplashDamage
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Biafra_UU_DoSplashDamage(player, unit, plot)
- DMS_Print("DMS_Biafra_UU_DoSplashDamage: perform splash damage from attack on plot (" .. plot:GetX() .. ", " .. plot:GetY() .. "), iterate nearby plots..")
- for nearbyPlot in PlotAreaSweepIterator(plot, splashDamageRange, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_EXCLUDE) do
- DMS_Print("DMS_Biafra_UU_DoSplashDamage: checking nearby plot (" .. nearbyPlot:GetX() .. ", " .. nearbyPlot:GetY() .. ")..")
- DMS_Biafra_UU_SplashDamageUnit(player, unit, plot)
- DMS_Biafra_UU_SplashDamageCities(player, plot)
- end
- end
- ----------------------------------------------------------------------------------------------------------------------------
- -- DMS_Biafra_UU_ResetPromotions
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Biafra_UU_ResetPromotions(unit)
- if unit:IsHasPromotion(promotionRedDevilAfterRandom) then
- DMS_Print("DMS_Biafra_UU_ResetPromotions: found unit with RedDevilAfterRandom promotion..")
- unit:SetHasPromotion(promotionRedDevilAfterRandom, false)
- unit:SetHasPromotion(promotionRedDevil, true)
- DMS_Print("DMS_Biafra_UU_ResetPromotions: promotions reset..")
- end
- end
- ----------------------------------------------------------------------------------------------------------------------------
- -- DMS_Biafra_UU_CombatListener
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Biafra_UU_CombatListener(player, plot, isRedDevil)
- local unit, redDevil = isRedDevil
- DMS_Print("DMS_Biafra_UU_CombatListener: info from DMS_Biafra_UU_IsRedDevil received..")
- if unit == "NONE" then DMS_Print("DMS_Biafra_UU_CombatListener: no unit found..") return false end
- if redDevil == false then DMS_Print("DMS_Biafra_UU_CombatListener: unit did not have correct promotion, return..") return false end
- DMS_Print("DMS_Biafra_UU_CombatListener: call DMS_Biafra_UU_DoSplashDamage..")
- DMS_Biafra_UU_DoSplashDamage(player, unit, plot)
- DMS_Print("DMS_Biafra_UU_CombatListener: call DMS_Biafra_UU_ResetPromotions..")
- DMS_Biafra_UU_ResetPromotions(unit)
- DMS_Print("DMS_Biafra_UU_CombatListener: return culprit found..")
- return redDevil
- end
- --==========================================================================================================================
- -- MAIN FUNCTIONS
- --==========================================================================================================================
- -- DMS_Biafra_UnitPrekill
- ----------------------------------------------------------------------------------------------------------------------------
- local UPK_RedDevil = "NONE"
- local function DMS_Biafra_UnitPrekill(killedUnitPlayerID, unitID, unitType, x, y, bDelay, killerUnitPlayerID)
- if bDelay then UPK_RedDevil = killerUnitPlayerID; DMS_Print("DMS_Biafra_UnitPrekill: bDelay is true, return..") return end
- if UPK_RedDevil == -1 then UPK_RedDevil= "NONE"; DMS_Print("DMS_Biafra_UnitPrekill: UPK_RedDevil is nil, return..") return end
- local killedUnitPlayer = Players[killedUnitPlayerID]
- if killedUnitPlayer == nil or killedUnitPlayer == -1 then DMS_Print("DMS_Biafra_UnitPrekill: killedUnitPlayer is nil, return..") return end
- local killedUnit = killedUnitPlayer:GetUnitByID(unitID)
- if killedUnit == nil or killedUnit == -1 then DMS_Print("DMS_Biafra_UnitPrekill: killedUnit is nil, return..") return end
- local killerUnitPlayer = Players[UPK_RedDevil]
- UPK_RedDevil = "NONE"
- if killerUnitPlayer == nil or killerUnitPlayer == -1 then DMS_Print("DMS_Biafra_UnitPrekill: killerUnitPlayer is nil, return..") return end
- DMS_Print("DMS_Biafra_UnitPrekill: killerUnitPlayer is " .. killerUnitPlayer:GetCivilizationShortDescription() .. "..")
- local plot = Map.GetPlot(x, y)
- if plot == nil or plot == -1 then return end
- DMS_Print("DMS_Biafra_UnitPrekill: killed unit is on plot (" .. plot:GetX() .. ", " .. plot:GetY() .. "), iterate nearby plots..")
- for nearbyPlot in PlotAreaSweepIterator(plot, 4, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
- DMS_Print("DMS_Biafra_UnitPrekill: checking nearby plot (" .. nearbyPlot:GetX() .. ", " .. nearbyPlot:GetY() .. ")..")
- splashDamagePerformed = DMS_Biafra_UU_CombatListener(killerUnitPlayer, nearbyPlot, DMS_Biafra_UU_IsRedDevil(nearbyPlot))
- if splashDamagePerformed then DMS_Print("DMS_Biafra_UnitPrekill: culprit found on plot (" .. nearbyPlot:GetX() .. ", " .. nearbyPlot:GetY() .. "), break plot iteration..") break end
- end
- end
- ----------------------------------------------------------------------------------------------------------------------------
- -- DMS_Biafra_SerialEventUnitSetDamage
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Biafra_SerialEventUnitSetDamage(playerID, unitID, newDamage, oldDamage)
- if newDamage < oldDamage then return end
- local player = Players[playerID]
- DMS_Print("DMS_Biafra_SerialEventUnitSetDamage: iterate units for player " .. player:GetCivilizationShortDescription() .. " (ID " .. playerID .. ") to see if attack is by Red Devil Unit..")
- for iterUnit in player:Units() do
- if iterUnit:GetID() == unitID then
- local plot = iterUnit:GetPlot()
- if plot ~= nil and plot ~= -1 then
- DMS_Print("DMS_Biafra_SerialEventUnitSetDamage: damaged unit is on plot (" .. plot:GetX() .. ", " .. plot:GetY() .. "), iterate nearby plots..")
- for nearbyPlot in PlotAreaSweepIterator(plot, 4, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
- DMS_Print("DMS_Biafra_SerialEventUnitSetDamage: checking nearby plot (" .. nearbyPlot:GetX() .. ", " .. nearbyPlot:GetY() .. ")..")
- splashDamagePerformed = DMS_Biafra_UU_CombatListener(player, nearbyPlot, DMS_Biafra_UU_IsRedDevil(nearbyPlot))
- if splashDamagePerformed then DMS_Print("DMS_Biafra_SerialEventUnitSetDamage: culprit found on plot (" .. nearbyPlot:GetX() .. ", " .. nearbyPlot:GetY() .. "), break plot iteration..") break end
- end
- end
- end
- end
- DMS_Print("DMS_Biafra_SerialEventUnitSetDamage: unit iteration done for player " .. player:GetCivilizationShortDescription() .. " (ID " .. playerID .. ")..")
- end
- ----------------------------------------------------------------------------------------------------------------------------
- -- DMS_Biafra_PlayerDoTurn
- ----------------------------------------------------------------------------------------------------------------------------
- local function DMS_Biafra_PlayerDoTurn(playerID)
- local player = Players[playerID]
- if player == nil or player == -1 then return end
- DMS_Print("DMS_Biafra_PlayerDoTurn: iterate units for player " .. player:GetCivilizationShortDescription() .. " (ID " .. playerID .. ") to reset possible Red Devil Unit Promotions..")
- for unit in player:Units() do
- DMS_Biafra_UU_ResetPromotions(unit)
- end
- DMS_Print("DMS_Biafra_PlayerDoTurn: unit iteration done for player " .. player:GetCivilizationShortDescription() .. " (ID " .. playerID .. ")..")
- end
- --==========================================================================================================================
- -- GAMEEVENTS / EVENTS HOOKS
- --==========================================================================================================================
- UnitPrekill(DMS_Biafra_UnitPrekill)
- PlayerDoTurn(DMS_Biafra_PlayerDoTurn)
- SerialEventUnitSetDamage(DMS_Biafra_SerialEventUnitSetDamage)
- --==========================================================================================================================
- --==========================================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement