--/////////////////////////////////////////////////////////////////////////////////////////////////
--  (c) Galyana's Ultimate Empire at War Modifications
--  
--     ******    ***        *** ************           ***         ***
--    *      *    *          *   *         *            *           *
--   *        *   *          *   *                      *           *
--  *         *   *          *   *                      *           *
--  *             *          *   *    *         **** *  *           *
--  *             *          *   ******        *    *   *           *
--  *      ****   *          *   *    *       *     *   *    ***    *
--  *         *   *          *   *           *      *   *     *     *
--   *        *    *        *    *           *      *    *    *    *
--    *      *      *      *     *         *  *    **     *   *   *
--     ******        ******     ************   **** **     *******
--/////////////////////////////////////////////////////////////////////////////////////////////////
-- C O N F I D E N T I A L   S O U R C E   C O D E -- D O   N O T   D I S T R I B U T E
--/////////////////////////////////////////////////////////////////////////////////////////////////
--
--            File: GUEaW/Data/Scripts/AI/LandMode/FireMagnepulse.lua
--
-- Original Editor: Giovanni Galyana
--
--   Final Edit By: Giovanni Galyana
--
--            Date: 9 April, 2023
--
--       Revisions: 2
--
--/////////////////////////////////////////////////////////////////////////////////////////////////

-- Self-attachment script for the Magnepulse Cannon, but currently a custom goal is the best tactic 

require("pgevents")

function Definitions()
	DebugMessage("%s -- In Definitions", tostring(Script))

	Category = "Fire_Magnepulse"
	IgnoreTarget = true
	TaskForce = 
	{
		{
			"MainForce"
			,"DenySpecialWeaponAttach"
			,"DenyHeroAttach"
			,"E_Ground_Magnepulse_Cannon | E_Ground_Magnepulse_Cannon_GC = 1"
		}
	}
	
	DebugMessage("%s -- Done Definitions", tostring(Script))
end

function MainForce_Thread()
	BlockOnCommand(MainForce.Produce_Force())

	-- Keep firing at the bigger (and probably slowest) enemies
	-- Add some variance, so that we can spread the effect around
	AITarget = FindTarget(MainForce, "Needs_Magnepulse_Shot", "Enemy_Unit", 0.8)
	DebugMessage("%s -- Found Target %s", tostring(Script), tostring(AITarget))

	-- Just fire once, because the effect isn't that useful to hit the same target in rapid succession
	if TestValid(AITarget) then
		MainForce.Fire_Special_Weapon("E_Ground_Magnepulse_Cannon", AITarget)
		MainForce.Fire_Special_Weapon("E_Ground_Magnepulse_Cannon_GC", AITarget)
	end

	ScriptExit()
end