########################################################
# 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.


#Titles other than cardinal are not displayed on character sheet, but do influence the full title of the characters. Don't know why...
title_cardinal = {
	religion = catholic
	can_elect_head = yes
	revoke_allowed = no
	grant_limit = 9
	realm_in_name = no
	show_as_title = yes
	opinion_effect = -10 #Cardinals get +15 when appointed. However they dislike other Popes...
	dignity = 0.9
	monthly_salary = 0.25
	monthly_prestige = 1.0
	monthly_piety = 0.25
	allow = {
		has_global_flag = PDP_cardinals_allowed #to make sure there are not cardinals at game start.
		PDP_fulfills_cardinal_requirement = yes
	}
	gain_effect = {
		add_trait = PDP_cardinal
		set_character_flag = PDP_college_supported_as_cardinal #in case the player takes over the papacy.
		#if the player is a cardinal, send him a fake event where he can decide if he agrees.
		if = {
			limit = {had_global_flag = {flag = PDP_cardinals_allowed days = 5}} #The college starts out without any Cardinals, therefore the voting is disabled for the first few days
			character_event = {id = PDP.69} #(looks for player cardinal and dispatches event)
		}
		rightful_religious_head_scope = {
			reverse_opinion = {modifier = opinion_supported_cardinal who = ROOT years = 150}
			clr_character_flag = PDP_vacant_seats_in_college #track if player appointed cardinals.
		}
		character_event = {id = PDP.78} #inform player that he's elected.
		if = {
			limit = {
				independent = no
				rightful_religious_head_scope = {ai = no} #since ai's decisions are not always final
			}
			liege = {
				rightful_religious_head_scope = { #always the same, since only independents can have antipope
					reverse_opinion = {modifier = opinion_merciful who = PREV years = 10}
				}
			}
		}
	}
	lose_effect = {
		remove_trait = PDP_cardinal
		clr_character_flag = PDP_attends_conclave
		if = {#player excommunicated him (without good reason) to stop him from being a cardinal
			limit = {
				has_global_flag = PDP_cardinals_allowed
				PDP_fulfills_cardinal_requirement_without_excommunication = yes
				trait = excommunicated
				is_impious_trigger = no
				PDP_evil_deeds = no
				rightful_religious_head_scope = {
					PDP_is_player_pope = yes
				}
			}
			rightful_religious_head_scope = { #inform the player that he's a bad sneaky player and has to stop.
				character_event = {id = PDP.300 days = 0}
			}
		}
	}
	retire_effect = { #dont know if actually working/needed
		remove_trait = PDP_cardinal
		clr_character_flag = PDP_attends_conclave
	}
	death_effect = {
		remove_trait = PDP_cardinal
		clr_character_flag = PDP_attends_conclave
	}
	message = yes
}

title_fraticelli_cardinal  = {
	religion = fraticelli
	can_elect_head = yes
	revoke_allowed = no
	grant_limit = 9
	realm_in_name = no
	show_as_title = yes
	opinion_effect = 20
	dignity = 0.9 #2.0
	monthly_salary = 0.25
	monthly_prestige = 1.0
	monthly_piety = 0.25
	allow = {
		religion = fraticelli
		OR = {
			is_theocracy = yes
			government = playable_theocracy_government
		}
		rightful_religious_head_scope = {
			has_landed_title = d_fraticelli #not under rule of antipope
			#I think I forgot that fraticelli has a different title, so events don't work...
			is_within_diplo_range = ROOT #prevent game from not appointing cardinals any more (india)
		}
	}
	gain_effect = {
		add_trait = PDP_cardinal
	}
	lose_effect = {
		remove_trait = PDP_cardinal
	}
	message = yes
}

title_cardinal_nephew = {
	religion = catholic
	revoke_allowed = yes
	grant_limit = 1
	realm_in_name = no
	show_as_title = yes
	opinion_effect = 10
	dignity = 0.91	#must be higher than cardinal
	#general_opinion = -5
	monthly_salary = 0.25
	monthly_prestige = 0.5
	monthly_piety = -0.25
	allow = {
		religion = catholic
		has_minor_title = title_cardinal
		religion_head = {
			dynasty = ROOT
		}
	}
	gain_effect = {
	}
	lose_effect = {
	}
	message = yes
}

title_cardinal_dean = {
	religion = catholic
	revoke_allowed = no
	grant_limit = 1
	realm_in_name = no
	show_as_title = yes
	opinion_effect = 10
	dignity = 0.92	#must be higher than cardinal (and nephew)
	monthly_salary = 0.5
	monthly_prestige = 0.5
	monthly_piety = 0.25
	allow = {
		religion = catholic
		has_minor_title = title_cardinal
		# NOT = {
			# PDP_cardinal = {
				# AND = {
					# is_older_than = ROOT
					# age_diff = {who = ROOT years = 1}
				# }
			# }
		# }
	}
	gain_effect = { #apparently, the AI appoints multiple cardinal deans. This might fix it?!
		while = {
			count = 9 #just in case...
			limit = {
				PDP_cardinal = {
					has_minor_title = title_cardinal_dean
					NOT = {character = PREV}
				}
			}
			PDP_cardinal = {
				limit = {
					has_minor_title = title_cardinal_dean
					NOT = {character = PREV}
				}
				remove_title = title_cardinal_dean
			}
		}
	}
	lose_effect = {
	}
	message = yes
}


title_papal_legate = {
	religion = catholic
	revoke_allowed = no
	grant_limit = 3
	realm_in_name = yes
	show_as_title = yes
	opinion_effect = 5
	dignity = 0.1
	monthly_salary = 0.2
	monthly_prestige = 0.2
	monthly_piety = 0.1
	allow = {
		religion = catholic
		NOT = {
			trait = excommunicated
		}
		PDP_is_theocracy = yes
		independent = no
		liege = {
			religion = catholic
			higher_tier_than = DUKE
			NOT = {has_landed_title = k_papal_state}
		}
		PDP_has_no_antipope = yes
	}
	gain_effect = {
	}
	lose_effect = {
	}
	message = yes
}
