namespace = Plus

#reserved: Plus.411 to Plus.424
#reserved: Plus.430 to Plus.434

###########################################
# Independence Events
###########################################

### TRIBUTARY EVENTS

# Ruler dies who has tributes
character_event = {
	id = Plus.411
	
	hide_window = yes
	is_triggered_only = yes

	only_independent = yes
	only_playable = yes
	
	trigger = {
		is_playable = yes
		any_tributary = {
			NOR = {
				is_tributary = { type = imperial }
				is_tributary = { type = permanent }
				is_tributary = { type = offmap }
				is_tributary = { type = nomadic }
			}
		}
	}
	
	immediate = {
		current_heir = { save_event_target_as = new_suzerain }
		any_tributary = {
			limit = {
				NOT = { character = event_target:new_suzerain }
				is_tributary = {
					type = forced
				}
			}
			set_character_flag = is_forced_tributary
			character_event = { id = Plus.417 days = 1 } # renew tribute status
		}
		any_tributary = {
			limit = {
				NOT = { character = event_target:new_suzerain }
				OR = {
					is_tributary = { type = voluntary }
					is_tributary = { type = default }
				}
			}
			set_character_flag = is_voluntary_tributary
			character_event = { id = Plus.417 days = 1 } # renew tribute status
		}
		any_tributary = {
			limit = {
				NOT = { character = event_target:new_suzerain }
				is_tributary = { type = protectorate }
			}
			set_character_flag = is_protectorate
			character_event = { id = Plus.417 days = 1 } # renew tribute status
		}
	}
}

# Tribute accepted
character_event = {
	id = Plus.414
	desc = EVTDESC_Plus_414
	picture = GFX_evt_emissary

	is_triggered_only = yes
	
	option = {
		name = EXCELLENT
		clr_character_flag = is_forced_tributary
		clr_character_flag = is_voluntary_tributary
		clr_character_flag = is_protectorate
	}
}

# Tribute refused
character_event = {
	id = Plus.415
	desc = EVTDESC_Plus_415
	picture = GFX_evt_emissary

	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_415
		clr_character_flag = is_forced_tributary
		clr_character_flag = is_voluntary_tributary
		clr_character_flag = is_protectorate
	}
}

