<?xml version="1.0" standalone="yes" ?> 
<scenario>
<difficulty value="4"/>
	<players>
		<player control="human" faction="player" team="1"/> <!-- 0 -->
		<player control="cpu" faction="computer" team="1"/> <!-- 1 -->
		<player control="cpu" faction="computer" team="2"/> <!-- 2 -->
		<player control="cpu" faction="computer" team="2"/> <!-- 3 -->	
		<player control="cpu" faction="computer" team="2"/> <!-- 4 -->	
		<player control="cpu" faction="computer" team="2"/> <!-- 5 -->	
		<player control="cpu" faction="computer" team="2"/> <!-- 6 -->	
		<player control="cpu" faction="computer" team="2"/> <!-- 7 -->	
	</players>
	<map value="map_1"/>
	<tileset value="city"/>
	<tech-tree value="data"/>
	<default-resources value="false"/>	
	<default-units value="false"/>
	<default-victory-conditions value="false"/>
	<fog-of-war value="false"/>
	<view-map-at-end-game value="false"/>
	<scripts>
		<startup>
			--disable AI
			disableAi(1)
			disableAi(2)
			disableAi(3)
			timer_event1=nil
			ai_guard_1=nil
			ai_guard_2=nil
			ai_guard_3=nil

			
			--player units
			createUnit('sam', 0, startLocation(3))	
			samUnit= lastCreatedUnit()
<!--
			createUnit('gunner', 0, startLocation(3))	
			bobUnit= lastCreatedUnit()

			createUnit('gunner', 0, startLocation(3))	
			jimUnit= lastCreatedUnit()
-->
			setCameraPosition(unitPosition(samUnit))
