-------------------------------------------------------------------------
-------------------------------------------------------------------------
--
-- Script File for TUTORIAL - BUILDING section
--
-------------------------------------------------------------------------
-------------------------------------------------------------------------



--
-- Initialisation and Setup
--
function Building_Init()

	Building_RegisterObjectives() -- see end of file
	
end



--
-- Start Tutorial
--
function Building_Start()

	-- clean up from the menu
	Rule_RemoveAll(0)
	HintPoint_RemoveAll()
	Game_SkipAllEvents(true)
	UI_ClearEventCues()
	
	tutorial_building_available = false
	tutorial_currentsection = "building"
	TutorialMenu_UpdateAvailability()
	
	Camera_SetInputEnabled(false)
	Game_FadeToBlack(FADE_OUT, TIMING_FADE_OUT)
	
	-- do the title card
	Game_TextTitleFade(409913, TIMING_FADE_IN, 3, TIMING_FADE_OUT, "" )
	
	Rule_AddOneShot(Building_StartB, 3+TIMING_FADE_IN)
	
end
function Building_StartB()

	-- clean up player units
	Player_GetAll(player1)
	SGroup_DestroyAllSquads(sg_allsquads)
	Player_GetAll(player5)
	SGroup_DestroyAllSquads(sg_allsquads)
	Player_GetAll(player6)
	SGroup_DestroyAllSquads(sg_allsquads)
	
	-- switch to the Allied player
	Game_SetLocalPlayer(player1)
	
	Rule_AddOneShot(Building_StartC, 0.5)
	
end
function Building_StartC()

	Rule_AddIntervalEx(Tutorial_RemoveParatroopers, 0.25, 20)

	-- reload taskbar for bindings that have been disabled
	UI_LoadTaskbar("taskbar.lua")
	Rule_AddOneShot(BuildingBindings, 0.1)
	
	Game_SetMode(UI_Normal)
	Game_FadeToBlack(FADE_IN, TIMING_FADE_IN)
	Game_Letterbox(false, 0)
	
	-- camera clamping
	Camera_ClampToMarker(camera_basebuilding_a)
	Camera_MoveToPosition(camera_building_hq)
	Camera_SetInputEnabled(true)
	Camera_ResetToDefault()

	-- bring up the perimeter
	EGroup_ReSpawn(LAYER_perimeter_base)
	EGroup_ReSpawn(LAYER_wall_building_1)
	EGroup_ReSpawn(LAYER_wall_building_2)
	EGroup_ReSpawn(LAYER_wall_building_3)
	EGroup_ReSpawn(LAYER_wall_building_4)
	EGroup_DeSpawn(LAYER_wall_building_5)
	
	-- create all the relevant units
	EGroup_SetPlayerOwner(eg_player1base, player3)
	EGroup_SetPlayerOwner(eg_player3base, player1)
	EGroup_SetStrategicPointNeutral(eg_player1hq)
	Modify_DisableHold(eg_building_house, true)
	
	-- switch off resource income
	Resources_Disable()
	
	-- ensure there are enough resources
	Player_SetResource(player1, RT_Manpower, 183.5)
	Player_SetResource(player1, RT_Munition, 0)
	Player_SetResource(player1, RT_Fuel, 0)
	Player_SetPopCapOverride(player1, 13)
	
	Cmd_InstantUpgrade(eg_building_bunker, UPG.AXIS.BUNKER_MG42)
	--Command_EntityPos(player1, eg_player3hq, CMD_RallyPoint, Marker_GetPosition(mkr_rally_buildinghq))

	-- lock out points
	EGroup_SetSelectable(eg_resourcing_munitionspoint, false)
	EGroup_SetSelectable(eg_resourcing_nullpoint, false)
	EGroup_SetSelectable(eg_building_squadcappoint1, false)
	EGroup_SetSelectable(eg_building_squadcappoint2, false)
	
	-- enable action point kickers from now on
	UI_EnableResourceTypeKicker(RT_Action, true)
	PlayerProfile_SetVar("Tutorial_EnableActionPointKickers", "true")

	-- give the introductory talk
	Util_StartIntel(EVENTS.BuildingIntro)
	
	-- start lesson 1 when ready
	Rule_AddInterval(Building_Engineers_BeginLesson, 0.5)
	
end

function BuildingBindings()

	UI_BindingSetEnabled("tacmap_button", false)
	UI_BindingSetEnabled("company_commander", false)
	UI_BindingSetEnabled("command_retire", false)
	UI_BindingSetEnabled("command_retire_squad", false)
	UI_BindingSetEnabled("construction_cancel_button", false)

	-- enable parts of the ui that are normally locked
	UI_BindingSetEnabled("manpower", true)
	UI_BindingSetEnabled("manpower_rate", true)
	UI_BindingSetEnabled("munition", true)
	UI_BindingSetEnabled("munition_rate", true)
	UI_BindingSetEnabled("fuel", true)
	UI_BindingSetEnabled("fuel_rate", true)
	UI_BindingSetEnabled("squadcap", true)
	UI_BindingSetEnabled("manage_hq", true)
	UI_BindingSetEnabled("manage_barracks", true)

end


--
-- Lesson: Build Engineers
--
function Building_Engineers_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingEngineersIntro)
		
		Rule_AddInterval(Building_Engineers_GiveObjective, 0.5)
		
	end
	
end

function Building_Engineers_GiveObjective()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- change perimeters
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_ENGINEERS, false)
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingEngineersIntro2)
		
		OBJ_BUILDING_ENGINEERS.PingID = Objective_AddUIElements(OBJ_BUILDING_ENGINEERS, eg_player3hq, false, 409550, true)
		
		Rule_AddInterval(Building_Engineers_HQSelected, 0.5)
		
	end
	
end

function Building_Engineers_HQSelected()
	
	if Misc_IsEGroupSelected(eg_player3hq, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Objective_RemoveUIElements(OBJ_BUILDING_ENGINEERS, OBJ_BUILDING_ENGINEERS.PingID)
		
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.ENGINEER, ITEM_DEFAULT)
		
		UI_FlashProductionButton(PITEM_Spawn, SBP.ALLIES.ENGINEER, true, BT_UI_Strong_CommandBtn )
		HintPoint_AddToProductionButton(PITEM_Spawn, SBP.ALLIES.ENGINEER, 409572, true)
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingEngineersIntro3)
		
		Rule_Add(Building_Engineers_Building)
		
	end
	
end

function Building_Engineers_Building()

	if EGroup_IsProducingSquads(eg_player3hq, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.ENGINEER, ITEM_LOCKED)
		
		Util_StartIntel(EVENTS.BuildingEngineersBuilding)
		
		Rule_AddInterval(Building_Engineers_Cancelled, 0.5)
		Rule_AddInterval(Building_Engineers_Done, 0.5)
		
	elseif Misc_IsEGroupSelected(eg_player3hq, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- ask to re-select HQ
		Util_StartIntel(EVENTS.HQReSelect)
		
		OBJ_BUILDING_ENGINEERS.PingID = Objective_AddUIElements(OBJ_BUILDING_ENGINEERS, eg_player3hq, false, 409550, true)
		
		Rule_AddInterval(Building_Engineers_HQSelected, 0.5)
		
	end
	
end


function Building_Engineers_Cancelled()

	Player_GetAll(player1)
	SGroup_Filter(sg_allsquads, SBP.ALLIES.ENGINEER, FILTER_KEEP)
	
	if EGroup_IsProducingSquads(eg_player3hq, ANY) == false and SGroup_Count(sg_allsquads) == 0 then
		
		Rule_RemoveMe()
		if Rule_Exists(Building_Engineers_Done) then Rule_Remove(Building_Engineers_Done) end
		Game_SkipEvent()
		
		-- unlock the engineer button
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.ENGINEER, ITEM_DEFAULT)
		
		if Misc_IsEGroupSelected(eg_player3hq, ANY) then
			
			-- chastise the player
			Util_StartIntel(EVENTS.BuildingEngineersCancelled)
			
			UI_FlashProductionButton(PITEM_Spawn, SBP.ALLIES.ENGINEER, true, BT_UI_Strong_CommandBtn )
			HintPoint_AddToProductionButton(PITEM_Spawn, SBP.ALLIES.ENGINEER, 409572, true)
			
			Rule_Add(Building_Engineers_Building)
			
		else
			
			-- ask to select HQ
			Util_StartIntel(EVENTS.HQSelect)
			
			OBJ_BUILDING_ENGINEERS.PingID = Objective_AddUIElements(OBJ_BUILDING_ENGINEERS, eg_player3hq, false, 409550, true)
			
			Rule_AddInterval(Building_Engineers_HQSelected, 0.5)
			
		end
		
	end
	
end


function Building_Engineers_Done()

	Player_GetAll(player1)
	SGroup_Filter(sg_allsquads, SBP.ALLIES.ENGINEER, FILTER_KEEP)
	
	if SGroup_Count(sg_allsquads) >= 1 then
		
		Rule_RemoveMe()
		if Rule_Exists(Building_Engineers_Cancelled) then Rule_Remove(Building_Engineers_Cancelled) end
		Game_SkipEvent()
		
		SGroup_AddGroup(sg_engineer, sg_allsquads)
		Util_StartIntel(EVENTS.BuildingEngineersDone)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_ENGINEERS, false)
		
		Rule_AddInterval(Building_Barracks_BeginLesson, 0.5)
		
	end

end



--
-- Lesson: Build Barracks
--
function Building_Barracks_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_BARRACKS, false)
		
		Player_SetEntityProductionAvailability(player1, EBP.ALLIES.BARRACKS, ITEM_DEFAULT)
		Player_SetConstructionMenuAvailability(player1, "tp_construction_allied_hq", ITEM_DEFAULT)
		UI_RestrictBuildingPlacement(mkr_building_barracks)
		
		if Misc_IsSGroupSelected(sg_engineer, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingBarracksIntro)
			
			flashid_building_barracks1 = UI_FlashConstructionMenu("tp_construction_allied_hq", false, BT_UI_Strong_CommandBtn )
			hpid_building_barracks1 = HintPoint_AddToConstructionMenu("tp_construction_allied_hq", 409570, false)
			
			UI_SetConstructionMenuCallback(Building_Barracks_ClickedBuildMenu)
			UI_SetBuildingPlacementCallback(Building_Barracks_Placing)
			
			Rule_AddInterval(Building_Barracks_EngineersDeSelected, 0.5)
			
		else
			
			-- ask to select engineers
			Util_StartIntel(EVENTS.BuildingBarracksSelectEngineers)
			
			OBJ_BUILDING_BARRACKS.PingID = Objective_AddUIElements(OBJ_BUILDING_BARRACKS, sg_engineer, false, 409551, true)
			
			Rule_AddInterval(Building_Barracks_EngineersSelected, 0.5)
			
		end
		
	end
	
end


function Building_Barracks_EngineersSelected()

	if Misc_IsSGroupSelected(sg_engineer, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Objective_RemoveUIElements(OBJ_BUILDING_BARRACKS, OBJ_BUILDING_BARRACKS.PingID)
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingBarracksIntro)
		
		flashid_building_barracks1 = UI_FlashConstructionMenu("tp_construction_allied_hq", false, BT_UI_Strong_CommandBtn )
		hpid_building_barracks1 = HintPoint_AddToConstructionMenu("tp_construction_allied_hq", 409570, false)
		
		UI_SetConstructionMenuCallback(Building_Barracks_ClickedBuildMenu)
		UI_SetBuildingPlacementCallback(Building_Barracks_Placing)
		
		Rule_AddInterval(Building_Barracks_EngineersDeSelected, 0.5)
		
	end

end


function Building_Barracks_EngineersDeSelected()

	if Misc_IsSGroupSelected(sg_engineer, ANY) == false then 
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_barracks1)
		HintPoint_Remove(hpid_building_barracks1)
		
		UI_ClearConstructionMenuCallback()
		UI_ClearBuildingPlacementCallback()
		
		-- ask to re-select engineers
		Util_StartIntel(EVENTS.EngineersReSelect)
		
		Objective_RemoveUIElements(OBJ_BUILDING_BARRACKS, OBJ_BUILDING_BARRACKS.PingID)
		OBJ_BUILDING_BARRACKS.PingID = Objective_AddUIElements(OBJ_BUILDING_BARRACKS, sg_engineer, false, 409551, true)
		
		Rule_AddInterval(Building_Barracks_EngineersSelected, 0.5)
		
	end

end

function Building_Barracks_ClickedBuildMenu(menuname, activated)
	if menuname == "tp_construction_allied_hq" then
		if activated == true then
			
			Game_SkipEvent()
			
			Util_StartIntel(EVENTS.BuildingBarracksInConstructionMenu)
			flashid_building_barracks2 = UI_FlashConstructionButton(EBP.ALLIES.BARRACKS, false, BT_UI_Strong_CommandBtn )
			hpid_building_barracks2 = HintPoint_AddToConstructionButton(EBP.ALLIES.BARRACKS, 409573, false)
			
		else
			
			UI_StopFlashing(flashid_building_barracks2)
			HintPoint_Remove(hpid_building_barracks2)
			
		end
	end
end


function Building_Barracks_Placing(ebp, phase)
	
	if ebp == EBP.ALLIES.BARRACKS then
		
		-- placing
		if phase == CP_Selected then
			
			UI_ClearConstructionMenuCallback()
			OBJ_BUILDING_BARRACKS.PingID = Objective_AddUIElements(OBJ_BUILDING_BARRACKS, mkr_building_barracks, false, 409552, true)
			
		-- placed
		elseif phase == CP_FinishedPlacing then
			
			UI_ClearBuildingPlacementCallback()
			Game_SkipEvent()
			
			Objective_RemoveUIElements(OBJ_BUILDING_BARRACKS, OBJ_BUILDING_BARRACKS.PingID)
			
			UI_StopFlashing(flashid_building_barracks1)
			UI_StopFlashing(flashid_building_barracks2)
			
			HintPoint_RemoveAll()
			
			if Rule_Exists(Building_Barracks_EngineersDeSelected) then Rule_Remove(Building_Barracks_EngineersDeSelected) end
			
			Util_StartIntel(EVENTS.BuildingBarracksPlaced)
			
			Rule_AddInterval(Building_Barracks_Done, 0.5)
			
		end
		
	end		
	
