﻿spawn_celestial_governance_contract_effect = {
	save_scope_as = governor
	# Select the Contract Tier (somewhat randomized, based on your experience as a governor)
	random_list = {
		30 = {
			save_scope_value_as = {
				name = governance_task_contract_tier
				value = define:NTaskContract|LOW_TASK_CONTRACT_TIER
			}
		}
		20 = {
			save_scope_value_as = {
				name = governance_task_contract_tier
				value = define:NTaskContract|MEDIUM_TASK_CONTRACT_TIER
			}

			modifier = {
				add = 10
				has_trait = governor
			}
			modifier = {
				add = 10
				has_trait = governor
				has_trait_xp = {
					trait = governor
					value >= 40
				}
			}
		}
		10 = {
			save_scope_value_as = {
				name = governance_task_contract_tier
				value = define:NTaskContract|HIGH_TASK_CONTRACT_TIER
			}

			modifier = {
				add = 10
				has_trait = governor
			}
			modifier = {
				add = 10
				has_trait = governor
				has_trait_xp = {
					trait = governor
					value >= 40
				}
			}
			modifier = {
				add = 20
				has_trait = governor
				has_trait_xp = {
					trait = governor
					value >= 80
				}
			}
		}
	}

	# Select which contract to create
	trigger_event = {
		on_action = spawn_celestial_governance_contract_on_action
	}

	play_sound_effect = "event:/DLC/EP4/SFX/UI/domicile_buildings/tgp_ui_domicile_building_archives_japanese"
}

remove_other_grand_guardian_modifiers_effect = {
	hidden_effect = { # No need to show this
		# Let's check for the county opinion modifier first
		scope:liege ?= {
			# We check and scope to all counties to make sure we remove any stray modifiers in case the capital is moved, etc.
			every_realm_county = {
				limit = {
					any_county_province = {
						has_province_modifier = grand_guardian_guard_the_capital_modifier
					}
				}
				every_county_province = {
					limit = {
						has_province_modifier = grand_guardian_guard_the_capital_modifier
					}
					remove_province_modifier = grand_guardian_guard_the_capital_modifier
				}
			}
		}
	}
}

### Grand Mentor Task Effects ###
grand_mentor_mentoring_skill_effect = {
	send_interface_toast = {
		type = event_royal_court_good_with_text
		title = grand_mentor_mentoring_title
		desc = grand_mentor_mentoring_notification_desc
		left_icon = root
		right_icon = scope:target_character

		scope:target_character = { add_$SKILL$_skill = 1 }
	}
}

grand_mentor_mentoring_merit_effect = {
	send_interface_toast = {
		type = event_royal_court_good_with_text
		title = grand_mentor_mentoring_title
		desc = grand_mentor_mentoring_notification_desc
		left_icon = root
		right_icon = scope:target_character

		scope:target_character = { change_merit = major_merit_gain }
	}
}

grand_mentor_mentoring_trait_xp_effect = {
	send_interface_toast = {
		type = event_royal_court_good_with_text
		title = grand_mentor_mentoring_title
		desc = grand_mentor_mentoring_notification_desc
		left_icon = root
		right_icon = scope:target_character

		scope:target_character = {
			add_trait_xp = {
				trait = $TRAIT$
				value = 5
			}
		}
	}
}

grand_mentor_mentoring_trait_track_xp_effect = {
	send_interface_toast = {
		type = event_royal_court_good_with_text
		title = grand_mentor_mentoring_title
		desc = grand_mentor_mentoring_notification_desc
		left_icon = root
		right_icon = scope:target_character

		scope:target_character = {
			add_trait_xp = {
				trait = $TRAIT$
				track = $TRACK$
				value = 5
			}
		}
	}
}

# Rewards for contributing to upgrading the great wall
contributor_great_wall_reward_effect = {
	if = {
		limit = {
			this != scope:owner
			is_alive = yes
		}
		send_interface_toast = {
			title = great_project_contribution_msg_t
			left_icon = root
			right_icon = scope:owner

			if = {
				limit = {
					government_allows = merit
				}
				change_merit = monumental_merit_gain
			}
			if = {
				limit = {
					government_allows = administrative
				}
				change_influence = monumental_influence_gain
			}
			else = {
				add_prestige = major_prestige_gain
			}
		}
	}
}

great_project_notify_completion = {
	$CHARACTER$ ?= {
		send_interface_toast = {
			type = event_generic_neutral_text
			title = great_project_completed_msg_t
			left_icon = scope:founder
			right_icon = scope:province.county
			desc = great_project_completed_msg_desc
		}
	}
}

# root = contributor
great_project_notify_contribution = {
	if = {
		limit = {
			this != scope:owner
		}
		scope:owner ?= {
			send_interface_toast = {
				type = event_generic_good_with_text
				title = great_project_contributed_msg_t
				desc = great_project_contributed_msg_desc
				left_icon = root
				right_icon = scope:great_project.great_project_location.county
			}			
		}
	}
}

# If both owner and contributor are part of the Dynastic Cycle, trigger the contribution catalyst
great_project_contribution_catalyst_effect = {
	if = {
		limit = {
			this != scope:owner
			scope:owner ?= {
				any_character_situation = {
					situation_type = dynastic_cycle
				}
			}
			OR = {
				scope:great_project.great_project_type = great_project_type:great_wall
				scope:great_project.great_project_type = great_project_type:great_wall_extend_to_shanhai_pass
				scope:great_project.great_project_type = great_project_type:great_wall_extend_to_liaodong
				scope:great_project.great_project_type = great_project_type:minister_project_establish_control
			}
		}
		random_character_situation = {
			limit = { situation_type = dynastic_cycle }
			switch = {
				trigger = scope:great_project.great_project_type
				great_project_type:great_wall = { trigger_situation_catalyst = catalyst_great_project_great_wall_contribution }
				great_project_type:great_wall_extend_to_shanhai_pass = { trigger_situation_catalyst = catalyst_great_project_great_wall_contribution }
				great_project_type:great_wall_extend_to_liaodong = { trigger_situation_catalyst = catalyst_great_project_great_wall_contribution }
				great_project_type:minister_project_establish_control = { trigger_situation_catalyst = catalyst_great_project_establish_control_contribution }
			}
		}
	}
}

# root = contributor
great_project_reward_contribution_completion_notification_effect = {
	if = {
		limit = { this != scope:owner }
		send_interface_toast = {
			title = great_project_contribution_msg_t
			left_icon = root
			right_icon = scope:owner
			
			great_project_contribution_completion_reward_$LEVEL$_effect = { EXTRA_EFFECT = $NON_OWNER_REWARD_EFFECT$ }
		}
	}
	else = {
		send_interface_toast = {
			title = great_project_contribution_msg_t
			left_icon = root
			right_icon = scope:province
			
			great_project_contribution_completion_reward_$LEVEL$_effect = { EXTRA_EFFECT = $OWNER_REWARD_EFFECT$ }
		}
	}
}

great_project_contribution_completion_reward_major_effect = {
	great_project_reward_contribution_completion_actual_reward_effect = {
		LEGITIMACY_GAIN = minor_legitimacy_gain
		INFLUENCE_GAIN = medium_influence_gain
		GOVERNANCE_GAIN = 5
		PRESTIGE_GAIN_WITH_GOVERNANCE = minor_prestige_gain
		PRESTIGE_GAIN_FALLBACK = major_prestige_gain
		MERIT_GAIN = minor_merit_gain
		EXTRA_EFFECT = $EXTRA_EFFECT$
	}
}

great_project_contribution_completion_reward_minor_effect = {
	great_project_reward_contribution_completion_actual_reward_effect = {
		LEGITIMACY_GAIN = miniscule_legitimacy_gain
		INFLUENCE_GAIN = minor_influence_gain
		GOVERNANCE_GAIN = 2
		PRESTIGE_GAIN_WITH_GOVERNANCE = miniscule_prestige_gain
		PRESTIGE_GAIN_FALLBACK = minor_prestige_gain
		MERIT_GAIN = miniscule_merit_gain
		EXTRA_EFFECT = $EXTRA_EFFECT$
	}
}

great_project_reward_contribution_completion_actual_reward_effect = {
	if = {
		limit = {
			is_valid_for_legitimacy_change = yes
		}
		add_legitimacy = {
			value = $LEGITIMACY_GAIN$
			if = {
				limit = {
					any_character_situation = {
						situation_type = dynastic_cycle
						has_situation_top_phase_parameter = dynastic_cycle_great_projects_increased_legitimacy
					}
				}
				multiply = 2
			}
		}
	}
	else = {
		if = {
			limit = { government_allows = administrative }
			change_influence = $INFLUENCE_GAIN$
		}

		if = {
			limit = { is_governor = yes }
			increase_governance_effect = { VALUE = $GOVERNANCE_GAIN$ }
			add_prestige = $PRESTIGE_GAIN_WITH_GOVERNANCE$
		}
		else = {
			add_prestige = $PRESTIGE_GAIN_FALLBACK$
		}
		if = {
			limit = {
				government_allows = merit
				this != title:h_china.holder # Chinese Emperor does not "use" merit
			}
			change_merit = $MERIT_GAIN$
		}
	}
	$EXTRA_EFFECT$ = yes
}

great_project_reward_contribution_completion_stewardship_xp = {
	add_stewardship_lifestyle_xp = medium_lifestyle_xp
}

# This is cursed but necessary for the string substitution in great_project_reward_contribution_completion effects to work
great_project_reward_contribution_completion_null = {}

spawn_natural_disaster_contract_effect = {
	if = {
		limit = {
			is_governor = yes
			trigger_if = {
				limit = { is_ai = yes }
				is_available = yes
			}
		}
		save_scope_as = governor
		# Select the Contract Tier (somewhat randomized, based on your experience as a governor)
		random_list = {
			30 = {
				save_scope_value_as = {
					name = governance_task_contract_tier
					value = define:NTaskContract|LOW_TASK_CONTRACT_TIER
				}
			}
			20 = {
				save_scope_value_as = {
					name = governance_task_contract_tier
					value = define:NTaskContract|MEDIUM_TASK_CONTRACT_TIER
				}

				modifier = {
					add = 10
					has_trait = governor
				}
				modifier = {
					add = 10
					has_trait = governor
					has_trait_xp = {
						trait = governor
						value >= 40
					}
				}
			}
			10 = {
				save_scope_value_as = {
					name = governance_task_contract_tier
					value = define:NTaskContract|HIGH_TASK_CONTRACT_TIER
				}

				modifier = {
					add = 10
					has_trait = governor
				}
				modifier = {
					add = 10
					has_trait = governor
					has_trait_xp = {
						trait = governor
						value >= 40
					}
				}
				modifier = {
					add = 20
					has_trait = governor
					has_trait_xp = {
						trait = governor
						value >= 80
					}
				}
			}
		}

		# Select which contract to create
		trigger_event = {
			on_action = spawn_natural_disaster_contract_on_action
		}

		play_sound_effect = "event:/DLC/EP4/SFX/UI/domicile_buildings/tgp_ui_domicile_building_archives_japanese"
	}
}
# root = scope:character
# requires a scope:situation_participant_group to be saved beforehand
# ran on game start through the dynastic cycle script and on character joining a movement
set_movement_leader_and_power_effect = {
	save_scope_as = char
	bring_disciples_to_movement_effect = yes
	scope:situation_participant_group = {
		# set root as leader if leader doesn't exist yet
		if = {
			limit = {
				NOT = { exists = var:movement_leader }
			}
			set_variable = {
				name = movement_leader
				value = scope:char
			}
		}
		# update movement power
		set_variable = {
			name = movement_power
			value = movement_power_value
		}
	}
}
# root = scope:character
# requires a scope:situation_participant_group to be saved beforehand
bring_disciples_to_movement_effect = {
	#all of your disciples should always follow you
	save_temporary_scope_as = recipient #for loc
	every_relation = {
		type = disciple
		custom = every_disciple_joins_movement
		scope:situation_participant_group = {
			switch = {
				trigger = participant_group_type
				expansion_movement = {
					custom_tooltip = celestial_switch_movement_to_expansion_tt
					prev = {
						if = {
							limit = {
								is_ai = no
							}
							run_interaction = {
								interaction = celestial_ask_to_switch_movements_interaction
								actor = scope:recipient
								recipient = this
								send_threshold = decline
							}
						}
						else = {
							set_variable = {
								name = movement_member
								value = flag:expansion
							}
						}
					}
				}
				advancement_movement = {
					custom_tooltip = celestial_switch_movement_to_advancement_tt
					prev = {
						if = {
							limit = {
								is_ai = no
							}
							run_interaction = {
								interaction = celestial_ask_to_switch_movements_interaction
								actor = scope:recipient
								recipient = this
								send_threshold = decline
							}
						}
						else = {
							set_variable = {
								name = movement_member
								value = flag:advancement
							}
						}
					}
				}
				pro_hegemon_movement = {
					custom_tooltip = celestial_switch_movement_to_pro_hegemon_tt
					prev = {
						if = {
							limit = {
								is_ai = no
							}
							run_interaction = {
								interaction = celestial_ask_to_switch_movements_interaction
								actor = scope:recipient
								recipient = this
								send_threshold = decline
							}
						}
						else = {
							set_variable = {
								name = movement_member
								value = flag:pro_hegemon
							}
						}
					}
				}
				conservative_movement = {
					custom_tooltip = celestial_switch_movement_to_conservative_tt
					prev = {
						if = {
							limit = {
								is_ai = no
							}
							run_interaction = {
								interaction = celestial_ask_to_switch_movements_interaction
								actor = scope:recipient
								recipient = this
								send_threshold = decline
							}
						}
						else = {
							set_variable = {
								name = movement_member
								value = flag:conservative
							}
						}
					}
				}
			}
		}
		custom_tooltip = every_disciple_adds_movement_power_tt
		hidden_effect = { recalculate_participant_group = situation:dynastic_cycle }
	}
}

# root = scope:situation_participant_group
# Fallback configuration of making sure we have a movement leader
# We run this on the yearly pulse through the dynastic cycle script and on character leaving a movement
update_movement_leader_effect = {
	ordered_situation_group_participant = {
		order_by = var:movement_power # just set the character with highest movement_power
		scope:situation_participant_group = {
			set_variable = {
				name = movement_leader
				value = prev
			}
		}
	}
}

# For when a character becomes the new movement leader
# Use in a character scope
make_movement_leader_effect = {
	save_temporary_scope_as = new_movement_leader
	if = {
		limit = {
			any_character_situation = {
				situation_type = dynastic_cycle
				any_participant_group = {
					participant_group_has_character = scope:new_movement_leader
					NOR = { # Is not a group without a leader
						participant_group_type = hegemon_ruler
						participant_group_type = undecided_movement
						participant_group_type = other_rulers
					}
					save_temporary_scope_as = leaders_movement
				}
			}
		}
		custom_description = {
			text = make_movement_leader_effect_desc
			subject = scope:new_movement_leader
			object = scope:leaders_movement
			situation:dynastic_cycle ?= {
				random_participant_group = {
					limit = {
						participant_group_has_character = scope:new_movement_leader
					}
					set_variable = {
						name = movement_leader
						value = scope:new_movement_leader
					}
				}
			}
		}
		if = {
			limit = {
				scope:debate_loser ?= {
					this != scope:new_movement_leader
					var:movement_power < scope:new_movement_leader.var:movement_power
				}
			}
			switch = {
				trigger = scope:leaders_movement
				situation:dynastic_cycle.situation_participant_group:expansion_movement = {
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:new_movement_leader.top_liege
						CATALYST = catalyst_movement_gained_power_expansion
					}
				}
				situation:dynastic_cycle.situation_participant_group:advancement_movement = {
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:new_movement_leader.top_liege
						CATALYST = catalyst_movement_gained_power_advancement
					}
				}
				situation:dynastic_cycle.situation_participant_group:conservative_movement = {
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:new_movement_leader.top_liege
						CATALYST = catalyst_movement_gained_power_conservative
					}
				}
				situation:dynastic_cycle.situation_participant_group:pro_hegemon_movement = {
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:new_movement_leader.top_liege
						CATALYST = catalyst_movement_gained_power_pro_hegemon
					}
				}
			}
		}
	}
}

# root = scope:situation_participant_group
# ran on yearly pulse through the dynastic cycle script and on character leaving a movement
update_movement_power_effect = {
	set_variable = {
		name = movement_power
		value = movement_power_value
	}
}

# root = scope:character
update_character_movement_power_individual_effect = {
	set_variable = {
		name = movement_power_individual
		value = movement_power_character_individual_value
	}
}

# root = scope:characte
update_character_movement_power_disciples_effect = {
	set_variable = {
		name = movement_power_disciples
		value = {
			value = every_disciple_movement_power_value
			multiply = 0.25
		}
	}
}

# root = scope:character
# ran on yearly pulse through the dynastic cycle script and on character leaving a movement
update_character_movement_power_effect = {
	update_character_movement_power_individual_effect = yes
	update_character_movement_power_disciples_effect = yes
	set_variable = {
		name = movement_power
		value = {
			add = {
				value = var:movement_power_individual
			}
			add = {
				value = var:movement_power_disciples
			}
		}
	}
}

change_bureaucracy_laws_increase_effect = {
	scope:hegemon = {
		change_realm_law_level = { law_group = celestial_bureaucracy change = 1 }
	}
}
change_bureaucracy_laws_decrease_effect = {
	scope:hegemon = {
		change_realm_law_level = { law_group = celestial_bureaucracy change = -1 }
	}
}
change_army_laws_increase_effect = {
	scope:hegemon = {
		change_realm_law_level = { law_group = celestial_army_liege_law change = 1 }
	}
}
change_army_laws_decrease_effect = {
	scope:hegemon = {
		change_realm_law_level = { law_group = celestial_army_liege_law change = -1 }
	}
}
change_province_metropolitan_effect = {
	if = {
		limit = {
			NOT = { exists = scope:province_change_recipient }
		}
		custom_tooltip = change_province_metropolitan_effect.no_scope
	}
	else = {
		scope:province_change_recipient = {
			vassal_contract_set_obligation_level = {
				type = celestial_provinces
				level = 2
			}
			hidden_effect = {
				set_vassal_contract_modification_blocked = yes
				add_realm_law_skip_effects = celestial_appointment_succession_law
			}
		}
	}
}
change_province_industrial_effect = {
	if = {
		limit = {
			NOT = { exists = scope:province_change_recipient }
		}
		custom_tooltip = change_province_industrial_effect.no_scope
	}
	else = {
		scope:province_change_recipient = {
			vassal_contract_set_obligation_level = {
				type = celestial_provinces
				level = 1
			}
			hidden_effect = {
				set_vassal_contract_modification_blocked = yes
				add_realm_law_skip_effects = celestial_appointment_succession_law
			}
		}
	}
}
change_province_military_effect = {
	if = {
		limit = {
			NOT = { exists = scope:province_change_recipient }
		}
		custom_tooltip = change_province_military_effect.no_scope
	}
	else = {
		scope:province_change_recipient = {
			vassal_contract_set_obligation_level = {
				type = celestial_provinces
				level = 3
			}
			hidden_effect = {
				set_vassal_contract_modification_blocked = yes
				add_realm_law_skip_effects = celestial_military_appointment_succession_law
			}
		}
	}
}
change_province_protectorate_effect = {
	if = {
		limit = {
			NOT = { exists = scope:province_change_recipient }
		}
		custom_tooltip = change_province_protectorate_effect.no_scope
	}
	else = {
		scope:province_change_recipient = {
			vassal_contract_set_obligation_level = {
				type = celestial_provinces
				level = 4
			}
			hidden_effect = {
				set_vassal_contract_modification_blocked = yes
				add_realm_law_skip_effects = celestial_military_appointment_succession_law
			}
		}
	}
}
hold_examinations_effect = {
	custom_tooltip = celestial_movement_demands_interaction.tt.hold_examinations_effect
	hidden_effect = {   
		scope:hegemon = {
			add_character_flag = {
			flag = examinations_ai_override
			}
			ai_attempt_to_host_activity = activity_imperial_examination
		}
	}
}
change_retirement_law_increase_effect = {
	scope:hegemon = {
		change_realm_law_level = { law_group = celestial_retirement_law change = -1 }
	}
}
change_retirement_law_decrease_effect = {
	scope:hegemon = {
		change_realm_law_level = { law_group = celestial_retirement_law change = 1 }
	}
}
change_candidate_score_law_effect = {
	scope:hegemon = {
		if = {
			limit = {
			has_realm_law = candidate_score_merit_law
			}
			add_realm_law_skip_effects = candidate_score_prestige_law
		}
		else = {
			add_realm_law_skip_effects = candidate_score_merit_law
		}
	}
}
increase_budget_salary_effect = {
	scope:hegemon = {
		if = {
			limit = {
			scope:petitioner.var:budget_change ?= flag:decrease_ministry
			}
			change_realm_law_level = { law_group = budget_allocation_salary_law change = 1 }
			change_realm_law_level = { law_group = budget_allocation_ministry_law change = -1 }
		}
		else = {
			change_realm_law_level = { law_group = budget_allocation_salary_law change = 1 }
			change_realm_law_level = { law_group = budget_allocation_military_law change = -1 }

		}
		enact_treasury_budgets_no_costs = yes
	}
}
increase_budget_ministry_effect = {
	scope:hegemon = {
		if = {
			limit = {
			scope:petitioner.var:budget_change ?= flag:decrease_salary
			}
			change_realm_law_level = { law_group = budget_allocation_ministry_law change = 1 }
			change_realm_law_level = { law_group = budget_allocation_salary_law change = -1 }
		}
		else = {
			change_realm_law_level = { law_group = budget_allocation_ministry_law change = 1 }
			change_realm_law_level = { law_group = budget_allocation_military_law change = -1 }

		}
		enact_treasury_budgets_no_costs = yes
	}
}
increase_budget_military_effect = {
	scope:hegemon = {
		if = {
			limit = {
			scope:petitioner.var:budget_change ?= flag:decrease_ministry
			}
			change_realm_law_level = { law_group = budget_allocation_military_law change = 1 }
			change_realm_law_level = { law_group = budget_allocation_ministry_law change = -1 }
		}
		else = {
			change_realm_law_level = { law_group = budget_allocation_military_law change = 1 }
			change_realm_law_level = { law_group = budget_allocation_salary_law change = -1 }

		}
		enact_treasury_budgets_no_costs = yes
	}
}

grant_movement_petition_tooltip_effect = {
	show_as_tooltip = {
		switch = {
			trigger = scope:movement_petition_effect
			flag:change_bureaucracy_laws_increase = {
				change_bureaucracy_laws_increase_effect = yes
			}
			flag:change_bureaucracy_laws_decrease = {
				change_bureaucracy_laws_decrease_effect = yes
			}
			flag:change_army_laws_increase = {
				change_army_laws_increase_effect = yes
			}
			flag:change_army_laws_decrease = {
				change_army_laws_decrease_effect = yes
			}
			flag:change_province_metropolitan = {
				change_province_metropolitan_effect = yes
			}
			flag:change_province_industrial = {
				change_province_industrial_effect = yes
			}
			flag:change_province_military = {
				change_province_military_effect = yes
			}
			flag:change_province_protectorate = {
				change_province_protectorate_effect = yes
			}
			flag:hold_examinations = {
				hold_examinations_effect = yes
			}
			flag:change_retirement_law_increase = {
				change_retirement_law_increase_effect = yes
			}
			flag:change_retirement_law_decrease = {
				change_retirement_law_decrease_effect = yes
			}
			flag:change_candidate_score_law = {
				change_candidate_score_law_effect = yes
			}
			flag:increase_budget_salary = {
				increase_budget_salary_effect = yes
			}
			flag:increase_budget_ministry = {
				increase_budget_ministry_effect = yes
			}
			flag:increase_budget_military = {
				increase_budget_military_effect = yes
			}
		}
		situation:dynastic_cycle ?= {
			if = {
				limit = {
				situation_top_has_catalyst = catalyst_hegemon_influenced_by_interaction  
				}
				trigger_situation_catalyst = {
				catalyst = catalyst_hegemon_influenced_by_interaction
				character = scope:petitioner
				}
			}
		}
		scope:hegemon = {
			add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_gain }
		}
		#set a cooldown variable in case the leader changes
		scope:actors_movement = {
			petition_change_movement_power_effect = {
				VALUE = 100
			}
			set_variable = {
				name = recent_movement_petition
				value = scope:petitioner
				years = 3
			}
		}
	}
}
grant_movement_petition_effect = {
	switch = {
		trigger = scope:petitioner.var:movement_petition
		flag:change_bureaucracy_laws_increase = {
			change_bureaucracy_laws_increase_effect = yes
		}
		flag:change_bureaucracy_laws_decrease = {
			change_bureaucracy_laws_decrease_effect = yes
		}
		flag:change_army_laws_increase = {
			change_army_laws_increase_effect = yes
		}
		flag:change_army_laws_decrease = {
			change_army_laws_decrease_effect = yes
		}
		flag:change_province_metropolitan = {
			change_province_metropolitan_effect = yes
		}
		flag:change_province_industrial = {
			change_province_industrial_effect = yes
		}
		flag:change_province_military = {
			change_province_military_effect = yes
		}
		flag:change_province_protectorate = {
			change_province_protectorate_effect = yes
		}
		flag:hold_examinations = {
			hold_examinations_effect = yes
		}
		flag:change_retirement_law_increase = {
			change_retirement_law_increase_effect = yes
		}
		flag:change_retirement_law_decrease = {
			change_retirement_law_decrease_effect = yes
		}
		flag:change_candidate_score_law = {
			change_candidate_score_law_effect = yes
		}
		flag:increase_budget_salary = {
			increase_budget_salary_effect = yes
		}
		flag:increase_budget_ministry = {
			increase_budget_ministry_effect = yes
		}
		flag:increase_budget_military = {
			increase_budget_military_effect = yes
		}
	}
	situation:dynastic_cycle ?= {
		if = {
			limit = {
			situation_top_has_catalyst = catalyst_hegemon_influenced_by_interaction  
			}
			trigger_situation_catalyst = {
			catalyst = catalyst_hegemon_influenced_by_interaction
			character = scope:petitioner
			}
		}
	}
	scope:hegemon = {
		add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_gain }
	}
	#set a cooldown variable in case the leader changes
	scope:actors_movement = {
		petition_change_movement_power_effect = {
			VALUE = 100
		}
		set_variable = {
			name = recent_movement_petition
			value = scope:petitioner
			years = 3
		}
	}
}

refuse_movement_petition_effect = {
	send_interface_message = {
		type = event_diplomacy_bad
		title = tgp_decision_events.0103.b_title
		left_icon = scope:petition_recipient
		add_opinion = {
			modifier = hegemon_refused_faction_demands_modifier
			target = scope:petition_recipient
			years = 5
		}
		scope:hegemon = {
			add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
			if = {
				limit = {
					scope:petitioner.var:movement_petition ?= flag:hold_examinations
				}
				situation:dynastic_cycle = {
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_imperial_examinations_gap_short_yearly
							exists = title:h_china.var:years_since_imperial_examination
							title:h_china.var:years_since_imperial_examination >= catalyst_imperial_examinations_gap_short_yearly_value
						}
						trigger_situation_catalyst = {
							catalyst = catalyst_imperial_examinations_gap_short_yearly
							character = scope:petitioner
						}
					}
					if = {
						limit = {
							situation_top_has_catalyst = catalyst_imperial_examinations_gap_long_yearly
							exists = title:h_china.var:years_since_imperial_examination
							title:h_china.var:years_since_imperial_examination >= catalyst_imperial_examinations_gap_long_yearly_value
						}
						trigger_situation_catalyst = {
							catalyst = catalyst_imperial_examinations_gap_long_yearly
							character = scope:petitioner
						}
					}
				}
			}
		}
		scope:actors_movement = {
			petition_change_movement_power_effect = {
				VALUE = -100
			}
		}
	}
}

display_movement_petition_recipient_acceptance_chance_effect = {
	if = {
		limit = {
			movement_demands_acceptance_value > 100
		}
		custom_tooltip = movement_petition_decision.recipient_will_accept
	}
	else_if = {
		limit = {
			movement_demands_acceptance_value >= 50
		}
		custom_tooltip = movement_petition_decision.recipient_may_accept
	}
	else_if = {
		limit = {
			movement_demands_acceptance_value >= 0
		}
		custom_tooltip = movement_petition_decision.recipient_may_refuse
	}
	else = {
		custom_tooltip = movement_petition_decision.recipient_will_refuse
	}
}

