print("sovereign vs godric");

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

-- looking for dead catapult --

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(15);
end

function Start()
    EnableAutoFinish(nil);
    sleep(20);
    SummonCreature(DEFENDER, 26, 5 + d * 2, 12, 3);
    sleep(20);
    SummonCreature(DEFENDER, 28, 8 + d * 3, 12, 8);
    sleep(20);
    SummonCreature(DEFENDER, 26, 5 + d * 2, 12, 12);
    sleep(20);
    SummonCreature(DEFENDER, 23, 35 + d * 5, 13, 5);
    sleep(20);
    SummonCreature(DEFENDER, 22, 25 + d * 5, 13, 10);
    sleep(20);
    EnableCinematicCamera(not nil);
end

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

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