SelectPlayerFirstOreRefinery0 = function()
	OreRefineryState0 = true
	OreRefinery0 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(proc) return proc.Type == "proc" and proc.Owner == multi0 end)
	Utils.Do(OreRefinery0, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			proc.GrantUpgrade("missionmarker.enabled")
			proc.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			Trigger.OnRemovedFromWorld(proc, function()
				OreRefineryState0 = false
			end)
			Trigger.OnKilled(proc, function()
			end)
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerFirstHarvester0()
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstOreRefinery1 = function()
	OreRefineryState1 = true
	OreRefinery1 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(proc) return proc.Type == "proc" and proc.Owner == multi1 end)
	Utils.Do(OreRefinery1, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			proc.GrantUpgrade("missionmarker.enabled")
			proc.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			Trigger.OnRemovedFromWorld(proc, function()
				OreRefineryState1 = false
			end)
			Trigger.OnKilled(proc, function()
			end)
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerFirstHarvester1()
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstOreRefinery2 = function()
	OreRefineryState2 = true
	OreRefinery2 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(proc) return proc.Type == "proc" and proc.Owner == multi2 end)
	Utils.Do(OreRefinery2, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			proc.GrantUpgrade("missionmarker.enabled")
			proc.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			Trigger.OnRemovedFromWorld(proc, function()
				OreRefineryState2 = false
			end)
			Trigger.OnKilled(proc, function()
			end)
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerFirstHarvester2()
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstOreRefinery3 = function()
	OreRefineryState3 = true
	OreRefinery3 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(proc) return proc.Type == "proc" and proc.Owner == multi3 end)
	Utils.Do(OreRefinery3, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			proc.GrantUpgrade("missionmarker.enabled")
			proc.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			Trigger.OnRemovedFromWorld(proc, function()
				OreRefineryState3 = false
			end)
			Trigger.OnKilled(proc, function()
			end)
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerFirstHarvester3()
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstHarvester0 = function()
	OreHarvesterState0 = true
	OreHarvester0 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(harv) return harv.Type == "harv" and harv.Owner == multi0 end)
	Utils.Do(OreHarvester0, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				OreHarvesterState0 = false
				PlayerFirstProcState0 = false
				FirstPlayerFirstProcState0 = false
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstHarvester1 = function()
	OreHarvesterState1 = true
	OreHarvester1 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(harv) return harv.Type == "harv" and harv.Owner == multi1 end)
	Utils.Do(OreHarvester1, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				OreHarvesterState1 = false
				PlayerFirstProcState1 = false
				FirstPlayerFirstProcState1 = false
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstHarvester2 = function()
	OreHarvesterState2 = true
	OreHarvester2 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(harv) return harv.Type == "harv" and harv.Owner == multi2 end)
	Utils.Do(OreHarvester2, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				OreHarvesterState2 = false
				PlayerFirstProcState2 = false
				FirstPlayerFirstProcState2 = false
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstHarvester3 = function()
	OreHarvesterState3 = true
	OreHarvester3 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(harv) return harv.Type == "harv" and harv.Owner == multi3 end)
	Utils.Do(OreHarvester3, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				OreHarvesterState3 = false
				PlayerFirstProcState3 = false
				FirstPlayerFirstProcState3 = false
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstHarvester0 = function()
	OreHarvesterState0 = true
	OreHarvester0 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(harv) return harv.Type == "harv" and harv.Owner == multi0 end)
	Utils.Do(OreHarvester0, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				OreHarvesterState0 = false
				PlayerFirstProcState0 = false
				FirstPlayerFirstProcState0 = false
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstHarvester1 = function()
	OreHarvesterState1 = true
	OreHarvester1 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(harv) return harv.Type == "harv" and harv.Owner == multi1 end)
	Utils.Do(OreHarvester1, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				OreHarvesterState1 = false
				PlayerFirstProcState1 = false
				FirstPlayerFirstProcState1 = false
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerFirstHarvester2 = function()
	OreHarvesterState2 = true
	OreHarvester2 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(harv) return harv.Type == "harv" and harv.Owner == multi2 end)
	Utils.Do(OreHarvester2, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				OreHarvesterState2 = false
				PlayerFirstProcState2 = false
				FirstPlayerFirstProcState2 = false
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerSecondOilTanker0 = function()
	SecondOilTankerState0 = true
	SecondOilTanker0 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(tanker) return tanker.Type == "oiltanker.second" and tanker.Owner == multi0 end)
	Utils.Do(SecondOilTanker0, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				SecondOilTankerState0 = false
				SecondOilTankerSelectState0 = false
			end)
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerSecondOilTanker0()
	end)