# Tributes decide whether or not to break tribute with heir
character_event = {
	id = Plus.417
	desc = EVTDESC_Plus_417
	picture = GFX_evt_emissary
	
	is_triggered_only = yes
	
	trigger = {
		event_target:new_suzerain = {
			ROOT = { NOT = { higher_tier_than = PREV } }
			NOT = { war_with = ROOT }
		}
	}
	
	option = {
		name = EVTOPTA_Plus_417 # Accept tribute status
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.2
				has_character_flag = is_voluntary_tributary
			}
			modifier = {
				factor = 2
				has_character_flag = is_protectorate
			}
			modifier = {
				factor = 3
				war = yes
				is_primary_war_defender = yes
			}
			modifier = {
				factor = 1.5
				event_target:new_suzerain = {
					any_realm_province = { any_neighbor_province = { owner = { same_realm = ROOT } } }
				}
			}
			modifier = {
				factor = 1.5
				trait = craven
			}
			modifier = {
				factor = 1.5
				trait = content
			}
			modifier = {
				factor = 1.5
				trait = humble
			}
			modifier = {
				factor = 2
				event_target:new_suzerain = {
					OR = {
						dynasty = ROOT
						is_allied_with = ROOT
						has_non_aggression_pact_with = ROOT
						is_friend = ROOT
					}
				}
			}
			modifier = {
				factor = 2
				dynasty_head = { character = event_target:new_suzerain}
			}
		}
		if = {
			limit = {
				has_character_flag = is_voluntary_tributary
			}
			event_target:new_suzerain = {
				tooltip = { make_tributary = { who = ROOT tributary_type = voluntary } }
				hidden_tooltip = { character_event = { id = Plus.418 } }
			}
		}
		if = {
			limit = {
				has_character_flag = is_forced_tributary
			}
			event_target:new_suzerain = {
				tooltip = { make_tributary = { who = ROOT tributary_type = forced } }
				hidden_tooltip = { character_event = { id = Plus.418 } }
			}
		}
		if = {
			limit = {
				has_character_flag = is_protectorate
			}
			event_target:new_suzerain = {
				tooltip = { make_tributary = { who = ROOT tributary_type = protectorate } }
				hidden_tooltip = { character_event = { id = Plus.418 } }
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_417 # Break tribute status
		trigger = {
			is_adult = yes
			NOT = { trait = incapable }
			prisoner = no
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0
				event_target:new_suzerain = {
					any_realm_province = { any_neighbor_province = { owner = { same_realm = ROOT } } }
					realm_levy_diff = { who = ROOT value = 5000 }
				}
			}
			modifier = {
				factor = 2
				event_target:new_suzerain = {
					is_rival = ROOT
				}
			}
			modifier = {
				factor = 1.5
				event_target:new_suzerain = {
					NOT = {
						any_realm_province = { any_neighbor_province = { owner = { same_realm = ROOT } } }
					}
				}
			}
			modifier = {
				factor = 1.5
				trait = brave
			}
			modifier = {
				factor = 1.5
				trait = ambitious
			}
			modifier = {
				factor = 1.5
				trait = proud
			}
			modifier = {
				factor = 1.5
				event_target:new_suzerain = { reverse_realm_levy_diff = { who = ROOT value = 10000 } }
			}
			modifier = {
				factor = 1.5
				event_target:new_suzerain = { reverse_realm_levy_diff = { who = ROOT value = 7500 } }
			}
			modifier = {
				factor = 1.5
				event_target:new_suzerain = { reverse_realm_levy_diff = { who = ROOT value = 5000 } }
			}
			modifier = {
				factor = 1.25
				event_target:new_suzerain = { reverse_realm_levy_diff = { who = ROOT value = 1000 } }
			}
			modifier = {
				factor = 0.5
				event_target:new_suzerain = { realm_levy_diff = { who = ROOT value = 5000 } }
			}
			modifier = {
				factor = 0.5
				event_target:new_suzerain = { realm_levy_diff = { who = ROOT value = 7500 } }
			}
			modifier = {
				factor = 0.5
				event_target:new_suzerain = { realm_levy_diff = { who = ROOT value = 10000 } }
			}
		}
		event_target:new_suzerain = {
			character_event = { id = Plus.419 tooltip = BREAK_TRIBUTE_STATUS }
		}
	}
}

# Former tribute offers to become tribute of heir
character_event = {
	id = Plus.418
	desc = EVTDESC_Plus_418
	picture = GFX_evt_emissary
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_418 # Accept tribute
		if = {
			limit = { FROM = { has_character_flag = is_voluntary_tributary } }
			make_tributary = { who = FROM tributary_type = voluntary }
		}
		if = {
			limit = { FROM = { has_character_flag = is_forced_tributary } }
			make_tributary = { who = FROM tributary_type = forced }
		}
		if = {
			limit = { FROM = { has_character_flag = is_protectorate } }
			make_tributary = { who = FROM tributary_type = protectorate }
		}
		FROM = {
			hidden_tooltip = { character_event = { id = Plus.414 } }
		}
	}
	option = {
		name = EVTOPTB_Plus_418 # Refuse tribute
		trigger = { ai = no }
		FROM = {
			character_event = { id = Plus.415 tooltip = REFUSE_TRIBUTE_STATUS }
		}
	}
}

