RR_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 = {
			OR = {
				religion_group = pagan_group
				religion = taoist
			}
			is_reformed_religion = no
			NOT = { religion = hellenic_pagan }
			NOT = { same_realm = FROM }
			NOT = { is_liege_or_above = FROM }
			mercenary = no
			NOT = { has_landed_title = e_china_west_governor }
			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 = {
				NOT = { has_character_modifier = launched_subjugation }
				AND = {
					has_ambition = obj_become_king
					capital_scope = {
						kingdom = {
							FROM = {
								any_realm_title = {
									kingdom = {
										title = PREVPREVPREV
									}
								}
							}
						}
					}
				}
			}
		}
		
		OR = { # Attacker must be higher tier than defender
			AND = {
				FROM = { tier = baron }
				ROOT = { higher_real_tier_than = baron }
			}
			AND = {
				FROM = { tier = count }
				ROOT = { higher_real_tier_than = count }
			}
			AND = {
				FROM = { tier = duke }
				ROOT = { higher_real_tier_than = duke }
			}
			AND = {
				FROM = { tier = king }
				ROOT = { higher_real_tier_than = king }
			}
		}
		
		FROM = {
			in_revolt = no
			is_nomadic = no
			NOT = { is_offmap_governor = yes }
			NOT = {
				any_war = {
					defender = { character = PREVPREV }
					OR = {
						using_cb = pagan_subjugation
						using_cb = nomad_subjugation
						using_cb = RR_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
				}
			}
		}
	}
}

RR_pagan_invasion_once_per_lifetime = {
	name = CB_NAME_INVASION
	war_name = WAR_NAME_INVASION
	sprite = 8
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	is_holy_war = 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
	
	allowed_to_target_tributaries = no
	
	sort_priority = 2000
	
	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		#ROOT = { piety = -1000 }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
		ROOT = {
			add_character_modifier = { 
				name = launched_subjugation
				years = 100
				hidden = yes
			}
		}
	}

	can_use = {
		ROOT = {
			NOT = { has_character_modifier = launched_subjugation } #once per lifetime
			independent = yes

			OR = {
				ai = yes
				multiplayer = no
				NOT = {
					has_game_rule = {
						name = multiplayer_invasions
						value = off
					}
				}
			}

			# This CB is available when your doctrines allow great holy wars, but your leadership type doesn't.
			has_religion_feature = religion_syncretic # Holy Warfare doctrine
			NOR = {
				has_religion_feature = religion_temporal_head
				has_religion_feature = religion_theocratic_head
			}
		}
		
		FROM = { NOT = { religion = ROOT } }
		
		ROOT = {
			NOT = { is_liege_or_above = FROM }
			mercenary = no
		}
	}
	
	can_use_title = {
		# Muslims require the target to have at least 6 counties within the target kingdom
		FROM = {
			num_of_realm_counties = {
				value = 6
				title = PREV
			}
		}
		# The attacker needs at least one county in the target kingdom, or a border
		any_direct_de_jure_vassal_title = {
			any_direct_de_jure_vassal_title = {
				OR = {
					holder_scope = {
						OR = {
							character = ROOT
							is_liege_or_above = ROOT
						}
					}
					location = {
						any_neighbor_province = {
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
								}
							}
						}
					}
				}
			}
		}
	}
	
	is_valid = {
		ROOT = {
			independent = yes
			has_religion_feature = religion_syncretic
		}
		FROM = { NOT = { religion = ROOT } }
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_success = {
		ROOT = {
			show_scope_change = no
			prestige = 200
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
			participation_scaled_prestige = 200
			if = {
				limit = {
					uses_decadence = yes
					FROM = { NOT = { uses_decadence = yes } }
				}
				participation_scaled_decadence = -20
			}
		}
		
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 200 
				if = {
					limit = {
						uses_decadence = yes
						FROM = { NOT = { uses_decadence = yes } }
					}
					participation_scaled_decadence = -20
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		FROM = {
			show_scope_change = no
			prestige = -200
		}
	}
	
	on_success_title = {
		custom_tooltip = { 
			text = other_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title_destroy_duchies = {
						title = PREV
						enemy = FROM
						is_crusade = no # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
						type = invasion
					}
					if = {
						limit = {
							OR = {
								this_has_lame_nickname_trigger = yes
								has_nickname = no
							}
						}
						random_list = {
							10 = { give_nickname = nick_the_holy }
							10 = { give_nickname = nick_the_glorious }
							10 = { give_nickname = nick_the_lionheart }
							10 = { give_nickname = nick_the_great }
							10 = { give_nickname = nick_the_hammer }
							10 = { give_nickname = nick_the_magnificent }
						}
					}
				}
			}
		}
	}

	on_fail = {
		FROM = {
			show_scope_change = no
			prestige = 100
		}
		FROM = {
			show_scope_change = no
			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 } }
			}
			hidden_effect = {
				if = {
					limit = {
						OR = {
							this_has_lame_nickname_trigger = yes
							has_nickname = no
						}
					}
					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_magnificent }
						10 = { give_nickname = nick_the_avenger }
					}
				}
			}
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		ROOT = {
			show_scope_change = no
			prestige = -200
		}
	}
	
	on_invalidation = { #If the war gts ivnalidated you can try again.
		ROOT = {
			remove_character_modifier = launched_subjugation
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			if = {
				limit = {
					NOT = {
						any_liege = {
							dynasty = PREV
						}
					}
				}
				decadence = 10
			}
		}
		FROM = {
			show_scope_change = no
			prestige = 200
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
			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 } }
			}
			hidden_effect = {
				if = {
					limit = {
						OR = {
							this_has_lame_nickname_trigger = yes
							has_nickname = no
						}
					}
					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_magnificent }
						10 = { give_nickname = nick_the_avenger }
					}
				}
			}
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = 100
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 150
	}
	
	ai_will_do = { 
		factor = 1
		
		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
						}
					}
				}
			}
		}
	}
}