<!--
			givePositionCommand(samUnit, 'attack', startLocation(2))
	-->
			

			createUnit('barbed_fence', 2, {startLocation(5)[1] - 39, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 37, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 35, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 33, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 31, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 29, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 27, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 25, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 23, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 21, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 19, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 17, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 15, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 13, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 11, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 9, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 7, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 5, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 3, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] - 1, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 1, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 3, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 5, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 7, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 17, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 19, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 21, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 23, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 25, startLocation(0)[2] + 24})
			createUnit('barbed_fence', 2, {startLocation(5)[1] + 27, startLocation(0)[2] + 24})


			--create enemy blue
			createUnit('hanger', 2, startLocation(1))
			createUnit('solder', 2, {startLocation(1)[1] - 3, startLocation(1)[2] + 3})
			hgUnit= lastCreatedUnit()
			createUnit('solder', 2, {startLocation(1)[1] + 25, startLocation(1)[2] - 25})
			smokeUnit= lastCreatedUnit()
			createUnit('helicopter', 2, {startLocation(1)[1] + 5, startLocation(1)[2] + 6})
			copUnit= lastCreatedUnit()
			createUnit('landing_pad', 2, {startLocation(1)[1] - 70, startLocation(1)[2] + 60})
			land2Unit= lastCreatedUnit()
			createUnit('building___', 2, {startLocation(1)[1] - 57, startLocation(1)[2] + 43})

			--create enemy pink
			createUnit('building____', 2, {startLocation(7)[1] + 2, startLocation(7)[2] + 2})
			createUnit('machine_gun_turret', 2, {startLocation(7)[1] + 5, startLocation(7)[2] + 0})
			createUnit('tank', 2, {startLocation(7)[1] + 5, startLocation(7)[2] - 6})

			--create enemy light blue
			createUnit('solder', 5, {startLocation(5)[1] - 15, startLocation(5)[2] + 15})
			ai1Unit= lastCreatedUnit()
			createUnit('solder', 5, {startLocation(5)[1] - 25, startLocation(5)[2] + 10})
			ai2Unit= lastCreatedUnit()
			createUnit('solder', 5, {startLocation(5)[1] - 10, startLocation(5)[2] + 20})
			ai3Unit= lastCreatedUnit()
			createUnit('landing_pad', 2, {startLocation(5)[1] + 0, startLocation(5)[2] - 8})
			landUnit= lastCreatedUnit()
			createUnit('machine_gun_turret', 2, {startLocation(5)[1] + 15, startLocation(5)[2] + 24})
			createUnit('tank', 2, {startLocation(5)[1] + 12, startLocation(5)[2] + 25})
			t3Unit= lastCreatedUnit()
			giveAttackStoppedCommand(t3Unit,'hold_position',1)

			-- creat drivable tank
			createUnit('tank__', 2, {startLocation(5)[1] + 34, startLocation(5)[2] + 12})
			tankUnit= lastCreatedUnit()

			createUnit('prisoner_quarters', 2, {startLocation(5)[1] - 47, startLocation(5)[2] - 20})
			prissonUnit= lastCreatedUnit()

			--create enemy white
			createUnit('building_', 2, startLocation(4))
			frUnit= lastCreatedUnit()
	
			createUnit('tank', 2, startLocation(6))	
			t1Unit= lastCreatedUnit()

			createUnit('tank', 2, startLocation(6))	
			t2Unit= lastCreatedUnit()

			--create enemy red
			createUnit('guard_tower', 2, {startLocation(0)[1] + 10, startLocation(0)[2] + 76})
			createUnit('guard_tower', 2, {startLocation(0)[1] - 26, startLocation(0)[2] + 10})
			createUnit('solder', 2, startLocation(0))	
			g2Unit= lastCreatedUnit()

			createUnit('solder', 2, startLocation(0))	
			g3Unit= lastCreatedUnit()

			createUnit('building', 2, {startLocation(0)[1] + 5, startLocation(0)[2] - 5})
			createUnit('building___', 2, {startLocation(0)[1] + 0, startLocation(0)[2] + 6})
			createUnit('building__', 2, {startLocation(0)[1] + 8, startLocation(0)[2] + 10})
			createUnit('radio_tower', 2, {startLocation(0)[1] - 8, startLocation(0)[2] - 8})
			towerUnit= lastCreatedUnit()
			createUnit ( "machine_gun_man", 2, {startLocation(0)[1] - 8, startLocation(0)[2] + 10})
			giveAttackStoppedCommand(lastCreatedUnit(),'hold_position',1)

			--create enemy green
			createUnit('building', 2, startLocation(2))	

			createUnit ( "machine_gun_man", 2, {startLocation(2)[1] - 4, startLocation(2)[2] + 5})
			g1Unit= lastCreatedUnit()

			<!--giveAttackCommand(g1Unit, samUnit)-->

			
			--objectives
			objective='destry_building'
			showMessage('start', 'comander')
			showMessage('start2', 'comander')
			showMessage('start3', 'comander')
			setDisplayText('destry_building')
			togglePauseGame(1);
			showMessage('pause', 'm')

    			 cell_event1 = registerCellTriggerEventForUnitToUnit(samUnit,copUnit)

    			 cell_event4 = registerCellTriggerEventForUnitToUnit(samUnit,frUnit)

			timer_gtp= startTimerEvent ()

			
		</startup>

		<cellTriggerEvent>   
		       if triggeredCellEventId() == cell_event1 then 

			morphToUnit(samUnit,'_',1)
