-- ScourgeRacial
-- Author: Michael
-- DateCreated: 8/5/2013 11:16:42 AM
--------------------------------------------------------------

print("Now loading Scourge Racial ability script");

local uGHOUL = GameInfoTypes.UNIT_GHOUL
-- EndCombatSim
-- SerialEventUnitDestroyed
GameEvents.EndCombatSim.add(

function(attackingPlayer, attackingUnit, defendingUnit)

local pPlayer = Players[attackingPlayer];
local attackUnit = attackingUnit;
local defendUnit = defendingUnit;

--Checking that attacking player is scourge
 if(pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_SCOURGE) then
  --Check that attacking unit is a ghoul.
  if(attackUnit:GetUnitType() == uGHOUL) then
   --Check if defending unit is dead.
   if(defendUnit:IsDead()) then
    --Spawn new unit on loser.
    local iRand = math.random(1, 100)
    if (iRand <33 ) then -- GHOUL
     local pNewUnit = attackPlayer:InitUnit(GameInfoTypes["UNIT_GHOUL"], defendUnit:GetX(), defendUnit:GetY());
     Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "A Ghoul arises from your foe!", "Victory");
    else --UNIT TYPE
     if(iRand < 66) then
      local pNewUnit = attackPlayer:InitUnit(GameInfoTypes[defendUnit:GetUnitType], defendUnit:GetX(), defendUnit:GetY());
      Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "Your foe rises from death!", "Victory");
     else --Zombie (NOT YET IMPLEMENTED
      local pNewUnit = attackPlayer:InitUnit(GameInfoTypes["UNIT_GHOUL"], defendUnit:GetX(), defendUnit:GetY());
         Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "A Ghoul arises from your foe!", "Victory");
     end
    end
   end
  end
 end
end
)