#################
# ASCENSION PATHS
#################

@ascension_path_base_weight = 500
@ascension_path_synergy_weight = 2
@ascension_path_anti_synergy_weight = 0.25
@ascension_path_mindwardens_present = 0.3

# Genetic Ascension  (regular empires & Hive Minds)
ap_engineered_evolution = {
	on_enabled = {
		if = {
			limit = {
				has_biogenesis_dlc = yes
				is_wilderness_empire = no
			}
			hidden_effect = {
				country_event = { id = bio.1 }
			}
			custom_tooltip = "engineered_evolution_biogenesis_tt"
			set_country_flag = genomic_research_facility_unlocked
		}
		else_if = {
			limit = {
				has_biogenesis_dlc = yes
				is_wilderness_empire = yes
			}
			hidden_effect = {
				country_event = { id = bio.1 }
			}
			custom_tooltip = "engineered_evolution_wilderness_tt"
		}
		else = {
			custom_tooltip = "engineered_evolution_tooltip"
		}
	}
	possible = {
		custom_tooltip = {
			fail_text = "synthetic_empire_biological_ascension"
			NOT = { has_trait = trait_mechanical }
		}
		if = {
			limit = {
				NOT = {
					has_origin = origin_clone_army
				}
			}
			custom_tooltip = {
				fail_text = "requires_ascension_perks_2"
				num_ascension_perks > 1
			}
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_the_flesh_is_weak"
			NOT = { has_ascension_perk = ap_the_flesh_is_weak }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_organo_machine_interfacing"
			NOT = { has_ascension_perk = ap_organo_machine_interfacing }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_mind_over_matter"
			has_psionic_ascension = no
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_synthetic_evolution"
			NOT = { has_ascension_perk = ap_synthetic_evolution }
		}
		custom_tooltip = {
			fail_text = "requires_free_tradition_tree"
			num_tradition_categories < @max_tradition_trees
		}
		if = {
			limit = {
				has_origin = origin_clone_army
			}
			custom_tooltip = {
				fail_text = "clone_soldier_locked_genes"
				OR = {
					has_country_flag = clone_army_fertility_unlocked
					has_country_flag = clone_army_full_potential
				}
			}
		}
	}

	potential = {
		NOR = {
			has_ascension_perk = ap_engineered_evolution
			has_ascension_perk = ap_the_flesh_is_weak 
			has_ascension_perk = ap_organo_machine_interfacing
			has_ascension_perk = ap_organo_machine_interfacing_assimilator
			has_ascension_perk = ap_synthetic_evolution
			has_ascension_perk = ap_mind_over_matter
			has_ascension_perk = ap_synthetic_age
			is_machine_empire = yes
			has_origin = origin_shroudwalker_apprentice
			has_origin = origin_cybernetic_creed
			has_origin = origin_synthetic_fertility
			has_origin = origin_endbringers
		}
		is_mechanical_empire = no
		is_individual_machine = no
		is_cyborg_empire = no
		is_natural_design_empire = no
		NOT = { has_valid_civic = civic_augmentation_bazaars }
		is_chosen_empire = no
		is_entropy_drinkers_empire = no
	}

	tradition_swap = {
		inherit_effects = yes
		inherit_icon = yes
		name = ap_engineered_evolution_wilderness
		trigger = {
			is_wilderness_empire = yes
		}
	}

	ai_weight = {
		factor = @ascension_path_base_weight
		modifier = {
			factor = @ascension_path_synergy_weight
			has_engineered_evolution_synergy = yes
		}
		modifier = {
			factor = @ascension_path_mindwardens_present
			any_country = {
				has_origin = origin_mindwardens
			}
		}
	}
}

