##########################################
# COUNCILLOR TITLES
##########################################

#	attribute: This attribute is added to the ruler's for governance purposes
#	viceroy: This is the Viceroy title for de jure Kingdoms
#	allow: conditions for the character to hold the title
#	gain_effect: fires when the title is granted
#	lose_effect: fires when a title is lost through most causes
#	retire_effect: fires when a title is lost due to the character stepping down, or getting a different liege
#	death_effect: fires when a title is lost due to the character dying
#	The other fields are all character modifiers

#	ROOT is councillor
#	FROM is liege

# NOTE: Plus has a different implementation of safe guards for negative opinion effect when swapping councillors. I'm keeping our version.

job_chancellor = {
	is_chancellor = yes
	is_voter = yes
	lift_fow = yes

	attribute = diplomacy
	dignity = 0.33
	opinion_effect = 10

	monthly_salary = 0.2
	monthly_prestige = 0.75
	#2.6: vanilla went from .015 to .75 for all non-spymaster jobs (except spiritual, which is .5)
	#Plus value was .025 so a buff that dramatic seemed worth updating

	action = action_statecraft			# Offmap, Monks and Mystics
	action = action_improve_relations
	action = action_fabricate_claims
	action = action_clan_sentiment		# Replaces Fabricate Claims for Nomads
	action = action_sow_dissent

	allow = {
		can_be_chancellor_trigger = yes
	}

	dismiss_trigger = {
		show_only_failed_conditions = yes

		trigger_if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			OR = {
				is_incapable = yes
				is_inaccessible_trigger = yes
			}
		}

		custom_tooltip = {
			text = not_changing_council_spot_tt
			NOT = { has_character_flag = is_moving_councillor }
		}
	}

	gain_effect = {
		remove_opinion = { who = FROM name = opinion_fired_from_council }
		remove_opinion = { who = FROM name = opinion_recently_fired }

		if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			opinion = {
				name = grateful_council_term
				who = FROM
				years = 1
			}
		}
	}

	lose_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = {
				NOR = {
					has_character_flag = is_moving_councillor
					has_character_flag = given_title
				}

				is_incapable = no
			}

			opinion = { who = FROM name = opinion_fired_from_council }
			opinion = { who = FROM name = opinion_recently_fired }
		}

		clr_character_flag = is_moving_councillor
		clr_character_flag = given_title

		remove_opinion = {
			name = grateful_council_term
			who = FROM
		}

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}
	}

	retire_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}

		if = {
			limit = {
				practical_age < 65
				health >= 3
				is_sick_or_injured_trigger = no
				can_be_councilmember_king_trigger = yes
			}

			reverse_opinion = {
				name = opinion_resigned_from_council
				who = FROM
			}
		}
	}
}

