#########################################
# Astral Planes - Astral Thread Actions #
#########################################

@ASTRAL_ACTION_10_YEARS_COOLDOWN = 3600
@ASTRAL_ACTION_5_YEARS_COOLDOWN = 1800
@ASTRAL_ACTION_2_HALF_YEARS_COOLDOWN = 900
@ASTRAL_ACTION_YEAR_COOLDOWN = 360

action_astral_boost = {
	sound = action_activation_astral_boost
	unlock_threshold = 1

	activation_cost = {
		cost = {
			astral_threads = 1
			multiplier = value:scaled_astral_action_cost|BASE|500|INCREASE|50|INCREASE_VARIABLE|astral_boost_usage_count|MAX|1000|
		}
	}

	cooldown = @ASTRAL_ACTION_5_YEARS_COOLDOWN
	picture = GFX_astral_action_astral_boost

	effect = {
		add_modifier = {
			modifier = "astral_boost_modifier"
			days = @ASTRAL_ACTION_5_YEARS_COOLDOWN
		}
		hidden_effect = {
			change_variable = {
				which = astral_boost_usage_count
				value = 1
			}
		}
	}

	ai_weight = {
		weight = 10
		modifier = {
			factor = 100
			is_at_war = yes
		}
	}
}

action_quantum_catapult_insight = {
	sound = event_administrative_work
	unlock_threshold = 2
	usages = 1
	upgrade = action_quantum_catapult_insight_2

	activation_cost = {
		cost = {
			astral_threads = 750
		}
	}

	picture = GFX_astral_action_quantum_catapult_insight

	potential = {
		has_overlord_dlc = yes
		is_nomadic = no
		NOR = {
			has_technology = tech_quantum_catapult
			has_tech_option = tech_quantum_catapult
		}
	}

	effect = {
		hidden_effect = {
			set_country_flag = has_quantum_catapult_insight
		}
		add_tech_progress = {
			tech = tech_quantum_catapult
			progress = 0.25
		}
	}

	ai_weight = {
		weight = 1000
	}
}

action_quantum_catapult_insight_2 = {
	sound = event_administrative_work
	unlock_threshold = 2
	usages = 1

	activation_cost = {
		cost = {
			astral_threads = 1500
		}
	}

	picture = GFX_astral_action_quantum_catapult_insight

	potential = {
		has_overlord_dlc = yes
		is_nomadic = no
		OR = {
			has_technology = tech_quantum_catapult
			has_tech_option = tech_quantum_catapult
		}
	}

	allow = {
		custom_tooltip = {
			fail_text = "action_quantum_catapult_insight_2_requirement_tooltip"
			any_owned_megastructure = {
				is_functional_quantum_catapult_megastructure = yes
			}
		}
	}

	effect = {
		add_modifier = {
			modifier = quantum_catapult_insight_2_modifier
		}
	}

	ai_weight = {
		weight = 1000
	}
}

action_exodus_jump_insight = {
	sound = event_administrative_work
	unlock_threshold = 2
	usages = 1
	upgrade = action_exodus_jump_insight_2

	activation_cost = {
		cost = {
			astral_threads = 750
		}
	}

	picture = GFX_astral_action_quantum_catapult_insight

	potential = {
		is_nomadic = yes
		NOR = {
			has_technology = tech_arkship_exodus_jump
			has_tech_option = tech_arkship_exodus_jump
		}
	}

	effect = {
		hidden_effect = {
			set_country_flag = has_exodus_jump_insight
		}
		add_tech_progress = {
			tech = tech_arkship_exodus_jump
			progress = 0.25
		}
	}

	ai_weight = {
		weight = 1000
	}
}

action_exodus_jump_insight_2 = {
	sound = event_administrative_work
	unlock_threshold = 2
	usages = 1

	activation_cost = {
		cost = {
			astral_threads = 1500
		}
	}

	picture = GFX_astral_action_quantum_catapult_insight

	potential = {
		is_nomadic = yes
		OR = {
			has_technology = tech_arkship_exodus_jump
			has_tech_option = tech_arkship_exodus_jump
		}
	}

	allow = {
		custom_tooltip = {
			fail_text = "action_exodus_jump_insight_2_requirement_tooltip"
			any_owned_fleet = {
				is_arkship_fleet = yes
				starbase? = {
					has_starbase_module = arkship_exodus_jump
				}
			}
		}
	}

	effect = {
		add_modifier = {
			modifier = quantum_catapult_insight_2_modifier
		}
	}

	ai_weight = {
		weight = 1000
	}
}