end


function Building_Barracks_RestartedConstruction()
	
	if SGroup_IsConstructingBuilding(sg_engineer, ANY) then
		
		Rule_RemoveMe()
		Objective_RemoveUIElements(OBJ_BUILDING_BARRACKS, OBJ_BUILDING_BARRACKS.PingID)
		Rule_AddInterval(Building_Barracks_Done, 0.5)
		
	end
	
end


function Building_Barracks_Done()

	if Player_HasBuilding(player1, EBP.ALLIES.BARRACKS) then
		
		Rule_RemoveMe()
		
		Player_SetEntityProductionAvailability(player1, EBP.ALLIES.BARRACKS, ITEM_LOCKED)
		Player_SetConstructionMenuAvailability(player1, "tp_construction_allied_hq", ITEM_LOCKED)
		UI_UnrestrictBuildingPlacement()
		
		Player_GetAll(player1)
		EGroup_Filter(eg_allentities, EBP.ALLIES.BARRACKS, FILTER_KEEP)
		EGroup_AddEGroup(eg_player3barracks, eg_allentities)
		EGroup_AddEGroup(eg_player3base, eg_allentities)
		
		SGroup_SetSelectable(sg_engineer, false)
		
		--Command_EntityPos(player1, eg_player3barracks, CMD_RallyPoint, Marker_GetPosition(mkr_rally_buildingbarracks))
		
		Util_StartIntel(EVENTS.BuildingBarracksDone)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_BARRACKS, false)
		
		Rule_AddInterval(Building_Riflemen_BeginLesson, 0.5)
		
	elseif SGroup_IsConstructing(sg_engineer, ANY) == false then
		
		Rule_RemoveMe()
		Player_GetAll(player1)
		EGroup_Filter(eg_allentities, EBP.ALLIES.BARRACKS, FILTER_KEEP)
		EGroup_AddEGroup(eg_player3barracks, eg_allentities)
		OBJ_BUILDING_BARRACKS.PingID = Objective_AddUIElements(OBJ_BUILDING_BARRACKS, eg_player3barracks, false, 409590, true)
		Rule_AddInterval(Building_Barracks_RestartedConstruction, 0.5)
		
	end
	
end



--
-- Lesson: Build Riflemen
--
function Building_Riflemen_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_DEFAULT)
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_RIFLEMEN, false)
		
		if Misc_IsEGroupSelected(eg_player3barracks, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingRiflemenIntro)
			
			flashid_building_riflemen = UI_FlashProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, true, BT_UI_Strong_CommandBtn )
			hpid_building_riflemen = HintPoint_AddToProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, 409574, true)
			
			Rule_Add(Building_Riflemen_Ordered)
			
		else
			
			-- ask to select barracks
			Util_StartIntel(EVENTS.BarracksSelect)
			
			OBJ_BUILDING_RIFLEMEN.PingID = Objective_AddUIElements(OBJ_BUILDING_RIFLEMEN, eg_player3barracks, false, 409553, true)
			
			Rule_AddInterval(Building_Riflemen_BarracksSelected, 0.5)
			
		end
		
	end
	
end


function Building_Riflemen_BarracksSelected()
	
	if Misc_IsEGroupSelected(eg_player3barracks, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingRiflemenIntro)
		
		Objective_RemoveUIElements(OBJ_BUILDING_RIFLEMEN, OBJ_BUILDING_RIFLEMEN.PingID)
		
		flashid_building_riflemen = UI_FlashProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, true, BT_UI_Strong_CommandBtn )
		hpid_building_riflemen = HintPoint_AddToProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, 409574, true)
		
		Rule_Add(Building_Riflemen_Ordered)
		
	end
	
end


function Building_Riflemen_Ordered()
	
	if EGroup_IsProducingSquads(eg_player3barracks, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- lock out the riflemen button
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_LOCKED)
		
		-- change perimeters
		HintPoint_RemoveAll()
		UI_StopFlashing(flashid_building_riflemen)
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingRiflemenOrdered)
		
		Rule_AddInterval(Building_Riflemen_Cancelled, 0.5)
		Rule_AddInterval(Building_Riflemen_Done, 0.5)
		
	elseif Misc_IsEGroupSelected(eg_player3barracks, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_riflemen)
		HintPoint_Remove(hpid_building_riflemen)
		
		-- ask to re-select barracks
		Util_StartIntel(EVENTS.BarracksReSelect)
		
		OBJ_BUILDING_RIFLEMEN.PingID = Objective_AddUIElements(OBJ_BUILDING_RIFLEMEN, eg_player3barracks, false, 409553, true)
		
		Rule_AddInterval(Building_Riflemen_BarracksSelected, 0.5)
		
	end
	
end


function Building_Riflemen_Cancelled()

	Player_GetAll(player1)
	SGroup_Filter(sg_allsquads, SBP.ALLIES.RIFLEMEN, FILTER_KEEP)
	
	if EGroup_IsProducingSquads(eg_player3barracks, ANY) == false and SGroup_Count(sg_allsquads) == 0 then
		
		Rule_RemoveMe()
		if Rule_Exists(Building_Riflemen_Done) then Rule_Remove(Building_Riflemen_Done) end
		Game_SkipEvent()
		
		Util_StartIntel(EVENTS.BuildingRiflemenOrderCancelled)
		
		-- unlock the riflemen button
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_DEFAULT)
		
		if Misc_IsEGroupSelected(eg_player3barracks, ANY) then
			
			flashid_building_riflemen = UI_FlashProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, false, BT_UI_Strong_CommandBtn )
			hpid_building_riflemen = HintPoint_AddToProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, 409574, false)
			
			Rule_Add(Building_Riflemen_Ordered)
			
		else
			
			OBJ_BUILDING_RIFLEMEN.PingID = Objective_AddUIElements(OBJ_BUILDING_RIFLEMEN, eg_player3barracks, false, 409553, true)
			
			Rule_AddInterval(Building_Riflemen_BarracksSelected, 0.5)
			
		end
		
	end
	
end


function Building_Riflemen_Done()
	
	Player_GetAll(player1)
	SGroup_Filter(sg_allsquads, SBP.ALLIES.RIFLEMEN, FILTER_KEEP)
	
	if SGroup_Count(sg_allsquads) >= 1 then
		
		Rule_RemoveMe()
		if Rule_Exists(Building_Riflemen_Cancelled) then Rule_Remove(Building_Riflemen_Cancelled) end
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_RIFLEMEN, false)
		
		Rule_AddInterval(Building_Resourcing_Intro, 0.5)
		
	end
	
end


--
-- Lesson: Resourcing Intro
--
function Building_Resourcing_Intro()

	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		Util_StartIntel(EVENTS.ResourcingIntroPart1)
		
		Rule_AddInterval(Building_TacMap_AskToTrigger, 0.5)
		
	end

end

function Building_TacMap_AskToTrigger()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		Util_StartIntel(EVENTS.ResourcingIntroPart1b)
		
		-- lockouts
		UI_BindingSetEnabled("tacmap_button", true)
		Rule_AddOneShot(Building_TacMap_FlashButton, 0.1)
		
		Rule_AddInterval(Building_TacMap_Triggered, 0.5)
		
	end
	
end
	
function Building_TacMap_FlashButton()
	flashid_building_tacmap = UI_FlashBinding("tacmap_button", true, BT_UI_Strong_TacmapBtn )
	hpid_building_tacmap = HintPoint_AddToTaskbarBinding("tacmap_button", 409575, true)
end

function Building_TacMap_Triggered()

	if UI_IsTacticalMapShown() then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Util_StartIntel(EVENTS.ResourcingIntroPart2)
		
		Player_GetAll(player1)
		SGroup_Filter(sg_allsquads, SBP.ALLIES.RIFLEMEN, FILTER_KEEP)
		SGroup_Clear(sg_group1)
		SGroup_AddGroup(sg_group1, sg_allsquads)
		
		Rule_AddInterval(Building_TacMap_Left, 0.5)
		
	end
	
end

function Building_TacMap_Left()

	if UI_IsTacticalMapShown() == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_BindingSetEnabled("tacmap_button", false)
		
		Camera_ClampToMarker(camera_basebuilding_b)
		Camera_MoveToEGroup(eg_resourcing_munitionspoint, true, SLOW_CAMERA_PANNING)
		Camera_SafetyDefault()
		EGroup_DeSpawn(LAYER_wall_building_1)
		Tutorial_WarpGuys(sg_group1, mkr_resourcing_munitionsdest)
		
		-- brw 08/02/07 - increased the addinterval time so that the riflemen are properly 
		-- marked with the objective hintpoint because the warping takes some sim time.
		Rule_AddInterval(Building_CaptureMunitions_BeginLesson, 1)
		
	end
	
end



--
-- Lesson: Capture Munitions Point
--
function Building_CaptureMunitions_BeginLesson()
	
	if Event_IsAnyRunning() == false then					-- wait until all previous speech is done
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- change perimeters
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_MUNITIONS, false)
		
		Player_SetCommandAvailability(player1, SCMD_Capture, ITEM_DEFAULT)
		EGroup_SetSelectable(eg_resourcing_munitionspoint, true)
		
		if Misc_IsSGroupSelected(sg_group1, ALL) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.ResourcingCapture1Intro)
			
			OBJ_BUILDING_MUNITIONS.PingID = Objective_AddUIElements(OBJ_BUILDING_MUNITIONS, eg_resourcing_munitionspoint, false, 409554, true, 2)
			
			Rule_AddInterval(Building_CaptureMunitions_Done, 0.5)
			
		else
			
			-- ask to select riflemen
			Util_StartIntel(EVENTS.RiflemenSelect)
			
			OBJ_BUILDING_MUNITIONS.PingID = Objective_AddUIElements(OBJ_BUILDING_MUNITIONS, sg_group1, false, 409562, true)
			
			Rule_AddInterval(Building_CaptureMunitions_RiflemenSelected, 0.5)
			
		end
		
	end

end


function Building_CaptureMunitions_RiflemenSelected()

	if Misc_IsSGroupSelected(sg_group1, ALL) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.ResourcingCapture1Intro)
		
		Objective_RemoveUIElements(OBJ_BUILDING_MUNITIONS, OBJ_BUILDING_MUNITIONS.PingID)
		OBJ_BUILDING_MUNITIONS.PingID = Objective_AddUIElements(OBJ_BUILDING_MUNITIONS, eg_resourcing_munitionspoint, false, 409554, true, 2)
		
		Rule_AddInterval(Building_CaptureMunitions_Done, 0.5)
		
	end

end


function Building_CaptureMunitions_Done()
	
	if Player_OwnsEGroup(player1, eg_resourcing_munitionspoint) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_BindingSetEnabled("tacmap_button", true)
		
		Util_StartIntel(EVENTS.ResourcingCapture1Done)
		
		-- fake the pop cap increase
		Player_SetPopCapOverride(player1, 21)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_MUNITIONS, false)
		HintPoint_RemoveAll()
		
		Rule_AddInterval(Building_CaptureMunitions_TriggeredTacMap, 0.5)
		
	elseif Misc_IsSGroupSelected(sg_group1, ALL) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- ask to re-select riflemen
		Util_StartIntel(EVENTS.RiflemenReSelect)
		
		Objective_RemoveUIElements(OBJ_BUILDING_MUNITIONS, OBJ_BUILDING_MUNITIONS.PingID)
		OBJ_BUILDING_MUNITIONS.PingID = Objective_AddUIElements(OBJ_BUILDING_MUNITIONS, sg_group1, false, 409562, true)
		
		Rule_AddInterval(Building_CaptureMunitions_RiflemenSelected, 0.5)
		
	end
	
end


function Building_CaptureMunitions_TriggeredTacMap()

	if UI_IsTacticalMapShown() then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Util_StartIntel(EVENTS.ResourcingSupplyIntro)
		
		Rule_AddInterval(Building_CaptureNull_BeginLesson, 0.5)
		
	end
	
end




--
-- Lesson: Capture Null Point
--
function Building_CaptureNull_BeginLesson()
	
	if UI_IsTacticalMapShown() == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_BindingSetEnabled("tacmap_button", false)
		
		-- change perimeters
		
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_NULL, false)
		
		Camera_ClampToMarker(camera_basebuilding_c)
		Camera_MoveToPosition(mkr_resourcing_nulldest, true, SLOW_CAMERA_PANNING)
		Camera_SafetyDefault()
		EGroup_DeSpawn(LAYER_wall_building_2)
		Misc_SelectSGroup(sg_group1, false)
		
		-- move the player's riflemen up to this position
		Tutorial_WarpGuys(sg_group1, mkr_resourcing_nulldest)
		SGroup_SetInvulnerable(sg_group1, true)
		
		-- create enemy units for small skirmish
		Util_CreateSquads(player2, sg_group3, SBP.AXIS.VOLKSGRENADIER, mkr_building_firstattackspawn, nil, 1)
		Modify_Vulnerability(sg_group3, 2.2)
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.ResourcingCapture2Intro)
		
		Rule_AddInterval(Building_CaptureNull_EnemyKilled, 0.5)
		
	end

end

