################################################
#
# Events for Pope vs Free Investiture
#
# ID 67000 - 67999 are reserved
#
##################################################
# Written by Johan Andersson


# The Pope singles out a Kingdom with Free Investiture (unless he has already targetted one)
character_event = {
	id = 67000
	desc = EVTDESC67000
	picture = GFX_evt_icon
	border = GFX_event_normal_frame_religion

	only_playable = yes
	religion_group = christian
	min_age = 16
	only_men = yes
	prisoner = no
	only_capable = yes
	war = no

	trigger = {
		controls_religion = yes
		year = 1000
		primary_title = {
			OR = {
				title = k_papal_state
				title = k_chalcedonian
				title = d_celtic_pagan_reformed
				title = d_pontifex_maximus
				title = d_cathar
				title = d_bogomilist
				title = d_manichean
				title = d_fraticelli
			}
		}
		religion_authority = 0.35
		NOT = { has_character_flag = pope_currently_demanding }
		any_independent_ruler = {
			religion = ROOT
			rightful_religious_head = ROOT
			NOT = { has_character_flag = pope_wants_our_law_changed }
			NOT = { has_character_flag = pope_respects_our_law }
			primary_title = {
				has_law = investiture_law_1
			}
		}
	}

	mean_time_to_happen = {
		months = 100 #once every 10 years
		modifier = {
			factor = 0.25
			trait = zealous
		}
	}

	option = {
		name = EVTOPTA67000
		ai_chance = { factor = 100 }
		set_character_flag = pope_currently_demanding
		random_independent_ruler = {
			limit = {
				religion = ROOT
				rightful_religious_head = ROOT
				NOT = { has_character_flag = pope_wants_our_law_changed }
				NOT = { has_character_flag = pope_respects_our_law }
				any_demesne_title = {
					tier = EMPEROR
					has_law = investiture_law_1
				}
			}
			character_event = { id = 67001 days = 14 tooltip = EVTTOOLTIP67001 }
			set_character_flag = pope_wants_our_law_changed
			break = yes
		}
		random_independent_ruler = {
			limit = {
				religion = ROOT
				rightful_religious_head = ROOT
				NOT = { has_character_flag = pope_wants_our_law_changed }
				NOT = { has_character_flag = pope_respects_our_law }
				any_demesne_title = {
					tier = KING
					has_law = investiture_law_1
				}
			}
			character_event = { id = 67001 days = 14 tooltip = EVTTOOLTIP67001 }
			set_character_flag = pope_wants_our_law_changed
		}
	}

	option = {
		name = EVTOPTB67000
		ai_chance = { factor = 0 }
	}
}


# King/Emperor gets the papal emissary asking them to change laws!
character_event = {
	id = 67001
	desc = EVTDESC67001
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA67001 # Fold to demand

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				trait = cynical
			}
			modifier = {
				factor = 5
				trait = zealous
			}
		}

		FROM = { clr_character_flag = pope_currently_demanding }

		primary_title = {
			revoke_law = investiture_law_1
			add_law_w_cooldown = investiture_law_0
		}
		piety = 50
		prestige = -200
		religion_authority = {
			modifier = ruler_bowed_to_pope
			years = 10
		}
		clr_character_flag = pope_wants_our_law_changed
		FROM = {
			opinion = {
				modifier = pope_invest_approve
				who = ROOT
				years = 5
			}
		}
		hidden_tooltip = {
			FROM = {  character_event = { id = 67002 } }
		}
	}
	option = {
		name = EVTOPTB67001 # Refuse
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				trait = zealous
			}
			modifier = {
				factor = 1.5
				trait = arbitrary
			}
			modifier = {
				factor = 1.5
				trait = cynical
			}
			modifier = {
				factor = 1.5
				trait = hedonist
			}
		}
		piety = -50
		add_trait = excommunicated
		religion_authority = {
			modifier = ruler_defied_pope
			years = 10
		}
		set_character_flag = pope_we_refuse_law_changed
		FROM = {
			opinion = {
				modifier = pope_invest_dislike
				who = ROOT
				years = 5
			}
		}
		hidden_tooltip = {
			FROM = {  character_event = { id = 67003 } }
		}
	}
	option = {
		name = EVTOPTC67001 # Give gold to Pope
		trigger = {
			diplomacy = 12			
		}
		ai_chance = {
			factor = 5
			modifier = {
				factor = 3
				trait = cynical
			}
			modifier = {
				factor = 0
				trait = zealous
			}
			modifier = {
				factor = 0.1
				NOT = { wealth = 200 }
			}
		}
		wealth = -200
		FROM = { clr_character_flag = pope_currently_demanding }
		set_character_flag = pope_respects_our_law
		clr_character_flag = pope_wants_our_law_changed
		hidden_tooltip = {
			FROM = { character_event = { id = 67004  } }
		}
	}
	option = {
		name = EVTOPTD67001 # Impress with Learning
		tooltip_info = learning
		trigger = {
			learning = 12
		}
		ai_chance = {
			factor = 100
		}
		piety = 10
		FROM = { clr_character_flag = pope_currently_demanding }
		set_character_flag = pope_respects_our_law
		clr_character_flag = pope_wants_our_law_changed
		hidden_tooltip = {
			FROM = {  character_event = { id = 67005 } }
		}
	}
}

