<?xml version="1.0" standalone="yes" ?> 
<scenario>
	<difficulty value="1"/>
	<players>
		<player control="human" faction="tower_2" team="1"/>
		<player control="cpu" faction="tower_2" team="2"/>
		<player control="cpu" faction="tower_2" team="2"/>
		<player control="cpu" faction="tower_2" team="2"/>	
	</players>
	<map value="defence_1"/>
	<tileset value="forest"/>
	<tech-tree value="tower"/>
	<default-resources value="false"/>
	<default-units value="false"/>
	<default-victory-conditions value="false"/>
	<scripts>
		<startup>
			disableAi(1)
			createUnit('finish', 0, startLocation(1))
			finishUnit= lastCreatedUnit()
			setCameraPosition(unitPosition(finishUnit))
                        createUnit('worker', 0, startLocation(3))
                        createUnit('worker', 0, startLocation(3))
			createUnit('worker', 0, startLocation(2))
			createUnit('worker', 0, startLocation(2))
			createUnit('w_c_1', 0, startLocation(2))
			w_c_1Unit= lastCreatedUnit()
			giveResource('gold', 0, 1000)
			showMessage('Welcome', 'sword_man')
			setDisplayText('setuptowers')
			objective= 'set_up_towers'
		</startup>		
		<unitCreatedOfType type="start_wave_1">			
			if objective=='set_up_towers' then
				showMessage('Thesword_manscome', 'sword_man')
				setDisplayText('Thesword_manscome')

			                createUnit('sword_man', 1, startLocation(0))
			                sword_manUnit= lastCreatedUnit()
			                givePositionCommand(sword_manUnit, 'move', startLocation(1))

				for i=1, 5 do
					createUnit('sword_man', 1, startLocation(0))
					givePositionCommand(lastCreatedUnit(), 'move', startLocation(1))
				end		

				objective= 'defend_from_sword_mans'			
		        	end	
			
		</unitCreatedOfType>

		<unitCreatedOfType type="start_wave_2">			
			if objective=='set_up_more_towers' and unitCount(1)==0 then
				showMessage('Theguardscome', 'guard')
				setDisplayText('Theguardscome')

			                createUnit('guard', 1, startLocation(0))
			                guardUnit= lastCreatedUnit()
			                givePositionCommand(guardUnit, 'move', startLocation(1))

				for i=1, 4 do
					createUnit('guard', 1, startLocation(0))
					givePositionCommand(lastCreatedUnit(), 'move', startLocation(1))
				end		

				objective= 'defend_from_guards'			
			        end	
			
		</unitCreatedOfType>

		<unitCreatedOfType type="start_wave_3">			
			if objective=='set_up_some_more_towers' and unitCount(1)==0 then
				showMessage('Theknightscome', 'knight')
				setDisplayText('Theknightscome')

			                createUnit('knight', 1, startLocation(0))
			                knightUnit= lastCreatedUnit()
			                givePositionCommand(knightUnit, 'move', startLocation(1))

				for i=1, 3 do
					createUnit('knight', 1, startLocation(0))
					givePositionCommand(lastCreatedUnit(), 'move', startLocation(1))
				end		

				objective= 'defend_from_knights'			
			        end	
			
		</unitCreatedOfType>

		<unitCreatedOfType type="start_wave_4">			
			if objective=='set_up_even_more_towers' and unitCount(1)==0 then
				showMessage('Thecatapultscome', 'catapult')
				setDisplayText('Thecatapultscome')

			                createUnit('catapult', 1, startLocation(0))
			                catapultUnit= lastCreatedUnit()
			                givePositionCommand(catapultUnit, 'move', startLocation(1))

				for i=1, 3 do
					createUnit('catapult', 1, startLocation(0))
					givePositionCommand(lastCreatedUnit(), 'move', startLocation(1))
				end		

				objective= 'defend_from_catapults'			
			        end	
			
		</unitCreatedOfType>

		<unitCreatedOfType type="start_wave_5">			
			if objective=='set_up_the_last_bunch_of_towers' and unitCount(1)==0 then
				showMessage('Thesiege_machinecomes', 'siege_machine')
				setDisplayText('Thesiege_machinecomes')

			                createUnit('siege_machine', 1, startLocation(0))
			                siege_machineUnit= lastCreatedUnit()
			                givePositionCommand(siege_machineUnit, 'move', startLocation(1))

				objective= 'defend_from_the_siege_machine'			
			        end	
			
		</unitCreatedOfType>

		<unitDied>
                        <!--  sword_man round   -->
			if objective=='defend_from_sword_mans' and unitCount(1)==0 then
				clearDisplayText()

			createUnit('w_c_2', 0, startLocation(2))
			w_c_2Unit= lastCreatedUnit()

			giveResource('gold', 0, 1000)
			setDisplayText('setupmoretowers')
			objective= 'set_up_more_towers'
			end
                        <!--  guard round   -->
			if objective=='defend_from_guards' and unitCount(1)==0 then
				clearDisplayText()

			createUnit('w_c_3', 0, startLocation(2))
			w_c_3Unit= lastCreatedUnit()

			giveResource('gold', 0, 1000)
			setDisplayText('setupsomemoretowers')
			objective= 'set_up_some_more_towers'
			end

                        <!--  knight round   -->
			if objective=='defend_from_knights' and unitCount(1)==0 then
				clearDisplayText()

			createUnit('w_c_4', 0, startLocation(2))
			w_c_4Unit= lastCreatedUnit()

			giveResource('gold', 0, 1500)
			setDisplayText('setupevenmoretowers')
			objective= 'set_up_even_more_towers'
			end

                        <!--  catapult round   -->
			if objective=='defend_from_catapults' and unitCount(1)==0 then
				clearDisplayText()

			createUnit('w_c_5', 0, startLocation(2))
			w_c_5Unit= lastCreatedUnit()

			giveResource('gold', 0, 1000)
			setDisplayText('setupthelastbunchoftowers')
			objective= 'set_up_the_last_bunch_of_towers'
			end

                        <!--  siege machine round   -->
		        if objective=='defend_from_the_siege_machine' and unitCount(1)==0 then
				clearDisplayText()

			createUnit('w_c_6', 0, startLocation(2))
			w_c_6Unit= lastCreatedUnit()

			giveResource('gold', 0, 1000)
			setDisplayText('setupabunchmoretowers')
			objective= 'set_up_a_bunch_more_towers'
			end


			--check for finish dying
			if lastDeadUnit()==finishUnit then
				clearDisplayText()
				setPlayerAsWinner(1)
				setPlayerAsWinner(2)
				setPlayerAsWinner(3)				
				endGame()
			end

			if objective=='defend_from_the_siege_machine' and unitCount(1)==0 then
				clearDisplayText()
				setPlayerAsWinner(0)
				endGame()
			end
		</unitDied>
	</scripts>
</scenario>