display_movement_petition_recipient_acceptance_effect = {
	display_movement_petition_recipient_acceptance_chance_effect = yes
	show_as_tooltip = {
		random_list = {
			1 = {
				show_chance = no
				desc = tgp_decision_events.0102.petition_accepted
				grant_movement_petition_tooltip_effect = yes
			}
			1 = {
				show_chance = no
				desc = tgp_decision_events.0102.petition_refused
				refuse_movement_petition_effect = yes
			}
		}
	}
}

# Makes the targeted movement become empowered
# Scope is situation_participant_group
make_movement_favored_effect = {
	save_scope_as = movement_to_be_favored
	custom_description = {
		text = new_movement_becomes_favored_desc
		object = scope:movement_to_be_favored
		situation:dynastic_cycle ?= {
			random_participant_group = {
				limit = {
					has_variable = movement_favored
				}
				set_variable = {
					name = movement_unfavored
					days = 1
				}
				remove_variable = movement_favored
			}
			scope:movement_to_be_favored = {
				set_variable = movement_favored
			}
		}
	}
	custom_tooltip = new_movement_becomes_favored_power_increase

	situation:dynastic_cycle ?= {
		random_participant_group = {
			limit = {
				has_variable = movement_unfavored
			}
			save_scope_as = movement_to_be_unfavored
		}
	}
	if = {
		limit = {
			exists = scope:movement_to_be_unfavored
		}
		custom_tooltip = new_movement_becomes_favored_power_decrease
	}
}

# ELDER = scope:character that should become the elder of the relation
# DISCIPLE = scope:character that should become the disciple of the relation
# MERIT = amount of merit the Elder will gain, can be set to 0 for no gain
set_elder_relation_effect = {
	$DISCIPLE$ = {
		save_scope_as = new_disciple
		random_relation = {
			type = elder
			save_scope_as = old_elder
		}
	}
	$ELDER$ = {
		save_scope_as = new_elder
	}
	if = {
		limit = {
			# no circular relations please
			NOT = {
				scope:new_disciple = {
					has_relation_elder = scope:new_elder
				}
			}
			# Disciple does not have a higher merit rank than the elder
			# The elder can have more disciples
			scope:new_elder = {
				eligible_for_elder_trigger = {
					DISCIPLE = scope:new_disciple
				}
			}
		}
		scope:new_disciple = {
			# in case you already had an elder, remove the relation and send them a letter
			if = {
				limit = {
					exists = scope:old_elder
				}
				remove_relation_elder = scope:old_elder
				save_scope_as = actor #for loc in tgp_interaction_event.0030
				scope:old_elder = {
					add_opinion = {
						target = scope:new_disciple
						modifier = refused_to_be_disciple_opinion
						opinion = -50
					}
					save_scope_as = recipient #for loc in tgp_interaction_event.0030
					trigger_event = tgp_interaction_event.0030
				}
			}
			set_relation_elder = scope:new_elder
		}
		scope:new_elder = {
			add_merit_if_relevant_effect = {
				MERIT = $MERIT$
			}
		}
	}
}

# Skips the opinion loss and the breakup event
set_elder_relation_no_breakup_effect = {
	$DISCIPLE$ = {
		save_scope_as = new_disciple
		random_relation = {
			type = elder
			save_scope_as = old_elder
		}
	}
	$ELDER$ = {
		save_scope_as = new_elder
	}
	if = {
		limit = {
			# no circular relations please
			NOT = {
				scope:new_disciple = {
					has_relation_elder = scope:new_elder
				}
			}
			# Disciple does not have a higher merit rank than the elder
			# The elder can have more disciples
			scope:new_elder = {
				eligible_for_elder_trigger = {
					DISCIPLE = scope:new_disciple
				}
			}
		}
		scope:new_disciple = {
			# in case you already had an elder, remove the relation and send them a letter
			if = {
				limit = {
					exists = scope:old_elder
				}
				remove_relation_elder = scope:old_elder
			}
			set_relation_elder = scope:new_elder
		}
		scope:new_elder = {
			add_merit_if_relevant_effect = {
				MERIT = minor_merit_value
			}
		}
	}
}

# This effect improves Development in Celestial Tributaries' capital provinces, for as long as they have the Trade Investiture and as long as it's below the Development level of China's capital province
develop_celestial_tributaries = {
	if = {
		limit = {
			subject_contract_has_flag = celestial_investiture_trade
			capital_county.development_level < overlord.capital_county.development_level
			subject_standing > 10
		}
		save_scope_value_as = {
			name = tributary_capital_development_growth
			value = {
				add = { # ratio of how close they are in development
					add = capital_county.development_level
					divide = overlord.capital_county.development_level
				}
				subtract = 1
				multiply = -1
				multiply = { # ratio of subject standing, with a minimum value to make at least something happen
					add = subject_standing
					divide = 100
					min = 0.2
				}
				multiply = celestial_investiture_trade_bonus_max
				add = { # to make it feel a bit more dynamic
					fixed_range = {
						min = -5
						max = 5
					}
				}
			}
		}
		if = {
			limit = { scope:tributary_capital_development_growth >= 1 }
			send_interface_message = {
				type = msg_tributary_capital_province_development_growth
				title = msg_tributary_capital_province_development_growth_title
				desc = msg_tributary_capital_province_development_growth_desc

				left_icon = root
				right_icon = overlord

				capital_county = {
					change_development_progress_with_overflow = scope:tributary_capital_development_growth
				}
			}
		}
	}
}

pledge_loyalty_to_liege_refund_and_cleanup_effect = {
	send_interface_toast = {
		type = event_toast_effect_neutral
		title = pledge_loyalty_to_liege_costs_refunded
		left_icon = root
		# Remove variable preventing you from kneeling before liege again
		if = {
			limit = {
				has_variable = pledge_loyalty_to_liege_grace
				exists = liege
				var:pledge_loyalty_to_liege_grace = liege
			}
			remove_variable = pledge_loyalty_to_liege_grace
		}
		# refund any costs
		if = {
			limit = {
				has_variable = pledge_loyalty_to_liege_gold_value
			}
			add_gold = var:pledge_loyalty_to_liege_gold_value
		}
		switch = {
			trigger = has_trait
			shy = { add_stress = medium_stress_impact_loss }
			arrogant = { add_stress = medium_stress_impact_loss }
		}
	}
	# Variable cleanup
	if = {
		limit = { has_variable = homage_type }
		remove_variable = homage_type
	}
	# Contract
	if = {
		limit = { has_variable = pledge_loyalty_to_liege_contract_type }
		remove_variable = pledge_loyalty_to_liege_contract_type
	}
	# Liege
	if = {
		limit = { has_variable = pledge_loyalty_to_liege_scope }
		remove_variable = pledge_loyalty_to_liege_scope
	}
	if = {
		limit = { has_variable = pledge_loyalty_to_liege_gold_value }
		remove_variable = pledge_loyalty_to_liege_gold_value
	}
}

#Adds Merit if your government has it
#Required Parameter MERIT
#Reminder, the values are
#miniscule_merit_value
#minor_merit_value
#medium_merit_value
#major_merit_value
#massive_merit_value
#monumental_merit_value
add_merit_if_relevant_effect = {
	if = {
		limit = {
			government_has_flag = government_has_merit
			top_liege != this
			$MERIT$ != 0
		}
		change_merit = $MERIT$
	}
}

#use this in SCHEMES to temporarily increase or decrease movement power of a character or movement
scheme_change_movement_power_effect = {
	save_scope_value_as = {
		name = movement_power_scheme_effect_value
		value = {
			value = $VALUE$
			multiply = 100
		}
	}
	if = {
		limit = {
			scope:movement_power_scheme_effect_value >= 0
		}
		if = {
			limit = {
				exists = var:movement_power_increased_scheme
			}
			set_variable = {
				name = movement_power_increased_scheme
				value = {
					value = var:movement_power_increased_scheme
					add = $VALUE$
				}
			}
		}
		else = {
			set_variable = {
				name = movement_power_increased_scheme
				value = $VALUE$
			}
		}
	}
	else = {
		if = {
			limit = {
				exists = var:movement_power_decreased_scheme
			}
			set_variable = {
				name = movement_power_decreased_scheme
				value = {
					value = var:movement_power_decreased_scheme
					add = $VALUE$
				}
			}
		}
		else = {
			set_variable = {
				name = movement_power_decreased_scheme
				value = $VALUE$
			}
		}
	}
	#force the update of variables to immediately show changes
	if = { #for characters
		limit = {
			exists = var:movement_power_individual
		}
		if = {
			limit = {
				scope:movement_power_scheme_effect_value >= 0
			}
			custom_tooltip = movement_power_scheme.tt.increased_character
		}
		else = {
			custom_tooltip = movement_power_scheme.tt.decreased_character
		}
		update_character_movement_power_effect = yes
		top_participant_group:dynastic_cycle ?= {
			update_movement_power_effect = yes
		}
	}
	else = { #for movements
		if = {
			limit = {
				scope:movement_power_scheme_effect_value >= 0
			}
			custom_tooltip = movement_power_scheme.tt.increased_movement
		}
		else = {
			custom_tooltip = movement_power_scheme.tt.decreased_movement
		}
		update_movement_power_effect = yes
	}
}

#use this in EVENTS to temporarily increase or decrease movement power of a character or movement
event_change_movement_power_effect = {
	if = {
		limit = {
			$VALUE$ >= 0
		}
		if = {
			limit = {
				exists = var:movement_power_increased_event
			}
			set_variable = {
				name = movement_power_increased_event
				value = {
					value = var:movement_power_increased_event
					add = $VALUE$
				}
			}
		}
		else = {
			set_variable = {
				name = movement_power_increased_event
				value = $VALUE$
			}
		}

	}
	else = {
		if = {
			limit = {
				exists = var:movement_power_decreased_event
			}
			set_variable = {
				name = movement_power_decreased_event
				value = {
					value = var:movement_power_decreased_event
					add = $VALUE$
				}
			}
		}
		else = {
			set_variable = {
				name = movement_power_decreased_event
				value = $VALUE$
			}
		}
	}
	#force the update of variables to immediately show changes
	if = { #for characters
		limit = {
			exists = var:movement_power_individual
		}
		update_character_movement_power_effect = yes
		top_participant_group:dynastic_cycle ?= {
			update_movement_power_effect = yes
		}
	}
	else = { #for movements
		update_movement_power_effect = yes
	}
}

#use this in PETITION to temporarily increase or decrease movement power of a character or movement
petition_change_movement_power_effect = {
	save_scope_value_as = {
		name =  petition_modifies_movement_power_value
		value = $VALUE$
	}
	if = {
		limit = {
			NOT = {
				participant_group_type = undecided_movement
			}
		}
		if = {
			limit = {
				$VALUE$ >= 0
			}
			custom_tooltip = {
				text = petition_increase_movement_power_effect_tooltip
				if = {
					limit = {
						exists = var:movement_power_increased_petition
					}
					set_variable = {
						name = movement_power_increased_petition
						value = {
							value = var:movement_power_increased_petition
							add = $VALUE$
						}
					}
				}
				else = {
					set_variable = {
						name = movement_power_increased_petition
						value = $VALUE$
					}
				}
			}
		}
		else = {
			custom_tooltip = {
				text = petition_decrease_movement_power_effect_tooltip
				if = {
					limit = {
						exists = var:movement_power_decreased_petition
					}
					set_variable = {
						name = movement_power_decreased_petition
						value = {
							value = var:movement_power_decreased_petition
							add = $VALUE$
						}
					}
				}
				else = {
					set_variable = {
						name = movement_power_decreased_petition
						value = $VALUE$
					}
				}
			}
		}
		#force the update of variables to immediately show changes
		if = { #for characters
			limit = {
				exists = var:movement_power_individual
			}
			update_character_movement_power_effect = yes
			top_participant_group:dynastic_cycle ?= {
				update_movement_power_effect = yes
			}
		}
		else = { #for movements
			update_movement_power_effect = yes
		}
	}
}

# update the variables on yearly pulse towards 0 and remove it if they reach it
update_modified_movement_power_effect = {
	if = {
		limit = {
			exists = var:movement_power_increased_scheme
		}
		change_variable = {
			name = movement_power_increased_scheme
			add = movement_power_increased_scheme_decay_value
		}
		if = {
			limit = { var:movement_power_increased_scheme <= 0 }
			remove_variable = movement_power_increased_scheme
		}
	}
	if = {
		limit = {
			exists = var:movement_power_decreased_scheme
		}
		change_variable = {
			name = movement_power_decreased_scheme
			add = movement_power_decreased_scheme_decay_value
		}
		if = {
			limit = { var:movement_power_decreased_scheme >= 0 }
			remove_variable = movement_power_decreased_scheme
		}
	}
	if = {
		limit = {
			exists = var:movement_power_increased_event
		}
		change_variable = {
			name = movement_power_increased_event
			add = movement_power_increased_event_decay_value
		}
		if = {
			limit = { var:movement_power_increased_event <= 0 }
			remove_variable = movement_power_increased_event
		}
	}
	if = {
		limit = {
			exists = var:movement_power_decreased_event
		}
		change_variable = {
			name = movement_power_decreased_event
			add = movement_power_decreased_event_decay_value
		}
		if = {
			limit = { var:movement_power_decreased_event >= 0 }
			remove_variable = movement_power_decreased_event
		}
	}
	if = {
		limit = {
			exists = var:movement_power_increased_petition
		}
		change_variable = {
			name = movement_power_increased_petition
			add = movement_power_increased_petition_decay_value
		}
		if = {
			limit = { var:movement_power_increased_petition <= 0 }
			remove_variable = movement_power_increased_petition
		}
	}
	if = {
		limit = {
			exists = var:movement_power_decreased_petition
		}
		change_variable = {
			name = movement_power_decreased_petition
			add = movement_power_decreased_petition_decay_value
		}
		if = {
			limit = { var:movement_power_decreased_petition >= 0 }
			remove_variable = movement_power_decreased_petition
		}
	}
}


# When scoped character is appointed as a minister
got_minister_position_effect = {
	save_scope_as = new_minister

	if = { # If your liege has a ministry, set up titles if needed
		limit = {
			scope:councillor_liege = {
				this != scope:new_minister
				tgp_has_access_to_ministry_trigger = yes
			}
			not = { exists = scope:swapped_position }
		}
		# Grant the ministry title if councillor doesn't have it
		if = {
			limit = {
				NOT = { has_title = title:$MINISTER_TITLE$ }
			}
			create_title_and_vassal_change = {
				type = appointment
				save_scope_as = minister_title_change
				add_claim_on_loss = no
			}

			if = {
				limit = {
					scope:councillor_liege = {
						tgp_has_access_to_ministry_trigger = yes
					}
					# retire from other ministry primary titles
					scope:new_minister = {
						OR = {
							primary_title = title:e_minister_chancellor
							primary_title = title:e_minister_censor
							primary_title = title:e_minister_grand_marshal
							primary_title = title:e_minister_of_personnel
							primary_title = title:e_minister_of_revenue
							primary_title = title:e_minister_of_rites
							primary_title = title:e_minister_of_war
							primary_title = title:e_minister_of_justice
							primary_title = title:e_minister_of_works
						}
						primary_title != title:$MINISTER_TITLE$
					}
				}
				primary_title = {
					save_scope_as = old_ministry_title					
					change_title_holder = {
						holder = current_heir
						change = scope:minister_title_change
					}
				}
			}

			title:$MINISTER_TITLE$ = {
				change_title_holder = {
					holder = scope:new_minister
					change = scope:minister_title_change
				}
			}
			resolve_title_and_vassal_change = scope:minister_title_change
		}
		# Add the correct title law if it doesn't have it already
		if = {
			limit = {
				exists = title:$MINISTER_TITLE$.holder
				title:$MINISTER_TITLE$ = title:e_minister_grand_marshal
				NOT = {
					title:$MINISTER_TITLE$ = {
						has_title_law = celestial_grand_marshal_appointment_succession_law
					}
				}
			}
			title:$MINISTER_TITLE$ = {
				add_title_law = celestial_grand_marshal_appointment_succession_law
			}
		}
		else_if = {
			limit = {
				exists = title:$MINISTER_TITLE$.holder
				NOR = {
					title:$MINISTER_TITLE$ = title:e_minister_grand_marshal
					title:$MINISTER_TITLE$ = {
						has_title_law = celestial_ministry_appointment_succession_law
					}
				}
			}
			title:$MINISTER_TITLE$ = {
				add_title_law = celestial_ministry_appointment_succession_law
			}
		}

		# Make them a minister if they don't have the council position
		if = {
			limit = {
				NOT = { has_council_position = $MINISTER_POSITION$ }
			}
			top_liege = {
				assign_councillor_type = {
					type = $MINISTER_POSITION$
					target = scope:new_minister
					remove_existing_councillor = yes
				}
			}
		}
		# If we have any noble family vassals remaining, let's move them to where they are supposed to be
		if = {
			limit = {
				vassal_count > 0
			}
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = minister_vassal_change
			}
			every_vassal = {
				limit = {
					any_held_title = {
						is_noble_family_title = yes
					}
					NOT = {
						any_held_title = {
							is_noble_family_title = no
						}
					}
				}
				change_liege = {
					liege = top_liege # I.e. the top liege
					change = scope:minister_vassal_change
				}
			}
			resolve_title_and_vassal_change = scope:minister_vassal_change
		}
		# If the new minister should be the diarch, make it so
		if = {
			limit = {
				OR = {
					AND = {
						top_liege ?= {
							has_realm_law = grand_chancellor_law
						}
						title:e_minister_chancellor = {
							this = title:$MINISTER_TITLE$
							holder = scope:new_minister
						}
					}
					AND = {
						top_liege ?= {
							has_realm_law = grand_marshal_law
						}
						title:e_minister_grand_marshal = {
							this = title:$MINISTER_TITLE$
							holder = scope:new_minister
						}
					}
					AND = {
						top_liege ?= {
							has_realm_law = grand_censor_law
						}
						title:e_minister_censor = {
							this = title:$MINISTER_TITLE$
							holder = scope:new_minister
						}
					}
				}
			}
			top_liege = {
				if = {
					limit = {
						diarch != scope:new_minister
					}
					if = {
						limit = {
							NOT = { has_diarchy_type = grand_secretariat }
						}
						try_start_diarchy = grand_secretariat
					}
					set_diarch = scope:new_minister
				}
			}
		}

		# Save and track accomplishment for the Gate domicile building
		if = {
			limit = {
				title:e_minister_chancellor = {
					this = title:$MINISTER_TITLE$
					holder = scope:new_minister
				}
			}
			scope:new_minister.house ?= {
				house_head ?= {
					if = {
						limit = {
							exists = domicile
						}
						domicile ?= {
							set_family_accomplishment_effect = { ACCOMPLISHMENT = family_accomplishment_minister }
						}
					}
				}
			}
		}
		if = {
			limit = {
				title:e_minister_grand_marshal = {
					this = title:$MINISTER_TITLE$
					holder = scope:new_minister
				}
			}
			scope:new_minister.house ?= {
				house_head ?= {
					if = {
						limit = {
							exists = domicile
						}
						domicile ?= {
							set_family_accomplishment_effect = { ACCOMPLISHMENT = family_accomplishment_grand_marshal }
						}
					}
				}
			}
		}
		if = { # make sure the minister is participant in the Dynastic Cycle situation
			limit = {
				NOT = {
					any_character_situation = {
						situation_type = dynastic_cycle
					}
				}
				top_liege ?= {
					any_character_situation = {
						situation_type = dynastic_cycle
					}
				}
			}

			situation:dynastic_cycle = {
				add_manual_participant = prev
			}
		}
	}
}

fired_minister_position_effect = {
	if = {
		limit = {
			scope:councillor_liege = {
				tgp_has_access_to_ministry_trigger = yes
			}
			not = { exists = scope:new_councillor }
		}

		switch = {
			trigger = primary_title
			title:e_minister_chancellor = {
				if = {
					limit = {
						exists = title:e_minister_chancellor.current_heir
					}
					title:e_minister_chancellor.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_chancellor MINISTER_POSITION = councillor_chancellor }
					}
				}
				else = {
					destroy_title = title:e_minister_chancellor
				}
			}
			title:e_minister_censor = {
				if = {
					limit = {
						exists = title:e_minister_censor.current_heir
					}
					title:e_minister_censor.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_censor MINISTER_POSITION = councillor_spymaster }
					}
				}
				else = {
					destroy_title = title:e_minister_censor
				}
			}
			title:e_minister_grand_marshal = {
				if = {
					limit = {
						exists = title:e_minister_grand_marshal.current_heir
					}
					title:e_minister_grand_marshal.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_grand_marshal MINISTER_POSITION = minister_grand_marshal }
					}
				}
				else = {
					destroy_title = title:e_minister_grand_marshal
				}
			}
			title:e_minister_of_personnel = {
				if = {
					limit = {
						exists = title:e_minister_of_personnel.current_heir
					}
					title:e_minister_of_personnel.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_of_personnel MINISTER_POSITION = minister_personnel }
					}
				}
				else = {
					destroy_title = title:e_minister_of_personnel
				}
			}
			title:e_minister_of_revenue = {
				if = {
					limit = {
						exists = title:e_minister_of_revenue.current_heir
					}
					title:e_minister_of_revenue.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_of_revenue MINISTER_POSITION = councillor_steward }
					}
				}
				else = {
					destroy_title = title:e_minister_of_revenue
				}
			}
			title:e_minister_of_rites = {
				if = {
					limit = {
						exists = title:e_minister_of_rites.current_heir
					}
					title:e_minister_of_rites.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_of_rites MINISTER_POSITION = councillor_court_chaplain }
					}
				}
				else = {
					destroy_title = title:e_minister_of_rites
				}
			}
			title:e_minister_of_war = {
				if = {
					limit = {
						exists = title:e_minister_of_war.current_heir
					}
					title:e_minister_of_war.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_of_war MINISTER_POSITION = councillor_marshal }
					}
				}
				else = {
					destroy_title = title:e_minister_of_war
				}
			}
			title:e_minister_of_justice = {
				if = {
					limit = {
						exists = title:e_minister_of_justice.current_heir
					}
					title:e_minister_of_justice.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_of_justice MINISTER_POSITION = minister_justice }
					}
				}
				else = {
					destroy_title = title:e_minister_of_justice
				}
			}
			title:e_minister_of_works = {
				if = {
					limit = {
						exists = title:e_minister_of_works.current_heir
					}
					title:e_minister_of_works.current_heir = {
						got_minister_position_effect = { MINISTER_TITLE = e_minister_of_works MINISTER_POSITION = minister_works }
					}
				}
				else = {
					destroy_title = title:e_minister_of_works
				}
			}
		}
	}
}

# Destroy any held ministry title - Use this on a character
destroy_held_ministry_titles_effect = {
	save_scope_as = minister_should_lose_ministry_title
	if = {
		limit = {
			OR = {
				has_title = title:e_minister_chancellor
				has_title = title:e_minister_censor
				has_title = title:e_minister_grand_marshal
				has_title = title:e_minister_of_personnel
				has_title = title:e_minister_of_revenue
				has_title = title:e_minister_of_rites
				has_title = title:e_minister_of_war
				has_title = title:e_minister_of_justice
				has_title = title:e_minister_of_works
			}
		}
		every_held_title = {
			switch = {
				trigger = this
				title:e_minister_chancellor = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_chancellor }
				}
				title:e_minister_censor = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_censor }
				}
				title:e_minister_grand_marshal = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_grand_marshal }
				}
				title:e_minister_of_personnel = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_of_personnel }
				}
				title:e_minister_of_revenue = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_of_revenue }
				}
				title:e_minister_of_rites = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_of_rites }
				}
				title:e_minister_of_war = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_of_war }
				}
				title:e_minister_of_justice = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_of_justice }
				}
				title:e_minister_of_works = {
					scope:minister_should_lose_ministry_title = { destroy_title = title:e_minister_of_works }
				}
			}
		}

		situation:dynastic_cycle = {
			remove_manual_participant = prev
		}
	}
}

# Fill the ministry with valid characters
fill_the_ministry_effect = {
	save_scope_as = councillor_liege
	# Assign a grand chancellor
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:councillor_chancellor }
				cp:councillor_chancellor ?= {
					NOT = { has_title = title:e_minister_chancellor }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = diplomacy
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_chancellor MINISTER_POSITION = councillor_chancellor }
		}
	}
	# Assign an imperial censor
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:councillor_spymaster }
				cp:councillor_spymaster ?= {
					NOT = { has_title = title:e_minister_censor }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = intrigue
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_censor MINISTER_POSITION = councillor_spymaster }
		}
	}
	# Assign a grand marshal
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:minister_grand_marshal }
				cp:minister_grand_marshal ?= {
					NOT = { has_title = title:e_minister_grand_marshal }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = martial
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_grand_marshal MINISTER_POSITION = minister_grand_marshal }
		}
	}
	# Assign a minister of personnel
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:minister_personnel }
				cp:minister_personnel ?= {
					NOT = { has_title = title:e_minister_of_personnel }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = diplomacy
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_of_personnel MINISTER_POSITION = minister_personnel }
		}
	}
	# Assign a minister of revenue
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:councillor_steward }
				cp:councillor_steward ?= {
					NOT = { has_title = title:e_minister_of_revenue }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = stewardship
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_of_revenue MINISTER_POSITION = councillor_steward }
		}
	}
	# Assign a minister of rites
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:councillor_court_chaplain }
				cp:councillor_court_chaplain ?= {
					NOT = { has_title = title:e_minister_of_rites }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = learning
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_of_rites MINISTER_POSITION = councillor_court_chaplain }
		}
	}
	# Assign a minister of war
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:councillor_marshal }
				cp:councillor_marshal ?= {
					NOT = { has_title = title:e_minister_of_war }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = martial
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_of_war MINISTER_POSITION = councillor_marshal }
		}
	}
	# Assign a minister of justice
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:minister_justice }
				cp:minister_justice ?= {
					NOT = { has_title = title:e_minister_of_justice }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = learning
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_of_justice MINISTER_POSITION = minister_justice }
		}
	}
	# Assign a minister of works
	if = {
		limit = {
			OR = {
				NOT = { exists = cp:minister_works }
				cp:minister_works ?= {
					NOT = { has_title = title:e_minister_of_works }
				}
			}
		}
		random_vassal = {
			limit = {
				tgp_can_be_a_minister_trigger = { COURT_OWNER = scope:councillor_liege }
				tgp_is_any_minister = no
			}
			weight = {
				base = 1
				modifier = {
					add = stewardship
				}
			}
			got_minister_position_effect = { MINISTER_TITLE = e_minister_of_works MINISTER_POSITION = minister_works }
		}
	}
}

# Minister courtier recruitment effect
minister_courtier_recruitment_effect = {
	while = {
		count = minister_recruit_courtier_value

		save_scope_as = minister
		create_character = {
			employer = scope:minister
			template = $COURTIER_TEMPLATE$
			faith = scope:minister.top_liege.capital_county.faith
			culture = scope:minister.top_liege.capital_county.culture
			save_scope_as = new_courtier
		}
		if = {
			limit = { exists = scope:new_courtier }
			scope:new_courtier = {
				assign_completed_exams_based_on_merit_effect = yes
				add_character_flag = {
					flag = blocked_from_leaving
					years = 25
				}
			}
			if = {
				limit = {
					scope:new_courtier = {
						NOT = { is_courtier_of = scope:minister }
					}
				}
				add_courtier = scope:new_courtier
			}
			send_interface_message = {
				title = minister_courtier_recruited_t
				left_icon = scope:new_courtier
				custom_tooltip = minister_courtier_recruited_desc
			}
		}
	}
}

# Effect to keep track of family accomplishments for the Ancestral Gate domicile building
set_family_accomplishment_effect = {
	# ACCOMPLISHMENT = the accomplishment you want to save
	if = {
		limit = {
			NOT = { has_variable = $ACCOMPLISHMENT$ }
		}
		set_variable = {
			name = $ACCOMPLISHMENT$
			value = yes
		}
		if = {
			limit = {
				has_variable = family_accomplishments
			}
			change_variable = {
				name = family_accomplishments
				add = 1
			}
		}
		else = {
			set_variable = {
				name = family_accomplishments
				value = 1
			}
		}
	}
}

