﻿# Definition of lease used for organized churches. Required for the game to run.
theocracy_lease = {
	hierarchy = {
		type = vassal
		ruler_valid = {
			rite ?= { rite_has_doctrine = doctrine_theocracy_temporal }
			NOT = { government_has_flag = government_is_theocracy }
		}
		liege_or_vassal_valid = {
			faith = scope:target.faith
		}
		lessee = cp:councillor_court_chaplain
		barony_valid = {
			title_province = { has_holding_type = church_holding }
		}
	}

	government = theocracy_government
	valid_holdings = { church_holding }
	ruler_share_min_opinion_from_lessee = 1
	hook_strength_max_opinion = strong

	tax_split = {
		lease_liege = 0.25
		ruler_max = 0.25
		ruler = {
			if = {
				limit = {
					scope:lessee = {
						court_chaplain_endorse_override_trigger = yes
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_STRONG_HOOK
					value = 0.25
				}
			}
			else_if = {
				limit = { is_ai = yes }
				add = {
					desc = THEOCRATIC_LEASE_RATIO_FROM_OPINION
					value = {
						scope:lessee = { value = "opinion(scope:ruler)" }
					}
					divide = 400
				}
			}

			save_temporary_value_as = current_total
			if = {
				limit = { scope:current_total > 0.25 }
				max = {
					desc = THEOCRATIC_LEASE_RATIO_MAX_25
					value = 0.25
				}
			}
		}
	}

	levy_split = {
		lease_liege = 0.15
		ruler_max = 0.50
		ruler = {
			if = {
				limit = {
					scope:lessee = { court_chaplain_endorse_override_trigger = yes }
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_STRONG_HOOK
					value = 0.5
				}
			}
			else = {
				add = {
					desc = THEOCRATIC_LEASE_RATIO_FROM_OPINION
					value = {
						scope:lessee = { value = "opinion(scope:ruler)" }
					}
					divide = 200
				}
			}
			max = 0.5
		}
	}
}


# Definition of lease used for Ecclesiastical churches (Christian)
ecclesiastical_lease = {
	hierarchy = {
		type = clerical_region
		ruler_valid = {
			rite = { rite_has_doctrine = doctrine_theocracy_temporal }
			NOT = { government_has_flag = government_is_ecclesiastical }
		}
		liege_or_vassal_valid = {
			faith = scope:target.faith
		}
		lessee = cp:councillor_court_chaplain	# should be a councillor

		barony_valid = {
			title_province = {
				has_holding_type = church_holding
			}
			# Allow Ecclesiastical rulers to hold temples directly
			NOT = {
				county = {
					holder = {
						government_has_flag = government_is_ecclesiastical
					}
				}
			}
		}
	}

	government = ecclesiastical_government
	valid_holdings = { church_holding }

	ruler_share_min_opinion_from_lessee = 1
	hook_strength_max_opinion = strong

	tax_split = {
		lease_liege = {
			value = 0
			if = {
				limit = {
					scope:lease_liege = {
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_minimal_centralization
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_MINIMAL_CENTRALIZATION
					value = 0.05
				}
			}
			else_if = {
				limit = {
					scope:lease_liege = {
						OR = {
							top_participant_group:the_christian_church ?= {
								has_participant_group_parameter = the_christian_church_mild_centralization
							}
							# Default for Ecclesiasticals outside of the situation
							NOT = { exists = top_participant_group:the_christian_church }
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_MILD_CENTRALIZATION
					value = 0.1
				}
			}
			else_if = {
				limit = {
					scope:lease_liege = {
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_strong_centralization
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_STRONG_CENTRALIZATION
					value = 0.20
				}
			}
			# Lessee Bishops don't pay hierarchical to the pope (they need a Clerical Region to exist)
			if = {
				limit = {
					is_landed = no # Local bishop lessee
					top_superior = scope:lease_liege # Head of Faith is superior
					NOT = { exists = liege.capital_county.clerical_region_title } # We don't have a clerical region
				}
				max = {
					desc = THEOCRATIC_LEASE_RATIO_MISSING_CLERICAL_REGION
					value = 0.001
				}
			}
		}
		top_lease_liege_direct = {
			value = 0
			if = {
				limit = {
					scope:lease_liege = {
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_strong_centralization
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_STRONG_CENTRALIZATION
					value = 0.01
				}
			}
		}

		ruler_max = 0.25	# Ceiling on the ruler's share, also quoted by the 'up to' tooltips.
		ruler = {
			value = 0
			if = {
				limit = {
					scope:lessee = {
						court_chaplain_endorse_override_trigger = yes
					}
					scope:ruler = {
						OR = {
							top_participant_group:the_christian_church ?= {
								has_participant_group_parameter = the_christian_church_personal_secular_obligations
							}
							# Default for Christians outside of the situation
							NOT = { exists = top_participant_group:the_christian_church }
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_STRONG_HOOK
					value = 0.25
				}
			}
			else_if = {
				limit = {
					scope:lessee = {
						is_ai = yes
						court_chaplain_endorse_override_trigger = no
					}
					scope:ruler = {
						OR = {
							top_participant_group:the_christian_church ?= {
								has_participant_group_parameter = the_christian_church_personal_secular_obligations
							}
							# Default for Christians outside of the situation
							NOT = { exists = top_participant_group:the_christian_church }
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_FROM_OPINION
					value = {
						scope:lessee = { value = "opinion(scope:ruler)" }
					}
					divide = 400 # Divide opinion -100/+100 with 400 gives range -0.25/+0.25
				}
			}
			else_if = {
				limit = {
					scope:ruler = {
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_fixed_secular_obligations
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_FIXED_OBLIGATIONS
					value = 0.15
				}
			}
			if = {
				limit = {
					scope:ruler = {
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_local_secular_power
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_LOCAL_SECULAR_POWER
					value = 0.10
				}
			}
			save_temporary_value_as = current_total
			if = {
				limit = {
					scope:current_total > 0.25
				}
				max = {
					desc = THEOCRATIC_LEASE_RATIO_MAX_25
					value = 0.25
				}
			}
		}
	}

	levy_split = {
		lease_liege = 0.15

		ruler_max = 0.50	# Ceiling on the ruler's share, also quoted by the 'up to' tooltips.
		ruler = {
			if = {
				limit = {
					scope:ruler = {
						OR = {
							has_strong_hook = scope:lessee
							top_participant_group:the_christian_church ?= {
								has_participant_group_parameter = the_christian_church_fixed_secular_obligations
							}
						}
					}
				}
				add = {
					desc = THEOCRATIC_LEASE_RATIO_STRONG_HOOK
					value = 0.50
				}
			}
			else = {
				add = {
					desc = THEOCRATIC_LEASE_RATIO_FROM_OPINION
					value = {
						scope:lessee = { value = "opinion(scope:ruler)" }
					}
					divide = 200 # Divide opinion range -100/+100 with 200 gives range -0.5/+0.5
				}
			}
			max = 0.50
		}
	}
}
