{$I PTL04Attacks.script}
{$I PTLRebuild.script}
{$I PTLDefence.script}

{$EVENT evtMissionStart:OnMissionStart__Mission4}
{$EVENT evtTick:OnTick__Mission4}

var newDefencePositionsPlaced: boolean;

procedure OnMissionStart__Mission4;
var aiPlayer1RedZone: Rectangle;
var aiPlayer2RedZone: Rectangle;
var aiPlayer3RedZone: Rectangle;
var aiPlayer4RedZone: Rectangle;
var aiPlayer5RedZone: Rectangle;
begin
	Actions.Log('MISSION 4 BEGIN');
	Actions.LogLinesMaxCnt(10000);
	
	Actions.ShowMsg(0, '<$0>');
	Actions.HouseAllowAllyToSelectAll(1, true);
	newDefencePositionsPlaced := false;
	FillAlliancesPerPlayerIdMap();
		
	aiPlayer1RedZone.topLeftCorner.X := 31;
	aiPlayer1RedZone.topLeftCorner.Y := 101;
	aiPlayer1RedZone.bottomRightCorner.X := 66;
	aiPlayer1RedZone.bottomRightCorner.Y := 120;
	
	aiPlayer2RedZone.topLeftCorner.X := 137;
	aiPlayer2RedZone.topLeftCorner.Y := 190;
	aiPlayer2RedZone.bottomRightCorner.X := 182; 
	aiPlayer2RedZone.bottomRightCorner.Y := 223;
	
	
	aiPlayer3RedZone.topLeftCorner.X := 9;
	aiPlayer3RedZone.topLeftCorner.Y := 5;
	aiPlayer3RedZone.bottomRightCorner.X := 49; 
	aiPlayer3RedZone.bottomRightCorner.Y := 31;
	
	aiPlayer4RedZone.topLeftCorner.X := 126;
	aiPlayer4RedZone.topLeftCorner.Y := 14;
	aiPlayer4RedZone.bottomRightCorner.X := 166; 
	aiPlayer4RedZone.bottomRightCorner.Y := 39;
	
	aiPlayer5RedZone.topLeftCorner.X := 171;
	aiPlayer5RedZone.topLeftCorner.Y := 29;
	aiPlayer5RedZone.bottomRightCorner.X := 224; 
	aiPlayer5RedZone.bottomRightCorner.Y := 75;
	
	aiPlayersRedZonesArray := AddElementToRectangleArray(aiPlayersRedZonesArray, aiPlayer1RedZone);
	aiPlayersRedZonesArray := AddElementToRectangleArray(aiPlayersRedZonesArray, aiPlayer2RedZone);
	aiPlayersRedZonesArray := AddElementToRectangleArray(aiPlayersRedZonesArray, aiPlayer3RedZone);		
	aiPlayersRedZonesArray := AddElementToRectangleArray(aiPlayersRedZonesArray, aiPlayer4RedZone);		
	aiPlayersRedZonesArray := AddElementToRectangleArray(aiPlayersRedZonesArray, aiPlayer5RedZone);		
	
end;	

procedure OnTick__Mission4;
var defencePosition: TKMDefencePositionInfo;
begin
	if States.GameTime mod 100 = 0 then
		begin
				Actions.HouseAllowAllyToSelectAll(1, true);
				Actions.HouseAllowAllyToSelectAll(2, true);
		end;
end;