﻿# NEOW: Japanese manor functions are reused by British Aristocratic and Commonwealth government domiciles.

add_random_internal_japanese_manor_building = {
	if = {
		limit = {
			domicile_building_has_free_internal_slot = japanese_manor_main_01
		}
		random_list = {
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_main_tax_collectors_01 }
				}
				add_domicile_building = japanese_main_tax_collectors_01
				if = {
					limit = { has_domicile_building = japanese_manor_main_03 }
					add_domicile_building = japanese_main_tax_collectors_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_main_carpenter_01 }
				}
				add_domicile_building = japanese_main_carpenter_01
				if = {
					limit = { has_domicile_building = japanese_manor_main_03 }
					add_domicile_building = japanese_main_carpenter_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = sarugaku_stage_01 }
				}
				add_domicile_building = sarugaku_stage_01
				if = {
					limit = { has_domicile_building = japanese_manor_main_03 }
					add_domicile_building = sarugaku_stage_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_manor_office_01 }
				}
				add_domicile_building = japanese_manor_office_01
				if = {
					limit = { has_domicile_building = japanese_manor_main_03 }
					add_domicile_building = japanese_manor_office_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_manor_servants_quarters_01 }
				}
				add_domicile_building = japanese_manor_servants_quarters_01
				if = {
					limit = { has_domicile_building = japanese_manor_main_03 }
					add_domicile_building = japanese_manor_servants_quarters_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_manor_library_confucian_01 }
				}
				add_domicile_building = japanese_manor_library_confucian_01
				if = {
					limit = { has_domicile_building = japanese_manor_main_03 }
					add_domicile_building = japanese_manor_library_confucian_02
				}
			}
		}
	}
}

add_random_external_japanese_manor_building = {
	if = {
		limit = { free_external_domicile_building_slots >= 1 }
		random_list = {
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_fields_01 }
				}
				add_domicile_building = japanese_fields_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_fields_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_fields_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_shrine_01 }
					owner.house = { has_house_aspiration_parameter = unlocks_japanese_manor_shrine }
				}
				add_domicile_building = japanese_shrine_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_shrine_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_shrine_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_brewery_01 }
					owner.house = { has_house_aspiration_parameter = unlocks_japanese_manor_brewery }
				}
				add_domicile_building = japanese_brewery_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_brewery_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_brewery_02
				}
			}
			10 = {
				trigger = {
					owner = { government_has_mechanic = administrative }
					NOT = { has_domicile_building_or_higher = japanese_archive_01 }
					owner.house = { has_house_aspiration_parameter = unlocks_japanese_manor_archive }
				}
				add_domicile_building = japanese_archive_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_archive_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_archive_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_armory_01 }
					owner.house = { has_house_aspiration_parameter = unlocks_japanese_manor_armory }
				}
				add_domicile_building = japanese_armory_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_armory_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_armory_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_watch_house_01 }
					owner.house = { has_house_aspiration_parameter = unlocks_japanese_manor_watch_house }
				}
				add_domicile_building = japanese_watch_house_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_watch_house_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_watch_house_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_horse_pastures_01 }
				}
				add_domicile_building = japanese_horse_pastures_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_horse_pastures_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_horse_pastures_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_tea_plantation_01 }
				}
				add_domicile_building = japanese_tea_plantation_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_tea_plantation_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_tea_plantation_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_stables_01 }
				}
				add_domicile_building = japanese_stables_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_stables_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_stables_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_workshop_01 }
				}
				add_domicile_building = japanese_workshop_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_workshop_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_workshop_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_tea_house_01 }
					owner.house = { has_house_aspiration_parameter = unlocks_japanese_manor_tea_house }
				}
				add_domicile_building = japanese_tea_house_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_tea_house_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_tea_house_02
				}
			}
			10 = {
				trigger = {
					NOT = { has_domicile_building_or_higher = japanese_garden_01 }
				}
				add_domicile_building = japanese_garden_01
				if = {
					limit = {
						has_domicile_building_or_higher = japanese_garden_01
						has_domicile_building_or_higher = japanese_manor_main_03
					}
					add_domicile_building = japanese_garden_02
				}
			}
		}
	}
}

fill_external_japanese_manor_building_effect = {
	switch = {
		trigger = has_domicile_building_or_higher
		japanese_manor_main_05 = {
			while = {
				limit = { free_external_domicile_building_slots >= 1 }
				add_random_external_japanese_manor_building = yes
			}
		}
		japanese_manor_main_04 = {
			while = {
				limit = { free_external_domicile_building_slots >= 2 }
				add_random_external_japanese_manor_building = yes
			}
		}
		japanese_manor_main_03 = {
			while = {
				limit = { free_external_domicile_building_slots >= 3 }
				add_random_external_japanese_manor_building = yes
			}
		}
		japanese_manor_main_02 = {
			while = {
				limit = { free_external_domicile_building_slots >= 4 }
				add_random_external_japanese_manor_building = yes
			}
		}
		japanese_manor_main_01 = {
			while = {
				limit = { free_external_domicile_building_slots >= 5 }
				add_random_external_japanese_manor_building = yes
			}
		}
	}
}