end
SelectPlayerSecondOilTanker1 = function()
	SecondOilTankerState1 = true
	SecondOilTanker1 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(tanker) return tanker.Type == "oiltanker.second" and tanker.Owner == multi1 end)
	Utils.Do(SecondOilTanker1, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				SecondOilTankerState1 = false
				SecondOilTankerSelectState1 = false
			end)
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerSecondOilTanker1()
	end)
end
SelectPlayerSecondOilTanker2 = function()
	SecondOilTankerState2 = true
	SecondOilTanker2 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(tanker) return tanker.Type == "oiltanker.second" and tanker.Owner == multi2 end)
	Utils.Do(SecondOilTanker2, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				SecondOilTankerState2 = false
				SecondOilTankerSelectState2 = false
			end)
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerSecondOilTanker2()
	end)
end
SelectPlayerSecondOilTanker3 = function()
	SecondOilTankerState3 = true
	SecondOilTanker3 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(tanker) return tanker.Type == "oiltanker.second" and tanker.Owner == multi3 end)
	Utils.Do(SecondOilTanker3, function(harv)
		if not harv.IsDead and harv.IsInWorld then
			harv.GrantUpgrade("worker.prefix")
			harv.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			harv.GrantUpgrade("nocontrol")
			harv.Scatter()
			harv.Wait(Utils.RandomInteger(33.33, 44.44))
			harv.FindResources()
			Trigger.OnKilled(harv, function()
				SecondOilTankerState3 = false
				SecondOilTankerSelectState3 = false
			end)
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerSecondOilTanker3()
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerSecondOilTanker0 = function()
	Media.PlaySpeechNotification(multi0, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OilRefinery0, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi0, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				Utils.Do(SecondOilTanker0, function(g)
					unit.GrantUpgrade("nocontrol")
					unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
					unit.Stance = "Defend"
					Trigger.OnIdle(unit, function(a)
						if not g.IsDead and g.IsInWorld then
							if not a.IsDead and a.IsInWorld then a.Guard(g) end
						end
					end)
				end)
			end)
		end
	end)
end
DefendPlayerSecondOilTanker1 = function()
	Media.PlaySpeechNotification(multi1, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OilRefinery1, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi1, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				Utils.Do(SecondOilTanker1, function(g)
					unit.GrantUpgrade("nocontrol")
					unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
					unit.Stance = "Defend"
					Trigger.OnIdle(unit, function(a)
						if not g.IsDead and g.IsInWorld then
							if not a.IsDead and a.IsInWorld then a.Guard(g) end
						end
					end)
				end)
			end)
		end
	end)
end
DefendPlayerSecondOilTanker2 = function()
	Media.PlaySpeechNotification(multi2, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OilRefinery2, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi2, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				Utils.Do(SecondOilTanker2, function(g)
					unit.GrantUpgrade("nocontrol")
					unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
					unit.Stance = "Defend"
					Trigger.OnIdle(unit, function(a)
						if not g.IsDead and g.IsInWorld then
							if not a.IsDead and a.IsInWorld then a.Guard(g) end
						end
					end)
				end)
			end)
		end
	end)
