﻿@crown_authority_cooldown_years = 20
@tribal_authority_cooldown_years = 10
@nomadic_authority_cooldown_years = 5
@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

@mandala_decree_piety_cost = 1000
@mandala_decree_prestige_cost = 500

crown_authority = {
	default = crown_authority_1
	cumulative = yes
	flag = realm_law
	
	crown_authority_0 = {
		modifier = {
			belligerent_opinion = -10
			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 = {
					government_allows = administrative
					top_liege != this
				}
				liege = { has_realm_law = crown_authority_0 }
			}
		}

		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
	
	crown_authority_1 = {
		modifier = {
			belligerent_opinion = 5
			barons_and_minor_landholders_opinion = -30
			glory_hound_opinion = -15
			parochial_opinion = -15
			courtly_opinion = -5
			minority_opinion = -10
		}
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = can_have_tributaries
		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 = {
					government_allows = administrative
					top_liege != this
				}
				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 = {
			belligerent_opinion = 10
			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 = 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 = {
					government_allows = administrative
					top_liege != this
				}
				liege = { has_realm_law = crown_authority_2 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = crown_authority_3 }
					NAND = {
						government_allows = administrative
						top_liege != this
					}
				}
				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 = {
			belligerent_opinion = 15
			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 = vassal_all_wars_banned
		flag = can_designate_heirs
		flag = max_authority_level
		
		can_keep = {
			realm_law_use_crown_authority = yes
			trigger_if = {
				limit = {
					government_allows = administrative
					top_liege != this
				}
				liege = { has_realm_law = crown_authority_3 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NAND = {
						government_allows = administrative
						top_liege != this
					}
				}
				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
			belligerent_opinion = -15
		}
		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
			belligerent_opinion = 5
		}
		flag = can_have_tributaries
		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
			belligerent_opinion = 15
		}
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = diarchs_want_to_subsidise_without_this_flag
		
		can_keep = {
			realm_law_use_tribal_authority = yes
			trigger_if = {
				limit = {
					NOT = {
						culture = {
							has_cultural_parameter = forming_confederations_is_easier 
						}
					}
				}
				NOT = {
					is_confederation_member = 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
			belligerent_opinion = 20
		}
		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
			trigger_if = {
				limit = {
					NOT = {
						culture = {
							has_cultural_parameter = forming_confederations_is_easier 
						}
					}
				}
				NOT = {
					is_confederation_member = 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 = {
		pass_phrase =  camp_purpose_pass_phrase
		confirmation_title = camp_purpose_pass_phrase
		confirmation_button_text = camp_purpose_confirmation_button_text

		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 = {
		pass_phrase =  camp_purpose_pass_phrase
		confirmation_title = camp_purpose_pass_phrase
		confirmation_button_text = camp_purpose_confirmation_button_text

		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 = {
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				value = 0
			}
			else = {
				# 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
				}
			}
		}
	}
	
	camp_purpose_scholars = {
		pass_phrase =  camp_purpose_pass_phrase
		confirmation_title = camp_purpose_pass_phrase
		confirmation_button_text = camp_purpose_confirmation_button_text

		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 = {
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				value = 0
			}
			else = {
				# 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
				}
			}	
		}
	}
	
	camp_purpose_explorers = {
		pass_phrase =  camp_purpose_pass_phrase
		confirmation_title = camp_purpose_pass_phrase
		confirmation_button_text = camp_purpose_confirmation_button_text

		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 = {
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				value = 0
			}
			else = {
				# 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
				}
			}
		}
	}
	
	camp_purpose_brigands = {
		pass_phrase =  camp_purpose_pass_phrase
		confirmation_title = camp_purpose_pass_phrase
		confirmation_button_text = camp_purpose_confirmation_button_text

		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 = {
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				value = 0
			}
			else = {
				# 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
				}
			}
		}
	}
	
	camp_purpose_legitimists = {
		pass_phrase =  camp_purpose_pass_phrase
		confirmation_title = camp_purpose_pass_phrase
		confirmation_button_text = camp_purpose_confirmation_button_text
		
		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
		flag = unlocks_proving_grounds_lockwagon

		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
			# If we've picked a purpose, don't change it.
			if = {
				limit = {
					NOT = { has_realm_law = camp_purpose_wanderers }
				}
				value = 0
			}
			else = {
				# 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
				}
			}
		}
	}
}

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

		can_keep = {
			realm_law_use_imperial_bureaucracy = yes
			trigger_if = {
				limit = {
					top_liege != this
				}
				liege = { has_realm_law = imperial_bureaucracy_0 }
			}
		}
		
		can_pass = {
			trigger_if = {
				limit = {
					top_liege != this
					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 = {
			belligerent_opinion = 5
			barons_and_minor_landholders_opinion = -30
			glory_hound_opinion = -15
			parochial_opinion = -15
			courtly_opinion = -5
			minority_opinion = -10
			vassal_limit = 100
		}
		flag = can_have_tributaries
		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 = {
					top_liege != this
				}
				liege = { has_realm_law = imperial_bureaucracy_1 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					has_realm_law = imperial_bureaucracy_0
					top_liege = this
				}
				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 = {
					top_liege != this
					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 = {
			belligerent_opinion = 10
			barons_and_minor_landholders_opinion = -10
			glory_hound_opinion = -10
			parochial_opinion = -10
			courtly_opinion = -5
			zealot_opinion = -10
			minority_opinion = -10
			republic_government_tax_contribution_add = 0.05
			vassal_limit = 100
		}
		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 = {
					top_liege != this
				}
				liege = { has_realm_law = imperial_bureaucracy_2 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = imperial_bureaucracy_3 }
					top_liege = this
				}
				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 = {
					top_liege != this
					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 = {
			belligerent_opinion = 15
			barons_and_minor_landholders_opinion = -20
			glory_hound_opinion = -25
			parochial_opinion = -25
			courtly_opinion = -10
			zealot_opinion = -20
			minority_opinion = -30
			republic_government_tax_contribution_add = 0.05
			vassal_limit = 200
		}
		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 = {
					top_liege != this
				}
				liege = { has_realm_law = imperial_bureaucracy_3 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					top_liege = this
				}
				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 = {
					top_liege != this
					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
		}
	}
}

nomadic_authority = {
	default = nomadic_authority_1
	cumulative = yes
	flag = realm_law
	flag = dominance_law
	
	nomadic_authority_1 = {
		pass_phrase = nomadic_authority_1_pass_phrase
		confirmation_title = nomadic_authority_1_pass_phrase
		confirmation_button_text = nomadic_authority_confirmation_button_text

		modifier = {
			belligerent_opinion = -25
			glory_hound_opinion = -20
			domain_limit_min = 1
			domain_limit_max = 2
			vassal_limit_min = 1
			vassal_limit_max = 1
		}
		flag = can_have_tributaries
		flag = title_revocation_allowed
		flag = uses_nomadic_authority
		flag = imprisonment_toggle_enable
		flag = access_to_nomadic_county_conquest
		
		can_pass = {
			has_realm_law = nomadic_authority_2
		}

		can_keep = { realm_law_use_nomadic_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
		}
	}
	
	nomadic_authority_2 = {
		pass_phrase = nomadic_authority_2_pass_phrase
		confirmation_title = nomadic_authority_2_pass_phrase
		confirmation_button_text = nomadic_authority_confirmation_button_text

		modifier = {
			belligerent_opinion = 10
			glory_hound_opinion = 10
			max_migration_distance_mult = 0.25
			domain_limit_min = 1
			domain_limit_max = 1
			vassal_limit_min = 1
			vassal_limit_max = 2 # 3
		}
		flag = can_change_succession_laws
		flag = imprisonment_toggle_on
		flag = title_revocation_allowed
		flag = migration_to_duchies
		flag = access_to_nomadic_county_conquest
		flag = unlock_maa_nomad_lancers

		can_keep = {
			realm_law_use_nomadic_authority = yes
		}

		can_pass = {
			custom_tooltip = {
				text = "nomadic_authority_2_level_requirement"
				OR = {
					has_realm_law = nomadic_authority_1
					has_realm_law = nomadic_authority_3
				}
			}
			custom_description = {
				subject = root
				text = "has_nomadic_authority_cooldown"
				NAND = {
					has_variable = nomadic_authority_cooldown
					NOT = {
						culture = { has_innovation = innovation_all_things }
					}
				}
			}
			domicile.herd >= nomadic_authority_level_2_requirement
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOR = {
							has_realm_law = nomadic_authority_2
							has_realm_law = nomadic_authority_3
						}
					}
					add = increase_nomadic_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = nomadic_authority_cooldown
				years = @nomadic_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = nomadic_authority_1 }
				value = 1
			}
		}
	}

	nomadic_authority_3 = {
		pass_phrase = nomadic_authority_3_pass_phrase
		confirmation_title = nomadic_authority_3_pass_phrase
		confirmation_button_text = nomadic_authority_confirmation_button_text

		modifier = {
			belligerent_opinion = 10
			glory_hound_opinion = 10
			max_migration_distance_mult = 0.5
			domain_limit_min = 2
			domain_limit_max = 3
			vassal_limit_min = 8
			vassal_limit_max = 12 # 15
		}
		flag = vassal_retraction_allowed
		flag = diarchs_want_to_subsidise_without_this_flag
		flag = migration_to_kingdoms
		flag = access_to_nomadic_duchy_conquest
		
		can_keep = {
			realm_law_use_nomadic_authority = yes
			trigger_if = {
				limit = {
					NOT = {
						culture = {
							has_cultural_parameter = forming_confederations_is_easier 
						}
					}
				}
				NOT = {
					is_confederation_member = yes
				}
			}
		}
		
		can_pass = {
			custom_tooltip = {
				text = "nomadic_authority_3_level_requirement"
				OR = {
					has_realm_law = nomadic_authority_2
					has_realm_law = nomadic_authority_4
				}
			}
			custom_description = {
				subject = root
				text = "has_nomadic_authority_cooldown"
				NAND = {
					has_variable = nomadic_authority_cooldown
					NOT = {
						culture = { has_innovation = innovation_all_things }
					}
				}
			}
			domicile.herd >= nomadic_authority_level_3_requirement
		}

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOR = {
							has_realm_law = nomadic_authority_3
							has_realm_law = nomadic_authority_4
						}
					}
					add = increase_nomadic_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = nomadic_authority_cooldown
				years = @nomadic_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = nomadic_authority_2 }
				value = 1
			}
		}
	}
	
	nomadic_authority_4 = {
		pass_phrase = nomadic_authority_4_pass_phrase
		confirmation_title = nomadic_authority_4_pass_phrase
		confirmation_button_text = nomadic_authority_confirmation_button_text

		modifier = {
			belligerent_opinion = 20
			glory_hound_opinion = 10
			max_migration_distance_mult = 1
			domain_limit_min = 2
			vassal_limit_min = 5
			vassal_limit_max = 15
		}
		flag = migration_to_empires
		#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_nomadic_authority = yes
			trigger_if = {
				limit = {
					NOT = {
						culture = {
							has_cultural_parameter = forming_confederations_is_easier 
						}
					}
				}
				NOT = {
					is_confederation_member = yes
				}
			}
		}
		
		can_pass = {
			custom_tooltip = {
				text = "nomadic_authority_4_level_requirement"
				OR = {
					has_realm_law = nomadic_authority_3
					has_realm_law = nomadic_authority_5
				}
			}
			custom_description = {
				subject = root
				text = "has_nomadic_authority_cooldown"
				NAND = {
					has_variable = nomadic_authority_cooldown
					NOT = {
						culture = { has_innovation = innovation_all_things }
					}
				}
			}
			domicile.herd >= nomadic_authority_level_4_requirement
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOR = {
							has_realm_law = nomadic_authority_4
							has_realm_law = nomadic_authority_5
						}
					}
					add = increase_nomadic_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = nomadic_authority_cooldown
				years = @nomadic_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = nomadic_authority_3 }
				value = 1
			}
		}
		
	}
	
	nomadic_authority_5 = {
		pass_phrase = nomadic_authority_5_pass_phrase
		confirmation_title = nomadic_authority_5_pass_phrase
		confirmation_button_text = nomadic_authority_confirmation_button_text

		modifier = {
			belligerent_opinion = 25
			glory_hound_opinion = 15
			max_migration_distance_mult = 10
			max_migration_distance_mult = 2
			vassal_limit_min = 985
			vassal_limit_max = 970
		}
		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_nomadic_authority = yes
			trigger_if = {
				limit = {
					NOT = {
						culture = {
							has_cultural_parameter = forming_confederations_is_easier 
						}
					}
				}
				NOT = {
					is_confederation_member = yes
				}
			}
		}
		
		can_pass = {
			has_realm_law = nomadic_authority_4
			trigger_if = {
				limit = {
					any_character_situation = {
						any_participant_group = {
							participant_group_type = nomad_rulers_capital
							participant_group_has_character = root
						}
					}
				}
				custom_description = {
					text = nomadic_authority_5_gurkhan
					any_character_situation = {
						any_participant_group = {
							participant_group_type = nomad_rulers_capital
							participant_group_has_character = root
						}
						situation_top_herd ?= root
					}
				}
			}
			custom_description = { 
				subject = root
				text = "has_nomadic_authority_cooldown"
				NAND = {
					has_variable = nomadic_authority_cooldown
					NOT = {
						culture = { has_innovation = innovation_all_things }
					}
				}
			}
			domicile.herd >= nomadic_authority_level_5_requirement
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = {
							has_realm_law = nomadic_authority_5
						}
					}
					add = increase_nomadic_authority_prestige_cost
					multiply = 2
				}
			}
		}
		
		on_pass = {
			# Increment cooldown breaker tally, if appropriate.
			calculate_authority_cooldown_break_effect = yes
			# Set regular cooldown.
			set_variable = {
				name = nomadic_authority_cooldown
				years = @nomadic_authority_cooldown_years
			}
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
			play_sound_effect = "event:/DLC/CE2/UI/Notifications/ce2_ui_notifications_nomadicAuthority_wolf"
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = nomadic_authority_4 }
				value = 1
			}
		}
	}
}