function Building_CaptureNull_EnemyKilled()
	
	if SGroup_Count(sg_group3) == 0 then
		
		Rule_RemoveMe()
		
		EGroup_SetSelectable(eg_resourcing_nullpoint, true)
		
		if Misc_IsSGroupSelected(sg_group1, ANY) then
			
			OBJ_BUILDING_NULL.PingID = Objective_AddUIElements(OBJ_BUILDING_NULL, eg_resourcing_nullpoint, false, 409555, true, 2)
			
			Rule_AddInterval(Building_CaptureNull_Done, 0.5)
			
		else
			
			Game_SkipEvent()
			
			-- ask to select riflemen
			Util_StartIntel(EVENTS.RiflemenSelect)
			
			OBJ_BUILDING_NULL.PingID = Objective_AddUIElements(OBJ_BUILDING_NULL, sg_group1, false, 409562, true)
			
			Rule_AddInterval(Building_CaptureNull_RiflemenSelected, 0.5)
			
		end
		
	end
	
end


function Building_CaptureNull_RiflemenSelected()

	if Misc_IsSGroupSelected(sg_group1, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Util_StartIntel(EVENTS.ResourcingCapture2Capture)
		
		Objective_RemoveUIElements(OBJ_BUILDING_NULL, OBJ_BUILDING_NULL.PingID)
		OBJ_BUILDING_NULL.PingID = Objective_AddUIElements(OBJ_BUILDING_NULL, eg_resourcing_nullpoint, false, 409555, true, 2)
		
		Rule_AddInterval(Building_CaptureNull_Done, 0.5)
		
	end

end


function Building_CaptureNull_Done()
	
	if Player_OwnsEGroup(player1, eg_resourcing_nullpoint) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Util_StartIntel(EVENTS.ResourcingCapture2Done)
		
		-- fake the pop cap increase
		Player_SetPopCapOverride(player1, 18)
		
		SGroup_SetInvulnerable(sg_group1, false)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_NULL, false)
		HintPoint_RemoveAll()
		
		Rule_AddInterval(Building_Secure_BeginLesson, 0.5)
		
	elseif Misc_IsSGroupSelected(sg_group1, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- ask to reselect riflemen
		Util_StartIntel(EVENTS.RiflemenReSelect)
		
		Objective_RemoveUIElements(OBJ_BUILDING_NULL, OBJ_BUILDING_NULL.PingID)
		OBJ_BUILDING_NULL.PingID = Objective_AddUIElements(OBJ_BUILDING_NULL, sg_group1, false, 409562, true)
		
		Rule_AddInterval(Building_CaptureNull_RiflemenSelected, 0.5)
		
	end
	
end



--
-- Lesson: Secure Munitions Point
--
function Building_Secure_BeginLesson()
	
	if Event_IsAnyRunning() == false then					-- wait until all previous speech is done
		
		Rule_RemoveMe()
		
		-- change perimeters
		
		Camera_MoveToEGroup(eg_resourcing_munitionspoint, true, SLOW_CAMERA_PANNING)
		Camera_SafetyDefault()
		Tutorial_WarpGuys(sg_group1, mkr_resourcing_munitionsdest)
		
		UI_SetConstructionMenuCallback(Building_Secure_ClickedBuildMenu)
		UI_SetBuildingPlacementCallback(Building_Secure_Placing)
		UI_RestrictBuildingPlacement(mkr_resourcing_secure)
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.ResourcingSecureIntro)
		
		Rule_AddInterval(Building_Secure_GiveObjective, 0.5)
		
	end

end


function Building_Secure_GiveObjective()

	if Event_IsAnyRunning() == false then					-- wait until all previous speech is done
		
		Rule_RemoveMe()
		
		-- ensure the player has enough resources
		Tutorial_SafetySetResources(cost.observationpost)		
		Player_SetEntityProductionAvailability(player1, EBP.ALLIES.OBSERVATION_POST, ITEM_DEFAULT)
		Player_SetConstructionMenuAvailability(player1, "tp_construction_rifleman_basic", ITEM_DEFAULT)
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_SECURE, false)
		
		if Misc_IsSGroupSelected(sg_group1, ALL) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.ResourcingSecureGiveObjective)
			
			flashid_building_op1 = UI_FlashConstructionMenu("tp_construction_rifleman_basic", false, BT_UI_Strong_CommandBtn )
			hpid_building_op1 = HintPoint_AddToConstructionMenu("tp_construction_rifleman_basic", 409571, false)
			
--~ 			UI_SetConstructionMenuCallback(Building_Secure_ClickedBuildMenu)
--~ 			UI_SetBuildingPlacementCallback(Building_Secure_Placing)
			
			Rule_AddInterval(Building_Secure_RiflemenDeSelected, 0.5)
			
		else
			
			-- ask to select riflemen
			Util_StartIntel(EVENTS.RiflemenSelect)
			
			OBJ_BUILDING_SECURE.PingID = Objective_AddUIElements(OBJ_BUILDING_SECURE, sg_group1, false, 409562, true)
			
			Rule_AddInterval(Building_Secure_RiflemenSelected, 0.5)
			
		end
		
	end
	
end


function Building_Secure_RiflemenSelected()

	if Misc_IsSGroupSelected(sg_group1, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.ResourcingSecureGiveObjective)
		
		Objective_RemoveUIElements(OBJ_BUILDING_SECURE, OBJ_BUILDING_SECURE.PingID)
		
		flashid_building_op1 = UI_FlashConstructionMenu("tp_construction_rifleman_basic", false, BT_UI_Strong_CommandBtn )
		hpid_building_op1 = HintPoint_AddToConstructionMenu("tp_construction_rifleman_basic", 409571, false)
		
--~ 		UI_SetConstructionMenuCallback(Building_Secure_ClickedBuildMenu)
--~ 		UI_SetBuildingPlacementCallback(Building_Secure_Placing)
		
		Rule_AddInterval(Building_Secure_RiflemenDeSelected, 0.5)
		
	end
	
end


function Building_Secure_RiflemenDeSelected()

	if Misc_IsSGroupSelected(sg_group1, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_op1)
		HintPoint_Remove(hpid_building_op1)
		
--~ 		UI_ClearConstructionMenuCallback()
--~ 		UI_ClearBuildingPlacementCallback()
		
		-- ask to re-select riflemen
		Util_StartIntel(EVENTS.RiflemenReSelect)
		
		Objective_RemoveUIElements(OBJ_BUILDING_SECURE, OBJ_BUILDING_SECURE.PingID)
		OBJ_BUILDING_SECURE.PingID = Objective_AddUIElements(OBJ_BUILDING_SECURE, sg_group1, false, 409562, true)
		
		Rule_AddInterval(Building_Secure_RiflemenSelected, 0.5)
		
	end
	
end


function Building_Secure_ClickedBuildMenu(menuname, activated)
	if menuname == "tp_construction_rifleman_basic" then
		if activated == true then
			
			UI_ClearConstructionMenuCallback()
			Game_SkipEvent()
			
			Util_StartIntel(EVENTS.ResourcingSecureInConstructionMenu)
			flashid_building_op2 = UI_FlashConstructionButton(EBP.ALLIES.OBSERVATION_POST, false, BT_UI_Strong_CommandBtn )
			hpid_building_op2 = HintPoint_AddToConstructionButton(EBP.ALLIES.OBSERVATION_POST, 409577, false)
			
		else
			UI_StopFlashing(flashid_building_op2)
			HintPoint_Remove(hpid_building_op2)
		end
	end
end


function Building_Secure_Placing(ebp, phase)
	
	if ebp == EBP.ALLIES.OBSERVATION_POST then
		
		-- placing
		if phase == CP_Selected then
			
			UI_ClearConstructionMenuCallback()
			OBJ_BUILDING_SECURE.PingID = Objective_AddUIElements(OBJ_BUILDING_SECURE, eg_resourcing_munitionspoint, false, 409557, true, 2)
			
		-- placed
		elseif phase == CP_FinishedPlacing then
			
			UI_ClearBuildingPlacementCallback()
			Game_SkipEvent()
			
			Objective_RemoveUIElements(OBJ_BUILDING_SECURE, OBJ_BUILDING_SECURE.PingID)
			
			if Rule_Exists(Building_Secure_RiflemenDeSelected) then Rule_Remove(Building_Secure_RiflemenDeSelected) end
			
			UI_StopFlashing(flashid_building_op1)
			UI_StopFlashing(flashid_building_op2)
			HintPoint_Remove(hpid_building_op1)
			HintPoint_Remove(hpid_building_op2)
			
			Util_StartIntel(EVENTS.ResourcingSecureBuilding)
			
			Rule_AddInterval(Building_Secure_Done, 0.5)
			
		end
		
	end
	
end

function Building_Secure_RestartedConstruction()
	
	if SGroup_IsConstructingBuilding(sg_group1, ANY) then
		
		Rule_RemoveMe()
		Objective_RemoveUIElements(OBJ_BUILDING_SECURE, OBJ_BUILDING_SECURE.PingID)
		Rule_AddInterval(Building_Secure_Done, 0.5)
		
	end
	
end

function Building_Secure_Done()
	
	if Player_HasBuilding(player1, EBP.ALLIES.OBSERVATION_POST) then
		
		Rule_RemoveMe()
		
		Player_SetEntityProductionAvailability(player1, EBP.ALLIES.OBSERVATION_POST, ITEM_LOCKED)
		Player_SetConstructionMenuAvailability(player1, "tp_construction_rifleman_basic", ITEM_LOCKED)
		UI_UnrestrictBuildingPlacement()
		
		Util_StartIntel(EVENTS.ResourcingSecureDone)
		
		Player_GetAll(player1)
		EGroup_Filter(eg_allentities, EBP.ALLIES.OBSERVATION_POST, FILTER_KEEP)
		EGroup_AddEGroup(eg_player3op, eg_allentities)
		EGroup_AddEGroup(eg_player3base, eg_allentities)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_SECURE, false)
		HintPoint_RemoveAll()
		
		Rule_AddInterval(Building_MGNest_BeginLesson, 0.5)
		
	elseif SGroup_IsConstructingBuilding(sg_group1, ANY) == false then
		
		Rule_RemoveMe()
		Player_GetAll(player1)
		EGroup_Filter(eg_allentities, EBP.ALLIES.OBSERVATION_POST, FILTER_KEEP)
		EGroup_AddEGroup(eg_player3op, eg_allentities)
		OBJ_BUILDING_SECURE.PingID = Objective_AddUIElements(OBJ_BUILDING_SECURE, eg_player3op, false, 409591, true)
		Rule_AddInterval(Building_Secure_RestartedConstruction, 0.5)
		
	end
	
end



--
-- Lesson: Build MG Nest
--
function Building_MGNest_BeginLesson()

	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingMGNestIntro1)
		
		Camera_ClampToMarker(camera_basebuilding_d)
		EGroup_DeSpawn(LAYER_wall_building_3)
		Cmd_Move(sg_engineer, camera_building_hq)
		
		Rule_AddInterval(Building_MGNest_GiveObjective, 0.5)
		
	end
	
end


function Building_MGNest_GiveObjective()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Tutorial_WarpGuys(sg_engineer, mkr_building_engineerforwardrally)
		
		FOW_RevealMarker(mkr_building_clearforwardfield, -1)
		Camera_MoveToPosition(mkr_building_mgnest, true, SLOW_CAMERA_PANNING)
		Camera_SafetyDefault()
		SGroup_SetSelectable(sg_engineer, true)
		SGroup_SetSelectable(sg_group1, false)
		
		-- ensure the player has enough resources
		Tutorial_SafetySetResources(cost.mgnest)		
		Player_SetEntityProductionAvailability(player1, EBP.ALLIES.MG_NEST, ITEM_DEFAULT)
		Player_SetConstructionMenuAvailability(player1, "tp_construction_engineer_basic", ITEM_DEFAULT)
		UI_RestrictBuildingPlacement(mkr_building_mgnest)
		
		-- remove any previous attempts
		EGroup_DestroyAllEntities(eg_player3mgnest)
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_MGNEST, false)
		
		-- brw 08/02/07 - added this one shot so that the engineers are properly 
		-- marked with the objective hintpoint because the warping takes some sim time.
		Rule_AddOneShot(Build_MGNest_AfterEngineerWarp, 1)
		
	end
	
end

function Build_MGNest_AfterEngineerWarp()

	if Misc_IsSGroupSelected(sg_engineer, ALL) then
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingMGNestGiveObjective)
		
		flashid_building_mgnest1 = UI_FlashConstructionMenu("tp_construction_engineer_basic", false, BT_UI_Strong_CommandBtn )
		hpid_building_mgnest1 = HintPoint_AddToConstructionMenu("tp_construction_engineer_basic", 409571, false)
		
		UI_SetConstructionMenuCallback(Building_MGNest_ClickedBuildMenu)
		UI_SetBuildingPlacementCallback(Building_MGNest_Placing)
		
		Rule_AddInterval(Building_MGNest_EngineerDeSelected, 0.5)
		
	else
		
		-- ask to select engineers
		Util_StartIntel(EVENTS.EngineersSelect)
		
		OBJ_BUILDING_MGNEST.PingID = Objective_AddUIElements(OBJ_BUILDING_MGNEST, sg_engineer, false, 409551, true)
		
		Rule_AddInterval(Building_MGNest_EngineerSelected, 0.5)
		
	end

end


function Building_MGNest_EngineerSelected()

	if Misc_IsSGroupSelected(sg_engineer, ALL) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingMGNestGiveObjective)
		
		Objective_RemoveUIElements(OBJ_BUILDING_MGNEST, OBJ_BUILDING_MGNEST.PingID)
		
		flashid_building_mgnest1 = UI_FlashConstructionMenu("tp_construction_engineer_basic", false, BT_UI_Strong_CommandBtn )
		hpid_building_mgnest1 = HintPoint_AddToConstructionMenu("tp_construction_engineer_basic", 409571, false)
		
		UI_SetConstructionMenuCallback(Building_MGNest_ClickedBuildMenu)
		UI_SetBuildingPlacementCallback(Building_MGNest_Placing)
		
		Rule_AddInterval(Building_MGNest_EngineerDeSelected, 0.5)
		
	end

