﻿@crown_authority_cooldown_years = 20
@tribal_authority_cooldown_years = 10

crown_authority = {
	default = crown_authority_1
	cumulative = yes
	flag = realm_law
	
	crown_authority_0 = {
		modifier = {
			direct_vassal_opinion = 10
			#feudal_government_tax_contribution_mult = -0.1
			#vassal_levy_contribution_mult = -0.1
		}

		can_have = { realm_law_use_crown_authority = yes }
	}
	
	crown_authority_1 = {
		modifier = {
			direct_vassal_opinion = -10
			#feudal_government_tax_contribution_mult = 0.1
			#vassal_levy_contribution_mult = 0.1
		}
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		flag = can_change_partition_succession_laws

		can_have = { realm_law_use_crown_authority = yes }

		can_pass = {
			trigger_if = {
				limit = { has_realm_law = crown_authority_0 }
				custom_description = {
					subject = root
					text = "has_crown_authority_cooldown"
					NOT = { has_variable = crown_authority_cooldown }
				}
			}
			root.culture = { has_innovation = innovation_plenary_assemblies }
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOR = {
							has_realm_law = crown_authority_2
							has_realm_law = crown_authority_3
						}
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			if = {
				limit = {
					NOT = { has_realm_law = crown_authority_2 }
				}
			}
			set_variable = {
				name = crown_authority_cooldown
				years = @crown_authority_cooldown_years
			}
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = crown_authority_0 }
				value = 1
			}
		}
	}
	
	crown_authority_2 = {
		modifier = {
			direct_vassal_opinion = -10
			feudal_government_tax_contribution_mult = 0.1
			vassal_levy_contribution_mult = 0.1
		}
		flag = vassal_internal_wars_banned
		flag = vassal_refusal_is_treason
		flag = can_change_succession_laws
		flag = titles_cannot_leave_realm_on_succession # Hardcoded flag
		
		can_have = { realm_law_use_crown_authority = yes }

		can_pass = {
			trigger_if = {
				limit = {
					NOT = { has_realm_law = crown_authority_3 }
				}
				has_realm_law = crown_authority_1
				custom_description = {
					subject = root
					text = "has_crown_authority_cooldown"
					NOT = { has_variable = crown_authority_cooldown }
				}
			}
			root.culture = { has_innovation = innovation_primogeniture }
		}

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law = crown_authority_3 }
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			if = {
				limit = {
					NOT = { has_realm_law = crown_authority_3 }
				}
			}
			set_variable = {
				name = crown_authority_cooldown
				years = @crown_authority_cooldown_years
			}
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = crown_authority_1 }
				value = 1
			}
		}
	}
	
	crown_authority_3 = {
		modifier = {
			direct_vassal_opinion = -20
			feudal_government_tax_contribution_mult = 0.25
			vassal_levy_contribution_mult = 0.25
		}
		flag = vassal_all_wars_banned
		flag = can_designate_heirs
		
		can_have = { realm_law_use_crown_authority = yes }

		can_pass = {
			has_realm_law = crown_authority_2
			custom_description = {
				subject = root
				text = "has_crown_authority_cooldown"
				NOT = { has_variable = crown_authority_cooldown }
			}
			root.culture = { has_innovation = innovation_primogeniture }
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law = crown_authority_3 }
					}
					add = increase_crown_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			set_variable = {
				name = crown_authority_cooldown
				years = @crown_authority_cooldown_years
			}
		}
	}
}

tribal_authority = {
	default = tribal_authority_1
	cumulative = yes
	flag = realm_law
	
	tribal_authority_0 = {
		modifier = { direct_vassal_opinion = 10 }

		can_have = { realm_law_use_crown_authority = no }
		#Imprisonment is disabled if you have this law. Script is in the interaction, currently in 00_prison_interactions.
	}
	
	tribal_authority_1 = {
		modifier = { direct_vassal_opinion = -10 }
		
		can_have = { realm_law_use_crown_authority = no }

		can_pass = {
			trigger_if = {
				limit = { has_realm_law = tribal_authority_0 }
				custom_description = {
					subject = root
					text = "has_tribal_authority_cooldown"
					NOT = { has_variable = tribal_authority_cooldown }
				}
			}
		}
		
		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOR = {
							has_realm_law = tribal_authority_2
							has_realm_law = tribal_authority_3
						}
					}
					add = increase_tribal_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			if = {
				limit = {
					NOR = {
						has_realm_law = tribal_authority_2
						has_realm_law = tribal_authority_3
					}
				}
			}
			set_variable = {
				name = tribal_authority_cooldown
				years = @tribal_authority_cooldown_years
			}
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = tribal_authority_0 }
				value = 1
			}
		}
	}
	
	tribal_authority_2 = {
		modifier = { direct_vassal_opinion = -10 }
		flag = title_revocation_allowed
		flag = vassal_retraction_allowed
		
		can_have = { realm_law_use_crown_authority = no }
		
		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"
					NOT = { has_variable = tribal_authority_cooldown }
				}
			}
		}

		pass_cost = {
			prestige = {
				if = {
					limit = {
						NOT = { has_realm_law = tribal_authority_3 }
					}
					add = increase_tribal_authority_prestige_cost
				}
			}
		}
		
		on_pass = {
			if = {
				limit = {
					NOT = { has_realm_law = tribal_authority_3 }
				}
			}
			set_variable = {
				name = tribal_authority_cooldown
				years = @tribal_authority_cooldown_years
			}
		}

		ai_will_do = {
			if = {
				limit = { has_realm_law = tribal_authority_1 }
				value = 1
			}
		}
	}
	
	tribal_authority_3 = {
		modifier = { direct_vassal_opinion = -20 }
		#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_have = { realm_law_use_crown_authority = no }
		
		can_pass = {
			has_realm_law = tribal_authority_2
			custom_description = {
				subject = root
				text = "has_tribal_authority_cooldown"
				NOT = { has_variable = tribal_authority_cooldown }
			}
		}
		
		pass_cost = { prestige = increase_tribal_authority_prestige_cost }
		
		on_pass = {
			set_variable = {
				name = tribal_authority_cooldown
				years = @tribal_authority_cooldown_years
			}
		}

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