﻿el_landed_tutor_education_trigger = {
	OR = {
		has_trait = education_diplomacy_3
		has_trait = education_diplomacy_4
		has_trait = education_diplomacy_5
		has_trait = education_martial_3
		has_trait = education_martial_4
		has_trait = education_martial_5
		has_trait = education_stewardship_3
		has_trait = education_stewardship_4
		has_trait = education_stewardship_5
		has_trait = education_intrigue_3
		has_trait = education_intrigue_4
		has_trait = education_intrigue_5
		has_trait = education_learning_3
		has_trait = education_learning_4
		has_trait = education_learning_5
	}
}

el_landed_rival_wont_raid_trigger = {
	NOT = {
		has_trait = craven
		has_trait = compassionate
		has_trait = honest
	}
}


el_landed_available_global = {
	OR = {
		el_landed_available_train_knight = yes
		el_landed_available_tutor_child = yes
		el_landed_available_des_nei = yes
		el_landed_available_regale_court = yes
		el_landed_available_imp_dom = yes
		el_landed_available_con_nei = yes
	}
}

el_landed_available_train_knight = {
	any_knight ={
		count > 2
		highest_held_title_tier <= tier_county
		NOT = { has_character_flag = el_wait_to_train_knight }
	}
}

el_landed_available_tutor_child = {
	OR = {
		any_child ={
			count > 0
			age > 6
			age <= 14
			is_courtier_of = root
			is_landed = no
			NOT = { has_character_flag = el_landed_child_had_tutor }				
		}
		any_child = {
			any_child ={
				count > 0
				age > 6
				age <= 14
				is_courtier_of = root
				is_landed = no
				NOT = { has_character_flag = el_landed_child_had_tutor }
			}
		}
		any_courtier = { 
			count > 0
			age > 6
			age <= 14
			is_hostage_of = root
			NOT = { has_character_flag = el_landed_child_had_tutor }
		}
	}
}

el_landed_available_des_nei = {
	OR = {
		any_neighboring_and_across_water_top_liege_realm_owner = {
			count > 0
			NOT = { is_tributary_of = root }
			any_sub_realm_county = {
				NOT = { has_variable = el_landed_des_nei_cournty_already }
				squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
				holder = { 
					NOR = { 
						has_government = nomad_government 
						has_government = herder_government
					} 
				}
			}
		}
		any_neighboring_and_across_water_realm_same_rank_owner = {
			count > 0
			NOT = { is_tributary_of = root }
			any_sub_realm_county = {
				NOT = { has_variable = el_landed_des_nei_cournty_already }
				squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
				holder = { 
					NOR = { 
						has_government = nomad_government 
						has_government = herder_government
					} 
				}
			}
		}
		any_land_neighboring_realm_with_tributaries_owner = {
			count > 0
			NOT = { is_tributary_of = root }
			any_sub_realm_county = {
				NOT = { has_variable = el_landed_des_nei_cournty_already }
				squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
				holder = { 
					NOR = { 
						has_government = nomad_government 
						has_government = herder_government
					} 
				}
			}
		}
		AND = {
			is_independent_ruler = no
			any_sub_realm_county = {
				any_neighboring_county = {
					count > 0
					holder = {
						NOT = { this = root }
						NOT = { is_tributary_of = root }
						NOT = { is_vassal_or_below_of = root }
						NOR = { 
							has_government = nomad_government 
							has_government = herder_government
						} 
						any_sub_realm_county = {
							NOT = { has_variable = el_landed_des_nei_cournty_already }
							squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
						}
					}
				}
			}
		}
	}
	NOT = { has_variable = el_landed_cant_use_des_nei }
}


el_landed_available_regale_court = {
	any_courtier_or_guest = {
		count > 1
		is_adult = yes
	}
	any_county = {
		any_county_province = {
		squared_distance = { target = root.capital_province value < el_squared_distance_camp }
			any_character_in_location = {
				has_government = landless_adventurer_government
				is_travelling = no
				is_at_war = no
				is_ai = yes
				is_in_army = no
				is_incapable = no
				NOT = { has_trait = infirm }
				is_adult = yes
				is_imprisoned = no
				NOT = { has_relation_rival = root }
				is_busy_in_events_unlocalised = no
				domicile.domicile_location = prev
				any_courtier = {
					count > 1
					is_male = yes
					is_adult = yes
				}
				root = {
					NOT = {
						is_target_in_variable_list = {
							name = el_landed_refuted_list
							target = prev
						}
					}
				}
			}
		}
	}
	NOT = { has_variable = el_landed_cant_use_regale_court }
}