end


function Building_MGNest_EngineerDeSelected()

	if Misc_IsSGroupSelected(sg_engineer, ALL) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_mgnest1)
		HintPoint_Remove(hpid_building_mgnest1)
		
		UI_ClearConstructionMenuCallback()
		UI_ClearBuildingPlacementCallback()
		
		-- ask to select engineers
		Util_StartIntel(EVENTS.EngineersSelect)
		
		Objective_RemoveUIElements(OBJ_BUILDING_MGNEST, OBJ_BUILDING_MGNEST.PingID)
		OBJ_BUILDING_MGNEST.PingID = Objective_AddUIElements(OBJ_BUILDING_MGNEST, sg_engineer, false, 409551, true)
		
		Rule_AddInterval(Building_MGNest_EngineerSelected, 0.5)
		
	end

end


function Building_MGNest_ClickedBuildMenu(menuname, activated)
	if menuname == "tp_construction_engineer_basic" then
		if activated == true then
			
			Game_SkipEvent()
			
			Util_StartIntel(EVENTS.BuildingMGNestInConstructionMenu)
			flashid_building_mgnest2 = UI_FlashConstructionButton(EBP.ALLIES.MG_NEST, false, BT_UI_Strong_CommandBtn )
			hpid_building_mgnest2 = HintPoint_AddToConstructionButton(EBP.ALLIES.MG_NEST, 409578, false)
			
		else
			UI_StopFlashing(flashid_building_mgnest2)
			HintPoint_Remove(hpid_building_mgnest2)
		end
	end
end


function Building_MGNest_Placing(ebp, phase)
	
	if ebp == EBP.ALLIES.MG_NEST then
		
		-- placing
		if phase == CP_Selected then
			
			OBJ_BUILDING_MGNEST.PingID = Objective_AddUIElements(OBJ_BUILDING_MGNEST, mkr_building_mgnest, false, 409556, true)
			
		-- rotating
		elseif phase == CP_StartedPlacing then
			
			Game_SkipEvent()
			
			Objective_RemoveUIElements(OBJ_BUILDING_MGNEST, OBJ_BUILDING_MGNEST.PingID)
			Util_StartIntel(EVENTS.BuildingMGNestRotate)
			
			EGroup_ReSpawn(eg_building_mgnestfacing)
			
		-- finished
		elseif phase == CP_FinishedPlacing then
			
			Game_SkipEvent()
			
			UI_ClearConstructionMenuCallback()
			UI_ClearBuildingPlacementCallback()
			
			if Rule_Exists(Building_MGNest_EngineerDeSelected) then Rule_Remove(Building_MGNest_EngineerDeSelected) end
			
			UI_StopFlashing(flashid_building_mgnest1)
			UI_StopFlashing(flashid_building_mgnest2)
			HintPoint_Remove(hpid_building_mgnest1)
			HintPoint_Remove(hpid_building_mgnest2)
			
			EGroup_DeSpawn(eg_building_mgnestfacing)
			
			Rule_AddInterval(Building_MGNest_Done, 0.5)
			
		end
		
	end		
	
end

function Building_MGNest_RestartedConstruction()
	
	if SGroup_IsConstructingBuilding(sg_engineer, ANY) then
		
		Rule_RemoveMe()
		Objective_RemoveUIElements(OBJ_BUILDING_MGNEST, OBJ_BUILDING_MGNEST.PingID)
		Rule_AddInterval(Building_MGNest_Done, 0.5)
		
	end
	
end

function Building_MGNest_Done()

	if Player_HasBuilding(player1, EBP.ALLIES.MG_NEST) then
		
		Rule_RemoveMe()
		
		Player_SetEntityProductionAvailability(player1, EBP.ALLIES.MG_NEST, ITEM_LOCKED)
		Player_SetConstructionMenuAvailability(player1, "tp_construction_engineer_basic", ITEM_LOCKED)
		UI_UnrestrictBuildingPlacement()
		
		Player_GetAll(player1)
		EGroup_Filter(eg_allentities, EBP.ALLIES.MG_NEST, FILTER_KEEP)
		EGroup_AddEGroup(eg_player3mgnest, eg_allentities)
		EGroup_AddEGroup(eg_player3base, eg_allentities)
		
		Modify_DisableHold(eg_player3mgnest, true)
		
		-- check direction of MG Nest
		local dir1 = Entity_GetHeading(EGroup_GetSpawnedEntityAt(eg_player3mgnest, 1))
		
		-- dir2 is the direction from the HMG to the bad guy's approach direction
		local hmgpos = EGroup_GetPosition_EVEN_IF_EMPTY(eg_player3mgnest)
		local enemypos = Marker_GetPosition(mkr_building_mgnestfacing)
		local dist = World_DistancePointToPoint(hmgpos, enemypos)
		local dir2 = World_Pos((enemypos.x - hmgpos.x)/dist, (enemypos.y - hmgpos.y)/dist, (enemypos.z - hmgpos.z)/dist)
		
		-- distance between the points should be less than 0.5 (approx. 30 degrees either side)
		if World_DistancePointToPoint(dir1, dir2) < 0.5 then
			
			Util_StartIntel(EVENTS.BuildingMGNestDone)
			
			-- complete the objective
			Objective_Complete(OBJ_BUILDING_MGNEST, false)
			
			Rule_AddInterval(Building_MGNest_StartAttack, 0.5)
			
		else
			
			Util_StartIntel(EVENTS.BuildingMGNestDoneWrongDirection)
			
			-- brw 08/02/07 - increased the addinterval time so that the riflemen are properly 
			-- marked with the objective hintpoint because the warping takes some sim time.
			Rule_AddInterval(Building_MGNest_GiveObjective, 1)
			
		end
		
	elseif SGroup_IsConstructing(sg_engineer, ANY) == false then
		
		Rule_RemoveMe()
		Player_GetAll(player1)
		EGroup_Filter(eg_allentities, EBP.ALLIES.MG_NEST, FILTER_KEEP)
		EGroup_AddEGroup(eg_player3mgnest, eg_allentities)
		OBJ_BUILDING_MGNEST.PingID = Objective_AddUIElements(OBJ_BUILDING_MGNEST, eg_player3mgnest, false, 409592, true)
 		Rule_AddInterval(Building_MGNest_RestartedConstruction, 0.5)
		
	end
	
end

function Building_MGNest_StartAttack()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		local pos = World_GetHiddenPositionOnPath(player1, mkr_building_spawnenemy1, mkr_building_wirestop, CHECK_IN_FOW)
		if pos == nil then
			pos = Marker_GetPosition(mkr_building_spawnenemy1)
		end
		Util_CreateSquads(player2, sg_group3, SBP.AXIS.GRENADIER, pos, nil, 3)
		Modify_Vulnerability(sg_group3, 2)
		Cmd_Attack(sg_group3, eg_player3mgnest)
		
		SGroup_SetInvulnerable(sg_playerunits, true)
		
		Util_StartIntel(EVENTS.BuildingMGNestAttack)
		
		Rule_AddInterval(Building_MGNest_AttackSuppressed, 0.5)
		Rule_AddInterval(Building_MGNest_AttackDone, 0.5)
		
	end

end

function Building_MGNest_AttackSuppressed()
	
	if SGroup_IsSuppressed(sg_group3, ANY) then
		
		Rule_RemoveMe()
		
		Util_StartIntel(EVENTS.BuildingMGNestSuppressingEnemy)
		
	end

end

function Building_MGNest_AttackDone()
	
	if SGroup_TotalMembersCount(sg_group3) <= 7 then
		
		Rule_RemoveMe()
		
		Cmd_Retreat(sg_group3, Marker_GetPosition(mkr_building_spawnenemy1))
		Util_StartIntel(EVENTS.BuildingMGNestAttackDone)
		
		Rule_AddInterval(Building_MGNest_AttackRemoveEnemies, 1)
		Rule_AddInterval(Building_Garrisson_BeginLesson, 0.5)
		
	end

end


function Building_MGNest_AttackRemoveEnemies()

	if SGroup_Count(sg_group3) == 0 then
		Rule_RemoveMe()
		SGroup_SetInvulnerable(sg_playerunits, false)
	elseif Player_CanSeeSGroup(player1, sg_group3, ANY) == false then
		Rule_RemoveMe()
		SGroup_DestroyAllSquads(sg_group3)
		SGroup_SetInvulnerable(sg_playerunits, false)
	end
	
end





--
-- Lesson: Garrisson
--
function Building_Garrisson_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- allow garrisonning
		Player_SetCommandAvailability(player1, SCMD_Load, ITEM_DEFAULT)
		
		Camera_MoveToPosition(mkr_building_house_camerafocus, true, SLOW_CAMERA_PANNING)
		Camera_SafetyDefault()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingGarrissonIntro)	
		
		Rule_AddInterval(Building_Garrisson_GiveObjective, 0.5)
		
	end
	
end


function Building_Garrisson_GiveObjective()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_GARRISSON, false)
		
		Modify_DisableHold(eg_building_house, false)
		
		if Misc_IsSGroupSelected(sg_engineer, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingGarrissonGiveObjective)	
			
			OBJ_BUILDING_GARRISSON.PingID = Objective_AddUIElements(OBJ_BUILDING_GARRISSON, eg_building_house, false, 409560, true)
			
			Rule_AddInterval(Building_Garrisson_Done, 0.5)
			
		else
			
			-- ask to select engineers
			Util_StartIntel(EVENTS.EngineersSelect)
			
			OBJ_BUILDING_GARRISSON.PingID = Objective_AddUIElements(OBJ_BUILDING_GARRISSON, sg_engineer, false, 409551, true)
			
			Rule_AddInterval(Building_Garrisson_EngineersSelected, 0.5)
			
		end
		
	end
	
end


function Building_Garrisson_EngineersSelected()
	
	if Misc_IsSGroupSelected(sg_engineer, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingGarrissonGiveObjective)	
		
		Objective_RemoveUIElements(OBJ_BUILDING_GARRISSON, OBJ_BUILDING_GARRISSON.PingID)
		OBJ_BUILDING_GARRISSON.PingID = Objective_AddUIElements(OBJ_BUILDING_GARRISSON, eg_building_house, false, 409560, true)
		
		Rule_AddInterval(Building_Garrisson_Done, 0.5)
		
	end
	
end


function Building_Garrisson_Done()
	
	if Player_OwnsEGroup(player1, eg_building_house) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Util_StartIntel(EVENTS.BuildingGarrissonDone)
		Player_SetCommandAvailability(player1, SCMD_Load, ITEM_LOCKED)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_GARRISSON, false)
		
		UI_BindingSetEnabled("command_unload_here", false)
		UI_BindingSetEnabled("command_unload_individual_squad", false)
		UI_BindingSetEnabled("hold_slot_frames", false)
		UI_BindingSetEnabled("hold occupants", false)
		SGroup_SetSelectable(sg_engineer, false)
		
		Rule_AddInterval(Building_Ambient_BeginLesson, 0.5)
		
	elseif Misc_IsSGroupSelected(sg_engineer, ANY) == false and SGroup_IsIdle(sg_engineer, ANY) == true then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- ask to re-select engineers
		Util_StartIntel(EVENTS.EngineersReSelect)
		
		Objective_RemoveUIElements(OBJ_BUILDING_GARRISSON, OBJ_BUILDING_GARRISSON.PingID)
		OBJ_BUILDING_GARRISSON.PingID = Objective_AddUIElements(OBJ_BUILDING_GARRISSON, sg_engineer, false, 409551, true)
		
		Rule_AddInterval(Building_Garrisson_EngineersSelected, 0.5)
		
	end
	
end

function SGroup_IsIdle(group, all)
	
	local _CheckSquad = function (gid, idx, sid)
		if Squad_HasActiveCommand(sid) then
			print(Squad_GetActiveCommand(sid))
			if Squad_GetActiveCommand(sid) == SQUADSTATEID_Idle then
				return true
			else
				return false
			end
		else
			return true
		end
	end
	
	return SGroup_ForEachAllOrAny(group, all, _CheckSquad)
	
end



--
-- Lesson: Ambient Building Upgrade
--
function Building_Ambient_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- ensure the player has enough resources
		Tutorial_SafetySetResources(cost.ambientupgrade)		
		
		Player_SetUpgradeAvailability(player1, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, ITEM_DEFAULT)
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_AMBIENTUPGRADE, false)
		
		if Misc_IsEGroupSelected(eg_building_house, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingAmbientIntro)
			
			flashid_building_ambientupgrade = UI_FlashProductionButton(PITEM_Upgrade, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, true, BT_UI_Strong_CommandBtn )
			hpid_building_ambientupgrade = HintPoint_AddToProductionButton(PITEM_Upgrade, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, 409587, true)
			
			Rule_Add(Building_Ambient_Upgrading)
			
		else
			
			-- ask to select house
			Util_StartIntel(EVENTS.BuildingSelect)
			
			OBJ_BUILDING_AMBIENTUPGRADE.PingID = Objective_AddUIElements(OBJ_BUILDING_AMBIENTUPGRADE, eg_building_house, false, 409561, true)
			
			Rule_AddInterval(Building_Ambient_HouseSelected, 0.5)
			
		end
		
	end
	
end


