{$I HKS_Functions.script}


{$I HKS_SaveCData.script}

var CastleVisited, //map is revealed or not
	MinersVisited //
	: Boolean;
	Time_CastleVisited, aGhost : Integer;

procedure CheckTheCastle;
var aUnit : KD_UnitStats;
begin
	CastleVisited := (SetUnit(S.UnitAt(19,61), aUnit)or SetUnit(S.UnitAt(19,62), aUnit)) and (aUnit.Owner = 0);
	If CastleVisited then
	begin
		A.FogRevealAll(0);
		Time_CastleVisited := GT;
		aGhost := A.GiveUnit(11, 0, 21, 61, 6);
		A.UnitOrderWalk(aGhost, 19, 61);
		Actions.OverlayTextSetFormatted(-1, '4', []);
		 Actions.OverlayTextAppendFormatted(-1, '<$4>', []);
	end;
end;

procedure CheckTheMiners;
var aUnit : KD_UnitStats;
	I : integer;
begin
	for I := 0 to 3 do 
	begin
		MinersVisited := SetUnit(S.UnitAt(38,138 + I), aUnit) and (aUnit.Owner = 0);
		If MinersVisited then
		begin
			Actions.OverlayTextSetFormatted(-1, '5', []);
		 Actions.OverlayTextAppendFormatted(-1, '<$5>', []);
			Break;
			
		end;
	end;
	If not MinersVisited then 
		for I := 0 to 5 do 
		begin
			MinersVisited := SetUnit(S.UnitAt(6 - I,123 + I), aUnit) and (aUnit.Owner = 0);
			If MinersVisited then
			begin
				Actions.OverlayTextSetFormatted(-1, '<$5>', []);
		 Actions.OverlayTextAppendFormatted(-1, '<$5>', []);
				Break;
			
			end;
			
		end;
		
end;



procedure OnTick;
begin
	If GT mod 10 = 0 then //King Dyron things
	begin
		If not CastleVisited then
			CheckTheCastle;
		If not MinersVisited then
			CheckTheMiners;
		If GT = Time_CastleVisited + 20 then 
			A.UnitKill(aGhost, true);
	end;
	
	
	If States.GameTime = 10 then
	begin
		 Actions.OverlayTextSetFormatted(-1, '1', []);
		 Actions.OverlayTextAppendFormatted(-1, '<$1>', []);
		 A.PlayOgg(0, '01', 1);
	end;
	 If States.GameTime = 113700 then
	begin
	   Actions.OverlayTextSetFormatted(-1, '2', []);
	   Actions.OverlayTextAppendFormatted(-1, '<$2>', []);
	   A.PlayOgg(0, '01', 1);
	end;
	 If States.GameTime = 600 then
	begin
	   Actions.OverlayTextSetFormatted(-1, '3', []);
	   Actions.OverlayTextAppendFormatted(-1, '<$3>', []);
	   A.PlayOgg(0, '01', 1);
	end;
end;