el_landed_available_imp_dom = {
	any_realm_province = {
		count > 0
		has_holding_type = city_holding 
		county = { NOT = { has_variable = el_landed_imp_dom_cournty_already } }
		squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
		county.holder = root
	}
	NOT = { has_variable = el_landed_cant_use_imp_dom }
}

el_landed_available_con_nei = {
	NOT = { 
		faith = { 
			has_doctrine_parameter = unreformed
		}
	}
	any_county = {
		any_county_province = {
		squared_distance = { target = root.capital_province value < el_squared_distance_camp }
			any_character_in_location = {
				has_government = landless_adventurer_government
				is_travelling = no
				is_at_war = no
				is_ai = yes
				is_in_army = no
				is_incapable = no
				NOT = { has_trait = infirm }
				is_adult = yes
				is_imprisoned = no
				NOT = { has_relation_rival = root }
				is_busy_in_events_unlocalised = no
				domicile.domicile_location = prev
				faith = root.faith
				root = {
					NOT = {
						is_target_in_variable_list = {
							name = el_landed_refuted_list
							target = prev
						}
					}
				}
			}
		}
	}
	OR = {
		any_neighboring_and_across_water_top_liege_realm_owner = {
			count > 0
			NOT = { is_tributary_of = root }
			exists = capital_province
			NOT = { faith =   root.faith  }
			NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
			highest_held_title_tier  < tier_kingdom
			capital_province = { squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } }
			NOT = { capital_county.faith = root.faith }
			NOT = {
				any_held_title = {
					is_head_of_faith = yes
				}
			}
		}
		any_neighboring_and_across_water_realm_same_rank_owner = {
			count > 0
			NOT = { is_tributary_of = root }
			exists = capital_province
			NOT = { faith =   root.faith  }
			NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
			highest_held_title_tier  < tier_kingdom
			capital_province = { squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } }
			NOT = { capital_county.faith = root.faith }
			NOT = {
				any_held_title = {
					is_head_of_faith = yes
				}
			}
		}
		any_neighboring_and_across_water_top_liege_realm_owner = {
			NOT = { is_tributary_of = root }
			any_sub_realm_county = {
				count > 0
				holder = {
					NOT = { faith =  root.faith  }
					NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
					highest_held_title_tier  < tier_kingdom
					NOT = {
						any_held_title = {
							is_head_of_faith = yes
						}
					}
					capital_province = {
						squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
					}
				}
				NOT = { faith = root.faith }
			}
		}
		any_land_neighboring_realm_with_tributaries_owner = {
			NOT = { is_tributary_of = root }
			any_sub_realm_county = {
				count > 0
				holder = {
					NOT = { faith =  root.faith  }
					NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
					highest_held_title_tier  < tier_kingdom
					NOT = {
						any_held_title = {
							is_head_of_faith = yes
						}
					}
					capital_province = {
						squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
					}
				}
				NOT = { faith = root.faith }
			}
		}
		top_liege ?= {					
			any_sub_realm_county = {
				count > 0
				holder = {
					NOT = { this = root }
					NOT = { this = root.top_liege }
					NOT = { is_vassal_or_below_of = root }
					NOT = { faith =  root.faith  }
					NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
					highest_held_title_tier  < tier_kingdom
					NOT = {
						any_held_title = {
							is_head_of_faith = yes
						}
					}
					capital_province = {
						squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
					}
				}
				NOT = { faith = root.faith }
			}
		}
	}
	NOT = { has_variable = el_landed_cant_use_con_nei }
}

