local directions = {
DirectionTypes.DIRECTION_NORTHEAST, DirectionTypes.DIRECTION_EAST,
DirectionTypes.DIRECTION_SOUTHEAST, DirectionTypes.DIRECTION_SOUTHWEST,
DirectionTypes.DIRECTION_WEST, DirectionTypes.DIRECTION_NORTHWEST
}
function OnCanAirliftFrom(iPlayer, iUnit, iPlotX, iPlotY)
local pPlot = Map.GetPlot(iPlotX, iPlotY);
local pCarrUnit = nil;
local pUnit = Players[iPlayer]:GetUnitByID(iUnit);
local bIsCanAirliftFrom = false;
if pPlot and pPlot:GetNumUnits() > 1 then
for i = 0, pPlot:GetNumUnits() - 1 do
pCarrUnit = pPlot:GetUnit(i);
if pCarrUnit:GetOwner() == iPlayer and pCarrUnit ~= pUnit and pCarrUnit:IsHoveringUnit() then
bIsCanAirliftFrom = true;
break;
end
end
end
if not bIsCanAirliftFrom then
for _, direction in ipairs(directions) do
pPlot = Map.PlotDirection(iPlotX, iPlotY, direction);
if pPlot and pPlot:GetNumUnits() > 0 then
for i = 0, pPlot:GetNumUnits() - 1 do
pCarrUnit = pPlot:GetUnit(i)
if pCarrUnit:GetOwner() == iPlayer and pCarrUnit:IsHoveringUnit() then
bIsCanAirliftFrom = true;
break;
end
end
if bIsCanAirliftFrom then
break;
end
end
end
end
if pUnit and pUnit:HasMoved() then
bIsCanAirliftFrom = false;
end
return bIsCanAirliftFrom;
end
GameEvents.CanAirliftFrom.Add(OnCanAirliftFrom)
function OnCanAirliftTo(iPlayer, iUnit, iPlotX, iPlotY)
local pPlot = Map.GetPlot(iPlotX, iPlotY);
local pCarrUnit = nil;
local bIsCanAirliftTo = false;
if pPlot:GetNumUnits() == 0 then
for _, direction in ipairs(directions) do
pPlot = Map.PlotDirection(iPlotX, iPlotY, direction);
if pPlot and pPlot:IsCity() then
local pCity = pPlot:GetPlotCity();
if (pCity:GetOwner() == iPlayer or Players[pCity:GetOwner()]:IsAllies(iPlayer))
and(pCity:IsHasBuilding(GameInfo.Buildings["BUILDING_AIRPORT"].ID)
or pCity:IsHasBuilding(GameInfo.Buildings["BUILDING_MILITARY_BASE"].ID))
then
bIsCanAirliftTo = true;
break;
end
elseif pPlot and pPlot:GetNumUnits() > 0 then
for i = 0, pPlot:GetNumUnits() - 1 do
pCarrUnit = pPlot:GetUnit(i)
if pCarrUnit:GetOwner() == iPlayer and pCarrUnit:IsHoveringUnit() then
bIsCanAirliftTo = true;
break;
end
end
if bIsCanAirliftTo then
break;
end
end
end
end
return bIsCanAirliftTo;
end
GameEvents.CanAirliftTo.Add(OnCanAirliftTo)