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

	is_triggered_only = yes # on_yearly_pulse, random_events, pope_events

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

	trigger = {
		controls_religion = yes
		year >= 1000
		is_catholic_branch = yes
		religion_authority >= 0.35
		NOT = { has_character_flag = pope_currently_demanding }

		any_independent_ruler = {
			higher_real_tier_than = DUKE
			religion = ROOT
			rightful_religious_head = ROOT

			any_demesne_title = {
				has_law = investiture_law_1
			}

			NOR = {
				has_character_flag = pope_wants_our_law_changed
				has_character_flag = pope_respects_our_law
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 4
			trait = zealous
		}
	}

	option = {
		name = EVTOPTA67000

		set_character_flag = pope_currently_demanding

		random_independent_ruler = {
			limit = {
				higher_real_tier_than = DUKE
				religion = ROOT
				rightful_religious_head = ROOT

				any_demesne_title = {
					has_law = investiture_law_1
				}

				NOR = {
					has_character_flag = pope_wants_our_law_changed
					has_character_flag = pope_respects_our_law
				}
			}

			preferred_limit = {
				real_tier = EMPEROR
			}

			save_event_target_as = target_ruler
			set_character_flag = pope_wants_our_law_changed

			character_event = {
				id = 67001
				days = 14
				tooltip = EVTTOOLTIP67001
			}
		}
	}

	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

		random_demesne_title = {
			limit = { has_law = investiture_law_1 }

			set_title_flag = non_manual_law_change # No prestige loss
			add_law_w_cooldown = investiture_law_0
			clr_title_flag = non_manual_law_change # No prestige loss
		}

		piety = 50
		prestige = -200

		religion_authority = {
			name = ruler_bowed_to_pope
			years = 10
		}

		clr_character_flag = pope_wants_our_law_changed

		FROM = {
			show_scope_change = no

			clr_character_flag = pope_currently_demanding

			opinion = {
				name = pope_invest_approve
				who = ROOT
				years = 5
			}

			character_event = { id = 67002 }
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 0.5
				trait = cynical
			}

			mult_modifier = {
				factor = 5
				trait = zealous
			}
		}
	}

	option = {
		name = EVTOPTB67001 # Refuse

		piety = -50

		religion_authority = {
			name = ruler_defied_pope
			years = 10
		}

		set_character_flag = pope_we_refuse_law_changed

		FROM = {
			show_scope_change = no

			opinion = {
				name = pope_invest_dislike
				who = ROOT
				years = 5
			}

			character_event = { id = 67003 }
		}

		ai_chance = {
			factor = 1

			trigger = {
				NOT = { trait = zealous }
			}

			mult_modifier = {
				factor = 1.5
				trait = arbitrary
			}

			mult_modifier = {
				factor = 1.5
				trait = cynical
			}

			mult_modifier = {
				factor = 1.5
				trait = hedonist
			}
		}
	}

	option = {
		name = EVTOPTC67001 # Give gold to Pope

		trigger = { diplomacy >= 10 }

		transfer_scaled_wealth = {
			to = FROM
			value = 1
			min = 200
			max = 200
		}

		set_character_flag = pope_respects_our_law
		clr_character_flag = pope_wants_our_law_changed

		FROM = {
			clr_character_flag = pope_currently_demanding
			character_event = { id = 67004 }
		}

		ai_chance = {
			factor = 5

			trigger = {
				NOT = { trait = zealous }
			}

			mult_modifier = {
				factor = 3
				trait = cynical
			}

			mult_modifier = {
				factor = 0.1
				wealth < 200
			}
		}
	}

	option = {
		name = EVTOPTD67001 # Impress with Learning
		tooltip_info = learning

		trigger = { learning >= 10 }

		piety = 10
		set_character_flag = pope_respects_our_law
		clr_character_flag = pope_wants_our_law_changed

		FROM = {
			clr_character_flag = pope_currently_demanding
			character_event = { id = 67005 }
		}

		ai_chance = { factor = 100 }
	}
}

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

	is_triggered_only = yes

	option = {
		name = GLORY_TO_HIGHGOD

		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 = {
		name = EVTOPTA67003 # Do nothing

		prestige = -50

		opinion = {
			name = pope_invest_dislike
			who = FROM
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 1.2
				trait = shy
			}

			mult_modifier = {
				factor = 1.5
				trait = kind
			}

			mult_modifier = {
				factor = 1.5
				trait = bad_priest_christian
			}

			mult_modifier = {
				factor = 2

				opinion = {
					who = FROM
					value >= 50
				}
			}
		}
	}

	option = {
		name = EVTOPTA67022 # Excommunicate the fool!

		prestige = -5

		opinion = {
			name = pope_invest_dislike
			who = FROM
		}

		FROM = {
			show_scope_change = no

			tooltip = {
				add_trait = excommunicated
			}

			character_event = {
				id = 38022 # Excommunication
				days = 10
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 1.2
				trait = proud
			}

			mult_modifier = {
				factor = 1.2
				trait = envious
			}

			mult_modifier = {
				factor = 1.5
				trait = crusader
			}

			mult_modifier = {
				factor = 1.5
				trait = ambitious
			}

			mult_modifier = {
				factor = 3
				trait = zealous
			}

			mult_modifier = {
				factor = 3

				opinion = {
					who = FROM
					value < 0
				}
			}
		}
	}

	after = {
		character_event = {
			id = 67009
			years = 1
			random = 1155 # 3 years, 2 months
		}
	}
}

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

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA67004

		tooltip = {
			transfer_scaled_wealth = {
				from = FROM
				value = 1
				min = 200
				max = 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
	}
}