el_landed_available_sup_fac = {
	OR = {
		any_neighboring_and_across_water_top_liege_realm_owner = {
			count > 0
			NOT = { is_tributary_of = root }
			capital_province = { squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } }
			has_targeting_faction = yes
			NOT = { has_character_flag = el_landed_sup_fac_cant_be_sup_fac }
			any_targeting_faction = {
				faction_is_at_war = no
				any_faction_member = {
					count > 0
					NOT = { this = root }
					#is_landed = yes
				}
			}
		}
		any_neighboring_and_across_water_realm_same_rank_owner = {
			count > 0
			NOT = { is_tributary_of = root }
			capital_province = { squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } }
			has_targeting_faction = yes
			NOT = { has_character_flag = el_landed_sup_fac_cant_be_sup_fac }
			any_targeting_faction = {
				faction_is_at_war = no
				any_faction_member = {
					count > 0
					NOT = { this = root }
					#is_landed = yes
				}
			}
		}
		any_land_neighboring_realm_with_tributaries_owner = {
			count > 0
			NOT = { is_tributary_of = root }
			capital_province = { squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } }
			has_targeting_faction = yes
			NOT = { has_character_flag = el_landed_sup_fac_cant_be_sup_fac }
			any_targeting_faction = {
				faction_is_at_war = no
				any_faction_member = {
					count > 0
					NOT = { this = root }
					#is_landed = yes
				}
			}
		}
		top_liege ?= {					
			any_sub_realm_county = {
				count > 0
				holder = {
					NOT = { this = root}
					NOT = { is_tributary_of = root }
					NOT = { is_vassal_or_below_of = root }
					has_targeting_faction = yes
					NOT = { has_character_flag = el_landed_sup_fac_cant_be_sup_fac }
					capital_province = {
						squared_distance = { target = root.capital_province value < el_squared_distance_max_travel } 
					}
					any_targeting_faction = {
						faction_is_at_war = no
						any_faction_member = {
							count > 0
							NOT = { this = root }
							#is_landed = yes
						}
					}
				}
			}
		}
	}
	NOT = { has_variable = el_landed_cant_use_sup_fac }
}



el_landed_available_train_knight_value = {
	scope:second = {
		any_knight ={
			count > 2
			highest_held_title_tier <= tier_county
			NOT = { has_character_flag = el_wait_to_train_knight }
		}
	}
}

el_landed_available_tutor_child_value = {
	scope:second = {
		save_temporary_scope_as = player
	
		OR = {
			any_child ={
				count > 0
				age > 6
				age <= 14
				is_courtier_of = scope:player
				is_landed = no
				NOT = { has_character_flag = el_landed_child_had_tutor }				
			}
			any_child = {
				any_child ={
					count > 0
					age > 6
					age <= 14
					is_courtier_of = scope:player
					is_landed = no
					NOT = { has_character_flag = el_landed_child_had_tutor }
				}
			}
			any_courtier = { 
				count > 0
				age > 6
				age <= 14
				is_hostage_of = scope:player
				NOT = { has_character_flag = el_landed_child_had_tutor }
			}
		}
	}
}

el_landed_available_des_nei_value = {
	scope:second = {
		save_temporary_scope_as = player
	
		OR = {
			any_neighboring_and_across_water_top_liege_realm_owner = {
				count > 0
				NOT = { is_tributary_of = scope:player }
				any_sub_realm_county = {
					NOT = { has_variable = el_landed_des_nei_cournty_already }
					squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
					holder = { 
						NOR = { 
							has_government = nomad_government 
							has_government = herder_government
						} 
					}
				}
			}
			any_neighboring_and_across_water_realm_same_rank_owner = {
				count > 0
				NOT = { is_tributary_of = scope:player }
				any_sub_realm_county = {
					NOT = { has_variable = el_landed_des_nei_cournty_already }
					squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
					holder = { 
						NOR = { 
							has_government = nomad_government 
							has_government = herder_government
						} 
					}
				}
			}
			any_land_neighboring_realm_with_tributaries_owner = {
				count > 0
				NOT = { is_tributary_of = scope:player }
				any_sub_realm_county = {
					NOT = { has_variable = el_landed_des_nei_cournty_already }
					squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
					holder = { 
						NOR = { 
							has_government = nomad_government 
							has_government = herder_government
						} 
					}
				}
			}
			AND = {
				is_independent_ruler = no
				any_sub_realm_county = {
					any_neighboring_county = {
						count > 0
						holder = {
							NOT = { this = scope:player }
							NOT = { is_tributary_of = scope:player }
							NOT = { is_vassal_or_below_of = scope:player }
							NOR = { 
								has_government = nomad_government 
								has_government = herder_government
							} 
							any_sub_realm_county = {
								NOT = { has_variable = el_landed_des_nei_cournty_already }
								squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
							}
						}
					}
				}
			}
		}
		NOT = { has_variable = el_landed_cant_use_des_nei }
	}
}