# Cyborg Ascension (regular empires)
ap_the_flesh_is_weak = {
	on_enabled = {
		custom_tooltip = "flesh_is_weak_tooltip"
	}
	possible = {
		custom_tooltip = {
			fail_text = "synthetic_empire_synthetic_ascension"
			NOT = { has_trait = trait_mechanical }
		}
		custom_tooltip = {
			fail_text = "requires_ascension_perks_2"
			OR = {
				num_ascension_perks > 1
				has_origin = origin_cybernetic_creed
				has_origin = origin_unplugged
			}
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_engineered_evolution"
			NOT = { has_ascension_perk = ap_engineered_evolution }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_mind_over_matter"
			has_psionic_ascension = no
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_synthetic_evolution"
			NOT = { has_ascension_perk = ap_synthetic_evolution }
		}
		custom_tooltip = {
			fail_text = "requires_free_tradition_tree"
			num_tradition_categories < @max_tradition_trees
		}
	}

	potential = {
		NOR = {
			has_ascension_perk = ap_engineered_evolution
			has_ascension_perk = ap_the_flesh_is_weak 
			has_ascension_perk = ap_organo_machine_interfacing
			has_ascension_perk = ap_organo_machine_interfacing_assimilator
			has_ascension_perk = ap_synthetic_evolution
			has_ascension_perk = ap_mind_over_matter
			has_ascension_perk = ap_synthetic_age
			has_origin = origin_shroudwalker_apprentice
			has_origin = origin_cybernetic_creed
			has_origin = origin_synthetic_fertility
			has_origin = origin_evolutionary_predators
			has_origin = origin_endbringers
			AND = {
				has_origin = origin_unplugged
				OR = {
					has_country_flag = is_decyberized
					has_country_flag = is_cyberized
				}
			}
		}
		is_gestalt = no
		is_individual_machine = no
		is_natural_design_empire = no
		is_chosen_empire = no
		owner_species = {
			NOT = { has_trait = trait_unplugged_decyberized }
		}
		is_entropy_drinkers_empire = no
	}

	ai_weight = {
		factor = @ascension_path_base_weight
		modifier = {
			factor = @ascension_path_synergy_weight
			is_materialist = yes
		}
		modifier = {
			factor = @ascension_path_anti_synergy_weight
			has_flesh_is_weak_anti_synergy = yes
		}
		modifier = {
			factor = @ascension_path_mindwardens_present
			any_country = {
				has_origin = origin_mindwardens
			}
		}
	}
}

# Cyborg Ascension (Hive Minds)
ap_organo_machine_interfacing = {
	on_enabled = {
		custom_tooltip = "organo_machine_interfacing_tooltip"
	}
	possible = {
		custom_tooltip = {
			fail_text = "requires_ascension_perks_2"
			num_ascension_perks > 1
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_engineered_evolution"
			NOT = { has_ascension_perk = ap_engineered_evolution }
		}
		if = {
			limit = { has_shroud_dlc = yes }
			custom_tooltip = {
				fail_text = "requires_not_ap_mind_over_matter"
				has_psionic_ascension = no
			}
			NOT = { country_has_situation = { SITUATION = situation_shroud_forged } }
		}
		custom_tooltip = {
			fail_text = "requires_free_tradition_tree"
			num_tradition_categories < @max_tradition_trees
		}
	}

	potential = {
		NOR = {
			has_ascension_perk = ap_engineered_evolution
			has_ascension_perk = ap_the_flesh_is_weak 
			has_ascension_perk = ap_organo_machine_interfacing
			has_ascension_perk = ap_organo_machine_interfacing_assimilator
			has_ascension_perk = ap_synthetic_evolution
			has_ascension_perk = ap_mind_over_matter
			has_ascension_perk = ap_synthetic_age
			has_origin = origin_evolutionary_predators
			has_origin = origin_wilderness
			has_origin = origin_endbringers
		}
		is_hive_empire = yes
		is_natural_design_empire = no
		is_chosen_empire = no
		is_entropy_drinkers_empire = no
	}

	ai_weight = {
		factor = @ascension_path_base_weight
		modifier = {
			factor = @ascension_path_mindwardens_present
			any_country = {
				has_origin = origin_mindwardens
			}
		}
	}
}