# NOTE: The allow trigger for this job also determines who can command armies!
job_marshal = {
	is_marshal = yes
	is_voter = yes
	lift_fow = yes

	attribute = martial
	dignity = 0.33
	opinion_effect = 10

	monthly_salary = 0.2
	monthly_prestige = 0.75

	action = action_organize_army			# Offmap, Monks and Mystics
	action = action_assist_arrest
	action = action_train_troops
	action = action_train_troops_nomadic
	action = action_advance_mil_tech
	action = action_organize_raid			# Replaces action_advance_mil_tech for Tribes

	allow = {
		can_be_marshal_trigger = yes
	}

	dismiss_trigger = {
		show_only_failed_conditions = yes

		trigger_if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			OR = {
				is_incapable = yes
				is_inaccessible_trigger = yes
			}
		}

		custom_tooltip = {
			text = not_changing_council_spot_tt
			NOT = { has_character_flag = is_moving_councillor }
		}
	}

	gain_effect = {
		remove_opinion = { who = FROM name = opinion_fired_from_council }
		remove_opinion = { who = FROM name = opinion_recently_fired }

		if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			opinion = {
				name = grateful_council_term
				who = FROM
				years = 1
			}
		}

		if = {
			limit = {
				FROM = {
					has_law = succ_byzantine_elective

					any_courtier_or_vassal = {
						# Check if any other vassal or courtier has higher martial than current character
						attribute_diff = {
							character = ROOT
							attribute = martial
							value > 5
						}

						# Check that said vassal or courtier would be a viable marshal
						can_be_marshal_trigger = yes
					}
				}
			}

			if = {
				limit = { martial < 2 }

				FROM = {
					change_variable = {
						which = byzantine_credibility_appointed_sycophant
						value = -10
					}
				}
			}
			else_if = {
				limit = { martial < 4 }

				FROM = {
					change_variable = {
						which = byzantine_credibility_appointed_sycophant
						value = -5
					}
				}
			}
			else_if = {
				limit = { martial < 6 }

				FROM = {
					change_variable = {
						which = byzantine_credibility_appointed_sycophant
						value = -4
					}
				}
			}
			else_if = {
				limit = { martial < 8 }

				FROM = {
					change_variable = {
						which = byzantine_credibility_appointed_sycophant
						value = -3
					}
				}
			}
			else_if = {
				limit = { martial < 10 }

				FROM = {
					change_variable = {
						which = byzantine_credibility_appointed_sycophant
						value = -2
					}
				}
			}
			else_if = {
				limit = { martial < 12 }

				FROM = {
					change_variable = {
						which = byzantine_credibility_appointed_sycophant
						value = -1
					}
				}
			}
		}
	}

	lose_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = {
				NOR = {
					has_character_flag = is_moving_councillor
					has_character_flag = given_title
				}

				is_incapable = no
			}

			opinion = { who = FROM name = opinion_fired_from_council }
			opinion = { who = FROM name = opinion_recently_fired }

			character_event = {
				id = HFP.20806 # Good Byzantine Marshal was discharged
				days = 1
			}
		}

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}

		clr_character_flag = is_moving_councillor
		clr_character_flag = given_title

		remove_opinion = {
			name = grateful_council_term
			who = FROM
		}
	}

	retire_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}

		if = {
			limit = {
				practical_age < 65
				health >= 3
				is_sick_or_injured_trigger = no
				can_be_councilmember_king_trigger = yes
			}

			reverse_opinion = {
				name = opinion_resigned_from_council
				who = FROM
			}
		}
	}
}

job_treasurer = {
	is_treasurer = yes
	is_voter = yes
	lift_fow = yes

	attribute = stewardship
	dignity = 0.2
	opinion_effect = 10

	monthly_salary = 0.2
	monthly_prestige = 0.75

	action = action_administer_realm
	action = action_squeeze_peasants
	action = action_collect_tribute			# Replaces action_squeeze_peasants for Nomads
	action = action_settle_tribe			# Replaces action_squeeze_peasants for Tribes
	action = action_oversee_construction
	action = action_advance_eco_tech
	action = action_build_legend			# Replaces action_advance_eco_tech for Tribes

	allow = {
		can_be_treasurer_trigger = yes
	}

	dismiss_trigger = {
		show_only_failed_conditions = yes

		trigger_if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			OR = {
				is_incapable = yes
				is_inaccessible_trigger = yes
			}
		}

		custom_tooltip = {
			text = not_changing_council_spot_tt
			NOT = { has_character_flag = is_moving_councillor }
		}
	}

	gain_effect = {
		remove_opinion = { who = FROM name = opinion_fired_from_council }
		remove_opinion = { who = FROM name = opinion_recently_fired }

		if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			opinion = {
				name = grateful_council_term
				who = FROM
				years = 1
			}
		}
	}

	lose_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = {
				NOR = {
					has_character_flag = is_moving_councillor
					has_character_flag = given_title
				}

				is_incapable = no
			}

			opinion = { who = FROM name = opinion_fired_from_council }
			opinion = { who = FROM name = opinion_recently_fired }
		}

		clr_character_flag = is_moving_councillor
		clr_character_flag = given_title

		remove_opinion = {
			name = grateful_council_term
			who = FROM
		}

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}
	}

	retire_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}

		if = {
			limit = {
				practical_age < 65
				health >= 3
				is_sick_or_injured_trigger = no
				can_be_councilmember_king_trigger = yes
			}

			reverse_opinion = {
				name = opinion_resigned_from_council
				who = FROM
			}
		}
	}
}

