# Arriving at the crusade target
character_event = {
	id = 8305
	desc = "EVTDESC8305"
	picture = "GFX_evt_siege"
	border = GFX_event_normal_frame_war

	min_age = 16
	capable_only = yes
	prisoner = no
	nothing
	in_command = yes
	
	is_triggered_only = yes
	
	trigger = {
		has_called_crusade = yes
		OR = {
			any_war = {
				OR = {
						using_cb = crusade
						using_cb = new_crusade
					}
			}
			any_liege = {
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}
				}
			}
		}

		crusade_target = {
			is_located_in = ROOT
		}
		NOT = { has_character_flag = arrived_at_crusade_target }
		location = {
			holder_scope = {
				NOT = { character = ROOT }
			}
		}
	}
	
	immediate = {
		hidden_tooltip = {
			set_character_flag = arrived_at_crusade_target
		}
	}
	
	option = {
		name = "EXCELLENT"
		prestige = 25
		piety = 25
	}
}

# Pope lifts Excommunication (AI characters only)
character_event = {
	id = 8306
	hide_window = yes

	only_men = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	nothing
	
	is_triggered_only = yes
	
	trigger = {
		controls_religion = yes
		has_called_crusade = yes
		OR = {
			any_independent_ruler = {
				ai = yes
				nothing
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}
				}
				excommunicated_for = ROOT
			}
			any_independent_ruler = {
				nothing
				any_realm_lord = {
					ai = yes
					nothing
					any_war = {
						OR = {
							using_cb = crusade
							using_cb = new_crusade
						}
					}
					excommunicated_for = ROOT
				}
			}
		}
	}
	
	immediate = {
		any_independent_ruler = {
			limit = {
				ai = yes
				nothing
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}
				}
				excommunicated_for = ROOT
			}
			set_character_flag = offered_revoked_excommunication
			letter_event = { id = 8467 days = 1 }
		}
		any_independent_ruler = {
			limit = {
				nothing
			}
			any_realm_lord = {
				limit = {
					ai = yes
					nothing
					any_war = {
						OR = {
							using_cb = crusade
							using_cb = new_crusade
						}
					}
					excommunicated_for = ROOT
				}
				set_character_flag = offered_revoked_excommunication
				letter_event = { id = 8467 days = 1 }
			}
		}
	}
}


### On actions events ###

# Character becomes zealous
# on_battle_won
# FROM = opposing army's owner
character_event = {
	id = 8310
	desc = "EVTDESC8310"
	picture = "GFX_evt_knight_kneeling"
	border = GFX_event_normal_frame_religion
	
	hide_from = yes
	
	min_age = 16
	capable_only = yes
	prisoner = no
	nothing
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { trait = zealous }
		NOT = { trait = cynical }
		
		has_called_crusade = yes
		OR = {
			any_war = {
				OR = {
					using_cb = crusade
					using_cb = new_crusade
				}
			}
			any_liege = {
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}
				}
			}
		}
		crusade_target = {
			is_located_in = ROOT
		}
	}

	option = {
		name = "EXCELLENT"
		add_trait = zealous
	}
}

# Character becomes cynical
# on_battle_lost
# FROM = opposing army's owner
character_event = {
	id = 8320
	desc = "EVTDESC8320"
	picture = "GFX_evt_pale_rider"
	border = GFX_event_normal_frame_war

	min_age = 16
	capable_only = yes
	prisoner = no
	nothing
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { trait = cynical }
		NOT = { trait = zealous }
		
		has_called_crusade = yes
		OR = {
			any_war = {
				OR = {
					using_cb = crusade
					using_cb = new_crusade
				}
			}
			any_liege = {
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}
				}
			}
		}
		crusade_target = {
			is_located_in = ROOT
		}
	}
	
	option = {
		name = "EVTOPTA8320"
		add_trait = cynical
	}
}