# Former tribute refuses to become tribute of heir
character_event = {
	id = Plus.419
	desc = EVTDESC_Plus_419
	picture = GFX_evt_emissary

	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_416 # Let them go
		ai_chance = {
			factor = 50
			modifier = {
				factor = 2
				FROM = { has_character_flag = is_protectorate }
			}
			modifier = {
				factor = 1.2
				FROM = { has_character_flag = is_voluntary_tributary }
			}
			modifier = {
				factor = 3
				war = yes
			}
			modifier = {
				factor = 2
				NOT = { any_realm_province = { any_neighbor_province = { owner = { same_realm = FROM } } } }
			}
			modifier = {
				factor = 2
				reverse_realm_levy_diff = { who = FROM value = 100 }
			}
			modifier = {
				factor = 2
				reverse_realm_levy_diff = { who = FROM value = 2500 }
			}
			modifier = {
				factor = 1.25
				trait = patient
			}
			modifier = {
				factor = 1.25
				trait = humble
			}
			modifier = {
				factor = 1.25
				trait = content
			}
			modifier = {
				factor = 1.25
				trait = kind
			}
			modifier = {
				factor = 1.25
				trait = craven
			}
		}
		opinion = { who = FROM modifier = opinion_outraged years = 10 }
		FROM = {
			clr_character_flag = is_forced_tributary
			clr_character_flag = is_voluntary_tributary
			clr_character_flag = is_protectorate
		}
	}
	option = {
		name = EVTOPTB_Plus_416 # Attack them
		trigger = {
			FROM = { NOT = { higher_tier_than = ROOT } }
			FROM = { NOT = { has_character_flag = is_protectorate } }
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.5
				realm_levy_diff = { who = FROM value = 2500 }
			}
			modifier = {
				factor = 1.5
				realm_levy_diff = { who = FROM value = 5000 }
			}
			modifier = {
				factor = 2
				realm_levy_diff = { who = FROM value = 10000 }
			}
			modifier = {
				factor = 0
				reverse_realm_levy_diff = { who = FROM value = 5000 }
			}
			modifier = {
				factor = 1.25
				trait = wroth
			}
			modifier = {
				factor = 1.25
				trait = proud
			}
			modifier = {
				factor = 1.25
				trait = ambitious
			}
			modifier = {
				factor = 0.5
				NOT = { any_realm_province = { any_neighbor_province = { owner = { same_realm = FROM } } } }
			}
		}
		FROM = {
			clr_character_flag = is_forced_tributary
			clr_character_flag = is_voluntary_tributary
		}
		set_character_flag = trying_to_gain_tributary
		war = {
			target = FROM
			casus_belli = tributary_cb
		}
		clr_character_flag = trying_to_gain_tributary
	}
}

# Ruler steps down peacefully - tributes automatically transfer
character_event = {
	id = Plus.420
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = { has_character_flag = is_voluntary_tributary }
			event_target:abdicate_heir = { make_tributary = { who = ROOT tributary_type = voluntary } }
		}
		if = {
			limit = { has_character_flag = is_forced_tributary }
			event_target:abdicate_heir = { make_tributary = { who = ROOT tributary_type = forced } }
		}
		if = {
			limit = { has_character_flag = is_protectorate }
			event_target:abdicate_heir = { make_tributary = { who = ROOT tributary_type = protectorate } }
		}
		clr_character_flag = is_voluntary_tributary
		clr_character_flag = is_forced_tributary
		clr_character_flag = is_protectorate
	}
}

### INDEPENDENCE EVENTS