function Building_Ambient_HouseSelected()

	if Misc_IsEGroupSelected(eg_building_house, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingAmbientIntro)
		
		Objective_RemoveUIElements(OBJ_BUILDING_AMBIENTUPGRADE, OBJ_BUILDING_AMBIENTUPGRADE.PingID)
		
		flashid_building_ambientupgrade = UI_FlashProductionButton(PITEM_Upgrade, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, true, BT_UI_Strong_CommandBtn )
		hpid_building_ambientupgrade = HintPoint_AddToProductionButton(PITEM_Upgrade, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, 409587, true)
		
		Rule_Add(Building_Ambient_Upgrading)
		
	end

end


function Building_Ambient_Upgrading()


	if EGroup_IsProducingUpgrade(eg_building_house, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Util_StartIntel(EVENTS.BuildingAmbientUpgrading)
		
		Rule_AddInterval(Building_Ambient_Done, 0.5)
		
	elseif Misc_IsEGroupSelected(eg_building_house, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_ambientupgrade)
		HintPoint_Remove(hpid_building_ambientupgrade)
		
		-- ask to re-select house
		Util_StartIntel(EVENTS.BuildingReSelect)
		
		OBJ_BUILDING_AMBIENTUPGRADE.PingID = Objective_AddUIElements(OBJ_BUILDING_AMBIENTUPGRADE, eg_building_house, false, 409561, true)
		
		Rule_AddInterval(Building_Ambient_HouseSelected, 0.5)
		
	end

end


function Building_Ambient_Done()
	
	if EGroup_HasUpgrade(eg_building_house, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, ANY) then
		
		Rule_RemoveMe()
		
		Util_StartIntel(EVENTS.BuildingAmbientDone)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_AMBIENTUPGRADE, false)
		
		Rule_AddInterval(Building_BuildSquad_BeginLesson, 0.5)
		
	elseif EGroup_IsProducingUpgrade(eg_building_house, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		if Misc_IsEGroupSelected(eg_building_house, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingAmbientIntro)
			
			flashid_building_ambientupgrade = UI_FlashProductionButton(PITEM_Upgrade, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, true, BT_UI_Strong_CommandBtn )
			hpid_building_ambientupgrade = HintPoint_AddToProductionButton(PITEM_Upgrade, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, 409587, true)
			
			Rule_AddInterval(Building_Ambient_Upgrading, 0.5)
			
		else
			
			-- ask to select house
			Util_StartIntel(EVENTS.BuildingSelect)
			
			OBJ_BUILDING_AMBIENTUPGRADE.PingID = Objective_AddUIElements(OBJ_BUILDING_AMBIENTUPGRADE, eg_building_house, false, 409561, true)
			
			Rule_AddInterval(Building_Ambient_HouseSelected, 0.5)
			
		end
		
	end
	
end



--
-- Lesson: Produce Squad
--
function Building_BuildSquad_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- ensure the player has enough resources
		Tutorial_SafetySetResources(cost.riflemen)		
		
		-- unlock the riflemen button
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_DEFAULT)
		EGroup_SetSelectable(eg_player3barracks, false)
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_BUILDARMY, false)
		
		if Misc_IsEGroupSelected(eg_building_house, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingAmbientBuildRiflemen)
			
			flashid_building_buildriflemen = UI_FlashProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, true, BT_UI_Strong_CommandBtn )
			
			Rule_AddInterval(Building_BuildSquad_Building, 0.5)
			
		else
			
			-- ask to select house
			Util_StartIntel(EVENTS.BuildingSelect)
			
			OBJ_BUILDING_BUILDARMY.PingID = Objective_AddUIElements(OBJ_BUILDING_BUILDARMY, eg_building_house, false, 409561, true)
			
			Rule_AddInterval(Building_BuildSquad_HouseSelected, 0.5)
			
		end
		
	end
	
end


function Building_BuildSquad_HouseSelected()

	if Misc_IsEGroupSelected(eg_building_house, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingAmbientBuildRiflemen)
		
		Objective_RemoveUIElements(OBJ_BUILDING_BUILDARMY, OBJ_BUILDING_BUILDARMY.PingID)
		flashid_building_buildriflemen = UI_FlashProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, true, BT_UI_Strong_CommandBtn )
		
		Rule_AddInterval(Building_BuildSquad_Building, 0.5)
		
	end

end


function Building_BuildSquad_Building()

	if EGroup_IsProducingSquad(eg_building_house, SBP.ALLIES.RIFLEMEN, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_buildriflemen)
		
		-- lock out the riflemen button
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_LOCKED)
		
		Rule_AddInterval(Building_BuildSquad_Done, 0.5)
		
	elseif Misc_IsEGroupSelected(eg_building_house, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- ask to re-select house
		Util_StartIntel(EVENTS.BuildingReSelect)
		
		OBJ_BUILDING_BUILDARMY.PingID = Objective_AddUIElements(OBJ_BUILDING_BUILDARMY, eg_building_house, false, 409561, true)
		
		Rule_AddInterval(Building_BuildSquad_HouseSelected, 0.5)
		
	end

end


function Building_BuildSquad_Done()
	
	Player_GetAll(player1)
	SGroup_Filter(sg_allsquads, SBP.ALLIES.RIFLEMEN, FILTER_KEEP)
	
	if SGroup_Count(sg_allsquads) >= 2 then
		
		Rule_RemoveMe()
		
		Util_StartIntel(EVENTS.BuildingAmbientBuildRiflemenDone)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_BUILDARMY, false)
		
		SGroup_Clear(sg_group2)
		SGroup_AddGroup(sg_playerunits, sg_allsquads)
		SGroup_RemoveGroup(sg_allsquads, sg_group1)
		SGroup_AddGroup(sg_group2, sg_allsquads)
		
		EGroup_SetSelectable(eg_player3barracks, true)
		
		Rule_AddInterval(Building_SquadCap_BeginLesson, 0.5)
		
	elseif EGroup_IsProducingSquad(eg_building_house, SBP.ALLIES.RIFLEMEN, ANY) == false then
		
		Rule_RemoveMe()
		
		-- unlock the riflemen button
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_DEFAULT)
		
		if Misc_IsEGroupSelected(eg_building_house, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingAmbientBuildRiflemen)
			
			flashid_building_buildriflemen = UI_FlashProductionButton(PITEM_Spawn, SBP.ALLIES.RIFLEMEN, true, BT_UI_Strong_CommandBtn )
			
			Rule_AddInterval(Building_BuildSquad_Building, 0.5)
			
		else
			
			-- ask to select house
			Util_StartIntel(EVENTS.BuildingSelect)
			
			OBJ_BUILDING_BUILDARMY.PingID = Objective_AddUIElements(OBJ_BUILDING_BUILDARMY, eg_building_house, false, 409561, true)
			
			Rule_AddInterval(Building_BuildSquad_HouseSelected, 0.5)
			
		end
		
	end
	
end



--
-- Lesson: Increase Squad Cap
--
function Building_SquadCap_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- change perimeters
		EGroup_DeSpawn(LAYER_wall_building_4)
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_SQUADCAP, false)
		
		Player_GetAll(player1)
		buildings_playercount = SGroup_TotalMembersCount(sg_allsquads)
		
		Camera_ClampToMarker(camera_basebuilding_e)
		EGroup_SetSelectable(eg_building_squadcappoint1, true)
		FOW_RevealArea(EGroup_GetPosition(eg_building_squadcappoint1), 10, -1)
		
		Rule_Add(Building_SquadCap_CheckSquads)
		
		if Misc_IsSGroupSelected(sg_group2, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingSquadCapFirstPointGiveObjective)
			
			OBJ_BUILDING_SQUADCAP.PingID = Objective_AddUIElements(OBJ_BUILDING_SQUADCAP, eg_building_squadcappoint1, false, 409555, true, 2)
			
			Rule_AddInterval(Building_SquadCap_Flag1, 0.5)
			
		else
			
			-- ask to select riflemen
			Util_StartIntel(EVENTS.RiflemenSelect)
			
			OBJ_BUILDING_SQUADCAP.PingID = Objective_AddUIElements(OBJ_BUILDING_SQUADCAP, sg_group2, false, 409562, true)
			
			Rule_AddInterval(Building_SquadCap_RiflemenSelected, 0.5)
			
		end
		
	end
	
end


function Building_SquadCap_RiflemenSelected()
	
	if Misc_IsSGroupSelected(sg_group2, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingSquadCapFirstPointGiveObjective)
		
		Objective_RemoveUIElements(OBJ_BUILDING_SQUADCAP, OBJ_BUILDING_SQUADCAP.PingID)
		OBJ_BUILDING_SQUADCAP.PingID = Objective_AddUIElements(OBJ_BUILDING_SQUADCAP, eg_building_squadcappoint1, false, 409555, true, 2)
		
		Rule_AddInterval(Building_SquadCap_Flag1, 0.5)
		
	end
	
end


function Building_SquadCap_Flag1()
	
	if Player_OwnsEGroup(player1, eg_building_squadcappoint1) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- fake the pop cap increase
		Player_SetPopCapOverride(player1, 29)
		
		Util_StartIntel(EVENTS.BuildingSquadCapFirstPointCaptured)
		
		Objective_RemoveUIElements(OBJ_BUILDING_SQUADCAP, OBJ_BUILDING_SQUADCAP.PingID)
		
		-- create the wall to trap the player here temporarily
		EGroup_ReSpawn(LAYER_wall_building_5)
		
		Player_GetAll(player1)
		SGroup_AddGroup(sg_playerunits, sg_allsquads)
		FOW_UnRevealArea(EGroup_GetPosition(eg_building_squadcappoint1), 10)
		
		Modify_ReceivedSuppression(sg_playerunits, 2)
		Rule_AddSGroupEvent(Building_Retreat_Activated, sg_playerunits, GE_SquadCommandIssued)
		
		Rule_AddOneShot(Building_SquadCap_CreateEnemy, 0.5)
		
		Rule_AddInterval(Building_SquadCap_Suppressed, 0.5)
		
	elseif Misc_IsSGroupSelected(sg_group2, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- ask to re-select riflemen
		Util_StartIntel(EVENTS.RiflemenReSelect)
		
		Objective_RemoveUIElements(OBJ_BUILDING_SQUADCAP, OBJ_BUILDING_SQUADCAP.PingID)
		OBJ_BUILDING_SQUADCAP.PingID = Objective_AddUIElements(OBJ_BUILDING_SQUADCAP, sg_group2, false, 409562, true)
		
		Rule_AddInterval(Building_SquadCap_RiflemenSelected, 0.5)
		
	end
	
end


function Building_SquadCap_CreateEnemy()
	
	Player_GetAllSquadsNearMarker(player1, sg_friends, EGroup_GetPosition_EVEN_IF_EMPTY(eg_building_squadcappoint2) , 60)
	
	Util_CreateSquads(player2, sg_group9, SBP.AXIS.HALFTRACK, mkr_building_spawnenemy1, nil, 1)
	Util_CreateSquads(player2, sg_group8, SBP.AXIS.GRENADIER, mkr_building_spawnenemy1, nil, 2)
	Util_CreateSquads(player2, sg_group7, SBP.AXIS.GRENADIER, sg_group9, nil, 1)
	
	SGroup_SetInvulnerable(sg_group9, true)
	
	Cmd_Move(sg_group9, mkr_building_attackdest1)
	Cmd_AttackMove(sg_group9, sg_friends, true)
	
	Cmd_AttackMove(sg_group8, mkr_building_attackdest2)
	Cmd_AttackMove(sg_group8, sg_friends, true)
	
	Cmd_AttackMove(sg_group3, mkr_building_attackdest2)
	
	Rule_AddInterval(Building_SquadCap_CreateMoreEnemies, 1)
	
end


function Building_SquadCap_CreateMoreEnemies()

	if SGroup_TotalMembersCount(sg_group8) <= 3 then
		Util_CreateSquads(player2, sg_group8, SBP.AXIS.GRENADIER, mkr_building_spawnenemy1, nil, 1)
		Cmd_AttackMove(sg_group8, mkr_building_attackdest2)
		Cmd_AttackMove(sg_group8, sg_friends, true)
	end
	
end


function Building_SquadCap_CheckSquads()

	Player_GetAll(player1)

	if SGroup_TotalMembersCount(sg_allsquads) > buildings_playercount then
		
		buildings_playercount = SGroup_TotalMembersCount(sg_allsquads)
		
	elseif (buildings_playercount - SGroup_TotalMembersCount(sg_allsquads)) >= 2  then
		
		Rule_RemoveMe()
		SGroup_SetInvulnerable(sg_allsquads, true)
		
	end

end

function Building_SquadCap_Suppressed()

	Player_GetAll(player1)
	
	if Event_IsAnyRunning() == false and SGroup_IsSuppressed(sg_allsquads, ANY) then
		
		Rule_RemoveMe()
		
		SGroup_Clear(sg_temp)
		local _CheckSquad = function (gid, idx, sid)
			if Squad_IsSuppressed(sid) then
				SGroup_Add(sg_temp, sid)
			end
		end
		SGroup_ForEach(sg_allsquads, _CheckSquad)
		Camera_MoveToSGroup(sg_temp, true, SLOW_CAMERA_PANNING)
		Camera_SafetyDefault()
		
		Util_StartIntel(EVENTS.BuildingSquadCapSuppressed)
		Modifier_RemoveAllFromSGroup(sg_playerunits)
		
		Rule_AddInterval(Building_SquadCap_CheckForPinned, 0.5)
		
	end

end
	
function Building_SquadCap_CheckForPinned()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		Modify_ReceivedSuppression(sg_playerunits, 2)
		
		Rule_AddInterval(Building_SquadCap_Pinned, 0.5)
		
	end
	
end

function Building_SquadCap_Pinned()
	
	Player_GetAll(player1)
	
	if SGroup_IsPinned(sg_allsquads, ANY) then
		
		Rule_RemoveMe()
		if Rule_Exists(Building_SquadCap_CreateMoreEnemies) then Rule_Remove(Building_SquadCap_CreateMoreEnemies) end
		
		SGroup_Clear(sg_temp)
		local _CheckSquad = function (gid, idx, sid)
			if Squad_IsPinned(sid) then
				SGroup_Add(sg_temp, sid)
			end
		end
		SGroup_ForEach(sg_allsquads, _CheckSquad)
		Camera_MoveToSGroup(sg_temp, true, SLOW_CAMERA_PANNING)
		Camera_SafetyDefault()
		
		Util_StartIntel(EVENTS.BuildingSquadCapPinned)
		Rule_AddInterval(Building_Retreat_BeginLesson, 0.5)
		
		if Rule_Exists(Building_SquadCap_CheckSquads) then
			
			Player_GetAll(player1)
			
			local kill = 2 - (buildings_playercount - SGroup_TotalMembersCount(sg_allsquads))
			local dist = 500
			local _FindClosest = function (gid, idx, sid)
				local thisdist = World_DistanceEGroupToPoint(eg_building_squadcappoint1, Squad_GetPosition(sid), true)
				if thisdist < dist then
					dist = thisdist
					closestsquad = sid
				end
			end
			SGroup_ForEach(sg_allsquads, _FindClosest)
			
			Entity_Kill(Squad_EntityAt(closestsquad, 0))
			Entity_Kill(Squad_EntityAt(closestsquad, 0))
			
		end
		
	end

end



--
-- Lesson: Retreat
--
function Building_Retreat_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- update the objective
		Objective_StopCounter(OBJ_BUILDING_SQUADCAP)
		Objective_UpdateText(OBJ_BUILDING_SQUADCAP, 409540, 409541, false)		
		
		Player_SetCommandAvailability(player1, SCMD_Retreat, ITEM_DEFAULT)
		
		if Misc_IsSGroupSelected(sg_allsquads, ANY) == true then
			
			if Rule_Exists(Building_Retreat_Activated) then
				flashid_building_retreat = UI_FlashCommandButton(SCMD_Retreat, false, BT_UI_Strong_CommandBtn )
				hpid_building_retreat = HintPoint_AddToCommandButton(SCMD_Retreat, 409582, false)
			end
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingRetreatIntro)
			
			Rule_AddInterval(Building_Retreat_Deselected, 0.5)
			
		else
			
			Util_StartIntel(EVENTS.RiflemenSelect)
			
			OBJ_BUILDING_SQUADCAP.PingID = Objective_AddUIElements(OBJ_BUILDING_SQUADCAP, sg_allsquads, false, 409562, true)
			
			Rule_AddInterval(Building_Retreat_Selected, 0.5)
			
		end
		
	end
	
