print("sovereign vs zehir");

d = GetGameVar("C6M5_diff") + 0;
sovereign = 0

function FindAttackerCatapult()
	local machines = GetAttackerWarMachines()
		for index,machine in machines do
			if GetWarMachineType(machine) == WAR_MACHINE_CATAPULT then
				return machine
			end
		end
	return nil
end

catapult = FindAttackerCatapult()

function AttackerWarMachineDeath(unitName)
	if unitName == catapult then
		Finish(DEFENDER)
	end
end

shield = GetDefenderBuilding(BUILDING_MAGIC_WALL)

function DefenderBuildingDeath(buildingName)
	if buildingName == shield then
		sleep(10);
		Finish(ATTACKER)
	end
end

function Prepare()
    EnableCinematicCamera(nil);
    sleep(1);
	AddCreature(DEFENDER, 41, 7 + d * 3, 12, 3);
    sleep(1);
    AddCreature(DEFENDER, 42, 8 + d * 4, 12, 8);
    sleep(1);
    AddCreature(DEFENDER, 41, 7 + d * 3, 12, 12);
end;

-- monsters: summon 2 ghosts, infernal succubus and balors

function Start()
    EnableCinematicCamera(nil);
    EnableAutoFinish(nil);
    sleep(20);
    SummonCreature(DEFENDER, 23, 45 + d * 5, 13, 6);
    sleep(2);
    SummonCreature(DEFENDER, 85, 40 + d * 10, 13, 3);
    sleep(2);
    SummonCreature(DEFENDER, 22, 50 + d * 5, 13, 10);
    sleep(5);
    EnableCinematicCamera(not nil);
end

function DefenderHeroMove(heroName)
    UnitCastGlobalSpell(GetDefenderHero(), 239);
    SummonCreature(DEFENDER, 23, 10 + d * 5, 13, 8);
    return not nil
end

function AttackerCreatureDeath()
    local attackers = GetAttackerCreatures();
    if (length(attackers) == 0) then Finish(DEFENDER) end;
end