--/////////////////////////////////////////////////////////////////////////////////////////////////
--  (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/PurchaseLandUpgradesGeneric.LUA
--
-- Original Editor: Giovanni Galyana
--
--   Final Edit By: Giovanni Galyana
--
--            Date: 1 January, 2024
--
--       Revisions: 12
--
--/////////////////////////////////////////////////////////////////////////////////////////////////

require("pgevents")


function Definitions()

	Category = "Purchase_Land_Upgrades_Generic"
	IgnoreTarget = true
	TaskForce = {
	{
		"ReserveForce"
		,"DenySpecialWeaponAttach"
		,"DenyHeroAttach"

		-- Even though only one can be purchased, the 0,10 should increase the liklihood of items from these lists being chosen.
		,"RL_Combat_Armor_L1_Upgrade | RL_Combat_Armor_L2_Upgrade | RL_Combat_Armor_L3_Upgrade | RL_Upgraded_Scopes_L1_Upgrade | RL_Upgraded_Scopes_L2_Upgrade | RL_Weatherproof_Upgrade | RL_Light_Shield_Regenerators_L1_Upgrade | RL_Light_Shield_Regenerators_L2_Upgrade | RL_Experimental_Shielding_L1_Upgrade | RL_Light_Aircraft_Armor_L1_Upgrade | RL_Light_Aircraft_Armor_L2_Upgrade | RL_Light_Aircraft_Armor_L3_Upgrade | RL_Enhanced_Repulsors_L1_Upgrade | RL_Enhanced_Repulsors_L2_Upgrade | RL_Heavy_Armor_L1_Upgrade | RL_Heavy_Armor_L2_Upgrade | RL_Improved_Treads_L1_Upgrade | RL_Improved_Treads_L2_Upgrade | RL_Improved_Tank_Damage_L1_Upgrade = 0,10"
		,"RL_Reinforced_Structures_Upgrade | RL_Enhanced_Turret_Defense_L1_Upgrade | RL_Enhanced_Turret_Defense_L2_Upgrade | RL_Enhanced_Turret_Defense_L3_Upgrade | RL_Enhanced_Base_Shield_Upgrade | RL_Bombing_Run_Use_Upgrade | RL_Planetary_Bombard_Use_Upgrade | RL_More_Garrisons_L1_Upgrade | RL_More_Garrisons_L2_Upgrade | RL_More_Garrisons_L3_Upgrade = 0,10"
		,"RL_SMITE_UPGRADE | RL_Commerce_L1_Upgrade | RL_Commerce_L2_Upgrade | RL_Commerce_L1_Upgrade_FCU | RL_Commerce_L2_Upgrade_FCU | RSR_Commerce_L1_Upgrade | RSR_Commerce_L2_Upgrade | RL_Efficient_Farms_L1_Upgrade | RL_Efficient_Farms_L2_Upgrade | RL_Refinement_L1_Upgrade | RL_Refinement_L2_Upgrade | RL_Refinement_L3_Upgrade | RL_Improved_Quarry_L1_Upgrade | RL_Improved_Quarry_L2_Upgrade | RL_Improved_Quarry_L3_Upgrade | RL_Increased_Production_L1_Upgrade | RL_Increased_Production_L2_Upgrade | RL_Increased_Production_L3_Upgrade | RL_Increased_Production_L1_Upgrade_FCU | RL_Increased_Production_L2_Upgrade_FCU | RL_Increased_Production_L3_Upgrade_FCU = 0,10"
		,"RG_Combat_Armor_L1_Upgrade | RG_Combat_Armor_L2_Upgrade | RG_Combat_Armor_L3_Upgrade | RG_Combat_Commanders_L1_Upgrade | RG_Combat_Commanders_L2_Upgrade | RG_Upgraded_Scopes_L1_Upgrade | RG_Upgraded_Scopes_L2_Upgrade | RG_Light_Shield_Regenerators_L1_Upgrade | RG_Light_Shield_Regenerators_L2_Upgrade | RG_Experimental_Shielding_L1_Upgrade | RG_Light_Aircraft_Armor_L1_Upgrade | RG_Light_Aircraft_Armor_L2_Upgrade | RG_Light_Aircraft_Armor_L3_Upgrade | RG_Enhanced_Repulsors_L1_Upgrade | RG_Enhanced_Repulsors_L2_Upgrade | RG_Heavy_Armor_L1_Upgrade | RG_Heavy_Armor_L2_Upgrade | RG_Improved_Treads_L1_Upgrade | RG_Improved_Treads_L2_Upgrade | RG_Improved_Tank_Damage_L1_Upgrade = 0,10" 
		,"RG_Reinforced_Structures_Upgrade | RG_Enhanced_Turret_Defense_L1_Upgrade | RG_Enhanced_Turret_Defense_L2_Upgrade | RG_Enhanced_Turret_Defense_L3_Upgrade | RG_Enhanced_Base_Shield_Upgrade = 0,5"

		,"EL_Increased_Mobility_Upgrade | EL_Increased_Mobility_L2_Upgrade | EL_Increased_Mobility_L3_Upgrade | EL_Scout_Snipers_Upgrade | EL_Overclocked_Snipers_Upgrade | EL_Weatherproof_Upgrade | EL_Light_Reflective_Armor_L1_Upgrade | EL_Light_Reflective_Armor_L2_Upgrade | EL_Enhanced_Reactors_L1_Upgrade | EL_Enhanced_Reactors_L2_Upgrade | EL_Upgraded_Cooling_Systems_L1_Upgrade | EL_Upgraded_Cooling_Systems_L2_Upgrade | EL_Heavy_Reflective_Armor_L1_Upgrade | EL_Heavy_Reflective_Armor_L2_Upgrade | EL_Fortified_Transports_Upgrade | EL_Improved_ATAT_Reactors_L1_Upgrade | EL_Improved_ATAT_Reactors_L2_Upgrade | EL_Siege_Bombers_Upgrade = 0,10"
		,"EL_Bombing_Run_Use_Upgrade | EL_Planetary_Bombard_Use_Upgrade | EL_Magnetically_Sealed_Structure_Upgrade | EL_Repair_Nanites_L1_Upgrade | EL_Repair_Nanites_L2_Upgrade | EL_Enhanced_Turret_Firepower_L1_Upgrade | EL_Enhanced_Turret_Firepower_L2_Upgrade | EL_Enhanced_Turret_Firepower_L3_Upgrade | EL_Enhanced_Base_Shield_Upgrade = 0,10"
		,"EL_SMITE_UPGRADE | EL_Refinement_L1_Upgrade | EL_Refinement_L2_Upgrade | EL_Refinement_L3_Upgrade | EL_Refinement_L4_Upgrade | EL_Refinement_L5_Upgrade | EL_Improved_Quarry_L1_Upgrade | EL_Improved_Quarry_L2_Upgrade | EL_Improved_Quarry_L3_Upgrade | EL_Increased_Production_L1_Upgrade | EL_Increased_Production_L2_Upgrade | EL_Increased_Production_L3_Upgrade | EL_Increased_Production_L1_Upgrade_FCU | EL_Increased_Production_L2_Upgrade_FCU | EL_Increased_Production_L3_Upgrade_FCU | EL_Advanced_Chemical_Refinement_Upgrade = 0,10"
		,"EG_Increased_Mobility_Upgrade | EG_Increased_Mobility_L2_Upgrade | EG_Increased_Mobility_L3_Upgrade | EG_Scout_Snipers_Upgrade | EG_Overclocked_Snipers_Upgrade | EG_Light_Reflective_Armor_L1_Upgrade | EG_Light_Reflective_Armor_L2_Upgrade | EG_Enhanced_Reactors_L1_Upgrade | EG_Enhanced_Reactors_L2_Upgrade | EG_Upgraded_Cooling_Systems_L1_Upgrade | EG_Upgraded_Cooling_Systems_L2_Upgrade | EG_Heavy_Reflective_Armor_L1_Upgrade | EG_Heavy_Reflective_Armor_L2_Upgrade | EG_Fortified_Transports_Upgrade | EG_Improved_ATAT_Reactors_L1_Upgrade | EG_Improved_ATAT_Reactors_L2_Upgrade | EG_Siege_Bombers_Upgrade = 0,10"  
		,"EG_Magnetically_Sealed_Structure_Upgrade | EG_Repair_Nanites_L1_Upgrade | EG_Repair_Nanites_L2_Upgrade | EG_Enhanced_Turret_Firepower_L1_Upgrade | EG_Enhanced_Turret_Firepower_L2_Upgrade | EG_Enhanced_Turret_Firepower_L3_Upgrade | EG_Enhanced_Base_Shield_Upgrade =0,5"
		
		,"UL_Rancor_Stimulant_L1_Upgrade | UL_Rancor_Stimulant_L2_Upgrade | UL_Ability_Recharge_L1_Upgrade | UL_Ability_Recharge_L2_Upgrade | UL_Selective_Breeding_L1_Upgrade | UL_Selective_Breeding_L2_Upgrade | UL_Smuggled_Droid_Systems_L1_Upgrade | UL_Smuggled_Droid_Systems_L2_Upgrade | UL_Improved_Chipsets_L1_Upgrade | UL_Improved_Chipsets_L2_Upgrade | UL_Improved_Hydraulics_L1_Upgrade | UL_Improved_Hydraulics_L2_Upgrade | UL_Cloaking_Generator_L1_Upgrade | UL_Cloaking_Generator_L2_Upgrade | UL_Weapon_Boost_L1_Upgrade | UL_Weapon_Boost_L2_Upgrade | UL_Heavy_Shielding_L1_Upgrade | UL_Heavy_Shielding_L2_Upgrade | UL_FCU_Armor_Plating_L1_Upgrade | UL_FCU_Reactors_L1_Upgrade = 0,10"
		,"UL_Bombing_Run_Use_Upgrade | UL_Planetary_Bombard_Use_Upgrade | UL_Black_Market_Shielding_L1_Upgrade | UL_Black_Market_Shielding_L2_Upgrade | UL_Bounty_Upgrade | UL_Enhanced_Deployment_L1_Upgrade | UL_Enhanced_Deployment_L2_Upgrade = 0,10"
		,"UL_SMITE_UPGRADE | UL_Refinement_L1_Upgrade | UL_Refinement_L2_Upgrade | UL_Refinement_L3_Upgrade | UL_Improved_Quarry_L1_Upgrade | UL_Improved_Quarry_L2_Upgrade | UL_Improved_Quarry_L3_Upgrade | UL_Increased_Gambling_L1_Upgrade | UL_Increased_Gambling_L2_Upgrade | UL_Increased_Gambling_L3_Upgrade | UL_Extort_Cash_L1_Upgrade | UL_Extort_Cash_L2_Upgrade | UL_Extort_Cash_L3_Upgrade | UL_Increased_Production_L1_Upgrade_FCU | UL_Increased_Production_L2_Upgrade_FCU | UL_Increased_Production_L3_Upgrade_FCU = 0,10"
		,"UG_Rancor_Stimulant_L1_Upgrade | UG_Rancor_Stimulant_L2_Upgrade | UG_Ability_Recharge_L1_Upgrade | UG_Ability_Recharge_L2_Upgrade | UG_Selective_Breeding_L1_Upgrade | UG_Selective_Breeding_L2_Upgrade | UG_Smuggled_Droid_Systems_L1_Upgrade | UG_Smuggled_Droid_Systems_L2_Upgrade | UG_Improved_Chipsets_L1_Upgrade | UG_Improved_Chipsets_L2_Upgrade | UG_Improved_Hydraulics_L1_Upgrade | UG_Improved_Hydraulics_L2_Upgrade | UG_Cloaking_Generator_L1_Upgrade | UG_Cloaking_Generator_L2_Upgrade | UG_Weapon_Boost_L1_Upgrade | UG_Weapon_Boost_L2_Upgrade | UG_Heavy_Shielding_L1_Upgrade | UG_Heavy_Shielding_L2_Upgrade = 0,10" 
		,"UG_Black_Market_Shielding_L1_Upgrade | UG_Black_Market_Shielding_L2_Upgrade | UG_Enhanced_Deployment_L1_Upgrade | UG_Enhanced_Deployment_L2_Upgrade = 0,5"

		,"HL_Combat_Training_L1_Upgrade | HL_Combat_Training_L2_Upgrade | HL_Combat_Training_L3_Upgrade | HL_Heavy_Rockets_L1_Upgrade | HL_Heavy_Rockets_L2_Upgrade | HL_Improved_Combat_Armor_L1_Upgrade | HL_Improved_Combat_Armor_L2_Upgrade | HL_Armor_Plating_L1_Upgrade | HL_Armor_Plating_L2_Upgrade | HL_Armor_Plating_L3_Upgrade | HL_Supercharged_Beams_L1_Upgrade | HL_Supercharged_Beams_L2_Upgrade | HL_Heavy_Armor_L1_Upgrade | HL_Heavy_Armor_L2_Upgrade | HL_Sailbarge_Repair_Crews_Upgrade | HL_Advanced_Gunship_Upgrade = 0,10"
		,"HL_Shielded_Deployment_L1_Upgrade | HL_Secure_Area_Upgrade | HL_Kavadonian_Nanites_Upgrade | HL_Reinforced_Structures_L1_Upgrade | HL_Reinforced_Structures_L2_Upgrade | HL_Reinforced_Structures_L3_Upgrade | HL_Enhanced_Turret_Firepower_L1_Upgrade | HL_Enhanced_Turret_Firepower_L2_Upgrade | HL_Enhanced_Turret_Firepower_L3_Upgrade | HL_Enhanced_Base_Shield_Upgrade | HL_Bombing_Run_Use_Upgrade | HL_Planetary_Bombard_Use_Upgrade | HL_Increased_Supplies_L1_Upgrade | HL_Increased_Supplies_L1_Upgrade_FCU = 0,10"
		,"HL_SMITE_UPGRADE | HL_Improved_Quarry_L1_Upgrade | HL_Improved_Quarry_L2_Upgrade | HL_Improved_Quarry_L3_Upgrade | HL_Improved_Quarry_L4_Upgrade | HL_Improved_Quarry_L5_Upgrade | HL_Increased_Production_L1_Upgrade | HL_Increased_Production_L2_Upgrade | HL_Increased_Production_L3_Upgrade | HL_Increased_Production_L1_Upgrade_FCU | HL_Increased_Production_L2_Upgrade_FCU | HL_Increased_Production_L3_Upgrade_FCU = 0,10"
		,"HG_Combat_Training_L1_Upgrade | HG_Combat_Training_L2_Upgrade | HG_Combat_Training_L3_Upgrade | HG_Heavy_Rockets_L1_Upgrade | HG_Heavy_Rockets_L2_Upgrade | HG_Improved_Combat_Armor_L1_Upgrade | HG_Improved_Combat_Armor_L2_Upgrade | HG_Armor_Plating_L1_Upgrade | HG_Armor_Plating_L2_Upgrade | HG_Armor_Plating_L3_Upgrade | HG_Supercharged_Beams_L1_Upgrade | HG_Supercharged_Beams_L2_Upgrade | HG_Heavy_Armor_L1_Upgrade | HG_Heavy_Armor_L2_Upgrade | HG_Sailbarge_Repair_Crews_Upgrade = 0,10"
		,"HG_Shielded_Deployment_L1_Upgrade | HG_Secure_Area_Upgrade | HG_Kavadonian_Nanites_Upgrade | HG_Reinforced_Structures_L1_Upgrade | HG_Reinforced_Structures_L2_Upgrade | HG_Reinforced_Structures_L3_Upgrade | HG_Enhanced_Turret_Firepower_L1_Upgrade | HG_Enhanced_Turret_Firepower_L2_Upgrade | HG_Enhanced_Turret_Firepower_L3_Upgrade | HG_Enhanced_Base_Shield_Upgrade = 0,5" 
		
		,"PL_More_Garrisons_L1_Upgrade | PL_Bacta_Pack_L1_Upgrade | PL_Bacta_Pack_L2_Upgrade | PL_Improved_Vehicle_Health_L1_Upgrade | PL_Improved_Vehicle_Health_L2_Upgrade | PL_Improved_Vehicle_Damage_L1_Upgrade | PL_Improved_Vehicle_Damage_L2_Upgrade | PL_Increased_Production_L1_Upgrade | PL_Increased_Production_L2_Upgrade | PL_Increased_Production_L3_Upgrade | PL_Reinforced_Structures_L1_Upgrade | PL_Reinforced_Structures_L2_Upgrade | PL_Bombing_Run_Use_Upgrade | PL_Planetary_Bombard_Use_Upgrade = 0,10"
		,"PG_Bacta_Pack_L1_Upgrade | PG_Bacta_Pack_L2_Upgrade | PG_Improved_Vehicle_Health_L1_Upgrade | PG_Improved_Vehicle_Health_L2_Upgrade | PG_Improved_Vehicle_Damage_L1_Upgrade | PG_Improved_Vehicle_Damage_L2_Upgrade | PG_Reinforced_Structures_L1_Upgrade | PG_Reinforced_Structures_L2_Upgrade | PG_Enhanced_Base_Shield_Upgrade = 0,10" 
	}
	}

	RequiredCategories = {"Upgrade"}
	AllowFreeStoreUnits = false

end

function ReserveForce_Thread()

	ReserveForce.Set_Plan_Result(true)
	ReserveForce.Set_As_Goal_System_Removable(false)
	BlockOnCommand(ReserveForce.Produce_Force())

	-- Give some time to accumulate money.
	tech_level = PlayerObject.Get_Tech_Level()
	min_credits = 2000
	if tech_level == 2 then
		min_credits = 3000
	elseif tech_level >= 3 then
		min_credits = 4000
	end

	max_sleep_seconds = 50
	current_sleep_seconds = 0
	while (PlayerObject.Get_Credits() < min_credits) and (current_sleep_seconds < max_sleep_seconds) do
		current_sleep_seconds = current_sleep_seconds + 1
		Sleep(1)
	end

	ScriptExit()
end