end

function Building_Retreat_Selected()

	if Misc_IsSGroupSelected(sg_allsquads, ANY) == true then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		Objective_RemoveUIElements(OBJ_BUILDING_SQUADCAP, OBJ_BUILDING_SQUADCAP.PingID)
		
		if Rule_Exists(Building_Retreat_Activated) then
			flashid_building_retreat = UI_FlashCommandButton(SCMD_Retreat, false, BT_UI_Strong_CommandBtn )
			hpid_building_retreat = HintPoint_AddToCommandButton(SCMD_Retreat, 409582, false)
		end
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingRetreatIntro)
		
		Rule_AddInterval(Building_Retreat_Deselected, 0.5)
		
	end
	
end

function Building_Retreat_Deselected()

	if Misc_IsSGroupSelected(sg_allsquads, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_retreat)
		HintPoint_Remove(hpid_building_retreat)
		
		Objective_RemoveUIElements(OBJ_BUILDING_SQUADCAP, OBJ_BUILDING_SQUADCAP.PingID)
		OBJ_BUILDING_SQUADCAP.PingID = Objective_AddUIElements(OBJ_BUILDING_SQUADCAP, sg_allsquads, false, 409562, true)
		
		Util_StartIntel(EVENTS.RiflemenReSelect)
		
		Rule_AddInterval(Building_Retreat_Selected, 0.5)
		
	end

end

function Building_Retreat_Activated(squad, commandID, target)
	
	if commandID == SCMD_Retreat then
		
		Rule_RemoveSGroupEvent(Building_Retreat_Activated, sg_playerunits)
		Game_SkipEvent()
		
		if Rule_Exists(Building_Retreat_BeginLesson) then Rule_Remove(Building_Retreat_BeginLesson) end
		if Rule_Exists(Building_Retreat_Deselected) then Rule_Remove(Building_Retreat_Deselected) end
		if Rule_Exists(Building_Retreat_Selected) then Rule_Remove(Building_Retreat_Selected) end
		if hpid_building_retreat ~= nil then HintPoint_Remove(hpid_building_retreat) end
		if flashid_building_retreat ~= nil then UI_StopFlashing(flashid_building_retreat) end
		
		Util_StartIntel(EVENTS.BuildingRetreatDone)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_SQUADCAP, false)
		
		-- remove the wall that traps the player here
		EGroup_DeSpawn(LAYER_wall_building_5)
		
		Modifier_RemoveAllFromSGroup(sg_playerunits)
		
		Rule_AddOneShot(Building_Retreat_FollowGuys, 0.5)
		Rule_AddInterval(Building_Retreat_WarpForward, 0.5)
		
	end
	
end

function Building_Retreat_FollowGuys()

	SGroup_Clear(sg_group6)
	local _CheckSquad = function (gid, idx, sid)
		if Squad_IsRetreating(sid) then
			SGroup_Add(sg_group6, sid)
		end
	end
	SGroup_ForEach(sg_playerunits, _CheckSquad)
	Camera_FollowSGroup(sg_group6)
	
end

function Building_Retreat_WarpForward()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		Game_FadeToBlack(FADE_OUT, TIMING_FADE_OUT)
		Rule_AddOneShot(Building_Retreat_WarpForwardB, TIMING_FADE_OUT)
		
	end
	
end
function Building_Retreat_WarpForwardB()

	Camera_MoveToPosition(mkr_building_camera_hq)
	Camera_ResetToDefault()
	
	SGroup_DestroyAllSquads(sg_group7)
	SGroup_DestroyAllSquads(sg_group8)
	SGroup_DestroyAllSquads(sg_group9)
	
	SGroup_WarpToMarker(sg_group6, mkr_building_retreatwarp)
	
	Rule_AddOneShot(Building_Retreat_WarpForwardC, TIMING_BLACK)

end
function Building_Retreat_WarpForwardC()

	Game_FadeToBlack(FADE_IN, TIMING_FADE_IN)
	
	Rule_AddInterval(Building_Retreat_ReachedBarracks, TIMING_FADE_IN)

end


function Building_Retreat_ReachedBarracks()
	
	if SGroup_IsRetreating(sg_playerunits, ANY) == false then
		
		Rule_RemoveMe()
		
		SGroup_SetInvulnerable(sg_playerunits, false)
		Rule_AddInterval(Building_Reinforce_BeginLesson, 0.5)
		
	end
	
end


--
-- Lesson: Reinforce
--
function Building_Reinforce_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		Player_GetAll(player1)
		SGroup_SetInvulnerable(sg_allsquads, false)
		-- give the player access to reinforce this type of squad
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_DEFAULT)
		-- however prevent them from building anymore from the barracks.
		EGroup_SetSelectable(eg_player3barracks, false)
		EGroup_SetSelectable(eg_building_house, false)
		
		building_reinforceclickcount = 2
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingReinforceIntro)
		
		Rule_AddInterval(Building_Reinforce_GiveObjective, 0.5)
		
	end
	
end

function Building_Reinforce_GiveObjective()

	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_REINFORCE, false)
		
		if Misc_IsSGroupSelected(sg_group6, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingReinforceGiveObjective)
			
			flashid_building_reinforce = UI_FlashProductionButton(PITEM_SquadReinforce, SBP.ALLIES.RIFLEMEN, false, BT_UI_Strong_UpgradeBtn )
			hpid_building_reinforce = HintPoint_AddToProductionButton(PITEM_SquadReinforce, SBP.ALLIES.RIFLEMEN, 409583, false)
			
			Rule_AddSGroupEvent(Building_Reinforce_Activated, sg_playerunits, GE_SquadCommandIssued)
			Rule_AddInterval(Building_Reinforce_RiflemenDeSelected, 0.5)
			
		else
			
			-- ask to select riflemen
			Util_StartIntel(EVENTS.RiflemenSelect)
			
			OBJ_BUILDING_REINFORCE.PingID = Objective_AddUIElements(OBJ_BUILDING_REINFORCE, sg_group6, false, 409562, true)
			
			Rule_AddInterval(Building_Reinforce_RiflemenSelected, 0.5)
			
		end
		
	end
	
end

function Building_Reinforce_RiflemenSelected()

	if Misc_IsSGroupSelected(sg_group6, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingReinforceGiveObjective)
		
		Objective_RemoveUIElements(OBJ_BUILDING_REINFORCE, OBJ_BUILDING_REINFORCE.PingID)
		
		flashid_building_reinforce = UI_FlashProductionButton(PITEM_SquadReinforce, SBP.ALLIES.RIFLEMEN, false, BT_UI_Strong_UpgradeBtn )
		hpid_building_reinforce = HintPoint_AddToProductionButton(PITEM_SquadReinforce, SBP.ALLIES.RIFLEMEN, 409583, false)
		
		Rule_AddSGroupEvent(Building_Reinforce_Activated, sg_playerunits, GE_SquadCommandIssued)
		Rule_AddInterval(Building_Reinforce_RiflemenDeSelected, 0.5)
		
	end
	
end

function Building_Reinforce_RiflemenDeSelected()

	if Misc_IsSGroupSelected(sg_group6, ANY) == false then
		
		Rule_RemoveMe()
		Rule_RemoveSGroupEvent(Building_Reinforce_Activated, sg_playerunits)
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_reinforce)
		HintPoint_Remove(hpid_building_reinforce)
		
		-- ask to select riflemen
		Util_StartIntel(EVENTS.RiflemenReSelect)
		
		OBJ_BUILDING_REINFORCE.PingID = Objective_AddUIElements(OBJ_BUILDING_REINFORCE, sg_group6, false, 409562, true)
		
		Rule_AddInterval(Building_Reinforce_RiflemenSelected, 0.5)
		
	end
	
end

function Building_Reinforce_Activated(squad, commandID, target)
	
	if commandID == SCMD_ReinforceUnit then
		
		building_reinforceclickcount = 	building_reinforceclickcount - 1
		
		if 	building_reinforceclickcount <= 0 then
			
			if Rule_Exists(Building_Reinforce_RiflemenSelected) then Rule_Remove(Building_Reinforce_RiflemenSelected) end
			if Rule_Exists(Building_Reinforce_RiflemenDeSelected) then Rule_Remove(Building_Reinforce_RiflemenDeSelected) end
			
			Util_StartIntel(EVENTS.BuildingReinforceDone)
			
			UI_StopFlashing(flashid_building_reinforce)
			HintPoint_Remove(hpid_building_reinforce)
			
			building_reinforcecount = SGroup_TotalMembersCount(sg_playerunits)
			Rule_RemoveSGroupEvent(Building_Reinforce_Activated, sg_playerunits)
			Rule_AddInterval(Building_Reinforce_Done, 0.5)
			
		end
		
	end
	
end

function Building_Reinforce_Done()
	
	if SGroup_TotalMembersCount(sg_playerunits) > building_reinforcecount then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_REINFORCE, false)
		
		-- set the barracks to selectable again, in case it is needed for other tutorials.
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_LOCKED)
		EGroup_SetSelectable(eg_player3barracks, true)
		EGroup_SetSelectable(eg_building_house, true)
		
		Rule_AddInterval(Building_CommandPoints1_BeginLesson, 0.5)
		
	else
		reinforcecount = SGroup_TotalMembersCount(sg_playerunits)
	end
	
end






--
-- Lesson: Command Points 1
--
function Building_CommandPoints1_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- change perimeters
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_COMMANDMENU, false)
		
		Util_StartIntel(EVENTS.BuildingCommanderIntro)
		
		-- ensure the player has enough command points
		local points = Player_GetResource(player1, RT_Command)
		if points < 1 then
			Player_AddUnspentCommandPoints(player1, (1 - points))
		end
		
		-- unlock the upgrade
		Player_SetUpgradeAvailability(player1, UPG.COMMANDER_TREE.ALLIES.INFANTRY_10, ITEM_UNLOCKED)
		
		-- lockouts
		UI_BindingSetEnabled("company_commander", true)
		Rule_AddOneShot(Building_CommandPoints1_PingButton, 0.1)
		
		Rule_AddInterval(Building_CommandPoints1_GiveObjective, 0.5)
		
	end
	
end

function Building_CommandPoints1_PingButton()
	hpid_building_cc = HintPoint_AddToTaskbarBinding("company_commander", 409579, true)
	flashid_building_cc = UI_FlashBinding("company_commander", true, BT_UI_Weak_CommanderBtn )
end

function Building_CommandPoints1_GiveObjective()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		UI_StopFlashing(flashid_building_cc)
		flashid_building_cc = UI_FlashBinding("company_commander", true, BT_UI_Strong_CommanderBtn )
		
		Util_StartIntel(EVENTS.BuildingCommanderClickButton)
		
		Rule_AddInterval(Building_CommandPoints1_InCommanderMenu, 0.5)
		
	end

end

function Building_CommandPoints1_InCommanderMenu()
	
	if UI_IsCommanderTreeShown() then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_cc)
		HintPoint_Remove(hpid_building_cc)
		
		Util_StartIntel(EVENTS.BuildingCommanderBranches)
		
		-- give the objective
		
		Rule_AddInterval(Building_CommandPoints1_InInfantryTree, 0.5)
		
	end
	
