﻿
# EFFECTS RELATING TO HOLD COURT

clear_court_event_participation = {
	if ={
		limit = {
			is_alive = yes
			has_character_flag = in_court_event
		}
		remove_character_flag = in_court_event
	}
}

apply_hold_court_grace_effect = {
	if = {
		limit = {
			has_dlc_feature = royal_court
			has_royal_court = yes

			#Character fulfills the pre-reqs 
			is_landed = yes
			highest_held_title_tier >= tier_kingdom
			OR = {
				government_has_flag = government_is_feudal
				government_has_flag = government_is_clan
			}
			is_available_adult = yes
			court_grandeur_current_level >= 1
		}
		if = {
			limit = { has_variable = last_hold_court_date }
			remove_variable = last_hold_court_date
		}
		set_variable = {
			name = last_hold_court_date
			value = current_year
		}
	}
}

# hire scope as position
employ_character_as_position_in_current_scope_court_effect = {
	if = {
		limit = {
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = $POSITION$
			}
		}
		#If character isn't already in your court, but a wandering guest, you recruit them
		if = {
			limit = {
				$CHARACTER$ = { is_pool_guest = yes }
			}
			add_courtier = $CHARACTER$
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = $POSITION$
		}
	}
}

# Hire scope in any available position. You must have checked that one exists first!, for example by using can_be_employed_in_any_court_position_trigger!
employ_character_as_any_free_position_effect = {
	hidden_effect = {
		random_list = {
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_physician_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = court_physician_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = master_of_horse_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = master_of_horse_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = master_of_hunt_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = master_of_hunt_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = keeper_of_swans_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = keeper_of_swans_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = travel_leader_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = travel_leader_court_position
				}
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_jester_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = court_jester_court_position
				}				
			}
			#AGOT Disabled
			# 10 = {
			# 	trigger = {
			# 		can_appoint_char_to_court_position = {
			# 			CHAR = $CHARACTER$
			# 			COURT_POS = high_almoner_court_position
			# 		}
			# 	}
			# 	appoint_court_position = {
			# 		recipient = $CHARACTER$
			# 		court_position = high_almoner_court_position
			# 	}				
			# }
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = seneschal_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = seneschal_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_tutor_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = court_tutor_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = cupbearer_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = cupbearer_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = chief_eunuch_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = chief_eunuch_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = antiquarian_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = antiquarian_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = royal_architect_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = royal_architect_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = lady_in_waiting_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = lady_in_waiting_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_poet_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = court_poet_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_musician_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = court_musician_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = bodyguard_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = bodyguard_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = champion_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = champion_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = food_taster_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = food_taster_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = executioner_court_position
					}
				}
				appoint_court_position = {
					recipient = $CHARACTER$
					court_position = executioner_court_position
				}				
			}
			#AGOT Disabled
			# 10 = {
			# 	trigger = {
			# 		can_appoint_char_to_court_position = {
			# 			CHAR = $CHARACTER$
			# 			COURT_POS = garuda_court_position
			# 		}
			# 	}
			# 	appoint_court_position = {
			# 		recipient = $CHARACTER$
			# 		court_position = garuda_court_position
			# 	}				
			# }
		}
	}
}

