print("sovereign vs raelag");

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

-- monsters: death knights, archdevils and infernal succubus

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

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

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