{$I HKS_SaveCData.script}

{.$DEFINE FEED}
{$DEFINE RES_HOUSES}
{.$DEFINE PATROL}
{.$DEFINE DIFFICULTY}
{.$DEFINE REBUILD}
{.$DEFINE ANIMATION}

{$I HKS_Functions.script}

var EVENT_TakeOverTheVillage : KD_Event;

procedure TakeOverTheVillage;
var I : Integer;
begin
	ChangeHousesOwner(S.PlayerGetAllHouses(17), PLAYER, false, true);
	//AddUnitsToPlayer([PLAYER], true);
	for I := 0 to 4 do
		A.GiveUnit(PLAYER, 0, 65,77, 4);
end;

procedure OnTick;
begin

	If GT mod 10 <> 0 then 
		Exit;
	
	If EVENT_TakeOverTheVillage.Finished then 
	begin
		If GT = EVENT_TakeOverTheVillage.aFinTime + 4200 then
		begin
			A.GiveGroup(1, 22, 9, 8, 3, 9, 3);
			A.GiveGroup(1, 17, 31, 12, 3, 12, 4);
			A.GiveGroup(1, 16, 8, 20, 3, 15, 5);
		end else
		If GT > EVENT_TakeOverTheVillage.aFinTime + 4200 then
			If S.StatArmyCount(1) = 0 then 
				A.PlayerWin([0], true);
			
		Exit;
	end;
	If S.StatArmyCount(17) = 0 then 
		FinEv(EVENT_TakeOverTheVillage);
end;
	
	
procedure OnMissionStart;
begin
	EvCreate(EVENT_TakeOverTheVillage, '<$1>', '<$2>');
	EVENT_TakeOverTheVillage.DoAtEnd := @TakeOverTheVillage;
end;