character_event = {
	id = Plus.430 #formerly 1000182684
	desc = "EVTDESC_Plus_430"
	picture = "GFX_evt_council"
	
	is_triggered_only = yes
	
	only_rulers = yes
	is_patrician = no

	trigger = {	
		#non-rebelling landed count+ with an independent liege
		independent = no
		is_nomadic = no
		liege = { independent = yes }
		num_of_count_titles = 1
		in_revolt = no
		NOT = { trait = pf_rebel }
		
		#who is not their de jure liege
		NOT = {
			liege = {
				ROOT = {
					primary_title = { de_jure_liege_or_above = PREVPREV }
				}
			}
		}
		
		#and who is either isolated from their liege, not subject to crown law, has Autonomous Vassals, or their liege is a Duke
		OR = {
			NOT = { any_demesne_province = { has_province_flag = contingent_territory } }
			liege = { capital_scope = { ROOT = { capital_scope = { distance = { where = PREVPREV value = 400 } } } } }
			NOT = { crownlaw_title = { always = yes } }
			crownlaw_title = { has_law = crown_authority_0 }
			liege = { lower_real_tier_than = king }
		}
	}

	option = {
		name = "EVTOPTA_Plus_430" # Declare independence
		trigger = {
			prisoner = no
			is_adult = yes
			NOT = { trait = incapable }
		}
		ai_chance = {
			factor = 4
			modifier = {
				factor = 0
				liege = {
					current_heir = { character = ROOT }
				}
			}
			modifier = {
				factor = 5
				any_allied_character = {
					independent = yes
					is_ruler = yes
					NOT = { same_realm = ROOT }
					ROOT = { de_jure_liege_or_above = PREV }
				}
			}
			modifier = {
				factor = 5
				trait = ambitious
			}
			modifier = {
				factor = 5
				liege = { primary_title = { is_titular = yes } }
			}			
			modifier = {
				factor = 25
				in_faction = faction_separatist
			}
			modifier = {
				factor = 4
				tier = KING
			}
			modifier = {
				factor = 2
				liege = {
					NOT = { religion = ROOT }
				}
			}
			modifier = {
				factor = 15
				liege = {
					NOT = { religion_group = ROOT }
				}
			}
			modifier = {
				factor = 1.5
				liege = {
					NOT = { culture_group = ROOT }
				}
			}
			modifier = {
				factor = 1.5
				liege = {
					NOT = { culture = ROOT }
				}
			}
			modifier = {
				factor = 0.50
				any_demesne_province = {
					any_neighbor_province = {
						owner = {
							top_liege = {
								realm_levy_diff = { who = ROOT value = 1000 }
								OR = {
									NOT = { religion_group = ROOT }
									is_heresy_of = ROOT
									is_parent_religion = ROOT
								}
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.50
				any_demesne_province = {
					any_neighbor_province = {
						owner = {
							top_liege = {
								realm_levy_diff = { who = ROOT value = 2500 }
								OR = {
									NOT = { religion_group = ROOT }
									is_heresy_of = ROOT
									is_parent_religion = ROOT
								}
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.25
				any_demesne_province = {
					any_neighbor_province = {
						owner = {
							top_liege = {
								realm_levy_diff = { who = ROOT value = 5000 }
								OR = {
									NOT = { religion_group = ROOT }
									is_heresy_of = ROOT
									is_parent_religion = ROOT
								}
							}
						}
					}
				}
			}
			modifier = {
				factor = 25
				trait = lunatic
			}
			modifier = {
				factor = 0.10
				trait = possessed
				has_character_modifier = voice_of_jesus
			}
			modifier = {
				factor = 30
				trait = possessed
				has_character_modifier = voice_of_satan
			}
			modifier = {
				factor = 15
				trait = possessed
				NOT = { has_character_modifier = voice_of_jesus }
				NOT = { has_character_modifier = voice_of_satan }
			}			
		}
		liege = {
			hidden_tooltip = {
				if = {
					limit = { NOT = { trait = depressed } }
					character_event = { id = Plus.431 }
				}
			}
		}
		set_defacto_liege = ROOT
		pf_liege_change_effect = yes
	}
	option = {
		name = "EVTOPTB_Plus_430" # Remain loyal
		ai_chance = {
			factor = 25
			modifier = {
				factor = 15
				trait = content
			}
			modifier = {
				factor = 5
				liege = { primary_title = { is_titular = no } }
			}						
			modifier = {
				factor = 5
				trait = slothful
			}	
			modifier = {
				factor = 2
				trait = infirm
			}				
			modifier = {
				factor = 10
				liege = {
					has_landed_title = e_hre
					trait = crowned_by_pope
				}
			}
			modifier = {
				factor = 20
				liege = { is_close_relative = ROOT }
			}
			modifier = {
				factor = 10
				liege = { dynasty = ROOT }
			}
			modifier = {
				factor = 10
				liege = {
					OR = {
						is_allied_with = ROOT
						has_non_aggression_pact_with = ROOT
					}
				}
			}			
			modifier = {
				factor = 0.2
				NOT = { opinion = { who = liege value = -100 } }
			}
			modifier = {
				factor = 0.4
				NOT = { opinion = { who = liege value = -75 } }
			}
			modifier = {
				factor = 0.6
				NOT = { opinion = { who = liege value = -50 } }
			}
			modifier = {
				factor = 0.8
				NOT = { opinion = { who = liege value = -25 } }
			}
			modifier = {
				factor = 3
				opinion = { who = liege value = 25 }
			}
			modifier = {
				factor = 6
				opinion = { who = liege value = 50 }
			}
			modifier = {
				factor = 12
				opinion = { who = liege value = 75 }
			}
			modifier = {
				factor = 24
				opinion = { who = liege value = 100 }
			}
			modifier = {
				factor = 100
				trait = zealous
				liege = {
					OR = {
						controls_religion = yes
						ROOT = { rightful_religious_head = PREV }
					}
					religion = ROOT
				}
			}
			modifier = {
				factor = 25
				NOT = { trait = zealous }
				liege = {
					OR = {
						controls_religion = yes
						ROOT = { rightful_religious_head = PREV }
					}
					religion = ROOT
				}
			}
			modifier = {
				factor = 10
				is_heretic = no
				liege = {
					is_heretic = no
					religion_group = ROOT
				}
			}
			modifier = {
				factor = 0
				uses_decadence = yes
				liege = {
					uses_decadence = yes
					NOT = { decadence = 100 }
					decadence = 80
				}
			}				
			modifier = {
				factor = 0.3
				uses_decadence = yes
				liege = {
					uses_decadence = yes
					NOT = { decadence = 80 }
					decadence = 60
				}
			}				
			modifier = {
				factor = 0.6
				uses_decadence = yes
				liege = {
					uses_decadence = yes
					NOT = { decadence = 60 }
					decadence = 40
				}
			}				
			modifier = {
				factor = 0.8
				uses_decadence = yes
				liege = {
					uses_decadence = yes
					NOT = { decadence = 40 }
					decadence = 25
				}
			}			
			modifier = {
				factor = 2
				uses_decadence = yes
				liege = {
					uses_decadence = yes
					NOT = { decadence = 20 }
					decadence = 15
				}
			}	
			modifier = {
				factor = 4
				uses_decadence = yes
				liege = {
					uses_decadence = yes
					NOT = { decadence = 15 }
					decadence = 10
				}
			}
			modifier = {
				factor = 8
				uses_decadence = yes
				liege = {
					uses_decadence = yes
					NOT = { decadence = 10 }
					decadence = 5
				}
			}
			modifier = {
				factor = 16
				uses_decadence = yes
				liege = {
					uses_decadence = yes
					NOT = { decadence = 5 }
					decadence = 0
				}
			}
			modifier = {
				factor = 0.75
				liege = {
					OR = {
						trait = tyrant1
						trait = tyrant2
						trait = tyrant3
						trait = tyrant4
						trait = tyrant5
					}
				}
			}
			modifier = {
				factor = 0.50
				liege = {
					OR = {
						trait = tyrant6
						trait = tyrant7
						trait = tyrant8
						trait = tyrant9
						trait = tyrant10
					}
				}
			}
			modifier = {
				factor = 0.25
				liege = {
					OR = {
						trait = tyrant11
						trait = tyrant12
						trait = tyrant13
						trait = tyrant14
						trait = tyrant15
					}
				}
			}
			modifier = {
				factor = 0.10
				liege = {
					OR = {
						trait = tyrant16
						trait = tyrant17
						trait = tyrant18
						trait = tyrant19
						trait = tyrant20
					}
				}
			}
			modifier = {
				factor = 10
				OR = {
					in_faction = faction_court
					leads_faction = faction_court
				}
			}
		}
	}
}

character_event = {
	id = Plus.431 #formerly 1000182685
	desc = "EVTDESC_Plus_431"
	picture = "GFX_evt_council"
	
	is_triggered_only = yes

	option = {
		name = "EVTOPTA_Plus_431" #Oh no!
		opinion = {
			modifier = opinion_independent
			who = FROM
			years = 50
		}
		random_list = {
			25 = { add_trait = stressed }
			75 = { }
		}
	}
}