celestial_bureaucracy = { # A variant of Imperial Bureaucracy for Celestial Government
	default = celestial_bureaucracy_1
	cumulative = yes
	flag = realm_law
	
	celestial_bureaucracy_0 = {
		modifier = {
			courtly_opinion = -20 # Pro-hegemon movement
			#parochial_opinion = 0 # Advancement movement
			#belligerent_opinion = 0 # Expansion movement
			glory_hound_opinion = 10 # Conservative movement
			#zealot_opinion = 0
			barons_and_minor_landholders_opinion = 10
			minority_opinion = 10
			
			celestial_government_tax_contribution_add = 0.05
			republic_government_tax_contribution_add = 0.05
		}
		flag = uses_celestial_bureaucracy
		flag = titles_cannot_leave_realm_on_succession # Hardcoded flag
		flag = can_have_tributaries

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

		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
	
	celestial_bureaucracy_1 = {
		modifier = {
			courtly_opinion = 20 # Pro-hegemon movement
			parochial_opinion = -5 # Advancement movement
			belligerent_opinion = -5 # Expansion movement
			glory_hound_opinion = -10 # Conservative movement
			#zealot_opinion = 0
			barons_and_minor_landholders_opinion = -15
			minority_opinion = -15
			
			celestial_government_tax_contribution_add = 0.05
			republic_government_tax_contribution_add = 0.05
		}
		flag = uses_celestial_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
		flag = can_have_tributaries

		can_keep = {
			realm_law_use_celestial_bureaucracy = yes
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = celestial_bureaucracy_1 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					has_realm_law = celestial_bureaucracy_0
					is_independent_ruler = yes
				}
				custom_description = {
					subject = root
					text = "has_celestial_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 = celestial_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 = celestial_bureaucracy_2
							has_realm_law = celestial_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 = celestial_bureaucracy_0 }
				value = 1
			}
		}
	}
	
	celestial_bureaucracy_2 = {
		modifier = {
			courtly_opinion = 5 # Pro-hegemon movement
			parochial_opinion = -5 # Advancement movement
			belligerent_opinion = -5 # Expansion movement
			glory_hound_opinion = -15 # Conservative movement
			zealot_opinion = -5
			barons_and_minor_landholders_opinion = -15
			minority_opinion = -15

			celestial_government_tax_contribution_add = 0.10
			republic_government_tax_contribution_add = 0.10
		}
		flag = uses_celestial_bureaucracy
		flag = vassal_refusal_is_treason
		flag = can_change_succession_laws
		flag = vassal_all_wars_banned
		flag = admin_change_vassal_gov_cheaper
		flag = can_have_tributaries
		
		can_keep = {
			realm_law_use_celestial_bureaucracy = yes
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = celestial_bureaucracy_2 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = celestial_bureaucracy_3 }
					is_independent_ruler = yes
				}
				has_realm_law = celestial_bureaucracy_1
				custom_description = {
					subject = root
					text = "has_celestial_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 = celestial_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 = celestial_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 = celestial_bureaucracy_1 }
				value = 1
			}
		}
	}
	
	celestial_bureaucracy_3 = {
		modifier = {
			courtly_opinion = 10 # Pro-hegemon movement
			parochial_opinion = -10 # Advancement movement
			belligerent_opinion = -10 # Expansion movement
			glory_hound_opinion = -15 # Conservative movement
			zealot_opinion = -15
			barons_and_minor_landholders_opinion = -20
			minority_opinion = -20
			
			celestial_government_tax_contribution_add = 0.10
			republic_government_tax_contribution_add = 0.10
		}
		flag = uses_celestial_bureaucracy
		flag = vassal_all_wars_banned_permanent
		flag = max_authority_level
		flag = can_have_tributaries
		
		can_keep = {
			realm_law_use_celestial_bureaucracy = yes
			trigger_if = {
				limit = {
					this = title:h_china.holder
				}
				situation:dynastic_cycle ?= {
					NOR = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
			}
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = celestial_bureaucracy_3 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					is_independent_ruler = yes
				}
				has_realm_law = celestial_bureaucracy_2
				custom_description = {
					subject = root
					text = "has_celestial_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 = celestial_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 = celestial_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
		}
	}
}

