﻿@crown_authority_cooldown_years = 20
@tribal_authority_cooldown_years = 10
@imperial_bureaucracy_cooldown_years_1 = 10
@imperial_bureaucracy_cooldown_years_2 = 20
@imperial_bureaucracy_cooldown_years_3 = 30

@camp_purpose_prestige_cost = 1000
@camp_purpose_ai_will_do_malus_t3 = -30
@camp_purpose_ai_will_do_malus_t2 = -20
@camp_purpose_ai_will_do_malus_t1 = -10
@camp_purpose_ai_will_do_bonus_t1 = 10
@camp_purpose_ai_will_do_bonus_t2 = 20
@camp_purpose_ai_will_do_bonus_t3 = 30

crown_authority = {
	default = crown_authority_1
	cumulative = yes
	flag = realm_law
	
	crown_authority_0 = {
		modifier = {
			barons_and_minor_landholders_opinion = 20
			glory_hound_opinion = 10
			parochial_opinion = 10
			courtly_opinion = 5
		}
		flag = uses_crown_authority

		can_keep = {
			realm_law_use_crown_authority = yes
			trigger_if = {
				limit = {
					has_government = administrative_government
					is_independent_ruler = no
				}
				liege = { has_realm_law = crown_authority_0 }
			}
		}

		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
	
	crown_authority_1 = {
		modifier = {
			barons_and_minor_landholders_opinion = -30
			glory_hound_opinion = -15
			parochial_opinion = -15
			courtly_opinion = -5
			minority_opinion = -10
		}
		flag = uses_crown_authority
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = can_change_partition_succession_laws
		flag = diarchs_want_to_subsidise_without_this_flag

		can_keep = {
			realm_law_use_crown_authority = yes
			trigger_if = {
				limit = {
					has_government = administrative_government
					is_independent_ruler = no
				}
				liege = { has_realm_law = crown_authority_1 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = { has_realm_law = crown_authority_0 }
				custom_description = {
					subject = root
					text = "has_crown_authority_cooldown"
					NAND = {
						has_variable = crown_authority_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
				}
			}
			can_pass_law_ca1_trigger = yes
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOR = {
							has_realm_law = crown_authority_2
							has_realm_law = crown_authority_3
						}
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = crown_authority_cooldown
				years = @crown_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = crown_authority_0 }
				value = 1
			}
		}
	}
	
	crown_authority_2 = {
		modifier = {
			barons_and_minor_landholders_opinion = -10
			glory_hound_opinion = -10
			parochial_opinion = -10
			courtly_opinion = -5
			zealot_opinion = -10
			minority_opinion = -10
			vassal_tax_contribution_mult = 0.1
			vassal_levy_contribution_mult = 0.1
		}
		flag = uses_crown_authority
		flag = vassal_internal_wars_banned
		flag = vassal_refusal_is_treason
		flag = can_change_succession_laws
		flag = titles_cannot_leave_realm_on_succession # Hardcoded flag
		
		can_keep = {
			realm_law_use_crown_authority = yes
			trigger_if = {
				limit = {
					has_government = administrative_government
					is_independent_ruler = no
				}
				liege = { has_realm_law = crown_authority_2 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = crown_authority_3 }
					NAND = {
						has_government = administrative_government
						is_independent_ruler = no
					}
				}
				has_realm_law = crown_authority_1
				custom_description = {
					subject = root
					text = "has_crown_authority_cooldown"
					NAND = {
						has_variable = crown_authority_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
				}
			}
			can_pass_law_ca2_trigger = yes
		}

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law = crown_authority_3 }
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = crown_authority_cooldown
				years = @crown_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = crown_authority_1 }
				value = 1
			}
		}
	}
	
	crown_authority_3 = {
		modifier = {
			barons_and_minor_landholders_opinion = -20
			glory_hound_opinion = -25
			parochial_opinion = -25
			courtly_opinion = -10
			zealot_opinion = -20
			minority_opinion = -30
			vassal_tax_contribution_mult = 0.25
			vassal_levy_contribution_mult = 0.25
		}
		flag = uses_crown_authority
		flag = vassal_all_wars_banned
		flag = can_designate_heirs
		flag = max_authority_level
		
		can_keep = {
			realm_law_use_crown_authority = yes
			trigger_if = {
				limit = {
					has_government = administrative_government
					is_independent_ruler = no
				}
				liege = { has_realm_law = crown_authority_3 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NAND = {
						has_government = administrative_government
						is_independent_ruler = no
					}
				}
				has_realm_law = crown_authority_2
				custom_description = {
					subject = root
					text = "has_crown_authority_cooldown"
					NAND = {
						has_variable = crown_authority_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
				}
			}
			can_pass_law_ca3_trigger = yes
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law = crown_authority_3 }
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = crown_authority_cooldown
				years = @crown_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
}

tribal_authority = {
	default = tribal_authority_1
	cumulative = yes
	flag = realm_law
	
	tribal_authority_0 = {
		modifier = {
			glory_hound_opinion = 10
			parochial_opinion = 10
			courtly_opinion = 5
		}
		flag = uses_tribal_authority
		flag = imprisonment_toggle_enable

		can_keep = { realm_law_use_tribal_authority = yes }
		#Imprisonment is disabled if you have this law. Script is in the interaction, currently in 00_prison_interactions.

		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
	
	tribal_authority_1 = {
		modifier = {
			glory_hound_opinion = -15
			parochial_opinion = -15
			courtly_opinion = -5
			minority_opinion = -10
		}
		flag = uses_tribal_authority
		flag = can_change_succession_laws
		flag = imprisonment_toggle_on

		can_keep = { realm_law_use_tribal_authority = yes }

		can_pass = {
			trigger_if = {
				limit = { has_realm_law = tribal_authority_0 }
				custom_description = {
					subject = root
					text = "has_tribal_authority_cooldown"
					NAND = {
						has_variable = tribal_authority_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
				}
			}
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOR = {
							has_realm_law = tribal_authority_2
							has_realm_law = tribal_authority_3
						}
					}
					add = increase_tribal_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = tribal_authority_cooldown
				years = @tribal_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = tribal_authority_0 }
				value = 1
			}
		}
	}
	
	tribal_authority_2 = {
		modifier = {
			glory_hound_opinion = -10
			parochial_opinion = -10
			courtly_opinion = -5
			zealot_opinion = -10
			minority_opinion = -10
		}
		flag = uses_tribal_authority
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = diarchs_want_to_subsidise_without_this_flag
		
		can_keep = { realm_law_use_tribal_authority = yes }
		
		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = tribal_authority_3 }
				}
				has_realm_law = tribal_authority_1
				custom_description = {
					subject = root
					text = "has_tribal_authority_cooldown"
					NAND = {
						has_variable = tribal_authority_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
				}
			}
		}

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law = tribal_authority_3 }
					}
					add = increase_tribal_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = tribal_authority_cooldown
				years = @tribal_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = tribal_authority_1 }
				value = 1
			}
		}
	}
	
	tribal_authority_3 = {
		modifier = {
			glory_hound_opinion = -25
			parochial_opinion = -25
			courtly_opinion = -10
			zealot_opinion = -20
			minority_opinion = -30
		}
		flag = uses_tribal_authority
		flag = max_authority_level
		#Settling is disabled unless you have this law. Script is in the decisions, currently in 80_major_decisions.
		#Reforming pagan religions (but not creating other faiths) is disabled unless you have this law. Script is in the reformation prereqs, currently in 00_rules.
		
		can_keep = { realm_law_use_tribal_authority = yes }
		
		can_pass = {
			has_realm_law = tribal_authority_2
			custom_description = {
				subject = root
				text = "has_tribal_authority_cooldown"
				NAND = {
						has_variable = tribal_authority_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
			}
		}
		
		pass_cost = { prestige = increase_tribal_authority_prestige_cost }
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = tribal_authority_cooldown
				years = @tribal_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = tribal_authority_2 }
				value = 1
			}
			if = { # Genghis is fundamentally uninterested in settling as feudal, and doesn't care for the additional -20 vassal opinion!
				limit = { has_title = title:e_mongol_empire }
				value = -10
			}
		}
	}
}

