hs_invasion = {
	name = CB_NAME_HSINVASION
	war_name = WAR_NAME_HSINVASION
	sprite = 8
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	can_ask_to_join_war = yes
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
	max_defender_occupation_score = 90
	allowed_to_target_tributaries = no
	
	sort_priority = 2000

	can_use_gui = {
		FROM = {
			conditional_tooltip = {
				trigger = {
					tier = BARON
				}
				ROOT = { prestige = 1000}
			}
			conditional_tooltip = {
				trigger = {
					tier = COUNT
				}
				ROOT = { prestige = 1000}
			}
			conditional_tooltip = {
				trigger = {
					tier = DUKE
				}
				ROOT = {prestige = 1500}
			}
			conditional_tooltip = {
				trigger = {
					tier = KING
				}
				ROOT = { prestige = 2000}
			}
			conditional_tooltip = {
				trigger = {
					tier = EMPEROR
				}
				ROOT = { prestige = 2500}
			}
		}
		
		#relative_realm_size = {
		#	who = FROM 
		#	size < 5
		#}
		check_if_crusader_trigger = yes
	}
	
	on_add = {
		if = {
			limit = { FROM = {lower_real_tier_than = DUKE} }
			ROOT = { prestige = -1000 }
		}
		if = {
			limit = { FROM = {tier = DUKE} }
			ROOT = { prestige = -1500 }
		}
		if = {
			limit = { FROM = {tier = KING} }
			ROOT = { prestige = -2000 }
		}
		if = {
			limit = { FROM = {tier = EMPEROR} }
			ROOT = { prestige = -2500 }
		}
		
		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 
			}
		}
	}

	can_use_title = {
		ROOT = {
			is_nomadic = no
			hs_isqingluezhe = yes
			OR = {
				trait = hs_bakemono
				trait = hs_renxing
				trait = cruel
				trait = ambitious
				trait = greedy
				trait = possessed
				trait = lunatic
			}
		}
		
		ROOT = {
			NOT = { same_realm = FROM }
		}
		
		OR = { # This ensures that the AI doesn't declare this type of war against someone who only holds a few counties within the targeted title...
			ROOT = {
				ai = no
			}
			FROM = {
				num_of_realm_counties = {
					value = 3
					title = PREV
				}
			}
		}
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_success = {
		ROOT = {
			show_scope_change = no
			prestige = 200
			participation_scaled_prestige = 200
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		FROM = {
			show_scope_change = no
			prestige = -200
		}
		hidden_tooltip = {
			ROOT = {
				occupy_minors_of_occupied_settlements = FROM
				gain_all_occupied_titles = { who = FROM type = invasion }				
			}
		}
	}
	
	on_success_title = {	
		custom_tooltip = {
			text = tribal_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title_destroy_duchies = {
						title = PREV
						enemy = FROM
						is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
						type = invasion
					}
				}
			}
		}
	}

	on_fail = {
		FROM = {
			show_scope_change = no
			prestige = 100
			
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_avenger }
						10 = { give_nickname = nick_the_lion }
						10 = { give_nickname = nick_the_bold }
					}
				}
			}
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		ROOT = {
			show_scope_change = no
			prestige = -200
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			show_scope_change = no
			prestige = 200
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_avenger }
						10 = { give_nickname = nick_the_lion }
						10 = { give_nickname = nick_the_bold }
					}
				}
			}
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
	}

	attacker_ai_victory_worth = {
		factor = 200
	}
	
	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		
		
		# Try to guide the Hordes in the right direction
		modifier = {
			factor = 0.9 
			FROM = {
				lower_real_tier_than = KING
			}
		}
		modifier = {
			factor = 0.9 
			FROM = {
				lower_real_tier_than = DUKE
			}
		}
		
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_nomadic = no
				NOT = {
					is_tribal = yes
				}
			}
			NOT = {
				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_tribal = yes
			}
			NOT = {
				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
							holding_type = tribal
						}
					}
				}
			}
		}
	}
}
hs_yizuruqing = {
	name = CB_NAME_hs_yizu
	war_name = WAR_NAME_hs_yizuruqing
	sprite = 6
	truce_days = 3650
    is_permanent = yes
	can_ask_to_join_war = yes
	is_holy_war = yes
	check_de_jure_tier = DUKE # this scans all de jure duchies for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes

	allowed_to_target_tributaries = no
	
	
	can_use_gui = {
		ROOT = {
			prestige = 3000
		}
	}
	
	on_add = {
		ROOT = { prestige = -1000 }
		#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 
			}
		}
	}

	can_use = {
		ROOT = {		
			NOT = { same_realm = FROM }
			mercenary = no
			NOR = {
				trait = kind
				trait = content
			}
		}
		FROM = {
			is_tribal  = no
			#NOT = {trait = hs_bakemono}
		}
		OR = {
			ROOT = {
				trait = hs_bakemono
			}
			FROM = {
				trait = hs_bakemono
			}
			
		}
		NOT = {
			ROOT = {
				trait = hs_bakemono
			}
			FROM = {
				trait = hs_bakemono
			}		
		}
		
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target duchy, or a border
		any_direct_de_jure_vassal_title = {
			OR = {
				holder_scope = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
				}
				location = {
					any_neighbor_province = {
						OR = {
							AND = {
								has_owner = yes
								owner = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
									}
								}
							}
							
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			NOR = {
				pays_tribute_to = FROM
				any_liege = {
					OR = {
						pays_tribute_to = FROM
						FROM = {
							pays_tribute_to = PREV
						}
					}
				}
			}
			NOT = { same_realm = FROM }
		}
	}
	
	on_success = {
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 200
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
			}
		}
		FROM = { prestige = -200 }
	}

	on_success_title = {
		custom_tooltip = {
			text = pagan_subjugation_tip
			hidden_tooltip = {
				ROOT = {
					subjugate_or_take_under_title = {
						title = PREV
						enemy = FROM
					}
				}
			}
		}

		hidden_tooltip = {
			check_if_reconquista_finished_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}

	on_fail = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 3.0
			}
			prestige = -300
		}
	}

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 5.0
			}
			prestige = -500
		}
		FROM = {
			participation_scaled_prestige = 1000
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_prestige = 1000
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
			}
		}
	}

	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 = 0.5
		modifier = {
			factor = 0
			ROOT = {
				NOT = { prestige = 3000 }
			    independent = yes
			}			
		}
	}
}
hs_reverse_invasion = {
	name = CB_NAME_reverse_invasion
	war_name = WAR_NAME_reverse_invasion
	sprite = 8
	is_permanent = yes
	can_ask_to_join_war = yes
	allowed_to_target_tributaries = no
	defender_unoccupied_warscore = yes
	infamy_modifier = 0.2
	sort_priority = 2000
	max_defender_occupation_score = 99
	truce_days = 1800
	hostile_against_others = yes
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes	
	can_use = {
		FROM = {
			hs_isqingluezhe = yes			
		}	
		ROOT = {
			hs_isqingluezhe = no
		}
		FROM = {
			in_revolt = no
			NOT = { is_offmap_governor = yes }
		}
		
	}
	can_use_gui = {
		ROOT = {
			prestige = 500
		}
		check_if_crusader_trigger = yes
	}
	
	on_add = {
		ROOT = { show_scope_change = no prestige = -500 }
		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 
			}
		}
		if = {
			limit = { 
				attacker = { 
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_great_conquerors
					} 
				} 
			}
			attacker = {  
				set_character_flag = flag_declared_bloodline_invasion
			}
		}
	}

	can_use_title = {		
		ROOT = {
			NOT = { same_realm = FROM }
		}
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_success = {
		ROOT = {
			show_scope_change = no
			piety = 500
			prestige = 500
			participation_scaled_piety = 1000
			participation_scaled_prestige = 1000
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 2000 }
		}
		FROM = {
			show_scope_change = no
			prestige = -500
		}
		hidden_tooltip = {
			ROOT = {
				occupy_minors_of_occupied_settlements = FROM
				gain_all_occupied_titles = { who = FROM type = invasion }	
			}
		}
	}
	
	on_success_title = {
	
		custom_tooltip = {
			text = tribal_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title_destroy_duchies = {
						title = PREV
						enemy = FROM
						is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
						type = invasion
					}
				}				
			}
		}
		hidden_tooltip = {
			check_if_reconquista_finished_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}

	on_fail = {
		FROM = {
			show_scope_change = no
			prestige = 300					
			participation_scaled_prestige = 1000
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 1000 }
		}
		ROOT = {
			show_scope_change = no
			prestige = -500
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			show_scope_change = no
			prestige = 200
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
	}

	attacker_ai_victory_worth = {
		factor = 200
	}
	
	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 = {
			factor = 0.9 # Prefer using CB's without on_add costs
		}
		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
				}
			}
		}
		
	}
}
hs_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 = {
			hs_isqingluezhe = yes	
			OR = {
				trait = hs_bakemono
				trait = hs_renxing
				trait = cruel
				trait = ambitious
				trait = greedy
				trait = possessed
				trait = lunatic
			}
		}		
		#OR = {
		#	NOT = { ROOT = { religion = aztec } }
		#	FROM = { religion = aztec }
		#}
		FROM = {
			in_revolt = no
			NOT = { is_offmap_governor = yes }
		}
		
	}
	can_use_gui = {
		FROM = {
			conditional_tooltip = {
				trigger = {
					tier = BARON
				}
				ROOT = {prestige = 1000}
			}
			conditional_tooltip = {
				trigger = {
					tier = COUNT
				}
				ROOT = {prestige = 1500}
			}
			conditional_tooltip = {
				trigger = {
					tier = DUKE
				}
				ROOT = {prestige = 2000}
			}
			conditional_tooltip = {
				trigger = {
					tier = KING
				}
				ROOT = {prestige = 2500}
			}
			conditional_tooltip = {
				trigger = {
					tier = EMPEROR
				}
				ROOT = { prestige = 3000}
			}
		}
	}
	on_add = {
		ROOT = {
			add_character_modifier = { 
				name = launched_subjugation
				years = 100
				hidden = yes
			}
		}
		if = {
			limit = { FROM = {lower_real_tier_than = DUKE} }
			ROOT = { prestige = -1500 }
		}
		if = {
			limit = { FROM = {tier = DUKE} }
			ROOT = { prestige = -2000 }
		}
		if = {
			limit = { FROM = {tier = KING} }
			ROOT = { prestige = -2500 }
		}
		if = {
			limit = { FROM = {tier = EMPEROR} }
			ROOT = { prestige = -3000 }
		}
		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 = {
			factor = 0.8 
			FROM = {
				lower_real_tier_than = KING
			}
		}
		modifier = {
			factor = 0.8 
			FROM = {
				lower_real_tier_than = DUKE
			}
		}
		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
				}
			}
		}
	}
}