# Pope demand tombola
character_event = {
	id = 67009

	is_triggered_only = yes
	hide_window = yes

	has_character_flag = pope_currently_demanding
	prisoner = no
	only_capable = yes
	war = no

	trigger = {
		controls_religion = yes
		is_catholic_branch = yes

		event_target:target_ruler = {
			any_demesne_title = {
				has_law = investiture_law_1
			}

			has_character_flag = pope_we_refuse_law_changed
			higher_real_tier_than = DUKE
			religion = ROOT
			rightful_religious_head = ROOT
		}
	}

	fail_trigger_effect = {
		if = {
			limit = {
				has_character_flag = pope_currently_demanding
				controls_religion = yes

				event_target:target_ruler = {
					any_demesne_title = {
						has_law = investiture_law_1
					}

					has_character_flag = pope_we_refuse_law_changed
					higher_real_tier_than = DUKE
					religion = ROOT
					rightful_religious_head = ROOT
				}
			}

			repeat_event = {
				id = 67009
				months = 2
			}
		}
		else = {
			clr_character_flag = pope_currently_demanding

			event_target:target_ruler = {
				clr_character_flag = pope_we_refuse_law_changed
			}
		}
	}

	immediate = {
		random_list = {
			1 = {
				repeat_event = {
					id = 67009
					years = 1
					random = 1155 # 3 years, 2 months
				}
			}

			50 = { # The Pope sends a delegate to a Bishop whose top liege has refused to change investiture Law
				trigger = {
					wealth >= 20

					event_target:target_ruler = {
						any_realm_lord = {
							is_theocracy = yes
							religion = ROOT
							NOT = { has_character_flag = pope_bribing }
						}
					}
				}

				mult_modifier = {
					factor = 4
					trait = zealous
				}

				character_event = { id = 67010 }

				repeat_event = {
					id = 67009
					years = 1
					random = 1155 # 3 years, 2 months
				}
			}

			50 = {
				trigger = {
					event_target:target_ruler = {
						any_realm_lord = {
							higher_real_tier_than = COUNT
							religion = ROOT
							relative_power_to_liege >= 0.05
							NOT = { has_character_flag = pope_vassal_approached }
						}
					}
				}

				mult_modifier = {
					factor = 4
					trait = ambitious
				}

				character_event = { id = 67020 }
			}
		}
	}
}