# Conquers the crusade target
# on_siege_won_leader
# FROM = barony won
character_event = {
	id = 8330
	desc = EVTDESC8330
	picture = GFX_evt_siege
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		FROM = { is_capital = yes }
#		nothing
		
		has_called_crusade = yes
		OR = {
			any_war = {
				OR = {
					using_cb = crusade
					using_cb = new_crusade
				}
			}
			any_liege = {
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}
				}
			}
		}
		crusade_target = {
			de_jure_vassal_or_below = FROM
		}
	}
	
	option = {
		name = EVTOPTA8330
		prestige = 100
		piety = 100
		hidden_tooltip = {
			set_character_flag = captures_crusade_target
			if = {
				limit = {
					independent = no
				}
				# Only liege
				if = {
					limit = {
						liege = {
							NOT = { character = ROOT }
							any_war = {
								OR = {
									using_cb = crusade
									using_cb = new_crusade
								}
							}
						}
						top_liege = {
							NOT = {
								any_war = {
									OR = {
										using_cb = crusade
										using_cb = new_crusade
									}
								}
							}
						}
					}
					liege = { letter_event = { id = 8331 days = 1 } }
				}
				# Only top liege
				if = {
					limit = {
						liege = {
							NOT = {
								any_war = {
									OR = {
										using_cb = crusade
										using_cb = new_crusade
									}
								}
							}
						}
						top_liege = {
							any_war = {
								OR = {
									using_cb = crusade
									using_cb = new_crusade
								}
							}
						}
					}
					top_liege = { letter_event = { id = 8331 days = 1 } }
				}
				# Both liege and top liege
				if = {
					limit = {
						liege = {
							NOT = { character = ROOT }
							any_war = {
								OR = {
									using_cb = crusade
									using_cb = new_crusade
								}
							}
							ROOT = {
								top_liege = {
									NOT = { character = PREVPREV }
									any_war = {
										OR = {
											using_cb = crusade
											using_cb = new_crusade
										}
									}
								}
							}
						}
					}
					liege = { letter_event = { id = 8331 days = 1 } }
					top_liege = { letter_event = { id = 8331 days = 1 } }
				}
			}
		}
	}
}

# Inform liege of capturing the crusade target
letter_event = {
	id = 8331
	desc = "EVTDESC8331"
	
	is_triggered_only = yes
	
	immediate = {
		abdicate_holy_order_if_religion_changes_effect = yes
	}
	
	option = {
		name = "EXCELLENT"
		if = {
			limit = { NOT = { has_character_flag = captures_crusade_target } }
			prestige = 25
			piety = 25
		}
		set_character_flag = captures_crusade_target
	}
}
# Loses the crusade target's capital
# on_siege_lost_leader
# FROM = barony lost
character_event = {
	id = 8350
	desc = "EVTDESC8350"
	picture = "GFX_evt_siege"
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		FROM = { is_capital = yes }
#		nothing
		OR = {
			any_war = {
				OR = {
					using_cb = crusade
					using_cb = new_crusade
				}
			}
			any_liege = {
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}
				}
			}
		}
		crusade_target = {
			de_jure_vassal_or_below = FROM
		}
	}
	
	option = {
		name = "EVTOPTA8350"
		prestige = -50
		piety = -50
		hidden_tooltip = {
			if = {
				limit = {
					independent = no
				}
				# Only liege
				if = {
					limit = {
						liege = {
							NOT = { character = ROOT }
							any_war = {
								OR = {
									using_cb = crusade
									using_cb = new_crusade
								}
							}
						}
						top_liege = {
							NOT = {
								any_war = {
									OR = {
										using_cb = crusade
										using_cb = new_crusade
									}
								}
							}
						}
					}
					liege = { letter_event = { id = 8351 days = 1 } }
				}
				# Only top liege
				if = {
					limit = {
						liege = {
							NOT = {
								any_war = {
									OR = {
										using_cb = crusade
										using_cb = new_crusade
									}
								}
							}
						}
						top_liege = {
							any_war = {
								OR = {
									using_cb = crusade
									using_cb = new_crusade
								}
							}
						}
					}
					top_liege = { letter_event = { id = 8351 days = 1 } }
				}
				# Both liege and top liege
				if = {
					limit = {
						liege = {
							NOT = { character = ROOT }
							any_war = {
								OR = {
									using_cb = crusade
									using_cb = new_crusade
								}
							}
							ROOT = {
								top_liege = {
									NOT = { character = PREVPREV }
									any_war = {
										OR = {
											using_cb = crusade
											using_cb = new_crusade
										}
									}
								}
							}
						}
					}
					liege = { letter_event = { id = 8351 days = 1 } }
					top_liege = { letter_event = { id = 8351 days = 1 } }
				}
			}
		}
	}
}
