local iBarbarianPlayerID = 63
local iDummyUnit = GameInfoTypes["UNIT_DUMMY_UNIT"]
local sDummyUnitDomain = GameInfo.Units[iDummyUnit].Domain
local bRequiresLand = (sDummyUnitDomain == "DOMAIN_LAND")
local bRequiresSea = (sDummyUnitDomain == "DOMAIN_SEA")
local bRequiresAir = (sDummyUnitDomain == "DOMAIN_AIR")
local Description = Locale.ConvertTextKey("TXT_KEY_STRING")
local DescriptionShort = Locale.ConvertTextKey("TXT_KEY_STRING_SHORT")
function ConvertToBarbarian(PlayerID, UnitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState)
if PlayerID ~= iBarbarianPlayerID then
local pPlayer = Players[PlayerID]
local pOldUnit = pPlayer:GetUnitByID(UnitID)
if(pOldUnit == nil or
pOldUnit:IsDead()) then
return
end
local iUnitType = pOldUnit:GetUnitType()
if iUnitType == iDummyUnit then
local pPlot = pOldUnit:GetPlot()
local iSpawnX, iSpawnY = pPlot:GetX(), pPlot:GetY()
local bProperSpawnPlotFound = false
if pPlot:IsCity() or (pPlot:GetNumUnits() > 1) then
for direction = 0, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
local pAdjacentPlot = Map.PlotDirection(pPlot:GetX(), pPlot:GetY(), direction)
if pAdjacentPlot and not pAdjacentPlot:IsUnit() then
if bRequiresLand then
if (not pAdjacentPlot:IsCity()) and (not pAdjacentPlot:IsLake()) and (not pAdjacentPlot:IsWater()) and (not pAdjacentPlot:IsMountain()) then
iSpawnX, iSpawnY = pAdjacentPlot:GetX(), pAdjacentPlot:GetY()
bProperSpawnPlotFound = true
break
end
elseif bRequiresSea then
if (not pAdjacentPlot:IsLake()) and (pAdjacentPlot:IsWater()) then
iSpawnX, iSpawnY = pAdjacentPlot:GetX(), pAdjacentPlot:GetY()
bProperSpawnPlotFound = true
break
end
end
end
end
else
if not bRequiresAir then
bProperSpawnPlotFound = true
end
end
if bProperSpawnPlotFound then
local pBarbPlayer = Players[iBarbarianPlayerID]
local pNewUnit = pBarbPlayer:InitUnit(iUnitType, iSpawnX, iSpawnY)
pNewUnit:Convert(pOldUnit)
if pOldUnit then
pOldUnit:Kill()
end
if pPlayer:IsHuman() then
pPlayer:AddNotification(NotificationTypes["NOTIFICATION_BARBARIAN"], Description, DescriptionShort)
Events.AudioPlay2DSound("AS2D_EVENT_NOTIFICATION_VERY_BAD")
end
end
end
end
end
Events.SerialEventUnitCreated.Add(ConvertToBarbarian)