--/////////////////////////////////////////////////////////////////////////////////////////////////
--  (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/SpaceMode/GroundToSpaceDamage.LUA
--
-- Original Editor: Giovanni Galyana
--
--   Final Edit By: Giovanni Galyana
--
--            Date: 9 July, 2020
--
--       Revisions: 3
--
--/////////////////////////////////////////////////////////////////////////////////////////////////

require("pgevents")

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

	Category = "Ground_To_Space_Damage"
	IgnoreTarget = true
	TaskForce = 
	{
		{
			"MainForce"
			,"DenySpecialWeaponAttach"
			,"DenyHeroAttach"
			,"Ground_Empire_Hypervelocity_Gun | Skirmish_Hypervelocity_Gun | Ground_Hutts_Hypervelocity_Gun | Skirmish_Hyper_Beam_Gun | Skirmish_Plasma_Cannon  = 1"
		}
	}
	
	DebugMessage("%s -- Done Definitions", tostring(Script))
end

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

	-- Keep firing at the biggest (and probably slowest) enemy until it's dead
--	AITarget = FindTarget(MainForce, "Needs_Hypervelocity_Shot", "Enemy_Unit", 1.0)
--	DebugMessage("%s -- Found Target %s", tostring(Script), tostring(AITarget))

	-- Try to fire each variety this weapon might be
	MainForce.Fire_Special_Weapon("Ground_Empire_Hypervelocity_Gun", AITarget)
	MainForce.Fire_Special_Weapon("Ground_Hutts_Hypervelocity_Gun", AITarget)
	MainForce.Fire_Special_Weapon("Skirmish_Hypervelocity_Gun", AITarget)
	MainForce.Fire_Special_Weapon("Skirmish_Hyper_Beam_Gun", AITarget)
	MainForce.Fire_Special_Weapon("Skirmish_Plasma_Cannon", AITarget)

	-- Rely on the Weapon Online event to fire the gun subsequent times
	while TestValid(AITarget) do
		Sleep(5)
	end
	
	ScriptExit()
end

function MainForce_Special_Weapon_Online(tf, special_weapon)
	if TestValid(AITarget) then
		special_weapon.Fire_Special_Weapon(AITarget, PlayerObject)
	else
		ScriptExit()
	end
end