## GRAND CAMPAIGN great project effects
set_duchies_to_attack_effect = {
	while = {
		count = 20 #as for tgp France holds the record for the most duchies with 17
		limit = {
			list_size:duchies_to_attack > 0
		}
		random_in_list = {
			list = duchies_to_attack
			limit = {
				this = scope:grand_campaign_project.great_project_location.duchy
			}
			set_duchies_to_attack_variable_effect = {
				VALUE = 1
			}
		}
		ordered_in_list = {
			list = duchies_to_attack
			order_by = {
				value = holder.realm_size
				multiply = -1
			}
			switch = {
				trigger = list_size:duchies_to_attack
				1 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 2
					}
				}
				2 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 3
					}
				}
				3 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 4
					}
				}
				4 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 5
					}
				}
				5 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 6
					}
				}
				6 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 7
					}
				}
				7 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 8
					}
				}
				8 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 9
					}
				}
				9 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 10
					}
				}
				10 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 11
					}
				}
				11 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 12
					}
				}
				12 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 13
					}
				}
				13 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 14
					}
				}
				14 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 15
					}
				}
				15 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 16
					}
				}
				16 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 17
					}
				}
				17 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 18
					}
				}
				18 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 19
					}
				}
				19 = {
					set_duchies_to_attack_variable_effect = {
						VALUE = 20
					}
				}
			}
		}
	}
}
set_duchies_to_attack_variable_effect = {
	save_temporary_scope_as = duchy
	scope:grand_campaign_project = {
		set_variable = {
			name = attack_$VALUE$
			value = scope:duchy
		}
		add_to_variable_list = {
			name = grand_campaign_targets
			target = scope:duchy
		}
	}
	remove_from_list = duchies_to_attack
}
display_duchy_to_attack = {
	prev.var:attack_$ID$ ?= {
		add_to_list = target_titles
	}
}

grand_campaign_contribution_effect = {
	save_scope_as = contributor
	scope:great_project.var:$TITLE$ ?= {
		save_scope_as = target_title
	}
	# the grand marshal should always be the war leader
	title:e_minister_grand_marshal.holder = {
		save_scope_as = war_leader
	}
	
	scope:great_project ?= {
		add_to_variable_list = {
			name = grand_campaign_titles
			target = scope:target_title
		}
	}
	# if war does not exist yet, declare it
	if = {
		limit = {
			NOT = { exists = scope:great_project.var:grand_campaign_war }
		}
		scope:war_leader = {
			trigger_event = tgp_china_ministry.0001
		}
		custom_tooltip = grand_campaign_start_tt
	}
	# if war exists, pull everyone in
	else = {
		trigger_event = tgp_china_ministry.0004
	}
	custom_tooltip = great_project_type_grand_campaign_project_contribution_tt
}

grand_campaign_contribution_complete_effect = {
	if = {
		limit = {
			situation:dynastic_cycle ?= {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					situation_current_phase = situation_dynastic_cycle_phase_instability
				}
			}
		}
		custom_tooltip = great_project_type_grand_campaign_project_contribution_win_tributaries_tt
	}
	else = {
		custom_tooltip = great_project_type_grand_campaign_project_contribution_win_tt
	}
}

# Chinese Estate building effects
add_random_internal_east_asian_estate_building = {
	random_list = {
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_servants_quarters_01 }
			}
			add_domicile_building = east_asian_estate_servants_quarters_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_servants_quarters_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_library_01 }
			}
			add_domicile_building = east_asian_estate_library_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_library_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_bath_01 }
			}
			add_domicile_building = east_asian_estate_bath_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_bath_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_courtyard_01 }
			}
			add_domicile_building = east_asian_estate_courtyard_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_courtyard_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_prison_01 }
			}
			add_domicile_building = east_asian_estate_prison_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_prison_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_living_quarters_01 }
			}
			add_domicile_building = east_asian_estate_living_quarters_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_living_quarters_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_study_01 }
			}
			add_domicile_building = east_asian_estate_study_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_study_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_guest_room_01 }
			}
			add_domicile_building = east_asian_estate_guest_room_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_guest_room_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_wine_cellar_01 }
			}
			add_domicile_building = east_asian_estate_wine_cellar_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_wine_cellar_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_taxation_01 }
			}
			add_domicile_building = east_asian_estate_taxation_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_taxation_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_drafting_room_01 }
			}
			add_domicile_building = east_asian_estate_drafting_room_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_drafting_room_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_clerks_hall_01 }
			}
			add_domicile_building = east_asian_estate_clerks_hall_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_clerks_hall_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_revenue_audit_desk_01 }
			}
			add_domicile_building = east_asian_estate_revenue_audit_desk_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_revenue_audit_desk_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_block_printing_hall_01 }
			}
			add_domicile_building = east_asian_estate_block_printing_hall_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_block_printing_hall_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_xuan_paper_stores_01 }
			}
			add_domicile_building = east_asian_estate_xuan_paper_stores_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_xuan_paper_stores_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_water_clock_room_01 }
			}
			add_domicile_building = east_asian_estate_water_clock_room_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_water_clock_room_02
			}
		}
		10 = {
			trigger = {
				NOT = { has_domicile_building_or_higher = east_asian_estate_examination_room_01 }
			}
			add_domicile_building = east_asian_estate_examination_room_01
			if = {
				limit = { has_domicile_building = east_asian_estate_main_03 }
				add_domicile_building = east_asian_estate_examination_room_02
			}
		}
	}
}

fill_external_east_asian_estate_building_effect = {
	switch = {
		trigger = has_domicile_building_or_higher
		east_asian_estate_main_05 = {
			while = {
				limit = { free_external_domicile_building_slots >= 2 }
				add_random_external_east_asian_estate_building = yes
			}
		}
		east_asian_estate_main_04 = {
			while = {
				limit = { free_external_domicile_building_slots >= 3 }
				add_random_external_east_asian_estate_building = yes
			}
		}
		east_asian_estate_main_03 = {
			while = {
				limit = { free_external_domicile_building_slots >= 4 }
				add_random_external_east_asian_estate_building = yes
			}
		}
		east_asian_estate_main_02 = {
			while = {
				limit = { free_external_domicile_building_slots >= 5 }
				add_random_external_east_asian_estate_building = yes
			}
		}
		east_asian_estate_main_01 = {
			while = {
				limit = { free_external_domicile_building_slots >= 6 }
				add_random_external_east_asian_estate_building = yes
			}
		}
	}
}

add_random_external_east_asian_estate_building = {
	if = {
		limit = {
			free_external_domicile_building_slots >= 1
		}
		random_list = {
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_ancestral_shrine_01 }
				}
				add_domicile_building = east_asian_estate_ancestral_shrine_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_ancestral_shrine_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_barracks_01 }
				}
				add_domicile_building = east_asian_estate_barracks_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_barracks_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_watchtower_01 }
				}
				add_domicile_building = east_asian_estate_watchtower_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_watchtower_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_garden_01 }
				}
				add_domicile_building = east_asian_estate_garden_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_garden_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_storage_01 }
				}
				add_domicile_building = east_asian_estate_storage_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_storage_02
				}
			}
			10 = {
				trigger = {
					NOT = {
						has_domicile_building_or_higher = east_asian_estate_rice_field_01
					}
				}
				add_domicile_building = east_asian_estate_rice_field_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_rice_field_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_stable_01 }
				}
				add_domicile_building = east_asian_estate_stable_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_stable_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_workshop_01 }
				}
				add_domicile_building = east_asian_estate_workshop_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_workshop_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_market_01 }
				}
				add_domicile_building = east_asian_estate_market_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_market_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_grazing_land_01 }
				}
				add_domicile_building = east_asian_estate_grazing_land_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_grazing_land_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_tea_01 }
				}
				add_domicile_building = east_asian_estate_tea_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_tea_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_health_01 }
				}
				add_domicile_building = east_asian_estate_health_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_health_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = east_asian_estate_silk_01 }
					owner = {
						OR = {
							custom_tooltip = {
								house = { has_house_modifier = ep3_unlocked_silk }
								text = has_unlocked_estate_silk
							}
							culture = { has_cultural_parameter = unlocks_silk_buildings_parameter }
						}
					}
				}
				add_domicile_building = east_asian_estate_silk_01
				if = {
					limit = { has_domicile_building = east_asian_estate_main_03 }
					add_domicile_building = east_asian_estate_silk_02
				}
			}
		}
	}
}

# Use this effect to set what exams a characters should have passed, based on their merit
# Used on game start, but can also be used for generated characters
assign_completed_exams_based_on_merit_effect = {
	# Empire merit ranked vassals have always passed the palace exams
	if = {
		limit = {
			merit >= empire_starting_merit_value
		}
		add_character_flag = passed_child_exam
		add_character_flag = passed_provincial_exam
		add_character_modifier = {
			modifier = tgp_passed_provincial_exam_modifier
		}
		add_character_flag = passed_metropolitan_exam
		add_character_modifier = {
			modifier = tgp_passed_metropolitan_exam_modifier
		}
		add_character_flag = passed_palace_exam
		add_character_modifier = {
			modifier = tgp_passed_palace_exam_modifier
		}
	}
	# Kingdom merit ranked vassals have always passed the metropolitan exams
	else_if = {
		limit = {
			merit >= kingdom_starting_merit_value
		}
		add_character_flag = passed_child_exam
		add_character_flag = passed_provincial_exam
		add_character_modifier = {
			modifier = tgp_passed_provincial_exam_modifier
		}
		add_character_flag = passed_metropolitan_exam
		add_character_modifier = {
			modifier = tgp_passed_metropolitan_exam_modifier
		}
		if = { # The AI has a chance to start with having passed additional exams
			limit = {
				is_ai = yes
			}
			random = {
				chance = 50
				add_character_flag = passed_palace_exam
				add_character_modifier = {
					modifier = tgp_passed_palace_exam_modifier
				}
			}
		}
		change_merit = merit_starting_boost_value
	}
	# Duchy merit ranked vassals have always passed the provincial exams
	else_if = {
		limit = {
			merit >= duchy_starting_merit_value
		}
		add_character_flag = passed_child_exam
		add_character_flag = passed_provincial_exam
		add_character_modifier = {
			modifier = tgp_passed_provincial_exam_modifier
		}
		if = { # The AI has a chance to start with having passed additional exams
			limit = {
				is_ai = yes
			}
			random = {
				chance = 60
				add_character_flag = passed_metropolitan_exam
				add_character_modifier = {
					modifier = tgp_passed_metropolitan_exam_modifier
				}

				random = {
					chance = 30
					add_character_flag = passed_palace_exam
					add_character_modifier = {
						modifier = tgp_passed_palace_exam_modifier
					}
				}
			}
		}
		change_merit = merit_starting_boost_value
	}
	# Everyone else have a chance to having passed the provincial exams
	else = {
		if = { # The AI has a chance to start with having passed the provincial exams
			limit = {
				is_ai = yes
			}
			random_list = {
				10 = {}
				50 = {
					add_character_flag = passed_provincial_exam
					add_character_modifier = {
						modifier = tgp_passed_provincial_exam_modifier
					}
					change_merit = {
						value = county_starting_merit_value
						add = age
						add = learning
					}
				}
				25 = {
					add_character_flag = passed_provincial_exam
					add_character_modifier = {
						modifier = tgp_passed_provincial_exam_modifier
					}
					add_character_flag = passed_metropolitan_exam
					add_character_modifier = {
						modifier = tgp_passed_metropolitan_exam_modifier
					}
					change_merit = {
						value = county_starting_merit_value
						add = age
						add = learning
					}
				}
				15 = {
					add_character_flag = passed_provincial_exam
					add_character_modifier = {
						modifier = tgp_passed_provincial_exam_modifier
					}
					add_character_flag = passed_metropolitan_exam
					add_character_modifier = {
						modifier = tgp_passed_metropolitan_exam_modifier
					}
					add_character_flag = passed_palace_exam
					add_character_modifier = {
						modifier = tgp_passed_palace_exam_modifier
					}
					change_merit = {
						value = county_starting_merit_value
						add = age
						add = learning
					}
				}
			}
			# Chance to start with having passed child exams (for flavor)
			random = {
				chance = 60
				add_character_flag = passed_child_exam
			}
		}
	}
}

meritocratic_assign_completed_exams_based_on_merit_effect = {
	if = {
		limit = {
			merit >= duchy_starting_merit_value
		}
		add_character_flag = passed_provincial_exam
		add_character_modifier = {
			modifier = tgp_passed_provincial_exam_modifier
		}
	}
	# Everyone else have a chance to having passed the provincial exams
	else = {
		if = { # The AI has a chance to start with having passed the provincial exams
			limit = {
				is_ai = yes
			}
			random = {
				chance = {
					value = 40
					if = {
						limit = {
							is_ruler = yes
						}
						add = 20
					}
				}
				add_character_flag = passed_provincial_exam
				add_character_modifier = {
					modifier = tgp_passed_provincial_exam_modifier
				}
			}
		}
	}
}

tgp_save_realm_ceremonial_liege_effect = {
	if = {
		limit = { tgp_realm_has_ceremonial_liege_trigger = yes }
		top_liege.primary_title.var:administrative_ui_special_title.holder = { save_scope_as = ceremonial_liege }
	}
}

tgp_imperial_policy_event_effect = {
	save_scope_as = liege
	every_player = {
		limit = { top_liege = scope:liege }
		trigger_event = tgp_japan_general.9300
	}
}

tgp_treasury_setup_effect = {
	if = {
		limit = { has_treasury = yes }
		enact_treasury_budgets_init = yes
	}
}

# Enact treasury template effect
# If you update these, remember to update the corresponding tooltip!
tgp_treasury_enact_salary_budget_effect = {
	custom_tooltip = {
		text = tgp_treasury_enact_salary_budget_desc
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_salary_45 }
			}
			add_realm_law = budget_allocation_salary_45
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_ministry_25 }
			}
			add_realm_law = budget_allocation_ministry_25
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_military_20 }
			}
			add_realm_law = budget_allocation_military_20
		}

		enact_treasury_budgets_no_costs = yes
	}
}

tgp_treasury_enact_ministry_budget_effect = {
	custom_tooltip = {
		text = tgp_treasury_enact_ministry_budget_desc
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_salary_25 }
			}
			add_realm_law = budget_allocation_salary_25
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_ministry_45 }
			}
			add_realm_law = budget_allocation_ministry_45
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_military_20 }
			}
			add_realm_law = budget_allocation_military_20
		}

		enact_treasury_budgets_no_costs = yes
	}
}

tgp_treasury_enact_military_budget_effect = {
	custom_tooltip = {
		text = tgp_treasury_enact_military_budget_desc
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_salary_30 }
			}
			add_realm_law = budget_allocation_salary_30
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_ministry_20 }
			}
			add_realm_law = budget_allocation_ministry_20
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_military_40 }
			}
			add_realm_law = budget_allocation_military_40
		}

		enact_treasury_budgets_no_costs = yes
	}
}

tgp_treasury_enact_hegemon_budget_effect = {
	custom_tooltip = {
		text = tgp_treasury_enact_hegemon_budget_desc
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_salary_30 }
			}
			add_realm_law = budget_allocation_salary_30
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_ministry_25 }
			}
			add_realm_law = budget_allocation_ministry_25
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_military_25 }
			}
			add_realm_law = budget_allocation_military_25
		}

		enact_treasury_budgets_no_costs = yes
	}
}

tgp_treasury_enact_balanced_budget_effect = {
	custom_tooltip = {
		text = tgp_treasury_enact_balanced_budget_desc
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_salary_35 }
			}
			add_realm_law = budget_allocation_salary_35
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_ministry_30 }
			}
			add_realm_law = budget_allocation_ministry_30
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_military_25 }
			}
			add_realm_law = budget_allocation_military_25
		}

		enact_treasury_budgets_no_costs = yes
	}
}

tgp_treasury_enact_meritocratic_salary_budget_effect = {
	custom_tooltip = {
		text = tgp_treasury_enact_meritocratic_salary_budget_desc
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_salary_55 }
			}
			add_realm_law = budget_allocation_salary_55
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_military_35 }
			}
			add_realm_law = budget_allocation_military_35
		}

		enact_treasury_budgets_no_costs = yes
	}
}

tgp_treasury_enact_meritocratic_military_budget_effect = {
	custom_tooltip = {
		text = tgp_treasury_enact_meritocratic_military_budget_desc
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_salary_35 }
			}
			add_realm_law = budget_allocation_salary_35
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_military_55 }
			}
			add_realm_law = budget_allocation_military_55
		}

		enact_treasury_budgets_no_costs = yes
	}
}

tgp_treasury_enact_meritocratic_balanced_budget_effect = {
	custom_tooltip = {
		text = tgp_treasury_enact_meritocratic_balanced_budget_desc
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_salary_45 }
			}
			add_realm_law = budget_allocation_salary_45
		}
		if = {
			limit = {
				NOT = { has_realm_law = budget_allocation_military_45 }
			}
			add_realm_law = budget_allocation_military_45
		}

		enact_treasury_budgets_no_costs = yes
	}
}

tgp_save_opposing_power_effect = {
	if = { # You are the Regent
		limit = {
			tgp_is_ceremonial_regent_trigger = yes
		}
		primary_title.var:administrative_ui_special_title.holder = { save_scope_as = opposing_power }
	}
	else = { # You are the liege
		top_liege = { save_scope_as = opposing_power }
	}
}

tgp_one_up_activity_effect = {
	tgp_save_opposing_power_effect = yes
	add_prestige = massive_prestige_gain
	if = {
		limit = {
			government_has_flag =  government_is_administrative
		}
		change_influence = massive_influence_gain
	}
	scope:opposing_power = {
		add_prestige = massive_prestige_loss
		if = {
			limit = {
				government_has_flag =  government_is_administrative
			}
			change_influence = massive_influence_loss
		}
	}
}

destroy_landless_title_no_tgp_dlc_effect = {
	if = {
		limit = {
			NOT = { has_dlc_feature = all_under_heaven }
			game_start_date = $DATE$
		}
		holder = { destroy_title = prev }
	}
}

coup_ceremonial_liege_scheme_success_effect = {
	# scope:target = ceremonial liege
	# scope:owner = ceremonial regent
	scope:owner.top_liege.primary_title.var:administrative_ui_special_title = { save_scope_as = ceremonial_title }
	scope:target = {
		save_scope_as = background_dungeon_scope
		save_scope_as = background_courtyard_scope
		save_scope_as = background_throne_room_scope
	}
	# Old ruler's fate
	if = {
		limit = { exists = scope:death }
		scope:target = {
			death = { death_reason = death_fight }
		}
	}
	else_if = {
		limit = { exists = scope:imprison }
		scope:target = { add_character_flag = was_abducted_block_notification_event }
		rightfully_imprison_character_less_verbose_effect = {
			TARGET = scope:target
			IMPRISONER = scope:owner
		}
	}
	create_title_and_vassal_change = {
		type = conquest
		save_scope_as = change
		add_claim_on_loss = yes
	}
	scope:target = {
		every_held_title = {
			limit = {
				tier > tier_barony
				OR = {
					scope:owner.top_liege.primary_title.var:administrative_ui_special_title = this
					exists = var:ceremonial_title
					is_landless_type_title = no
				}
			}
			change_title_holder_include_vassals = {
				holder = scope:owner
				change = scope:change
			}
		}
	}
	resolve_title_and_vassal_change = scope:change
	rightfully_imprison_character_less_verbose_effect = {
		TARGET = scope:target
		IMPRISONER = scope:owner
	}
	add_clan_unity_interaction_effect = {
		CHARACTER = scope:owner
		TARGET = scope:target
		VALUE = medium_unity_loss
		DESC = clan_unity_coup_ceremonial_liege_attempted.desc
		REVERSE_NON_HOUSE_TARGET = no
	}
	successful_coup_ceremonial_liege_opinion_effect = {
		VICTIM = scope:target
		PLOTTER = scope:owner
	}
	scope:owner = {
		create_character_memory = {
			type = seized_throne_memory
			participants = { deposed = scope:target }
		}
		ordered_memory = {
			memory_type = seized_throne_memory
			order_by = memory_creation_date
			if = {
				limit = {
					NOT = { exists = var:ceremonial_title }
				}
				set_variable = {
					name = ceremonial_title
					value = scope:ceremonial_title
				}
			}
		}
	}
	scope:target = {
		create_character_memory = {
			type = throne_seized_memory
			participants = { deposer = scope:owner }
		}
		ordered_memory = {
			memory_type = throne_seized_memory
			order_by = memory_creation_date
			if = {
				limit = {
					NOT = { exists = var:ceremonial_title }
				}
				set_variable = {
					name = ceremonial_title
					value = scope:ceremonial_title
				}
			}
		}
	}
}