end

function Building_CommandPoints1_InInfantryTree()
	
	if Player_HasUpgrade(player1, UPG.COMMANDER_TREE.ALLIES.INFANTRY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashingCommanderTreeUpgrade(flashid_building_cc_tree)
		
		Util_StartIntel(EVENTS.BuildingCommanderSkills)
		
		-- give the objective
		
		Rule_AddInterval(Building_CommandPoints1_OutOfCommanderMenu, 0.5)
		
	end
	
end

function Building_CommandPoints1_OutOfCommanderMenu()
	
	if Player_HasUpgrade(player1, UPG.COMMANDER_TREE.ALLIES.INFANTRY_10) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashingCommanderBranchUpgrade(flashid_building_cc_branch1)
		
		-- change perimeters
		
		Objective_Complete(OBJ_BUILDING_COMMANDMENU, false)
		
		Rule_AddInterval(Building_Defences_BeginLesson, 0.5)
		
	end
	
end



--
-- Lesson: Build Defences
--
function Building_Defences_BeginLesson()

	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingDefencesIntro)
		
		-- unlock the riflemen button
		Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_DEFAULT)
		
		Camera_MoveToPosition(mkr_building_mgnest, true, SLOW_CAMERA_PANNING)
		Camera_SafetyDefault()
		Tutorial_WarpGuys(sg_group1, mkr_building_engineerforwardrally)
		SGroup_SetSelectable(sg_group1, true)
		
		-- brw 08/02/07 - increased the addinterval time so that the riflemen are properly 
		-- marked with the objective hintpoint because the warping takes some sim time.
		Rule_AddInterval(Building_Defences_GiveObjective, 1)
		
	end
	
end

function Building_Defences_GiveObjective()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- change perimeters
		Player_SetEntityProductionAvailability(player1, EBP.ALLIES.SANDBAG_RIFLEMEN, ITEM_DEFAULT)
		Player_SetConstructionMenuAvailability(player1, "tp_construction_rifleman_basic", ITEM_DEFAULT)
		UI_RestrictBuildingPlacement(mkr_building_sandbagstart)
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_DEFENCES, false)
		
		if Misc_IsSGroupSelected(sg_group1, ANY) then
			
			-- give the introductory talk
			Util_StartIntel(EVENTS.BuildingDefencesGiveObjective)
			
			flashid_building_sandbags1 = UI_FlashConstructionMenu("tp_construction_rifleman_basic", false, BT_UI_Strong_CommandBtn )
			hpid_building_sandbags1 = HintPoint_AddToConstructionMenu("tp_construction_rifleman_basic", 409571, false)
			
			UI_SetConstructionMenuCallback(Building_Defences_ClickedBuildMenu)
			UI_SetBuildingPlacementCallback(Building_Defences_Placing)
			
			Rule_AddInterval(Building_Defences_RiflemenDeSelected, 0.5)
			
		else
			
			-- ask to select riflemen
			Util_StartIntel(EVENTS.RiflemenSelect)
			
			OBJ_BUILDING_DEFENCES.PingID = Objective_AddUIElements(OBJ_BUILDING_DEFENCES, sg_group1, false, 409562, true)
			
			Rule_AddInterval(Building_Defences_RiflemenSelected, 0.5)
			
		end
		
	end
	
end


function Building_Defences_RiflemenSelected()

	if Misc_IsSGroupSelected(sg_group1, ANY) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		-- give the introductory talk
		Util_StartIntel(EVENTS.BuildingDefencesGiveObjective)
		
		Objective_RemoveUIElements(OBJ_BUILDING_DEFENCES, OBJ_BUILDING_DEFENCES.PingID)
		
		flashid_building_sandbags1 = UI_FlashConstructionMenu("tp_construction_rifleman_basic", false, BT_UI_Strong_CommandBtn )
		hpid_building_sandbags1 = HintPoint_AddToConstructionMenu("tp_construction_rifleman_basic", 409571, false)
		
		UI_SetConstructionMenuCallback(Building_Defences_ClickedBuildMenu)
		UI_SetBuildingPlacementCallback(Building_Defences_Placing)
		
		Rule_AddInterval(Building_Defences_RiflemenDeSelected, 0.5)
		
	end
	
end

function Building_Defences_RiflemenDeSelected()

	if Misc_IsSGroupSelected(sg_group1, ANY) == false then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_sandbags1)
		HintPoint_Remove(hpid_building_sandbags1)
		
		UI_ClearConstructionMenuCallback()
		UI_ClearBuildingPlacementCallback()
		
		-- ask to select riflemen
		Util_StartIntel(EVENTS.RiflemenSelect)
		
		Objective_RemoveUIElements(OBJ_BUILDING_DEFENCES, OBJ_BUILDING_DEFENCES.PingID)
		OBJ_BUILDING_DEFENCES.PingID = Objective_AddUIElements(OBJ_BUILDING_DEFENCES, sg_group1, false, 409562, true)
		
		Rule_AddInterval(Building_Defences_RiflemenSelected, 0.5)
		
	end

end


function Building_Defences_ClickedBuildMenu(menuname, activated)
	if menuname == "tp_construction_rifleman_basic" then
		if activated == true then
			flashid_building_sandbags2 = UI_FlashConstructionButton(EBP.ALLIES.SANDBAG_RIFLEMEN, false, BT_UI_Strong_CommandBtn )
			hpid_building_sandbags2 = HintPoint_AddToConstructionButton(EBP.ALLIES.SANDBAG_RIFLEMEN, 409589, false)
		else
			UI_StopFlashing(flashid_building_sandbags2)
			HintPoint_Remove(hpid_building_sandbags2)
		end
	end
end


function Building_Defences_Placing(ebp, phase)
	
	if ebp == EBP.ALLIES.SANDBAG_RIFLEMEN then
		
		-- placing
		if phase == CP_Selected then
			
			Game_SkipEvent()
			
			Objective_RemoveUIElements(OBJ_BUILDING_DEFENCES, OBJ_BUILDING_DEFENCES.PingID)
			OBJ_BUILDING_DEFENCES.PingID = Objective_AddUIElements(OBJ_BUILDING_DEFENCES, mkr_building_sandbagstart, false, 409558, true)
			
			Util_StartIntel(EVENTS.BuildingDefencesStartPoint)
			
		-- start pos set
		elseif phase == CP_StartedPlacing then
			
			Game_SkipEvent()
			
			Objective_RemoveUIElements(OBJ_BUILDING_DEFENCES, OBJ_BUILDING_DEFENCES.PingID)
			OBJ_BUILDING_DEFENCES.PingID = Objective_AddUIElements(OBJ_BUILDING_DEFENCES, mkr_building_sandbagstop, false, 409559, true)
			
			Util_StartIntel(EVENTS.BuildingDefencesEndPoint)
			
		-- end pos set
		elseif phase == CP_FinishedPlacing then
			
			Game_SkipEvent()
			
			Objective_RemoveUIElements(OBJ_BUILDING_DEFENCES, OBJ_BUILDING_DEFENCES.PingID)
			
			if Rule_Exists(Building_Defences_RiflemenDeSelected) then Rule_Remove(Building_Defences_RiflemenDeSelected) end
			
			UI_ClearConstructionMenuCallback()
			UI_ClearBuildingPlacementCallback()
			
			UI_StopFlashing(flashid_building_sandbags1)
			UI_StopFlashing(flashid_building_sandbags2)
			HintPoint_Remove(hpid_building_sandbags1)
			HintPoint_Remove(hpid_building_sandbags2)
			
			Util_StartIntel(EVENTS.BuildingDefencesDone)
			
			Rule_AddInterval(Building_Defences_Done, 0.5)
			
		end
		
	end		
	
end

function Building_Defences_Done()

	if Player_HasBuilding(player1, EBP.ALLIES.SANDBAG_RIFLEMEN) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_UnrestrictBuildingPlacement()
		
		Util_StartIntel(EVENTS.BuildingDefencesBuilt)
		
		-- complete the objective
		Objective_Complete(OBJ_BUILDING_DEFENCES, false)
		
		Rule_AddInterval(Building_StartAttacks, 0.5)
		
	end
	
end


function Building_StartAttacks()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		SGroup_DestroyAllSquads(sg_group3)
		
		UI_BindingSetEnabled("command_unload_here", false)
		UI_BindingSetEnabled("command_unload_individual_squad", true)
		Player_SetCommandAvailability(player1, SCMD_Load, ITEM_DEFAULT)
		SGroup_SetSelectable(sg_engineer, true)
		
		building_attack1units = {{bp = SBP.AXIS.VOLKSGRENADIER, count = 2}, {bp = SBP.AXIS.STORMTROOPER, count = 1}}
		building_attack2units = {{bp = SBP.AXIS.VOLKSGRENADIER, count = 2}, {bp = SBP.AXIS.PIONEER, count = 1}}
		building_attack3units = {{bp = SBP.AXIS.VOLKSGRENADIER, count = 2}, {bp = SBP.AXIS.GRENADIER, count = 2}, {bp = SBP.AXIS.STORMTROOPER, count = 1}}
		
		Rule_AddInterval(Building_StartAttacks_SendIn1, 5)
		Rule_AddInterval(Building_StartAttacks_SendIn2, 10)
		Rule_AddInterval(Building_StartAttacks_SendIn3, 15)
		
		Rule_AddOneShot(Building_CommandPoints2_BeginLesson, 45)
		
	end

end


function Building_StartAttacks_SendIn1()

	if SGroup_Count(sg_group3) == 0 then
		
		item = Table_GetRandomItem(building_attack1units, 1)
		Util_CreateSquads(player2, sg_group3, item.bp, mkr_building_spawnenemy1, nil, item.count)
		Cmd_AttackMove(sg_group3, mkr_building_mgnest)
		
	end
	
end

function Building_StartAttacks_SendIn2()

	if SGroup_Count(sg_group4) == 0 then
		
		item = Table_GetRandomItem(building_attack2units, 1)
		Util_CreateSquads(player2, sg_group4, item.bp, mkr_building_spawnenemy2, nil, item.count)
		Cmd_AttackMove(sg_group4, mkr_building_mgnest)
		
	end
	
end

function Building_StartAttacks_SendIn3()

	if SGroup_Count(sg_group5) == 0 then
		
		item = Table_GetRandomItem(building_attack3units, 1)
		Util_CreateSquads(player2, sg_group5, item.bp, mkr_building_spawnenemy3, nil, item.count)
		Cmd_AttackMove(sg_group5, mkr_building_mgnest)
		
	end
	
end





--
-- Lesson: Command Points 2 (Artillery)
--
function Building_CommandPoints2_BeginLesson()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		-- change perimeters
		
		-- give the objective
		Objective_Start(OBJ_BUILDING_ARTILLERY, false)
		
		-- ensure the player has enough command points
		local points = Player_GetResource(player1, RT_Command)
		if points < 2 then
			Player_AddUnspentCommandPoints(player1, (2 - points))
		end
		
		-- unlock the upgrade
		Player_SetUpgradeAvailability(player1, UPG.COMMANDER_TREE.ALLIES.INFANTRY_11, ITEM_UNLOCKED)
		
		flashid_building_cc = UI_FlashBinding("company_commander", true, BT_UI_Strong_CommanderBtn )
		hpid_building_cc = HintPoint_AddToTaskbarBinding("company_commander", 409579, true)
		
		Util_StartIntel(EVENTS.BuildingArtilleryIntro)
		
		Rule_AddInterval(Building_CommandPoints2_InCommanderTree, 0.5)
		
	end
	
end


function Building_CommandPoints2_InCommanderTree()
	
	if UI_IsCommanderTreeBranchShown() then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashing(flashid_building_cc)
		HintPoint_Remove(hpid_building_cc)
		
		-- change perimeters
		
		Util_StartIntel(EVENTS.BuildingArtilleryBuySkill)
		
		flashid_building_cc_branch2 = UI_FlashCommanderBranchUpgrade(UPG.COMMANDER_TREE.ALLIES.INFANTRY_11, BT_UI_Strong_CCOptions)
		
		Rule_AddInterval(Building_CommandPoints2_OutOfCommanderTree, 0.5)
		
	end
	
end

function Building_CommandPoints2_OutOfCommanderTree()
	
	if Player_HasUpgrade(player1, UPG.COMMANDER_TREE.ALLIES.INFANTRY_11) then
		
		Rule_RemoveMe()
		Game_SkipEvent()
		
		UI_StopFlashingCommanderBranchUpgrade(flashid_building_cc_branch2)
		
		-- change perimeters
		
		Util_StartIntel(EVENTS.BuildingArtilleryDone)
		
		-- ensure the player has enough resources for an artillery barrage
		Tutorial_SafetySetResources(cost.artillery)	
		
		flashid_building_artillery = UI_FlashAbilityButton(ABILITY.COMMANDER_TREE.ALLIES.HOWITZER_SHOOT, false, BT_UI_Strong_AbilityBtn )
		hpid_building_artillery = HintPoint_AddToAbilityButton(ABILITY.COMMANDER_TREE.ALLIES.HOWITZER_SHOOT, 409584, false)
		
		Rule_AddPlayerEvent(Building_DropArtillery, player1, GE_AbilityExecuted) 
		
	end
	
end