el_landed_available_regale_court_value = {
	root = {
		any_courtier_or_guest = {
			count > 1
			is_adult = yes
		}
	}
	scope:second = {
			save_temporary_scope_as = player
		
		any_courtier_or_guest = {
			count > 1
			is_adult = yes
		}
		any_county = {
			any_county_province = {
			squared_distance = { target = scope:player.capital_province value < el_squared_distance_camp }
				any_character_in_location = {
					has_government = landless_adventurer_government
					is_travelling = no
					is_at_war = no
					is_ai = yes
					is_in_army = no
					is_incapable = no
					NOT = { has_trait = infirm }
					is_adult = yes
					is_imprisoned = no
					NOT = { has_relation_rival = scope:player }
					is_busy_in_events_unlocalised = no
					domicile.domicile_location = prev
					any_courtier = {
						count > 1
						is_male = yes
						is_adult = yes
					}
					scope:player = {
						NOT = {
							is_target_in_variable_list = {
								name = el_landed_refuted_list
								target = prev
							}
						}
					}
				}
			}
		}
		NOT = { has_variable = el_landed_cant_use_regale_court }
	}
}


el_landed_available_imp_dom_value = {
	scope:second = {
		save_temporary_scope_as = player
	
	any_realm_province = {
		count > 0
		has_holding_type = city_holding 
		county = { NOT = { has_variable = el_landed_imp_dom_cournty_already } }
		squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
		county.holder = scope:player
	}
	NOT = { has_variable = el_landed_cant_use_imp_dom }
	}
}

el_landed_available_con_nei_value = {
	scope:second = {
		save_temporary_scope_as = player
	
	NOT = { 
		faith = { 
			has_doctrine_parameter = unreformed
		}
	}
	faith = root.faith
	any_county = {
		any_county_province = {
		squared_distance = { target = scope:player.capital_province value < el_squared_distance_camp }
			any_character_in_location = {
				has_government = landless_adventurer_government
				is_travelling = no
				is_at_war = no
				is_ai = yes
				is_in_army = no
				is_incapable = no
				NOT = { has_trait = infirm }
				is_adult = yes
				is_imprisoned = no
				NOT = { has_relation_rival = scope:player }
				is_busy_in_events_unlocalised = no
				domicile.domicile_location = prev
				faith = scope:player.faith
				scope:player = {
					NOT = {
						is_target_in_variable_list = {
							name = el_landed_refuted_list
							target = prev
						}
					}
				}
			}
		}
	}
	OR = {
		any_neighboring_and_across_water_top_liege_realm_owner = {
			count > 0
			NOT = { is_tributary_of = scope:player }
			exists = capital_province
			NOT = { faith =   scope:player.faith  }
			NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
			highest_held_title_tier  < tier_kingdom
			capital_province = { squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } }
			NOT = { capital_county.faith = scope:player.faith }
			NOT = {
				any_held_title = {
					is_head_of_faith = yes
				}
			}
		}
		any_neighboring_and_across_water_realm_same_rank_owner = {
			count > 0
			NOT = { is_tributary_of = scope:player }
			exists = capital_province
			NOT = { faith =   scope:player.faith  }
			NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
			highest_held_title_tier  < tier_kingdom
			capital_province = { squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } }
			NOT = { capital_county.faith = scope:player.faith }
			NOT = {
				any_held_title = {
					is_head_of_faith = yes
				}
			}
		}
		any_neighboring_and_across_water_top_liege_realm_owner = {
			NOT = { is_tributary_of = scope:player }
			any_sub_realm_county = {
				count > 0
				holder = {
					NOT = { faith =  scope:player.faith  }
					NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
					highest_held_title_tier  < tier_kingdom
					NOT = {
						any_held_title = {
							is_head_of_faith = yes
						}
					}
					capital_province = {
						squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
					}
				}
				NOT = { faith = scope:player.faith }
			}
		}
		any_land_neighboring_realm_with_tributaries_owner = {
			NOT = { is_tributary_of = scope:player }
			any_sub_realm_county = {
				count > 0
				holder = {
					NOT = { faith =  scope:player.faith  }
					NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
					highest_held_title_tier  < tier_kingdom
					NOT = {
						any_held_title = {
							is_head_of_faith = yes
						}
					}
					capital_province = {
						squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
					}
				}
				NOT = { faith = scope:player.faith }
			}
		}
		top_liege ?= {					
			any_sub_realm_county = {
				count > 0
				holder = {
					NOT = { this = scope:player }
					NOT = { this = scope:player.top_liege }
					NOT = { is_vassal_or_below_of = scope:player }
					NOT = { faith =  scope:player.faith  }
					NOT = { has_character_flag = el_landed_con_nei_cant_be_conv }
					highest_held_title_tier  < tier_kingdom
					NOT = {
						any_held_title = {
							is_head_of_faith = yes
						}
					}
					capital_province = {
						squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
					}
				}
				NOT = { faith = scope:player.faith }
			}
		}
	}
	NOT = { has_variable = el_landed_cant_use_con_nei }
	}
}