<!--			createUnit('helicopter', 0, {startLocation(1)[1] + 5, startLocation(1)[2] + 6})
			cop2Unit= lastCreatedUnit()-->
			destroyUnit(copUnit);

			--objectives
			objective='get_in'
			showMessage('mis4_1', 'comander')
			showMessage('mis4_2', 'comander')
			clearDisplayText()
			setDisplayText('get_in')
			togglePauseGame(1);
			showMessage('pause', 'm')
 		         unregisterCellTriggerEvent(cell_event1)

    			 cell_event2 = registerCellTriggerEventForUnitToUnit(samUnit,landUnit)
    			 cell_event3 = registerCellTriggerEventForUnitToUnit(samUnit,land2Unit)

		       end

		       if triggeredCellEventId() == cell_event2 then 

			createUnit('helicopter', 2, {startLocation(5)[1] + 0, startLocation(5)[2] - 8})
			morphToUnit(samUnit,'_',1)

			--objectives
			objective='find_ph'
			showMessage('mis5_1', 'comander')
			showMessage('mis5_2', 'comander')
			clearDisplayText()
			setDisplayText('find_ph')
			togglePauseGame(1);
			showMessage('pause', 'm')
 		         unregisterCellTriggerEvent(cell_event2)

		       end

		       if triggeredCellEventId() == cell_event3 then 

			createUnit('helicopter', 2, {startLocation(1)[1] - 70, startLocation(1)[2] + 60})
			morphToUnit(samUnit,'_',1)

			for i=1, 6 do
				createUnit('solder', 2, {startLocation(1)[1] - 57, startLocation(1)[2] + 43})
				givePositionCommand(lastCreatedUnit(), 'attack',  {startLocation(1)[1] - 75, startLocation(1)[2] + 65})
			end

			--objectives
			objective='stuck'
			showMessage('s', 'comander')
			clearDisplayText()
			setDisplayText('stuck')
			togglePauseGame(1);
			showMessage('pause', 'm')
 		         unregisterCellTriggerEvent(cell_event3)

		       end

		       if triggeredCellEventId() == cell_eventtank then 

			destroyUnit(tank2Unit);
			morphToUnit(samUnit,'__',1)
			showMessage('great', 'comander')
			togglePauseGame(1);

			timer_event2= startTimerEvent ()

 		         unregisterCellTriggerEvent(cell_eventtank)

		       end

		       if triggeredCellEventId() == cell_event_win then 

				clearDisplayText()
				setPlayerAsWinner(0)
				setPlayerAsWinner(1)				
				endGame()

 		         unregisterCellTriggerEvent(cell_event_win)

		       end

		</cellTriggerEvent>



		<timerTriggerEvent>

 		  if triggeredTimerEventId() == timer_event1 then
  		    if timerEventSecondsElapsed(triggeredTimerEventId()) >= 1 then
				<!--givePositionCommand(siUnit, samUnit)-->
		moveToUnit(siUnit, samUnit)