end
DefendPlayerSecondOilTanker3 = function()
	Media.PlaySpeechNotification(multi3, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OilRefinery3, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi3, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				Utils.Do(SecondOilTanker3, function(g)
					unit.GrantUpgrade("nocontrol")
					unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
					unit.Stance = "Defend"
					Trigger.OnIdle(unit, function(a)
						if not g.IsDead and g.IsInWorld then
							if not a.IsDead and a.IsInWorld then a.Guard(g) end
						end
					end)
				end)
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerFirstHarvester0 = function()
	Media.PlaySpeechNotification(multi0, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OreRefinery0, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi0, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OreHarvesterState0 then 
					Utils.Do(OreHarvester0, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
DefendPlayerFirstHarvester1 = function()
	Media.PlaySpeechNotification(multi1, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OreRefinery1, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi1, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OreHarvesterState1 then 
					Utils.Do(OreHarvester1, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
DefendPlayerFirstHarvester2 = function()
	Media.PlaySpeechNotification(multi2, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OreRefinery2, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi2, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OreHarvesterState2 then 
					Utils.Do(OreHarvester2, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
DefendPlayerFirstHarvester3 = function()
	Media.PlaySpeechNotification(multi3, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OreRefinery3, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi3, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OreHarvesterState3 then 
					Utils.Do(OreHarvester3, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerSecondHarvester0 = function()
	Media.PlaySpeechNotification(multi0, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OreRefinery0, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi0, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OreHarvesterState0 then 
					Utils.Do(OreHarvester0, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerFirstHarvester1 = function()
	Media.PlaySpeechNotification(multi1, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OreRefinery1, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi1, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OreHarvesterState1 then 
					Utils.Do(OreHarvester1, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerFirstHarvester2 = function()
	Media.PlaySpeechNotification(multi2, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OreRefinery2, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi2, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OreHarvesterState2 then 
					Utils.Do(OreHarvester2, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerFirstHarvester3 = function()
	Media.PlaySpeechNotification(multi3, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OreRefinery3, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi3, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OreHarvesterState3 then 
					Utils.Do(OreHarvester3, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
SelectPlayerSecondHarvester0 = function()
	OilRefineryState0 = true
	OilHarvesterState0 = true
	OilRefinery0 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(oilrefinery) return oilrefinery.Type == "oilrefinery" and oilrefinery.Owner == multi0 end)
	Utils.Do(OilRefinery0, function(oilrefinery)
		if not oilrefinery.IsDead and oilrefinery.IsInWorld then
			oilrefinery.GrantUpgrade("missionmarker.enabled")
			oilrefinery.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
-----------------------------------------------------------------------------------------------
			Trigger.OnRemovedFromWorld(oilrefinery, function()
				OilRefineryState0 = false
			end)
			Trigger.OnKilled(oilrefinery, function()
			end)
-----------------------------------------------------------------------------------------------
		end
	end)
	OilHarvester0 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(oiltanker) return oiltanker.Type == "oiltanker" and oiltanker.Owner == multi0 end)
	Utils.Do(OilHarvester0, function(oiltanker)
		if not oiltanker.IsDead and oiltanker.IsInWorld then
			oiltanker.GrantUpgrade("missionmarker.empty")
			oiltanker.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			oiltanker.GrantUpgrade("nocontrol")
			oiltanker.Scatter()
			oiltanker.Wait(Utils.RandomInteger(33.33, 44.44))
			oiltanker.Scatter()
			oiltanker.FindResources()
-----------------------------------------------------------------------------------------------
			Trigger.OnRemovedFromWorld(oiltanker, function()
				PlayerSecondProcState0 = false
				FirstPlayerSecondProcState0 = false
			end)
			Trigger.OnKilled(oiltanker, function()
				OilHarvesterState0 = false
			end)
-----------------------------------------------------------------------------------------------
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerFirstOilHarvester0()
	end)
end
SelectPlayerSecondHarvester1 = function()
	OilRefineryState1 = true
	OilHarvesterState1 = true
	OilRefinery1 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(oilrefinery) return oilrefinery.Type == "oilrefinery" and oilrefinery.Owner == multi1 end)
	Utils.Do(OilRefinery1, function(oilrefinery)
		if not oilrefinery.IsDead and oilrefinery.IsInWorld then
			oilrefinery.GrantUpgrade("missionmarker.enabled")
			oilrefinery.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
-----------------------------------------------------------------------------------------------
			Trigger.OnRemovedFromWorld(oilrefinery, function()
				OilRefineryState1 = false
			end)
			Trigger.OnKilled(oilrefinery, function()
			end)
-----------------------------------------------------------------------------------------------
		end
	end)
	OilHarvester1 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(oiltanker) return oiltanker.Type == "oiltanker" and oiltanker.Owner == multi1 end)
	Utils.Do(OilHarvester1, function(oiltanker)
		if not oiltanker.IsDead and oiltanker.IsInWorld then
			oiltanker.GrantUpgrade("missionmarker.empty")
			oiltanker.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			oiltanker.GrantUpgrade("nocontrol")
			oiltanker.Scatter()
			oiltanker.Wait(Utils.RandomInteger(33.33, 44.44))
			oiltanker.Scatter()
			oiltanker.FindResources()
-----------------------------------------------------------------------------------------------
			Trigger.OnRemovedFromWorld(oiltanker, function()
				PlayerSecondProcState1 = false
				FirstPlayerSecondProcState1 = false
			end)
			Trigger.OnKilled(oiltanker, function()
				OilHarvesterState1 = false
			end)
-----------------------------------------------------------------------------------------------
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerFirstOilHarvester1()
	end)
end
SelectPlayerSecondHarvester2 = function()
	OilRefineryState2 = true
	OilHarvesterState2 = true
	OilRefinery2 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(oilrefinery) return oilrefinery.Type == "oilrefinery" and oilrefinery.Owner == multi2 end)
	Utils.Do(OilRefinery2, function(oilrefinery)
		if not oilrefinery.IsDead and oilrefinery.IsInWorld then
			oilrefinery.GrantUpgrade("missionmarker.empty")
			oilrefinery.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
-----------------------------------------------------------------------------------------------
			Trigger.OnRemovedFromWorld(oilrefinery, function()
				OilRefineryState2 = false
			end)
			Trigger.OnKilled(oilrefinery, function()
			end)
-----------------------------------------------------------------------------------------------
		end
	end)
	OilHarvester2 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(oiltanker) return oiltanker.Type == "oiltanker" and oiltanker.Owner == multi2 end)
	Utils.Do(OilHarvester2, function(oiltanker)
		if not oiltanker.IsDead and oiltanker.IsInWorld then
			oiltanker.GrantUpgrade("missionmarker.enabled")
			oiltanker.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			oiltanker.GrantUpgrade("nocontrol")
			oiltanker.Scatter()
			oiltanker.Wait(Utils.RandomInteger(33.33, 44.44))
			oiltanker.Scatter()
			oiltanker.FindResources()
-----------------------------------------------------------------------------------------------
			Trigger.OnRemovedFromWorld(oiltanker, function()
				PlayerSecondProcState2 = false
				FirstPlayerSecondProcState2 = false
			end)
			Trigger.OnKilled(oiltanker, function()
				OilHarvesterState2 = false
			end)
-----------------------------------------------------------------------------------------------
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerFirstOilHarvester2()
	end)
end
SelectPlayerSecondHarvester3 = function()
	OilRefineryState3 = true
	OilHarvesterState3 = true
	OilRefinery3 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(oilrefinery) return oilrefinery.Type == "oilrefinery" and oilrefinery.Owner == multi3 end)
	Utils.Do(OilRefinery3, function(oilrefinery)
		if not oilrefinery.IsDead and oilrefinery.IsInWorld then
			oilrefinery.GrantUpgrade("missionmarker.enabled")
			oilrefinery.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
-----------------------------------------------------------------------------------------------
			Trigger.OnRemovedFromWorld(oilrefinery, function()
				OilRefineryState3 = false
			end)
			Trigger.OnKilled(oilrefinery, function()
			end)
-----------------------------------------------------------------------------------------------
		end
	end)
	OilHarvester3 = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(oiltanker) return oiltanker.Type == "oiltanker" and oiltanker.Owner == multi3 end)
	Utils.Do(OilHarvester3, function(oiltanker)
		if not oiltanker.IsDead and oiltanker.IsInWorld then
			oiltanker.GrantUpgrade("missionmarker.empty")
			oiltanker.GrantTimedUpgrade("normal.objective", Utils.RandomInteger(111.111, 222.222))
			oiltanker.GrantUpgrade("nocontrol")
			oiltanker.Scatter()
			oiltanker.Wait(Utils.RandomInteger(33.33, 44.44))
			oiltanker.Scatter()
			oiltanker.FindResources()
-----------------------------------------------------------------------------------------------
			Trigger.OnRemovedFromWorld(oiltanker, function()
				PlayerSecondProcState3 = false
				FirstPlayerSecondProcState3 = false
			end)
			Trigger.OnKilled(oiltanker, function()
				OilHarvesterState3 = false
			end)
-----------------------------------------------------------------------------------------------
		end
	end)
	Trigger.AfterDelay(2, function()
		DefendPlayerFirstOilHarvester3()
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerFirstOilHarvester0 = function()
	Media.PlaySpeechNotification(multi0, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OilRefinery0, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi0, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OilHarvesterState0 then 
					Utils.Do(OilHarvester0, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerFirstOilHarvester1 = function()
	Media.PlaySpeechNotification(multi1, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OilRefinery1, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi1, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OilHarvesterState1 then 
					Utils.Do(OilHarvester1, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerFirstOilHarvester2 = function()
	Media.PlaySpeechNotification(multi2, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OilRefinery2, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi2, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OilHarvesterState2 then 
					Utils.Do(OilHarvester2, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------
DefendPlayerFirstOilHarvester3 = function()
	Media.PlaySpeechNotification(multi3, "SupplySpeech" .. Utils.RandomInteger(0, 9) .. Utils.RandomInteger(0, 9) )
	Utils.Do(OilRefinery3, function(proc)
		if not proc.IsDead and proc.IsInWorld then
			local Path = { Map.ClosestEdgeCell(proc.Location), proc.Location + CVec.New(2, 2) }
			local unit = Reinforcements.ReinforceWithTransport(multi3, "carryall.reinforce", HarvesterGuardTypes, Path, { Path[1] })[2]
			Utils.Do(unit, function(unit)
				if OilHarvesterState3 then 
					Utils.Do(OilHarvester3, function(g)
						unit.GrantUpgrade("nocontrol")
--						unit.GrantUpgrade("autocontrol")
						unit.GrantUpgrade(Utils.Random({ "missionmarker.enabled", "communicate.prefix", "tactics.prefix", "chip.prefix", "fuel.upg", "worker.prefix" }))
						unit.Stance = "Defend"
						Trigger.OnIdle(unit, function(a)
							if not g.IsDead and g.IsInWorld then
								if not a.IsDead and a.IsInWorld then a.Guard(g) end
							end
						end)
					end)
				end
			end)
		end
	end)
end
-----------------------------------------------------------------------------------------------


