<?xml version="1.0" standalone="yes" ?> 
<scenario>
	<difficulty value="1"/>
	<players>
		<player control="human" faction="tower_1" team="1"/>
		<player control="cpu" faction="tower_1" team="2"/>
		<player control="cpu" faction="tower_1" team="2"/>
		<player control="cpu" faction="tower_1" 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', 'daemon')
			setDisplayText('setuptowers')
			objective= 'set_up_towers'
		</startup>		
		<unitCreatedOfType type="start_wave_1">			
			if objective=='set_up_towers' then
				showMessage('Thedaemonscome', 'daemon')
				setDisplayText('Thedaemonscome')

			                createUnit('daemon', 1, startLocation(0))
			                daemonUnit= lastCreatedUnit()
			                givePositionCommand(daemonUnit, 'move', startLocation(1))

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

				objective= 'defend_from_daemons'			
		        	end	
			
		</unitCreatedOfType>

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

			                createUnit('behemoth', 1, startLocation(0))
			                behemothUnit= lastCreatedUnit()
			                givePositionCommand(behemothUnit, 'move', startLocation(1))

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

				objective= 'defend_from_behemoths'			
			        end	
			
		</unitCreatedOfType>

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

			                createUnit('golem', 1, startLocation(0))
			                golemUnit= lastCreatedUnit()
			                givePositionCommand(golemUnit, 'move', startLocation(1))

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

				objective= 'defend_from_golems'			
			        end	
			
		</unitCreatedOfType>

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

			                createUnit('meck', 1, startLocation(0))
			                meckUnit= lastCreatedUnit()
			                givePositionCommand(meckUnit, 'move', startLocation(1))

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

				objective= 'defend_from_meck'			
			        end	
			
		</unitCreatedOfType>

		<unitDied>
                        <!--  daemon round   -->
			if objective=='defend_from_daemons' 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
                        <!--  behemoth round   -->
			if objective=='defend_from_behemoths' 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

                        <!--  golem round   -->
			if objective=='defend_from_golems' 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

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

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