el_landed_available_sup_fac_value = {
	scope:second = {
		save_temporary_scope_as = player
	
	OR = {
		any_neighboring_and_across_water_top_liege_realm_owner = {
			count > 0
			NOT = { is_tributary_of = scope:player }
			capital_province = { squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } }
			has_targeting_faction = yes
			NOT = { has_character_flag = el_landed_sup_fac_cant_be_sup_fac }
			any_targeting_faction = {
				faction_is_at_war = no
				any_faction_member = {
					count > 0
					NOT = { this = scope:player }
					#is_landed = yes
				}
			}
		}
		any_neighboring_and_across_water_realm_same_rank_owner = {
			count > 0
			NOT = { is_tributary_of = scope:player }
			capital_province = { squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } }
			has_targeting_faction = yes
			NOT = { has_character_flag = el_landed_sup_fac_cant_be_sup_fac }
			any_targeting_faction = {
				faction_is_at_war = no
				any_faction_member = {
					count > 0
					NOT = { this = scope:player }
					#is_landed = yes
				}
			}
		}
		any_land_neighboring_realm_with_tributaries_owner = {
			count > 0
			NOT = { is_tributary_of = scope:player }
			capital_province = { squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } }
			has_targeting_faction = yes
			NOT = { has_character_flag = el_landed_sup_fac_cant_be_sup_fac }
			any_targeting_faction = {
				faction_is_at_war = no
				any_faction_member = {
					count > 0
					NOT = { this = scope:player }
					#is_landed = yes
				}
			}
		}
		top_liege ?= {					
			any_sub_realm_county = {
				count > 0
				holder = {
					NOT = { this = scope:player}
					NOT = { is_tributary_of = scope:player }
					NOT = { is_vassal_or_below_of = scope:player }
					has_targeting_faction = yes
					NOT = { has_character_flag = el_landed_sup_fac_cant_be_sup_fac }
					capital_province = {
						squared_distance = { target = scope:player.capital_province value < el_squared_distance_max_travel } 
					}
					any_targeting_faction = {
						faction_is_at_war = no
						any_faction_member = {
							count > 0
							NOT = { this = scope:player }
							#is_landed = yes
						}
					}
				}
			}
		}
	}
	NOT = { has_variable = el_landed_cant_use_sup_fac }
	}
}

is_busy_in_events_unlocalised = {
	OR = {
		has_character_flag = is_in_diplomacy_foreign_special_event
		has_character_flag = is_in_diplomacy_family_special_event
		has_character_flag = is_in_diplomacy_majesty_special_event
		has_character_flag = is_in_martial_special_event
		has_character_flag = is_in_stewardship_domain_special_event
		has_character_flag = is_in_stewardship_duty_special_event
		has_character_flag = is_in_stewardship_wealth_special_event
		has_character_flag = is_in_intrigue_special_event
		has_character_flag = is_in_learning_special_event
		has_character_flag = is_in_task_contract_event_chain
	}
}