<?xml version="1.0" standalone="yes" ?> 
<scenario>
	<difficulty value="3"/>
	<players>
		<player control="human" faction="pirates" team="1"/>
		<player control="cpu" faction="pirates" team="1"/>
		<player control="cpu" faction="pirates" team="2"/>
		<player control="closed"/>		
	</players>
	<map value="The_sea2"/>
	<tileset value="sea"/>
	<tech-tree value="magitech"/>
	<default-resources value="false"/>
	<default-units value="false"/>
	<default-victory-conditions value="false"/>
	<scripts>
		<startup>
			--disable AI
			disableAi(1)
			disableAi(2)
			disableAi(3)
			
			--allied units
			createUnit('docks', 0, startLocation(2))
			dockUnit= lastCreatedUnit()
			giveResource('gold', 0, 500); 
			giveResource('wood', 0, 500);
			giveResource('stone', 0, 500);
			giveResource('food', 0, 50);
			createUnit('worker', 0, startLocation(2))
			createUnit('worker', 0, startLocation(2))
			createUnit('worker', 0, startLocation(2))
			createUnit('captain', 1, startLocation(2))
			captainUnit= lastCreatedUnit()
			
			--player units
			for i=1, 1 do
				createUnit('pirate_ship', 0, startLocation(0))
			end	
			
			--create enemy attackers
			for i=1, 1 do
				createUnit('cargo_ship', 2, startLocation(1))
			        ship1Unit= lastCreatedUnit()
				givePositionCommand(ship1Unit(), 'attack', startLocation(2))	
			end	
			for i=1, 1 do
				createUnit('cargo_ship', 2, startLocation(1))
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))	
			end
			for i=1, 1 do
				createUnit('cargo_ship', 2, startLocation(1))
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))	
			end
			
			--objectives
			objective='ObjectiveBoat'
			showMessage('start', 'captain')
			setDisplayText('ObjectiveBoat')
			
		</startup>

		<unitDied>
			--check for dock dying
			if lastDeadUnit()==dockUnit then
				clearDisplayText()
				setPlayerAsWinner(3)				
				endGame()
			end

			if objective=='ObjectiveBoat' and unitCount(0)==0 then

			for i=1, 4 do
				createUnit('cargo_ship', 2, startLocation(1))
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))	
			end

			objective='ObjectiveBoat2'
			showMessage('boat', 'captain')
			setDisplayText('ObjectiveBoat2')

			if objective=='bjectiveBoat2' and unitCount(0)==0 then
				clearDisplayText()
				setPlayerAsWinner(1)
				endGame()
			end

		</unitDied>	
		
		<unitDied>
			--check for dock dying
			if lastDeadUnit()==dockUnit then
			
			--check for first village destroyed
			if lastDeadUnit()==ship1Unit then

			for i=1, 1 do
				createUnit('cargo_ship', 2, startLocation(1))
			        ship2Unit= lastCreatedUnit()
				givePositionCommand(ship2Unit(), 'attack', startLocation(2))	
			end

			for i=1, 3 do
				createUnit('cargo_ship', 2, startLocation(1))
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))	
			end	

			--check for second village destroyed
			if lastDeadUnit()==ship2Unit then
				clearDisplayText()
				setPlayerAsWinner(0)
				setPlayerAsWinner(1)				
				endGame()
			end
			
		</unitDied>		
	</scripts>		
</scenario>
