########################################################
# RELIGIOUS TITLES
# Titles given out by the religious head
########################################################
#	religion: Religion that owns this title.
#	can_elect_head: If holders of this title can elect a new head.
#	grant_limit: Max number of holders.
#	realm_in_name: Append the name of the country after the title (Queen [of Sweden])
#	allow: conditions for the character to hold the title
#	gain_effect: fires when the title is granted
#	lose_effect: fires when a title is lost if dismissal_trigger evaluates to false
#	message: should fire a message to the its owner when set
#	The other fields are all character modifiers.

title_cardinal = {
	religion = catholic
	can_elect_head = yes
	revoke_allowed = no
	
	grant_limit = 20
	
	realm_in_name = no
	show_as_title = yes
	
	opinion_effect = 20
	
	dignity = 5
	monthly_salary = 5
	monthly_prestige = 5
	monthly_piety = 5
	
	allowed_to_grant = {
		always = no
	}
	allow = {
		religion = catholic
		is_theocracy = yes
		is_landed = yes
	#	k_papal_state = {
	#		holder_scope = {
	#			is_within_diplo_range = ROOT
	#		}
	#	}		
#		NOT = { # old version
#			top_liege = {
#				any_vassal = {
#					any_claim = {
#						title = k_papal_state
#					}
#				}
#			}
#		}
		NOT = {
			any_liege = {
				has_claim = k_papal_state
			}
		}
		NOT = {
			has_claim = k_papal_state
		}
		NOT = {
			any_vassal = {
				has_claim = k_papal_state
			}
		}
		NOT = {
			top_liege = {
				any_realm_character = {
					has_claim = k_papal_state
				}
			}
		}
		NOT = {
			is_landed = no
		}
	}
	gain_effect = {
		remove_trait = Eveque-Catholic
		add_trait = Cardinal-Catholic
		if = {
			limit = {
				not = {
					any_owned_bloodline = {
						has_bloodline_flag = Cardinal-Catholic_bloodline
						founder = {
							character = ROOT
						}
					}
				}
			}
			create_bloodline = {
				type = Cardinal-Catholic_bloodline
				inheritance = all_descendants
			}
		}
	}
	lose_effect = {
		remove_trait = Cardinal-Catholic
		k_papal_state = {
			holder_scope = {
				save_event_target_as = pope_traits_cardinal_catholique
			}
		}
		if = {
			limit = {
				NOT = {
					has_landed_title = k_papal_state
				}
			}
			transfer_scaled_wealth = {
				to = event_target:pope_traits_cardinal_catholique
				value = all
			}
			any_artifact = {
				transfer_artifact = {
					to = event_target:pope_traits_cardinal_catholique
					from = PREV
				}
			}
		}
		any_bloodline = {
			limit = {
				has_bloodline_flag = Cardinal-Catholic_bloodline
				founder = {
					character = ROOT
				}
			}
			destroy_bloodline = yes
		}
	}
	message = yes
}

title_fraticelli_cardinal = {
	religion = fraticelli
	can_elect_head = yes
	revoke_allowed = no
	
	grant_limit = 20
	
	realm_in_name = no
	show_as_title = yes
	
	opinion_effect = 20
	
	dignity = 5
	monthly_salary = 5
	monthly_prestige = 5
	monthly_piety = 5
	
	allowed_to_grant = {
		always = no
	}
	allow = {
		religion = fraticelli
		is_theocracy = yes
		is_landed = yes
	#	d_fraticelli = {
	#		holder_scope = {
	#			is_within_diplo_range = ROOT
	#		}
	#	}		
#		NOT = { # old version
#			top_liege = {
#				any_vassal = {
#					any_claim = {
#						title = d_fraticelli
#					}
#				}
#			}
#		}
		NOT = {
			any_liege = {
				has_claim = d_fraticelli
			}
		}
		NOT = {
			has_claim = d_fraticelli
		}
		NOT = {
			any_vassal = {
				has_claim = d_fraticelli
			}
		}
		NOT = {
			top_liege = {
				any_realm_character = {
					has_claim = d_fraticelli
				}
			}
		}
		NOT = {
			is_landed = no
		}
	}	
	gain_effect = {
		remove_trait = Eveque-Fraticelli
		add_trait = Cardinal-Fraticelli
		if = {
			limit = {
				not = {
					any_owned_bloodline = {
						has_bloodline_flag = Cardinal-Fraticelli_bloodline
						founder = {
							character = ROOT
						}
					}
				}
			}
			create_bloodline = {
				type = Cardinal-Catholic_bloodline
				inheritance = all_descendants
			}
		}
	}
	lose_effect = {
		remove_trait = Cardinal-Fraticelli
		d_fraticelli = {
			holder_scope = {
				save_event_target_as = pope_traits_cardinal_fraticelli
			}
		}
		if = {
			limit = {
				NOT = {
					has_landed_title = d_fraticelli
				}
			}
			transfer_scaled_wealth = {
				to = event_target:pope_traits_cardinal_fraticelli
				value = all
			}
			any_artifact = {
				transfer_artifact = {
					to = event_target:pope_traits_cardinal_fraticelli
					from = PREV
				}
			}
		}
		any_bloodline = {
			limit = {
				has_bloodline_flag = Cardinal-Fraticelli_bloodline
				founder = {
					character = ROOT
				}
			}
			destroy_bloodline = yes
		}
	}
	message = yes
}
