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

{$I HKS_Functions.script}
{$I HKS_SaveCData.script}

var EVENT_Fisherman, EVENT_Animation : KD_Event;
	PlayersToDefeat : array of Integer;
	
procedure MakeHeroWalk;
begin

	with aHeros[0] do 
	begin
		If GT >= 200 then 
		begin
			A.GroupOrderWalk(aGroupID, 76, 187, 5)
			Exit;
		end;
		If not S.UnitIdle(ID) then 
			Exit;
		
		If Pos = U.Kmpoint(70, 184) then 
			A.GroupOrderWalk(aGroupID, 81, 193, 5)
		else
			A.GroupOrderWalk(aGroupID, 70, 184, 1);
	end;
end;
procedure CheckDefeat;
var I : Integer;
	canWin : Boolean;
begin
	canWin := true;
	for I := 0 to high(PlayersToDefeat) do 
		If (S.StatArmyCount(PlayersToDefeat[I]) > 0) or (S.StatHouseMultipleTypesCount(PlayersToDefeat[I], [11, 13, 21]) > 0) then 
			canWin := false;
	If canWin then 
		FinEv(EVENT_Animation);
		
end;

procedure OnTick;
begin
	OnTickHero;
	
	//if States.GameTime = 1 then        
	//	Actions.ShowMsg (-1, '<$1>');  
	If GT mod 10 <> 0 then 
		Exit;
	If not EVENT_Animation.Finished then 
		If GT > 300 then 
			CheckDefeat;
	
	If GT <= 200 then 
		MakeHeroWalk;

	If GT = 240 then 	
	begin
		A.GameSpeedChangeAllowed(true);
		A.CinematicEnd(PLAYER);
	end;
	
	with EVENT_Animation do 
		If Finished then 
		begin
			If GT = aFinTime + 10 then 
			begin
				A.PlayOggFadeMusic(PLAYER, 'pathfinder', 1)
				A.CinematicStart(PLAYER);
				A.CinematicPanTo(PLAYER, 62, 198, 350);
				A.GameSpeed(1);
				A.GameSpeedChangeAllowed(false);
				
				AddOvMessage(10, aFinTime + 10);
                   
				AddOvMessage(11, 60);							
				AddOvMessage(12, 120);			
				AddOvMessage(13, 180);		
				AddOvMessage(14, 270);	
				AddOvMessage(15, 330);                   
				AddOvMessage(16, 390);                     
				AddOvMessage(17, 450);                    
				AddOvMessage(18, 520);                 
				AddOvMessage(19, 570);                      
				AddOvMessage(20, 620);                
				AddOvMessage(21, 690);
				
			end;
			
			If GT = aFinTime + 360 then 
				A.CinematicPanTo(PLAYER, 62, 38, 350);
			
			If GT = aFinTime + 750 then 
				A.CinematicEnd(PLAYER);
				
			If GT = aFinTime + 800 then 
				A.playerWin([PLAYER], true);
		end;	
		
		
	If EVENT_Fisherman.Finished then 
		Exit;
	If aHeros[0].Pos = U.KMPoint(2, 146) then 
	begin
		FinEv(EVENT_Fisherman);
		SetHeroStats(42, 34, 493, 4, 30, 6, hcMichel);
		aHeros[0].RegPoints := 2;
		aHeros[0].Name := '[$00D1FF]King Michel';
	end;
end;

procedure OnMissionStart;
begin
	A.CinematicStart(PLAYER);
	A.GameSpeedChangeAllowed(false);
	
	EvCreate(EVENT_Fisherman, 'Fiherman', '<$8>');
	EvCreate(EVENT_Animation, 'Animation', '');
	
	AddHero(S.GroupAt(70,184));
	SetHeroStats(33, 32, 76, 6, 25, 4, hcMichel);
	aHeros[0].FeedHero := true;
	A.PlayOGGFadeMusic(PLAYER, 'crusader', 1);
	
	PlayersToDefeat := [1, 2, 6, 7, 8, 9, 10, 12, 14, 15, 16, 17 ];
	
	
	AddOvMessage(1{ID wiadomości}, 10{czas});
	AddOvMessage(2, 50);
	AddOvMessage(3, 110);
	AddOvMessage(4, 170);
	
end;
