grant_imperial_court = {
	category = emperor


	require_acceptance = no 

	is_visible = {
		is_emperor = yes
		NOT = {
			FROM = {
				OR = {
					has_country_flag = GE_HRE_Imperial_Court
					has_country_flag = GE_HRE_Imperial_Marshall
				}
			}
		}
		FROM = {
			is_part_of_hre = yes
		}
		NOT = {
			any_country = {
				has_country_flag = GE_HRE_Imperial_Court
			}
		}
	}
	is_allowed = {
		is_emperor = yes
		NOT = {
			FROM = {
				OR = {
					has_country_flag = GE_HRE_Imperial_Court
					has_country_flag = GE_HRE_Imperial_Marshall
				}
			}
		}
		FROM = {
			is_part_of_hre = yes
		}
	}
	on_accept = {
		FROM = {
			set_country_flag = GE_HRE_Imperial_Court
			country_event = {
				id = GE_privileges.13
			}
		}
		ROOT = {
			add_ruler_modifier = {
				name = GE_HRE_Emperor_has_Judge
				duration = -1
			}
			if = {
				limit = {
					NOT = {
						ai = yes
					}
				}
				add_imperial_influence = -5
			}
		}
	}
	on_decline = {
	}

	ai_acceptance = { # This works similarly to variable_arithmetic_trigger, but does not support triggers generally. Instead, "limit" will be evaluated first and the rest ignored if it isn't passed.
	}

	ai_will_do = { # this is a trigger
		FROM = {
			calc_true_if = {
				is_elector = yes
				any_ally = {
					tag = ROOT
				}
				marriage_with = ROOT
				ROOT = {				
					has_opinion = {
						who = FROM
						value = 200
					}
				}
				amount = 3
			}
		}
	}
}

cancel_imperial_court =  {
	category = emperor
	require_acceptance = no
	is_visible = {
		is_emperor = yes
		FROM = {
			has_country_flag = GE_HRE_Imperial_Court
		}
	}
	is_allowed = {
		is_emperor = yes
		FROM = {
			has_country_flag = GE_HRE_Imperial_Court
		}
	}
	on_accept = {
		FROM = {
			clr_country_flag = GE_HRE_Imperial_Court
			country_event = {
				id = GE_privileges.14
			}
		}
	}
	ai_will_do = {
		OR = {
			FROM = {
				NOT = {
					calc_true_if = {
						is_elector = yes
						any_ally = {
							tag = ROOT
						}
						marriage_with = ROOT
						ROOT = {				
							has_opinion = {
								who = FROM
								value = 200
							}
						}
						amount = 3
					}
				}
			}
			ROOT = {
				NOT = {
					has_ruler_modifier = GE_HRE_Emperor_has_Judge
				}
			}
		}
	}
}

grant_imperial_marshall = {
	category = emperor


	require_acceptance = no 

	is_visible = {
		is_emperor = yes
		NOT = {
			FROM = {
				OR = {
					has_country_flag = GE_HRE_Imperial_Court
					has_country_flag = GE_HRE_Imperial_Marshall
				}
			}
		}
		FROM = {
			is_part_of_hre = yes
		}
		NOT = {
			any_country = {
				has_country_flag = GE_HRE_Imperial_Marshall
			}
		}
	}
	is_allowed = {
		is_emperor = yes
		NOT = {
			FROM = {
				OR = {
					has_country_flag = GE_HRE_Imperial_Court
					has_country_flag = GE_HRE_Imperial_Marshall
				}
			}
		}
		FROM = {
			is_part_of_hre = yes
		}
	}
	on_accept = {
		FROM = {
			set_country_flag = GE_HRE_Imperial_Marshall
			country_event = {
				id = GE_privileges.15
			}
		}
		ROOT = {
			add_ruler_modifier = {
				name = GE_HRE_Emperor_has_Marshall
				duration = -1
			}
			if = {
				limit = {
					NOT = {
						ai = yes
					}
				}
				add_imperial_influence = -5
			}
		}
	}
	on_decline = {
	}

	ai_acceptance = { # This works similarly to variable_arithmetic_trigger, but does not support triggers generally. Instead, "limit" will be evaluated first and the rest ignored if it isn't passed.
	}

	ai_will_do = { # this is a trigger
		FROM = {
			calc_true_if = {
				is_elector = yes
				any_ally = {
					tag = ROOT
				}
				marriage_with = ROOT
				ROOT = {				
					has_opinion = {
						who = FROM
						value = 200
					}
				}
				amount = 3
			}
		}
	}
}

cancel_imperial_marshall =  {
	category = emperor
	require_acceptance = no
	is_visible = {
		is_emperor = yes
		FROM = {
			has_country_flag = GE_HRE_Imperial_Marshall
		}
	}
	is_allowed = {
		is_emperor = yes
		FROM = {
			has_country_flag = GE_HRE_Imperial_Marshall
		}
	}
	on_accept = {
		FROM = {
			clr_country_flag = GE_HRE_Imperial_Marshall
			country_event = {
				id = GE_privileges.16
			}
		}
	}
	ai_will_do = {
		OR = {
			FROM = {
				NOT = {
					calc_true_if = {
						is_elector = yes
						any_ally = {
							tag = ROOT
						}
						marriage_with = ROOT
						ROOT = {				
							has_opinion = {
								who = FROM
								value = 200
							}
						}
						amount = 3
					}
				}
			}
			ROOT = {
				NOT = {
					has_ruler_modifier = GE_HRE_Emperor_has_Marshall
				}
			}
		}
	}
}