mandala_decree = {
	default = mandala_decree_reverence
	flag = mandala_law

	mandala_decree_none = {
		#Standard laws
		flag = can_have_tributaries
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = can_change_succession_laws

		can_keep = { realm_law_is_mandala = yes }

		can_pass = {
		}

		pass_cost = {
			prestige = @mandala_decree_prestige_cost
		}
		
		on_pass = {
		}

		ai_will_do = {
			value = 0
		}
	}
	
	mandala_decree_prosperity = {
		modifier = {
			men_at_arms_maintenance = 0.25
			levy_size = -0.25
			tributary_opinion = 15
		}
		#Standard laws
		flag = can_have_tributaries
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = can_change_succession_laws
		#Decree specific
		flag = piety_devotion_from_defensive_wars
		flag = subjects_appear_more_economical
		flag = can_use_piety_to_reassert_tributary
		flag = tributaries_less_likely_to_break_free

		can_keep = { realm_law_is_mandala = yes }

		can_pass = {
			legitimacy_level >= 2
			trigger_if = {
				limit = {
					house ?= { NOT = { has_house_head_parameter = can_enact_prosperity_decree } }
				}
				custom_tooltip = {
					text = devaraja_aspect_does_not_allow_this_decree
					always = no
				}
			}
		}

		pass_cost = {
			prestige = @mandala_decree_prestige_cost
		}
		
		on_pass = {
			#Don't need the alert no more
			set_variable = {
				name = has_picked_mandala_decree
				value = flag:yes
			}
		}

		ai_will_do = {
			value = 1
			#Traits
			if = {
				limit = { has_trait = greedy }
				add = 5
			}
			if = {
				limit = { has_trait = craven }
				add = 5
			}
			if = {
				limit = { ai_has_economical_boom_personality = yes }
				add = 10
			}
		}
	}
	
	mandala_decree_expansion = {
		modifier = {
			vassal_levy_contribution_mult = 0.25
			independent_ruler_opinion = -25
			tributary_opinion = 25
		}
		#Standard laws
		flag = can_have_tributaries
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = can_change_succession_laws
		#Decree specific
		flag = piety_devotion_from_offensive_wars
		flag = piety_for_sieging_capital_temple_complexes
		flag = can_call_tributaries_for_piety
		flag = subjects_appear_more_warlike

		can_keep = { realm_law_is_mandala = yes }

		can_pass = {
			trigger_if = {
				limit = {
					house ?= { NOT = { has_house_head_parameter = can_enact_expansion_decree } }
				}
				custom_tooltip = {
					text = devaraja_aspect_does_not_allow_this_decree
					always = no
				}
			}
			legitimacy_level >= 2
		}

		pass_cost = {
			prestige = @mandala_decree_prestige_cost
		}
		
		on_pass = {
			#Don't need the alert no more
			set_variable = {
				name = has_picked_mandala_decree
				value = flag:yes
			}
		}

		ai_will_do = {
			value = 1
			#Traits
			if = {
				limit = { has_trait = brave }
				add = 5
			}
			if = {
				limit = { has_trait = ambitious }
				add = 5
			}
			if = {
				limit = { ai_has_warlike_personality = yes }
				add = 10
			}
		}
	}

	mandala_decree_reverence = {
		modifier = {
		}
		#Standard laws
		flag = can_have_tributaries
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = can_change_succession_laws
		#Decree specific
		flag = cheaper_pilgrimages
		flag = vassals_more_inclined_to_convert
		flag = subjects_appear_more_pious
		flag = can_convert_all_subjects_to_mandalas #Vassals more likely to accept, can now also ask Tribs
		flag = tributaries_more_likely_to_contribute_to_GPs

		can_keep = { realm_law_is_mandala = yes }

		can_pass = {
			legitimacy_level >= 2
			trigger_if = {
				limit = {
					house ?= { NOT = { has_house_head_parameter = can_enact_reverence_decree } }
				}
				custom_tooltip = {
					text = devaraja_aspect_does_not_allow_this_decree
					always = no
				}
			}
		}

		pass_cost = {
			prestige = @mandala_decree_prestige_cost
		}
		
		on_pass = {
			#Don't need the alert no more
			set_variable = {
				name = has_picked_mandala_decree
				value = flag:yes
			}
		}

		ai_will_do = {
			value = 1
			#Traits
			if = {
				limit = { has_trait = zealous }
				add = 5
			}
			if = {
				limit = { has_trait = arrogant }
				add = 5
			}
			if = {
				limit = { ai_has_pious_builder_personality = yes }
				add = 10
			}
		}
	}
}

