<?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))
			summonerUnit= lastCreatedUnit()
			<!--setCameraPosition(unitPosition(summonerUnit))-->
			<!--givePositionCommand(summonerUnit, 'attack', startLocation(1))-->
			
			--player units
			for i=1, 1 do
				createUnit('pirate_ship', 0, startLocation(0))
			end

			<!--enemy units village
			createUnit('library', 2, startLocation(1))	
			libraryUnit= lastCreatedUnit()
			createUnit('golem', 2, startLocation(1))-->	
			
			--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>
		
		<unitCreated>		
			--send units attack location 0
			if objective=='destroy_north_east_village' and unitFaction(lastCreatedUnit())==1 then
				firstArmorUnit=lastCreatedUnit()
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(0))
				givePositionCommand(summonerUnit, 'attack', startLocation(0))
				
				for i=1, 2 do
					createUnit('guard', 3, startLocation(0))
					givePositionCommand(lastCreatedUnit(), 'attack', startLocation(1))	
				end				
			end	
			
			--send units attack location 3
			if objective=='destroy_south_east_village' and unitFaction(lastCreatedUnit())==1 then
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(3))
				givePositionCommand(firstArmorUnit, 'attack', startLocation(3))
				givePositionCommand(summonerUnit, 'attack', startLocation(3))
				
				--create enemy attackers
				createUnit('ornithopter', 3, startLocation(3))
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(0))	
				createUnit('archmage', 2, startLocation(3))
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(0))	
				createUnit('battlemage', 2, startLocation(3))
				givePositionCommand(lastCreatedUnit(), 'attack', startLocation(0))					
			end				
		</unitCreated>	
		
		<unitDied>
			--check for dock dying
			if lastDeadUnit()==dockUnit then
				clearDisplayText()
				setPlayerAsWinner(3)				
				endGame()
			end
			
			--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>