camp_purpose = {
	default = camp_purpose_wanderers
	flag = realm_law
	
	camp_purpose_wanderers = {
		flag = uses_camp_purpose
		flag = can_change_succession_laws
		flag = can_change_purpose_for_free
		

		can_keep = { realm_law_use_camp_purpose = yes }

		pass_cost = {
			prestige = @camp_purpose_prestige_cost
		}
		
		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
			# Remove inappropriate buildings.
			laamp_clear_inappropriate_buildings_effect = yes
			# Adjust flavourisation.
			remove_camp_purpose_flavourisation_variables_effect = yes
			set_variable = flavourise_camp_purpose_wanderers
			local_arbitration_boon_set_purpose_effect = {
				MODIFIER = landless_local_arbitration_wanderers_modifier
			}
		}

		ai_will_do = { value = 0 }
	}
	
	camp_purpose_mercenaries = {
		flag = uses_camp_purpose
		flag = can_change_succession_laws
		flag = laamp_contracts_weight_up_mercenary
		flag = laamp_contracts_weight_up_martial
		flag = laamp_contracts_weight_up_prowess
		flag = martial_camp_purpose

		# Camp unlocks.
		flag = unlocks_baggage_train_siege_engineers
		flag = unlocks_proving_grounds_lockwagon
		flag = unlocks_camp_perimeter_palisade
		flag = unlocks_camp_perimeter_ditch

		can_keep = { realm_law_use_camp_purpose = yes }

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law_flag = can_change_purpose_for_free }
					}
					value = @camp_purpose_prestige_cost
				}
			}
		}
		
		modifier = {
			men_at_arms_cap = 1
			embarkation_cost_mult = -0.5
			knight_limit = 8
		}
		
		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
			# Remove inappropriate buildings.
			laamp_clear_inappropriate_buildings_effect = yes
			# Adjust flavourisation.
			remove_camp_purpose_flavourisation_variables_effect = yes
			set_variable = flavourise_camp_purpose_mercenaries
			local_arbitration_boon_set_purpose_effect = {
				MODIFIER = landless_local_arbitration_mercenaries_modifier
			}
		}

		ai_will_do = {
			# Traits.
			## Education.
			if = {
				limit = { has_trait = education_martial }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			## Personality.
			### Cultural traditions
			if = {
				limit = {
					culture = {
						OR = {
							has_cultural_parameter = much_more_likely_to_be_laamps
							has_cultural_parameter = more_likely_to_be_laamps
						}
					}
				}
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Wrathful
			if = {
				limit = { has_trait = wrathful }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Calm
			if = {
				limit = { has_trait = calm }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			### Callous
			if = {
				limit = { has_trait = callous }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Sadistic
			if = {
				limit = { has_trait = sadistic }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Compassionate
			if = {
				limit = { has_trait = compassionate }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			### Brave
			if = {
				limit = { has_trait = brave }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Craven
			if = {
				limit = { has_trait = craven }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				multiply = 0
			}
		}
	}
	
	camp_purpose_scholars = {
		modifier = {
			monthly_lifestyle_xp_gain_mult = 0.2
		}
		flag = uses_camp_purpose
		flag = can_change_succession_laws
		flag = laamp_contracts_weight_up_learning
		flag = laamp_contracts_weight_up_stewardship
		flag = laamp_contracts_weight_up_diplomacy_slight
		flag = nerd_camp_purpose

		# Camp unlocks.
		flag = unlocks_baggage_train_siege_engineers
		flag = unlocks_barber_tent_reference_corpus
		flag = unlocks_barber_tent_morticians_tools
		flag = unlocks_baggage_train_scribes
		flag = unlocks_baggage_train_ascetics
		flag = unlocks_camp_fire_nightly_debates
		flag = unlocks_proving_grounds_martial_study

		can_keep = { realm_law_use_camp_purpose = yes }

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law_flag = can_change_purpose_for_free }
					}
					value = @camp_purpose_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
			# Remove inappropriate buildings.
			laamp_clear_inappropriate_buildings_effect = yes
			# Adjust flavourisation.
			remove_camp_purpose_flavourisation_variables_effect = yes
			set_variable = flavourise_camp_purpose_scholars
			local_arbitration_boon_set_purpose_effect = {
				MODIFIER = landless_local_arbitration_scholars_modifier
			}
		}

		ai_will_do = {
			# Traits.
			## Education.
			if = {
				limit = { has_trait = education_learning }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			if = {
				limit = { has_trait = education_stewardship }
				add = @camp_purpose_ai_will_do_bonus_t1
			}
			## Personality.
			### Honest
			if = {
				limit = { has_trait = honest }
				add = @camp_purpose_ai_will_do_bonus_t1
			}
			### Generous
			if = {
				limit = { has_trait = generous }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Calm
			if = {
				limit = { has_trait = calm }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Wrathful
			if = {
				limit = { has_trait = wrathful }
				add = @camp_purpose_ai_will_do_malus_t2
			}
			### Eccentric
			if = {
				limit = { has_trait = eccentric }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Patient
			if = {
				limit = { has_trait = patient }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Impatient
			if = {
				limit = { has_trait = impatient }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			### Shy
			if = {
				limit = { has_trait = shy }
				add = @camp_purpose_ai_will_do_bonus_t1
			}
			### Gregarious
			if = {
				limit = { has_trait = gregarious }
				add = @camp_purpose_ai_will_do_malus_t1
			}
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				multiply = 0
			}
		}
	}
	
	camp_purpose_explorers = {
		modifier = {
			character_travel_speed_mult = 0.25
			coastal_sea_travel_danger = medium_sea_danger_reduction
			sea_travel_danger = medium_sea_danger_reduction
		}
		flag = uses_camp_purpose
		flag = can_change_succession_laws
		flag = laamp_contracts_weight_up_transport
		flag = laamp_contracts_weight_up_diplomacy
		flag = laamp_contracts_weight_up_intrigue
		flag = laamp_contracts_weight_up_martial_slight

		# Camp unlocks.
		flag = unlocks_supply_tent_reserve_provisions
		flag = unlocks_supply_tent_reserve_water
		flag = unlocks_supply_tent_climbing_gear
		flag = unlocks_camp_fire_local_hangers_on
		flag = unlocks_camp_perimeter_extra_watch

		can_keep = { realm_law_use_camp_purpose = yes }

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law_flag = can_change_purpose_for_free }
					}
					value = @camp_purpose_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
			# Remove inappropriate buildings.
			laamp_clear_inappropriate_buildings_effect = yes
			# Adjust flavourisation.
			remove_camp_purpose_flavourisation_variables_effect = yes
			set_variable = flavourise_camp_purpose_explorers
			local_arbitration_boon_set_purpose_effect = {
				MODIFIER = landless_local_arbitration_explorers_modifier
			}
		}

		ai_will_do = {
			# Traits.
			## Education.
			if = {
				limit = { has_trait = education_diplomacy }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			if = {
				limit = { has_trait = education_stewardship }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			## Personality.
			### Diligent
			if = {
				limit = { has_trait = diligent }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Lazy
			if = {
				limit = { has_trait = lazy }
				add = @camp_purpose_ai_will_do_malus_t2
			}
			### Athletic
			if = {
				limit = { has_trait = athletic }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Brave
			if = {
				limit = { has_trait = brave }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Craven
			if = {
				limit = { has_trait = craven }
				add = @camp_purpose_ai_will_do_malus_t2
			}
			### Eccentric
			if = {
				limit = { has_trait = eccentric }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Stubborn
			if = {
				limit = { has_trait = stubborn }
				add = @camp_purpose_ai_will_do_bonus_t1
			}
			### Fickle
			if = {
				limit = { has_trait = fickle }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Humble
			if = {
				limit = { has_trait = humble }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Arrogant
			if = {
				limit = { has_trait = arrogant }
				add = @camp_purpose_ai_will_do_malus_t2
			}
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				multiply = 0
			}
		}
	}
	
	camp_purpose_brigands = {
		flag = uses_camp_purpose
		flag = can_change_succession_laws
		flag = laamp_contracts_weight_up_criminal
		flag = laamp_contracts_weight_up_prowess
		flag = laamp_contracts_weight_up_intrigue
		flag = martial_camp_purpose

		# Camp unlocks.
		flag = unlocks_proving_grounds_lockwagon
		flag = unlocks_barber_tent_morticians_tools
		flag = unlocks_supply_tent_subdued_gear
		flag = unlocks_baggage_train_ransom_cages
		flag = unlocks_baggage_train_negotiators
		flag = unlocks_camp_fire_juicy_rumors
		flag = unlocks_proving_grounds_the_stick_game

		can_keep = { realm_law_use_camp_purpose = yes }

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law_flag = can_change_purpose_for_free }
					}
					value = @camp_purpose_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
			# Remove inappropriate buildings.
			laamp_clear_inappropriate_buildings_effect = yes
			# Adjust flavourisation.
			remove_camp_purpose_flavourisation_variables_effect = yes
			set_variable = flavourise_camp_purpose_brigands
			local_arbitration_boon_set_purpose_effect = {
				MODIFIER = landless_local_arbitration_brigands_modifier
			}
		}
		
		modifier = {
			embarkation_cost_mult = -0.5
			knight_limit = 3
		}

		ai_will_do = {
			# Traits.
			## Education.
			if = {
				limit = { has_trait = education_intrigue }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Cultural traditions
			if = {
				limit = {
					culture = {
						OR = {
							has_cultural_parameter = much_more_likely_to_be_laamps
							has_cultural_parameter = more_likely_to_be_laamps
						}
					}
				}
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			## Personality.
			### Deceitful.
			if = {
				limit = { has_trait = deceitful }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Honest.
			if = {
				limit = { has_trait = honest }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			### Arbitrary.
			if = {
				limit = { has_trait = arbitrary }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Just,
			if = {
				limit = { has_trait = just }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			### Greedy + either Humble or Content.
			if = {
				limit = {
					has_trait = greedy
					OR = {
						has_trait = humble
						has_trait = content
					}
				}
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Generous.
			if = {
				limit = { has_trait = generous }
				add = @camp_purpose_ai_will_do_malus_t2
			}
			### Arrogant.
			if = {
				limit = { has_trait = arrogant }
				add = @camp_purpose_ai_will_do_malus_t2
			}
			### Ambitious.
			if = {
				limit = { has_trait = ambitious }
				add = @camp_purpose_ai_will_do_malus_t2
			}
			### Wrathful.
			if = {
				limit = { has_trait = wrathful }
				add = @camp_purpose_ai_will_do_bonus_t1
			}
			### Calm.
			if = {
				limit = { has_trait = calm }
				add = @camp_purpose_ai_will_do_malus_t1
			}
			### Sadistic.
			if = {
				limit = { has_trait = sadistic }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Callous.
			if = {
				limit = { has_trait = callous }
				add = @camp_purpose_ai_will_do_bonus_t2
			}
			### Compassionate.
			if = {
				limit = { has_trait = compassionate }
				add = @camp_purpose_ai_will_do_malus_t2
			}
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				multiply = 0
			}
		}
	}
	
	camp_purpose_legitimists = {
		flag = uses_camp_purpose
		flag = can_change_succession_laws
		flag = martial_camp_purpose

		# Camp unlocks.
		flag = unlocks_baggage_train_scribes
		flag = unlocks_proving_grounds_martial_study
		flag = unlocks_baggage_train_proof_of_claims
		flag = unlocks_baggage_train_ransom_cages
		flag = unlocks_camp_fire_future_dreams
		flag = unlocks_proving_grounds_bodyguard_drills

		can_keep = {
			realm_law_use_camp_purpose = yes
			ep3_can_have_legitimists_camp_purpose_trigger = yes
		}

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law_flag = can_change_purpose_for_free }
					}
					value = @camp_purpose_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
			# Remove inappropriate buildings.
			laamp_clear_inappropriate_buildings_effect = yes
			# Adjust flavourisation.
			remove_camp_purpose_flavourisation_variables_effect = yes
			set_variable = flavourise_camp_purpose_legitimists
			local_arbitration_boon_set_purpose_effect = {
				MODIFIER = landless_local_arbitration_legitimists_modifier
			}
		}
		
		modifier = {
			men_at_arms_cap = 1
			knight_limit = 8
		}

		ai_will_do = {
			# Weight up legitimists inherently.
			value = 100
			# Traits.
			## Education.
			if = {
				limit = {
					OR = {
						has_trait = education_diplomacy
						has_trait = education_martial
					}
				}
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			## Personality.
			### Ambitious
			if = {
				limit = { has_trait = ambitious }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Content
			if = {
				limit = { has_trait = content }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			### Arrogant
			if = {
				limit = { has_trait = arrogant }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Humble
			if = {
				limit = { has_trait = humble }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			### Vengeful
			if = {
				limit = { has_trait = vengeful }
				add = @camp_purpose_ai_will_do_bonus_t3
			}
			### Forgiving
			if = {
				limit = { has_trait = forgiving }
				add = @camp_purpose_ai_will_do_malus_t3
			}
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				multiply = 0
			}
		}
	}
}

imperial_bureaucracy = {
	default = imperial_bureaucracy_1
	cumulative = yes
	flag = realm_law
	
	imperial_bureaucracy_0 = {
		modifier = {
			barons_and_minor_landholders_opinion = 20
			glory_hound_opinion = 10
			parochial_opinion = 10
			courtly_opinion = 5
		}
		flag = uses_imperial_bureaucracy
		flag = titles_cannot_leave_realm_on_succession # Hardcoded flag

		can_keep = {
			realm_law_use_imperial_bureaucracy = yes
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = imperial_bureaucracy_0 }
			}
		}
		
		can_pass = {
			trigger_if = {
				limit = {
					is_independent_ruler = no
					liege = { has_realm_law = imperial_bureaucracy_0 }
				}
				custom_tooltip = {
					text = imperial_bureaucracy_pending_law_change
					always = no
				}
			}
		}

		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
	
	imperial_bureaucracy_1 = {
		modifier = {
			barons_and_minor_landholders_opinion = -30
			glory_hound_opinion = -15
			parochial_opinion = -15
			courtly_opinion = -5
			minority_opinion = -10
			administrative_government_tax_contribution_add = 0.05
			vassal_limit = 100
		}
		flag = uses_imperial_bureaucracy
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = can_change_partition_succession_laws
		flag = vassal_internal_wars_banned
		flag = diarchs_want_to_subsidise_without_this_flag

		can_keep = {
			realm_law_use_imperial_bureaucracy = yes
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = imperial_bureaucracy_1 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					has_realm_law = imperial_bureaucracy_0
					is_independent_ruler = yes
				}
				custom_description = {
					subject = root
					text = "has_imperial_bureaucracy_cooldown"
					NAND = {
						has_variable = imperial_bureaucracy_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
				}
			}
			trigger_if = {
				limit = {
					is_independent_ruler = no
					liege = { has_realm_law = imperial_bureaucracy_1 }
				}
				custom_tooltip = {
					text = imperial_bureaucracy_pending_law_change
					always = no
				}
			}
			can_pass_law_ca1_trigger = yes
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOR = {
							has_realm_law = imperial_bureaucracy_2
							has_realm_law = imperial_bureaucracy_3
						}
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = imperial_bureaucracy_cooldown
				years = @imperial_bureaucracy_cooldown_years_1
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = imperial_bureaucracy_0 }
				value = 1
			}
		}
	}
	
	imperial_bureaucracy_2 = {
		modifier = {
			barons_and_minor_landholders_opinion = -10
			glory_hound_opinion = -10
			parochial_opinion = -10
			courtly_opinion = -5
			zealot_opinion = -10
			minority_opinion = -10
			administrative_government_tax_contribution_add = 0.05
			republic_government_tax_contribution_add = 0.05
			vassal_limit = 100
		}
		flag = uses_imperial_bureaucracy
		flag = vassal_refusal_is_treason
		flag = can_change_succession_laws
		flag = vassal_all_wars_banned
		flag = admin_change_vassal_gov_cheaper
		flag = admin_title_troop_cost_reduction
		
		can_keep = {
			realm_law_use_imperial_bureaucracy = yes
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = imperial_bureaucracy_2 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = imperial_bureaucracy_3 }
					is_independent_ruler = yes
				}
				has_realm_law = imperial_bureaucracy_1
				custom_description = {
					subject = root
					text = "has_imperial_bureaucracy_cooldown"
					NAND = {
						has_variable = imperial_bureaucracy_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
				}
			}
			trigger_if = {
				limit = {
					is_independent_ruler = no
					liege = { has_realm_law = imperial_bureaucracy_2 }
				}
				custom_tooltip = {
					text = imperial_bureaucracy_pending_law_change
					always = no
				}
			}
			can_pass_law_ca2_trigger = yes
		}

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law = imperial_bureaucracy_3 }
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = imperial_bureaucracy_cooldown
				years = @imperial_bureaucracy_cooldown_years_2
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = imperial_bureaucracy_1 }
				value = 1
			}
		}
	}
	
	imperial_bureaucracy_3 = {
		modifier = {
			barons_and_minor_landholders_opinion = -20
			glory_hound_opinion = -25
			parochial_opinion = -25
			courtly_opinion = -10
			zealot_opinion = -20
			minority_opinion = -30
			administrative_government_tax_contribution_add = 0.1
			republic_government_tax_contribution_add = 0.05
			vassal_limit = 200
		}
		flag = uses_imperial_bureaucracy
		flag = vassal_all_wars_banned_permanent
		flag = max_authority_level
		flag = admin_title_troop_cost_reduction_high
		
		can_keep = {
			realm_law_use_imperial_bureaucracy = yes
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = imperial_bureaucracy_3 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					is_independent_ruler = yes
				}
				has_realm_law = imperial_bureaucracy_2
				custom_description = {
					subject = root
					text = "has_imperial_bureaucracy_cooldown"
					NAND = {
						has_variable = imperial_bureaucracy_cooldown
						NOT = {
							culture = { has_innovation = innovation_all_things }
						}
					}
				}
			}
			trigger_if = {
				limit = {
					is_independent_ruler = no
					liege = { has_realm_law = imperial_bureaucracy_3 }
				}
				custom_tooltip = {
					text = imperial_bureaucracy_pending_law_change
					always = no
				}
			}
			can_pass_law_ca3_trigger = yes
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law = imperial_bureaucracy_3 }
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = imperial_bureaucracy_cooldown
				years = @imperial_bureaucracy_cooldown_years_3
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
}
