--/////////////////////////////////////////////////////////////////////////////////////////////////
--  (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/FreeStore/GalacticHeroFreeStore.LUA
--
-- Original Editor: Giovanni Galyana
--
--   Final Edit By: Giovanni Galyana
--
--            Date: 7 March, 2019
--
--       Revisions: 0
--
--/////////////////////////////////////////////////////////////////////////////////////////////////

require("pgcommands")

function Definitions()
	DebugMessage("%s -- Defining custom freestore movement perceptions", tostring(Script))

	-- Table which maps heroes to perceptions for systems they like to hang out on when not in active use
	-- The boolean is for whether or not the hero prefers to stay in space, if he has a choice
	-- Generally, this is to find the system where their abilities provide the best defensive or infrastructure bonuses
	CustomUnitPlacement = {
		EMPEROR_PALPATINE_TEAM = {"Is_Home_Planet", false}
		,GRAND_MOFF_TARKIN_TEAM = {"Is_Home_Planet", true}
		,UEAW_SATE_PESTAGE_TEAM = {"Is_Home_Planet", false}
		,DARTH_TEAM = {nil, false}
		,DARTH_TEAM_EXECUTOR = {nil, true}
		,GENERAL_VEERS_TEAM = {nil, false}
		,BOBA_FETT_TEAM = {nil, true}
		,ACCUSER_STAR_DESTROYER = {nil, true}
		,ADMIRAL_PIETT_EXECUTOR = {nil, true}
		,ISD_GORGON = {nil, true}
		,PELLAEON_ACCLAMATOR = {nil, true}
		,ARC_HAMMER = {"Is_Home_Planet", true}
		,ADMONITOR_STAR_DESTROYER = {nil, true}

		,MON_MOTHMA_TEAM = {"Is_Home_Planet", false}
		,HOME_ONE = {nil, true}
		,HAN_SOLO_TEAM = {nil, false}
		,OBI_WAN_TEAM = {nil, false}
		,DROIDS_TEAM = {nil, false}
		,LUKE_TEAM = {nil, true}
		,LUKE_SKYWALKER_JEDI_TEAM = {nil, false}
		,YODA_TEAM = {nil,false}
		,ROGUE_SQUADRON_SPACE = {nil,true}
		
		,BOSSK_TEAM = {nil, true}
		,IG88_TEAM = {nil, true}
		,SILRI_TEAM = {nil, false}
		,URAI_FEN_TEAM = {nil, false}
		,TYBER_ZANN_TEAM = {nil, true}
		,ERRANT_VENTURE = {nil, true}
		
		,NIKOMER_TEAM = {nil, true}
		,CUARSON_TEAM = {nil, true}
		,SYKARIIUS_TEAM = {nil, true}
		,XIZOR_TEAM = {nil, false}
		,PESTELOUS_TEAM = {nil, true}
		,GALYANA_SSD_GC = {nil, true}
	}
	
end

function Find_Custom_Target(object)
	object_type = object.Get_Type()
	object_type_name = object_type.Get_Name()

	unit_entry = CustomUnitPlacement[object_type_name]

	if unit_entry then
		perception = unit_entry[1]
		prefers_space = unit_entry[2]
		if perception then
			target = FindTarget.Reachable_Target(PlayerObject, perception, "Friendly", "No_Threat", 1.0, object)
			if TestValid(target) then
				return target
			end
		end
		
		if prefers_space then
			return Find_Space_Unit_Target(object)
		else
			return Find_Ground_Unit_Target(object)
		end
	else
		DebugMessage("%s -- Error: Type %s not found in CustomUnitPlacement table.", tostring(Script), object_type_name)
	end
end