#king accepts
character_event = {
	id = 67002
	desc = EVTDESC67002
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA67002
		prestige = 5
	}
}

#king refuses us
character_event = {
	id = 67003
	desc = EVTDESC67003
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = { # Do nothing
		name = EVTOPTA67003
		ai_chance = {
			factor = 1
			modifier = {
				factor = 1.2
				trait = shy
			}
			modifier = {
				factor = 1.5
				trait = kind
			}
			modifier = {
				factor = 1.5
				trait = bad_priest_christian
			}
			modifier = {
				factor = 2
				opinion = {
					who = FROM
					value = 50
				}
			}
		}
		prestige = -50
		opinion = {
			modifier = pope_invest_dislike
			who = FROM
		}
	}
	option = { # Excommunicate the fool!
		name = EVTOPTA67022
		ai_chance = {
			factor = 1
			modifier = {
				factor = 1.2
				trait = proud
			}
			modifier = {
				factor = 1.2
				trait = envious
			}
			modifier = {
				factor = 1.5
				trait = crusader
			}
			modifier = {
				factor = 1.5
				trait = ambitious
			}
			modifier = {
				factor = 3
				trait = zealous
			}
			modifier = {
				factor = 3
				NOT = {
					opinion = {
						who = FROM
						value = 0
					}
				}
			}
		}
		prestige = -5
		opinion = {
			modifier = pope_invest_dislike
			who = FROM
		}
		tooltip = {
			FROM = {
				add_trait = excommunicated
	}
		}
		hidden_tooltip = {
			FROM = { character_event = { id = 38022 days = 10 } }
		}
	}
}

#king bribes us"
character_event = {
	id = 67004
	desc = EVTDESC67004
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = "EVTOPTA67004"
		wealth = 200
	}
}

#king outwits us.
character_event = {
	id = 67005
	desc = EVTDESC67005
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA67005
		piety = -5
	}
}

# The Pope sends a delegate to a Bishop whose top liege has refused to change investiture Law
character_event = {
	id = 67010
	desc = EVTDESC67010
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	only_playable = yes
	religion_group = christian
	min_age = 16
	only_men = yes
	prisoner = no
	only_capable = yes
	war = no
	
	has_character_flag = pope_currently_demanding

	trigger = {
		controls_religion = yes
		year = 1000
		primary_title = {
			OR = {
				title = k_papal_state
				title = k_chalcedonian
				title = d_celtic_pagan_reformed
				title = d_pontifex_maximus
				title = d_cathar
				title = d_bogomilist
				title = d_manichean
				title = d_fraticelli
			}
		}
		wealth = 20
		any_independent_ruler = {
			religion = ROOT
			rightful_religious_head = ROOT
			has_character_flag = pope_we_refuse_law_changed
			primary_title = {
				has_law = investiture_law_1
			}
			any_realm_lord = {
				is_theocracy = yes
				religion = ROOT
				NOT = { has_character_flag = pope_bribing }
			}
		}
	}

	mean_time_to_happen = {
		months = 50
		modifier = {
			factor = 0.25
			trait = zealous
		}
	}

	option = {
		name = EVTOPTA67010
		ai_chance = { factor = 100 }
		random_independent_ruler = {
			limit = {
				religion = ROOT
				rightful_religious_head = ROOT
				has_character_flag = pope_we_refuse_law_changed
				primary_title = {
					has_law = investiture_law_1
				}
				any_realm_lord = {
					is_theocracy = yes
					religion = ROOT
					NOT = { has_character_flag = pope_bribing }
				}
			}
			random_realm_lord = {
				limit = {
					is_theocracy = yes
					religion = ROOT
					NOT = { has_character_flag = pope_bribing }
				}
				set_character_flag = pope_bribing
				character_event = { id = 67011 days = 14 tooltip = EVTTOOLTIP67011 }
			}
		}
	}

	option = {
		name = EVTOPTB67010
		ai_chance = { factor = 0 }
		random_independent_ruler = {
			limit = {
				religion = ROOT
				rightful_religious_head = ROOT
				has_character_flag = pope_we_refuse_law_changed
				primary_title = {
					has_law = investiture_law_1
				}
				any_realm_lord = {
					is_theocracy = yes
					religion = ROOT
					NOT = { has_character_flag = pope_bribing }
				}
			}
			clr_character_flag = pope_we_refuse_law_changed
		}
		clr_character_flag = pope_currently_demanding
	}

}

