imperial_dignity = {
	name = CB_IMPERIAL_DIGNITY
	war_name = WAR_NAME_IMPERIAL_DIGNITY
	sprite = 17
	truce_days = 3650
	is_permanent = yes
	check_all_titles = yes
	is_holy_war = yes # experimental: might make others join the target?
	can_ask_to_join_war = yes
	can_call_allies = yes
	allow_whitepeace = no
	
	
	can_use_title = {
		tier = emperor
	}
	
	can_use = {
		ROOT = {
			has_landed_title = e_roman_empire
			independent = yes
			religion_group = christian
			NOT = { same_realm = FROM }
		}
		FROM = {
			religion_group = christian
		}
	}

	is_valid = {
		ROOT = {
			independent = yes
			religion_group = christian
			NOT = { same_realm = FROM }
		}
	}
	
	on_success = {
		custom_tooltip = { 
			text = imperial_dignity_succ_tip
			any_attacker = {
				limit = { character = ROOT }
				participation_scaled_prestige = 1000
			}
			any_attacker = {
				limit = { NOT = { character = ROOT } }
				hidden_tooltip = { 
					participation_scaled_prestige = 100
				}
			}
			
			FROM = {
				prestige = -1000
			}
		}
	}

	on_success_title = {
		custom_tooltip = { 

			# Transfer all vassal kingdoms to target emperor
			#holder_scope = {
			#	any_title_under = {
			#		if = {
			#			limit = {
			#				OR = {
			#					tier = king
			#				}
			#				is_titular = no
			#			}
			#			usurp_title = FROM
			#		}
			#	}
			#}

			# Make the target empire titular
			hidden_tooltip = {
				any_direct_de_jure_vassal_title = { # kingdoms, since target is empire
					holder_scope = {
						is_liege_or_above = FROM
					}
					# grant_title = FROM # not recommended: grant all de-jure kingdoms to target emperor, even unowned or uncreated ones
					de_jure_liege = --- # wipe out kingdom-empire de-jure level
				}
			}
			
			# After we did everything else, pull the trigger on target empire
			destroy_landed_title = THIS
		}
	}

	on_fail = {
	}

	on_reverse_demand = {
		custom_tooltip = {
			text = imperial_dignity_rev_tip
			ROOT = {
				transfer_scaled_wealth = {
					to = FROM
					value = 15.0
				}
				ROOT = { prestige = -5000 }
				
				# Reverse the restoration
				hidden_tooltip = {
					primary_title = {
						any_direct_de_jure_vassal_title = {
							de_jure_liege = e_byzantium
						}
					}
				}
				e_byzantium = {
					grant_title = ROOT
					copy_title_laws = e_roman_empire
					copy_title_history = e_roman_empire
				}
				e_roman_empire = {
					destroy_landed_title = THIS
				}
			}
			any_defender = {
				limit = { character = FROM }
				participation_scaled_piety = 100
				participation_scaled_prestige = 200
				if = {
					limit = {
						religion_group = muslim
					}
					participation_scaled_decadence = -10
				}
			}
			any_defender = {
				limit = { NOT = { character = FROM } }
				hidden_tooltip = { 
					participation_scaled_piety = 100
					participation_scaled_prestige = 200
					if = {
						limit = {
							religion_group = muslim
						}
						participation_scaled_decadence = -10
					}
				}
			}
		}
	}
	
	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 200
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 200
	}

}

great_dejure_war = {
	name = CB_GREAT_DEJURE
	war_name = WAR_NAME_GREAT_DEJURE
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	battle_warscore_mult = 0.5
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
	
	can_use_gui = {
		ROOT = {
			religion_authority = 0.4
			c_byzantion = {
				location = {
					NOT = {
						has_province_modifier = launched_great_dejure_war
					}
				}
			}
		}
	}

	can_use = {
		ROOT = {
			OR = {
				has_landed_title = e_byzantium
				has_landed_title = e_roman_empire
			}
			has_landed_title = c_byzantion
			independent = yes
			religion = orthodox
			NOT = { same_realm = FROM }
		}
		
		FROM = {
			NOT = { religion_group = christian }
		}
	}

	can_use_title = {
		tier = king
		is_titular = no

		# de_jure_liege = ROOT
		
		OR = {
			de_jure_liege = e_byzantium
			de_jure_liege = e_roman_empire
		}

		any_direct_de_jure_vassal_title = {
			OR = {
				holder_scope = {
					OR = {
						character = FROM
						is_liege_or_above = FROM
					}
				}
			}
		}
		
		
	}
	
	is_valid = {
		FROM = {
			NOT = { religion_group = christian }
		}
	}

	on_add = {
		# Constantinople is not going anywhere, so lets use it to store the 20 year cooldown so it can
		# outlast the current Emperor if needed.
		c_byzantion = {
			location = {
				add_province_modifier = { name = launched_great_dejure_war duration = 7300 }
			}
		}
		# Targets the de jure capital, not sure if this always works as intended
		#k_greece = {
		#	capital_scope = {
		#		add_province_modifier = { name = launched_great_dejure_war duration = 7300 }
		#	}
		#}
	}

	on_success_title = {
	
		ROOT = {
			vassalize_or_take_under_title = {
				title = PREV
				enemy = FROM
				same_religion = yes # Only vassalize rulers of my religion
			}
			#gain_settlements_under_title = {
			#	title = PREV
			#	enemy = FROM
			#}
		}
		
		ROOT = {
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
		}
		
		FROM = {
			piety = -100
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}			
		}
	}

	on_fail = {
		ROOT = {
			piety = -100
		}
		
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					religion_group = muslim
				}
				participation_scaled_decadence = -50
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						religion_group = muslim
					}
					participation_scaled_decadence = -50
				}
			}
		}
		
	}

	on_reverse_demand = {
		ROOT = {
			piety = -200
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = {
			piety = 100
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 300
			participation_scaled_prestige = 150
			if = {
				limit = {
					religion_group = muslim
				}
				participation_scaled_decadence = -100
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 300
				participation_scaled_prestige = 150
				if = {
					limit = {
						religion_group = muslim
					}
					participation_scaled_decadence = -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
	}
}