action_summon_dimensional_fleet = {
	sound = action_activation_phase_fleet
	unlock_threshold = 5

	activation_cost = {
		cost = {
			astral_threads = 1750
		}
	}

	cooldown = @ASTRAL_ACTION_5_YEARS_COOLDOWN
	picture = GFX_astral_action_summon_dimensional_fleet

	allow_unlock = {
		has_technology = tech_psionic_theory
	}

	effect = {
		custom_tooltip = "action_summon_dimensional_fleet_tooltip"

		create_fleet = {
			name = "NAME_Dimensional_Fleet"
			settings = {
				can_upgrade = no
				can_change_composition = no
				can_change_leader = no
				uses_naval_capacity = no
				spawn_debris = no
			}
			effect = {
				set_owner = root
				while = {
					count = value:num_dimensional_fleet_big_ships
					create_ship = {
						fleet_cache_recalc = no #skip fleet cache recalculation on each individual ship being added. Effect create_fleet will recalculate everything once after all the ships are in.
						name = "NAME_Astral_Avatar"
						design = "NAME_Astral_Avatar"
						upgradable = no
						graphical_culture = "extra_dimensional_01"
					}
				}
				while = {
					count = value:num_dimensional_fleet_small_ships
					create_ship = {
						fleet_cache_recalc = no #skip fleet cache recalculation on each individual ship being added. Effect create_fleet will recalculate everything once after all the ships are in.
						name = "NAME_Astral_Avatar_Small"
						design = "NAME_Astral_Avatar_Small"
						upgradable = no
						graphical_culture = "extra_dimensional_01"
					}
				}
				set_location = root.capital_scope
				set_fleet_flag = dimensional_fleet
			}
		}

		hidden_effect = {
			last_created_fleet = {
				fleet_event = {
					id = astral_planes.1000
					days = @ASTRAL_ACTION_5_YEARS_COOLDOWN
				}
			}
		}
	}

	ai_weight = {
		weight = 10
		modifier = {
			factor = 10
			is_militarist = yes
		}
		modifier = {
			factor = 100
			is_at_war = yes
		}
	}
}

action_astral_splitting = {
	sound = rift_open
	usages = 4

	activation_cost = {
		cost = {
			astral_threads = 1
			multiplier = value:scaled_astral_action_cost|BASE|300|INCREASE|300|INCREASE_VARIABLE|num_rifts_splitted|MAX|1200|
		}
	}

	cooldown = @ASTRAL_ACTION_10_YEARS_COOLDOWN
	picture = GFX_astral_action_astral_splitting

	allow_unlock = {
		has_technology = tech_rift_sphere
	}

	allow = {
		custom_tooltip = {
			fail_text = "action_astral_splitting_too_many_rifts"
			check_variable = {
				which = num_rifts_splitted
				value < 4
			}
			is_astral_rift_pool_empty = no
		}
		custom_tooltip = {
			fail_text = "action_astral_splitting_no_rift_spawning_location"
			if = {
				limit = {
					is_nomadic = no
				}
				any_system_within_border = {
					can_spawn_astral_rift = yes
				}
			}
			else = {
				any_owned_nonprimary_starbase = {
					is_waystation_starbase = yes
					solar_system? = {
						can_spawn_astral_rift = yes
					}
				}
			}
		}
	}

	effect = {
		hidden_effect = {
			change_variable = {
				which = num_rifts_splitted
				value = 1
			}
		}
		if = {
			limit = {
				is_nomadic = no
			}
			astral_splitting = yes
		}
		else = {
			astral_splitting_nomad = yes
		}
	}

	ai_weight = {
		weight = 0
		modifier = {
			add = 200
			count_owned_leader = {
				count >= 2
				limit = {
					leader_class = scientist
				}
			}
		}
		modifier = {
			add = 100
			count_owned_leader = {
				count > 2
				limit = {
					leader_class = scientist
				}
			}
		}
	}
}

action_gain_physics_insight = {
	sound = event_administrative_work

	activation_cost = {
		cost = {
			astral_threads = 1
			multiplier = value:scaled_astral_action_cost|BASE|250|INCREASE|50|INCREASE_VARIABLE|physics_insight_usage_count|MAX|1750|
		}
	}

	cooldown = @ASTRAL_ACTION_5_YEARS_COOLDOWN
	picture = GFX_astral_action_gain_physics_insight

	effect = {
		add_modifier = {
			modifier = gain_physics_insight_modifier
			days = @ASTRAL_ACTION_5_YEARS_COOLDOWN
		}
		hidden_effect = {
			change_variable = {
				which = physics_insight_usage_count
				value = 1
			}
		}
	}

	ai_weight = {
		weight = 100
	}
}

