###IDEOLOGIC WARS###

democratic = {
	name = CB_NAME_DEMOCRATIC
	war_name = WAR_NAME_DEMOCRATIC
	sprite = 9
	truce_days = 3000
	is_permanent = yes
	is_holy_war = yes
	allowed_to_target_tributaries = no
	check_de_jure_tier = DUKE # this scans all dejure 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
	
	on_add = {
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	can_use = {
		ROOT = {
			is_nomadic = no
			OR = {
				religion = liberalist
				religion = interventionist
				religion = neo_classical
				religion = imperialist
				AND = {
					OR = {
						religion = anarcho-capitalism
						religion = minarchist
						religion = paleolibertarianism
						religion = geolibertarianism
					}
					has_global_flag = libertarian_synthesis_proclaimed
				}
			}
			NOT = { pacifist = yes }
			
			NOT = { same_realm = FROM }
			OR = {
				NOT = { religion_group = FROM }
				is_heresy_of = FROM
				is_parent_religion = FROM
				AND = {
					has_dharmic_religion_trigger = yes
					FROM = { religion = taoist }
				}
				AND = {
					religion_group = muslim
					NOT = { religion = FROM }
					FROM = {
						NOT = { 
							any_current_enemy = {
								NOT = {
									religion_group = muslim
								}
							}
						}
					}
				}
				AND = {
					religion_group = FROM
					FROM = {
						has_character_modifier = known_satanist
					}
					NOT = {
						has_character_modifier = known_satanist
					}
				}
			}
			top_liege = {
				religion_group = ROOT
				OR = {
					NOT = { religion = FROM }
					AND = {
						religion = FROM
						FROM = {
							has_character_modifier = known_satanist
						}
						NOT = {
							has_character_modifier = known_satanist
						}
						ROOT = {
							NOT = {
								has_character_modifier = known_satanist
							}
						}
					}
				}
				OR = {
					religion = ROOT
					AND = {
						is_heretic = no
						ROOT = { is_heretic = no }
					}
				}
			}
			mercenary = no
		}
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target kingdom, or a border, or be only two sea zones away from one of your counties
		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
									}
								}
							}
							AND = {
								is_land = no
								OR = {
									ROOT = { religion_group = muslim }
									FROM = { religion_group = muslim }
									AND = {
										ROOT = { religion_group = pagan_group }
										has_global_flag = pagan_ghws_unlocked
									}
									AND = {
										ROOT = { religion_group = christian }
										has_global_flag = christian_crusades_unlocked
									}
									AND = {
										ROOT = { religion_group = muslim }
										has_global_flag = muslim_jihads_unlocked
									}
								}
								any_neighbor_province = {
									OR = {
										AND = {
											has_owner = yes
											owner = {
												OR = {
													character = ROOT
													is_liege_or_above = ROOT
												}
											}
										}
										AND = {
											is_land = no
											any_neighbor_province = {
												owner = {
													OR = {
														character = ROOT
														is_liege_or_above = ROOT
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			religion_group = capitalist
			NOT = { religion_group = pagan_group }
			NOT = { pacifist = yes }
			NOT = { same_realm = FROM }
			OR = {
				NOT = { religion_group = FROM }
				is_heresy_of = FROM
				is_parent_religion = FROM
				AND = {
					has_dharmic_religion_trigger = yes
					FROM = { religion = taoist }
				}
				AND = {
					religion_group = FROM
					FROM = {
						has_character_modifier = known_satanist
					}
					ROOT = {
						NOT = {
							has_character_modifier = known_satanist
						}
					}
				}
				AND = {
					religion_group = muslim
					NOT = { religion = FROM }
				}
			}
			top_liege = {
				OR = {
					NOT = { religion = FROM }
					AND = {
						religion = FROM
						FROM = {
							has_character_modifier = known_satanist
						}
						NOT = {
							has_character_modifier = known_satanist
						}
						ROOT = {
							NOT = {
								has_character_modifier = known_satanist
							}
						}
					}
				}
			}
		}
	}
	
	on_success = {
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		
		ROOT = { 
			participation_scaled_piety = 100
			participation_scaled_prestige = 50
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
		FROM = {
			if = {
				limit = {
					NOT = {
						has_character_modifier = known_satanist
					}
				}
				religion_authority = {
					modifier = lost_holy_war
					years = 20
				}		
			}
		}
		FROM = { piety = -100 }
		FROM = { prestige = -50 }
	}

	on_success_title = {
		if = { # Standard Holy War behaviour for Non-Muslims and Muslims fighting other Muslims
			limit = {
				OR = {
					ROOT = {
						NOT = {
							religion_group = muslim
						}
					}
					AND = {
						ROOT = {
							religion_group = muslim
						}
						FROM = {
							religion_group = muslim
						}
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							same_religion = yes # Only vassalize rulers of my religion
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}
		if = { # Muslims fighting Non-Muslims preserve vassals
			limit = {
				ROOT = {
					religion_group = muslim
				}
				FROM = {
					NOT = {
						religion_group = muslim
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_muslim_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}
	}

	on_fail = {
		ROOT = { 
			piety = -50 
			prestige = -100
		}
	}

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -75
			prestige = -150
		}
		FROM = {
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		any_attacker = {
			limit = {
				character = ROOT
				uses_decadence = yes
			}
			participation_scaled_decadence = 20
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
			}
			hidden_tooltip = { 
				participation_scaled_decadence = 20
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
	}

	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
			NOT = { trait = zealous }
			over_vassal_limit = 1
		}
		
		# Try to guide the Hordes in the right direction
		modifier = {
			factor = 0.1
			ROOT = {
				OR = {
					dynasty = 613 # Seljuks
					dynasty = 800 # Timurids
					primary_title = { title = e_il-khanate }
				}
			}
			OR = {
				empire = {
					NOT = {
						OR = {
							title = e_persia
							title = e_byzantium
							title = e_arabia
						}
					}
				}
				FROM = {
					primary_title = { title = e_golden_horde }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				primary_title = { title = e_golden_horde }
			}
			OR = {
				empire = {
					OR = {
						title = e_persia
						title = e_byzantium
						title = e_arabia
					}
				}
				FROM = {
					primary_title = { title = e_il-khanate }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 2.0
			OR = {
				culture = persian
				culture = baloch
				culture = afghan
				culture = turkish
			}
			empire = {
				OR = {
					title = e_persia
					title = e_rajastan
				}
			}
		}
	}
}

communist = {
	name = CB_NAME_COMMUNIST
	war_name = WAR_NAME_COMMUNIST
	sprite = 9
	truce_days = 3000
	is_permanent = yes
	is_holy_war = yes
	allowed_to_target_tributaries = no
	check_de_jure_tier = DUKE # this scans all dejure 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
	
	on_add = {
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	can_use = {
		ROOT = {
			is_nomadic = no
			OR = {
				religion = marxist
				religion = bolchevik
				religion = trotskist
				religion = maoist
				AND = {
					OR = {
						religion = anarchist
						religion = anarcho-syndicalism
						religion = anarcho-mutualism
						religion = anarcho-feminism
						religion = ecoanarchism	
					}
					has_global_flag = anarchist_synthesis_proclaimed
				}
			}
			NOT = { pacifist = yes }
			NOT = { same_realm = FROM }
			OR = {
				NOT = { religion_group = FROM }
				is_heresy_of = FROM
				is_parent_religion = FROM
				AND = {
					has_dharmic_religion_trigger = yes
					FROM = { religion = taoist }
				}
				AND = {
					religion_group = muslim
					NOT = { religion = FROM }
					FROM = {
						NOT = { 
							any_current_enemy = {
								NOT = {
									religion_group = muslim
								}
							}
						}
					}
				}
				AND = {
					religion_group = FROM
					FROM = {
						has_character_modifier = known_satanist
					}
					NOT = {
						has_character_modifier = known_satanist
					}
				}
			}
			top_liege = {
				religion_group = ROOT
				OR = {
					NOT = { religion = FROM }
					AND = {
						religion = FROM
						FROM = {
							has_character_modifier = known_satanist
						}
						NOT = {
							has_character_modifier = known_satanist
						}
						ROOT = {
							NOT = {
								has_character_modifier = known_satanist
							}
						}
					}
				}
				OR = {
					religion = ROOT
					AND = {
						is_heretic = no
						ROOT = { is_heretic = no }
					}
				}
			}
			mercenary = no
		}
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target kingdom, or a border, or be only two sea zones away from one of your counties
		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
									}
								}
							}
							AND = {
								is_land = no
								OR = {
									ROOT = { religion_group = muslim }
									FROM = { religion_group = muslim }
									AND = {
										ROOT = { religion_group = pagan_group }
										has_global_flag = pagan_ghws_unlocked
									}
									AND = {
										ROOT = { religion_group = christian }
										has_global_flag = christian_crusades_unlocked
									}
									AND = {
										ROOT = { religion_group = muslim }
										has_global_flag = muslim_jihads_unlocked
									}
								}
								any_neighbor_province = {
									OR = {
										AND = {
											has_owner = yes
											owner = {
												OR = {
													character = ROOT
													is_liege_or_above = ROOT
												}
											}
										}
										AND = {
											is_land = no
											any_neighbor_province = {
												owner = {
													OR = {
														character = ROOT
														is_liege_or_above = ROOT
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			religion_group = communism
			NOT = { religion_group = pagan_group }
			NOT = { pacifist = yes }
			NOT = { same_realm = FROM }
			OR = {
				NOT = { religion_group = FROM }
				is_heresy_of = FROM
				is_parent_religion = FROM
				AND = {
					has_dharmic_religion_trigger = yes
					FROM = { religion = taoist }
				}
				AND = {
					religion_group = FROM
					FROM = {
						has_character_modifier = known_satanist
					}
					ROOT = {
						NOT = {
							has_character_modifier = known_satanist
						}
					}
				}
				AND = {
					religion_group = muslim
					NOT = { religion = FROM }
				}
			}
			top_liege = {
				OR = {
					NOT = { religion = FROM }
					AND = {
						religion = FROM
						FROM = {
							has_character_modifier = known_satanist
						}
						NOT = {
							has_character_modifier = known_satanist
						}
						ROOT = {
							NOT = {
								has_character_modifier = known_satanist
							}
						}
					}
				}
			}
		}
	}
	
	on_success = {
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		
		ROOT = { 
			participation_scaled_piety = 100
			participation_scaled_prestige = 50
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
		FROM = {
			if = {
				limit = {
					NOT = {
						has_character_modifier = known_satanist
					}
				}
				religion_authority = {
					modifier = lost_holy_war
					years = 20
				}		
			}
		}
		FROM = { piety = -100 }
		FROM = { prestige = -50 }
	}

	on_success_title = {
		if = { # Standard Holy War behaviour for Non-Muslims and Muslims fighting other Muslims
			limit = {
				OR = {
					ROOT = {
						NOT = {
							religion_group = muslim
						}
					}
					AND = {
						ROOT = {
							religion_group = muslim
						}
						FROM = {
							religion_group = muslim
						}
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							same_religion = yes # Only vassalize rulers of my religion
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}
		if = { # Muslims fighting Non-Muslims preserve vassals
			limit = {
				ROOT = {
					religion_group = muslim
				}
				FROM = {
					NOT = {
						religion_group = muslim
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_muslim_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}
	}

	on_fail = {
		ROOT = { 
			piety = -50 
			prestige = -100
		}
	}

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -75
			prestige = -150
		}
		FROM = {
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		any_attacker = {
			limit = {
				character = ROOT
				uses_decadence = yes
			}
			participation_scaled_decadence = 20
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
			}
			hidden_tooltip = { 
				participation_scaled_decadence = 20
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
	}

	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
		
		# Try to guide the Hordes in the right direction
		modifier = {
			factor = 0.1
			ROOT = {
				OR = {
					dynasty = 613 # Seljuks
					dynasty = 800 # Timurids
					primary_title = { title = e_il-khanate }
				}
			}
			OR = {
				empire = {
					NOT = {
						OR = {
							title = e_persia
							title = e_byzantium
							title = e_arabia
						}
					}
				}
				FROM = {
					primary_title = { title = e_golden_horde }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				primary_title = { title = e_golden_horde }
			}
			OR = {
				empire = {
					OR = {
						title = e_persia
						title = e_byzantium
						title = e_arabia
					}
				}
				FROM = {
					primary_title = { title = e_il-khanate }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 2.0
			OR = {
				culture = persian
				culture = baloch
				culture = afghan
				culture = turkish
			}
			empire = {
				OR = {
					title = e_persia
					title = e_rajastan
				}
			}
		}
	}
}

totalitarist = {
	name = CB_NAME_TOTALITARIST
	war_name = WAR_NAME_TOTALITARIST
	sprite = 9
	truce_days = 3000
	is_permanent = yes
	is_holy_war = yes
	allowed_to_target_tributaries = no
	check_de_jure_tier = DUKE # this scans all dejure 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
	
	on_add = {
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	can_use = {
		ROOT = {
			is_nomadic = no
			religion_group = totalitarist
			NOT = { pacifist = yes }
			
			NOT = { same_realm = FROM }
			OR = {
				NOT = { religion_group = FROM }
				is_heresy_of = FROM
				is_parent_religion = FROM
				AND = {
					has_dharmic_religion_trigger = yes
					FROM = { religion = taoist }
				}
				AND = {
					religion_group = muslim
					NOT = { religion = FROM }
					FROM = {
						NOT = { 
							any_current_enemy = {
								NOT = {
									religion_group = muslim
								}
							}
						}
					}
				}
				AND = {
					religion_group = FROM
					FROM = {
						has_character_modifier = known_satanist
					}
					NOT = {
						has_character_modifier = known_satanist
					}
				}
			}
			top_liege = {
				religion_group = ROOT
				OR = {
					NOT = { religion = FROM }
					AND = {
						religion = FROM
						FROM = {
							has_character_modifier = known_satanist
						}
						NOT = {
							has_character_modifier = known_satanist
						}
						ROOT = {
							NOT = {
								has_character_modifier = known_satanist
							}
						}
					}
				}
				OR = {
					religion = ROOT
					AND = {
						is_heretic = no
						ROOT = { is_heretic = no }
					}
				}
			}
			mercenary = no
		}
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target kingdom, or a border, or be only two sea zones away from one of your counties
		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
									}
								}
							}
							AND = {
								is_land = no
								OR = {
									ROOT = { religion_group = muslim }
									FROM = { religion_group = muslim }
									AND = {
										ROOT = { religion_group = pagan_group }
										has_global_flag = pagan_ghws_unlocked
									}
									AND = {
										ROOT = { religion_group = christian }
										has_global_flag = christian_crusades_unlocked
									}
									AND = {
										ROOT = { religion_group = muslim }
										has_global_flag = muslim_jihads_unlocked
									}
								}
								any_neighbor_province = {
									OR = {
										AND = {
											has_owner = yes
											owner = {
												OR = {
													character = ROOT
													is_liege_or_above = ROOT
												}
											}
										}
										AND = {
											is_land = no
											any_neighbor_province = {
												owner = {
													OR = {
														character = ROOT
														is_liege_or_above = ROOT
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			religion_group = totalitarist
			NOT = { religion_group = pagan_group }
			NOT = { pacifist = yes }
			NOT = { same_realm = FROM }
			OR = {
				NOT = { religion_group = FROM }
				is_heresy_of = FROM
				is_parent_religion = FROM
				AND = {
					has_dharmic_religion_trigger = yes
					FROM = { religion = taoist }
				}
				AND = {
					religion_group = FROM
					FROM = {
						has_character_modifier = known_satanist
					}
					ROOT = {
						NOT = {
							has_character_modifier = known_satanist
						}
					}
				}
				AND = {
					religion_group = muslim
					NOT = { religion = FROM }
				}
			}
			top_liege = {
				OR = {
					NOT = { religion = FROM }
					AND = {
						religion = FROM
						FROM = {
							has_character_modifier = known_satanist
						}
						NOT = {
							has_character_modifier = known_satanist
						}
						ROOT = {
							NOT = {
								has_character_modifier = known_satanist
							}
						}
					}
				}
			}
		}
	}
	
	on_success = {
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		
		ROOT = { 
			participation_scaled_piety = 100
			participation_scaled_prestige = 50
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
		FROM = {
			if = {
				limit = {
					NOT = {
						has_character_modifier = known_satanist
					}
				}
				religion_authority = {
					modifier = lost_holy_war
					years = 20
				}		
			}
		}
		FROM = { piety = -100 }
		FROM = { prestige = -50 }
	}

	on_success_title = {
		if = { # Standard Holy War behaviour for Non-Muslims and Muslims fighting other Muslims
			limit = {
				OR = {
					ROOT = {
						NOT = {
							religion_group = muslim
						}
					}
					AND = {
						ROOT = {
							religion_group = muslim
						}
						FROM = {
							religion_group = muslim
						}
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							same_religion = yes # Only vassalize rulers of my religion
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}
		if = { # Muslims fighting Non-Muslims preserve vassals
			limit = {
				ROOT = {
					religion_group = muslim
				}
				FROM = {
					NOT = {
						religion_group = muslim
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_muslim_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}
	}

	on_fail = {
		ROOT = { 
			piety = -50 
			prestige = -100
		}
	}

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -75
			prestige = -150
		}
		FROM = {
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		any_attacker = {
			limit = {
				character = ROOT
				uses_decadence = yes
			}
			participation_scaled_decadence = 20
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
			}
			hidden_tooltip = { 
				participation_scaled_decadence = 20
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
	}

	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
		
		# Try to guide the Hordes in the right direction
		modifier = {
			factor = 0.1
			ROOT = {
				OR = {
					dynasty = 613 # Seljuks
					dynasty = 800 # Timurids
					primary_title = { title = e_il-khanate }
				}
			}
			OR = {
				empire = {
					NOT = {
						OR = {
							title = e_persia
							title = e_byzantium
							title = e_arabia
						}
					}
				}
				FROM = {
					primary_title = { title = e_golden_horde }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				primary_title = { title = e_golden_horde }
			}
			OR = {
				empire = {
					OR = {
						title = e_persia
						title = e_byzantium
						title = e_arabia
					}
				}
				FROM = {
					primary_title = { title = e_il-khanate }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 2.0
			OR = {
				culture = persian
				culture = baloch
				culture = afghan
				culture = turkish
			}
			empire = {
				OR = {
					title = e_persia
					title = e_rajastan
				}
			}
		}
	}
}

put_end_old_regime_communist = {
	name = CB_NAME_END_OLD_REGIME
	war_name = WAR_NAME_END_OLD_REGIME
	sprite = 9
	truce_days = 3650
	
	is_permanent = yes
	can_ask_to_join_war = yes
	hostile_against_others = no
	check_all_titles = yes
	allowed_to_target_tributaries = no
	
	defender_unoccupied_warscore = yes
	
	can_use_gui = {
		ROOT = {
			piety = 250
		}
	}
	
	can_use = {
		ROOT = {
			OR = {
				religion = marxist
				religion = bolchevik
				religion = trotskist
				religion = maoist
				AND = {
					OR = {
						religion = anarchist
						religion = anarcho-syndicalism
						religion = anarcho-mutualism
						religion = anarcho-feminism
						religion = ecoanarchism	
					}
					has_global_flag = anarchist_synthesis_proclaimed
				}
			}
			NOT = { is_liege_or_above = FROM }
		}
		FROM = {
			NOT = { religion_group = communism }
			is_landed = yes
			any_demesne_title = {
				tier = EMPEROR
			}
		}
		OR = {
			AND = {
				ROOT = { religion_group = communism }
				FROM = { NOT = { religion_group = communism } }
				ROOT = { NOT = { same_realm = FROM } }
				FROM = { independent = yes }
			}
			AND = {
				ROOT = { religion_group = communism }
				FROM = { NOT = { religion_group = communism } }
				ROOT = { same_realm = FROM }
			}
		}
	}
	
	can_use_title = {
		tier = EMPEROR
		temporary = no
	}
	
	is_valid = {
		ROOT = {
			religion_group = communism
		}
		FROM = {
			NOT = { religion_group = communism }
		}
	}
	
	is_valid_title = {
		FROM = { has_landed_title = PREV }
	}
	
	on_add = {

	}
	
	on_add_title = {
		ROOT = {
			piety = -500
		}
	}
	
	on_success_title = {
		FROM = {
			destroy_landed_title = PREV
			add_claim = PREV
		}
		FROM = {
			prestige = -1000
		}
	}
	
	on_success = {
		ROOT = {
			prestige = 250
			piety = 250
		}
		any_attacker = {
			limit = { not = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		FROM = {
			piety = -150
		}
	}
	
	on_fail = {
		FROM = {
			prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	on_reverse_demand = {
		
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			prestige = -500
		}
		FROM = {
			prestige = 200
		}
		any_defender = {
			limit = { not = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	attacker_ai_victory_worth = {
		factor = -1
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = {
		factor = 1
		modifier = {
			factor = 0.9 # Prefer using CB's without on_add costs
		}
		modifier = {
			factor = 2.0
			FROM = { # Communism vs Fascism
				religion_group = totalitarist
			}	
		}
		modifier = {
			factor = 1.5
			FROM = { # For Trotskists, we must export the Revolution
				religion = trotskist
			}	
		}
		modifier = {
			factor = 1.3
			FROM = { # The Holy Roman Empire and the Byzantine Empire are the symbols of the Old Feudalism
				OR = {
					primary_title = { title = e_byzantium }
					primary_title = { title = e_hre }
				}
			}
		}
		modifier = {
			factor = 1.2
			FROM = { # This ruler can be a new hero of the old system, and that must be prevented
				NOR = {
					religion_group = capitalist
					religion_group = totalitarist
				}
			}
		}
		modifier = {
			factor = 0.8
			NOT = { 
				ROOT = {
					de_jure_liege_or_above = FROM
				}
			}
		}
		modifier = {
			factor = 0.1 # Nomads care little to dejure rules
			ROOT = {
				is_nomadic = yes
			}
		}
		modifier = {
			factor = 0.4 # Reduce chance as more risky to take on
			ROOT = {
				NOT = {
					relative_power_including_allies_attacker = {
						who = FROM
						power = 0.9
					}
				}
			}
		}
	}
}

put_end_old_regime_capitalist = { #Guarantee the people's freedom
	name = CB_NAME_END_OLD_REGIME_CAPITALIST
	war_name = WAR_NAME_GUARANTEE_PEOPLE_FREEDOM
	sprite = 9
	truce_days = 3650
	
	is_permanent = yes
	can_ask_to_join_war = yes
	hostile_against_others = no
	check_all_titles = yes
	allowed_to_target_tributaries = no
	
	defender_unoccupied_warscore = yes
	
	can_use_gui = {
		ROOT = {
			piety = 250
		}
	}
	
	can_use = {
		ROOT = {
			OR = {
				religion = liberalist
				religion = interventionist
				religion = neo_classical
				religion = imperialist
				AND = {
					OR = {
						religion = anarcho-capitalism
						religion = minarchist
						religion = paleolibertarianism
						religion = geolibertarianism
					}
					has_global_flag = libertarian_synthesis_proclaimed
				}
			}
			NOT = { is_liege_or_above = FROM }
		}
		FROM = {
			NOT = { religion_group = capitalist }
			is_landed = yes
			any_demesne_title = {
				tier = EMPEROR
			}
			any_realm_province = {
				NOT = { culture = FROM }
			}
		}
		OR = {
			AND = {
				ROOT = { religion_group = capitalist }
				FROM = { NOT = { religion_group = capitalist } }
				ROOT = { NOT = { same_realm = FROM } }
				FROM = { independent = yes }
			}
			AND = {
				ROOT = { religion_group = capitalist }
				FROM = { NOT = { religion_group = capitalist } }
				ROOT = { same_realm = FROM }
			}
		}
	}
	
	can_use_title = {
		tier = EMPEROR
		temporary = no
	}
	
	is_valid = {
		ROOT = {
			religion_group = capitalist
		}
		FROM = {
			NOT = { religion_group = capitalist }
		}
	}
	
	is_valid_title = {
		FROM = { has_landed_title = PREV }
	}
	
	on_add = {

	}
	
	on_add_title = {
		ROOT = {
			piety = -500
		}
	}
	
	on_success_title = {
		FROM = {
			destroy_landed_title = PREV
			add_claim = PREV
		}
		FROM = {
			prestige = -1000
		}
	}
	
	on_success = {
		ROOT = {
			prestige = 250
			piety = 250
		}
		any_attacker = {
			limit = { not = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		FROM = {
			piety = -150
		}
	}
	
	on_fail = {
		FROM = {
			prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	on_reverse_demand = {
		
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			prestige = -500
		}
		FROM = {
			prestige = 200
		}
		any_defender = {
			limit = { not = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	attacker_ai_victory_worth = {
		factor = -1
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = {
		factor = 1
		modifier = {
			factor = 0.9 # Prefer using CB's without on_add costs
		}
		modifier = {
			factor = 2.0
			FROM = { # Capitalism vs Communism
				religion_group = communism
			}	
		}
		modifier = {
			factor = 1.5 
			ROOT = { # For Imperialists, it's a way to develop their sphere of influence... 
				religion = imperialist
			}	
		}
		modifier = {
			factor = 1.2
			FROM = { # The Holy Roman Empire and the Byzantine Empire are the symbols of the Old Feudalism
				OR = {
					primary_title = { title = e_byzantium }
					primary_title = { title = e_hre }
				}
			}
		}
		modifier = {
			factor = 1.1
			FROM = { # This ruler can be a new hero of the old system, and that must be prevented
				NOR = {
					religion_group = capitalist
					religion_group = totalitarist
				}
			}
		}
		modifier = {
			factor = 0.8
			NOT = { 
				ROOT = {
					de_jure_liege_or_above = FROM
				}
			}
		}
		modifier = {
			factor = 0.7 
			ROOT = {
				NOT = { religion = imperialist }
			}
		}
		modifier = {
			factor = 0.1 # Nomads care little to dejure rules
			ROOT = {
				is_nomadic = yes
			}
		}
		modifier = {
			factor = 0.4 # Reduce chance as more risky to take on
			ROOT = {
				NOT = {
					relative_power_including_allies_attacker = {
						who = FROM
						power = 0.9
					}
				}
			}
		}
	}
}

just_war = { # Imperialist CB
	name = CB_NAME_JUST_WAR
	war_name = WAR_NAME_JUST_WAR
	sprite = 35
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	check_de_jure_tier = KING
	allowed_to_target_tributaries = no
	defender_unoccupied_warscore = yes
	apply_short_occ_mod = no # Do not apply the 'recently_conquered' modifier to Holdings
	
	sort_priority = 3000
	
	on_add = {
		hidden_tooltip = {
			ROOT = {
				set_character_flag = used_just_war_justification
			}
		}
		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 = {
			OR = {
				religion = imperialist
				AND = {
					OR = {
						religion = anarcho-capitalism
						religion = minarchist
						religion = paleolibertarianism
						religion = geolibertarianism
					}
					has_global_flag = libertarian_synthesis_proclaimed
				}
			}
			independent = yes
			NOT = {
				has_character_flag = used_just_war_justification
			}
			NOT = { same_realm = FROM }
			NOT = { religion_group = FROM }
		}
	}
	
	can_use_gui = {
		ROOT = {
			piety = 300
		}
	}
	
	can_use_title = {
		any_de_jure_vassal_title = {
			tier = COUNT
			holder_scope = {
				OR = {
					character = FROM
					is_liege_or_above = FROM
				}
			}
			location = {
				religion_group = ROOT
			}
		}
		# The attacker needs at least one county in the target kingdom, or a border, or be only two sea zones away from one of your counties
		any_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
									}
								}
							}
							AND = {
								is_land = no
								OR = {
									ROOT = { religion_group = muslim }
									FROM = { religion_group = muslim }
									AND = {
										ROOT = { religion_group = pagan_group }
										has_global_flag = pagan_ghws_unlocked
									}
									AND = {
										ROOT = { religion_group = christian }
										has_global_flag = christian_crusades_unlocked
									}
									AND = {
										ROOT = { religion_group = muslim }
										has_global_flag = muslim_jihads_unlocked
									}
								}
								any_neighbor_province = {
									OR = {
										AND = {
											has_owner = yes
											owner = {
												OR = {
													character = ROOT
													is_liege_or_above = ROOT
												}
											}
										}
										AND = {
											is_land = no
											any_neighbor_province = {
												owner = {
													OR = {
														character = ROOT
														is_liege_or_above = ROOT
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			NOT = { pacifist = yes }
			NOT = { same_realm = FROM }
			NOT = { religion_group = FROM }
		}
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}
	
	on_add_title = {
		ROOT = {
			piety = -250
		}
	}
	
	on_success = {
		hidden_tooltip = { 
			any_attacker = {
				limit = { NOT = { character = ROOT } }
				
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
		
		ROOT = {
			show_scope_change = no
			participation_scaled_piety = 500
			participation_scaled_prestige = 250
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
		}
		FROM = { show_scope_change = no piety = -100 }
		FROM = { show_scope_change = no prestige = -50 }
	}

	on_success_title = {
		custom_tooltip = {
			text = religious_liberation_cb_succ_tip
			hidden_tooltip = {
				if = {
					limit = {
						ROOT = { has_character_flag = choose_intern_governor }
					}
					FROM = {
						if = {
							limit = {
								any_realm_title = {
									tier = COUNT
									kingdom = { title = PREVPREVPREV }
									location = {
										religion_group = ROOT
									}
								}
							}
							random_realm_title = {
								limit = {
									tier = COUNT
									kingdom = { title = PREVPREVPREV }
									location = {
										religion_group = ROOT
									}
								}
								location = {
									create_character = {
										religion = ROOT
										culture = ROOT
										dynasty = random
										random_traits = yes
										female = no
										age = 20
										health = 7
										fertility = 0.7
										attributes = {
											martial = 10
											diplomacy = 10
											stewardship = 10
										}
										flag = is_religious_liberation_ruler
									}
									new_character = {
										remove_trait = cynical
										add_trait = zealous
										wealth = 500
										prestige = 500
										piety = 500
										save_event_target_as = new_ruler
										usurp_title = { target = PREVPREV type = invasion }
									}
								}
							}
						}
						if = {
							limit = {
								NOR = {
									event_target:new_ruler = { is_alive = yes }
									any_realm_title = {
										tier = COUNT
										kingdom = { title = PREVPREVPREV }
										location = {
											religion = ROOT
										}
									}
								}
							}
							random_realm_title = {
								limit = {
									tier = COUNT
									kingdom = { title = PREVPREVPREV }
								}
								location = {
									create_character = {
										religion = ROOT
										culture = ROOT
										dynasty = random
										random_traits = yes
										female = no
										age = 20
										health = 7
										fertility = 0.7
										attributes = {
											martial = 10
											diplomacy = 10
											stewardship = 10
										}
										flag = is_religious_liberation_ruler
									}
									new_character = {
										remove_trait = cynical
										add_trait = zealous
										wealth = 500
										prestige = 500
										piety = 500
										save_event_target_as = new_ruler
										usurp_title = { target = PREVPREV type = invasion }
									}
								}
							}
						}
					}
					ROOT = {
						clr_character_flag = choose_intern_governor 
					}
				}
				if = {
					limit = {
						ROOT = { has_character_flag = chose_extern_governor }
					}
					FROM = {
						if = {
							limit = {
								any_realm_title = {
									tier = COUNT
									kingdom = { title = PREVPREVPREV }
									location = {
										religion_group = ROOT
									}
								}
							}
							random_realm_title = {
								limit = {
									tier = COUNT
									kingdom = { title = PREVPREVPREV }
									location = {
										religion_group = ROOT
									}
								}
								location = {
									create_character = {
										religion = ROOT
										culture = THIS
										dynasty = random
										random_traits = yes
										female = no
										age = 20
										health = 7
										fertility = 0.7
										attributes = {
											martial = 10
											diplomacy = 10
											stewardship = 10
										}
										flag = is_religious_liberation_ruler
									}
									new_character = {
										remove_trait = cynical
										add_trait = zealous
										wealth = 500
										prestige = 500
										piety = 500
										save_event_target_as = new_ruler
										usurp_title = { target = PREVPREV type = invasion }
									}
								}
							}
						}
						if = {
							limit = {
								NOR = {
									event_target:new_ruler = { is_alive = yes }
									any_realm_title = {
										tier = COUNT
										kingdom = { title = PREVPREVPREV }
										location = {
											religion = ROOT
										}
									}
								}
							}
							random_realm_title = {
								limit = {
									tier = COUNT
									kingdom = { title = PREVPREVPREV }
								}
								location = {
									create_character = {
										religion = ROOT
										culture = THIS
										dynasty = random
										random_traits = yes
										female = no
										age = 20
										health = 7
										fertility = 0.7
										attributes = {
											martial = 10
											diplomacy = 10
											stewardship = 10
										}
										flag = is_religious_liberation_ruler
									}
									new_character = {
										remove_trait = cynical
										add_trait = zealous
										wealth = 500
										prestige = 500
										piety = 500
										save_event_target_as = new_ruler
										usurp_title = { target = PREVPREV type = invasion }
									}
								}
							}
						}
					}
					ROOT = {
						clr_character_flag = chose_extern_governor 
					}
				}
				if = {
					limit = {
						has_holder = no
					}
					usurp_title = { target = event_target:new_ruler type = invasion }
				}
				else = {
					event_target:new_ruler = {
						create_title = {
							tier = KING
							landless = no
							temporary = no
							custom_created = yes
							culture = event_target:new_ruler
							holder = event_target:new_ruler
							name = "LIBERATED_STATE"
						}
					}
				}
				
				event_target:new_ruler = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
						same_religion = yes # Only vassalize rulers of my religion
						is_religious = yes
						type = holy_war
						as_if_allied_to = ROOT
					}
					set_defacto_liege = THIS
				}
				
				if = {
					limit = {
						has_holder = yes
						holder_scope = {
							OR = {
								character = FROM
								is_liege_or_above = FROM
							}
						}
					}
					destroy_landed_title = THIS
					usurp_title_only = { target = event_target:new_ruler type = invasion }
					make_primary_title = yes
					event_target:new_ruler = {
						any_demesne_title = {
							limit = {
								tier = KING
								is_primary_holder_title = no
							}
							destroy_landed_title = THIS
						}
					}
				}
				
				ROOT = {
					hidden_tooltip = {
						if = {
							limit = {
								has_ambition = obj_strengthen_religion
							}
							change_variable = { which = strengthen_religion value = 1 }
						}
					}
					make_tributary = { who = event_target:new_ruler tributary_type = permanent }
				}
			}
		}

		hidden_tooltip = {
			check_if_reconquista_finished_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_fail = {
		ROOT = { 
			show_scope_change = no
			piety = -125 
			prestige = -250
		}
	}
	
	on_invalidation = {
		ROOT = {
			clr_character_flag = used_liberate_opportunity
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -250
			prestige = -500
		}
		FROM = {
			show_scope_change = no
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		any_attacker = {
			limit = {
				character = ROOT
				uses_decadence = yes
			}
			participation_scaled_decadence = 20
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
			}
			hidden_tooltip = { 
				participation_scaled_decadence = 20
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}			
		}
	}

	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 = 1.5
			over_vassal_limit = 1
		}
		modifier = { #Focus on other things.
			factor = 0.8
			NOT = { trait = zealous }
		}
		modifier = {
			factor = 0.1
			FROM = {
				culture_group = ROOT
			}
		}
	}
}

# The CB used by Anarchists characters who lead a revolt to destroy an empire
anarchist_revolution = {
	name = CB_NAME_ANARCHIST_REVOLUTION
	war_name = WAR_NAME_ANARCHIST_REVOLUTION
	sprite = 7
	truce_days = 365
	hostile_against_others = yes
	attacker_can_call_allies = no
	defender_can_call_allies = no
	can_ask_to_join_war = no
	check_de_jure_tier = DUKE
	
	can_use = {
		ROOT = {
			OR = {
				religion = anarchist
				religion = anarcho-syndicalism
				religion = anarcho-mutualism
				religion = anarcho-feminism
				religion = ecoanarchism
			}
			has_character_flag = heretic_revolter 
		}
		FROM = {
			primary_title = {
				tier = EMPEROR
			}
		}
	}
	
	can_use_title = {
		tier = DUKE
		temporary = no
	}
	
	is_valid = {
		FROM = {
			NOT = { religion = ROOT }
		}
	}

	on_add = {
		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 = {
			prestige = 200
			piety = 100
			occupy_minors_of_occupied_settlements = FROM
			gain_all_occupied_titles = { who = FROM type = revolt }
			clr_character_flag = heretic_revolter
		}
		
		FROM = {
			prestige = -500
			piety = -500
			
			religion_authority = {
				modifier = lost_heretic_revolt
			}		
		}
	}
	
	on_success_title = {
		ROOT = {
			vassalize_or_take_under_title = {
				title = PREV
				enemy = FROM
				same_religion = yes # Only vassalize rulers of my religion
				is_religious = yes
				type = holy_war
			}
		}
		if = {
			limit = {
				controls_religion = no
				holder_scope = {
					OR = {
						character = FROM
						is_liege_or_above = FROM
					}
				}
			}
			usurp_title = { target = ROOT type = holy_war }
		}
		if = {
			limit = {
				has_holder = no
			}
			usurp_title = { target = ROOT type = holy_war }
		}
		FROM = {
			primary_title = {
				destroy_landed_title = THIS
				add_claim = THIS
			}
		}
	}

	on_fail = {
		ROOT = {
			clear_wealth = yes
			imprison = FROM
			clr_character_flag = heretic_revolter
			hidden_tooltip = {
				add_character_modifier = { 
					name = broken_spirit
					days = -1
				}
			}
		}
		FROM = {
			prestige = 50
			piety = 100
			hidden_tooltip = {
				opinion = {
					modifier = opinion_rebel_traitor 
					who = ROOT
					months = 1200
				}
			}
			religion_authority = {
				modifier = won_heretic_revolt
			}
		}
	}

	on_reverse_demand = {
		ROOT = {
			clear_wealth = yes
			imprison = FROM
			clr_character_flag = heretic_revolter
			hidden_tooltip = {
				add_character_modifier = { 
					name = broken_spirit
					days = -1
				}
			}
		}
		FROM = {
			prestige = 100
			piety = 200
			hidden_tooltip = {
				opinion = {
					modifier = opinion_rebel_traitor 
					who = ROOT
					months = 1200
				}
				add_character_modifier = { 
					name = crushed_revolt
					days = 3650
				}
			}
			religion_authority = {
				modifier = won_heretic_revolt
			}
		}
	}

	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
	}
}

#The special CB for Rising Sun Empire event
rising_sun_invasion = {
	name = CB_NAME_RISING_SUN_INVASION
	war_name = WAR_RISING_SUN_INVASION
	sprite = 9
	truce_days = 3650
	hostile_against_others = yes
	is_holy_war = yes
	allowed_to_target_tributaries = no
	check_de_jure_tier = DUKE # this scans all dejure duchies for the counties which are held by or vassals(or below) of selected character

	can_use = {
		ROOT = { 
			AND = {
				has_landed_title = k_guandong
				holy_order = yes
				has_character_flag = rising_sun_invasion_operation 
			}
		}
	}

	is_valid = {
		always = yes
	}

	on_add = {
		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 = { 
			prestige = 250
			hidden_tooltip = {
				clr_character_flag = rising_sun_invasion_operation
				set_global_flag = guandong_army_arrival
				give_nickname = nick_the_conqueror
			}
		}
		FROM = {
			prestige = -250 
		}
		set_title_landless = {
			title = k_guandong
			status = no
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = other_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
						type = host
					}
				}
			}
		}

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

	on_fail = {
		FROM = {
			prestige = 100
			hidden_tooltip = {
				opinion = {
					modifier = opinion_rebel_traitor 
					who = ROOT
					months = 1200
				}
			}
		}
		ROOT = {
			clear_wealth = yes
			imprison = FROM 
			hidden_tooltip = {
				disband_event_forces = yes
				clr_character_flag = rising_sun_invasion_operation
			}
			hidden_effect = { 
				any_player = {
					limit = {
						OR = {
							AND = {
								has_offmap_news_enabled = offmap_china
								is_within_diplo_range = FROM
							}
							liege = { character = ROOT }
						}
					}
					narrative_event = { id = 270925 }
				}
				any_demesne_title = {
					limit = {
						higher_tier_than = DUKE
						NOR = {
							controls_religion = yes
							clan = yes
						}
					}
					destroy_landed_title = THIS
				}
			}
		}
		
	
		ROOT = { prestige = -100 }
	}

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		
		FROM = {
			prestige = 200
		}
		
		ROOT = {
			clear_wealth = yes
			imprison = FROM
			prestige = -200
			hidden_tooltip = {
				disband_event_forces = yes
				clr_character_flag = rising_sun_invasion_operation
			}
		}
	}
	
	on_attacker_leader_death = {
		ROOT = {
			hidden_tooltip = {
				disband_event_forces = yes
				clr_character_flag = rising_sun_invasion_operation
			}
		}
		end_war = invalid
	}

	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
	}
}

invasion_of_china_hakko_ichiu_cb = {
	name = CB_NAME_INVASION_OF_CHINA_JAPAN
	war_name = WAR_NAME_INVASION_OF_CHINA_JAPAN
	sprite = 30
	truce_days = 365
	hostile_against_others = yes
	can_ask_to_join_war = yes
	allowed_to_target_tributaries = no
	allow_whitepeace = no
	battle_warscore_mult = 1.5
	max_attacker_occupation_score = 50
	max_defender_occupation_score = 50
	max_attacker_battle_score = 100
	capturing_defender_is_complete_victory = no

	# attacker_unoccupied_warscore = yes - If attacker completely unoccupied, attacker will get ticking warscore. Only works if no title is targetted
	# defender_unoccupied_warscore = yes - If defender completely unoccupied, defender will get ticking warscore. Only works if no title is targetted
	
	can_use = {
		ROOT = {
			independent = yes
			NOT = { same_realm = FROM }
			NOT = { is_liege_or_above = FROM }
			has_landed_title = k_guandong
		}
		FROM = {
			is_offmap_governor = yes
			offmap_power = { is_offmap_tag = offmap_china }
		}
	}

	is_valid = { ROOT = { has_landed_title = k_guandong } }

	on_success = { 
		ROOT = {
			show_scope_change = no
			custom_tooltip = {
				text = invasion_of_china_success_tt
				hidden_effect = {
					remove_character_modifier = china_raid_active
					create_character = {
						random_traits = yes
						dynasty = random
						religion = hakko-ichiu
						culture = han
						female = no
						age = 45
					}
					new_character = {
						save_event_target_as = new_collaborator_governor
					}
					offmap_china = {
						governor = {
							any_demesne_title = {
								limit = {
									NOT = {
										tier = EMPEROR
									}
								}
								grant_title = ROOT
							}
						}
						ROOT = {
							if = {
								limit = { government = chinese_imperial_government }
								offmap_china = { set_offmap_flag = rename_override }
								primary_title = {
									trigger_switch = {
										on_trigger = has_title_flag
										china_name_Tang = { offmap_china = { set_offmap_name = "tang_china" } }
										china_name_Jin = { offmap_china = { set_offmap_name = "jin_china" } }
										china_name_Wei = { offmap_china = { set_offmap_name = "wei_china" } }
										china_name_Qi = { offmap_china = { set_offmap_name = "qi_china" } }
										china_name_Zhou = { offmap_china = { set_offmap_name = "zhou_china" } }
										china_name_Han = { offmap_china = { set_offmap_name = "han_china" } }
										china_name_Qin = { offmap_china = { set_offmap_name = "qin_china" } }
										china_name_Yan = { offmap_china = { set_offmap_name = "yan_china" } }
										china_name_Zhao = { offmap_china = { set_offmap_name = "zhao_china" } }
										china_name_Liao = { offmap_china = { set_offmap_name = "liao_china" } }
										china_name_Yuan = { offmap_china = { set_offmap_name = "yuan_china" } }
										china_name_Xia = { offmap_china = { set_offmap_name = "xia_china" } }
										china_name_Qing = { offmap_china = { set_offmap_name = "qing_china" } }
										china_name_Dai = { offmap_china = { set_offmap_name = "dai_china" } }
										china_name_Cheng = { offmap_china = { set_offmap_name = "cheng_china" } }
										china_name_Liang = { offmap_china = { set_offmap_name = "liang_china" } }
										china_name_Song = { offmap_china = { set_offmap_name = "song_china" } }
										china_name_Ming = { offmap_china = { set_offmap_name = "ming_china" } }
										china_name_Shu = { offmap_china = { set_offmap_name = "shu_china" } }
										china_name_Wu = { offmap_china = { set_offmap_name = "wu_china" } }
										china_name_Chu = { offmap_china = { set_offmap_name = "chu_china" } }
										china_name_Yue = { offmap_china = { set_offmap_name = "yue_china" } }
										china_name_Yin = { offmap_china = { set_offmap_name = "yin_china" } }
										china_name_Shun = { offmap_china = { set_offmap_name = "shun_china" } }
									}
									clr_title_flag = pretender_chinese_empire
									clr_title_flag = uses_temple_names_by_script
									clear_flags_with_prefix = temple_name_
									clear_flags_with_prefix = china_name_
									set_name = "[Root.Capital.GetName] Empire"
								}
								clr_character_flag = given_temple_name_by_script
								set_name = ""
								set_government_type = feudal_government
							}
						}
						set_offmap_flag = no_succession_news
						set_offmap_flag = no_war_news
						clr_offmap_flag = china_invaded_player_dynasty
						set_offmap_flag = china_invaded_player_dynasty
						set_offmap_holder = event_target:new_collaborator_governor
						clr_offmap_flag = no_succession_news
						clr_offmap_flag = rename_override
						
						if = {
							limit = {
								NOR = {
									has_status = china_stable
									has_status = china_golden_age
								}
							}
							set_offmap_flag = no_status_news
							set_status = china_stable
							clr_offmap_flag = no_status_news
						}
					}
					any_player = {
						limit = {
							OR = {
								AND = {
									has_offmap_news_enabled = offmap_china
									is_within_diplo_range = FROM
								}
								liege = { character = ROOT }
							}
						}
						narrative_event = { id = 270924 }
					}
				}
			}
			participation_scaled_prestige = 5000
			set_offmap_currency = { offmap = offmap_china value = 5000 }
			wealth = 10000
			add_character_modifier = { name = chinese_favored_in_trade inherit = yes years = 50 }
			if = {
				limit = { NOT = { has_artifact = jade_dragon } }
				add_artifact = jade_dragon
			}
			if = {
				limit = { NOT = { has_artifact = chinese_dragon_amulet } }
				add_artifact = chinese_dragon_amulet
			}
			if = {
				limit = { NOT = { has_artifact = water_clock } }
				add_artifact = water_clock
			}
			if = {
				limit = { NOT = { has_artifact = jian_sword } }
				add_artifact = jian_sword
			}
			hidden_effect = { add_character_modifier = { name = peace_deal_with_china inherit = yes years = 50 } }
			remove_character_modifier = china_raid_active
			remove_character_modifier = war_with_china_modifier
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 2000 }
		}
		clear_global_event_target = invasion_of_china_claimant
	}

	on_invalidation = {
		FROM = {
			piety = 200
			participation_scaled_prestige = 250
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 250 }
		}
		ROOT = {
			prestige = -2500
			remove_character_modifier = war_with_china_modifier
			custom_tooltip = {
				text = invasion_of_china_cb_fail_tt
				hidden_effect = { add_character_modifier = { name = failed_invasion_of_china duration = -1 hidden = yes } }
			}
			hidden_effect = {
				offmap_china = { set_offmap_flag = no_war_news }
				any_player = {
					limit = {
						OR = {
							AND = {
								has_offmap_news_enabled = offmap_china
								is_within_diplo_range = FROM
							}
							liege = { character = ROOT }
						}
					}
					narrative_event = { id = 270926 }
				}
			}
			custom_tooltip = {
				text = angered_china_tt #Scripter! Update this is you change the value below.
				add_character_modifier = {
					modifier = angered_china_modifier
					inherit = yes
					years = 50
				}
			}
		}
		clear_global_event_target = invasion_of_china_claimant
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -3000
			transfer_scaled_wealth = {
				to = FROM
				value = 5.0
				min = 5000
			}
			remove_character_modifier = war_with_china_modifier
			custom_tooltip = {
				text = invasion_of_china_cb_fail_tt
				hidden_effect = { add_character_modifier = { name = failed_invasion_of_china duration = -1 hidden = yes } }
			}
			custom_tooltip = {
				text = destabilization_china_success_tt
				hidden_effect = { 
					offmap_china = { set_offmap_flag = no_war_news }
					any_player = {
						limit = {
							OR = {
								AND = {
									has_offmap_news_enabled = offmap_china
									is_within_diplo_range = FROM
								}
								liege = { character = ROOT }
							}
						}
						narrative_event = { id = 270925 }
					}
					any_demesne_title = {
						limit = {
							higher_tier_than = DUKE
							NOR = {
								controls_religion = yes
								clan = yes
							}
						}
						destroy_landed_title = THIS
					}
				}
			}
			custom_tooltip = {
				text = angered_china_tt #Scripter! Update this is you change the value below.
				add_character_modifier = {
					modifier = angered_china_modifier
					inherit = yes
					years = 50
				}
			}
		}
		FROM = {
			piety = 200
			participation_scaled_prestige = 1000
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 1000 }
		}
		clear_global_event_target = invasion_of_china_claimant
	}
	
	on_attacker_leader_death = {
		#end_war = invalid
	}

	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
	}
}

# The Revolution CB
revolution_war = {
	name = CB_NAME_REVOLUTION
	war_name = WAR_NAME_REVOLUTION
	sprite = 16
	truce_days = 365
	hostile_against_others = yes
	check_de_jure_tier = KING # this scans all dejure duchies for the counties which are held by or vassals(or below) of selected character
	press_claim = yes
	can_ask_to_join_war = no
	is_independence = yes
	
	can_use = {
		ROOT = { has_character_flag = revolutionary_leader }
	}

	can_use_title = {
		tier = king
	}
	
	is_valid = {
		FROM = {
			NOT = { religion = ROOT }
		}
	}

	is_valid_title = {
		always = yes
	}

	on_add = {
		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 = {
			prestige = 1000
			occupy_minors_of_occupied_settlements = FROM
			gain_all_occupied_titles = { who = FROM type = revolt }
			clr_character_flag = revolutionary_leader
			give_nickname = nick_the_liberator
		}
		FROM = {
			prestige = -500
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = tribal_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
						is_revolt = yes
						type = revolt
					}
					if = {
						limit = {
							num_of_count_titles = 5
							PREV = { 
								OR = {
									has_holder = no 
									holder_scope = {
										character = FROM
									}
								}
							}
						}
						usurp_title = { target = PREV type = revolt }
					}
				}
			}
		}

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

	on_fail_title = {
		FROM = {
			prestige = 100
			hidden_tooltip = {
				opinion = {
					modifier = opinion_rebel_traitor 
					who = ROOT
					months = 1200
				}
			}
		}
		ROOT = {
			clear_wealth = yes
			imprison = FROM
			clr_character_flag = revolutionary_leader
			hidden_tooltip = {
				add_character_modifier = { 
					name = broken_spirit
					days = -1
				}
				remove_trait = inspiring_leader
			}
		}
	}

	on_reverse_demand = {
		FROM = {
			prestige = 200
			hidden_tooltip = {
				opinion = {
					modifier = opinion_rebel_traitor 
					who = ROOT
					months = 1200
				}
				add_character_modifier = { 
					name = crushed_major_revolt
					days = 3650
				}
			}
		}
		ROOT = {
			clear_wealth = yes
			imprison = FROM
			clr_character_flag = revolutionary_leader
			hidden_tooltip = {
				add_character_modifier = { 
					name = broken_spirit
					days = -1
				}
				remove_trait = inspiring_leader
			}
		}
	}

	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 = 100
	}
}

change_universal_democracy_succession_law = {
	name = CB_NAME_UNIVERSAL_DEMOCRACY_SUCCESSION_LAW
	war_name = WAR_NAME_UNIVERSAL_DEMOCRACY_SUCCESSION_LAW
	sprite = 6
	truce_days = 3650
	attacker_can_call_allies = no
	can_ask_to_join_war = no
	major_revolt = yes
	
	can_use_gui = {
		check_if_crusader_trigger = yes
	}

	can_use = {
		ROOT = {
			vassal_of = FROM	
		}
	}
	
	is_valid = {
		FROM = {
			in_revolt = no
			liege_before_war = {
				in_revolt = no
				liege_before_war = {
					in_revolt = no
				}
			}
		}
		ROOT = {
			OR = {
				liege = {
					character = PREV # either independent
				}
				liege = { 
					FROM = { 
						is_liege_or_above = PREV # or have shared liege
					}
				}
			}
		}
	}

	is_valid_title = {
		NOT = {
			has_law = succ_democracy
		}
		OR = {
			tier = emperor
			tier = king
			is_primary_holder_title = yes
		}
	}

	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = { detract_grace_super_huge_effect = yes }
		}
	}
	
	on_success = {
		FROM = {
			hidden_tooltip = { disband_event_forces = faction_loyalists }
			if = {
				limit = { NOT = { has_dlc = "Zeus" } }
				any_demesne_title = { # All titles
					if = {
						limit = {
							OR = {
								tier = king
								tier = emperor
							}
		#					is_titular = no
							NOT = { has_law = crown_authority_0 }
						}
						if = {
							limit = { has_law = crown_authority_1 }
							add_law = crown_authority_0
						}
						if = {
							limit = { has_law = crown_authority_2 }
							add_law = crown_authority_1
						}
						if = {
							limit = { has_law = crown_authority_3 }
							add_law = crown_authority_2
						}
						if = {
							limit = { has_law = crown_authority_4 }
							add_law = crown_authority_3
						}
					}
				}
			}
		}
		
		ROOT = {
			participation_scaled_prestige = 100
			hidden_tooltip = {
				disband_event_forces = faction_revolters
			}
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = {
				participation_scaled_prestige = 100 
				disband_event_forces = faction_revolters
			}
		}
	}

	on_success_title = {
		succession_w_cooldown = succ_democracy
	}

	on_fail = {
		ROOT = {
			prestige = -100
		}
		FROM = {
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
		
		hidden_tooltip = {
			any_attacker = {
				disband_event_forces = faction_revolters
				add_character_modifier = {
					name = faction_succ_democracy_universal_ultimatum_timer
					hidden = yes
					duration = 3650
				}
			}
		}
		FROM = { hidden_tooltip = { disband_event_forces = faction_loyalists } }
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			prisoner = FROM
		}
		FROM = {
			participation_scaled_prestige = 100
			hidden_tooltip = { 
				if = { 
					limit = { NOT = { has_opinion_modifier = { modifier = opinion_traitor who = ROOT } } } #Allow free revocation of a title.
					opinion = {
						who = ROOT
						modifier = opinion_traitor
					}
				}
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		
		hidden_tooltip = {
			any_attacker = {
				limit = { liege = { character = FROM } }
				prisoner = FROM
				disband_event_forces = faction_revolters
				add_character_modifier = {
					name = faction_succ_democracy_universal_ultimatum_timer
					hidden = yes
					duration = 3650
				}
			}
		}
		
		FROM = { hidden_tooltip = { disband_event_forces = faction_loyalists } }
	}

	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
	}
}

change_democracy_capa_succession_law = {
	name = CB_NAME_DEMOCRACY_CAPA_SUCCESSION_LAW
	war_name = WAR_NAME_DEMOCRACY_CAPA_SUCCESSION_LAW
	sprite = 6
	truce_days = 3650
	attacker_can_call_allies = no
	can_ask_to_join_war = no
	major_revolt = yes
	
	can_use_gui = {
		check_if_crusader_trigger = yes
	}

	can_use = {
		ROOT = {
			vassal_of = FROM	
		}
	}
	
	is_valid = {
		FROM = {
			in_revolt = no
			liege_before_war = {
				in_revolt = no
				liege_before_war = {
					in_revolt = no
				}
			}
		}
		ROOT = {
			OR = {
				liege = {
					character = PREV # either independent
				}
				liege = { 
					FROM = { 
						is_liege_or_above = PREV # or have shared liege
					}
				}
			}
		}
	}

	is_valid_title = {
		NOT = {
			has_law = succ_democracy_capa
		}
		OR = {
			tier = emperor
			tier = king
			is_primary_holder_title = yes
		}
	}

	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = { detract_grace_super_huge_effect = yes }
		}
	}
	
	on_success = {
		FROM = {
			hidden_tooltip = { disband_event_forces = faction_loyalists }
			if = {
				limit = { NOT = { has_dlc = "Zeus" } }
				any_demesne_title = { # All titles
					if = {
						limit = {
							OR = {
								tier = king
								tier = emperor
							}
		#					is_titular = no
							NOT = { has_law = crown_authority_0 }
						}
						if = {
							limit = { has_law = crown_authority_1 }
							add_law = crown_authority_0
						}
						if = {
							limit = { has_law = crown_authority_2 }
							add_law = crown_authority_1
						}
						if = {
							limit = { has_law = crown_authority_3 }
							add_law = crown_authority_2
						}
						if = {
							limit = { has_law = crown_authority_4 }
							add_law = crown_authority_3
						}
					}
				}
			}
		}
		
		ROOT = {
			participation_scaled_prestige = 100
			hidden_tooltip = {
				disband_event_forces = faction_revolters
			}
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = {
				participation_scaled_prestige = 100 
				disband_event_forces = faction_revolters
			}
		}
	}

	on_success_title = {
		add_law_w_cooldown = succ_democracy_capa
	}

	on_fail = {
		ROOT = {
			prestige = -100
		}
		FROM = {
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
		
		hidden_tooltip = {
			any_attacker = {
				disband_event_forces = faction_revolters
				add_character_modifier = {
					name = faction_succ_democracy_capa_ultimatum_timer
					hidden = yes
					duration = 3650
				}
			}
		}
		FROM = { hidden_tooltip = { disband_event_forces = faction_loyalists } }
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			prisoner = FROM
		}
		FROM = {
			participation_scaled_prestige = 100
			hidden_tooltip = { 
				if = { 
					limit = { NOT = { has_opinion_modifier = { modifier = opinion_traitor who = ROOT } } } #Allow free revocation of a title.
					opinion = {
						who = ROOT
						modifier = opinion_traitor
					}
				}
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		
		hidden_tooltip = {
			any_attacker = {
				limit = { liege = { character = FROM } }
				prisoner = FROM
				disband_event_forces = faction_revolters
				add_character_modifier = {
					name = faction_succ_democracy_capa_ultimatum_timer
					hidden = yes
					duration = 3650
				}
			}
		}
		
		FROM = { hidden_tooltip = { disband_event_forces = faction_loyalists } }
	}

	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
	}
}

change_democracy_censal_succession_law = {
	name = CB_NAME_DEMOCRACY_CENSAL_SUCCESSION_LAW
	war_name = WAR_NAME_DEMOCRACY_CENSAL_SUCCESSION_LAW
	sprite = 6
	truce_days = 3650
	attacker_can_call_allies = no
	can_ask_to_join_war = no
	major_revolt = yes
	
	can_use_gui = {
		check_if_crusader_trigger = yes
	}

	can_use = {
		ROOT = {
			vassal_of = FROM	
		}
	}
	
	is_valid = {
		FROM = {
			in_revolt = no
			liege_before_war = {
				in_revolt = no
				liege_before_war = {
					in_revolt = no
				}
			}
		}
		ROOT = {
			OR = {
				liege = {
					character = PREV # either independent
				}
				liege = { 
					FROM = { 
						is_liege_or_above = PREV # or have shared liege
					}
				}
			}
		}
	}

	is_valid_title = {
		NOT = {
			has_law = succ_democracy_censal
		}
		OR = {
			tier = emperor
			tier = king
			is_primary_holder_title = yes
		}
	}

	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = { detract_grace_super_huge_effect = yes }
		}
	}
	
	on_success = {
		FROM = {
			hidden_tooltip = { disband_event_forces = faction_loyalists }
			if = {
				limit = { NOT = { has_dlc = "Zeus" } }
				any_demesne_title = { # All titles
					if = {
						limit = {
							OR = {
								tier = king
								tier = emperor
							}
		#					is_titular = no
							NOT = { has_law = crown_authority_0 }
						}
						if = {
							limit = { has_law = crown_authority_1 }
							add_law = crown_authority_0
						}
						if = {
							limit = { has_law = crown_authority_2 }
							add_law = crown_authority_1
						}
						if = {
							limit = { has_law = crown_authority_3 }
							add_law = crown_authority_2
						}
						if = {
							limit = { has_law = crown_authority_4 }
							add_law = crown_authority_3
						}
					}
				}
			}
		}
		
		ROOT = {
			participation_scaled_prestige = 100
			hidden_tooltip = {
				disband_event_forces = faction_revolters
			}
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = {
				participation_scaled_prestige = 100 
				disband_event_forces = faction_revolters
			}
		}
	}

	on_success_title = {
		add_law_w_cooldown = succ_democracy_censal
	}

	on_fail = {
		ROOT = {
			prestige = -100
		}
		FROM = {
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
		
		hidden_tooltip = {
			any_attacker = {
				disband_event_forces = faction_revolters
				add_character_modifier = {
					name = faction_succ_democracy_censal_ultimatum_timer
					hidden = yes
					duration = 3650
				}
			}
		}
		FROM = { hidden_tooltip = { disband_event_forces = faction_loyalists } }
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			prisoner = FROM
		}
		FROM = {
			participation_scaled_prestige = 100
			hidden_tooltip = { 
				if = { 
					limit = { NOT = { has_opinion_modifier = { modifier = opinion_traitor who = ROOT } } } #Allow free revocation of a title.
					opinion = {
						who = ROOT
						modifier = opinion_traitor
					}
				}
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		
		hidden_tooltip = {
			any_attacker = {
				limit = { liege = { character = FROM } }
				prisoner = FROM
				disband_event_forces = faction_revolters
				add_character_modifier = {
					name = faction_succ_democracy_censal_ultimatum_timer
					hidden = yes
					duration = 3650
				}
			}
		}
		
		FROM = { hidden_tooltip = { disband_event_forces = faction_loyalists } }
	}

	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
	}
}