meritocratic_bureaucracy = { # A variant of Imperial Bureaucracy for Meritocratic Government
	default = meritocratic_bureaucracy_1
	cumulative = yes
	flag = realm_law
	
	meritocratic_bureaucracy_0 = {
		modifier = {
			belligerent_opinion = -10
			barons_and_minor_landholders_opinion = 20
			glory_hound_opinion = 10
			parochial_opinion = 10
			courtly_opinion = 5
		}
		flag = uses_meritocratic_bureaucracy
		flag = titles_cannot_leave_realm_on_succession # Hardcoded flag
		flag = can_have_tributaries

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

		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
	
	meritocratic_bureaucracy_1 = {
		modifier = {
			belligerent_opinion = 5
			barons_and_minor_landholders_opinion = -30
			glory_hound_opinion = -15
			parochial_opinion = -15
			courtly_opinion = -5
			minority_opinion = -10
			meritocratic_government_tax_contribution_add = 0.05
		}
		flag = uses_meritocratic_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
		flag = can_have_tributaries

		can_keep = {
			realm_law_use_meritocratic_bureaucracy = yes
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = meritocratic_bureaucracy_1 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					has_realm_law = meritocratic_bureaucracy_0
					is_independent_ruler = yes
				}
				custom_description = {
					subject = root
					text = "has_meritocratic_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 = meritocratic_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 = meritocratic_bureaucracy_2
							has_realm_law = meritocratic_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 = meritocratic_bureaucracy_0 }
				value = 1
			}
		}
	}
	
	meritocratic_bureaucracy_2 = {
		modifier = {
			belligerent_opinion = 10
			barons_and_minor_landholders_opinion = -10
			glory_hound_opinion = -10
			parochial_opinion = -10
			courtly_opinion = -5
			zealot_opinion = -10
			minority_opinion = -10
			meritocratic_government_tax_contribution_add = 0.05
			republic_government_tax_contribution_add = 0.05
		}
		flag = uses_meritocratic_bureaucracy
		flag = vassal_refusal_is_treason
		flag = can_change_succession_laws
		flag = vassal_all_wars_banned
		flag = admin_change_vassal_gov_cheaper
		flag = can_have_tributaries
		
		can_keep = {
			realm_law_use_meritocratic_bureaucracy = yes
			trigger_if = {
				limit = {
					this = title:h_china.holder
				}
				situation:dynastic_cycle ?= {
					NOR = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
			}
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = meritocratic_bureaucracy_2 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = meritocratic_bureaucracy_3 }
					is_independent_ruler = yes
				}
				has_realm_law = meritocratic_bureaucracy_1
				custom_description = {
					subject = root
					text = "has_meritocratic_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 = meritocratic_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 = meritocratic_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 = meritocratic_bureaucracy_1 }
				value = 1
			}
		}
	}
	
	meritocratic_bureaucracy_3 = {
		modifier = {
			belligerent_opinion = 15
			barons_and_minor_landholders_opinion = -20
			glory_hound_opinion = -25
			parochial_opinion = -25
			courtly_opinion = -10
			zealot_opinion = -20
			minority_opinion = -30
			meritocratic_government_tax_contribution_add = 0.1
			republic_government_tax_contribution_add = 0.05
		}
		flag = uses_meritocratic_bureaucracy
		flag = vassal_all_wars_banned_permanent
		flag = max_authority_level
		flag = can_have_tributaries
		
		can_keep = {
			realm_law_use_meritocratic_bureaucracy = yes
			trigger_if = {
				limit = {
					is_independent_ruler = no
				}
				liege = { has_realm_law = meritocratic_bureaucracy_3 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					is_independent_ruler = yes
				}
				has_realm_law = meritocratic_bureaucracy_2
				custom_description = {
					subject = root
					text = "has_meritocratic_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 = meritocratic_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 = meritocratic_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
		}
	}
}

japanese_bureaucracy = { # A variant of Imperial Bureaucracy for Ritsuryo Government
	default = japanese_bureaucracy_1
	cumulative = yes
	flag = realm_law
	
	japanese_bureaucracy_0 = {
		modifier = {
			belligerent_opinion = -10
			barons_and_minor_landholders_opinion = 20
			glory_hound_opinion = 10
			parochial_opinion = 10
			courtly_opinion = 5
		}
		flag = uses_japanese_bureaucracy
		flag = titles_cannot_leave_realm_on_succession # Hardcoded flag

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

		on_pass = {
			# Remove modifiers.
			remove_law_related_modifiers_effect = yes
		}
	}
	
	japanese_bureaucracy_1 = {
		modifier = {
			belligerent_opinion = 5
			barons_and_minor_landholders_opinion = -30
			glory_hound_opinion = -15
			parochial_opinion = -15
			courtly_opinion = -5
			minority_opinion = -10
			japan_administrative_government_tax_contribution_add = 0.05
		}
		flag = uses_celestial_bureaucracy
		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_japanese_bureaucracy = yes
			trigger_if = {
				limit = { is_independent_ruler = no }
				liege = { has_realm_law = japanese_bureaucracy_1 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					has_realm_law = japanese_bureaucracy_0
					is_independent_ruler = yes
				}
				custom_description = {
					subject = root
					text = "has_japanese_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 = japanese_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 = japanese_bureaucracy_2
							has_realm_law = japanese_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 = japanese_bureaucracy_0 }
				value = 1
			}
		}
	}
	
	japanese_bureaucracy_2 = {
		modifier = {
			belligerent_opinion = 10
			barons_and_minor_landholders_opinion = -10
			glory_hound_opinion = -10
			parochial_opinion = -10
			courtly_opinion = -5
			zealot_opinion = -10
			minority_opinion = -10
			japan_administrative_government_tax_contribution_add = 0.05
			republic_government_tax_contribution_add = 0.05
		}
		flag = uses_japanese_bureaucracy
		flag = vassal_refusal_is_treason
		flag = can_change_succession_laws
		flag = admin_change_vassal_gov_cheaper
		
		can_keep = {
			realm_law_use_japanese_bureaucracy = yes
			trigger_if = {
				limit = {
					this = title:h_china.holder
				}
				situation:dynastic_cycle ?= {
					NOR = {
						situation_current_phase = situation_dynastic_cycle_phase_instability
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
			}
			trigger_if = {
				limit = { is_independent_ruler = no }
				liege = { has_realm_law = japanese_bureaucracy_2 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = japanese_bureaucracy_3 }
					is_independent_ruler = yes
				}
				has_realm_law = japanese_bureaucracy_1
				custom_description = {
					subject = root
					text = "has_japanese_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 = japanese_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 = japanese_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 = japanese_bureaucracy_1 }
				value = 1
			}
		}
	}
	
	japanese_bureaucracy_3 = {
		modifier = {
			belligerent_opinion = 15
			barons_and_minor_landholders_opinion = -20
			glory_hound_opinion = -25
			parochial_opinion = -25
			courtly_opinion = -10
			zealot_opinion = -20
			minority_opinion = -30
			japan_administrative_government_tax_contribution_add = 0.1
			republic_government_tax_contribution_add = 0.05
		}
		flag = uses_japanese_bureaucracy
		flag = max_authority_level
		
		can_keep = {
			realm_law_use_japanese_bureaucracy = yes
			trigger_if = {
				limit = { is_independent_ruler = no }
				liege = { has_realm_law = japanese_bureaucracy_3 }
			}
		}

		can_pass = {
			trigger_if = {
				limit = { is_independent_ruler = yes }
				has_realm_law = japanese_bureaucracy_2
				custom_description = {
					subject = root
					text = "has_japanese_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 = japanese_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 = japanese_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
		}

	}
}

crowned_laws = {
	default = uncrowned
	cumulative = no
	flag = realm_law
	flag = realm_law_no_number
	flag = realm_no_pass

	uncrowned = {
		can_keep = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}
		can_have = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}
		modifier = {
			vassal_opinion = -10
			legitimacy_gain_mult = -0.25
			monthly_legitimacy_add = -2.5
			ai_war_chance = -100
		}
		can_pass = {
			custom_tooltip = {
				text = can_only_be_lost_through_losing_titles
				NOR = {
					has_realm_law = crowned_king
					has_realm_law = crowned_emperor
				}
			}
		}
		potential = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}
	}

	crowned_king = {
		can_keep = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}
		can_have = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}
		modifier = {
			courtly_opinion = 5
			barons_and_minor_landholders_opinion = 5
		}
		can_pass = {
			# If you have a worse Coronation law, we will tell the player they can gain this with a Coronation
			custom_tooltip = {
				text = can_only_be_passed_through_coronation
				NOT = { has_realm_law = uncrowned }
			}
			# If you have a better Coronation law, we will tell the player this is pointless for them
			custom_tooltip = {
				text = already_better_coronation
				NOT = { has_realm_law = crowned_emperor }
			}
		}
		potential = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}
	}

	crowned_emperor = {
		can_keep = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}
		can_have = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}
		modifier = {
			courtly_opinion = 10
			barons_and_minor_landholders_opinion = 10
			zealot_opinion = 5
		}
		can_pass = {
			# If you have a worse Coronation law, we will tell the player they can gain this with a Coronation
			custom_tooltip = {
				text = can_only_be_passed_through_coronation
				NOR = {
					has_realm_law = uncrowned
					has_realm_law = crowned_king
				}
			}
		}
		should_start_with = {
			always = no
		}
		potential = {
			coronation_trigger = yes
			NOT = {
				has_game_rule = coronation_laws_off
			}
		}

	}
}
