# Pagans can subjugate other pagans
pagan_subjugation = {
	name = CB_NAME_PAGAN_SUBJUGATION
	war_name = WAR_NAME_PAGAN_SUBJUGATION
	sprite = 8
	truce_days = 365
	is_permanent = yes
	can_ask_to_join_war = yes
	allowed_to_target_tributaries = no
	defender_unoccupied_warscore = yes
	
	sort_priority = 2000
	
	can_use = {
		ROOT = {
			religion_group = pagan_group
			is_reformed_religion = no
			NOT = { religion = hellenic_pagan }
			NOT = { same_realm = FROM }
			NOT = { is_liege_or_above = FROM }
                        NOT = ( has_law = succ_seniority }
			mercenary = no
			OR = {
				AND = {
					has_dlc = "Horse Lords"
					is_nomadic = no
				}
				AND = {
					NOT = { has_dlc = "Horse Lords" }
					has_horde_culture = no # Should use tribal invasion instead
				}
			}		
			OR = {
				is_tribal = yes
				primary_title = {
					has_law = succ_elective_gavelkind
				}
			}
			
			OR = {
				NOT = { has_character_modifier = launched_subjugation }
				AND = {
					has_ambition = obj_become_king
					capital_scope = {
						kingdom = {
							FROM = {
								any_realm_title = {
									kingdom = {
										title = PREVPREVPREV
									}
								}
							}
						}
					}
				}
			}
		}
		
		OR = {
			NOT = { ROOT = { religion = aztec } }
			FROM = { religion = aztec }
		}
		
		FROM = {
			in_revolt = no
			religion_group = pagan_group
			is_nomadic = no
			NOT = { is_offmap_governor = yes }
			OR = {
				is_reformed_religion = no
				is_reformed_religion = ROOT
			}
			NOT = {
				any_war = {
					defender = { character = PREVPREV }
					OR = {
						using_cb = pagan_subjugation
						using_cb = nomad_subjugation
					}
				}
			}
		}
	}
	
	on_add = {
		ROOT = {
			add_character_modifier = { 
				name = launched_subjugation
				years = 100
				hidden = yes
			}
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	on_success = {
		ROOT = {
			piety = 100
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		FROM = {
			piety = -100
			prestige = -100
			
			if = {
				limit = {
					is_reformed_religion = ROOT
					controls_religion = no
				}
				religion = ROOT # Reformed pagans are forced to convert back
			}
			
			custom_tooltip = {
				text = tribal_subjugation_tip
			}
				
			hidden_tooltip = {
				opinion = {
					modifier = opinion_subjugated 
					who = ROOT
				}
				any_vassal = {
					opinion = {
						modifier = opinion_subjugated 
						who = ROOT
					}
				}				
				any_demesne_title = {
					limit = {
						higher_tier_than = ROOT
					}
					ROOT = { usurp_title = { target = PREV type = invasion } }
					add_pressed_claim = PREV
				}
				any_demesne_title = {
					limit = {
						tier = ROOT
					}
					ROOT = { usurp_title = { target = PREV type = invasion } }
					add_pressed_claim = PREV
				}
				set_defacto_liege = ROOT
			}
		}
	}
	
	on_fail = {
		FROM = {
			piety = 50
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
		ROOT = {
			piety = -100
		}
	}
	
	on_invalidation = {
		ROOT = {
			remove_character_modifier = launched_subjugation
		}
	}

	on_reverse_demand = {
		ROOT = {
			piety = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 2.0
			}
		}
		FROM = {
			piety = 100
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
						OR = { 
							religion_group = christian
							religion = hellenic_pagan
							religion = hellenic_pagan_reformed
						}
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = { 
		factor = 1
		modifier = { #Focus on Coronation first.
			factor = 0.1
			has_dlc = "Holy Fury"
			ROOT = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
	}
}