# Crown level (de jure) laws
# Laws ending with 0 will be default laws at game start

de_jure_laws = {

	# CROWN AUTHORITY

	crown_authority_0 = {
		group = crown_authority
		default = yes

		feudal_opinion = 5
		city_opinion = 5
		temple_opinion = 5
		vassal_limit = 10

		potential = {
			holder_scope = {
				is_tribal = no
				is_nomadic = no
			}
		}

		allow = {
			trigger_if = {
				limit = {
					OR = {
						has_law = crown_authority_0
						has_law = crown_authority_1
						has_law = crown_authority_2
						has_law = crown_authority_3
						has_law = crown_authority_4
					}
				}

				has_law = crown_authority_1
			}
		}

		pass_effect = {
			# log = "crown_authority_0 pass ([This.GetFullBaseName])"

			if = {
				limit = {
					has_law = crown_authority_1
					has_game_started = yes
					NOT = { has_title_flag = non_manual_law_change } # No opinion penalty
				}

				decreased_crown_authority_effect = yes
			}
		}

		effect = {
			# log = "crown_authority_0 ([This.GetFullBaseName])"

			if  = {
				limit = { NOT = { has_dlc = "Conclave" } }

				set_the_kings_peace = no
				set_the_kings_full_peace = no
				set_protected_inheritance = no
				set_allow_title_revokation = no
				set_allow_free_infidel_revokation = no
				# set_allow_free_revokation = no
				# set_appoint_generals = no
				# set_appoint_regents = no
			}

			revoke_law = crown_authority_1
			revoke_law = crown_authority_2
			revoke_law = crown_authority_3
			revoke_law = crown_authority_4
		}

		ai_will_do = {
			factor = 0.01

			trigger = {
				holder_scope = {
					NOR = {
						trait = content
						trait = ambitious
					}
				}
			}

			mult_modifier = {
				factor = 2

				holder_scope = {
					OR = {
						trait = dull
						trait = socializer
						trait = naive_appeaser
						trait = underhanded_rogue
						trait = charismatic_negotiator
						trait = grey_eminence
					}
				}
			}

			mult_modifier = {
				factor = 2

				holder_scope = {
					OR = {
						trait = charitable
						trait = kind
						trait = humble
					}
				}
			}
		}
	}

	crown_authority_1 = {
		group = crown_authority

		castle_vassal_max_levy = 0.05
		city_vassal_max_levy = 0.05
		temple_vassal_max_levy = 0.05

		castle_vassal_min_levy = 0.05
		city_vassal_min_levy = 0.05
		temple_vassal_min_levy = 0.05

		vassal_limit = 7
		demesne_size = 1

		potential = {
			is_law_potential = crown_authority_0
		}

		allow = {
			show_only_failed_conditions = yes

			OR = {
				has_law = crown_authority_0
				has_law = crown_authority_2
			}

			trigger_if = {
				limit = {
					NOR = {
						has_law = crown_authority_2
						has_law = crown_authority_3
						has_law = crown_authority_4
					}
				}

				show_only_failed_conditions = yes

				holder_scope = {
					show_scope_change = no

					plus_law_prestige_trigger_1 = yes
					NOT = { trait = uncrowned }
				}
			}
		}

		pass_effect = {
			# log = "crown_authority_1 pass ([This.GetFullBaseName])"

			if = {
				limit = {
					has_game_started = yes
					NOT = { has_title_flag = non_manual_law_change } # No opinion penalty
				}

				if = {
					limit = { has_law = crown_authority_0 }
					increased_crown_authority_effect = yes
				}
				else = {
					decreased_crown_authority_effect = yes
				}
			}

			if = {
				limit = {
					has_law = crown_authority_0
					has_title_flag = do_not_destroy
				}

				clr_title_flag = do_not_destroy
			}

			if = {
				limit = {
					NOR = {
						has_law = crown_authority_2
						has_law = crown_authority_3
						has_law = crown_authority_4
					}
				}

				plus_law_change_prestige_effect_1 = yes
			}
		}

		effect = {
			# log = "crown_authority_1 ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				if = {
					limit = {
						NOR = {
							has_law = crown_authority_2
							has_law = crown_authority_3
							has_law = crown_authority_4
						}
					}

					plus_law_change_prestige_effect_1 = yes
				}
			}

			if = {
				limit = { NOT = { has_dlc = "Conclave" } }

				set_the_kings_peace = no
				set_the_kings_full_peace = no
				set_protected_inheritance = no
				set_allow_title_revokation = yes
				set_allow_free_infidel_revokation = no

				# set_allow_free_revokation = no
				# set_appoint_generals = yes
				# set_appoint_regents = no
			}

			if = {
				limit = { has_law = crown_authority_0 }
				custom_tooltip = { text = enables_tribal_levy_laws }
			}

			hidden_effect = {
				revoke_law = crown_authority_0
				revoke_law = crown_authority_2
				revoke_law = crown_authority_3
				revoke_law = crown_authority_4
				set_tribal_vassal_levy_control = yes
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				holder_scope = {
					NOT = { trait = content }
				}
			}

			mult_modifier = {
				factor = 0.01
				holder_scope = { has_law = crown_authority_2 }
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_2

				holder_scope = {
					OR = {
						trait = dull
						trait = socializer
						trait = naive_appeaser
						trait = underhanded_rogue
						trait = charismatic_negotiator
						trait = grey_eminence
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_2

				holder_scope = {
					OR = {
						trait = charitable
						trait = kind
						trait = humble
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_0

				holder_scope = {
					OR = {
						trait = shrewd
						trait = administrator
						trait = indulgent_wastrel
						trait = thrifty_clerk
						trait = fortune_builder
						trait = midas_touched
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_0

				holder_scope = {
					OR = {
						trait = greedy
						trait = envious
						trait = proud
					}
				}
			}

			mult_modifier = {
				factor = 10

				has_law = crown_authority_0

				holder_scope = {
					trait = ambitious
				}
			}
		}
	}

	crown_authority_2 = {
		group = crown_authority

		feudal_opinion = -5
		city_opinion = -5
		temple_opinion = -5

		castle_vassal_max_levy = 0.1
		city_vassal_max_levy = 0.1
		temple_vassal_max_levy = 0.1

		castle_vassal_min_levy = 0.1
		city_vassal_min_levy = 0.1
		temple_vassal_min_levy = 0.1

		vassal_limit = 4
		demesne_size = 2

		potential = {
			is_law_potential = crown_authority_0
		}

		allow = {
			show_only_failed_conditions = yes

			OR = {
				has_law = crown_authority_1
				has_law = crown_authority_3
			}

			holder_scope = {
				show_scope_change = no
				is_not_unreformed_pagan_trigger = yes
			}

			trigger_if = {
				limit = {
					NOR = {
						has_law = crown_authority_3
						has_law = crown_authority_4
					}
				}

				show_only_failed_conditions = yes

				holder_scope = {
					show_scope_change = no

					plus_law_prestige_trigger_2 = yes
					NOT = { trait = uncrowned }
				}
			}
		}

		pass_effect = {
			# log = "crown_authority_2 pass ([This.GetFullBaseName])"

			if = {
				limit = {
					has_game_started = yes
					NOT = { has_title_flag = non_manual_law_change } # No opinion penalty
				}

				if = {
					limit = { has_law = crown_authority_1 }
					increased_crown_authority_effect = yes
				}
				else = {
					decreased_crown_authority_effect = yes
				}
			}

			if = {
				limit = {
					NOR = {
						has_law = crown_authority_3
						has_law = crown_authority_4
					}
				}

				plus_law_change_prestige_effect_2 = yes
			}
		}

		effect = {
			# log = "crown_authority_2 ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				if = {
					limit = {
						NOR = {
							has_law = crown_authority_3
							has_law = crown_authority_4
						}
					}

					plus_law_change_prestige_effect_2 = yes
				}
			}

			if = {
				limit = { NOT = { has_dlc = "Conclave" } }

				set_the_kings_peace = yes
				set_the_kings_full_peace = no
				set_protected_inheritance = no
				set_allow_title_revokation = yes
				set_allow_free_infidel_revokation = yes
				# set_allow_free_revokation = no
				# set_appoint_generals = yes
				# set_appoint_regents = no
			}

			if = {
				limit = { has_law = crown_authority_0 }
				custom_tooltip = { text = enables_tribal_levy_laws }
			}

			hidden_effect = {
				revoke_law = crown_authority_0
				revoke_law = crown_authority_1
				revoke_law = crown_authority_3
				revoke_law = crown_authority_4
				set_tribal_vassal_levy_control = yes
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				holder_scope = {
					NOT = { trait = content }
				}
			}

			mult_modifier = {
				factor = 0.01
				has_law = crown_authority_3
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_3

				holder_scope = {
					OR = {
						trait = dull
						trait = socializer
						trait = naive_appeaser
						trait = underhanded_rogue
						trait = charismatic_negotiator
						trait = grey_eminence
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_3

				holder_scope = {
					OR = {
						trait = charitable
						trait = kind
						trait = humble
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_1

				holder_scope = {
					OR = {
						trait = shrewd
						trait = administrator
						trait = indulgent_wastrel
						trait = thrifty_clerk
						trait = fortune_builder
						trait = midas_touched
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_1

				holder_scope = {
					OR = {
						trait = greedy
						trait = envious
						trait = proud
					}
				}
			}

			mult_modifier = {
				factor = 10

				has_law = crown_authority_1

				holder_scope = {
					trait = ambitious
				}
			}
		}
	}

	crown_authority_3 = {
		group = crown_authority

		feudal_opinion = -10
		city_opinion = -10
		temple_opinion = -10

		castle_vassal_max_levy = 0.15
		city_vassal_max_levy = 0.15
		temple_vassal_max_levy = 0.15

		castle_vassal_min_levy = 0.15
		city_vassal_min_levy = 0.15
		temple_vassal_min_levy = 0.15

		vassal_limit = 2
		demesne_size = 3

		potential = {
			is_law_potential = crown_authority_0
		}

		allow = {
			show_only_failed_conditions = yes

			OR = {
				has_law = crown_authority_2
				has_law = crown_authority_4
			}

			holder_scope = {
				show_scope_change = no

				is_republic = no
				is_not_unreformed_pagan_trigger = yes
			}

			trigger_if = {
				limit = { NOT = { has_law = crown_authority_4 } }

				show_only_failed_conditions = yes

				holder_scope = {
					show_scope_change = no

					plus_law_prestige_trigger_3 = yes
					NOT = { trait = uncrowned }
				}
			}

			trigger_if = {
				limit = {
					title = e_byzantium
					NOT = { has_law = crown_authority_4 }
				}

				holder_scope = {
					show_scope_change = no
					trait = strong_basileus
				}
			}
		}

		pass_effect = {
			# log = "crown_authority_3 pass ([This.GetFullBaseName])"

			if = {
				limit = {
					has_game_started = yes
					NOT = { has_title_flag = non_manual_law_change } # No opinion penalty
				}

				if = {
					limit = { has_law = crown_authority_2 }
					increased_crown_authority_effect = yes
				}
				else = {
					decreased_crown_authority_effect = yes
				}
			}

			if = {
				limit = { NOT = { has_law = crown_authority_4 } }
				plus_law_change_prestige_effect_3 = yes
			}
		}

		effect = {
			# log = "crown_authority_3 ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				if = {
					limit = { NOT = { has_law = crown_authority_4 } }
					plus_law_change_prestige_effect_3 = yes
				}
			}

			if = {
				limit = { NOT = { has_dlc = "Conclave" } }

				set_the_kings_peace = yes
				set_the_kings_full_peace = no
				set_protected_inheritance = yes
				set_allow_title_revokation = yes
				set_allow_free_infidel_revokation = yes
				# set_allow_free_revokation = no
				# set_appoint_generals = yes
				# set_appoint_regents = yes
			}

			hidden_effect = {
				set_tribal_vassal_levy_control = yes
				revoke_law = crown_authority_0
				revoke_law = crown_authority_1
				revoke_law = crown_authority_2
				revoke_law = crown_authority_4
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				holder_scope = {
					NOT = { trait = content }
					ruled_years >= 10
				}
			}

			mult_modifier = {
				factor = 0.01
				holder_scope = { has_law = crown_authority_4 }
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_4

				holder_scope = {
					OR = {
						trait = dull
						trait = socializer
						trait = naive_appeaser
						trait = underhanded_rogue
						trait = charismatic_negotiator
						trait = grey_eminence
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_4

				holder_scope = {
					OR = {
						trait = charitable
						trait = kind
						trait = humble
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_2

				holder_scope = {
					OR = {
						trait = shrewd
						trait = administrator
						trait = indulgent_wastrel
						trait = thrifty_clerk
						trait = fortune_builder
						trait = midas_touched
					}
				}
			}

			mult_modifier = {
				factor = 2

				has_law = crown_authority_2

				holder_scope = {
					OR = {
						trait = greedy
						trait = envious
						trait = proud
					}
				}
			}

			mult_modifier = {
				factor = 10

				has_law = crown_authority_2

				holder_scope = {
					trait = ambitious
				}
			}
		}
	}

	crown_authority_4 = {
		group = crown_authority

		feudal_opinion = -15
		city_opinion = -15
		temple_opinion = -15

		castle_vassal_max_levy = 0.2
		city_vassal_max_levy = 0.2
		temple_vassal_max_levy = 0.2

		castle_vassal_min_levy = 0.2
		city_vassal_min_levy = 0.2
		temple_vassal_min_levy = 0.2

		demesne_size = 4

		potential = {
			is_law_potential = crown_authority_0
		}

		allow = {
			show_only_failed_conditions = yes

			has_law = crown_authority_3

			holder_scope = {
				show_scope_change = no

				is_republic = no
				is_not_unreformed_pagan_trigger = yes
				plus_law_prestige_trigger_4 = yes
				NOT = { trait = uncrowned }
			}

			trigger_if = {
				limit = { title = e_byzantium }

				holder_scope = {
					show_scope_change = no
					trait = strong_basileus
				}
			}
		}

		pass_effect = {
			# log = "crown_authority_4 pass ([This.GetFullBaseName])"

			if = {
				limit = {
					has_game_started = yes
					NOT = { has_title_flag = non_manual_law_change } # No opinion penalty
				}

				increased_crown_authority_effect = yes
			}

			plus_law_change_prestige_effect_4 = yes
		}

		effect = {
			# log = "crown_authority_4 ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				plus_law_change_prestige_effect_4 = yes
			}

			if = {
				limit = { NOT = { has_dlc = "Conclave" } }

				set_the_kings_peace = yes
				set_the_kings_full_peace = yes
				set_protected_inheritance = yes
				set_allow_title_revokation = yes
				set_allow_free_infidel_revokation = yes
				# set_allow_free_revokation = yes
				# set_appoint_generals = yes
				# set_appoint_regents = yes
			}

			hidden_effect = {
				set_tribal_vassal_levy_control = yes
				revoke_law = crown_authority_0
				revoke_law = crown_authority_1
				revoke_law = crown_authority_2
				revoke_law = crown_authority_3
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				holder_scope = {
					NOT = { trait = content }
					ruled_years >= 10
				}
			}

			mult_modifier = {
				factor = 2

				holder_scope = {
					OR = {
						trait = shrewd
						trait = administrator
						trait = indulgent_wastrel
						trait = thrifty_clerk
						trait = fortune_builder
						trait = midas_touched
					}
				}
			}

			mult_modifier = {
				factor = 2

				holder_scope = {
					OR = {
						trait = greedy
						trait = envious
						trait = proud
					}
				}
			}

			mult_modifier = {
				factor = 10
				holder_scope = { trait = ambitious }
			}
		}
	}

	# INVESTITURE

	# Papal Investiture
	investiture_law_0 = {
		group = investiture_law
		default = yes

		potential = {
			holder_scope = {
				show_scope_change = no

				OR = {
					religion = catholic
					religion = fraticelli
				}

				is_tribal = no
				is_nomadic = no
				NOT = { rightful_religious_head = THIS }
			}
		}

		allow = {
			show_only_failed_conditions = yes

			year >= 1059 # In nomine Domini Codified by Benedict X

			holder_scope = {
				show_scope_change = no
				plus_law_prestige_trigger_1 = yes
				NOT = { trait = uncrowned }
			}
		}

		pass_effect = {
			# log = "investiture_law_0 ([This.GetFullBaseName])"
			plus_law_change_prestige_effect_1 = yes
		}

		effect = {
			# log = "investiture_law_0 pass ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				plus_law_change_prestige_effect_1 = yes
			}

			set_investiture = head
			revoke_law = investiture_law_1
		}

		ai_will_do = {
			factor = 0.002 # Rare to do this

			trigger = {
				holder_scope = {
					NOT = { trait = cynical }
				}
			}

			mult_modifier = {
				factor = 10
				holder_scope = { trait = zealous }
			}
		}

		default_selection = {
			factor = 10

			trigger = {
				OR = {
					holy_order = yes
					year >= 1059
				}
			}
		}
	}

	# Free Investiture
	investiture_law_1 = {
		group = investiture_law

		rel_head_opinion = -20
		free_invest_vassal_opinion = 5 # vassals with bishops will appreciate this law
		temple_all_opinion = 10 # Bishops will tend to be more loyal to the Crown

		potential = {
			is_law_potential = investiture_law_0
		}

		allow = {
			show_only_failed_conditions = yes

			holy_order = no

			holder_scope = {
				show_scope_change = no
				plus_law_prestige_trigger_1 = yes
				NOT = { trait = uncrowned }
			}
		}

		pass_effect = {
			# log = "investiture_law_1 ([This.GetFullBaseName])"
			plus_law_change_prestige_effect_1 = yes
		}

		effect = {
			# log = "investiture_law_1 pass ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				plus_law_change_prestige_effect_1 = yes
			}

			set_investiture = any
			revoke_law = investiture_law_0
		}

		ai_will_do = {
			factor = 0.002 # Rare to do this

			trigger = {
				holder_scope = {
					NOT = { trait = zealous }
				}
			}

			mult_modifier = {
				factor = 10
				holder_scope = { trait = cynical }
			}
		}

		default_selection = {
			factor = 1
		}
	}
}