function Building_DropArtillery(player, abilityID, target)

	if abilityID == ABILITY.COMMANDER_TREE.ALLIES.HOWITZER_SHOOT then
		
		Game_SkipEvent()
		
		HintPoint_Remove(hpid_building_artillery)
		UI_StopFlashing(flashid_building_artillery)
		
		Rule_RemovePlayerEvent(Building_DropArtillery, player1)
		
		Objective_Complete(OBJ_BUILDING_ARTILLERY, false)
		Util_StartIntel(EVENTS.BuildingArtilleryActivated)
		Tutorial_SafetySetResources(cost.artillery)
		
		-- stop generating attacks
		if Rule_Exists(Building_StartAttacks_SendIn1) then Rule_Remove(Building_StartAttacks_SendIn1) end
		if Rule_Exists(Building_StartAttacks_SendIn2) then Rule_Remove(Building_StartAttacks_SendIn2) end
		if Rule_Exists(Building_StartAttacks_SendIn3) then Rule_Remove(Building_StartAttacks_SendIn3) end
		
		Rule_AddInterval(Building_AttackKilled, 1)
		
	end
	
end


function Building_AttackKilled()

	if SGroup_Count(sg_group3) + SGroup_Count(sg_group4) + SGroup_Count(sg_group5) == 0 then	
		
		Rule_RemoveMe()
		
		Util_StartIntel(EVENTS.BuildingEndTutorial)
		
		Rule_AddInterval(Building_TutorialComplete, 1)
	elseif SGroup_IsEmpty( sg_group3 ) == false then
		Cmd_AttackMove(sg_group3, mkr_building_mgnest)
	elseif SGroup_IsEmpty( sg_group4 ) == false then
		Cmd_AttackMove(sg_group4, mkr_building_mgnest)
	elseif SGroup_IsEmpty( sg_group5 ) == false then
		Cmd_AttackMove(sg_group5, mkr_building_mgnest)
	end
	
end





--
-- Closing
--
function Building_TutorialComplete()
	
	if Event_IsAnyRunning() == false then
		
		Rule_RemoveMe()
		
		Util_MissionTitle(409923)
		
		PlayerProfile_SetVar("BuildingTutorial_Completed", "true")
		
		Rule_AddOneShot(Building_EndTutorial, 5)
		
	end
	
end




--------------------------------------------------------------------------------
-- End the tutorial and return to the courtyard
--------------------------------------------------------------------------------
function Building_EndTutorial()

	Rule_RemoveAll(0)
	Game_SkipAllEvents(true)
	
	Building_CleanUp()
	Courtyard_Start()

end

function Building_CleanUp()

	HintPoint_RemoveAll()
	SelectionCheck_Stop()
	
	-- stop everything
	Player_GetAll(player1)
	Cmd_Stop(eg_allentities)
	Cmd_Stop(sg_allsquads)
	
	
	-- revert all territories
	EGroup_SetStrategicPointNeutral(eg_resourcing_munitionspoint)
	EGroup_SetStrategicPointNeutral(eg_resourcing_nullpoint)
	EGroup_SetStrategicPointNeutral(eg_building_squadcappoint1)
	EGroup_SetStrategicPointNeutral(eg_building_squadcappoint2)
	
	
	-- remove all the units spawned for this tutorial
	SGroup_DestroyAllSquads(sg_playerunits)
	SGroup_DestroyAllSquads(sg_engineer)
	SGroup_DestroyAllSquads(sg_friends)
	SGroup_DestroyAllSquads(sg_convoy)
	SGroup_DestroyAllSquads(sg_group1)
	SGroup_DestroyAllSquads(sg_group2)
	SGroup_DestroyAllSquads(sg_group3)
	SGroup_DestroyAllSquads(sg_group4)
	SGroup_DestroyAllSquads(sg_group5)
	SGroup_DestroyAllSquads(sg_group6)
	SGroup_DestroyAllSquads(sg_group7)
	SGroup_DestroyAllSquads(sg_group8)
	SGroup_DestroyAllSquads(sg_group9)
	SGroup_DestroyAllSquads(sg_allsquads)


	-- hide resource rates / squad caps
	UI_BindingSetEnabled("manpower", false)
	UI_BindingSetEnabled("manpower_rate", false)
	UI_BindingSetEnabled("munition", false)
	UI_BindingSetEnabled("munition_rate", false)
	UI_BindingSetEnabled("fuel", false)
	UI_BindingSetEnabled("fuel_rate", false)
	UI_BindingSetEnabled("squadcap", false)
	UI_BindingSetEnabled("company_commander", false)
	UI_BindingSetEnabled("tacmap_button", false)
	UI_BindingSetEnabled("manage_hq", false)
	UI_BindingSetEnabled("manage_barracks", false)
	UI_BindingSetEnabled("command_unload_here", true)
	UI_BindingSetEnabled("command_unload_individual_squad", true)
	
	-- replace any locks
	Player_SetCommandAvailability(player1, SCMD_Load, ITEM_LOCKED)
	Player_SetCommandAvailability(player1, SCMD_Retreat, ITEM_LOCKED)
	Player_SetCommandAvailability(player1, SCMD_Capture, ITEM_LOCKED)
	Player_SetSquadProductionAvailability(player1, SBP.ALLIES.ENGINEER, ITEM_DEFAULT)
	Player_SetSquadProductionAvailability(player1, SBP.ALLIES.RIFLEMEN, ITEM_DEFAULT)
	Player_SetEntityProductionAvailability(player1, EBP.ALLIES.BARRACKS, ITEM_LOCKED)	
	Player_SetEntityProductionAvailability(player1, EBP.ALLIES.OBSERVATION_POST, ITEM_LOCKED)
	Player_SetEntityProductionAvailability(player1, EBP.ALLIES.MG_NEST, ITEM_LOCKED)
	Player_SetEntityProductionAvailability(player1, EBP.ALLIES.SANDBAG_RIFLEMEN, ITEM_LOCKED)
	Player_SetAbilityAvailability(player1, ABILITY.COMMANDER_TREE.ALLIES.HOWITZER_SHOOT, ITEM_REMOVED)
	Player_SetUpgradeAvailability(player1, UPG.ALLIES.CONVERT_AMBIENT_BUILDING, ITEM_LOCKED)
	Player_SetConstructionMenuAvailability(player1, "tp_construction_rifleman_basic", ITEM_LOCKED)
	Player_SetConstructionMenuAvailability(player1, "tp_construction_allied_hq", ITEM_LOCKED)
	Player_SetConstructionMenuAvailability(player1, "tp_construction_engineer_basic", ITEM_LOCKED)
	
	UI_UnrestrictBuildingPlacement()
	
	-- undo any FOW Reveals
	FOW_UnRevealMarker(mkr_building_clearforwardfield)
	FOW_UnRevealArea(EGroup_GetPosition(eg_building_squadcappoint1), 10)
	
	
	-- gather all new buildings into the P3 base group
	Player_GetAll(player1)
	EGroup_Filter(eg_allentities, {EBP.ALLIES.BARRACKS, EBP.ALLIES.MG_NEST}, FILTER_KEEP)
	EGroup_DestroyAllEntities(eg_allentities)
	
	EGroup_SetPlayerOwner(eg_player1base, player1)
	EGroup_SetPlayerOwner(eg_player3base, player3)
	EGroup_SetStrategicPointNeutral(eg_player3hq)
	
	Resources_Disable()
	
	
	-- remove all the objectives used in this tutorial
 	Objective_Show(OBJ_BUILDING_ENGINEERS, false)
 	Objective_Show(OBJ_BUILDING_BARRACKS, false)
 	Objective_Show(OBJ_BUILDING_RIFLEMEN, false)
 	Objective_Show(OBJ_BUILDING_MUNITIONS, false)
 	Objective_Show(OBJ_BUILDING_NULL, false)
 	Objective_Show(OBJ_BUILDING_SECURE, false)
 	Objective_Show(OBJ_BUILDING_MGNEST, false)
 	Objective_Show(OBJ_BUILDING_GARRISSON, false)
 	Objective_Show(OBJ_BUILDING_AMBIENTUPGRADE, false)
 	Objective_Show(OBJ_BUILDING_BUILDARMY, false)
 	Objective_Show(OBJ_BUILDING_SQUADCAP, false)
 	Objective_Show(OBJ_BUILDING_REINFORCE, false)
 	Objective_Show(OBJ_BUILDING_COMMANDMENU, false)
 	Objective_Show(OBJ_BUILDING_DEFENCES, false)
 	Objective_Show(OBJ_BUILDING_ARTILLERY, false)

	
	-- remove any perimeters
	EGroup_DeSpawn(LAYER_perimeter_base)
	EGroup_DeSpawn(eg_building_mgnestfacing)
	
end





--
-- Objectives
--
function Building_RegisterObjectives()


	OBJ_BUILDING_ENGINEERS = {
		SetupUI = function() end,
		OnStart = function() 
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_ENGINEERS, true, false, true)
		end,
		OnComplete = function() end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409500,
		Description = 409501,
		Type = OT_Primary,
		Icon = IT_P_Upgrade,
	}
	Objective_Register(OBJ_BUILDING_ENGINEERS)


	OBJ_BUILDING_BARRACKS = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_BARRACKS, true, false, true)
		end,
		OnComplete = function() end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409502,
		Description = 409503,
		Type = OT_Primary,
		Icon = IT_P_Upgrade,
	}
	Objective_Register(OBJ_BUILDING_BARRACKS)
	

	OBJ_BUILDING_RIFLEMEN = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_RIFLEMEN, true, false, true)
		end,
		OnComplete = function() end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409504,
		Description = 409505,
		Type = OT_Primary,
		Icon = IT_P_Upgrade,
	}
	Objective_Register(OBJ_BUILDING_RIFLEMEN)


	OBJ_BUILDING_MUNITIONS = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_MUNITIONS, true, true, true)
		end,
		OnComplete = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_MUNITIONS, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409506,
		Description = 409507,
		Type = OT_Primary,
		Icon = IT_P_Capture,
	}
	Objective_Register(OBJ_BUILDING_MUNITIONS)


	OBJ_BUILDING_NULL = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_NULL, true, true, true)
		end,
		OnComplete = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_NULL, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409508,
		Description = 409509,
		Type = OT_Primary,
		Icon = IT_P_Capture,
	}
	Objective_Register(OBJ_BUILDING_NULL)


	OBJ_BUILDING_SECURE = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_SECURE, true, true, true)
		end,
		OnComplete = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_SECURE, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409510,
		Description = 409511,
		Type = OT_Primary,
		Icon = IT_P_Capture,
	}
	Objective_Register(OBJ_BUILDING_SECURE)

	
	OBJ_BUILDING_MGNEST = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_MGNEST, true, true, true)
		end,
		OnComplete = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_MGNEST, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409512,
		Description = 409513,
		Type = OT_Primary,
		Icon = IT_P_Upgrade,
	}
	Objective_Register(OBJ_BUILDING_MGNEST)


	OBJ_BUILDING_GARRISSON = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_GARRISSON, true, true, true)
		end,
		OnComplete = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_GARRISSON, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409514,
		Description = 409515,
		Type = OT_Primary,
		Icon = IT_P_Garrison,
	}
	Objective_Register(OBJ_BUILDING_GARRISSON)
	

	OBJ_BUILDING_AMBIENTUPGRADE = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_AMBIENTUPGRADE, true, true, true)
		end,
		OnComplete = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_AMBIENTUPGRADE, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409516,
		Description = 409517,
		Type = OT_Primary,
		Icon = IT_P_Upgrade,
	}
	Objective_Register(OBJ_BUILDING_AMBIENTUPGRADE)
	
	
	OBJ_BUILDING_BUILDARMY = {
		SetupUI = function()
			Objective_AddUIElements(OBJ_BUILDING_BUILDARMY, eg_building_house, false, false, true)
		end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_BUILDARMY, true, true, true)
		end,
		OnComplete = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_BUILDARMY, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409518,
		Description = 409519,
		Type = OT_Primary,
		Icon = IT_P_Defend,
	}
	Objective_Register(OBJ_BUILDING_BUILDARMY)


	OBJ_BUILDING_SQUADCAP = {
		SetupUI = function() end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_SQUADCAP, true, true, true)
		end,
		OnComplete = function() 
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_SQUADCAP, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409520,
		Description = 409521,
		Type = OT_Primary,
		Icon = IT_P_Capture,
	}
	Objective_Register(OBJ_BUILDING_SQUADCAP)


	OBJ_BUILDING_REINFORCE = {
		SetupUI = function() 
		end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_REINFORCE, true, true, true)
		end,
		OnComplete = function() 
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_REINFORCE, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409522,
		Description = 409523,
		Type = OT_Primary,
		Icon = IT_P_Capture,
	}
	Objective_Register(OBJ_BUILDING_REINFORCE)


	OBJ_BUILDING_COMMANDMENU = {
		SetupUI = function() 
		end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_COMMANDMENU, true, true, true)
		end,
		OnComplete = function() 
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_COMMANDMENU, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409524,
		Description = 409525,
		Type = OT_Primary,
		Icon = IT_P_Capture,
	}
	Objective_Register(OBJ_BUILDING_COMMANDMENU)


	OBJ_BUILDING_DEFENCES = {
		SetupUI = function() 
		end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_DEFENCES, true, true, true)
		end,
		OnComplete = function() 
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_DEFENCES, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409526,
		Description = 409527,
		Type = OT_Primary,
		Icon = IT_P_Capture,
	}
	Objective_Register(OBJ_BUILDING_DEFENCES)


	OBJ_BUILDING_ARTILLERY = {
		SetupUI = function() 
		end,
		OnStart = function()
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_ARTILLERY, true, true, true)
		end,
		OnComplete = function() 
			Objective_SetAlwaysShowDetails(OBJ_BUILDING_ARTILLERY, true, false, false)
		end,
		OnFail = function() end,
		OnSitRep = function() end,
		Title = 409528,
		Description = 409529,
		Type = OT_Primary,
		Icon = IT_P_Capture,
	}
	Objective_Register(OBJ_BUILDING_ARTILLERY)


end