# Cyborg Ascension (Machine Intelligence: Driven Assimilators)
ap_organo_machine_interfacing_assimilator = {
	on_enabled = {
		custom_tooltip = "organo_machine_interfacing_tooltip"
	}
	possible = {
		custom_tooltip = {
			fail_text = "requires_ascension_perks_2"
			num_ascension_perks > 1
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_synthetic_age"
			NOT = { has_ascension_perk = ap_synthetic_age }
		}
		if = {
			limit = { has_shroud_dlc = yes }
			custom_tooltip = {
				fail_text = "requires_not_ap_interdimensional_processing"
				has_psionic_ascension = no
			}
			NOT = { country_has_situation = { SITUATION = situation_shroud_forged } }
		}
		custom_tooltip = {
			fail_text = "requires_free_tradition_tree"
			num_tradition_categories < @max_tradition_trees
		}
	}

	potential = {
		NOR = {
			has_ascension_perk = ap_engineered_evolution
			has_ascension_perk = ap_the_flesh_is_weak 
			has_ascension_perk = ap_organo_machine_interfacing
			has_ascension_perk = ap_organo_machine_interfacing_assimilator
			has_ascension_perk = ap_synthetic_evolution
			has_ascension_perk = ap_mind_over_matter
			has_ascension_perk = ap_synthetic_age
			has_origin = origin_endbringers
		}
		has_civic = civic_machine_assimilator
		is_chosen_empire = no
		is_entropy_drinkers_empire = no
	}

	ai_weight = {
		factor = @ascension_path_base_weight
		modifier = {
			factor = @ascension_path_synergy_weight
			has_organo_machine_interfacing_assimilator_synergy = yes
		}
		modifier = {
			factor = @ascension_path_mindwardens_present
			any_country = {
				has_origin = origin_mindwardens
			}
		}
	}
}

# Synthetic Ascension (regular empires)
ap_synthetic_evolution = {
	on_enabled = {
		custom_tooltip = "synthetic_evolution_tooltip"
		if = {
			limit = {
				has_origin = origin_necrophage
				has_trait = trait_necrophage
			}
			custom_tooltip = disables_necrophage_features
		}
		if = {
			limit = {
				has_origin = origin_clone_army
				OR = {
					has_trait = trait_clone_soldier_infertile
					has_trait = trait_clone_soldier_infertile_full_potential
					has_trait = trait_clone_soldier_fertile
				}
			}
			custom_tooltip = disables_clone_army_origin_features
		}
		if = {
			limit = {
				has_origin = origin_overtuned
			}
			custom_tooltip = disables_overtuned_features
		}
		if = {
			limit = {
				OR = {
					has_valid_civic = civic_idyllic_bloom
					has_valid_civic = civic_hive_idyllic_bloom
				}
			}
			custom_tooltip = disables_idyllic_bloom
		}
	}
	possible = {
		custom_tooltip = {
			fail_text = "synthetic_empire_synthetic_ascension"
			NOT = { has_trait = trait_mechanical }
		}
		custom_tooltip = {
			fail_text = "requires_ascension_perks_2"
			num_ascension_perks > 1
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_engineered_evolution"
			NOT = { has_ascension_perk = ap_engineered_evolution }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_the_flesh_is_weak"
			NOT = { has_ascension_perk = ap_the_flesh_is_weak }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_mind_over_matter"
			has_psionic_ascension = no
		}
		custom_tooltip = {
			fail_text = "requires_free_tradition_tree"
			num_tradition_categories < @max_tradition_trees
		}
	}

	potential = {
		NOR = {
			has_ascension_perk = ap_engineered_evolution
			has_ascension_perk = ap_the_flesh_is_weak 
			has_ascension_perk = ap_organo_machine_interfacing
			has_ascension_perk = ap_organo_machine_interfacing_assimilator
			has_ascension_perk = ap_synthetic_evolution
			has_ascension_perk = ap_mind_over_matter
			has_ascension_perk = ap_synthetic_age
			is_machine_empire = yes
			has_origin = origin_shroudwalker_apprentice
			has_origin = origin_cybernetic_creed
			has_origin = origin_synthetic_fertility
			has_origin = origin_evolutionary_predators
			has_origin = origin_endbringers
			has_tradition = tr_cybernetics_adopt
		}
		is_gestalt = no
		is_mechanical_empire = no
		is_natural_design_empire = no
		NOT = { has_valid_civic = civic_augmentation_bazaars }
		is_individual_machine = no
		owner_species = {
			NOT = { has_trait = trait_unplugged_decyberized }
		}
		is_chosen_empire = no
		is_galvanic_empire = no
		is_entropy_drinkers_empire = no
	}

	ai_weight = {
		factor = @ascension_path_base_weight
		modifier = {
			factor = @ascension_path_synergy_weight
			has_synthetic_evolution_synergy = yes
		}
		modifier = {
			factor = @ascension_path_anti_synergy_weight
			has_synthetic_evolution_anti_synergy = yes
		}
		modifier = {
			factor = @ascension_path_mindwardens_present
			any_country = {
				has_origin = origin_mindwardens
			}
		}
		modifier = {
			factor = 0
			blocks_ai_synthetic_evolution = yes
		}
	}
}