action_hyper_relay_insight = {
	sound = event_administrative_work
	unlock_threshold = 2
	upgrade = action_flash_forge_hyper_relay

	activation_cost = {
		cost = {
			astral_threads = 300
		}
	}

	picture = GFX_astral_action_hyper_relay_insight

	potential = {
		has_overlord_dlc = yes
		NOR = {
			has_technology = tech_hyper_relays
			has_tech_option = tech_hyper_relays
		}
	}

	allow = {
		has_technology = tech_hyper_drive_2
	}

	is_exhausted = {
		has_tech_option = tech_hyper_relays
	}

	effect = {
		add_tech_progress = {
			tech = tech_hyper_relays
			progress = 0.5
		}
	}

	ai_weight = {
		weight = 1000
	}
}

action_flash_forge_hyper_relay = {
	sound = evn_ove_hyper_relay_construction
	unlock_threshold = 2

	activation_cost = {
		cost = {
			influence = 50
		}
		cost = {
			astral_threads = 1
			multiplier = value:scaled_astral_action_cost|BASE|500|INCREASE|50|INCREASE_VARIABLE|flash_forge_usage_count|MAX|1000|
		}
	}

	cooldown = @ASTRAL_ACTION_2_HALF_YEARS_COOLDOWN
	uses_custom_cooldown = yes
	picture = GFX_astral_action_flash_forge_hyper_relay

	potential = {
		OR = {
			has_technology = tech_hyper_relays
			has_tech_option = tech_hyper_relays
		}
	}

	effect = {
		custom_tooltip = "action_flash_forge_hyper_relay_tooltip"
		set_country_flag = flash_forge_hyper_relay_activated
		hidden_effect = {
			change_variable = {
				which = flash_forge_usage_count
				value = 1
			}
		}
	}

	allow = {
		has_technology = tech_hyper_relays
		custom_tooltip = {
			fail_text = "action_flash_forge_hyper_relay_available_tooltip"
			NOT = { has_country_flag = flash_forge_hyper_relay_activated }
		}
		custom_tooltip = {
			fail_text = "action_flash_forge_hyper_relay_executing_tooltip"
			NOT = {
				any_owned_fleet = {
					is_ship_class = shipclass_constructor
					has_fleet_flag = flash_forging_hyper_relay
				}
			}
		}
	}

	ai_weight = {
		weight = 0
		modifier = {
			add = 200
			if = {
				limit = {
					is_nomadic = no
				}
				any_system_within_border = {
					has_any_hyper_relay = no
				}
			}
			else = {
				any_owned_nonprimary_starbase = {
					has_starbase_size >= starbase_waystation_2
					solar_system = {
						has_any_hyper_relay = no
					}
				}
			}
		}
	}
}

action_lateral_artifacting = {
	sound = action_activation_refresh_triumph
	unlock_threshold = 4

	activation_cost = {
		cost = {
			astral_threads = 1
			multiplier = value:lateral_artifacting_cost|BASE|1000|BASE_DAYS|3600|INCREASE|100|INCREASE_VARIABLE|lateral_artifacting_usage_count|MAX|2000|
		}
	}

	cooldown = @ASTRAL_ACTION_10_YEARS_COOLDOWN
	picture = GFX_astral_action_lateral_artifacting

	allow_unlock = {
		num_owned_relics >= 2
	}

	allow = {
		has_modifier = relic_activation_cooldown
	}

	effect = {
		hidden_effect = {
			export_modifier_duration_to_variable = {
				modifier = relic_activation_cooldown
				variable = lateral_artifacting_remaining_duration
			}
			set_timed_country_flag = {
				flag = lateral_artifacting_available
				days = lateral_artifacting_remaining_duration
			}
			remove_modifier = relic_activation_cooldown
			clear_variable = lateral_artifacting_remaining_duration
			change_variable = {
				which = lateral_artifacting_usage_count
				value = 1
			}
		}
		custom_tooltip = "action_lateral_artifacting_tooltip"
	}

	ai_weight = {
		weight = 500
		modifier = {
			factor = 0
			has_resource = {
				type = unity
				amount < 10000
			}
		}
	}
}

