﻿@crown_authority_cooldown_years = 20
@tribal_authority_cooldown_years = 10
@nomadic_authority_cooldown_years = 5
@church_authority_cooldown_years = 20
@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_0 = {
	law_group_type = crown_authority
	index = 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
	flag = authority_level_0
	flag = has_requirement_for_authority_level

	can_keep = {
		realm_law_use_crown_authority = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = crown_authority_0 }
		}
	}

	on_pass = {
		# Remove modifiers.
		remove_law_related_modifiers_effect = yes
	}
}

crown_authority_1 = {
	law_group_type = crown_authority
	index = 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
	flag = authority_level_1

	can_keep = {
		realm_law_use_crown_authority = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			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 = {
					has_realm_law = crown_authority_0
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = crown_authority_0
			}
			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 = {
	law_group_type = crown_authority
	index = 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
	flag = authority_level_2

	can_keep = {
		realm_law_use_crown_authority = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = crown_authority_2 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				NOT = { has_realm_law = crown_authority_3 }
				should_synchronize_liege_law = 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 = {
					has_realm_law = crown_authority_1
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = crown_authority_1
			}
			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 = {
	law_group_type = crown_authority
	index = 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
	flag = authority_level_3

	can_keep = {
		realm_law_use_crown_authority = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = crown_authority_3 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = { should_synchronize_liege_law = 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 = {
					has_realm_law = crown_authority_2
				}
				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_0 = {
	law_group_type = tribal_authority
	index = 0

	modifier = {
		glory_hound_opinion = 10
		parochial_opinion = 10
		courtly_opinion = 5
		belligerent_opinion = -15
	}
	flag = uses_tribal_authority
	flag = imprisonment_toggle_enable
	flag = authority_level_0

	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 = {
	law_group_type = tribal_authority
	index = 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
	flag = authority_level_1

	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 = {
					has_realm_law = tribal_authority_0
				}
				add = increase_tribal_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = tribal_authority_0
			}
			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 = {
	law_group_type = tribal_authority
	index = 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
	flag = authority_level_2

	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 = {
					has_realm_law = tribal_authority_1
				}
				add = increase_tribal_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = tribal_authority_1
			}
			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 = {	
	law_group_type = tribal_authority
	index = 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
	flag = authority_level_3
	#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
		}
	}
}


church_authority_0 = {
	law_group_type = church_authority
	index = 0

	modifier = {
		zealot_opinion = 10
		parochial_opinion = 10
		minority_opinion = -10
	}
	flag = uses_church_authority
	flag = has_requirement_for_authority_level
	flag = authority_level_0

	can_keep = { realm_law_use_church_authority = yes }

	on_pass = {
		# Remove modifiers.
		remove_law_related_modifiers_effect = yes
	}
}

church_authority_1 = {
	law_group_type = church_authority
	index = 1

	modifier = {
		zealot_opinion = 15
		parochial_opinion = -5
		minority_opinion = -15
		glory_hound_opinion = -5
	}
	flag = title_revocation_allowed
	flag = vassal_retraction_allowed
	flag = bulls_allowed
	flag = authority_level_1
	flag = puppet_acceptance_1

	can_keep = { realm_law_use_church_authority = yes }

	can_pass = {
		trigger_if = {
			limit = { has_realm_law = church_authority_0 }
			custom_description = {
				subject = root
				text = "has_church_authority_cooldown"
				NOT = { has_variable = church_authority_cooldown }
			}
		}
		can_pass_law_church_authority_1_trigger = yes
	}

	pass_cost = {
		piety = {
			if = {
				limit = {
					NOR = {
						has_realm_law = church_authority_2
						has_realm_law = church_authority_3
					}
				}
				add = increase_church_authority_piety_cost
			}
		}
		prestige = {
			if = {
				limit = {
					has_realm_law = church_authority_0
				}
				add = increase_crown_authority_prestige_cost
				multiply = 0.4
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = church_authority_0
			}
			calculate_authority_cooldown_break_effect = yes
		}
		# Set regular cooldown.
		set_variable = {
			name = church_authority_cooldown
			years = @church_authority_cooldown_years
		}
		# Remove modifiers.
		remove_law_related_modifiers_effect = yes
	}

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

church_authority_2 = {
	law_group_type = church_authority
	index = 2

	modifier = {
		zealot_opinion = 20
		parochial_opinion = -10
		courtly_opinion = -10
		barons_and_minor_landholders_opinion = -5
		belligerent_opinion = -20
		minority_opinion = -20
		glory_hound_opinion = -10
		vassal_tax_contribution_mult = 0.1
		vassal_levy_contribution_mult = 0.1
	}
	flag = can_establish_theocratic_dynasty
	flag = vassal_internal_wars_banned
	flag = vassal_refusal_is_treason
	flag = titles_cannot_leave_realm_on_succession # Hardcoded flag
	flag = authority_level_2
	flag = puppet_acceptance_2

	can_keep = { realm_law_use_church_authority = yes }

	can_pass = {
		trigger_if = {
			limit = {
				NOT = { has_realm_law = church_authority_3 }
			}
			has_realm_law = church_authority_1
			custom_description = {
				subject = root
				text = "has_church_authority_cooldown"
				NOT = { has_variable = church_authority_cooldown }
			}
		}
		can_pass_law_church_authority_2_trigger = yes
	}

	pass_cost = {
		piety = {
			if = {
				limit = {
					NOT = { has_realm_law = church_authority_3 }
				}
				add = increase_church_authority_piety_cost
			}
		}
		prestige = {
			if = {
				limit = {
					has_realm_law = church_authority_1
				}
				add = increase_crown_authority_prestige_cost
				multiply = 0.4
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = church_authority_1
			}
			calculate_authority_cooldown_break_effect = yes
		}
		# Set regular cooldown.
		set_variable = {
			name = church_authority_cooldown
			years = @church_authority_cooldown_years
		}
		# Remove modifiers.
		remove_law_related_modifiers_effect = yes
	}

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

church_authority_3 = {
	law_group_type = church_authority
	index = 3

	modifier = {
		zealot_opinion = 30
		parochial_opinion = -20
		courtly_opinion = -15
		barons_and_minor_landholders_opinion = -5
		belligerent_opinion = -30
		minority_opinion = -30
		glory_hound_opinion = -10
		vassal_tax_contribution_mult = 0.25
		vassal_levy_contribution_mult = 0.25
	}
	flag = vassal_all_wars_banned
	flag = max_authority_level
	flag = authority_level_3
	flag = clergy_force_land_transfers
	flag = puppet_acceptance_3

	can_keep = { realm_law_use_church_authority = yes }

	can_pass = {
		has_realm_law = church_authority_2
		custom_description = {
			subject = root
			text = "has_church_authority_cooldown"
			NOT = { has_variable = church_authority_cooldown }
		}
		can_pass_law_church_authority_3_trigger = yes
	}

	pass_cost = {
		piety = {
			if = {
				limit = {
					NOT = { has_realm_law = church_authority_3 }
				}
				add = increase_church_authority_piety_cost
			}
		}
		prestige = {
			if = {
				limit = {
					has_realm_law = church_authority_2
				}
				add = increase_crown_authority_prestige_cost
				multiply = 0.4
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		calculate_authority_cooldown_break_effect = yes
		# Set regular cooldown.
		set_variable = {
			name = church_authority_cooldown
			years = @church_authority_cooldown_years
		}
		# Remove modifiers.
		remove_law_related_modifiers_effect = yes
	}

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


camp_purpose_wanderers = {
	law_group_type = camp_purpose
	index = 0

	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 = {
	law_group_type = camp_purpose
	index = 1

	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 = {
	law_group_type = camp_purpose
	index = 2

	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 = {
	law_group_type = camp_purpose
	index = 3

	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 = {
	law_group_type = camp_purpose
	index = 4

	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 = {
	law_group_type = camp_purpose
	index = 5

	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_0 = {
	law_group_type = imperial_bureaucracy
	index = 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
	flag = authority_level_0
	flag = has_requirement_for_authority_level

	can_keep = {
		realm_law_use_imperial_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = imperial_bureaucracy_0 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				should_synchronize_liege_law = yes
				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 = {
	law_group_type = imperial_bureaucracy
	index = 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
	flag = authority_level_1

	can_keep = {
		realm_law_use_imperial_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = imperial_bureaucracy_1 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				has_realm_law = imperial_bureaucracy_0
				should_synchronize_liege_law = no
			}
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = imperial_bureaucracy_0
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = imperial_bureaucracy_0
			}
			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 = {
	law_group_type = imperial_bureaucracy
	index = 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
	flag = authority_level_2

	can_keep = {
		realm_law_use_imperial_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = imperial_bureaucracy_2 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				NOT = { has_realm_law = imperial_bureaucracy_3 }
				should_synchronize_liege_law = no
			}
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = imperial_bureaucracy_1
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = imperial_bureaucracy_1
			}
			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 = {
	law_group_type = imperial_bureaucracy
	index = 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
	flag = authority_level_3

	can_keep = {
		realm_law_use_imperial_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = imperial_bureaucracy_3 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = { should_synchronize_liege_law = no }
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = imperial_bureaucracy_2
				}
				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_1 = {
	law_group_type = nomadic_authority
	index = 0

	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
	flag = authority_level_0

	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 = {
	law_group_type = nomadic_authority
	index = 1

	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
	flag = authority_level_1

	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 = {
					has_realm_law = nomadic_authority_1
				}
				add = increase_nomadic_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = nomadic_authority_1
			}
			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 = {
	law_group_type = nomadic_authority
	index = 2

	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
	flag = authority_level_2

	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 = {
					has_realm_law = nomadic_authority_2
				}
				add = increase_nomadic_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = nomadic_authority_2
			}
			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 = {
	law_group_type = nomadic_authority
	index = 3

	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
	flag = authority_level_3
	#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 = {
					has_realm_law = nomadic_authority_3
				}
				add = increase_nomadic_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = nomadic_authority_3
			}
			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 = {
	law_group_type = nomadic_authority
	index = 4

	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
	flag = authority_level_4
	#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_0 = {
	law_group_type = celestial_bureaucracy
	index = 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
	flag = authority_level_0
	flag = has_requirement_for_authority_level

	can_keep = {
		realm_law_use_celestial_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = celestial_bureaucracy_0 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				should_synchronize_liege_law = yes
				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 = {
	law_group_type = celestial_bureaucracy
	index = 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
	flag = authority_level_1

	can_keep = {
		realm_law_use_celestial_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = celestial_bureaucracy_1 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				has_realm_law = celestial_bureaucracy_0
				should_synchronize_liege_law = no
			}
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = celestial_bureaucracy_0
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = celestial_bureaucracy_0
			}
			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 = {
	law_group_type = celestial_bureaucracy
	index = 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
	flag = authority_level_2

	can_keep = {
		realm_law_use_celestial_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = celestial_bureaucracy_2 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				NOT = { has_realm_law = celestial_bureaucracy_3 }
				should_synchronize_liege_law = no
			}
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = celestial_bureaucracy_1
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = celestial_bureaucracy_1
			}
			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 = {
	law_group_type = celestial_bureaucracy
	index = 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
	flag = authority_level_3

	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 = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = celestial_bureaucracy_3 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = { should_synchronize_liege_law = no }
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = celestial_bureaucracy_2
				}
				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_none = {
	law_group_type = mandala_decree
	index = 0

	#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 = {
	law_group_type = mandala_decree
	index = 1

	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 = {
	law_group_type = mandala_decree
	index = 2

	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 = {
	law_group_type = mandala_decree
	index = 3

	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_0 = {
	law_group_type = meritocratic_bureaucracy
	index = 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
	flag = authority_level_0
	flag = has_requirement_for_authority_level

	can_keep = {
		realm_law_use_meritocratic_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = meritocratic_bureaucracy_0 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				should_synchronize_liege_law = yes
				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 = {
	law_group_type = meritocratic_bureaucracy
	index = 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
		steppe_admin_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
	flag = authority_level_1

	can_keep = {
		realm_law_use_meritocratic_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = meritocratic_bureaucracy_1 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				has_realm_law = meritocratic_bureaucracy_0
				should_synchronize_liege_law = no
			}
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = meritocratic_bureaucracy_0
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = meritocratic_bureaucracy_0
			}
			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 = {
	law_group_type = meritocratic_bureaucracy
	index = 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
		steppe_admin_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
	flag = authority_level_2

	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 = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = meritocratic_bureaucracy_2 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				NOT = { has_realm_law = meritocratic_bureaucracy_3 }
				should_synchronize_liege_law = no
			}
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = meritocratic_bureaucracy_1
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = meritocratic_bureaucracy_1
			}
			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 = {
	law_group_type = meritocratic_bureaucracy
	index = 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
		steppe_admin_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
	flag = authority_level_3

	can_keep = {
		realm_law_use_meritocratic_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = meritocratic_bureaucracy_3 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = { should_synchronize_liege_law = no }
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = meritocratic_bureaucracy_2
				}
				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_0 = {
	law_group_type = japanese_bureaucracy
	index = 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
	flag = can_designate_heirs
	flag = authority_level_0
	flag = has_requirement_for_authority_level

	can_keep = {
		realm_law_use_japanese_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = japanese_bureaucracy_0 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				should_synchronize_liege_law = yes
				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 = {
	law_group_type = japanese_bureaucracy
	index = 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 = 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
	flag = can_designate_heirs
	flag = can_have_tributaries
	flag = authority_level_1

	can_keep = {
		realm_law_use_japanese_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = japanese_bureaucracy_1 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				has_realm_law = japanese_bureaucracy_0
				should_synchronize_liege_law = no
			}
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = japanese_bureaucracy_0
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = japanese_bureaucracy_0
			}
			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 = {
	law_group_type = japanese_bureaucracy
	index = 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
		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
	flag = can_designate_heirs
	flag = vassal_internal_wars_banned
	flag = can_have_tributaries
	flag = authority_level_2

	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 = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = japanese_bureaucracy_2 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = {
				NOT = { has_realm_law = japanese_bureaucracy_3 }
				should_synchronize_liege_law = no
			}
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = japanese_bureaucracy_1
				}
				add = increase_crown_authority_prestige_cost
			}
		}
	}

	on_pass = {
		# Increment cooldown breaker tally, if appropriate.
		if = {
			limit = {
				has_realm_law = japanese_bureaucracy_1
			}
			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 = {
	law_group_type = japanese_bureaucracy
	index = 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.15
		vassal_levy_contribution_mult = 0.15
		republic_government_tax_contribution_add = 0.05
	}
	flag = uses_japanese_bureaucracy
	flag = max_authority_level
	flag = can_designate_heirs
	flag = vassal_all_wars_banned_permanent
	flag = can_have_tributaries
	flag = authority_level_3

	can_keep = {
		realm_law_use_japanese_bureaucracy = yes
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			liege = { has_realm_law = japanese_bureaucracy_3 }
		}
	}

	can_pass = {
		trigger_if = {
			limit = { should_synchronize_liege_law = no }
			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 = {
				should_synchronize_liege_law = yes
				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 = {
					has_realm_law = japanese_bureaucracy_2
				}
				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
	}
}

uncrowned = {
	law_group_type = crowned_laws
	index = 0

	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 = {
	law_group_type = crowned_laws
	index = 1

	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 = {
	law_group_type = crowned_laws
	index = 2

	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
		}
	}
}