# Psionic Ascension
ap_mind_over_matter = {
	on_enabled = {
		custom_tooltip = "mind_over_matter_tooltip"
	}
	possible = {
		custom_tooltip = {
			fail_text = "synthetic_empire_psionic_ascension"
			NOT = { has_trait = trait_mechanical }
		}
		if = {
			limit = {
				OR = {
					is_synthetic_empire = no
					has_origin = origin_shroud_forged
					is_chosen_empire = yes
				}
			}
			custom_tooltip = {
				fail_text = "requires_ascension_perks_2"
				num_ascension_perks > 1
			}
		}
		else_if = {
			custom_tooltip = {
				fail_text = "requires_ascension_perks_3"
				num_ascension_perks > 2
			}
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_engineered_evolution"
			NOT = { has_ascension_perk = ap_engineered_evolution }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_the_flesh_is_weak"
			NOT = { has_ascension_perk = ap_the_flesh_is_weak }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_synthetic_evolution"
			NOT = { has_ascension_perk = ap_synthetic_evolution }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_synthetic_age"
			NOT = { has_ascension_perk = ap_synthetic_age }
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_organo_machine_interfacing"
			NOR = {
				has_ascension_perk = ap_organo_machine_interfacing
				has_ascension_perk = ap_organo_machine_interfacing_assimilator
			}
		}
		custom_tooltip = {
			fail_text = "requires_free_tradition_tree"
			num_tradition_categories < @max_tradition_trees
		}
		if = {
			limit = {
				has_origin = origin_unplugged
			}
			custom_tooltip = {
				fail_text = "requires_unplugged_decyberized"
				has_country_flag = is_decyberized
			}
		}
		if = {
			limit = { has_origin = origin_shroud_forged }
			if = {
				limit = {
					any_situation = {
						is_situation_type = situation_shroud_forged
					}
				}
				custom_tooltip = {
					fail_text = "shroud_forged_situation_ongoing"
					always = no
				}
			}
			else = {
				custom_tooltip = {
					fail_text = "shroud_forged_liberation_acquired"
					NOT = { has_country_flag = finish_shroud_forged_liberation_flag }
				}
			}
		}
	}

	potential = {
		NOR = {
			has_country_flag = ratling_country
			has_ascension_perk = ap_engineered_evolution
			has_ascension_perk = ap_the_flesh_is_weak 
			has_ascension_perk = ap_organo_machine_interfacing
			has_ascension_perk = ap_organo_machine_interfacing_assimilator
			has_ascension_perk = ap_synthetic_evolution
			has_ascension_perk = ap_mind_over_matter
			has_ascension_perk = ap_synthetic_age
			has_origin = origin_shroudwalker_apprentice
			has_origin = origin_cybernetic_creed
			has_origin = origin_synthetic_fertility
			has_origin = origin_evolutionary_predators
			has_origin = origin_wilderness
			has_valid_civic = civic_augmentation_bazaars
			has_origin = origin_mindwardens
			has_origin = origin_endbringers
		}
		OR = {
			has_shroud_dlc = yes # Shroud DLC allows gestalt/machines to become Psionic
			AND = {
				is_gestalt = no
				is_mechanical_empire = no
				OR = {
					is_cyborg_empire = no
					AND = {
						has_origin = origin_unplugged
						NOT = { has_country_flag = is_cyberized }
					}
				}
				is_individual_machine = no
			}
		}
		is_natural_design_empire = no
		if = {
			limit = { has_origin = origin_shroud_forged }
			NOT = { has_country_flag = finish_shroud_forged_control_flag }
		}
	}

	tradition_swap = {
		name = ap_interdimensional_processing
		inherit_name = no
		inherit_icon = no
		inherit_effects = yes
		trigger = {
			has_shroud_dlc = yes
			is_synthetic_empire = yes
		}
		weight = { factor = 1 }
	}

	ai_weight = {
		factor = @ascension_path_base_weight
		modifier = {
			factor = @ascension_path_synergy_weight
			is_spiritualist = yes
		}
		modifier = {
			factor = @ascension_path_synergy_weight
			OR = {
				has_mind_over_matter_synergy = yes
				any_country = {
					has_origin = origin_mindwardens
					NOT = { is_same_value = prev }
				}
			}
		}
		modifier = {
			factor = @ascension_path_synergy_weight
			# We want more psionic AIs when someone's playing Mindwardens, so you should ascend if at least you're not materialist
			is_materialist = no
			any_country = {
				has_origin = origin_mindwardens
			}
		}
		modifier = {
			factor = @ascension_path_anti_synergy_weight
			has_mind_over_matter_anti_synergy = yes
		}
		modifier = {
			factor = value:psionic_offices_mind_over_matter_mult
			any_owned_planet = {
				exists = branch_office_owner
				has_holding = {
					holding = building_psionic_offices
					owner = branch_office_owner
				}
			}
		}
		modifier = {
			factor = 0
			has_origin = origin_mindwardens
		}
	}
}