action_dimensional_lock = {
	sound = action_activation_construct_lock
	unlock_threshold = 3

	activation_cost = {
		cost = {
			astral_threads = @dimensional_lock_cost
		}
	}

	cooldown = @ASTRAL_ACTION_10_YEARS_COOLDOWN # Overriden by define DIMENSIONAL_LOCK_EXPIRATION_TIME
	uses_custom_cooldown = yes
	picture = GFX_astral_action_dimensional_lock

	allow_unlock = {
		has_technology = tech_wormhole_stabilization
	}

	effect = {
		custom_tooltip = "action_dimensional_lock_tooltip"
		set_country_flag = dimensional_lock_available
	}

	ai_weight = {
		weight = 10
		modifier = {
			factor = 10
			is_militarist = yes
		}
		modifier = {
			factor = 100
			is_at_war = yes
		}
		modifier = {
			factor = 0
			OR = {
				NOT = {
					any_system_within_border = {
						has_natural_wormhole = yes
					}
				}
				NOT = {
					any_owned_nonprimary_starbase = {
						is_waystation_starbase = yes
						solar_system? = {
							has_natural_wormhole = yes
						}
					}
				}
			}
		}
	}
}

action_folding_hyperspace = {
	sound = action_activation_astral_hyperjump
	unlock_threshold = 3
	usages = 1
	custom_usage_tooltip = ASTRAL_ACTION_UNIQUE_USAGE_DESC_FLEET_ABILITY

	activation_cost = {
		cost = {
			astral_threads = 1000
		}
	}

	picture = GFX_astral_action_folding_hyperspace

	allow_unlock = {
		OR = {
			has_technology = tech_jump_drive_1
			has_technology = tech_psi_jump_drive_1
			has_technology = tech_subspace_drive
		}
	}

	effect = {
		if = {
			limit = { is_nomadic = yes }
			custom_tooltip = "action_folding_hyperspace_tooltip_nomad"
		}
		else = {
			custom_tooltip = "action_folding_hyperspace_tooltip"
		}
		set_country_flag = unlock_astral_jump
	}

	ai_weight = {
		weight = 10
		modifier = {
			factor = 10
			is_militarist = yes
		}
		modifier = {
			factor = 100
			is_at_war = yes
		}
	}
}

action_dimensional_shifting = {
	sound = action_activation_phase_fleet
	unlock_threshold = 4
	usages = 1
	custom_usage_tooltip = ASTRAL_ACTION_UNIQUE_USAGE_DESC_FLEET_ABILITY

	activation_cost = {
		cost = {
			astral_threads = 1000
		}
	}

	picture = GFX_astral_action_dimensional_shifting

	effect = {
		custom_tooltip = "action_dimensional_shifting_tooltip"
		set_country_flag = unlock_phase_fleet
	}

	ai_weight = {
		weight = 10
		modifier = {
			factor = 10
			is_militarist = yes
		}
		modifier = {
			factor = 100
			is_at_war = yes
		}
	}
}

action_astral_siphon = {
	sound = action_activation_astral_siphon
	unlock_threshold = 1
	usages = 3

	activation_cost = {
		cost = {
			trigger = {
				check_variable = { which = astral_siphon_unlocked value <= 0 }
			}
			astral_threads = 700
		}
		cost = {
			trigger = {
				check_variable = { which = astral_siphon_unlocked value = 1 }
			}
			astral_threads = 800
		}
		cost = {
			trigger = {
				check_variable = { which = astral_siphon_unlocked value >= 2 }
			}
			astral_threads = 900
		}
	}

	cooldown = @ASTRAL_ACTION_10_YEARS_COOLDOWN
	picture = GFX_astral_action_astral_siphon

	effect = {
		hidden_effect = {
			if = {
				limit = {
					check_variable = {
						which = astral_siphon_unlocked
						value < 1
					}
				}
				custom_tooltip = action_astral_siphon_unlock_tooltip_lvl1
			}
			else_if = {
				limit = {
					check_variable = {
						which = astral_siphon_unlocked
						value = 1
					}
				}
				custom_tooltip = action_astral_siphon_unlock_tooltip_lvl2
			}
			else = {
				custom_tooltip = action_astral_siphon_unlock_tooltip_lvl3
			}
			change_variable = {
				which = astral_siphon_unlocked
				value = 1
			}
		}
	}

	ai_weight = {
		weight = 200
	}
}

action_planar_mastery = {
	sound = ap_rift_event_0_astral_wonder
	unlock_threshold = 5
	usages = 1

	activation_cost = {
		cost = {
			astral_threads = 1500
		}
	}

	picture = GFX_astral_action_planar_mastery

	effect = {
		custom_tooltip = "action_planar_mastery_tooltip"
		set_country_flag = action_planar_mastery_activated
	}

	ai_weight = {
		weight = 10
		modifier = {
			factor = 100
			end_game_years_passed > 0
		}
	}
}
