﻿select_personal_leviathan_union_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"
	}
	desc = select_personal_leviathan_union_decision_desc
	selection_tooltip = select_personal_leviathan_union_decision_tooltip

	is_shown = {
		# Following a valid religion & faith.
		faith = { has_doctrine = special_doctrine_british_unity } #Do they have the Leviathan virtues/sins doctrine?

		faith = { has_doctrine_parameter = select_personal_god_active }
	}

	is_valid = {
	}

	is_valid_showing_failures_only = {
		# Have to at _least_ not be in piety debt.
		piety >= 0
	}

	cooldown = { years = 2 }

	effect = {
		# Show the possible options.
		show_as_tooltip = {
			random_list = {
				desc = select_personal_leviathan_union_decision_tt
				100 = {
					show_chance = no
					desc = select_personal_leviathan_union_decision.select_nationalisators
					add_character_modifier = bhakti_leviathan_nationalisators
				}
				100 = {
					show_chance = no
					desc = select_personal_leviathan_union_decision.select_technosaurs
					add_character_modifier = bhakti_leviathan_technosaurs
				}
				100 = {
					show_chance = no
					desc = select_personal_leviathan_union_decision.select_mechasaurs
					add_character_modifier = bhakti_leviathan_mechasaurs
				}
				100 = {
					show_chance = no
					desc = select_personal_leviathan_union_decision.select_petrosaurs
					add_character_modifier = bhakti_leviathan_petrosaurs
				}
				100 = {
					show_chance = no
					desc = select_personal_leviathan_union_decision.select_metallurgicals
					add_character_modifier = bhakti_leviathan_metallurgicals
				}
				100 = {
					show_chance = no
					desc = select_personal_leviathan_union_decision.select_nautiluses
					add_character_modifier = bhakti_leviathan_nautiluses
				}
				100 = {
					show_chance = no
					desc = select_personal_leviathan_union_decision.select_aerosaurs
					add_character_modifier = bhakti_leviathan_aerosaurs
				}
			}
		}
		# And the actual effect.
		trigger_event = NEOW_religious_decision.0001
	}

	ai_check_interval = 96
	
	ai_potential = {
		piety >= minor_piety_value
		NOR = {
			has_character_modifier = bhakti_leviathan_nationalisators
			has_character_modifier = bhakti_leviathan_technosaurs
			has_character_modifier = bhakti_leviathan_mechasaurs
			has_character_modifier = bhakti_leviathan_petrosaurs
			has_character_modifier = bhakti_leviathan_metallurgicals
			has_character_modifier = bhakti_leviathan_nautiluses
			has_character_modifier = bhakti_leviathan_aerosaurs
		}
	}

	ai_will_do = {
		base = 100
	}
}
subjugate_hof_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_major_religion.dds"
	}

	desc = subjugate_hof_decision_desc
	selection_tooltip = subjugate_hof_decision_tooltip
	
	decision_group_type = major

	is_shown = {
		#always = no
		faith = {
			exists = religious_head
		}
		#let's not assimilate people if the HoF doesn't have our own faith
		faith = faith.religious_head.faith
		any_religion_global = {
			any_faith = {
				NOT = {
					this = root.faith
				}
				NOT = {
					has_locked_hof = yes
				}
				NOT = {
					has_doctrine = unreformed_faith_doctrine
				}
				OR = {
					AND = {
						faith_hostility_level = {
							target = root.faith
							value <= faith_astray_level
						}
						root.faith = {
							faith_hostility_level = {
								target = prev
								value <= faith_astray_level
							}
						}
						#this decision is mostly disabled for now, since we want more control
						#but it's enabled to revert emancipations
						always = no
					}
					AND = {
						has_variable = former_foreign_hof
						var:former_foreign_hof = root.faith
					}
				}
				any_holy_site = {
					#count >= holy_sites_to_create_spiritual_head_of_faith
					count >= 3
					holder.top_liege = root
					holder.faith = root.faith
				}
				OR = {
					AND = {
						has_doctrine = doctrine_spiritual_head
						root.faith = {
							has_doctrine = doctrine_spiritual_head
						}
					}
					AND = {
						has_doctrine = doctrine_temporal_head
						root.faith = {
							has_doctrine = doctrine_temporal_head
						}
					}
					AND = {
						has_doctrine = doctrine_holy_order_head
						root.faith = {
							has_doctrine = doctrine_holy_order_head
						}
					}
					#headless faiths can't be subjugated
					#has_doctrine = doctrine_no_head
				}
				OR = {
					NOT = {
						exists = religious_head
					}
					NOT = {
						religious_head.faith = root.faith
					}
				}
				#don't assimilate dead faiths
				num_county_followers > 0
			}
		}
	}
	is_valid = {
		piety_level >= 3
		is_independent_ruler = yes
		
		faith = faith.religious_head.faith
		
		#custom_description = your_faith_holds_at_least_3_holy_sites
	}

	is_valid_showing_failures_only = {

	}

	effect = {
		faith = {
			save_scope_as = dominant_faith
		}
		every_religion_global = {
			random_faith = {
				limit = {
					NOT = {
						this = root.faith
					}
					NOT = {
						has_doctrine = unreformed_faith_doctrine
					}
					NOT = {
						has_locked_hof = yes
					}
					OR = {
						AND = {
							faith_hostility_level = {
								target = root.faith
								value <= faith_astray_level
							}
							root.faith = {
								faith_hostility_level = {
									target = prev
									value <= faith_astray_level
								}
							}
							#this decision is mostly disabled for now, since we want more control
							#but it's enabled to revert emancipations
							always = no
						}
						AND = {
							has_variable = former_foreign_hof
							var:former_foreign_hof = root.faith
						}
					}
					any_holy_site = {
						#count >= holy_sites_to_create_spiritual_head_of_faith
						count >= 3
						holder.top_liege = root
						holder.faith = root.faith
					}
					OR = {
						AND = {
							has_doctrine = doctrine_spiritual_head
							root.faith = {
								has_doctrine = doctrine_spiritual_head
							}
						}
						AND = {
							has_doctrine = doctrine_temporal_head
							root.faith = {
								has_doctrine = doctrine_temporal_head
							}
						}
						AND = {
							has_doctrine = doctrine_holy_order_head
							root.faith = {
								has_doctrine = doctrine_holy_order_head
							}
						}
						has_doctrine = doctrine_no_head
					}
					OR = {
						NOT = {
							exists = religious_head
						}
						NOT = {
							religious_head.faith = root.faith
						}
					}
					#don't assimilate dead faith
					num_county_followers > 0
				}
				save_scope_as = subjugated_faith
				set_variable = faith_that_was_subjugated
			}
		}
		
		scope:subjugated_faith = {
			religious_head_title ?= {
				root.faith.religious_head = {
					destroy_title = scope:subjugated_faith.religious_head_title
				}
			}
			set_religious_head_title = root.faith.religious_head_title
			
		}
		
	}
	
	cost = {
		piety = massive_piety_value
		#TODO cost should scale with religious differences - it should be hard to join with a faith from another religion, for example
	}

	ai_check_interval = 36

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}	