coup_ceremonial_liege_scheme_failure_effect = {
	scope:owner.top_liege.primary_title.var:administrative_ui_special_title = { save_scope_as = ceremonial_title }
	scope:scheme = { end_scheme = yes }
 	#Add Watchful Modifier to the target
	scope:target = {
		save_scope_as = background_dungeon_scope
		save_scope_as = background_courtyard_scope
		save_scope_as = background_throne_room_scope
		show_as_tooltip = {
			add_character_modifier = {
				modifier = watchful_modifier
				days = watchful_modifier_duration
			}
		}
	}
	scope:owner = {
		create_character_memory = {
			type = seized_throne_failed_memory
			participants = { deposed = scope:target }
		}
		ordered_memory = {
			memory_type = seized_throne_failed_memory
			order_by = memory_creation_date
			if = {
				limit = {
					NOT = { exists = var:ceremonial_title }
				}
				set_variable = {
					name = ceremonial_title
					value = scope:ceremonial_title
				}
			}
		}
		add_character_flag = was_abducted_block_notification_event
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		every_held_title = {
			limit = {
				is_landless_type_title = no
				tier > tier_barony
			}
			change_title_holder_include_vassals = {
				holder = scope:target
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
	}
	hidden_effect = { change_prison_type = dungeon }
	rightfully_imprison_character_less_verbose_effect = {
		TARGET = scope:owner
		IMPRISONER = scope:target
	}
	attempted_coup_ceremonial_liege_opinion_effect = {
		VICTIM = scope:target
		PLOTTER = scope:owner
	}
	# If we're a clan this affects unity
	add_clan_unity_interaction_effect = {
		CHARACTER = scope:owner
		TARGET = scope:target
		VALUE = medium_unity_loss
		DESC = clan_unity_coup_ceremonial_liege_attempted.desc
		REVERSE_NON_HOUSE_TARGET = no
	}
	scope:target = {
		create_character_memory = {
			type = throne_seized_failed_memory
			participants = { deposer = scope:owner }
		}
		ordered_memory = {
			memory_type = throne_seized_failed_memory
			order_by = memory_creation_date
			if = {
				limit = {
					NOT = { exists = var:ceremonial_title }
				}
				set_variable = {
					name = ceremonial_title
					value = scope:ceremonial_title
				}
			}
		}
	}
}

successful_coup_ceremonial_liege_opinion_effect = {
	$VICTIM$ = {
		if = {
			limit = { is_alive = yes }
			add_opinion = {
				target = $PLOTTER$
				modifier = seized_my_throne_crime
			}
			set_relation_rival = {
				target = scope:owner
				reason = rival_seized_throne_reason
			}
		}
		every_spouse = {
			limit = {
				NOR = {
					this = $PLOTTER$
					is_spouse_of = $PLOTTER$
					is_close_family_of = $PLOTTER$
				}
			}
			add_to_temporary_list = close_family_coup_ceremonial_liege_opinion_list
		}
		every_close_family_member = {
			limit = {
				NOR = {
					this = $PLOTTER$
					is_spouse_of = $PLOTTER$
					is_close_family_of = $PLOTTER$
				}
			}
			add_to_temporary_list = close_family_coup_ceremonial_liege_opinion_list
		}
		every_in_list = {
			list = close_family_coup_ceremonial_liege_opinion_list
			limit = { top_liege = scope:owner.top_liege }
			rightfully_imprison_character_less_verbose_effect = {
				TARGET = this
				IMPRISONER = scope:owner
			}
		}
		every_in_list = {
			list = close_family_coup_ceremonial_liege_opinion_list
			custom = all_close_family_and_spouses
			add_opinion = {
				target = $PLOTTER$
				modifier = seized_close_family_throne_crime
			}
		}
	}
}

attempted_coup_ceremonial_liege_opinion_effect = {
	$VICTIM$ = {
		if = {
			limit = { is_alive = yes }
			add_opinion = {
				target = $PLOTTER$
				modifier = attempted_to_seize_my_throne_crime
			}
		}
		every_spouse = {
			limit = { NOT = { this = $PLOTTER$ } }
			add_to_temporary_list = close_family_coup_ceremonial_liege_opinion_list
		}
		every_close_family_member = {
			limit = { NOT = { this = $PLOTTER$ } }
			add_to_temporary_list = close_family_coup_ceremonial_liege_opinion_list
		}
		if = {
			limit = {
				any_in_list = { list = close_family_coup_ceremonial_liege_opinion_list }
			}
			every_in_list = {
				list = close_family_coup_ceremonial_liege_opinion_list
				custom = all_close_family_and_spouses
				add_opinion = {
					target = $PLOTTER$
					modifier = attempted_to_seize_throne_close_family_crime
				}
			}
		}
	}
}

nomad_domicile_refund_treasury_or_gold_effect = {
	#Domicile buildings give cash refund
	if = {
		limit = {
			has_domicile = yes
		}
		save_scope_as = former_nomad
		custom_tooltip = nomad_domicile_buildings_converted_for_treasury_or_gold
		hidden_effect = {
			save_scope_value_as = {
				name = domicile_refund_treasury_or_gold_value
				value = {
					value = medium_gold_value
					switch = {
						trigger = domicile.num_domicile_buildings
						7 = { multiply = 7 }
						6 = { multiply = 6 }
						5 = { multiply = 5 }
						4 = { multiply = 4 }
						3 = { multiply = 3 }
						2 = { multiply = 2 }
					}
				}
			}
		}
	}
}

nomad_convert_herds_to_treasury_or_gold_special_troops_effect = {
	save_scope_as = former_nomad
	custom_tooltip = treasury_or_gold_army_for_herd_tt
	hidden_effect = {
		if = {
			limit = {
				domicile.herd >= 50
			}
			save_scope_as = army_getter
			save_scope_value_as = {
				name = nomad_convert_herds_to_treasury_or_gold_value
				value = {
					value = domicile.herd
					multiply = 0.3
					min = 100
					max = 10000
				}
			}
			spawn_army = {
				levies = 200
				men_at_arms = {
					type = horse_archers
					men = { value = domicile.herd multiply = 0.02 min = 100 max = 10000 }
				}
				men_at_arms = {
					type = steppe_raiders
					men = { value = domicile.herd multiply = 0.01 min = 100 max = 10000 }
				}
				men_at_arms = {
					type = nomad_lancers
					men = { value = domicile.herd multiply = 0.01 min = 100 max = 10000 }
				}
				men_at_arms = {
					type = nomadic_riders
					men = { value = domicile.herd multiply = 0.1 min = 100 max = 10000 }
				}
				location = capital_province
				inheritable = yes
				uses_supply = yes
				name = former_nomad_army_name
			}
		}
	}
}

empty_treasury_when_abandoning_landed_life_effect = {
	if = {
		limit = {
			treasury > 0
		}
		save_scope_value_as = {
			name = current_treasury
			value = treasury
		}
		remove_treasury = {
			value = scope:current_treasury
		}
	}
}

refund_noble_family_domicile_buildings_effect = {
	if = {
		limit = {
			has_domicile = yes
		}
		save_scope_as = former_noble_family_head
		custom_tooltip = noble_family_domicile_buildings_converted
		hidden_effect = {
			add_gold = {
				value = {
					value = medium_gold_value
					switch = {
						trigger = domicile.num_domicile_buildings
						7 = { multiply = 7 }
						6 = { multiply = 6 }
						5 = { multiply = 5 }
						4 = { multiply = 4 }
						3 = { multiply = 3 }
						2 = { multiply = 2 }
					}
				}
			}
		}
	}
}

refund_vassal_noble_families_and_make_them_nomads_effect = {
	if = {
		limit = {
			any_vassal = {
				is_landless_ruler = yes
				culture = {
					has_same_culture_heritage = root.culture
				}
				any_held_title = {
					is_noble_family_title = yes
				}
			}
		}
		every_vassal = {
			limit = {
				is_landless_ruler = yes
				culture = {
					has_same_culture_heritage = root.culture
				}
				any_held_title = {
					is_noble_family_title = yes
				}
			}
			if = {
				limit = {
					has_domicile = yes
				}
				add_gold = {
					value = {
						value = medium_gold_value
						switch = {
							trigger = domicile.num_domicile_buildings
							7 = { multiply = 7 }
							6 = { multiply = 6 }
							5 = { multiply = 5 }
							4 = { multiply = 4 }
							3 = { multiply = 3 }
							2 = { multiply = 2 }
						}
					}
				}
			}
			change_government = nomad_government
			if = {
				limit = { NOT = { has_trait = nomadic_philosophy } }
				add_trait = nomadic_philosophy
			}
			every_held_title = {
				limit = {
					is_noble_family_title = yes
				}
				holder = {
					destroy_title = prev
				}
			}
		}
	}
}

rehome_noble_families_to_compatible_liege_effect = {
	if = {
		limit = {
			any_vassal = {
				is_landless_ruler = yes
				NOT = {
					culture = {
						has_same_culture_heritage = root.culture
					}
				}
				any_held_title = {
					is_noble_family_title = yes
				}
			}
		}
		if = {
			limit = {
				any_vassal = {
					is_landed = yes
					highest_held_title_tier >= tier_kingdom
					government_has_flag = government_has_merit
				}
			}
			random_vassal = {
				limit = {
					is_landed = yes
					highest_held_title_tier >= tier_kingdom
					government_has_flag = government_has_merit
				}
				save_scope_as = new_liege_for_homeless_families
			}
		}
		else_if = {
			limit = {
				any_tributary = {
					highest_held_title_tier >= tier_kingdom
					government_has_flag = government_has_merit
				}
			}
			random_tributary = {
				limit = {
					highest_held_title_tier >= tier_kingdom
					government_has_flag = government_has_merit
				}
				save_scope_as = new_liege_for_homeless_families
			}
		}
		else_if = {
			limit = {
				any_neighboring_top_liege_realm_owner = {
					government_has_flag = government_has_merit
					highest_held_title_tier >= tier_empire
				}
			}
			random_neighboring_top_liege_realm_owner = {
				limit = {
					government_has_flag = government_has_merit
					highest_held_title_tier >= tier_hegemony
				}
				save_scope_as = new_liege_for_homeless_families
			}
		}
		else_if = {
			limit = {
				any_independent_ruler = {
					NOT = {
						this = root
					}
					in_diplomatic_range = root
					government_has_flag = government_has_merit
					highest_held_title_tier >= tier_empire
				}
			}
			random_independent_ruler = {
				limit = {
					NOT = {
						this = root
					}
					in_diplomatic_range = root
					government_has_flag = government_has_merit
					highest_held_title_tier >= tier_empire
				}
				save_scope_as = new_liege_for_homeless_families
			}
		}
		else_if = {
			limit = {
				any_independent_ruler = {
					NOT = {
						this = root
					}
					in_diplomatic_range = root
					government_has_flag = government_has_merit
					highest_held_title_tier >= tier_kingdom
				}
			}
			random_independent_ruler = {
				limit = {
					NOT = {
						this = root
					}
					in_diplomatic_range = root
					government_has_flag = government_has_merit
					highest_held_title_tier >= tier_kingdom
				}
				save_scope_as = new_liege_for_homeless_families
			}
		}
		if = {
			limit = {
				exists = scope:new_liege_for_homeless_families
			}
			every_vassal = {
				limit = {
					is_landless_ruler = yes
					NOT = {
						culture = {
							has_same_culture_heritage = root.culture
						}
					}
					any_held_title = {
						is_noble_family_title = yes
					}
				}
				create_title_and_vassal_change = {
					type = swear_fealty
					save_scope_as = title_change
				}
				change_liege = {
					liege = scope:new_liege_for_homeless_families
					change = scope:title_change
				}
				resolve_title_and_vassal_change = scope:title_change
				domicile = {
					move_domicile = scope:new_liege_for_homeless_families.capital_province
				}
			}
		}
		else = {
			every_vassal = {
				limit = {
					is_landless_ruler = yes
					NOT = {
						culture = {
							has_same_culture_heritage = root.culture
						}
					}
					any_held_title = {
						is_noble_family_title = yes
					}
				}
				every_held_title = {
					limit = {
						is_noble_family_title = yes
					}
					holder = {
						destroy_title = prev
					}
				}
				move_to_pool_effect = yes
			}
		}
	}
}

convert_steppe_admin_vassals_to_meritocratic_effect = {
	if = {
		limit = {
			any_vassal_or_below = {
				government_has_flag = government_is_steppe_admin
			}
		}
		every_vassal_or_below = {
			limit = {
				government_has_flag = government_is_steppe_admin
			}
			change_government = meritocratic_government
		}
	}
}

nomad_to_steppe_admin_new_capital_effect = {
	every_sub_realm_county = {
		limit = {
			title_province = {
				NOR = {
					has_holding_type = nomad_holding
					has_holding_type = herder_holding
					has_holding_type = tribal_holding
				}
			}
		}
		add_to_list = potential_new_capitals
	}
	every_held_title = {
		limit = {
			tier = tier_county
			title_province = {
				NOR = {
					has_holding_type = nomad_holding
					has_holding_type = herder_holding
					has_holding_type = tribal_holding
				}
			}
		}
		add_to_list = potential_new_capitals
	}
	ordered_in_list = {
		order_by = development_level
		list = potential_new_capitals
		save_scope_as = new_capital
	}
	if = {
		limit = {
			capital_county = {
				title_province = {
					NOR = {
						has_holding_type = nomad_holding
						has_holding_type = herder_holding
						has_holding_type = tribal_holding
					}
				}
			}
		}
		capital_county = {
			save_scope_as = new_capital
		}
	}
	if = {
		limit = {
			exists = scope:new_capital
			capital_county != scope:new_capital
		}
		if = {
			limit = {
				scope:new_capital.holder != root
			}
			create_title_and_vassal_change = {
				type = usurped
				save_scope_as = change
				add_claim_on_loss = yes
			}
			scope:new_capital = {
				change_title_holder = {
					holder = root
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}
		set_realm_capital = scope:new_capital
	}
	scope:new_capital.duchy = { save_scope_as = nomad_duchy_for_name }
	#Should gain target title, if possible
	if = {
		limit = {
			scope:new_capital.kingdom = {
				NOT = {
					exists = holder
				}
			}
		}
		create_title_and_vassal_change = {
			type = created
			save_scope_as = change
			add_claim_on_loss = yes
		}
		scope:new_capital.kingdom = {
			save_scope_as = new_primary
			change_title_holder = {
				holder = root
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
	}
	if = {
		limit = {
			scope:new_capital.duchy = {
				NOT = {
					exists = holder
				}
			}
		}
		hidden_effect = {
			create_title_and_vassal_change = {
				type = created
				save_scope_as = change_1
				add_claim_on_loss = yes
			}
			scope:new_capital.duchy = {
				change_title_holder = {
					holder = root
					change = scope:change_1
				}
			}
			resolve_title_and_vassal_change = scope:change_1
		}
	}
	#For GoK, they keep using their Gok Title
	if = {
		limit = {
			AND = {
				exists = global_var:greatest_of_khans_title
				primary_title = global_var:greatest_of_khans_title
			}
		}
		primary_title = {
			set_can_be_named_after_dynasty = yes
			set_definitive_form = yes
			save_scope_as = new_primary
			save_scope_as = new_title
			set_capital_county = scope:new_capital
		}
	}
	#Otherwise, gain titular empire
	else = {
		hidden_effect = {
			create_dynamic_title = {
				tier = empire
				name = SETTLED_NOMAD_STEPPE_ADMIN_EMPIRE_NAME
				adj = SETTLED_NOMAD_STEPPE_ADMIN_EMPIRE_ADJ
			}
			scope:new_title = {
				save_scope_as = new_primary
				set_definitive_form = yes
			}
			create_title_and_vassal_change = {
				type = created
				save_scope_as = change_2
				add_claim_on_loss = no
			}
			scope:new_title = {
				set_can_be_named_after_dynasty = yes
				change_title_holder = {
					holder = root
					change = scope:change_2
				}
			}
			resolve_title_and_vassal_change = scope:change_2
			scope:new_title = { generate_coa = yes }
		}
		#Make this their primary title, if highest tier
		hidden_effect = {
			if = {
				limit = {
					exists = scope:new_primary
					NOT = {
						highest_held_title_tier > scope:new_primary.tier
					}
				}
				set_primary_title_to = scope:new_primary
				scope:new_primary = {
					set_capital_county = scope:new_capital
				}
			}
		}
	}
}

generate_new_steppe_admin_families_effect = {
	while = {
		count = 10
		create_character = {
			template = tgp_steppe_admin_family_head_template
			culture = root.capital_county.culture
			faith = root.capital_county.faith
			location = root.location
			dynasty = generate
			after_creation = {
				add_to_list = new_steppe_admin_family_heads
				set_employer = root
			}
		}
	}
	every_in_list = {
		list = new_steppe_admin_family_heads
		give_noble_family_title = {
			name = noble_family_name
			tier = county
			article = DEFAULT_TITLE_NAME_ARTICLE
			government = steppe_admin_government
			save_scope_as = new_title
		}
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = change
	}
	every_in_list = {
		list = new_steppe_admin_family_heads
		change_liege = {
			liege = root
			change = scope:change
		}
	}
	resolve_title_and_vassal_change = scope:change
	scope:new_title = {
		set_coa = holder.house
	}
}

tgp_cranial_trophies_beheading_effect = {
	$KILLER$ = {
		save_temporary_scope_as = the_killer # for the Artifact localization
	}
	$DEAD$ = {
		save_temporary_scope_as = dead_one # for the Artifact localization
		save_scope_as = dead_character
	}
	if = {
		limit = {
			$DEAD$ = {
				highest_held_title_tier = tier_hegemony
			}
		}
		$KILLER$ = {
			create_artifact = {
				name = tgp_cranial_trophy_artifact
				description = tgp_cranial_trophy_artifact_desc
				rarity = illustrious
				type = miscellaneous
				modifier = cranial_trophy_modifier_t6
				decaying = yes
				template = tgp_severed_head_template
				visuals = pocket_severed_head
				creator = $DEAD$
				save_scope_as = new_head_artifact
			}
		}
	}
	else_if = {
		limit = {
			$DEAD$ = {
				highest_held_title_tier = tier_empire
			}
		}
		$KILLER$ = {
			create_artifact = {
				name = tgp_cranial_trophy_artifact
				description = tgp_cranial_trophy_artifact_desc
				rarity = illustrious
				type = miscellaneous
				modifier = cranial_trophy_modifier_t5
				decaying = yes
				template = tgp_severed_head_template
				visuals = pocket_severed_head
				creator = $DEAD$
				save_scope_as = new_head_artifact
			}
		}
	}
	else_if = {
		limit = {
			$DEAD$ = {
				highest_held_title_tier = tier_kingdom
			}
		}
		$KILLER$ = {
			create_artifact = {
				name = tgp_cranial_trophy_artifact
				description = tgp_cranial_trophy_artifact_desc
				rarity = famed
				type = miscellaneous
				modifier = cranial_trophy_modifier_t4
				decaying = yes
				template = tgp_severed_head_template
				visuals = pocket_severed_head
				creator = $DEAD$
				save_scope_as = new_head_artifact
			}
		}
	}
	else_if = {
		limit = {
			$DEAD$ = {
				highest_held_title_tier = tier_duchy
			}
		}
		$KILLER$ = {
			create_artifact = {
				name = tgp_cranial_trophy_artifact
				description = tgp_cranial_trophy_artifact_desc
				rarity = famed
				type = miscellaneous
				modifier = cranial_trophy_modifier_t3
				decaying = yes
				template = tgp_severed_head_template
				visuals = pocket_severed_head
				creator = $DEAD$
				save_scope_as = new_head_artifact
			}
		}
	}
	else_if = {
		limit = {
			$DEAD$ = {
				highest_held_title_tier = tier_county
			}
		}
		$KILLER$ = {
			create_artifact = {
				name = tgp_cranial_trophy_artifact
				description = tgp_cranial_trophy_artifact_desc
				rarity = masterwork
				type = miscellaneous
				modifier = cranial_trophy_modifier_t2
				decaying = yes
				template = tgp_severed_head_template
				visuals = pocket_severed_head
				creator = $DEAD$
				save_scope_as = new_head_artifact
			}
		}
	}
	else_if = {
		limit = {
			$DEAD$ = {
				highest_held_title_tier = tier_barony
			}
		}
		$KILLER$ = {
			create_artifact = {
				name = tgp_cranial_trophy_artifact
				description = tgp_cranial_trophy_artifact_desc
				rarity = masterwork
				type = miscellaneous
				modifier = cranial_trophy_modifier_t1
				decaying = yes
				template = tgp_severed_head_template
				visuals = pocket_severed_head
				creator = $DEAD$
				save_scope_as = new_head_artifact
			}
		}
	}
	else = {
		$KILLER$ = {
			create_artifact = {
				name = tgp_cranial_trophy_artifact
				description = tgp_cranial_trophy_artifact_desc
				rarity = common
				type = miscellaneous
				modifier = cranial_trophy_modifier_t0
				decaying = yes
				template = tgp_severed_head_template
				visuals = pocket_severed_head
				creator = $DEAD$
				save_scope_as = new_head_artifact
			}
		}
	}
	scope:new_head_artifact = {
		flag_as_trash_artifact = yes
	}
	$KILLER$ = {
		add_piety = {
			value = cranial_trophies_stolen_prestige_value
		}
	}
}

generate_ci_poem_title_effect = {
	#For use with the [SCOPE.Custom('GetCiPoemName')] loc key. This sets a poem.
	#Only needed if you want a randomized but persistent name - otherwise we just use the custom loc key directly and it works out of the box.
	random_list = {
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:riverside_city
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:green_jade_bowl
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:scent_fills_the_hall
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:lady_yu
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:butterflies_love_blossoms
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:plucking_mulberry_leafs
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:rivertown_man
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:fragrance_filling_the_hall
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:butterflies_kiss_flowers
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:spring_in_the_han_palace
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:winds_between_pine_trees
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:memories_of_the_past_at_red_cliff
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:my_wrath_bristles_through_my_helmet
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:thinking_of_the_past_at_beigu_pavilion
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:dream_song
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:picking_mulberry
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:as_in_a_dream
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:immortal_by_the_river
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:longing_for_qin_e
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:new_chrysanthemum_flowers
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:poluomen_son
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:pouring_out_deep_emotions
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:rain_hits_a_bell
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:spring_in_the_tower_of_jade
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:drunk_in_the_fairyland
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:anxiety_of_a_beauty
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:writing_of_my_sorrow
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:sad_remembrance
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:on_the_advent_of_spring
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:silk_washing_stream
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:at_an_inn_in_xinshi
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:on_red_lotus_petals
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:pusa_man
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:a_quiet_night
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:huanxi_sand
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:overlapping_golden_light_of_small_hills
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:the_river_is_red
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:the_road_is_difficult
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:phoenix_hairpin
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:boating_on_tai_lake
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:prelude_to_the_water_song
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:rambling_young_man
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:king_of_lanling
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:washing_creek_sands
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:magnolia_blossoms
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:petals_falling_in_the_river
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:my_way_passed_ancient_tombs
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:the_water_clock_sings_at_night
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:dreaming_of_the_south_side_of_the_river
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:beautiful_barbarian
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:missing_the_emperors_hometown
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:daoist_priestess
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:a_bushel_of_pearls
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:bodhisattva_barbarian
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:clear_and_even_music
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:lost_battle
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:beauty_yu
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:crows_cry_at_night
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:phoenix_perched_on_the_parasol_tree
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:imperial_avenue_procession
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:rain_hits_a_bell
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:divination_song
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:attached_to_her_skirt
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:partridge_sky
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:mountain_hawthorn
			}
		}
		1 = {
			save_scope_value_as = {
				name = poem_tune
				value = flag:the_song_of_tangduo
			}
		}
	}
}

tgp_step_down_title_recipient_tooltip_effect = {
	if = {
		limit = { is_independent_ruler = no }
		top_liege = { save_temporary_scope_as = fallback_temp }
	}
	else = {
		primary_title.current_heir = { save_temporary_scope_as = fallback_temp }
	}
	show_as_tooltip = {
		create_title_and_vassal_change = {
			type = appointment
			save_scope_as = change
		}
		every_held_title = {
			limit = {
				is_landless_type_title = no
				tier > tier_barony
			}
			save_temporary_scope_as = lost_title_temp
			current_heir ?= { save_temporary_scope_as = heir_temp }
			if = {
				limit = { NOT = { exists = scope:heir_temp } }
				scope:fallback_temp = { save_temporary_scope_as = heir_temp }
			}
			change_title_holder = {
				holder = scope:heir_temp
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
	}
}

tgp_domicile_conversion_when_changing_government_type = {
	hidden_effect = {
		if = {
			limit = {
				any_held_title = {
					is_noble_family_title = yes
				}
				has_domicile = yes
				NOT = {
					domicile ?= {
						is_domicile_type = $NEW_DOMICILE_TYPE$
					}
				}
			}
			random_held_title = {
				limit = {
					is_noble_family_title = yes
				}
				save_scope_as = old_nf_title
			}
			tgp_wipe_domicile_effect = yes
			if = {
				limit = {
					has_character_flag = new_government_is_byz_admin
				}
				give_noble_family_title = {
					name = noble_family_name
					tier = duchy
					article = DEFAULT_TITLE_NAME_ARTICLE
					government = $NEW_GOVERNMENT_TYPE$
					save_scope_as = new_title
				}
			}
			else = {
				give_noble_family_title = {
					name = noble_family_name
					tier = county
					article = DEFAULT_TITLE_NAME_ARTICLE
					government = $NEW_GOVERNMENT_TYPE$
					save_scope_as = new_title
				}
			}
			scope:new_title = {
				copy_title_history = scope:old_nf_title
			}
			destroy_title = scope:old_nf_title
			domicile ?= {
				set_up_domicile_estate_effect = yes
			}
		}
	}
}

tgp_wipe_domicile_effect = {
	domicile ?= {
		if = {
			limit = { has_domicile_building = east_asian_estate_main_01 }
			remove_domicile_building = east_asian_estate_main_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_main_02 }
			remove_domicile_building = east_asian_estate_main_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_main_03 }
			remove_domicile_building = east_asian_estate_main_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_main_04 }
			remove_domicile_building = east_asian_estate_main_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_main_05 }
			remove_domicile_building = east_asian_estate_main_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_library_01 }
			remove_domicile_building = east_asian_estate_library_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_library_02 }
			remove_domicile_building = east_asian_estate_library_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_library_education_03 }
			remove_domicile_building = east_asian_estate_library_education_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_library_education_04 }
			remove_domicile_building = east_asian_estate_library_education_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_taxation_01 }
			remove_domicile_building = east_asian_estate_taxation_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_taxation_02 }
			remove_domicile_building = east_asian_estate_taxation_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_taxation_03 }
			remove_domicile_building = east_asian_estate_taxation_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_taxation_04 }
			remove_domicile_building = east_asian_estate_taxation_04
		}
		if = {
			limit = { has_domicile_building = east_asian_peasant_quarters_01 }
			remove_domicile_building = east_asian_peasant_quarters_01
		}
		if = {
			limit = { has_domicile_building = east_asian_peasant_quarters_02 }
			remove_domicile_building = east_asian_peasant_quarters_02
		}
		if = {
			limit = { has_domicile_building = east_asian_peasant_quarters_03 }
			remove_domicile_building = east_asian_peasant_quarters_03
		}
		if = {
			limit = { has_domicile_building = east_asian_peasant_quarters_04 }
			remove_domicile_building = east_asian_peasant_quarters_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_minister_office_01 }
			remove_domicile_building = east_asian_estate_minister_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_minister_office_02 }
			remove_domicile_building = east_asian_estate_minister_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_minister_office_03 }
			remove_domicile_building = east_asian_estate_minister_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_minister_office_04 }
			remove_domicile_building = east_asian_estate_minister_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_movement_study_01 }
			remove_domicile_building = east_asian_estate_movement_study_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_movement_study_02 }
			remove_domicile_building = east_asian_estate_movement_study_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_movement_study_03 }
			remove_domicile_building = east_asian_estate_movement_study_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_movement_study_04 }
			remove_domicile_building = east_asian_estate_movement_study_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_archive_01 }
			remove_domicile_building = east_asian_estate_archive_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_archive_02 }
			remove_domicile_building = east_asian_estate_archive_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_archive_03 }
			remove_domicile_building = east_asian_estate_archive_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_archive_04 }
			remove_domicile_building = east_asian_estate_archive_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cartography_office_01 }
			remove_domicile_building = east_asian_estate_cartography_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cartography_office_02 }
			remove_domicile_building = east_asian_estate_cartography_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cartography_office_03 }
			remove_domicile_building = east_asian_estate_cartography_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cartography_office_04 }
			remove_domicile_building = east_asian_estate_cartography_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drafting_room_01 }
			remove_domicile_building = east_asian_estate_drafting_room_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drafting_room_02 }
			remove_domicile_building = east_asian_estate_drafting_room_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drafting_room_03 }
			remove_domicile_building = east_asian_estate_drafting_room_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drafting_room_04 }
			remove_domicile_building = east_asian_estate_drafting_room_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_clerks_hall_01 }
			remove_domicile_building = east_asian_estate_clerks_hall_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_clerks_hall_02 }
			remove_domicile_building = east_asian_estate_clerks_hall_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_clerks_hall_03 }
			remove_domicile_building = east_asian_estate_clerks_hall_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_clerks_hall_04 }
			remove_domicile_building = east_asian_estate_clerks_hall_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_revenue_audit_desk_01 }
			remove_domicile_building = east_asian_estate_revenue_audit_desk_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_revenue_audit_desk_02 }
			remove_domicile_building = east_asian_estate_revenue_audit_desk_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_revenue_audit_desk_03 }
			remove_domicile_building = east_asian_estate_revenue_audit_desk_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_revenue_audit_desk_04 }
			remove_domicile_building = east_asian_estate_revenue_audit_desk_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_block_printing_hall_01 }
			remove_domicile_building = east_asian_estate_block_printing_hall_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_block_printing_hall_02 }
			remove_domicile_building = east_asian_estate_block_printing_hall_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_block_printing_hall_03 }
			remove_domicile_building = east_asian_estate_block_printing_hall_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_block_printing_hall_04 }
			remove_domicile_building = east_asian_estate_block_printing_hall_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_xuan_paper_stores_01 }
			remove_domicile_building = east_asian_estate_xuan_paper_stores_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_xuan_paper_stores_02 }
			remove_domicile_building = east_asian_estate_xuan_paper_stores_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_xuan_paper_stores_03 }
			remove_domicile_building = east_asian_estate_xuan_paper_stores_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_xuan_paper_stores_04 }
			remove_domicile_building = east_asian_estate_xuan_paper_stores_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_water_clock_room_01 }
			remove_domicile_building = east_asian_estate_water_clock_room_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_water_clock_room_02 }
			remove_domicile_building = east_asian_estate_water_clock_room_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_water_clock_room_03 }
			remove_domicile_building = east_asian_estate_water_clock_room_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_water_clock_room_04 }
			remove_domicile_building = east_asian_estate_water_clock_room_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_examination_room_01 }
			remove_domicile_building = east_asian_estate_examination_room_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_examination_room_02 }
			remove_domicile_building = east_asian_estate_examination_room_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_examination_room_03 }
			remove_domicile_building = east_asian_estate_examination_room_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_examination_room_04 }
			remove_domicile_building = east_asian_estate_examination_room_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_living_quarters_01 }
			remove_domicile_building = east_asian_estate_living_quarters_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_living_quarters_02 }
			remove_domicile_building = east_asian_estate_living_quarters_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_living_quarters_03 }
			remove_domicile_building = east_asian_estate_living_quarters_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_living_quarters_04 }
			remove_domicile_building = east_asian_estate_living_quarters_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_study_01 }
			remove_domicile_building = east_asian_estate_study_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_study_02 }
			remove_domicile_building = east_asian_estate_study_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_study_03 }
			remove_domicile_building = east_asian_estate_study_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_study_04 }
			remove_domicile_building = east_asian_estate_study_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_commander_study_01 }
			remove_domicile_building = east_asian_estate_commander_study_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_commander_study_02 }
			remove_domicile_building = east_asian_estate_commander_study_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_commander_study_03 }
			remove_domicile_building = east_asian_estate_commander_study_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_commander_study_04 }
			remove_domicile_building = east_asian_estate_commander_study_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_office_01 }
			remove_domicile_building = east_asian_estate_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_office_02 }
			remove_domicile_building = east_asian_estate_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_office_03 }
			remove_domicile_building = east_asian_estate_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_office_04 }
			remove_domicile_building = east_asian_estate_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_servants_quarters_01 }
			remove_domicile_building = east_asian_estate_servants_quarters_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_servants_quarters_02 }
			remove_domicile_building = east_asian_estate_servants_quarters_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_servants_quarters_03 }
			remove_domicile_building = east_asian_estate_servants_quarters_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_servants_quarters_04 }
			remove_domicile_building = east_asian_estate_servants_quarters_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bath_01 }
			remove_domicile_building = east_asian_estate_bath_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bath_02 }
			remove_domicile_building = east_asian_estate_bath_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bath_03 }
			remove_domicile_building = east_asian_estate_bath_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bath_04 }
			remove_domicile_building = east_asian_estate_bath_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_guest_room_01 }
			remove_domicile_building = east_asian_estate_guest_room_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_guest_room_02 }
			remove_domicile_building = east_asian_estate_guest_room_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_guest_room_03 }
			remove_domicile_building = east_asian_estate_guest_room_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_guest_room_04 }
			remove_domicile_building = east_asian_estate_guest_room_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_wine_cellar_01 }
			remove_domicile_building = east_asian_estate_wine_cellar_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_wine_cellar_02 }
			remove_domicile_building = east_asian_estate_wine_cellar_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_wine_cellar_03 }
			remove_domicile_building = east_asian_estate_wine_cellar_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_courtyard_01 }
			remove_domicile_building = east_asian_estate_courtyard_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_courtyard_02 }
			remove_domicile_building = east_asian_estate_courtyard_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_courtyard_03 }
			remove_domicile_building = east_asian_estate_courtyard_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_courtyard_04 }
			remove_domicile_building = east_asian_estate_courtyard_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_prison_01 }
			remove_domicile_building = east_asian_estate_prison_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_prison_02 }
			remove_domicile_building = east_asian_estate_prison_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_prison_03 }
			remove_domicile_building = east_asian_estate_prison_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_prison_04 }
			remove_domicile_building = east_asian_estate_prison_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_reception_hall_01 }
			remove_domicile_building = east_asian_estate_reception_hall_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_reception_hall_02 }
			remove_domicile_building = east_asian_estate_reception_hall_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_reception_hall_03 }
			remove_domicile_building = east_asian_estate_reception_hall_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_reception_hall_04 }
			remove_domicile_building = east_asian_estate_reception_hall_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_reception_hall_05 }
			remove_domicile_building = east_asian_estate_reception_hall_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cabinet_of_curiosities_01 }
			remove_domicile_building = east_asian_estate_cabinet_of_curiosities_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cabinet_of_curiosities_02 }
			remove_domicile_building = east_asian_estate_cabinet_of_curiosities_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cabinet_of_curiosities_03 }
			remove_domicile_building = east_asian_estate_cabinet_of_curiosities_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_field_01 }
			remove_domicile_building = east_asian_estate_rice_field_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_field_02 }
			remove_domicile_building = east_asian_estate_rice_field_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_field_03 }
			remove_domicile_building = east_asian_estate_rice_field_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_field_04 }
			remove_domicile_building = east_asian_estate_rice_field_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_field_05 }
			remove_domicile_building = east_asian_estate_rice_field_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_field_06 }
			remove_domicile_building = east_asian_estate_rice_field_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_01 }
			remove_domicile_building = east_asian_estate_tea_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_02 }
			remove_domicile_building = east_asian_estate_tea_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_03 }
			remove_domicile_building = east_asian_estate_tea_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_04 }
			remove_domicile_building = east_asian_estate_tea_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_05 }
			remove_domicile_building = east_asian_estate_tea_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_06 }
			remove_domicile_building = east_asian_estate_tea_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_market_01 }
			remove_domicile_building = east_asian_estate_market_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_market_02 }
			remove_domicile_building = east_asian_estate_market_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_market_03 }
			remove_domicile_building = east_asian_estate_market_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_market_04 }
			remove_domicile_building = east_asian_estate_market_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_market_05 }
			remove_domicile_building = east_asian_estate_market_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_market_06 }
			remove_domicile_building = east_asian_estate_market_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_health_01 }
			remove_domicile_building = east_asian_estate_health_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_health_02 }
			remove_domicile_building = east_asian_estate_health_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_health_03 }
			remove_domicile_building = east_asian_estate_health_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_health_04 }
			remove_domicile_building = east_asian_estate_health_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_health_05 }
			remove_domicile_building = east_asian_estate_health_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_health_06 }
			remove_domicile_building = east_asian_estate_health_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_01 }
			remove_domicile_building = east_asian_estate_silk_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_02 }
			remove_domicile_building = east_asian_estate_silk_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_03 }
			remove_domicile_building = east_asian_estate_silk_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_04 }
			remove_domicile_building = east_asian_estate_silk_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_05 }
			remove_domicile_building = east_asian_estate_silk_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_06 }
			remove_domicile_building = east_asian_estate_silk_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_shrine_01 }
			remove_domicile_building = east_asian_estate_ancestral_shrine_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_shrine_02 }
			remove_domicile_building = east_asian_estate_ancestral_shrine_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_shrine_03 }
			remove_domicile_building = east_asian_estate_ancestral_shrine_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_shrine_04 }
			remove_domicile_building = east_asian_estate_ancestral_shrine_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_shrine_05 }
			remove_domicile_building = east_asian_estate_ancestral_shrine_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_shrine_06 }
			remove_domicile_building = east_asian_estate_ancestral_shrine_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_01 }
			remove_domicile_building = east_asian_estate_temple_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_02 }
			remove_domicile_building = east_asian_estate_temple_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_03 }
			remove_domicile_building = east_asian_estate_temple_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_04 }
			remove_domicile_building = east_asian_estate_temple_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_05 }
			remove_domicile_building = east_asian_estate_temple_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_06 }
			remove_domicile_building = east_asian_estate_temple_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_barracks_01 }
			remove_domicile_building = east_asian_estate_barracks_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_barracks_02 }
			remove_domicile_building = east_asian_estate_barracks_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_barracks_03 }
			remove_domicile_building = east_asian_estate_barracks_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_barracks_04 }
			remove_domicile_building = east_asian_estate_barracks_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_barracks_05 }
			remove_domicile_building = east_asian_estate_barracks_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_barracks_06 }
			remove_domicile_building = east_asian_estate_barracks_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watchtower_01 }
			remove_domicile_building = east_asian_estate_watchtower_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watchtower_02 }
			remove_domicile_building = east_asian_estate_watchtower_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watchtower_03 }
			remove_domicile_building = east_asian_estate_watchtower_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watchtower_04 }
			remove_domicile_building = east_asian_estate_watchtower_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watchtower_05 }
			remove_domicile_building = east_asian_estate_watchtower_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watchtower_06 }
			remove_domicile_building = east_asian_estate_watchtower_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_01 }
			remove_domicile_building = east_asian_estate_garden_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_02 }
			remove_domicile_building = east_asian_estate_garden_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_03 }
			remove_domicile_building = east_asian_estate_garden_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_leisure_04 }
			remove_domicile_building = east_asian_estate_garden_leisure_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_leisure_05 }
			remove_domicile_building = east_asian_estate_garden_leisure_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_leisure_06 }
			remove_domicile_building = east_asian_estate_garden_leisure_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_fruit_04 }
			remove_domicile_building = east_asian_estate_garden_fruit_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_fruit_05 }
			remove_domicile_building = east_asian_estate_garden_fruit_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_garden_fruit_06 }
			remove_domicile_building = east_asian_estate_garden_fruit_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_01 }
			remove_domicile_building = east_asian_estate_stable_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_02 }
			remove_domicile_building = east_asian_estate_stable_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_03 }
			remove_domicile_building = east_asian_estate_stable_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_grand_04 }
			remove_domicile_building = east_asian_estate_stable_grand_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_grand_05 }
			remove_domicile_building = east_asian_estate_stable_grand_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_grand_06 }
			remove_domicile_building = east_asian_estate_stable_grand_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_kennel_04 }
			remove_domicile_building = east_asian_estate_stable_kennel_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_kennel_05 }
			remove_domicile_building = east_asian_estate_stable_kennel_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_stable_kennel_06 }
			remove_domicile_building = east_asian_estate_stable_kennel_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_01 }
			remove_domicile_building = east_asian_estate_workshop_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_02 }
			remove_domicile_building = east_asian_estate_workshop_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_carpenter_03 }
			remove_domicile_building = east_asian_estate_workshop_carpenter_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_carpenter_04 }
			remove_domicile_building = east_asian_estate_workshop_carpenter_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_carpenter_05 }
			remove_domicile_building = east_asian_estate_workshop_carpenter_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_carpenter_06 }
			remove_domicile_building = east_asian_estate_workshop_carpenter_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_mason_03 }
			remove_domicile_building = east_asian_estate_workshop_mason_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_mason_04 }
			remove_domicile_building = east_asian_estate_workshop_mason_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_mason_05 }
			remove_domicile_building = east_asian_estate_workshop_mason_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_mason_06 }
			remove_domicile_building = east_asian_estate_workshop_mason_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_textile_03 }
			remove_domicile_building = east_asian_estate_workshop_textile_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_textile_04 }
			remove_domicile_building = east_asian_estate_workshop_textile_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_textile_05 }
			remove_domicile_building = east_asian_estate_workshop_textile_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_workshop_textile_06 }
			remove_domicile_building = east_asian_estate_workshop_textile_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_01 }
			remove_domicile_building = east_asian_estate_storage_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_02 }
			remove_domicile_building = east_asian_estate_storage_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_warehouse_03 }
			remove_domicile_building = east_asian_estate_storage_warehouse_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_warehouse_04 }
			remove_domicile_building = east_asian_estate_storage_warehouse_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_warehouse_05 }
			remove_domicile_building = east_asian_estate_storage_warehouse_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_warehouse_06 }
			remove_domicile_building = east_asian_estate_storage_warehouse_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_granary_03 }
			remove_domicile_building = east_asian_estate_storage_granary_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_granary_04 }
			remove_domicile_building = east_asian_estate_storage_granary_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_granary_05 }
			remove_domicile_building = east_asian_estate_storage_granary_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_storage_granary_06 }
			remove_domicile_building = east_asian_estate_storage_granary_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grazing_land_01 }
			remove_domicile_building = east_asian_estate_grazing_land_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grazing_land_02 }
			remove_domicile_building = east_asian_estate_grazing_land_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grazing_land_03 }
			remove_domicile_building = east_asian_estate_grazing_land_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grazing_land_04 }
			remove_domicile_building = east_asian_estate_grazing_land_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grazing_land_05 }
			remove_domicile_building = east_asian_estate_grazing_land_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grazing_land_06 }
			remove_domicile_building = east_asian_estate_grazing_land_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_horse_pasture_04 }
			remove_domicile_building = east_asian_estate_horse_pasture_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_horse_pasture_05 }
			remove_domicile_building = east_asian_estate_horse_pasture_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_horse_pasture_06 }
			remove_domicile_building = east_asian_estate_horse_pasture_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_camel_pasture_04 }
			remove_domicile_building = east_asian_estate_camel_pasture_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_camel_pasture_05 }
			remove_domicile_building = east_asian_estate_camel_pasture_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_camel_pasture_06 }
			remove_domicile_building = east_asian_estate_camel_pasture_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_elephant_pasture_04 }
			remove_domicile_building = east_asian_estate_elephant_pasture_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_elephant_pasture_05 }
			remove_domicile_building = east_asian_estate_elephant_pasture_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_elephant_pasture_06 }
			remove_domicile_building = east_asian_estate_elephant_pasture_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_01 }
			remove_domicile_building = east_asian_estate_gate_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_02 }
			remove_domicile_building = east_asian_estate_gate_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_03 }
			remove_domicile_building = east_asian_estate_gate_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_04 }
			remove_domicile_building = east_asian_estate_gate_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_05 }
			remove_domicile_building = east_asian_estate_gate_05
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_06 }
			remove_domicile_building = east_asian_estate_gate_06
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_waterways_office_01 }
			remove_domicile_building = east_asian_estate_waterways_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_waterways_office_02 }
			remove_domicile_building = east_asian_estate_waterways_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_waterways_office_03 }
			remove_domicile_building = east_asian_estate_waterways_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_waterways_office_04 }
			remove_domicile_building = east_asian_estate_waterways_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_field_surveyors_office_01 }
			remove_domicile_building = east_asian_estate_field_surveyors_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_field_surveyors_office_02 }
			remove_domicile_building = east_asian_estate_field_surveyors_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_field_surveyors_office_03 }
			remove_domicile_building = east_asian_estate_field_surveyors_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_field_surveyors_office_04 }
			remove_domicile_building = east_asian_estate_field_surveyors_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_buffer_stock_granary_01 }
			remove_domicile_building = east_asian_estate_buffer_stock_granary_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_buffer_stock_granary_02 }
			remove_domicile_building = east_asian_estate_buffer_stock_granary_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_buffer_stock_granary_03 }
			remove_domicile_building = east_asian_estate_buffer_stock_granary_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_buffer_stock_granary_04 }
			remove_domicile_building = east_asian_estate_buffer_stock_granary_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_fish_duck_ponds_01 }
			remove_domicile_building = east_asian_estate_rice_fish_duck_ponds_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_fish_duck_ponds_02 }
			remove_domicile_building = east_asian_estate_rice_fish_duck_ponds_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_fish_duck_ponds_03 }
			remove_domicile_building = east_asian_estate_rice_fish_duck_ponds_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rice_fish_duck_ponds_04 }
			remove_domicile_building = east_asian_estate_rice_fish_duck_ponds_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_militia_muster_green_01 }
			remove_domicile_building = east_asian_estate_militia_muster_green_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_militia_muster_green_02 }
			remove_domicile_building = east_asian_estate_militia_muster_green_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_militia_muster_green_03 }
			remove_domicile_building = east_asian_estate_militia_muster_green_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_militia_muster_green_04 }
			remove_domicile_building = east_asian_estate_militia_muster_green_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ration_wine_stores_01 }
			remove_domicile_building = east_asian_estate_ration_wine_stores_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ration_wine_stores_02 }
			remove_domicile_building = east_asian_estate_ration_wine_stores_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ration_wine_stores_03 }
			remove_domicile_building = east_asian_estate_ration_wine_stores_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ration_wine_stores_04 }
			remove_domicile_building = east_asian_estate_ration_wine_stores_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_vintner_halls_01 }
			remove_domicile_building = east_asian_estate_vintner_halls_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_vintner_halls_02 }
			remove_domicile_building = east_asian_estate_vintner_halls_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_vintner_halls_03 }
			remove_domicile_building = east_asian_estate_vintner_halls_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_vintner_halls_04 }
			remove_domicile_building = east_asian_estate_vintner_halls_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_wine_press_01 }
			remove_domicile_building = east_asian_estate_wine_press_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_wine_press_02 }
			remove_domicile_building = east_asian_estate_wine_press_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_wine_press_03 }
			remove_domicile_building = east_asian_estate_wine_press_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_wine_press_04 }
			remove_domicile_building = east_asian_estate_wine_press_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cellar_cave_01 }
			remove_domicile_building = east_asian_estate_cellar_cave_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cellar_cave_02 }
			remove_domicile_building = east_asian_estate_cellar_cave_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cellar_cave_03 }
			remove_domicile_building = east_asian_estate_cellar_cave_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_cellar_cave_04 }
			remove_domicile_building = east_asian_estate_cellar_cave_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_jar_kiln_01 }
			remove_domicile_building = east_asian_estate_jar_kiln_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_jar_kiln_02 }
			remove_domicile_building = east_asian_estate_jar_kiln_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_jar_kiln_03 }
			remove_domicile_building = east_asian_estate_jar_kiln_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_jar_kiln_04 }
			remove_domicile_building = east_asian_estate_jar_kiln_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_weighing_house_01 }
			remove_domicile_building = east_asian_estate_weighing_house_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_weighing_house_02 }
			remove_domicile_building = east_asian_estate_weighing_house_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_weighing_house_03 }
			remove_domicile_building = east_asian_estate_weighing_house_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_weighing_house_04 }
			remove_domicile_building = east_asian_estate_weighing_house_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_meeting_houses_01 }
			remove_domicile_building = east_asian_estate_meeting_houses_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_meeting_houses_02 }
			remove_domicile_building = east_asian_estate_meeting_houses_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_meeting_houses_03 }
			remove_domicile_building = east_asian_estate_meeting_houses_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_meeting_houses_04 }
			remove_domicile_building = east_asian_estate_meeting_houses_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_night_watch_01 }
			remove_domicile_building = east_asian_estate_night_watch_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_night_watch_02 }
			remove_domicile_building = east_asian_estate_night_watch_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_night_watch_03 }
			remove_domicile_building = east_asian_estate_night_watch_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_night_watch_04 }
			remove_domicile_building = east_asian_estate_night_watch_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fire_brigade_01 }
			remove_domicile_building = east_asian_estate_fire_brigade_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fire_brigade_02 }
			remove_domicile_building = east_asian_estate_fire_brigade_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fire_brigade_03 }
			remove_domicile_building = east_asian_estate_fire_brigade_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fire_brigade_04 }
			remove_domicile_building = east_asian_estate_fire_brigade_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_courier_posthouse_01 }
			remove_domicile_building = east_asian_estate_courier_posthouse_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_courier_posthouse_02 }
			remove_domicile_building = east_asian_estate_courier_posthouse_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_courier_posthouse_03 }
			remove_domicile_building = east_asian_estate_courier_posthouse_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_courier_posthouse_04 }
			remove_domicile_building = east_asian_estate_courier_posthouse_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_dye_works_01 }
			remove_domicile_building = east_asian_estate_dye_works_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_dye_works_02 }
			remove_domicile_building = east_asian_estate_dye_works_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_dye_works_03 }
			remove_domicile_building = east_asian_estate_dye_works_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_dye_works_04 }
			remove_domicile_building = east_asian_estate_dye_works_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_sericulture_school_01 }
			remove_domicile_building = east_asian_estate_sericulture_school_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_sericulture_school_02 }
			remove_domicile_building = east_asian_estate_sericulture_school_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_sericulture_school_03 }
			remove_domicile_building = east_asian_estate_sericulture_school_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_sericulture_school_04 }
			remove_domicile_building = east_asian_estate_sericulture_school_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_inspection_office_01 }
			remove_domicile_building = east_asian_estate_inspection_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_inspection_office_02 }
			remove_domicile_building = east_asian_estate_inspection_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_inspection_office_03 }
			remove_domicile_building = east_asian_estate_inspection_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_inspection_office_04 }
			remove_domicile_building = east_asian_estate_inspection_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_mulberry_nursery_01 }
			remove_domicile_building = east_asian_estate_mulberry_nursery_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_mulberry_nursery_02 }
			remove_domicile_building = east_asian_estate_mulberry_nursery_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_mulberry_nursery_03 }
			remove_domicile_building = east_asian_estate_mulberry_nursery_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_mulberry_nursery_04 }
			remove_domicile_building = east_asian_estate_mulberry_nursery_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_storage_01 }
			remove_domicile_building = east_asian_estate_silk_storage_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_storage_02 }
			remove_domicile_building = east_asian_estate_silk_storage_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_storage_03 }
			remove_domicile_building = east_asian_estate_silk_storage_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_silk_storage_04 }
			remove_domicile_building = east_asian_estate_silk_storage_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_roasting_house_01 }
			remove_domicile_building = east_asian_estate_roasting_house_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_roasting_house_02 }
			remove_domicile_building = east_asian_estate_roasting_house_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_roasting_house_03 }
			remove_domicile_building = east_asian_estate_roasting_house_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_roasting_house_04 }
			remove_domicile_building = east_asian_estate_roasting_house_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grading_hall_01 }
			remove_domicile_building = east_asian_estate_grading_hall_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grading_hall_02 }
			remove_domicile_building = east_asian_estate_grading_hall_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grading_hall_03 }
			remove_domicile_building = east_asian_estate_grading_hall_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_grading_hall_04 }
			remove_domicile_building = east_asian_estate_grading_hall_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_horse_road_office_01 }
			remove_domicile_building = east_asian_estate_tea_horse_road_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_horse_road_office_02 }
			remove_domicile_building = east_asian_estate_tea_horse_road_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_horse_road_office_03 }
			remove_domicile_building = east_asian_estate_tea_horse_road_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_horse_road_office_04 }
			remove_domicile_building = east_asian_estate_tea_horse_road_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_tax_office_01 }
			remove_domicile_building = east_asian_estate_tea_tax_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_tax_office_02 }
			remove_domicile_building = east_asian_estate_tea_tax_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_tax_office_03 }
			remove_domicile_building = east_asian_estate_tea_tax_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_tea_tax_office_04 }
			remove_domicile_building = east_asian_estate_tea_tax_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_teahouse_01 }
			remove_domicile_building = east_asian_estate_teahouse_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_teahouse_02 }
			remove_domicile_building = east_asian_estate_teahouse_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_teahouse_03 }
			remove_domicile_building = east_asian_estate_teahouse_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_teahouse_04 }
			remove_domicile_building = east_asian_estate_teahouse_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pharmacy_01 }
			remove_domicile_building = east_asian_estate_pharmacy_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pharmacy_02 }
			remove_domicile_building = east_asian_estate_pharmacy_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pharmacy_03 }
			remove_domicile_building = east_asian_estate_pharmacy_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pharmacy_04 }
			remove_domicile_building = east_asian_estate_pharmacy_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_hot_baths_01 }
			remove_domicile_building = east_asian_estate_hot_baths_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_hot_baths_02 }
			remove_domicile_building = east_asian_estate_hot_baths_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_hot_baths_03 }
			remove_domicile_building = east_asian_estate_hot_baths_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_hot_baths_04 }
			remove_domicile_building = east_asian_estate_hot_baths_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_medical_library_01 }
			remove_domicile_building = east_asian_estate_medical_library_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_medical_library_02 }
			remove_domicile_building = east_asian_estate_medical_library_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_medical_library_03 }
			remove_domicile_building = east_asian_estate_medical_library_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_medical_library_04 }
			remove_domicile_building = east_asian_estate_medical_library_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_field_surgeon_cart_01 }
			remove_domicile_building = east_asian_estate_field_surgeon_cart_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_field_surgeon_cart_02 }
			remove_domicile_building = east_asian_estate_field_surgeon_cart_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_field_surgeon_cart_03 }
			remove_domicile_building = east_asian_estate_field_surgeon_cart_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_field_surgeon_cart_04 }
			remove_domicile_building = east_asian_estate_field_surgeon_cart_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_herb_drying_terrace_01 }
			remove_domicile_building = east_asian_estate_herb_drying_terrace_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_herb_drying_terrace_02 }
			remove_domicile_building = east_asian_estate_herb_drying_terrace_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_herb_drying_terrace_03 }
			remove_domicile_building = east_asian_estate_herb_drying_terrace_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_herb_drying_terrace_04 }
			remove_domicile_building = east_asian_estate_herb_drying_terrace_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bell_drum_tower_01 }
			remove_domicile_building = east_asian_estate_bell_drum_tower_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bell_drum_tower_02 }
			remove_domicile_building = east_asian_estate_bell_drum_tower_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bell_drum_tower_03 }
			remove_domicile_building = east_asian_estate_bell_drum_tower_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bell_drum_tower_04 }
			remove_domicile_building = east_asian_estate_bell_drum_tower_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_land_office_01 }
			remove_domicile_building = east_asian_estate_temple_land_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_land_office_02 }
			remove_domicile_building = east_asian_estate_temple_land_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_land_office_03 }
			remove_domicile_building = east_asian_estate_temple_land_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_temple_land_office_04 }
			remove_domicile_building = east_asian_estate_temple_land_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lecture_pavilion_01 }
			remove_domicile_building = east_asian_estate_lecture_pavilion_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lecture_pavilion_02 }
			remove_domicile_building = east_asian_estate_lecture_pavilion_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lecture_pavilion_03 }
			remove_domicile_building = east_asian_estate_lecture_pavilion_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lecture_pavilion_04 }
			remove_domicile_building = east_asian_estate_lecture_pavilion_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_guesthouse_01 }
			remove_domicile_building = east_asian_estate_guesthouse_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_guesthouse_02 }
			remove_domicile_building = east_asian_estate_guesthouse_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_guesthouse_03 }
			remove_domicile_building = east_asian_estate_guesthouse_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_guesthouse_04 }
			remove_domicile_building = east_asian_estate_guesthouse_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_chanting_hall_01 }
			remove_domicile_building = east_asian_estate_chanting_hall_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_chanting_hall_02 }
			remove_domicile_building = east_asian_estate_chanting_hall_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_chanting_hall_03 }
			remove_domicile_building = east_asian_estate_chanting_hall_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_chanting_hall_04 }
			remove_domicile_building = east_asian_estate_chanting_hall_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_genealogy_hall_01 }
			remove_domicile_building = east_asian_estate_genealogy_hall_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_genealogy_hall_02 }
			remove_domicile_building = east_asian_estate_genealogy_hall_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_genealogy_hall_03 }
			remove_domicile_building = east_asian_estate_genealogy_hall_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_genealogy_hall_04 }
			remove_domicile_building = east_asian_estate_genealogy_hall_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_history_school_01 }
			remove_domicile_building = east_asian_estate_history_school_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_history_school_02 }
			remove_domicile_building = east_asian_estate_history_school_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_history_school_03 }
			remove_domicile_building = east_asian_estate_history_school_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_history_school_04 }
			remove_domicile_building = east_asian_estate_history_school_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_orchard_01 }
			remove_domicile_building = east_asian_estate_ancestral_orchard_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_orchard_02 }
			remove_domicile_building = east_asian_estate_ancestral_orchard_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_orchard_03 }
			remove_domicile_building = east_asian_estate_ancestral_orchard_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ancestral_orchard_04 }
			remove_domicile_building = east_asian_estate_ancestral_orchard_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rites_office_01 }
			remove_domicile_building = east_asian_estate_rites_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rites_office_02 }
			remove_domicile_building = east_asian_estate_rites_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rites_office_03 }
			remove_domicile_building = east_asian_estate_rites_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rites_office_04 }
			remove_domicile_building = east_asian_estate_rites_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_memorial_archway_01 }
			remove_domicile_building = east_asian_estate_memorial_archway_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_memorial_archway_02 }
			remove_domicile_building = east_asian_estate_memorial_archway_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_memorial_archway_03 }
			remove_domicile_building = east_asian_estate_memorial_archway_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_memorial_archway_04 }
			remove_domicile_building = east_asian_estate_memorial_archway_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_armorer_01 }
			remove_domicile_building = east_asian_estate_armorer_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_armorer_02 }
			remove_domicile_building = east_asian_estate_armorer_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_armorer_03 }
			remove_domicile_building = east_asian_estate_armorer_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_armorer_04 }
			remove_domicile_building = east_asian_estate_armorer_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_veterans_hall_01 }
			remove_domicile_building = east_asian_estate_veterans_hall_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_veterans_hall_02 }
			remove_domicile_building = east_asian_estate_veterans_hall_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_veterans_hall_03 }
			remove_domicile_building = east_asian_estate_veterans_hall_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_veterans_hall_04 }
			remove_domicile_building = east_asian_estate_veterans_hall_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_quartermaster_01 }
			remove_domicile_building = east_asian_estate_quartermaster_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_quartermaster_02 }
			remove_domicile_building = east_asian_estate_quartermaster_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_quartermaster_03 }
			remove_domicile_building = east_asian_estate_quartermaster_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_quartermaster_04 }
			remove_domicile_building = east_asian_estate_quartermaster_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_sergeants_school_01 }
			remove_domicile_building = east_asian_estate_sergeants_school_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_sergeants_school_02 }
			remove_domicile_building = east_asian_estate_sergeants_school_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_sergeants_school_03 }
			remove_domicile_building = east_asian_estate_sergeants_school_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_sergeants_school_04 }
			remove_domicile_building = east_asian_estate_sergeants_school_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drill_yard_01 }
			remove_domicile_building = east_asian_estate_drill_yard_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drill_yard_02 }
			remove_domicile_building = east_asian_estate_drill_yard_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drill_yard_03 }
			remove_domicile_building = east_asian_estate_drill_yard_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drill_yard_04 }
			remove_domicile_building = east_asian_estate_drill_yard_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pass_office_01 }
			remove_domicile_building = east_asian_estate_pass_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pass_office_02 }
			remove_domicile_building = east_asian_estate_pass_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pass_office_03 }
			remove_domicile_building = east_asian_estate_pass_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pass_office_04 }
			remove_domicile_building = east_asian_estate_pass_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gunpowder_storage_01 }
			remove_domicile_building = east_asian_estate_gunpowder_storage_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gunpowder_storage_02 }
			remove_domicile_building = east_asian_estate_gunpowder_storage_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gunpowder_storage_03 }
			remove_domicile_building = east_asian_estate_gunpowder_storage_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gunpowder_storage_04 }
			remove_domicile_building = east_asian_estate_gunpowder_storage_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_signal_fires_01 }
			remove_domicile_building = east_asian_estate_signal_fires_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_signal_fires_02 }
			remove_domicile_building = east_asian_estate_signal_fires_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_signal_fires_03 }
			remove_domicile_building = east_asian_estate_signal_fires_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_signal_fires_04 }
			remove_domicile_building = east_asian_estate_signal_fires_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_regular_patrols_01 }
			remove_domicile_building = east_asian_estate_regular_patrols_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_regular_patrols_02 }
			remove_domicile_building = east_asian_estate_regular_patrols_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_regular_patrols_03 }
			remove_domicile_building = east_asian_estate_regular_patrols_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_regular_patrols_04 }
			remove_domicile_building = east_asian_estate_regular_patrols_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_crossbow_storage_01 }
			remove_domicile_building = east_asian_estate_crossbow_storage_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_crossbow_storage_02 }
			remove_domicile_building = east_asian_estate_crossbow_storage_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_crossbow_storage_03 }
			remove_domicile_building = east_asian_estate_crossbow_storage_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_crossbow_storage_04 }
			remove_domicile_building = east_asian_estate_crossbow_storage_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_aviary_01 }
			remove_domicile_building = east_asian_estate_aviary_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_aviary_02 }
			remove_domicile_building = east_asian_estate_aviary_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_aviary_03 }
			remove_domicile_building = east_asian_estate_aviary_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_aviary_04 }
			remove_domicile_building = east_asian_estate_aviary_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_four_gentlemen_01 }
			remove_domicile_building = east_asian_estate_four_gentlemen_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_four_gentlemen_02 }
			remove_domicile_building = east_asian_estate_four_gentlemen_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_four_gentlemen_03 }
			remove_domicile_building = east_asian_estate_four_gentlemen_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_four_gentlemen_04 }
			remove_domicile_building = east_asian_estate_four_gentlemen_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_scholars_rocks_01 }
			remove_domicile_building = east_asian_estate_scholars_rocks_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_scholars_rocks_02 }
			remove_domicile_building = east_asian_estate_scholars_rocks_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_scholars_rocks_03 }
			remove_domicile_building = east_asian_estate_scholars_rocks_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_scholars_rocks_04 }
			remove_domicile_building = east_asian_estate_scholars_rocks_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lotus_pond_01 }
			remove_domicile_building = east_asian_estate_lotus_pond_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lotus_pond_02 }
			remove_domicile_building = east_asian_estate_lotus_pond_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lotus_pond_03 }
			remove_domicile_building = east_asian_estate_lotus_pond_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lotus_pond_04 }
			remove_domicile_building = east_asian_estate_lotus_pond_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fruit_trees_01 }
			remove_domicile_building = east_asian_estate_fruit_trees_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fruit_trees_02 }
			remove_domicile_building = east_asian_estate_fruit_trees_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fruit_trees_03 }
			remove_domicile_building = east_asian_estate_fruit_trees_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fruit_trees_04 }
			remove_domicile_building = east_asian_estate_fruit_trees_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_foaling_pens_01 }
			remove_domicile_building = east_asian_estate_foaling_pens_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_foaling_pens_02 }
			remove_domicile_building = east_asian_estate_foaling_pens_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_foaling_pens_03 }
			remove_domicile_building = east_asian_estate_foaling_pens_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_foaling_pens_04 }
			remove_domicile_building = east_asian_estate_foaling_pens_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_riding_arena_01 }
			remove_domicile_building = east_asian_estate_riding_arena_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_riding_arena_02 }
			remove_domicile_building = east_asian_estate_riding_arena_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_riding_arena_03 }
			remove_domicile_building = east_asian_estate_riding_arena_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_riding_arena_04 }
			remove_domicile_building = east_asian_estate_riding_arena_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_farriers_office_01 }
			remove_domicile_building = east_asian_estate_farriers_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_farriers_office_02 }
			remove_domicile_building = east_asian_estate_farriers_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_farriers_office_03 }
			remove_domicile_building = east_asian_estate_farriers_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_farriers_office_04 }
			remove_domicile_building = east_asian_estate_farriers_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bloodline_records_office_01 }
			remove_domicile_building = east_asian_estate_bloodline_records_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bloodline_records_office_02 }
			remove_domicile_building = east_asian_estate_bloodline_records_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bloodline_records_office_03 }
			remove_domicile_building = east_asian_estate_bloodline_records_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_bloodline_records_office_04 }
			remove_domicile_building = east_asian_estate_bloodline_records_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fodder_reserves_01 }
			remove_domicile_building = east_asian_estate_fodder_reserves_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fodder_reserves_02 }
			remove_domicile_building = east_asian_estate_fodder_reserves_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fodder_reserves_03 }
			remove_domicile_building = east_asian_estate_fodder_reserves_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_fodder_reserves_04 }
			remove_domicile_building = east_asian_estate_fodder_reserves_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_paper_mill_01 }
			remove_domicile_building = east_asian_estate_paper_mill_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_paper_mill_02 }
			remove_domicile_building = east_asian_estate_paper_mill_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_paper_mill_03 }
			remove_domicile_building = east_asian_estate_paper_mill_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_paper_mill_04 }
			remove_domicile_building = east_asian_estate_paper_mill_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ink_brush_makers_01 }
			remove_domicile_building = east_asian_estate_ink_brush_makers_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ink_brush_makers_02 }
			remove_domicile_building = east_asian_estate_ink_brush_makers_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ink_brush_makers_03 }
			remove_domicile_building = east_asian_estate_ink_brush_makers_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ink_brush_makers_04 }
			remove_domicile_building = east_asian_estate_ink_brush_makers_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ceramics_kiln_01 }
			remove_domicile_building = east_asian_estate_ceramics_kiln_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ceramics_kiln_02 }
			remove_domicile_building = east_asian_estate_ceramics_kiln_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ceramics_kiln_03 }
			remove_domicile_building = east_asian_estate_ceramics_kiln_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ceramics_kiln_04 }
			remove_domicile_building = east_asian_estate_ceramics_kiln_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lacquer_studio_01 }
			remove_domicile_building = east_asian_estate_lacquer_studio_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lacquer_studio_02 }
			remove_domicile_building = east_asian_estate_lacquer_studio_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lacquer_studio_03 }
			remove_domicile_building = east_asian_estate_lacquer_studio_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_lacquer_studio_04 }
			remove_domicile_building = east_asian_estate_lacquer_studio_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_leatherworks_01 }
			remove_domicile_building = east_asian_estate_leatherworks_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_leatherworks_02 }
			remove_domicile_building = east_asian_estate_leatherworks_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_leatherworks_03 }
			remove_domicile_building = east_asian_estate_leatherworks_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_leatherworks_04 }
			remove_domicile_building = east_asian_estate_leatherworks_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ever_normal_granaries_01 }
			remove_domicile_building = east_asian_estate_ever_normal_granaries_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ever_normal_granaries_02 }
			remove_domicile_building = east_asian_estate_ever_normal_granaries_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ever_normal_granaries_03 }
			remove_domicile_building = east_asian_estate_ever_normal_granaries_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ever_normal_granaries_04 }
			remove_domicile_building = east_asian_estate_ever_normal_granaries_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_millhouse_01 }
			remove_domicile_building = east_asian_estate_millhouse_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_millhouse_02 }
			remove_domicile_building = east_asian_estate_millhouse_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_millhouse_03 }
			remove_domicile_building = east_asian_estate_millhouse_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_millhouse_04 }
			remove_domicile_building = east_asian_estate_millhouse_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ledger_office_01 }
			remove_domicile_building = east_asian_estate_ledger_office_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ledger_office_02 }
			remove_domicile_building = east_asian_estate_ledger_office_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ledger_office_03 }
			remove_domicile_building = east_asian_estate_ledger_office_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_ledger_office_04 }
			remove_domicile_building = east_asian_estate_ledger_office_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drying_loft_01 }
			remove_domicile_building = east_asian_estate_drying_loft_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drying_loft_02 }
			remove_domicile_building = east_asian_estate_drying_loft_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drying_loft_03 }
			remove_domicile_building = east_asian_estate_drying_loft_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_drying_loft_04 }
			remove_domicile_building = east_asian_estate_drying_loft_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_weights_measures_bench_01 }
			remove_domicile_building = east_asian_estate_weights_measures_bench_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_weights_measures_bench_02 }
			remove_domicile_building = east_asian_estate_weights_measures_bench_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_weights_measures_bench_03 }
			remove_domicile_building = east_asian_estate_weights_measures_bench_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_weights_measures_bench_04 }
			remove_domicile_building = east_asian_estate_weights_measures_bench_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_seasonal_shelters_01 }
			remove_domicile_building = east_asian_estate_seasonal_shelters_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_seasonal_shelters_02 }
			remove_domicile_building = east_asian_estate_seasonal_shelters_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_seasonal_shelters_03 }
			remove_domicile_building = east_asian_estate_seasonal_shelters_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_seasonal_shelters_04 }
			remove_domicile_building = east_asian_estate_seasonal_shelters_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_veterinary_shed_01 }
			remove_domicile_building = east_asian_estate_veterinary_shed_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_veterinary_shed_02 }
			remove_domicile_building = east_asian_estate_veterinary_shed_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_veterinary_shed_03 }
			remove_domicile_building = east_asian_estate_veterinary_shed_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_veterinary_shed_04 }
			remove_domicile_building = east_asian_estate_veterinary_shed_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watering_ditches_01 }
			remove_domicile_building = east_asian_estate_watering_ditches_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watering_ditches_02 }
			remove_domicile_building = east_asian_estate_watering_ditches_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watering_ditches_03 }
			remove_domicile_building = east_asian_estate_watering_ditches_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_watering_ditches_04 }
			remove_domicile_building = east_asian_estate_watering_ditches_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_salt_lick_terraces_01 }
			remove_domicile_building = east_asian_estate_salt_lick_terraces_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_salt_lick_terraces_02 }
			remove_domicile_building = east_asian_estate_salt_lick_terraces_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_salt_lick_terraces_03 }
			remove_domicile_building = east_asian_estate_salt_lick_terraces_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_salt_lick_terraces_04 }
			remove_domicile_building = east_asian_estate_salt_lick_terraces_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rotation_paddocks_01 }
			remove_domicile_building = east_asian_estate_rotation_paddocks_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rotation_paddocks_02 }
			remove_domicile_building = east_asian_estate_rotation_paddocks_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rotation_paddocks_03 }
			remove_domicile_building = east_asian_estate_rotation_paddocks_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_rotation_paddocks_04 }
			remove_domicile_building = east_asian_estate_rotation_paddocks_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_disciples_hall_01 }
			remove_domicile_building = east_asian_estate_disciples_hall_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_disciples_hall_02 }
			remove_domicile_building = east_asian_estate_disciples_hall_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_disciples_hall_03 }
			remove_domicile_building = east_asian_estate_disciples_hall_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_disciples_hall_04 }
			remove_domicile_building = east_asian_estate_disciples_hall_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_donation_box_01 }
			remove_domicile_building = east_asian_estate_donation_box_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_donation_box_02 }
			remove_domicile_building = east_asian_estate_donation_box_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_donation_box_03 }
			remove_domicile_building = east_asian_estate_donation_box_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_donation_box_04 }
			remove_domicile_building = east_asian_estate_donation_box_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_plaques_01 }
			remove_domicile_building = east_asian_estate_gate_plaques_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_plaques_02 }
			remove_domicile_building = east_asian_estate_gate_plaques_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_plaques_03 }
			remove_domicile_building = east_asian_estate_gate_plaques_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_gate_plaques_04 }
			remove_domicile_building = east_asian_estate_gate_plaques_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pavilion_01 }
			remove_domicile_building = east_asian_estate_pavilion_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pavilion_02 }
			remove_domicile_building = east_asian_estate_pavilion_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pavilion_03 }
			remove_domicile_building = east_asian_estate_pavilion_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_pavilion_04 }
			remove_domicile_building = east_asian_estate_pavilion_04
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_performance_stage_01 }
			remove_domicile_building = east_asian_estate_performance_stage_01
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_performance_stage_02 }
			remove_domicile_building = east_asian_estate_performance_stage_02
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_performance_stage_03 }
			remove_domicile_building = east_asian_estate_performance_stage_03
		}
		if = {
			limit = { has_domicile_building = east_asian_estate_performance_stage_04 }
			remove_domicile_building = east_asian_estate_performance_stage_04
		}
		if = {
			limit = { has_domicile_building = estate_main_01 }
			remove_domicile_building = estate_main_01
		}
		if = {
			limit = { has_domicile_building = estate_main_02 }
			remove_domicile_building = estate_main_02
		}
		if = {
			limit = { has_domicile_building = estate_main_03 }
			remove_domicile_building = estate_main_03
		}
		if = {
			limit = { has_domicile_building = estate_main_04 }
			remove_domicile_building = estate_main_04
		}
		if = {
			limit = { has_domicile_building = estate_main_05 }
			remove_domicile_building = estate_main_05
		}
		if = {
			limit = { has_domicile_building = living_quarters_01 }
			remove_domicile_building = living_quarters_01
		}
		if = {
			limit = { has_domicile_building = living_quarters_02 }
			remove_domicile_building = living_quarters_02
		}
		if = {
			limit = { has_domicile_building = living_quarters_03 }
			remove_domicile_building = living_quarters_03
		}
		if = {
			limit = { has_domicile_building = living_quarters_04 }
			remove_domicile_building = living_quarters_04
		}
		if = {
			limit = { has_domicile_building = trophy_room_01 }
			remove_domicile_building = trophy_room_01
		}
		if = {
			limit = { has_domicile_building = trophy_room_02 }
			remove_domicile_building = trophy_room_02
		}
		if = {
			limit = { has_domicile_building = trophy_room_03 }
			remove_domicile_building = trophy_room_03
		}
		if = {
			limit = { has_domicile_building = trophy_room_04 }
			remove_domicile_building = trophy_room_04
		}
		if = {
			limit = { has_domicile_building = office_01 }
			remove_domicile_building = office_01
		}
		if = {
			limit = { has_domicile_building = office_02 }
			remove_domicile_building = office_02
		}
		if = {
			limit = { has_domicile_building = office_03 }
			remove_domicile_building = office_03
		}
		if = {
			limit = { has_domicile_building = office_04 }
			remove_domicile_building = office_04
		}
		if = {
			limit = { has_domicile_building = servants_quarters_01 }
			remove_domicile_building = servants_quarters_01
		}
		if = {
			limit = { has_domicile_building = servants_quarters_02 }
			remove_domicile_building = servants_quarters_02
		}
		if = {
			limit = { has_domicile_building = servants_quarters_03 }
			remove_domicile_building = servants_quarters_03
		}
		if = {
			limit = { has_domicile_building = servants_quarters_04 }
			remove_domicile_building = servants_quarters_04
		}
		if = {
			limit = { has_domicile_building = library_01 }
			remove_domicile_building = library_01
		}
		if = {
			limit = { has_domicile_building = library_02 }
			remove_domicile_building = library_02
		}
		if = {
			limit = { has_domicile_building = library_observatory_03 }
			remove_domicile_building = library_observatory_03
		}
		if = {
			limit = { has_domicile_building = library_observatory_04 }
			remove_domicile_building = library_observatory_04
		}
		if = {
			limit = { has_domicile_building = library_education_03 }
			remove_domicile_building = library_education_03
		}
		if = {
			limit = { has_domicile_building = library_education_04 }
			remove_domicile_building = library_education_04
		}
		if = {
			limit = { has_domicile_building = bath_01 }
			remove_domicile_building = bath_01
		}
		if = {
			limit = { has_domicile_building = bath_02 }
			remove_domicile_building = bath_02
		}
		if = {
			limit = { has_domicile_building = bath_03 }
			remove_domicile_building = bath_03
		}
		if = {
			limit = { has_domicile_building = bath_04 }
			remove_domicile_building = bath_04
		}
		if = {
			limit = { has_domicile_building = guest_room_01 }
			remove_domicile_building = guest_room_01
		}
		if = {
			limit = { has_domicile_building = guest_room_02 }
			remove_domicile_building = guest_room_02
		}
		if = {
			limit = { has_domicile_building = guest_room_03 }
			remove_domicile_building = guest_room_03
		}
		if = {
			limit = { has_domicile_building = guest_room_04 }
			remove_domicile_building = guest_room_04
		}
		if = {
			limit = { has_domicile_building = guest_room_05 }
			remove_domicile_building = guest_room_05
		}
		if = {
			limit = { has_domicile_building = guest_room_06 }
			remove_domicile_building = guest_room_06
		}
		if = {
			limit = { has_domicile_building = wine_cellar_01 }
			remove_domicile_building = wine_cellar_01
		}
		if = {
			limit = { has_domicile_building = wine_cellar_02 }
			remove_domicile_building = wine_cellar_02
		}
		if = {
			limit = { has_domicile_building = wine_cellar_03 }
			remove_domicile_building = wine_cellar_03
		}
		if = {
			limit = { has_domicile_building = courtyard_01 }
			remove_domicile_building = courtyard_01
		}
		if = {
			limit = { has_domicile_building = courtyard_02 }
			remove_domicile_building = courtyard_02
		}
		if = {
			limit = { has_domicile_building = courtyard_03 }
			remove_domicile_building = courtyard_03
		}
		if = {
			limit = { has_domicile_building = courtyard_04 }
			remove_domicile_building = courtyard_04
		}
		if = {
			limit = { has_domicile_building = prison_01 }
			remove_domicile_building = prison_01
		}
		if = {
			limit = { has_domicile_building = prison_02 }
			remove_domicile_building = prison_02
		}
		if = {
			limit = { has_domicile_building = prison_03 }
			remove_domicile_building = prison_03
		}
		if = {
			limit = { has_domicile_building = prison_04 }
			remove_domicile_building = prison_04
		}
		if = {
			limit = { has_domicile_building = reception_hall_01 }
			remove_domicile_building = reception_hall_01
		}
		if = {
			limit = { has_domicile_building = reception_hall_02 }
			remove_domicile_building = reception_hall_02
		}
		if = {
			limit = { has_domicile_building = reception_hall_03 }
			remove_domicile_building = reception_hall_03
		}
		if = {
			limit = { has_domicile_building = reception_hall_04 }
			remove_domicile_building = reception_hall_04
		}
		if = {
			limit = { has_domicile_building = reception_hall_05 }
			remove_domicile_building = reception_hall_05
		}
		if = {
			limit = { has_domicile_building = cabinet_of_curiosities_01 }
			remove_domicile_building = cabinet_of_curiosities_01
		}
		if = {
			limit = { has_domicile_building = cabinet_of_curiosities_02 }
			remove_domicile_building = cabinet_of_curiosities_02
		}
		if = {
			limit = { has_domicile_building = cabinet_of_curiosities_03 }
			remove_domicile_building = cabinet_of_curiosities_03
		}
		if = {
			limit = { has_domicile_building = grand_solar_01 }
			remove_domicile_building = grand_solar_01
		}
		if = {
			limit = { has_domicile_building = grand_solar_02 }
			remove_domicile_building = grand_solar_02
		}
		if = {
			limit = { has_domicile_building = grand_solar_03 }
			remove_domicile_building = grand_solar_03
		}
		if = {
			limit = { has_domicile_building = grand_solar_04 }
			remove_domicile_building = grand_solar_04
		}
		if = {
			limit = { has_domicile_building = temple_small_01 }
			remove_domicile_building = temple_small_01
		}
		if = {
			limit = { has_domicile_building = temple_small_02 }
			remove_domicile_building = temple_small_02
		}
		if = {
			limit = { has_domicile_building = temple_small_03 }
			remove_domicile_building = temple_small_03
		}
		if = {
			limit = { has_domicile_building = temple_crypt_04 }
			remove_domicile_building = temple_crypt_04
		}
		if = {
			limit = { has_domicile_building = temple_crypt_05 }
			remove_domicile_building = temple_crypt_05
		}
		if = {
			limit = { has_domicile_building = temple_crypt_06 }
			remove_domicile_building = temple_crypt_06
		}
		if = {
			limit = { has_domicile_building = temple_large_04 }
			remove_domicile_building = temple_large_04
		}
		if = {
			limit = { has_domicile_building = temple_large_05 }
			remove_domicile_building = temple_large_05
		}
		if = {
			limit = { has_domicile_building = temple_large_06 }
			remove_domicile_building = temple_large_06
		}
		if = {
			limit = { has_domicile_building = temple_monastery_04 }
			remove_domicile_building = temple_monastery_04
		}
		if = {
			limit = { has_domicile_building = temple_monastery_05 }
			remove_domicile_building = temple_monastery_05
		}
		if = {
			limit = { has_domicile_building = temple_monastery_06 }
			remove_domicile_building = temple_monastery_06
		}
		if = {
			limit = { has_domicile_building = barracks_01 }
			remove_domicile_building = barracks_01
		}
		if = {
			limit = { has_domicile_building = barracks_02 }
			remove_domicile_building = barracks_02
		}
		if = {
			limit = { has_domicile_building = barracks_03 }
			remove_domicile_building = barracks_03
		}
		if = {
			limit = { has_domicile_building = barracks_04 }
			remove_domicile_building = barracks_04
		}
		if = {
			limit = { has_domicile_building = barracks_05 }
			remove_domicile_building = barracks_05
		}
		if = {
			limit = { has_domicile_building = barracks_06 }
			remove_domicile_building = barracks_06
		}
		if = {
			limit = { has_domicile_building = watchtower_01 }
			remove_domicile_building = watchtower_01
		}
		if = {
			limit = { has_domicile_building = watchtower_02 }
			remove_domicile_building = watchtower_02
		}
		if = {
			limit = { has_domicile_building = watchtower_03 }
			remove_domicile_building = watchtower_03
		}
		if = {
			limit = { has_domicile_building = watchtower_04 }
			remove_domicile_building = watchtower_04
		}
		if = {
			limit = { has_domicile_building = watchtower_05 }
			remove_domicile_building = watchtower_05
		}
		if = {
			limit = { has_domicile_building = watchtower_06 }
			remove_domicile_building = watchtower_06
		}
		if = {
			limit = { has_domicile_building = guardhouse_01 }
			remove_domicile_building = guardhouse_01
		}
		if = {
			limit = { has_domicile_building = guardhouse_02 }
			remove_domicile_building = guardhouse_02
		}
		if = {
			limit = { has_domicile_building = guardhouse_03 }
			remove_domicile_building = guardhouse_03
		}
		if = {
			limit = { has_domicile_building = guardhouse_04 }
			remove_domicile_building = guardhouse_04
		}
		if = {
			limit = { has_domicile_building = garden_01 }
			remove_domicile_building = garden_01
		}
		if = {
			limit = { has_domicile_building = garden_02 }
			remove_domicile_building = garden_02
		}
		if = {
			limit = { has_domicile_building = garden_03 }
			remove_domicile_building = garden_03
		}
		if = {
			limit = { has_domicile_building = garden_leisure_04 }
			remove_domicile_building = garden_leisure_04
		}
		if = {
			limit = { has_domicile_building = garden_leisure_05 }
			remove_domicile_building = garden_leisure_05
		}
		if = {
			limit = { has_domicile_building = garden_leisure_06 }
			remove_domicile_building = garden_leisure_06
		}
		if = {
			limit = { has_domicile_building = garden_fruit_04 }
			remove_domicile_building = garden_fruit_04
		}
		if = {
			limit = { has_domicile_building = garden_fruit_05 }
			remove_domicile_building = garden_fruit_05
		}
		if = {
			limit = { has_domicile_building = garden_fruit_06 }
			remove_domicile_building = garden_fruit_06
		}
		if = {
			limit = { has_domicile_building = stable_01 }
			remove_domicile_building = stable_01
		}
		if = {
			limit = { has_domicile_building = stable_02 }
			remove_domicile_building = stable_02
		}
		if = {
			limit = { has_domicile_building = stable_03 }
			remove_domicile_building = stable_03
		}
		if = {
			limit = { has_domicile_building = stable_grand_04 }
			remove_domicile_building = stable_grand_04
		}
		if = {
			limit = { has_domicile_building = stable_grand_05 }
			remove_domicile_building = stable_grand_05
		}
		if = {
			limit = { has_domicile_building = stable_grand_06 }
			remove_domicile_building = stable_grand_06
		}
		if = {
			limit = { has_domicile_building = stable_kennel_04 }
			remove_domicile_building = stable_kennel_04
		}
		if = {
			limit = { has_domicile_building = stable_kennel_05 }
			remove_domicile_building = stable_kennel_05
		}
		if = {
			limit = { has_domicile_building = stable_kennel_06 }
			remove_domicile_building = stable_kennel_06
		}
		if = {
			limit = { has_domicile_building = stable_chariot_04 }
			remove_domicile_building = stable_chariot_04
		}
		if = {
			limit = { has_domicile_building = stable_chariot_05 }
			remove_domicile_building = stable_chariot_05
		}
		if = {
			limit = { has_domicile_building = stable_chariot_06 }
			remove_domicile_building = stable_chariot_06
		}
		if = {
			limit = { has_domicile_building = workshop_01 }
			remove_domicile_building = workshop_01
		}
		if = {
			limit = { has_domicile_building = workshop_02 }
			remove_domicile_building = workshop_02
		}
		if = {
			limit = { has_domicile_building = workshop_carpenter_03 }
			remove_domicile_building = workshop_carpenter_03
		}
		if = {
			limit = { has_domicile_building = workshop_carpenter_04 }
			remove_domicile_building = workshop_carpenter_04
		}
		if = {
			limit = { has_domicile_building = workshop_carpenter_05 }
			remove_domicile_building = workshop_carpenter_05
		}
		if = {
			limit = { has_domicile_building = workshop_carpenter_06 }
			remove_domicile_building = workshop_carpenter_06
		}
		if = {
			limit = { has_domicile_building = workshop_mason_03 }
			remove_domicile_building = workshop_mason_03
		}
		if = {
			limit = { has_domicile_building = workshop_mason_04 }
			remove_domicile_building = workshop_mason_04
		}
		if = {
			limit = { has_domicile_building = workshop_mason_05 }
			remove_domicile_building = workshop_mason_05
		}
		if = {
			limit = { has_domicile_building = workshop_mason_06 }
			remove_domicile_building = workshop_mason_06
		}
		if = {
			limit = { has_domicile_building = workshop_textile_03 }
			remove_domicile_building = workshop_textile_03
		}
		if = {
			limit = { has_domicile_building = workshop_textile_04 }
			remove_domicile_building = workshop_textile_04
		}
		if = {
			limit = { has_domicile_building = workshop_textile_05 }
			remove_domicile_building = workshop_textile_05
		}
		if = {
			limit = { has_domicile_building = workshop_textile_06 }
			remove_domicile_building = workshop_textile_06
		}
		if = {
			limit = { has_domicile_building = storage_01 }
			remove_domicile_building = storage_01
		}
		if = {
			limit = { has_domicile_building = storage_02 }
			remove_domicile_building = storage_02
		}
		if = {
			limit = { has_domicile_building = storage_warehouse_03 }
			remove_domicile_building = storage_warehouse_03
		}
		if = {
			limit = { has_domicile_building = storage_warehouse_04 }
			remove_domicile_building = storage_warehouse_04
		}
		if = {
			limit = { has_domicile_building = storage_granary_03 }
			remove_domicile_building = storage_granary_03
		}
		if = {
			limit = { has_domicile_building = storage_granary_04 }
			remove_domicile_building = storage_granary_04
		}
		if = {
			limit = { has_domicile_building = market_01 }
			remove_domicile_building = market_01
		}
		if = {
			limit = { has_domicile_building = market_02 }
			remove_domicile_building = market_02
		}
		if = {
			limit = { has_domicile_building = market_03 }
			remove_domicile_building = market_03
		}
		if = {
			limit = { has_domicile_building = market_04 }
			remove_domicile_building = market_04
		}
		if = {
			limit = { has_domicile_building = market_05 }
			remove_domicile_building = market_05
		}
		if = {
			limit = { has_domicile_building = market_06 }
			remove_domicile_building = market_06
		}
		if = {
			limit = { has_domicile_building = grazing_land_01 }
			remove_domicile_building = grazing_land_01
		}
		if = {
			limit = { has_domicile_building = grazing_land_02 }
			remove_domicile_building = grazing_land_02
		}
		if = {
			limit = { has_domicile_building = grazing_land_03 }
			remove_domicile_building = grazing_land_03
		}
		if = {
			limit = { has_domicile_building = grazing_land_04 }
			remove_domicile_building = grazing_land_04
		}
		if = {
			limit = { has_domicile_building = grazing_land_05 }
			remove_domicile_building = grazing_land_05
		}
		if = {
			limit = { has_domicile_building = grazing_land_06 }
			remove_domicile_building = grazing_land_06
		}
		if = {
			limit = { has_domicile_building = horse_pasture_04 }
			remove_domicile_building = horse_pasture_04
		}
		if = {
			limit = { has_domicile_building = horse_pasture_05 }
			remove_domicile_building = horse_pasture_05
		}
		if = {
			limit = { has_domicile_building = horse_pasture_06 }
			remove_domicile_building = horse_pasture_06
		}
		if = {
			limit = { has_domicile_building = camel_pasture_04 }
			remove_domicile_building = camel_pasture_04
		}
		if = {
			limit = { has_domicile_building = camel_pasture_05 }
			remove_domicile_building = camel_pasture_05
		}
		if = {
			limit = { has_domicile_building = camel_pasture_06 }
			remove_domicile_building = camel_pasture_06
		}
		if = {
			limit = { has_domicile_building = elephant_pasture_04 }
			remove_domicile_building = elephant_pasture_04
		}
		if = {
			limit = { has_domicile_building = elephant_pasture_05 }
			remove_domicile_building = elephant_pasture_05
		}
		if = {
			limit = { has_domicile_building = elephant_pasture_06 }
			remove_domicile_building = elephant_pasture_06
		}
		if = {
			limit = { has_domicile_building = grain_field_01 }
			remove_domicile_building = grain_field_01
		}
		if = {
			limit = { has_domicile_building = grain_field_02 }
			remove_domicile_building = grain_field_02
		}
		if = {
			limit = { has_domicile_building = grain_field_03 }
			remove_domicile_building = grain_field_03
		}
		if = {
			limit = { has_domicile_building = grain_field_04 }
			remove_domicile_building = grain_field_04
		}
		if = {
			limit = { has_domicile_building = grain_field_05 }
			remove_domicile_building = grain_field_05
		}
		if = {
			limit = { has_domicile_building = grain_field_06 }
			remove_domicile_building = grain_field_06
		}
		if = {
			limit = { has_domicile_building = rice_field_01 }
			remove_domicile_building = rice_field_01
		}
		if = {
			limit = { has_domicile_building = rice_field_02 }
			remove_domicile_building = rice_field_02
		}
		if = {
			limit = { has_domicile_building = rice_field_03 }
			remove_domicile_building = rice_field_03
		}
		if = {
			limit = { has_domicile_building = rice_field_04 }
			remove_domicile_building = rice_field_04
		}
		if = {
			limit = { has_domicile_building = rice_field_05 }
			remove_domicile_building = rice_field_05
		}
		if = {
			limit = { has_domicile_building = rice_field_06 }
			remove_domicile_building = rice_field_06
		}
		if = {
			limit = { has_domicile_building = vineyard_01 }
			remove_domicile_building = vineyard_01
		}
		if = {
			limit = { has_domicile_building = vineyard_02 }
			remove_domicile_building = vineyard_02
		}
		if = {
			limit = { has_domicile_building = vineyard_03 }
			remove_domicile_building = vineyard_03
		}
		if = {
			limit = { has_domicile_building = vineyard_04 }
			remove_domicile_building = vineyard_04
		}
		if = {
			limit = { has_domicile_building = vineyard_05 }
			remove_domicile_building = vineyard_05
		}
		if = {
			limit = { has_domicile_building = vineyard_06 }
			remove_domicile_building = vineyard_06
		}
		if = {
			limit = { has_domicile_building = tea_01 }
			remove_domicile_building = tea_01
		}
		if = {
			limit = { has_domicile_building = tea_02 }
			remove_domicile_building = tea_02
		}
		if = {
			limit = { has_domicile_building = tea_03 }
			remove_domicile_building = tea_03
		}
		if = {
			limit = { has_domicile_building = tea_04 }
			remove_domicile_building = tea_04
		}
		if = {
			limit = { has_domicile_building = tea_05 }
			remove_domicile_building = tea_05
		}
		if = {
			limit = { has_domicile_building = tea_06 }
			remove_domicile_building = tea_06
		}
		if = {
			limit = { has_domicile_building = olive_01 }
			remove_domicile_building = olive_01
		}
		if = {
			limit = { has_domicile_building = olive_02 }
			remove_domicile_building = olive_02
		}
		if = {
			limit = { has_domicile_building = olive_03 }
			remove_domicile_building = olive_03
		}
		if = {
			limit = { has_domicile_building = olive_04 }
			remove_domicile_building = olive_04
		}
		if = {
			limit = { has_domicile_building = olive_05 }
			remove_domicile_building = olive_05
		}
		if = {
			limit = { has_domicile_building = olive_06 }
			remove_domicile_building = olive_06
		}
		if = {
			limit = { has_domicile_building = silk_01 }
			remove_domicile_building = silk_01
		}
		if = {
			limit = { has_domicile_building = silk_02 }
			remove_domicile_building = silk_02
		}
		if = {
			limit = { has_domicile_building = silk_03 }
			remove_domicile_building = silk_03
		}
		if = {
			limit = { has_domicile_building = silk_04 }
			remove_domicile_building = silk_04
		}
		if = {
			limit = { has_domicile_building = silk_05 }
			remove_domicile_building = silk_05
		}
		if = {
			limit = { has_domicile_building = silk_06 }
			remove_domicile_building = silk_06
		}
		if = {
			limit = { has_domicile_building = japanese_manor_main_01 }
			remove_domicile_building = japanese_manor_main_01
		}
		if = {
			limit = { has_domicile_building = japanese_manor_main_02 }
			remove_domicile_building = japanese_manor_main_02
		}
		if = {
			limit = { has_domicile_building = japanese_manor_main_03 }
			remove_domicile_building = japanese_manor_main_03
		}
		if = {
			limit = { has_domicile_building = japanese_manor_main_04 }
			remove_domicile_building = japanese_manor_main_04
		}
		if = {
			limit = { has_domicile_building = japanese_manor_main_05 }
			remove_domicile_building = japanese_manor_main_05
		}
		if = {
			limit = { has_domicile_building = japanese_manor_main_06 }
			remove_domicile_building = japanese_manor_main_06
		}
		if = {
			limit = { has_domicile_building = japanese_main_tax_collectors_01 }
			remove_domicile_building = japanese_main_tax_collectors_01
		}
		if = {
			limit = { has_domicile_building = japanese_main_tax_collectors_02 }
			remove_domicile_building = japanese_main_tax_collectors_02
		}
		if = {
			limit = { has_domicile_building = japanese_main_tax_collectors_03 }
			remove_domicile_building = japanese_main_tax_collectors_03
		}
		if = {
			limit = { has_domicile_building = japanese_main_tax_collectors_04 }
			remove_domicile_building = japanese_main_tax_collectors_04
		}
		if = {
			limit = { has_domicile_building = japanese_main_tax_collectors_05 }
			remove_domicile_building = japanese_main_tax_collectors_05
		}
		if = {
			limit = { has_domicile_building = japanese_main_tax_collectors_06 }
			remove_domicile_building = japanese_main_tax_collectors_06
		}
		if = {
			limit = { has_domicile_building = japanese_main_carpenter_01 }
			remove_domicile_building = japanese_main_carpenter_01
		}
		if = {
			limit = { has_domicile_building = japanese_main_carpenter_02 }
			remove_domicile_building = japanese_main_carpenter_02
		}
		if = {
			limit = { has_domicile_building = japanese_main_carpenter_03 }
			remove_domicile_building = japanese_main_carpenter_03
		}
		if = {
			limit = { has_domicile_building = japanese_main_carpenter_04 }
			remove_domicile_building = japanese_main_carpenter_04
		}
		if = {
			limit = { has_domicile_building = japanese_main_carpenter_05 }
			remove_domicile_building = japanese_main_carpenter_05
		}
		if = {
			limit = { has_domicile_building = japanese_main_carpenter_06 }
			remove_domicile_building = japanese_main_carpenter_06
		}
		if = {
			limit = { has_domicile_building = japanese_manor_poetry_library_01 }
			remove_domicile_building = japanese_manor_poetry_library_01
		}
		if = {
			limit = { has_domicile_building = japanese_manor_poetry_library_02 }
			remove_domicile_building = japanese_manor_poetry_library_02
		}
		if = {
			limit = { has_domicile_building = japanese_manor_poetry_library_03 }
			remove_domicile_building = japanese_manor_poetry_library_03
		}
		if = {
			limit = { has_domicile_building = japanese_manor_poetry_library_04 }
			remove_domicile_building = japanese_manor_poetry_library_04
		}
		if = {
			limit = { has_domicile_building = japanese_manor_poetry_library_05 }
			remove_domicile_building = japanese_manor_poetry_library_05
		}
		if = {
			limit = { has_domicile_building = japanese_manor_poetry_library_06 }
			remove_domicile_building = japanese_manor_poetry_library_06
		}
		if = {
			limit = { has_domicile_building = sarugaku_stage_01 }
			remove_domicile_building = sarugaku_stage_01
		}
		if = {
			limit = { has_domicile_building = sarugaku_stage_02 }
			remove_domicile_building = sarugaku_stage_02
		}
		if = {
			limit = { has_domicile_building = sarugaku_stage_03 }
			remove_domicile_building = sarugaku_stage_03
		}
		if = {
			limit = { has_domicile_building = sarugaku_stage_04 }
			remove_domicile_building = sarugaku_stage_04
		}
		if = {
			limit = { has_domicile_building = sarugaku_stage_05 }
			remove_domicile_building = sarugaku_stage_05
		}
		if = {
			limit = { has_domicile_building = sarugaku_stage_06 }
			remove_domicile_building = sarugaku_stage_06
		}
		if = {
			limit = { has_domicile_building = japanese_manor_trophy_room_01 }
			remove_domicile_building = japanese_manor_trophy_room_01
		}
		if = {
			limit = { has_domicile_building = japanese_manor_trophy_room_02 }
			remove_domicile_building = japanese_manor_trophy_room_02
		}
		if = {
			limit = { has_domicile_building = japanese_manor_trophy_room_03 }
			remove_domicile_building = japanese_manor_trophy_room_03
		}
		if = {
			limit = { has_domicile_building = japanese_manor_trophy_room_04 }
			remove_domicile_building = japanese_manor_trophy_room_04
		}
		if = {
			limit = { has_domicile_building = japanese_manor_trophy_room_05 }
			remove_domicile_building = japanese_manor_trophy_room_05
		}
		if = {
			limit = { has_domicile_building = japanese_manor_trophy_room_06 }
			remove_domicile_building = japanese_manor_trophy_room_06
		}
		if = {
			limit = { has_domicile_building = japanese_manor_office_01 }
			remove_domicile_building = japanese_manor_office_01
		}
		if = {
			limit = { has_domicile_building = japanese_manor_office_02 }
			remove_domicile_building = japanese_manor_office_02
		}
		if = {
			limit = { has_domicile_building = japanese_manor_office_03 }
			remove_domicile_building = japanese_manor_office_03
		}
		if = {
			limit = { has_domicile_building = japanese_manor_office_04 }
			remove_domicile_building = japanese_manor_office_04
		}
		if = {
			limit = { has_domicile_building = japanese_manor_office_05 }
			remove_domicile_building = japanese_manor_office_05
		}
		if = {
			limit = { has_domicile_building = japanese_manor_office_06 }
			remove_domicile_building = japanese_manor_office_06
		}
		if = {
			limit = { has_domicile_building = japanese_manor_servants_quarters_01 }
			remove_domicile_building = japanese_manor_servants_quarters_01
		}
		if = {
			limit = { has_domicile_building = japanese_manor_servants_quarters_02 }
			remove_domicile_building = japanese_manor_servants_quarters_02
		}
		if = {
			limit = { has_domicile_building = japanese_manor_servants_quarters_03 }
			remove_domicile_building = japanese_manor_servants_quarters_03
		}
		if = {
			limit = { has_domicile_building = japanese_manor_servants_quarters_04 }
			remove_domicile_building = japanese_manor_servants_quarters_04
		}
		if = {
			limit = { has_domicile_building = japanese_manor_servants_quarters_05 }
			remove_domicile_building = japanese_manor_servants_quarters_05
		}
		if = {
			limit = { has_domicile_building = japanese_manor_servants_quarters_06 }
			remove_domicile_building = japanese_manor_servants_quarters_06
		}
		if = {
			limit = { has_domicile_building = japanese_manor_library_confucian_01 }
			remove_domicile_building = japanese_manor_library_confucian_01
		}
		if = {
			limit = { has_domicile_building = japanese_manor_library_confucian_02 }
			remove_domicile_building = japanese_manor_library_confucian_02
		}
		if = {
			limit = { has_domicile_building = japanese_manor_library_confucian_03 }
			remove_domicile_building = japanese_manor_library_confucian_03
		}
		if = {
			limit = { has_domicile_building = japanese_manor_library_confucian_04 }
			remove_domicile_building = japanese_manor_library_confucian_04
		}
		if = {
			limit = { has_domicile_building = japanese_manor_library_confucian_05 }
			remove_domicile_building = japanese_manor_library_confucian_05
		}
		if = {
			limit = { has_domicile_building = japanese_manor_library_confucian_06 }
			remove_domicile_building = japanese_manor_library_confucian_06
		}
		if = {
			limit = { has_domicile_building = japanese_manor_retainer_accomodations_01 }
			remove_domicile_building = japanese_manor_retainer_accomodations_01
		}
		if = {
			limit = { has_domicile_building = japanese_manor_retainer_accomodations_02 }
			remove_domicile_building = japanese_manor_retainer_accomodations_02
		}
		if = {
			limit = { has_domicile_building = japanese_manor_retainer_accomodations_03 }
			remove_domicile_building = japanese_manor_retainer_accomodations_03
		}
		if = {
			limit = { has_domicile_building = japanese_manor_retainer_accomodations_04 }
			remove_domicile_building = japanese_manor_retainer_accomodations_04
		}
		if = {
			limit = { has_domicile_building = japanese_manor_retainer_accomodations_05 }
			remove_domicile_building = japanese_manor_retainer_accomodations_05
		}
		if = {
			limit = { has_domicile_building = japanese_fields_01 }
			remove_domicile_building = japanese_fields_01
		}
		if = {
			limit = { has_domicile_building = japanese_fields_02 }
			remove_domicile_building = japanese_fields_02
		}
		if = {
			limit = { has_domicile_building = japanese_fields_03 }
			remove_domicile_building = japanese_fields_03
		}
		if = {
			limit = { has_domicile_building = japanese_fields_04 }
			remove_domicile_building = japanese_fields_04
		}
		if = {
			limit = { has_domicile_building = japanese_fields_05 }
			remove_domicile_building = japanese_fields_05
		}
		if = {
			limit = { has_domicile_building = japanese_fields_06 }
			remove_domicile_building = japanese_fields_06
		}
		if = {
			limit = { has_domicile_building = japanese_granary_01 }
			remove_domicile_building = japanese_granary_01
		}
		if = {
			limit = { has_domicile_building = japanese_granary_02 }
			remove_domicile_building = japanese_granary_02
		}
		if = {
			limit = { has_domicile_building = japanese_granary_03 }
			remove_domicile_building = japanese_granary_03
		}
		if = {
			limit = { has_domicile_building = japanese_granary_04 }
			remove_domicile_building = japanese_granary_04
		}
		if = {
			limit = { has_domicile_building = japanese_granary_05 }
			remove_domicile_building = japanese_granary_05
		}
		if = {
			limit = { has_domicile_building = japanese_granary_06 }
			remove_domicile_building = japanese_granary_06
		}
		if = {
			limit = { has_domicile_building = japanese_rice_broker_01 }
			remove_domicile_building = japanese_rice_broker_01
		}
		if = {
			limit = { has_domicile_building = japanese_rice_broker_02 }
			remove_domicile_building = japanese_rice_broker_02
		}
		if = {
			limit = { has_domicile_building = japanese_rice_broker_03 }
			remove_domicile_building = japanese_rice_broker_03
		}
		if = {
			limit = { has_domicile_building = japanese_rice_broker_04 }
			remove_domicile_building = japanese_rice_broker_04
		}
		if = {
			limit = { has_domicile_building = japanese_rice_broker_05 }
			remove_domicile_building = japanese_rice_broker_05
		}
		if = {
			limit = { has_domicile_building = japanese_rice_broker_06 }
			remove_domicile_building = japanese_rice_broker_06
		}
		if = {
			limit = { has_domicile_building = japanese_tenant_farmers_01 }
			remove_domicile_building = japanese_tenant_farmers_01
		}
		if = {
			limit = { has_domicile_building = japanese_tenant_farmers_02 }
			remove_domicile_building = japanese_tenant_farmers_02
		}
		if = {
			limit = { has_domicile_building = japanese_tenant_farmers_03 }
			remove_domicile_building = japanese_tenant_farmers_03
		}
		if = {
			limit = { has_domicile_building = japanese_tenant_farmers_04 }
			remove_domicile_building = japanese_tenant_farmers_04
		}
		if = {
			limit = { has_domicile_building = japanese_tenant_farmers_05 }
			remove_domicile_building = japanese_tenant_farmers_05
		}
		if = {
			limit = { has_domicile_building = japanese_tenant_farmers_06 }
			remove_domicile_building = japanese_tenant_farmers_06
		}
		if = {
			limit = { has_domicile_building = japanese_shrine_01 }
			remove_domicile_building = japanese_shrine_01
		}
		if = {
			limit = { has_domicile_building = japanese_shrine_02 }
			remove_domicile_building = japanese_shrine_02
		}
		if = {
			limit = { has_domicile_building = japanese_shrine_03 }
			remove_domicile_building = japanese_shrine_03
		}
		if = {
			limit = { has_domicile_building = japanese_shrine_04 }
			remove_domicile_building = japanese_shrine_04
		}
		if = {
			limit = { has_domicile_building = japanese_shrine_05 }
			remove_domicile_building = japanese_shrine_05
		}
		if = {
			limit = { has_domicile_building = japanese_shrine_06 }
			remove_domicile_building = japanese_shrine_06
		}
		if = {
			limit = { has_domicile_building = japanese_cemetery_01 }
			remove_domicile_building = japanese_cemetery_01
		}
		if = {
			limit = { has_domicile_building = japanese_cemetery_02 }
			remove_domicile_building = japanese_cemetery_02
		}
		if = {
			limit = { has_domicile_building = japanese_cemetery_03 }
			remove_domicile_building = japanese_cemetery_03
		}
		if = {
			limit = { has_domicile_building = japanese_cemetery_04 }
			remove_domicile_building = japanese_cemetery_04
		}
		if = {
			limit = { has_domicile_building = japanese_cemetery_05 }
			remove_domicile_building = japanese_cemetery_05
		}
		if = {
			limit = { has_domicile_building = japanese_cemetery_06 }
			remove_domicile_building = japanese_cemetery_06
		}
		if = {
			limit = { has_domicile_building = japanese_shokubo_01 }
			remove_domicile_building = japanese_shokubo_01
		}
		if = {
			limit = { has_domicile_building = japanese_shokubo_02 }
			remove_domicile_building = japanese_shokubo_02
		}
		if = {
			limit = { has_domicile_building = japanese_shokubo_03 }
			remove_domicile_building = japanese_shokubo_03
		}
		if = {
			limit = { has_domicile_building = japanese_shokubo_04 }
			remove_domicile_building = japanese_shokubo_04
		}
		if = {
			limit = { has_domicile_building = japanese_shokubo_05 }
			remove_domicile_building = japanese_shokubo_05
		}
		if = {
			limit = { has_domicile_building = japanese_shokubo_06 }
			remove_domicile_building = japanese_shokubo_06
		}
		if = {
			limit = { has_domicile_building = japanese_monastery_01 }
			remove_domicile_building = japanese_monastery_01
		}
		if = {
			limit = { has_domicile_building = japanese_monastery_02 }
			remove_domicile_building = japanese_monastery_02
		}
		if = {
			limit = { has_domicile_building = japanese_monastery_03 }
			remove_domicile_building = japanese_monastery_03
		}
		if = {
			limit = { has_domicile_building = japanese_monastery_04 }
			remove_domicile_building = japanese_monastery_04
		}
		if = {
			limit = { has_domicile_building = japanese_monastery_05 }
			remove_domicile_building = japanese_monastery_05
		}
		if = {
			limit = { has_domicile_building = japanese_monastery_06 }
			remove_domicile_building = japanese_monastery_06
		}
		if = {
			limit = { has_domicile_building = japanese_brewery_01 }
			remove_domicile_building = japanese_brewery_01
		}
		if = {
			limit = { has_domicile_building = japanese_brewery_02 }
			remove_domicile_building = japanese_brewery_02
		}
		if = {
			limit = { has_domicile_building = japanese_brewery_03 }
			remove_domicile_building = japanese_brewery_03
		}
		if = {
			limit = { has_domicile_building = japanese_brewery_04 }
			remove_domicile_building = japanese_brewery_04
		}
		if = {
			limit = { has_domicile_building = japanese_brewery_05 }
			remove_domicile_building = japanese_brewery_05
		}
		if = {
			limit = { has_domicile_building = japanese_brewery_06 }
			remove_domicile_building = japanese_brewery_06
		}
		if = {
			limit = { has_domicile_building = japanese_koshu_cellars_01 }
			remove_domicile_building = japanese_koshu_cellars_01
		}
		if = {
			limit = { has_domicile_building = japanese_koshu_cellars_02 }
			remove_domicile_building = japanese_koshu_cellars_02
		}
		if = {
			limit = { has_domicile_building = japanese_koshu_cellars_03 }
			remove_domicile_building = japanese_koshu_cellars_03
		}
		if = {
			limit = { has_domicile_building = japanese_koshu_cellars_04 }
			remove_domicile_building = japanese_koshu_cellars_04
		}
		if = {
			limit = { has_domicile_building = japanese_koshu_cellars_05 }
			remove_domicile_building = japanese_koshu_cellars_05
		}
		if = {
			limit = { has_domicile_building = japanese_koshu_cellars_06 }
			remove_domicile_building = japanese_koshu_cellars_06
		}
		if = {
			limit = { has_domicile_building = japanese_gambling_den_01 }
			remove_domicile_building = japanese_gambling_den_01
		}
		if = {
			limit = { has_domicile_building = japanese_gambling_den_02 }
			remove_domicile_building = japanese_gambling_den_02
		}
		if = {
			limit = { has_domicile_building = japanese_gambling_den_03 }
			remove_domicile_building = japanese_gambling_den_03
		}
		if = {
			limit = { has_domicile_building = japanese_gambling_den_04 }
			remove_domicile_building = japanese_gambling_den_04
		}
		if = {
			limit = { has_domicile_building = japanese_gambling_den_05 }
			remove_domicile_building = japanese_gambling_den_05
		}
		if = {
			limit = { has_domicile_building = japanese_gambling_den_06 }
			remove_domicile_building = japanese_gambling_den_06
		}
		if = {
			limit = { has_domicile_building = japanese_sumo_hall_01 }
			remove_domicile_building = japanese_sumo_hall_01
		}
		if = {
			limit = { has_domicile_building = japanese_sumo_hall_02 }
			remove_domicile_building = japanese_sumo_hall_02
		}
		if = {
			limit = { has_domicile_building = japanese_sumo_hall_03 }
			remove_domicile_building = japanese_sumo_hall_03
		}
		if = {
			limit = { has_domicile_building = japanese_sumo_hall_04 }
			remove_domicile_building = japanese_sumo_hall_04
		}
		if = {
			limit = { has_domicile_building = japanese_sumo_hall_05 }
			remove_domicile_building = japanese_sumo_hall_05
		}
		if = {
			limit = { has_domicile_building = japanese_sumo_hall_06 }
			remove_domicile_building = japanese_sumo_hall_06
		}
		if = {
			limit = { has_domicile_building = japanese_archive_01 }
			remove_domicile_building = japanese_archive_01
		}
		if = {
			limit = { has_domicile_building = japanese_archive_02 }
			remove_domicile_building = japanese_archive_02
		}
		if = {
			limit = { has_domicile_building = japanese_archive_03 }
			remove_domicile_building = japanese_archive_03
		}
		if = {
			limit = { has_domicile_building = japanese_archive_04 }
			remove_domicile_building = japanese_archive_04
		}
		if = {
			limit = { has_domicile_building = japanese_archive_05 }
			remove_domicile_building = japanese_archive_05
		}
		if = {
			limit = { has_domicile_building = japanese_archive_06 }
			remove_domicile_building = japanese_archive_06
		}
		if = {
			limit = { has_domicile_building = japanese_schoolhouse_01 }
			remove_domicile_building = japanese_schoolhouse_01
		}
		if = {
			limit = { has_domicile_building = japanese_schoolhouse_02 }
			remove_domicile_building = japanese_schoolhouse_02
		}
		if = {
			limit = { has_domicile_building = japanese_schoolhouse_03 }
			remove_domicile_building = japanese_schoolhouse_03
		}
		if = {
			limit = { has_domicile_building = japanese_schoolhouse_04 }
			remove_domicile_building = japanese_schoolhouse_04
		}
		if = {
			limit = { has_domicile_building = japanese_schoolhouse_05 }
			remove_domicile_building = japanese_schoolhouse_05
		}
		if = {
			limit = { has_domicile_building = japanese_schoolhouse_06 }
			remove_domicile_building = japanese_schoolhouse_06
		}
		if = {
			limit = { has_domicile_building = japanese_law_library_01 }
			remove_domicile_building = japanese_law_library_01
		}
		if = {
			limit = { has_domicile_building = japanese_law_library_02 }
			remove_domicile_building = japanese_law_library_02
		}
		if = {
			limit = { has_domicile_building = japanese_law_library_03 }
			remove_domicile_building = japanese_law_library_03
		}
		if = {
			limit = { has_domicile_building = japanese_law_library_04 }
			remove_domicile_building = japanese_law_library_04
		}
		if = {
			limit = { has_domicile_building = japanese_law_library_05 }
			remove_domicile_building = japanese_law_library_05
		}
		if = {
			limit = { has_domicile_building = japanese_law_library_06 }
			remove_domicile_building = japanese_law_library_06
		}
		if = {
			limit = { has_domicile_building = japanese_messenger_service_01 }
			remove_domicile_building = japanese_messenger_service_01
		}
		if = {
			limit = { has_domicile_building = japanese_messenger_service_02 }
			remove_domicile_building = japanese_messenger_service_02
		}
		if = {
			limit = { has_domicile_building = japanese_messenger_service_03 }
			remove_domicile_building = japanese_messenger_service_03
		}
		if = {
			limit = { has_domicile_building = japanese_messenger_service_04 }
			remove_domicile_building = japanese_messenger_service_04
		}
		if = {
			limit = { has_domicile_building = japanese_messenger_service_05 }
			remove_domicile_building = japanese_messenger_service_05
		}
		if = {
			limit = { has_domicile_building = japanese_messenger_service_06 }
			remove_domicile_building = japanese_messenger_service_06
		}
		if = {
			limit = { has_domicile_building = japanese_armory_01 }
			remove_domicile_building = japanese_armory_01
		}
		if = {
			limit = { has_domicile_building = japanese_armory_02 }
			remove_domicile_building = japanese_armory_02
		}
		if = {
			limit = { has_domicile_building = japanese_armory_03 }
			remove_domicile_building = japanese_armory_03
		}
		if = {
			limit = { has_domicile_building = japanese_armory_04 }
			remove_domicile_building = japanese_armory_04
		}
		if = {
			limit = { has_domicile_building = japanese_armory_05 }
			remove_domicile_building = japanese_armory_05
		}
		if = {
			limit = { has_domicile_building = japanese_armory_06 }
			remove_domicile_building = japanese_armory_06
		}
		if = {
			limit = { has_domicile_building = japanese_bladesmith_01 }
			remove_domicile_building = japanese_bladesmith_01
		}
		if = {
			limit = { has_domicile_building = japanese_bladesmith_02 }
			remove_domicile_building = japanese_bladesmith_02
		}
		if = {
			limit = { has_domicile_building = japanese_bladesmith_03 }
			remove_domicile_building = japanese_bladesmith_03
		}
		if = {
			limit = { has_domicile_building = japanese_bladesmith_04 }
			remove_domicile_building = japanese_bladesmith_04
		}
		if = {
			limit = { has_domicile_building = japanese_bladesmith_05 }
			remove_domicile_building = japanese_bladesmith_05
		}
		if = {
			limit = { has_domicile_building = japanese_bladesmith_06 }
			remove_domicile_building = japanese_bladesmith_06
		}
		if = {
			limit = { has_domicile_building = japanese_armorer_01 }
			remove_domicile_building = japanese_armorer_01
		}
		if = {
			limit = { has_domicile_building = japanese_armorer_02 }
			remove_domicile_building = japanese_armorer_02
		}
		if = {
			limit = { has_domicile_building = japanese_armorer_03 }
			remove_domicile_building = japanese_armorer_03
		}
		if = {
			limit = { has_domicile_building = japanese_armorer_04 }
			remove_domicile_building = japanese_armorer_04
		}
		if = {
			limit = { has_domicile_building = japanese_armorer_05 }
			remove_domicile_building = japanese_armorer_05
		}
		if = {
			limit = { has_domicile_building = japanese_armorer_06 }
			remove_domicile_building = japanese_armorer_06
		}
		if = {
			limit = { has_domicile_building = japanese_barracks_01 }
			remove_domicile_building = japanese_barracks_01
		}
		if = {
			limit = { has_domicile_building = japanese_barracks_02 }
			remove_domicile_building = japanese_barracks_02
		}
		if = {
			limit = { has_domicile_building = japanese_barracks_03 }
			remove_domicile_building = japanese_barracks_03
		}
		if = {
			limit = { has_domicile_building = japanese_barracks_04 }
			remove_domicile_building = japanese_barracks_04
		}
		if = {
			limit = { has_domicile_building = japanese_barracks_05 }
			remove_domicile_building = japanese_barracks_05
		}
		if = {
			limit = { has_domicile_building = japanese_barracks_06 }
			remove_domicile_building = japanese_barracks_06
		}
		if = {
			limit = { has_domicile_building = japanese_watch_house_01 }
			remove_domicile_building = japanese_watch_house_01
		}
		if = {
			limit = { has_domicile_building = japanese_watch_house_02 }
			remove_domicile_building = japanese_watch_house_02
		}
		if = {
			limit = { has_domicile_building = japanese_watch_house_03 }
			remove_domicile_building = japanese_watch_house_03
		}
		if = {
			limit = { has_domicile_building = japanese_watch_house_04 }
			remove_domicile_building = japanese_watch_house_04
		}
		if = {
			limit = { has_domicile_building = japanese_watch_house_05 }
			remove_domicile_building = japanese_watch_house_05
		}
		if = {
			limit = { has_domicile_building = japanese_watch_house_06 }
			remove_domicile_building = japanese_watch_house_06
		}
		if = {
			limit = { has_domicile_building = japanese_spy_network_01 }
			remove_domicile_building = japanese_spy_network_01
		}
		if = {
			limit = { has_domicile_building = japanese_spy_network_02 }
			remove_domicile_building = japanese_spy_network_02
		}
		if = {
			limit = { has_domicile_building = japanese_spy_network_03 }
			remove_domicile_building = japanese_spy_network_03
		}
		if = {
			limit = { has_domicile_building = japanese_spy_network_04 }
			remove_domicile_building = japanese_spy_network_04
		}
		if = {
			limit = { has_domicile_building = japanese_spy_network_05 }
			remove_domicile_building = japanese_spy_network_05
		}
		if = {
			limit = { has_domicile_building = japanese_spy_network_06 }
			remove_domicile_building = japanese_spy_network_06
		}
		if = {
			limit = { has_domicile_building = japanese_infiltrators_01 }
			remove_domicile_building = japanese_infiltrators_01
		}
		if = {
			limit = { has_domicile_building = japanese_infiltrators_02 }
			remove_domicile_building = japanese_infiltrators_02
		}
		if = {
			limit = { has_domicile_building = japanese_infiltrators_03 }
			remove_domicile_building = japanese_infiltrators_03
		}
		if = {
			limit = { has_domicile_building = japanese_infiltrators_04 }
			remove_domicile_building = japanese_infiltrators_04
		}
		if = {
			limit = { has_domicile_building = japanese_infiltrators_05 }
			remove_domicile_building = japanese_infiltrators_05
		}
		if = {
			limit = { has_domicile_building = japanese_infiltrators_06 }
			remove_domicile_building = japanese_infiltrators_06
		}
		if = {
			limit = { has_domicile_building = japanese_prison_01 }
			remove_domicile_building = japanese_prison_01
		}
		if = {
			limit = { has_domicile_building = japanese_prison_02 }
			remove_domicile_building = japanese_prison_02
		}
		if = {
			limit = { has_domicile_building = japanese_prison_03 }
			remove_domicile_building = japanese_prison_03
		}
		if = {
			limit = { has_domicile_building = japanese_prison_04 }
			remove_domicile_building = japanese_prison_04
		}
		if = {
			limit = { has_domicile_building = japanese_prison_05 }
			remove_domicile_building = japanese_prison_05
		}
		if = {
			limit = { has_domicile_building = japanese_prison_06 }
			remove_domicile_building = japanese_prison_06
		}
		if = {
			limit = { has_domicile_building = japanese_horse_pastures_01 }
			remove_domicile_building = japanese_horse_pastures_01
		}
		if = {
			limit = { has_domicile_building = japanese_horse_pastures_02 }
			remove_domicile_building = japanese_horse_pastures_02
		}
		if = {
			limit = { has_domicile_building = japanese_horse_pastures_03 }
			remove_domicile_building = japanese_horse_pastures_03
		}
		if = {
			limit = { has_domicile_building = japanese_horse_pastures_04 }
			remove_domicile_building = japanese_horse_pastures_04
		}
		if = {
			limit = { has_domicile_building = japanese_horse_pastures_05 }
			remove_domicile_building = japanese_horse_pastures_05
		}
		if = {
			limit = { has_domicile_building = japanese_horse_pastures_06 }
			remove_domicile_building = japanese_horse_pastures_06
		}
		if = {
			limit = { has_domicile_building = japanese_stud_farm_01 }
			remove_domicile_building = japanese_stud_farm_01
		}
		if = {
			limit = { has_domicile_building = japanese_stud_farm_02 }
			remove_domicile_building = japanese_stud_farm_02
		}
		if = {
			limit = { has_domicile_building = japanese_stud_farm_03 }
			remove_domicile_building = japanese_stud_farm_03
		}
		if = {
			limit = { has_domicile_building = japanese_stud_farm_04 }
			remove_domicile_building = japanese_stud_farm_04
		}
		if = {
			limit = { has_domicile_building = japanese_stud_farm_05 }
			remove_domicile_building = japanese_stud_farm_05
		}
		if = {
			limit = { has_domicile_building = japanese_stud_farm_06 }
			remove_domicile_building = japanese_stud_farm_06
		}
		if = {
			limit = { has_domicile_building = japanese_ox_breeder_01 }
			remove_domicile_building = japanese_ox_breeder_01
		}
		if = {
			limit = { has_domicile_building = japanese_ox_breeder_02 }
			remove_domicile_building = japanese_ox_breeder_02
		}
		if = {
			limit = { has_domicile_building = japanese_ox_breeder_03 }
			remove_domicile_building = japanese_ox_breeder_03
		}
		if = {
			limit = { has_domicile_building = japanese_ox_breeder_04 }
			remove_domicile_building = japanese_ox_breeder_04
		}
		if = {
			limit = { has_domicile_building = japanese_ox_breeder_05 }
			remove_domicile_building = japanese_ox_breeder_05
		}
		if = {
			limit = { has_domicile_building = japanese_ox_breeder_06 }
			remove_domicile_building = japanese_ox_breeder_06
		}
		if = {
			limit = { has_domicile_building = japanese_riding_school_01 }
			remove_domicile_building = japanese_riding_school_01
		}
		if = {
			limit = { has_domicile_building = japanese_riding_school_02 }
			remove_domicile_building = japanese_riding_school_02
		}
		if = {
			limit = { has_domicile_building = japanese_riding_school_03 }
			remove_domicile_building = japanese_riding_school_03
		}
		if = {
			limit = { has_domicile_building = japanese_riding_school_04 }
			remove_domicile_building = japanese_riding_school_04
		}
		if = {
			limit = { has_domicile_building = japanese_riding_school_05 }
			remove_domicile_building = japanese_riding_school_05
		}
		if = {
			limit = { has_domicile_building = japanese_riding_school_06 }
			remove_domicile_building = japanese_riding_school_06
		}
		if = {
			limit = { has_domicile_building = japanese_tea_plantation_01 }
			remove_domicile_building = japanese_tea_plantation_01
		}
		if = {
			limit = { has_domicile_building = japanese_tea_plantation_02 }
			remove_domicile_building = japanese_tea_plantation_02
		}
		if = {
			limit = { has_domicile_building = japanese_tea_plantation_03 }
			remove_domicile_building = japanese_tea_plantation_03
		}
		if = {
			limit = { has_domicile_building = japanese_tea_plantation_04 }
			remove_domicile_building = japanese_tea_plantation_04
		}
		if = {
			limit = { has_domicile_building = japanese_tea_plantation_05 }
			remove_domicile_building = japanese_tea_plantation_05
		}
		if = {
			limit = { has_domicile_building = japanese_tea_plantation_06 }
			remove_domicile_building = japanese_tea_plantation_06
		}
		if = {
			limit = { has_domicile_building = japanese_matcha_factory_01 }
			remove_domicile_building = japanese_matcha_factory_01
		}
		if = {
			limit = { has_domicile_building = japanese_matcha_factory_02 }
			remove_domicile_building = japanese_matcha_factory_02
		}
		if = {
			limit = { has_domicile_building = japanese_matcha_factory_03 }
			remove_domicile_building = japanese_matcha_factory_03
		}
		if = {
			limit = { has_domicile_building = japanese_matcha_factory_04 }
			remove_domicile_building = japanese_matcha_factory_04
		}
		if = {
			limit = { has_domicile_building = japanese_matcha_factory_05 }
			remove_domicile_building = japanese_matcha_factory_05
		}
		if = {
			limit = { has_domicile_building = japanese_matcha_factory_06 }
			remove_domicile_building = japanese_matcha_factory_06
		}
		if = {
			limit = { has_domicile_building = japanese_medicine_house_01 }
			remove_domicile_building = japanese_medicine_house_01
		}
		if = {
			limit = { has_domicile_building = japanese_medicine_house_02 }
			remove_domicile_building = japanese_medicine_house_02
		}
		if = {
			limit = { has_domicile_building = japanese_medicine_house_03 }
			remove_domicile_building = japanese_medicine_house_03
		}
		if = {
			limit = { has_domicile_building = japanese_medicine_house_04 }
			remove_domicile_building = japanese_medicine_house_04
		}
		if = {
			limit = { has_domicile_building = japanese_medicine_house_05 }
			remove_domicile_building = japanese_medicine_house_05
		}
		if = {
			limit = { has_domicile_building = japanese_medicine_house_06 }
			remove_domicile_building = japanese_medicine_house_06
		}
		if = {
			limit = { has_domicile_building = japanese_roastery_01 }
			remove_domicile_building = japanese_roastery_01
		}
		if = {
			limit = { has_domicile_building = japanese_roastery_02 }
			remove_domicile_building = japanese_roastery_02
		}
		if = {
			limit = { has_domicile_building = japanese_roastery_03 }
			remove_domicile_building = japanese_roastery_03
		}
		if = {
			limit = { has_domicile_building = japanese_roastery_04 }
			remove_domicile_building = japanese_roastery_04
		}
		if = {
			limit = { has_domicile_building = japanese_roastery_05 }
			remove_domicile_building = japanese_roastery_05
		}
		if = {
			limit = { has_domicile_building = japanese_roastery_06 }
			remove_domicile_building = japanese_roastery_06
		}
		if = {
			limit = { has_domicile_building = japanese_stables_01 }
			remove_domicile_building = japanese_stables_01
		}
		if = {
			limit = { has_domicile_building = japanese_stables_02 }
			remove_domicile_building = japanese_stables_02
		}
		if = {
			limit = { has_domicile_building = japanese_stables_03 }
			remove_domicile_building = japanese_stables_03
		}
		if = {
			limit = { has_domicile_building = japanese_stables_04 }
			remove_domicile_building = japanese_stables_04
		}
		if = {
			limit = { has_domicile_building = japanese_stables_05 }
			remove_domicile_building = japanese_stables_05
		}
		if = {
			limit = { has_domicile_building = japanese_stables_06 }
			remove_domicile_building = japanese_stables_06
		}
		if = {
			limit = { has_domicile_building = japanese_yabusame_ground_01 }
			remove_domicile_building = japanese_yabusame_ground_01
		}
		if = {
			limit = { has_domicile_building = japanese_yabusame_ground_02 }
			remove_domicile_building = japanese_yabusame_ground_02
		}
		if = {
			limit = { has_domicile_building = japanese_yabusame_ground_03 }
			remove_domicile_building = japanese_yabusame_ground_03
		}
		if = {
			limit = { has_domicile_building = japanese_yabusame_ground_04 }
			remove_domicile_building = japanese_yabusame_ground_04
		}
		if = {
			limit = { has_domicile_building = japanese_yabusame_ground_05 }
			remove_domicile_building = japanese_yabusame_ground_05
		}
		if = {
			limit = { has_domicile_building = japanese_yabusame_ground_06 }
			remove_domicile_building = japanese_yabusame_ground_06
		}
		if = {
			limit = { has_domicile_building = japanese_farrier_01 }
			remove_domicile_building = japanese_farrier_01
		}
		if = {
			limit = { has_domicile_building = japanese_farrier_02 }
			remove_domicile_building = japanese_farrier_02
		}
		if = {
			limit = { has_domicile_building = japanese_farrier_03 }
			remove_domicile_building = japanese_farrier_03
		}
		if = {
			limit = { has_domicile_building = japanese_farrier_04 }
			remove_domicile_building = japanese_farrier_04
		}
		if = {
			limit = { has_domicile_building = japanese_farrier_05 }
			remove_domicile_building = japanese_farrier_05
		}
		if = {
			limit = { has_domicile_building = japanese_farrier_06 }
			remove_domicile_building = japanese_farrier_06
		}
		if = {
			limit = { has_domicile_building = japanese_hunting_lodge_01 }
			remove_domicile_building = japanese_hunting_lodge_01
		}
		if = {
			limit = { has_domicile_building = japanese_hunting_lodge_02 }
			remove_domicile_building = japanese_hunting_lodge_02
		}
		if = {
			limit = { has_domicile_building = japanese_hunting_lodge_03 }
			remove_domicile_building = japanese_hunting_lodge_03
		}
		if = {
			limit = { has_domicile_building = japanese_hunting_lodge_04 }
			remove_domicile_building = japanese_hunting_lodge_04
		}
		if = {
			limit = { has_domicile_building = japanese_hunting_lodge_05 }
			remove_domicile_building = japanese_hunting_lodge_05
		}
		if = {
			limit = { has_domicile_building = japanese_hunting_lodge_06 }
			remove_domicile_building = japanese_hunting_lodge_06
		}
		if = {
			limit = { has_domicile_building = japanese_workshop_01 }
			remove_domicile_building = japanese_workshop_01
		}
		if = {
			limit = { has_domicile_building = japanese_workshop_02 }
			remove_domicile_building = japanese_workshop_02
		}
		if = {
			limit = { has_domicile_building = japanese_workshop_03 }
			remove_domicile_building = japanese_workshop_03
		}
		if = {
			limit = { has_domicile_building = japanese_workshop_04 }
			remove_domicile_building = japanese_workshop_04
		}
		if = {
			limit = { has_domicile_building = japanese_workshop_05 }
			remove_domicile_building = japanese_workshop_05
		}
		if = {
			limit = { has_domicile_building = japanese_workshop_06 }
			remove_domicile_building = japanese_workshop_06
		}
		if = {
			limit = { has_domicile_building = japanese_bowyer_01 }
			remove_domicile_building = japanese_bowyer_01
		}
		if = {
			limit = { has_domicile_building = japanese_bowyer_02 }
			remove_domicile_building = japanese_bowyer_02
		}
		if = {
			limit = { has_domicile_building = japanese_bowyer_03 }
			remove_domicile_building = japanese_bowyer_03
		}
		if = {
			limit = { has_domicile_building = japanese_bowyer_04 }
			remove_domicile_building = japanese_bowyer_04
		}
		if = {
			limit = { has_domicile_building = japanese_bowyer_05 }
			remove_domicile_building = japanese_bowyer_05
		}
		if = {
			limit = { has_domicile_building = japanese_bowyer_06 }
			remove_domicile_building = japanese_bowyer_06
		}
		if = {
			limit = { has_domicile_building = japanese_lacquerer_01 }
			remove_domicile_building = japanese_lacquerer_01
		}
		if = {
			limit = { has_domicile_building = japanese_lacquerer_02 }
			remove_domicile_building = japanese_lacquerer_02
		}
		if = {
			limit = { has_domicile_building = japanese_lacquerer_03 }
			remove_domicile_building = japanese_lacquerer_03
		}
		if = {
			limit = { has_domicile_building = japanese_lacquerer_04 }
			remove_domicile_building = japanese_lacquerer_04
		}
		if = {
			limit = { has_domicile_building = japanese_lacquerer_05 }
			remove_domicile_building = japanese_lacquerer_05
		}
		if = {
			limit = { has_domicile_building = japanese_lacquerer_06 }
			remove_domicile_building = japanese_lacquerer_06
		}
		if = {
			limit = { has_domicile_building = japanese_carpenter_01 }
			remove_domicile_building = japanese_carpenter_01
		}
		if = {
			limit = { has_domicile_building = japanese_carpenter_02 }
			remove_domicile_building = japanese_carpenter_02
		}
		if = {
			limit = { has_domicile_building = japanese_carpenter_03 }
			remove_domicile_building = japanese_carpenter_03
		}
		if = {
			limit = { has_domicile_building = japanese_carpenter_04 }
			remove_domicile_building = japanese_carpenter_04
		}
		if = {
			limit = { has_domicile_building = japanese_carpenter_05 }
			remove_domicile_building = japanese_carpenter_05
		}
		if = {
			limit = { has_domicile_building = japanese_carpenter_06 }
			remove_domicile_building = japanese_carpenter_06
		}
		if = {
			limit = { has_domicile_building = japanese_tea_house_01 }
			remove_domicile_building = japanese_tea_house_01
		}
		if = {
			limit = { has_domicile_building = japanese_tea_house_02 }
			remove_domicile_building = japanese_tea_house_02
		}
		if = {
			limit = { has_domicile_building = japanese_tea_house_03 }
			remove_domicile_building = japanese_tea_house_03
		}
		if = {
			limit = { has_domicile_building = japanese_tea_house_04 }
			remove_domicile_building = japanese_tea_house_04
		}
		if = {
			limit = { has_domicile_building = japanese_tea_house_05 }
			remove_domicile_building = japanese_tea_house_05
		}
		if = {
			limit = { has_domicile_building = japanese_tea_house_06 }
			remove_domicile_building = japanese_tea_house_06
		}
		if = {
			limit = { has_domicile_building = japanese_guest_house_01 }
			remove_domicile_building = japanese_guest_house_01
		}
		if = {
			limit = { has_domicile_building = japanese_guest_house_02 }
			remove_domicile_building = japanese_guest_house_02
		}
		if = {
			limit = { has_domicile_building = japanese_guest_house_03 }
			remove_domicile_building = japanese_guest_house_03
		}
		if = {
			limit = { has_domicile_building = japanese_guest_house_04 }
			remove_domicile_building = japanese_guest_house_04
		}
		if = {
			limit = { has_domicile_building = japanese_guest_house_05 }
			remove_domicile_building = japanese_guest_house_05
		}
		if = {
			limit = { has_domicile_building = japanese_guest_house_06 }
			remove_domicile_building = japanese_guest_house_06
		}
		if = {
			limit = { has_domicile_building = japanese_performance_stage_01 }
			remove_domicile_building = japanese_performance_stage_01
		}
		if = {
			limit = { has_domicile_building = japanese_performance_stage_02 }
			remove_domicile_building = japanese_performance_stage_02
		}
		if = {
			limit = { has_domicile_building = japanese_performance_stage_03 }
			remove_domicile_building = japanese_performance_stage_03
		}
		if = {
			limit = { has_domicile_building = japanese_performance_stage_04 }
			remove_domicile_building = japanese_performance_stage_04
		}
		if = {
			limit = { has_domicile_building = japanese_performance_stage_05 }
			remove_domicile_building = japanese_performance_stage_05
		}
		if = {
			limit = { has_domicile_building = japanese_performance_stage_06 }
			remove_domicile_building = japanese_performance_stage_06
		}
		if = {
			limit = { has_domicile_building = japanese_asobi_colony_01 }
			remove_domicile_building = japanese_asobi_colony_01
		}
		if = {
			limit = { has_domicile_building = japanese_asobi_colony_02 }
			remove_domicile_building = japanese_asobi_colony_02
		}
		if = {
			limit = { has_domicile_building = japanese_asobi_colony_03 }
			remove_domicile_building = japanese_asobi_colony_03
		}
		if = {
			limit = { has_domicile_building = japanese_asobi_colony_04 }
			remove_domicile_building = japanese_asobi_colony_04
		}
		if = {
			limit = { has_domicile_building = japanese_asobi_colony_05 }
			remove_domicile_building = japanese_asobi_colony_05
		}
		if = {
			limit = { has_domicile_building = japanese_asobi_colony_06 }
			remove_domicile_building = japanese_asobi_colony_06
		}
		if = {
			limit = { has_domicile_building = japanese_garden_01 }
			remove_domicile_building = japanese_garden_01
		}
		if = {
			limit = { has_domicile_building = japanese_garden_02 }
			remove_domicile_building = japanese_garden_02
		}
		if = {
			limit = { has_domicile_building = japanese_garden_03 }
			remove_domicile_building = japanese_garden_03
		}
		if = {
			limit = { has_domicile_building = japanese_garden_04 }
			remove_domicile_building = japanese_garden_04
		}
		if = {
			limit = { has_domicile_building = japanese_garden_05 }
			remove_domicile_building = japanese_garden_05
		}
		if = {
			limit = { has_domicile_building = japanese_garden_06 }
			remove_domicile_building = japanese_garden_06
		}
		if = {
			limit = { has_domicile_building = japanese_rock_garden_01 }
			remove_domicile_building = japanese_rock_garden_01
		}
		if = {
			limit = { has_domicile_building = japanese_rock_garden_02 }
			remove_domicile_building = japanese_rock_garden_02
		}
		if = {
			limit = { has_domicile_building = japanese_rock_garden_03 }
			remove_domicile_building = japanese_rock_garden_03
		}
		if = {
			limit = { has_domicile_building = japanese_rock_garden_04 }
			remove_domicile_building = japanese_rock_garden_04
		}
		if = {
			limit = { has_domicile_building = japanese_rock_garden_05 }
			remove_domicile_building = japanese_rock_garden_05
		}
		if = {
			limit = { has_domicile_building = japanese_rock_garden_06 }
			remove_domicile_building = japanese_rock_garden_06
		}
		if = {
			limit = { has_domicile_building = japanese_kazan_display_01 }
			remove_domicile_building = japanese_kazan_display_01
		}
		if = {
			limit = { has_domicile_building = japanese_kazan_display_02 }
			remove_domicile_building = japanese_kazan_display_02
		}
		if = {
			limit = { has_domicile_building = japanese_kazan_display_03 }
			remove_domicile_building = japanese_kazan_display_03
		}
		if = {
			limit = { has_domicile_building = japanese_kazan_display_04 }
			remove_domicile_building = japanese_kazan_display_04
		}
		if = {
			limit = { has_domicile_building = japanese_kazan_display_05 }
			remove_domicile_building = japanese_kazan_display_05
		}
		if = {
			limit = { has_domicile_building = japanese_kazan_display_06 }
			remove_domicile_building = japanese_kazan_display_06
		}
		if = {
			limit = { has_domicile_building = japanese_orchard_01 }
			remove_domicile_building = japanese_orchard_01
		}
		if = {
			limit = { has_domicile_building = japanese_orchard_02 }
			remove_domicile_building = japanese_orchard_02
		}
		if = {
			limit = { has_domicile_building = japanese_orchard_03 }
			remove_domicile_building = japanese_orchard_03
		}
		if = {
			limit = { has_domicile_building = japanese_orchard_04 }
			remove_domicile_building = japanese_orchard_04
		}
		if = {
			limit = { has_domicile_building = japanese_orchard_05 }
			remove_domicile_building = japanese_orchard_05
		}
		if = {
			limit = { has_domicile_building = japanese_orchard_06 }
			remove_domicile_building = japanese_orchard_06
		}
	}
}