# Mark a random court position to hire a person in. Use this in the immediate and then employ_character_as_marked_court_position_effect in the option to give proper tooltips about what position you're filling.
mark_court_position_for_employment_effect = {
	hidden_effect = {
		random_list = {
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_physician_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:court_physician_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = master_of_horse_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:master_of_horse_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = master_of_hunt_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:master_of_hunt_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = keeper_of_swans_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:keeper_of_swans_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = travel_leader_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:travel_leader_court_position
				}
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_jester_court_position
					}
					NAND = {
						exists = scope:courtier_given_title
						scope:courtier_given_title = { has_court_position = court_jester_court_position }
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:court_jester_court_position
				}				
			}
			#AGOT Disabled
			# 10 = {
			# 	trigger = {
			# 		can_appoint_char_to_court_position = {
			# 			CHAR = $CHARACTER$
			# 			COURT_POS = high_almoner_court_position
			# 		}
			# 	}
			# 	save_scope_value_as = {
			# 		name = court_position_to_fill
			# 		value = flag:high_almoner_court_position
			# 	}				
			# }
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = seneschal_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:seneschal_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_tutor_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:court_tutor_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = cupbearer_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:cupbearer_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = chief_eunuch_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:chief_eunuch_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = antiquarian_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:antiquarian_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = royal_architect_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:royal_architect_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = lady_in_waiting_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:lady_in_waiting_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_poet_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:court_poet_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = court_musician_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:court_musician_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = bodyguard_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:bodyguard_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = champion_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:champion_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = food_taster_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:food_taster_court_position
				}				
			}
			10 = {
				trigger = {
					can_appoint_char_to_court_position = {
						CHAR = $CHARACTER$
						COURT_POS = executioner_court_position
					}
				}
				save_scope_value_as = {
					name = court_position_to_fill
					value = flag:executioner_court_position
				}				
			}
			#AGOT Disabled
			# 10 = {
			# 	trigger = {
			# 		can_appoint_char_to_court_position = {
			# 			CHAR = $CHARACTER$
			# 			COURT_POS = garuda_court_position
			# 		}
			# 	}
			# 	save_scope_value_as = {
			# 		name = court_position_to_fill
			# 		value = flag:garuda_court_position
			# 	}				
			# }
		}
	}
}

# To be used after mark_court_position_for_employment_effect to fill the position marked in that effect.
employ_character_as_marked_court_position_effect = {
	if = {
		limit = {
			$POSITION$ = flag:court_physician_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = court_physician_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = court_physician_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:master_of_horse_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = master_of_horse_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = master_of_horse_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:master_of_hunt_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = master_of_hunt_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = master_of_hunt_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:keeper_of_swans_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = keeper_of_swans_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = keeper_of_swans_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:travel_leader_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = travel_leader_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = travel_leader_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:court_jester_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = court_jester_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = court_jester_court_position
		}
	}
	#AGOT Disabled
	# else_if = {
	# 	limit = {
	# 		$POSITION$ = flag:high_almoner_court_position
	# 		#Making sure they still can be employed in the position
	# 		can_appoint_char_to_court_position = {
	# 			CHAR = $CHARACTER$
	# 			COURT_POS = high_almoner_court_position
	# 		}
	# 	}
	# 	appoint_court_position = {
	# 		recipient = $CHARACTER$
	# 		court_position = high_almoner_court_position
	# 	}
	# }
	else_if = {
		limit = {
			$POSITION$ = flag:seneschal_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = seneschal_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = seneschal_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:court_tutor_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = court_tutor_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = court_tutor_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:cupbearer_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = cupbearer_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = cupbearer_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:chief_eunuch_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = chief_eunuch_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = chief_eunuch_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:antiquarian_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = antiquarian_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = antiquarian_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:royal_architect_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = royal_architect_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = royal_architect_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:lady_in_waiting_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = lady_in_waiting_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = lady_in_waiting_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:court_poet_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = court_poet_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = court_poet_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:court_musician_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = court_musician_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = court_musician_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:bodyguard_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = bodyguard_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = bodyguard_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:champion_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = champion_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = champion_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:food_taster_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = food_taster_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = food_taster_court_position
		}
	}
	else_if = {
		limit = {
			$POSITION$ = flag:executioner_court_position
			#Making sure they still can be employed in the position
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = executioner_court_position
			}
		}
		appoint_court_position = {
			recipient = $CHARACTER$
			court_position = executioner_court_position
		}
	}
	#AGOT Disabled
	# else_if = {
	# 	limit = {
	# 		$POSITION$ = flag:garuda_court_position
	# 		#Making sure they still can be employed in the position
	# 		can_appoint_char_to_court_position = {
	# 			CHAR = $CHARACTER$
	# 			COURT_POS = garuda_court_position
	# 		}
	# 	}
	# 	appoint_court_position = {
	# 		recipient = $CHARACTER$
	# 		court_position = garuda_court_position
	# 	}
	# }

	#If character isn't already in your court, but a wandering guest, you recruit them
	if = {
		limit = {
			$CHARACTER$ = { is_pool_guest = yes }
		}
		add_courtier = $CHARACTER$
	}
}

