print("sovereign vs heam");

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(10);
    SummonCreature(DEFENDER, 89, 5 + d * 5, 12, 3);
    sleep(10);
    SummonCreature(DEFENDER, 42, 4 + d * 4, 12, 8);
    sleep(10);
    SummonCreature(DEFENDER, 89, 5 + d * 5, 12, 12);
    sleep(10);
end

function Start()
    EnableAutoFinish(nil);
    SummonCreature(DEFENDER, 21, 40 + d * 10, 13, 5);
    sleep(2);
    SummonCreature(DEFENDER, 24, 55 + d * 5, 13, 10);
    sleep(5);
    EnableCinematicCamera(not nil);
end

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

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