disburse_festival_piety_reward_effect = {
	if = {
		limit = {
			root.faith = {
				OR = {
					has_doctrine_parameter = piety_from_festivals_active
					AND = {
						has_doctrine_parameter = summer_festivals_active
						# Only during 'summer' (May 1st through July 31st).
						current_month >= 5
						current_month <= 7
					}
				}
			}
		}
		root = {
			add_piety = {
				value = 0

				if = {
					limit = {
						faith = { has_doctrine_parameter = summer_festivals_active }
						# Only during 'summer' (May 1st through July 31st).
						current_month >= 5
						current_month <= 7
					}
					add = major_piety_value
				}
				if = {
					limit = {
						faith = { has_doctrine = tenet_ritual_celebrations }
					}
					add = medium_piety_value
				}
				if = {
					limit = {
						faith = { has_doctrine = tenet_hedonistic }
					}
					add = medium_piety_value
				}
				if = {
					limit = {
						has_royal_court = yes
						has_dlc_feature = royal_court
						amenity_level = { target = court_food_quality value >= 5 }
					}
					multiply = 2.5
				}
				else_if = {
					limit = {
						has_royal_court = yes
						has_dlc_feature = royal_court
						amenity_level = { target = court_food_quality value >= 4 }
					}
					multiply = 2
				}
				else_if = {
					limit = {
						has_royal_court = yes
						has_dlc_feature = royal_court
						amenity_level = { target = court_food_quality value >= 3 }
					}
					multiply = 1.5
				}
				else_if = {
					limit = {
						has_royal_court = yes
						has_dlc_feature = royal_court
						amenity_level = { target = court_food_quality value >= 2 }
					}
					multiply = 1
				}
				else_if = {
					limit = {
						has_royal_court = yes
						has_dlc_feature = royal_court
						amenity_level = { target = court_food_quality value <= 1 }
					}
					multiply = 0.5
				}

				# Always give some piety, even if you completely cheaped out.
				min = medium_piety_value
			}
		}
	}
}