RR_pagan_invasion_invaders = {
	name = CB_NAME_INVASION
	war_name = WAR_NAME_INVASION
	sprite = 8
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	is_holy_war = 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
	
	allowed_to_target_tributaries = no
	
	sort_priority = 2000

	can_use_gui = {
		ROOT = {
			piety = 1000
		}
	}
	
	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		ROOT = { piety = -1000 }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	can_use = {
		ROOT = {
			OR = {
				ai = yes
				multiplayer = no
				NOT = {
					has_game_rule = {
						name = multiplayer_invasions
						value = off
					}
				}
			}

			OR = {
				has_religion_feature = religion_feature_aztec
				religion = aztec
			}

			# If you have the free pagan invasion available from nature+leadership combo, use that instead.
			# So to use this one, you must not have the free one available.
			OR = {
				has_character_modifier = launched_subjugation #Already used the free one.
				has_religion_feature = religion_peaceful
				has_religion_feature = religion_defensive
				has_religion_feature = religion_cosmopolitan
				has_religion_feature = religion_temporal_head
				has_religion_feature = religion_theocratic_head
			}
		}
		
		FROM = { NOT = { religion = ROOT } }
		
		ROOT = {
			NOT = { is_liege_or_above = FROM }
			mercenary = no
		}
	}
	
	can_use_title = {
		# Muslims require the target to have at least 6 counties within the target kingdom
		FROM = {
			num_of_realm_counties = {
				value = 6
				title = PREV
			}
		}
		# The attacker needs at least one county in the target kingdom, or a border
		any_direct_de_jure_vassal_title = {
			any_direct_de_jure_vassal_title = {
				OR = {
					holder_scope = {
						OR = {
							character = ROOT
							is_liege_or_above = ROOT
						}
					}
					location = {
						any_neighbor_province = {
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
								}
							}
						}
					}
				}
			}
		}
	}
	
	is_valid = {
		ROOT = {
			OR = {
				has_religion_feature = religion_feature_aztec
				religion = aztec
			}
		}
		FROM = { NOT = { religion = ROOT } }
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_success = {
		ROOT = {
			show_scope_change = no
			prestige = 200
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
			participation_scaled_prestige = 200
			if = {
				limit = {
					uses_decadence = yes
					FROM = { NOT = { uses_decadence = yes } }
				}
				participation_scaled_decadence = -20
			}
		}
		
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 200 
				if = {
					limit = {
						uses_decadence = yes
						FROM = { NOT = { uses_decadence = yes } }
					}
					participation_scaled_decadence = -20
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		FROM = {
			show_scope_change = no
			prestige = -200
		}
	}
	
	on_success_title = {
		custom_tooltip = { 
			text = other_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title_destroy_duchies = {
						title = PREV
						enemy = FROM
						is_crusade = no # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
						type = invasion
					}
					if = {
						limit = {
							OR = {
								this_has_lame_nickname_trigger = yes
								has_nickname = no
							}
						}
						random_list = {
							10 = { give_nickname = nick_the_holy }
							10 = { give_nickname = nick_the_glorious }
							10 = { give_nickname = nick_the_lionheart }
							10 = { give_nickname = nick_the_great }
							10 = { give_nickname = nick_the_hammer }
							10 = { give_nickname = nick_the_magnificent }
						}
					}
				}
			}
		}
	}

	on_fail = {
		FROM = {
			show_scope_change = no
			prestige = 100
		}
		FROM = {
			show_scope_change = no
			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 } }
			}
			hidden_effect = {
				if = {
					limit = {
						OR = {
							this_has_lame_nickname_trigger = yes
							has_nickname = no
						}
					}
					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_magnificent }
						10 = { give_nickname = nick_the_avenger }
					}
				}
			}
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		ROOT = {
			show_scope_change = no
			prestige = -200
		}
	}
	
	on_invalidation = {
		ROOT = {
			show_scope_change = no
			piety = 1000
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			if = {
				limit = {
					NOT = {
						any_liege = {
							dynasty = PREV
						}
					}
				}
				decadence = 10
			}
		}
		FROM = {
			show_scope_change = no
			prestige = 200
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
			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 } }
			}
			hidden_effect = {
				if = {
					limit = {
						OR = {
							this_has_lame_nickname_trigger = yes
							has_nickname = no
						}
					}
					random_list = {
						10 = { give_nickname = nick_the_holy }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_lionheart }
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_magnificent }
						10 = { give_nickname = nick_the_avenger }
					}
				}
			}
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = 100
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 150
	}
	
	ai_will_do = { 
		factor = 1
		
		modifier = {
			factor = 0.9 # Prefer using CB's without on_add costs
		}
		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
						}
					}
				}
			}
		}
	}
}