# 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

	is_triggered_only = yes

	option = {
		name = EVTOPTA67010

		event_target:target_ruler = {
			show_scope_change = no

			random_realm_lord = {
				show_scope_change = no

				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

		clr_character_flag = pope_currently_demanding

		event_target:target_ruler = {
			clr_character_flag = pope_we_refuse_law_changed
		}

		ai_chance = { factor = 0 }
	}
}

# 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

		transfer_scaled_wealth = {
			from = FROM
			value = 1
			min = 20
			max = 20
		}

		opinion = {
			name = bishop_bribed_by_pope
			who = FROM
			years = 5
		}

		random = {
			chance = 33

			top_liege = {
				show_scope_change = no

				character_event = {
					id = 67012
					days = 14
					tooltip = EVTTOOLTIP67012
				}
			}
		}

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 0.1

				opinion = {
					who = top_liege
					value >= 75
				}
			}
		}
	}

	option = {
		name = EVTOPTB67011

		prestige = 1

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 1.5

				opinion = {
					who = top_liege
					value >= 20
				}
			}

			mult_modifier = {
				factor = 2

				opinion = {
					who = top_liege
					value >= 40
				}
			}

			mult_modifier = {
				factor = 4

				opinion = {
					who = top_liege
					value >= 60
				}
			}

			mult_modifier = {
				factor = 100

				opinion = {
					who = top_liege
					value >= 90
				}
			}
		}
	}
}

# 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 = {
			name = opinion_dishonorable
			who = FROM
			years = 5
		}
	}
}

# 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

	is_triggered_only = yes

	option = {
		name = EVTOPTA67020

		clr_character_flag = pope_currently_demanding

		event_target:target_ruler = {
			show_scope_change = no

			random_realm_lord = {
				show_scope_change = no

				limit = {
					higher_real_tier_than = COUNT
					religion = ROOT
					relative_power_to_liege >= 0.05
					NOT = { has_character_flag = pope_vassal_approached }
				}

				set_character_flag = pope_vassal_approached

				character_event = {
					id = 67021
					days = 14
					tooltip = EVTTOOLTIP67021
				}
			}
		}
	}

	option = {
		name = EVTOPTB67020

		clr_character_flag = pope_currently_demanding

		event_target:target_ruler = {
			clr_character_flag = pope_we_refuse_law_changed
		}

		ai_chance = { factor = 0 }
	}
}

# 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 = {
			name = bishop_bribed_by_pope
			who = FROM
			years = 5
		}

		piety = 10
		add_pressed_claim = top_liege

		random = {
			chance = 33

			top_liege = {
				show_scope_change = no

				character_event = {
					id = 67022
					days = 14
					tooltip = EVTTOOLTIP67022
				}
			}
		}

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 0.1

				opinion = {
					who = top_liege
					value >= 75
				}
			}
		}
	}

	option = {
		name = EVTOPTB67021

		piety = -20

		opinion = {
			name = loyal_vassal_against_pope
			who = top_liege
			years = 5
		}

		ai_chance = {
			factor = 1

			trigger = {
				opinion = {
					who = top_liege
					value >= 50
				}
			}

			mult_modifier = {
				factor = 2

				opinion = {
					who = top_liege
					value >= 55
				}
			}

			mult_modifier = {
				factor = 4

				opinion = {
					who = top_liege
					value >= 60
				}
			}

			mult_modifier = {
				factor = 100

				opinion = {
					who = top_liege
					value >= 80
				}
			}
		}
	}
}

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 = {
			name = my_vassal_bribed_by_pope
			who = FROM
			years = 5
		}

		reverse_opinion = {
			name = my_vassal_bribed_by_pope
			who = FROM
			years = 5
		}
	}
}