<!--  		        stopTimerEvent(timer_event1)
 		         unregisterCellTriggerEvent(cell_event1)-->
 		     end
 		  end

 		  if triggeredTimerEventId() == timer_event2 then
  		    if timerEventSecondsElapsed(triggeredTimerEventId()) >= 60 then

			print('Test #1')

			morphToUnit(samUnit,'___',1)
			showMessage('gasrunout', 'comander')

			print('Test #2')

			run= unitPosition ( samUnit )

			print('Test #3')

			createUnit('tank_', 2, run)

			print('Test #4')

 		        stopTimerEvent(timer_event2)

			print('Test #5')
		  	stopTimerEvent(timer_event2)
 		     end
 		  end


 		  if triggeredTimerEventId() == timer_gtp then
  		    if timerEventSecondsElapsed(triggeredTimerEventId()) >= 60 then
			if ai1Unit ~= nil then
				givePositionCommand(ai1Unit, 'attack', startLocation(7))
			end	
			if ai2Unit ~= nil then
				givePositionCommand(ai2Unit, 'attack', startLocation(5))
			end	
			if ai3Unit ~= nil then
				givePositionCommand(ai3Unit, 'attack', {startLocation(7)[1] + 5, startLocation(7)[2] + 20})
			end	


		        stopTimerEvent(timer_gtp)
			timer_gtp= startTimerEvent ()
			end
 		  end

		</timerTriggerEvent>



		<unitDied>
			--check for g1 dying
			if lastDeadUnit()==g1Unit then

			givePositionCommand(g2Unit, 'attack', startLocation(2))
			givePositionCommand(g3Unit, 'attack', startLocation(2))


			--objectives
			objective='destry_tower'
			showMessage('mis2_1', 'comander')
			showMessage('mis2_2', 'comander')
			clearDisplayText()
			setDisplayText('destry_tower')
			togglePauseGame(1);
			showMessage('pause', 'm')

			end	
			--check for sam dying
			if lastDeadUnit()==samUnit then

				clearDisplayText()
				setPlayerAsWinner(2)
				setPlayerAsWinner(3)				
				endGame()

				if timer_event1 ~= nil then
		  		        stopTimerEvent(timer_event1)
					timer_event1=nil
				end	
			end	

			--check for si dying
			if lastDeadUnit()==siUnit then

				clearDisplayText()
				setPlayerAsWinner(2)
				setPlayerAsWinner(3)				
				endGame()

				if timer_event1 ~= nil then
		  		        stopTimerEvent(timer_event1)
					timer_event1=nil
				end
			end	

			--check for ai_1 dying
			if lastDeadUnit()==ai1Unit then
				ai1Unit=nil
			end
			--check for ai_2 dying
			if lastDeadUnit()==ai2Unit then
				ai2Unit=nil
			end
			--check for ai_3 dying
			if lastDeadUnit()==ai3Unit then
				ai3Unit=nil
			end

			--check for prisson dying
			if lastDeadUnit()==prissonUnit then

			createUnit('solder', 2, {startLocation(5)[1] + 15, startLocation(5)[2] + 24})
			disableAi(5)
				if ai1Unit ~= nil then
			givePositionCommand(ai1Unit, 'attack', {startLocation(5)[1] - 47, startLocation(5)[2] - 20})
				end
				if ai2Unit ~= nil then
			givePositionCommand(ai2Unit, 'attack', {startLocation(5)[1] - 47, startLocation(5)[2] - 20})
				end
				if ai3Unit ~= nil then
			givePositionCommand(ai3Unit, 'attack', {startLocation(5)[1] - 47, startLocation(5)[2] - 20})
				end

			destroyUnit(tankUnit);
			createUnit('solder', 2, {startLocation(5)[1] + 34, startLocation(5)[2] + 12})
			runUnit= lastCreatedUnit()
			givePositionCommand(runUnit, 'attack', {startLocation(5)[1] + 0, startLocation(5)[2] - 8})
			createUnit('tank_', 2, {startLocation(5)[1] + 34, startLocation(5)[2] + 12})
			tank2Unit= lastCreatedUnit()
    			 cell_eventtank = registerCellTriggerEventForUnitToUnit(samUnit,tank2Unit)



			createUnit('scientist', 1, {startLocation(5)[1] - 38, startLocation(5)[2] - 19})
			siUnit= lastCreatedUnit()
			createUnit('trigger', 2, startLocation(3))
			winTrigger= lastCreatedUnit()
    			cell_event_win = registerCellTriggerEventForUnitToUnit(siUnit,winTrigger)

			timer_event1= startTimerEvent ()

			for i=1, 3 do
				createUnit('solder', 2, {startLocation(7)[1] + 2, startLocation(7)[2] + 2})
				givePositionCommand(lastCreatedUnit(), 'attack', {startLocation(5)[1] + 0, startLocation(5)[2] - 8})
			end

			givePositionCommand(t1Unit, 'attack', {startLocation(0)[1] - 0, startLocation(0)[2] + 30})

			givePositionCommand(t2Unit, 'attack', {startLocation(0)[1] - 0, startLocation(0)[2] + 28})

			givePositionCommand(t3Unit, 'attack', {startLocation(5)[1] - 47, startLocation(5)[2] - 20})


			--objectives
			objective='escape'
			showMessage('mis6_1', 'comander')
			showMessage('mis6_2', 'comander')
			clearDisplayText()
			setDisplayText('escape')
			togglePauseGame(1);
			showMessage('pause', 'm')

			end	

			--check for tower destroyed
			if lastDeadUnit()==towerUnit then

				createUnit('solder', 2, startLocation(0))
				givePositionCommand(lastCreatedUnit(), 'attack', {startLocation(0)[1] - 8, startLocation(0)[2] - 12})

			givePositionCommand(t1Unit, 'attack', {startLocation(4)[1] - 8, startLocation(4)[2] - 4})

			givePositionCommand(t2Unit, 'attack', {startLocation(4)[1] - 8, startLocation(4)[2] + 4})



			--objectives
			objective='find_hanger'
			showMessage('mis3_1', 'comander')
			showMessage('mis3_2', 'comander')
			clearDisplayText()
			setDisplayText('find_hanger')
			togglePauseGame(1);
			showMessage('pause', 'm')

			end

			--check hanger guard dying
			if lastDeadUnit()==hgUnit then

			givePositionCommand(smokeUnit, 'attack', {startLocation(1)[1] - 3, startLocation(1)[2] + 3})

			end
			<!--check for you wining
			if lastDeadUnit()==towerUnit then
				clearDisplayText()
				setPlayerAsWinner(0)
				setPlayerAsWinner(1)				
				endGame()
			end-->
			
		</unitDied>	
		
	</scripts>		
</scenario>