tgp_flip_education_track_on_game_start = {
	switch = {
		trigger = has_trait
		#Flip the military trait to a random civilian one of the same level
		education_martial_1 = {
			remove_trait = education_martial_1
			random_list = {
				1 = {
					add_trait = education_intrigue_1
				}
				1 = {
					add_trait = education_diplomacy_1
				}
				1 = {
					add_trait = education_stewardship_1
				}
				1 = {
					add_trait = education_learning_1
				}
			}
		}
		education_martial_2 = {
			remove_trait = education_martial_2
			random_list = {
				1 = {
					add_trait = education_intrigue_2
				}
				1 = {
					add_trait = education_diplomacy_2
				}
				1 = {
					add_trait = education_stewardship_2
				}
				1 = {
					add_trait = education_learning_2
				}
			}
		}
		education_martial_3 = {
			remove_trait = education_martial_3
			random_list = {
				1 = {
					add_trait = education_intrigue_3
				}
				1 = {
					add_trait = education_diplomacy_3
				}
				1 = {
					add_trait = education_stewardship_3
				}
				1 = {
					add_trait = education_learning_3
				}
			}
		}
		education_martial_4 = {
			remove_trait = education_martial_4
			random_list = {
				1 = {
					add_trait = education_intrigue_4
				}
				1 = {
					add_trait = education_diplomacy_4
				}
				1 = {
					add_trait = education_stewardship_4
				}
				1 = {
					add_trait = education_learning_4
				}
			}
		}
		education_martial_5 = {
			remove_trait = education_martial_5
			random_list = {
				1 = {
					add_trait = education_intrigue_5
				}
				1 = {
					add_trait = education_diplomacy_5
				}
				1 = {
					add_trait = education_stewardship_5
				}
				1 = {
					add_trait = education_learning_5
				}
			}
		}
		# Flip civilian education traits to martial of the same level
		education_intrigue_1 = {
			remove_trait = education_intrigue_1
			add_trait = education_martial_1
		}
		education_intrigue_2 = {
			remove_trait = education_intrigue_2
			add_trait = education_martial_2
		}
		education_intrigue_3 = {
			remove_trait = education_intrigue_3
			add_trait = education_martial_3
		}
		education_intrigue_4 = {
			remove_trait = education_intrigue_4
			add_trait = education_martial_4
		}
		education_intrigue_5 = {
			remove_trait = education_intrigue_5
			add_trait = education_martial_5
		}
		education_diplomacy_1 = {
			remove_trait = education_diplomacy_1
			add_trait = education_martial_1
		}
		education_diplomacy_2 = {
			remove_trait = education_diplomacy_2
			add_trait = education_martial_2
		}
		education_diplomacy_3 = {
			remove_trait = education_diplomacy_3
			add_trait = education_martial_3
		}
		education_diplomacy_4 = {
			remove_trait = education_diplomacy_4
			add_trait = education_martial_4
		}
		education_diplomacy_5 = {
			remove_trait = education_diplomacy_5
			add_trait = education_martial_5
		}
		education_stewardship_1 = {
			remove_trait = education_stewardship_1
			add_trait = education_martial_1
		}
		education_stewardship_2 = {
			remove_trait = education_stewardship_2
			add_trait = education_martial_2
		}
		education_stewardship_3 = {
			remove_trait = education_stewardship_3
			add_trait = education_martial_3
		}
		education_stewardship_4 = {
			remove_trait = education_stewardship_4
			add_trait = education_martial_4
		}
		education_stewardship_5 = {
			remove_trait = education_stewardship_5
			add_trait = education_martial_5
		}
		education_learning_1 = {
			remove_trait = education_learning_1
			add_trait = education_martial_1
		}
		education_learning_2 = {
			remove_trait = education_learning_2
			add_trait = education_martial_2
		}
		education_learning_3 = {
			remove_trait = education_learning_3
			add_trait = education_martial_3
		}
		education_learning_4 = {
			remove_trait = education_learning_4
			add_trait = education_martial_4
		}
		education_learning_5 = {
			remove_trait = education_learning_5
			add_trait = education_martial_5
		}
	}
}