# Synthetic Ascension (Machine Intelligence or Individualistic Machine)
ap_synthetic_age = {
	potential = {
		OR = {
			is_machine_empire = yes
			is_individual_machine = yes
		}
		NOR = {
			has_ascension_perk = ap_engineered_evolution
			has_ascension_perk = ap_the_flesh_is_weak 
			has_ascension_perk = ap_organo_machine_interfacing
			has_ascension_perk = ap_organo_machine_interfacing_assimilator
			has_ascension_perk = ap_synthetic_evolution
			has_ascension_perk = ap_mind_over_matter
			has_ascension_perk = ap_synthetic_age
			has_origin = origin_shroudwalker_apprentice
			has_origin = origin_endbringers
		}
		is_natural_design_empire = no
		is_chosen_empire = no
		is_entropy_drinkers_empire = no
	}

	possible = {
		custom_tooltip = {
			fail_text = "requires_ascension_perks_2"
			num_ascension_perks > 1
		}
		custom_tooltip = {
			fail_text = "requires_not_ap_organo_machine_interfacing"
			NOT = { has_ascension_perk = ap_organo_machine_interfacing_assimilator }
		}
		if = {
			limit = { has_shroud_dlc = yes }
			custom_tooltip = {
				fail_text = "requires_not_ap_interdimensional_processing"
				has_psionic_ascension = no
			}
			NOT = { country_has_situation = { SITUATION = situation_shroud_forged } }
		}
		custom_tooltip = {
			fail_text = "requires_free_tradition_tree"
			num_tradition_categories < @max_tradition_trees
		}
	}

	custom_tooltip = "synthetic_age_tooltip"

	tradition_swap = {
		inherit_name = yes
		inherit_effects = no
		inherit_icon = yes
		trigger = {
			has_machine_age_dlc = yes
		}
		custom_tooltip = "synthetic_age_tooltip_machine_age"
		on_enabled = {
			hidden_effect = {
				country_event = { id = machine_age.4000 }
			}
		}

		weight = {
			factor = 1
		}
	}

	ai_weight = {
		factor = @ascension_path_base_weight
		modifier = {
			factor = @ascension_path_anti_synergy_weight
			has_synthetic_age_anti_synergy = yes
		}
		modifier = {
			factor = @ascension_path_mindwardens_present
			any_country = {
				has_origin = origin_mindwardens
			}
		}
	}
}
