# Tribal
tribal = {
	# Basic Keep (results in ca_keep_1 when converted)
	tb_basic_keep_1 = {
		desc = ca_keep_1_desc
		not_if_x_exists = { tb_town_hall_1 }
		gold_cost = 15
		build_time = 365
		ai_creation_factor = 400
		ai_feudal_modifier = 10
		ai_republic_modifier = -10
		extra_tech_building_start = 0.24

		levy_size = 0.01
		garrison_size = 0.01
		tax_income = 0.1

		potential = {
			# No getting around existing requirements
			trigger_if = {
				limit = { has_castle = yes }

				has_city = yes
				has_temple = no
			}
		}

		trigger = {
			TECH_CASTLE_CONSTRUCTION >= 1
			ai_can_build_trigger = yes

			# Tell the player about the mutual exclusivity
			trigger_if = {
				limit = { has_building = tb_town_hall_1 }
				
				NOT = { has_building = tb_town_hall_1 }
			}
		}
	}

	tb_basic_keep_2 = {
		desc = ca_keep_1_desc
		upgrades_from = tb_basic_keep_1
		gold_cost = 30
		build_time = 547
		ai_creation_factor = 400
		ai_feudal_modifier = 10
		ai_republic_modifier = -10
		extra_tech_building_start = 0.48

		levy_size = 0.01
		garrison_size = 0.01
		tax_income = 0.1

		trigger = {
			TECH_CASTLE_CONSTRUCTION >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_basic_keep_3 = {
		desc = ca_keep_1_desc
		upgrades_from = tb_basic_keep_2
		gold_cost = 57
		build_time = 1095
		ai_creation_factor = 400
		ai_feudal_modifier = 10
		ai_republic_modifier = -10
		extra_tech_building_start = 0.72

		levy_size = 0.01
		garrison_size = 0.01
		tax_income = 0.1

		trigger = {
			TECH_CASTLE_CONSTRUCTION >= 1
			TECH_FORTIFICATIONS_CONSTRUCTION >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_basic_keep_4 = {
		desc = ca_keep_1_desc
		upgrades_from = tb_basic_keep_3
		gold_cost = 114
		build_time = 1460
		ai_creation_factor = 400
		ai_feudal_modifier = 10
		ai_republic_modifier = -10
		extra_tech_building_start = 0.96

		levy_size = 0.01
		garrison_size = 0.01
		tax_income = 0.1

		trigger = {
			TECH_CASTLE_CONSTRUCTION >= 1
			TECH_FORTIFICATIONS_CONSTRUCTION >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_basic_keep_5 = {
		desc = ca_keep_1_desc
		upgrades_from = tb_basic_keep_4
		convert_to_castle = ca_keep_1
		gold_cost = 114
		build_time = 2190
		ai_creation_factor = 400
		ai_feudal_modifier = 10
		ai_republic_modifier = -10
		extra_tech_building_start = 1.2

		fort_level = 0.5
		levy_size = 0.02
		garrison_size = 0.02
		tax_income = 0.2

		trigger = {
			TECH_CASTLE_CONSTRUCTION >= 1
			TECH_FORTIFICATIONS_CONSTRUCTION >= 1
			ai_can_build_trigger = yes
		}
	}

	# Town Hall (Results in Merchant's Guild when converted)
	tb_town_hall_1 = {
		not_if_x_exists = { tb_basic_keep_1 }
		gold_cost = 15
		build_time = 365
		ai_creation_factor = 200
		ai_feudal_modifier = -10
		ai_republic_modifier = 10
		extra_tech_building_start = 0.16

		tax_income = 0.5

		potential = {
			OR = {
				FROM = {
					trigger_if = {
						limit = { is_tribal = yes }
						ai = yes # AI can break the rules
					}
				}

				is_capital = no

				trigger_if = {
					limit = { is_coastal = yes }
					has_dlc = "The Republic"
				}
			}

			trigger_if = { # No getting around existing requirements
				limit = { has_city = yes }

				has_castle = yes
				has_temple = yes
			}
		}

		trigger = {
			TECH_CITY_CONSTRUCTION >= 1
			ai_can_build_trigger = yes

			# Tell the player about the mutual exclusivity
			trigger_if = {
				limit = { has_building = tb_basic_keep_1 }
				
				NOT = { has_building = tb_basic_keep_1 }
			}
		}
	}

	tb_town_hall_2 = {
		upgrades_from = tb_town_hall_1
		gold_cost = 30
		build_time = 547
		ai_creation_factor = 200
		ai_feudal_modifier = -10
		ai_republic_modifier = 10
		extra_tech_building_start = 0.32

		tax_income = 0.5

		potential = {
			OR = {
				FROM = {
					trigger_if = {
						limit = { is_tribal = yes }
						ai = yes # AI can break the rules
					}
				}

				is_capital = no

				trigger_if = {
					limit = { is_coastal = yes }
					has_dlc = "The Republic"
				}
			}
		}

		trigger = {
			TECH_CITY_CONSTRUCTION >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_town_hall_3 = {
		upgrades_from = tb_town_hall_2
		gold_cost = 57
		build_time = 1095
		ai_creation_factor = 200
		ai_feudal_modifier = -10
		ai_republic_modifier = 10
		extra_tech_building_start = 0.48

		tax_income = 0.5

		potential = {
			OR = {
				FROM = {
					trigger_if = {
						limit = { is_tribal = yes }
						ai = yes # AI can break the rules
					}
				}

				is_capital = no

				trigger_if = {
					limit = { is_coastal = yes }
					has_dlc = "The Republic"
				}
			}
		}

		trigger = {
			TECH_CITY_CONSTRUCTION >= 1
			TECH_TRADE_PRACTICES >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_town_hall_4 = {
		upgrades_from = tb_town_hall_3
		gold_cost = 114
		build_time = 1460
		ai_creation_factor = 200
		ai_feudal_modifier = -10
		ai_republic_modifier = 10
		extra_tech_building_start = 0.64

		tax_income = 0.5

		potential = {
			OR = {
				FROM = {
					trigger_if = {
						limit = { is_tribal = yes }
						ai = yes # AI can break the rules
					}
				}

				is_capital = no

				trigger_if = {
					limit = { is_coastal = yes }
					has_dlc = "The Republic"
				}
			}
		}

		trigger = {
			TECH_CITY_CONSTRUCTION >= 1
			TECH_TRADE_PRACTICES >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_town_hall_5 = {
		upgrades_from = tb_town_hall_4
		convert_to_city = ct_merchant_guild_1
		gold_cost = 114
		build_time = 2190
		ai_creation_factor = 200
		ai_feudal_modifier = -10
		ai_republic_modifier = 10
		extra_tech_building_start = 0.8

		tax_income = 0.5

		potential = {
			OR = {
				FROM = {
					trigger_if = {
						limit = { is_tribal = yes }
						ai = yes # AI can break the rules
					}
				}

				is_capital = no

				trigger_if = {
					limit = { is_coastal = yes }
					has_dlc = "The Republic"
				}
			}
		}

		trigger = {
			TECH_CITY_CONSTRUCTION >= 1
			TECH_TRADE_PRACTICES >= 1
			ai_can_build_trigger = yes
		}
	}

	# Town Center
	tb_town_market_1 = {
		convert_to_castle = ca_town_market_1
		convert_to_city = ct_town_market_1
		prestige_cost = 1
		build_time = 1
		ai_creation_factor = 200
		extra_tech_building_start = -1

		tax_income = 0.5

		add_number_to_name = no

		trigger = {
			OR = {
				TECH_CASTLE_CONSTRUCTION >= 0
				TECH_CITY_CONSTRUCTION >= 0
			}
		}
	}

	tb_town_market_2 = {
		upgrades_from = tb_town_market_1
		convert_to_castle = ca_town_market_2
		convert_to_city = ct_town_market_2
		prestige_cost = 400
		build_time = 547
		ai_creation_factor = 200
		extra_tech_building_start = 1.2

		tax_income = 0.5

		add_number_to_name = no

		trigger = {
			OR = {
				TECH_CASTLE_CONSTRUCTION >= 1
				TECH_CITY_CONSTRUCTION >= 1
			}
		}
	}

	# Housing
	tb_housing_1 = {
		convert_to_castle = ca_housing_1
		convert_to_city = ct_housing_1
		prestige_cost = 1
		build_time = 1
		ai_creation_factor = 200
		extra_tech_building_start = -1

		land_morale = 0.05
		levy_size = 0.025
		levy_reinforce_rate = 0.05
		light_infantry = 16
		archers = 12

		trigger = {
			TECH_CITY_CONSTRUCTION >= 0
		}
	}

	tb_housing_2 = {
		prerequisites = { tb_town_market_1 }
		upgrades_from = tb_housing_1
		convert_to_castle = ca_housing_2
		convert_to_city = ct_housing_2
		prestige_cost = 400
		build_time = 730
		ai_creation_factor = 200
		extra_tech_building_start = 1.4

		land_morale = 0.05
		levy_size = 0.025
		levy_reinforce_rate = 0.05
		light_infantry = 16
		archers = 12

		trigger = {
			OR = {
				TECH_CASTLE_CONSTRUCTION >= 1
				TECH_CITY_CONSTRUCTION >= 1
			}
		}
	}

	# Stable
	tb_stable_1 = {
		convert_to_castle = ca_stable_1
		convert_to_city = ct_stable_1
		prestige_cost = 200
		build_time = 365
		ai_creation_factor = 89
		extra_tech_building_start = 0.6

		light_cavalry = 46

		potential = {
			OR = {
				FROMFROM = { has_building = tb_stable_1 }

				AND = {
					TECH_CAVALRY >= 1

					FROMFROM = {
						has_building = tb_town_market_1
						has_building = tb_housing_1
					}
				}
			}
		}

		trigger = {
			TECH_CAVALRY >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_stable_2 = {
		upgrades_from = tb_stable_1
		convert_to_castle = ca_stable_2
		convert_to_city = ct_stable_2
		prestige_cost = 300
		build_time = 547
		ai_creation_factor = 88
		extra_tech_building_start = 1.2

		light_cavalry = 56

		trigger = {
			TECH_CAVALRY >= 1
			ai_can_build_trigger = yes
		}
	}

	# Desert Stable
	tb_desert_stable_1 = {
		replaces = tb_stable_1
		convert_to_castle = ca_desert_stable_1
		convert_to_city = ca_desert_stable_1
		prestige_cost = 200
		build_time = 365
		ai_creation_factor = 89
		extra_tech_building_start = 0.6

		camel_cavalry = 46

		potential = {
			terrain = desert

			OR = {
				FROMFROM = { has_building = tb_desert_stable_1 }

				AND = {
					TECH_CAVALRY >= 1

					FROMFROM = {
						has_building = tb_town_market_1
						has_building = tb_housing_1
					}
				}
			}
		}

		trigger = {
			TECH_CAVALRY >= 1
		}
	}

	tb_desert_stable_2 = {
		replaces = tb_stable_2
		upgrades_from = tb_desert_stable_1
		convert_to_castle = ca_desert_stable_2
		convert_to_city = ct_desert_stable_2
		prestige_cost = 300
		build_time = 547
		ai_creation_factor = 88
		extra_tech_building_start = 1.2

		camel_cavalry = 56

		potential = {
			terrain = desert
		}

		trigger = {
			TECH_CAVALRY >= 1
		}
	}

	# Steppe Stable
	tb_steppe_stable_1 = {
		replaces = tb_stable_1
		convert_to_castle = ca_steppe_stable_1
		convert_to_city = ct_steppe_stable_1
		prestige_cost = 200
		build_time = 365
		ai_creation_factor = 89
		extra_tech_building_start = 0.6

		light_cavalry = 32
		horse_archers = 14

		potential = {
			terrain = steppe

			OR = {
				FROMFROM = { has_building = tb_steppe_stable_1 }

				AND = {
					TECH_CAVALRY >= 1

					FROMFROM = {
						has_building = tb_town_market_1
						has_building = tb_housing_1
					}
				}
			}
		}

		trigger = {
			TECH_CAVALRY >= 1
		}
	}

	tb_steppe_stable_2 = {
		replaces = tb_stable_2
		upgrades_from = tb_steppe_stable_1
		convert_to_castle = ca_steppe_stable_2
		convert_to_city = ct_steppe_stable_2
		prestige_cost = 300
		build_time = 547
		ai_creation_factor = 88
		extra_tech_building_start = 1.2

		light_cavalry = 42
		horse_archers = 24

		potential = {
			terrain = steppe
		}

		trigger = {
			TECH_CAVALRY >= 1
		}
	}

	# City Wall
	tb_wall_1 = {
		convert_to_castle = ca_wall_1
		convert_to_city = ct_wall_1
		prestige_cost = 200
		build_time = 365
		ai_creation_factor = 90
		extra_tech_building_start = 1.2

		fort_level = 1

		potential = {
			OR = {
				FROMFROM = { has_building = tb_wall_1 }

				AND = {
					TECH_FORTIFICATIONS_CONSTRUCTION >= 1

					FROMFROM = {
						has_building = tb_town_market_1
						has_building = tb_housing_1
					}
				}
			}
		}

		trigger = {
			TECH_FORTIFICATIONS_CONSTRUCTION >= 1
		}
	}

	tb_wall_2 = {
		upgrades_from = tb_wall_1
		convert_to_castle = ca_wall_2
		convert_to_city = ct_wall_2
		prestige_cost = 300
		build_time = 547 #1.5y
		ai_creation_factor = 89
		extra_tech_building_start = 0.6

		fort_level = 0.75

		trigger = {
			TECH_FORTIFICATIONS_CONSTRUCTION >= 2
		}
	}

	# Militia
	tb_militia_1 = {
		convert_to_castle = ca_militia_1
		convert_to_city = ct_militia_1
		prestige_cost = 200
		build_time = 365
		ai_creation_factor = 100
		extra_tech_building_start = 1.2

		light_infantry = 50
		archers = 100

		potential = {
			FROMFROM = {
				OR = {
					has_building = tb_militia_1

					AND = {
						has_building = tb_town_market_1
						has_building = tb_housing_1
					}
				}
			}
		}

		trigger = {
			TECH_LIGHT_INFANTRY >= 0
		}
	}

	tb_militia_2 = {
		upgrades_from = tb_militia_1
		convert_to_castle = ca_militia_2
		convert_to_city = ct_militia_2
		prestige_cost = 300
		build_time = 547
		ai_creation_factor = 98
		extra_tech_building_start = 1.2

		light_infantry = 50
		archers = 100

		trigger = {
			TECH_LIGHT_INFANTRY >= 1
		}
	}

	# Navy
	tb_shipyard_1 = {
		convert_to_castle = ca_shipyard_1
		convert_to_city = ct_shipyard_1
		prestige_cost = 200
		build_time = 365
		ai_creation_factor = 85
		extra_tech_building_start = 0.5

		galleys = 10

		port = yes

		potential = {
			OR = {
				FROMFROM = { has_building = tb_shipyard_1 }

				AND = {
					TECH_NAVAL >= 1

					FROMFROM = {
						has_building = tb_town_market_1
						has_building = tb_housing_1
					}
				}
			}
		}

		trigger = {
			TECH_NAVAL >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_shipyard_2 = {
		upgrades_from = tb_shipyard_1
		convert_to_castle = ca_shipyard_2
		convert_to_city = ct_shipyard_2
		prestige_cost = 300
		build_time = 730
		ai_creation_factor = 85
		extra_tech_building_start = 0.7

		galleys = 5

		port = yes

		trigger = {
			TECH_NAVAL >= 2
		}
	}

	# Trade
	tb_port_1 = {
		convert_to_castle = ca_port_1
		convert_to_city = ct_port_1
		prestige_cost = 200
		build_time = 365
		ai_creation_factor = 130
		extra_tech_building_start = 0

		tax_income = 0.5

		port = yes

		potential = {
			OR = {
				FROMFROM = { has_building = tb_port_1 }

				AND = {
					TECH_TRADE_PRACTICES >= 1
					TECH_NAVAL >= 1

					FROMFROM = {
						has_building = tb_town_market_1
						has_building = tb_housing_1
					}
				}
			}
		}

		trigger = {
			TECH_TRADE_PRACTICES >= 1
			TECH_NAVAL >= 1
			ai_can_build_trigger = yes
		}
	}

	tb_port_2 = {
		upgrades_from = tb_port_1
		convert_to_castle = ca_port_2
		convert_to_city = ct_port_2
		prestige_cost = 300
		build_time = 547
		ai_creation_factor = 130
		extra_tech_building_start = 0.6

		tax_income = 0.5

		port = yes

		trigger = {
			TECH_TRADE_PRACTICES >= 3
			ai_can_build_trigger = yes
		}
	}
}