replace_existing_position_with_character_in_current_scope_court_effect = {
	if = {
		limit = {
			can_appoint_char_to_court_position = {
				CHAR = $CHARACTER$
				COURT_POS = $POSITION$
			}
		}

		if = {
			limit = {
				any_courtier = {
					has_court_position = $POSITION$
				}
			}
			random_courtier = {
				limit = {
					has_court_position = $POSITION$
				}
				replace_court_position = {
					recipient = $CHARACTER$
					holder = PREV
					court_position = $POSITION$
				}
			}
		}
		else = {
			appoint_court_position = {
				recipient = $CHARACTER$
				court_position = $POSITION$
			}
		}
	}
}

hold_court_queue_next_event_effect = {
	# Sort the widget for next time.
	change_variable = {
		name = petitioner_current_progress
		add = 1
	}
	# Update the widget.
	save_scope_value_as = {
		name = event_chain_progress
		value = var:petitioner_current_progress
	}
	# Trigger the next event along.
	if = {
		limit = { var:num_petitioners = 3 }
		# Reduce the tracking variable by one.
		change_variable = {
			name = num_petitioners
			add = -1
		}
		# Then, trigger an event.
		trigger_event = { on_action = RE_hold_court_event_selection }
	}
	else_if = {
		limit = { 
			var:num_petitioners = 2 
			OR = {
				has_court_type = court_tribal
				is_ai = yes
			}
		}
		# Reduce the tracking variable by one.
		change_variable = {
			name = num_petitioners
			add = -1
		}
		# Then, trigger an event.
		trigger_event = { on_action = hold_court_event_selection }
	}
	else_if = {
		limit = { 
			var:num_petitioners = 2 
		}
		# Reduce the tracking variable by one.
		change_variable = {
			name = num_petitioners
			add = -1
		}
		# Then, trigger an event.
		trigger_event = RE_hold_axis.0001
		trigger_event = { on_action = RE_hold_court_axis_selection }
	}
	else_if = {
		limit = { var:num_petitioners = 1 }
		# Reduce the tracking variable by one.
		change_variable = {
			name = num_petitioners
			add = -1
		}
		# Then, trigger an event.
		trigger_event = { on_action = hold_court_event_selection }
	}
	# Or else remove the empty variable.
	else = { remove_variable = num_petitioners }
}

hold_court_queue_next_event_effect_cut = {
	# Sort the widget for next time.
	change_variable = {
		name = petitioner_current_progress
		add = 1
	}
	# Update the widget.
	save_scope_value_as = {
		name = event_chain_progress
		value = var:petitioner_current_progress
	}
	change_variable = {
		name = num_petitioners
		add = -1
	}
}

RE_remove_court_flags = {
	remove_character_flag = RE_diplo_first_flag
	remove_character_flag = RE_diplo_sec_flag
	remove_character_flag = RE_diplo_tri_flag
	remove_character_flag = RE_mart_first_flag
	remove_character_flag = RE_mart_sec_flag
	remove_character_flag = RE_mart_tri_flag
	remove_character_flag = RE_stew_first_flag
	remove_character_flag = RE_stew_sec_flag
	remove_character_flag = RE_stew_tri_flag
	remove_character_flag = RE_intr_first_flag
	remove_character_flag = RE_intr_sec_flag
	remove_character_flag = RE_intr_tri_flag
	remove_character_flag = RE_lear_first_flag
	remove_character_flag = RE_lear_sec_flag
	remove_character_flag = RE_lear_tri_flag
}

hold_court_queue_post_event_effect = {
	# Sort the ending counter.
	## If there's no ending counter, create one.
	if = {
		limit = {
			NOT = { has_variable = petitioners_dealt_with_count }
		}
		set_variable = {
			name = petitioners_dealt_with_count
			value = 1
		}
	}
	## Else if there is a counter below the total petitioner tally, increment it.
	else_if = {
		limit = { var:petitioners_dealt_with_count < initial_petitioners_value }
		change_variable = {
			name = petitioners_dealt_with_count
			add = 1
		}
	}
	## If appropriate, run the end stuff.
	if = {
		limit = {
			exists = var:petitioners_dealt_with_count
			var:petitioners_dealt_with_count >= initial_petitioners_value
		}
		# Remove the counter.
		remove_variable = petitioners_dealt_with_count
		# Launch into cleanup.
		trigger_event = hold_court.0021
	}
}

# Adds a character flag that is used for all court events so they don't steal characters from each other
court_event_character_flag_effect = {
	add_character_flag = {
		flag = in_court_event
		days = 180
	}
}