# The Bishop receives the Papal emissary
character_event = {
	id = 67011
	desc = EVTDESC67011
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA67011
		wealth = 20
		opinion = {
			modifier = bishop_bribed_by_pope
			who = FROM
			years = 5
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0.1
				opinion = { who = top_liege value = 75 }
			}
		}
		random = {
			chance = 33
			top_liege = {
				character_event = { id = 67012 days = 14 tooltip = EVTTOOLTIP67012 }
			}
		}
	}
	option = {
		name = EVTOPTB67011
		ai_chance = {
			factor = 1
			modifier = {
				factor = 1.5
				opinion = { who = top_liege value = 20 }
			}
			modifier = {
				factor = 2
				opinion = { who = top_liege value = 40 }
			}
			modifier = {
				factor = 4
				opinion = { who = top_liege value =  60 }
			}
			modifier = {
				factor = 100
				opinion = { who = top_liege value =  90 }
			}
		}
		prestige = 1
	}
}

#King knows of bishop getting bribed
character_event = {
	id = 67012
	desc = EVTDESC67012
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA67012
		opinion = {
			modifier = opinion_dishonorable
			who = FROM
			months = 60
		}
	}
}

# The Pope contacts a powerful (preferably rebellious) vassal of a liege who has refused to change investiture Law
character_event = {
	id = 67020
	desc = EVTDESC67020
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	only_playable = yes
	religion_group = christian
	min_age = 16
	only_men = yes
	prisoner = no
	only_capable = yes
	war = no	
	has_character_flag = pope_currently_demanding

	trigger = {
		controls_religion = yes
		year = 1000
		primary_title = {
			OR = {
				title = k_papal_state
				title = k_chalcedonian
				title = d_celtic_pagan_reformed
				title = d_pontifex_maximus
				title = d_cathar
				title = d_bogomilist
				title = d_manichean
				title = d_fraticelli
			}
		}
		any_independent_ruler = {
			religion = ROOT
			rightful_religious_head = ROOT
			has_character_flag = pope_we_refuse_law_changed
			primary_title = {
				has_law = investiture_law_1
			}
			any_realm_lord = {
				OR = { tier = KING tier = DUKE }
				NOT = { has_character_flag = pope_vassal_approached }
				religion = ROOT
				relative_power_to_liege = 0.05
			}
		}
	}

	mean_time_to_happen = {
		months = 50
		modifier = {
			factor = 0.5
			trait = ambitious
		}
	}
	
	option = {
		name = EVTOPTA67020
		ai_chance = { factor = 100 }
		random_independent_ruler = {
			limit = {
				religion = ROOT
				rightful_religious_head = ROOT
				has_character_flag = pope_we_refuse_law_changed
				primary_title = {
					has_law = investiture_law_1
				}
				any_realm_lord = {
					OR = { tier = KING tier = DUKE }
					NOT = { has_character_flag = pope_vassal_approached }
					religion = ROOT
					relative_power_to_liege = 0.05
				}
			}
			random_realm_lord = {
				limit = {
					OR = { tier = KING tier = DUKE }
					NOT = { has_character_flag = pope_vassal_approached }
					religion = ROOT
					relative_power_to_liege = 0.05
				}
				set_character_flag = pope_vassal_approached 
				character_event = { id = 67021 days = 14 tooltip = EVTTOOLTIP67021 }
			}			
		}
		clr_character_flag = pope_currently_demanding
	}

	option = {
		name = EVTOPTB67020
		ai_chance = { factor = 0 }
		random_independent_ruler = {
			limit = {
				religion = ROOT
				rightful_religious_head = ROOT
				has_character_flag = pope_we_refuse_law_changed
				primary_title = {
					has_law = investiture_law_1
				}
				any_realm_lord = {
					OR = { tier = KING tier = DUKE }
					NOT = { has_character_flag = pope_vassal_approached }
					religion = ROOT
					relative_power_to_liege = 0.1
				}
			}
			clr_character_flag = pope_we_refuse_law_changed
		}
		clr_character_flag = pope_currently_demanding
	}
}


#- The vassal receives the claim
character_event = {
	id = 67021
	desc = EVTDESC67021
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = "EVTOPTA67021"
		opinion = {
			modifier = bishop_bribed_by_pope
			who = FROM
			years = 5
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0.1
				opinion = { who = top_liege value = 75 }
			}
		}
		piety = 10
		top_liege = { primary_title = { add_pressed_claim = ROOT  }}
		random = {
			chance = 33
			top_liege = {
				character_event = { id = 67022 days = 14 tooltip = EVTTOOLTIP67022 }
			}
		}
	}
	option = {
		name = EVTOPTB67021
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { opinion = { who = top_liege value = 50 } }
			}
			modifier = {
				factor = 2
				opinion = { who = top_liege value = 55 }
			}
			modifier = {
				factor = 4
				opinion = { who = top_liege value =  60 }
			}
			modifier = {
				factor = 100
				opinion = { who = top_liege value =  80 }
			}
		}
		piety = -20
		opinion = {
			modifier = loyal_vassal_against_pope
			who = top_liege
			years = 5
		}
	}
}

character_event = {
	id = 67022
	desc = EVTDESC67022
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA67022
		prestige = -5
		opinion = {
			modifier = my_vassal_bribed_by_pope
			who = FROM
			years = 5
		}
		FROM = {
			opinion = {
				modifier = my_vassal_bribed_by_pope
				who = ROOT
				years = 5
			}
		}
	}
}