job_spymaster = {
	is_spymaster = yes
	is_voter = yes
	lift_neighbor_fow = yes

	attribute = intrigue
	dignity = 0.1
	opinion_effect = 10

	monthly_salary = 0.2
	monthly_prestige = 0.75

	action = action_uncover_plots
	action = action_uncover_plots_offmap	# Replaces action_uncover_plots if mystics is activated.
	action = action_sabotage_province
	action = action_organize_spies
	action = action_study_technology

	allow = {
		can_be_spymaster_trigger = yes
	}

	dismiss_trigger = {
		show_only_failed_conditions = yes

		trigger_if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			OR = {
				is_incapable = yes
				is_inaccessible_trigger = yes
			}
		}

		custom_tooltip = {
			text = not_changing_council_spot_tt
			NOT = { has_character_flag = is_moving_councillor }
		}
	}

	gain_effect = {
		remove_opinion = { who = FROM name = opinion_fired_from_council }
		remove_opinion = { who = FROM name = opinion_recently_fired }

		if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			opinion = {
				name = grateful_council_term
				who = FROM
				years = 1
			}
		}
	}

	lose_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = {
				NOR = {
					has_character_flag = is_moving_councillor
					has_character_flag = given_title
				}

				is_incapable = no
			}

			opinion = { who = FROM name = opinion_fired_from_council }
			opinion = { who = FROM name = opinion_recently_fired }
		}

		clr_character_flag = is_moving_councillor
		clr_character_flag = given_title

		remove_opinion = {
			name = grateful_council_term
			who = FROM
		}

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}
	}

	retire_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}

		if = {
			limit = {
				practical_age < 65
				health >= 3
				is_sick_or_injured_trigger = no
				can_be_councilmember_king_trigger = yes
			}

			reverse_opinion = {
				name = opinion_resigned_from_council
				who = FROM
			}
		}
	}
}

job_spiritual = {
	is_spiritual = yes
	is_voter = yes
	lift_fow = yes

	attribute = learning
	dignity = 0.15
	opinion_effect = 10

	monthly_salary = 0.2
	monthly_piety = 0.5

	action = action_hunt_heretics			# Offmap, Monks and Mystics
	action = action_inquisition
	action = action_advance_cul_tech
	action = action_improve_rel_relations
	action = action_charity
	action = action_build_zeal				# Tribal replacement for 'action_advance_cul_tech'

	allow = {
		can_be_spiritual_trigger = yes
	}

	dismiss_trigger = {
		show_only_failed_conditions = yes

		trigger_if = {
			limit = { FROM = { has_law = council_privileges_1 } }

			OR = {
				NOT = { religion = FROM }
				is_incapable = yes
				is_inaccessible_trigger = yes
			}
		}

		custom_tooltip = {
			text = not_changing_council_spot_tt
			NOT = { has_character_flag = is_moving_councillor }
		}
	}

	gain_effect = {
		remove_opinion = { who = FROM name = opinion_fired_from_council }
		remove_opinion = { who = FROM name = opinion_recently_fired }

		if = {
			limit = { FROM = { has_law = council_privileges_1  } }

			opinion = {
				name = grateful_council_term
				who = FROM
				years = 1
			}
		}
	}

	lose_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = {
				NOR = {
					has_character_flag = is_moving_councillor
					has_character_flag = given_title
				}

				is_incapable = no
			}

			opinion = { who = FROM name = opinion_fired_from_council }
			opinion = { who = FROM name = opinion_recently_fired }
		}

		clr_character_flag = is_moving_councillor
		clr_character_flag = given_title

		remove_opinion = {
			who = FROM
			name = grateful_council_term
		}

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}
	}

	retire_effect = {
		clr_character_flag = assigned_councillor_job # See CK2Plus_councillor_events

		if = {
			limit = { has_character_flag = relic_hunter }
			character_event = { id = MNM.9034 } # Artifact hunter councllior fired/retires ping
		}

		if = {
			limit = {
				practical_age < 65
				health >= 3
				is_sick_or_injured_trigger = no
				can_be_councilmember_king_trigger = yes
			}

			reverse_opinion = {
				name = opinion_resigned_from_council
				who = FROM
			}
		}
	}
}