var MessageSend : Boolean;
const BARBARIANS_ATTACK = 51600;
{$I HKS_Functions.script}
{$I HKS_ResHouses.script}

{$I HKS_SaveCData.script}

procedure AddBarbariansGroups(aMode : Integer);
var I : Integer;
begin
	If aMode in [-1, 0] then 
		for I := -1 to 1 do 		
			AddGBG(  AddGBG //count of 	'( AddGBG'	must be the same as the number of groups you want to add behind first group
			( A.GiveGroup(9, 23, 57 + ( I * 6)+ S.KaMRandomI(5), 14 + S.KaMRandomI(4), 4, 15, 5)//first line
			, 9, 17, 9, 3, 1  )//sec line
			, 9, 15, 12, 4, 1 );
		
	If aMode in [-1, 1] then 
	begin
		AddGBG //count of 	'( AddGBG'	must be the same as the number of groups you want to add behind first group
		( A.GiveGroup(10, 23, 153, 92, 6, 15, 5)//first line
		, 10, 19, 9, 3, 1  );
		
		AddGBG(AddGBG
		( A.GiveGroup(10, 23, 152, 103, 5, 12, 4)//first line
		, 10, 14, 9, 3, 1  )
		, 10, 17, 15, 5, 1  );
		
		A.AIAttackAdd(9, true, 0, 1, 0, 0, 0, 0, true, attClosestBuildingFromStartPos, U.KMPoint(0, 0));
		A.AIAttackAdd(10, true, 0, 1, 0, 0, 0, 0, true, attClosestBuildingFromStartPos, U.KMPoint(0, 0));
		
	end;
end;
Procedure OnTick;
var aUnit : KD_UnitStats;
begin
  if States.GameTime = 10 then
	Actions.ShowMsg(0, '<$1>');
  if States.GameTime = 900 then
	Actions.ShowMsg(0, '<$2>');
  if States.GameTime = 51600 then
	Actions.ShowMsg(0, '<$4>');
	
	//If Gt = 600 then 
	//	ChangeHousesOwner(S.PlayerGetAllHouses(7), 0, true, true);
	
	If S.GameTime mod 10 = 0 then 
	begin
	
		If not MessageSend then 
			If SetUnit(S.UnitAt(10,4),aUnit) or SetUnit(S.UnitAt(10,5),aUnit) then
				If aUnit.Owner = 0 then 
				begin
					MessageSend := true;
					A.ShowMsg(0, '<$3>');//do zmienienia przez kamrata
				end;
	
	end;
	If GT = BARBARIANS_ATTACK then 
		AddBarbariansGroups(-1);
		
	If GT = BARBARIANS_ATTACK + 200 then 
		AddBarbariansGroups(-1);
		
	If GT = BARBARIANS_ATTACK + 300 then 
		AddBarbariansGroups(1);
	If GT = BARBARIANS_ATTACK + 600 then 
		AddBarbariansGroups(0);
	If GT = BARBARIANS_ATTACK + 800 then 
		AddBarbariansGroups(1);
end;