﻿# ================= TAWN_HOLL (6 уровней замены) =================
town_holl_1_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
town_holl_2_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
town_holl_3_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
town_holl_4_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
town_holl_5_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
town_holl_6_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }

# ================= TRADE_CENTR (6 уровней замены) =================
trade_centr_1_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
trade_centr_2_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
trade_centr_3_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
trade_centr_4_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
trade_centr_5_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }
trade_centr_6_max_level = { add = { desc = "BUILDING_LEVEL_BASE" value = 1 } }

# ================= INFRASTRUCTURE (Оригинальная схема: стак по dev/pop) =================
infrastructure_max_level = {
	add = { desc = "BUILDING_LEVEL_BASE" value = 1 }
	add = { desc = "BUILDING_LEVEL_DEVELOPMENT" value = development multiply = 0.1 }
	add = { desc = "BUILDING_LEVEL_POPULATION" value = population multiply = 0.05 }
	if = {
		limit = { location_rank ?= location_rank:city }
		add = { desc = "BUILDING_LEVEL_IS_CITY" value = 1 }
		if = { limit = { is_capital = yes } add = { desc = "is_capital" value = 1 } }
	}
}

Proximity_house_max_level = {
	if = {
		limit = {
			current_age_or_later = { age = age_1_traditions }
		}
		add = {
			desc = "age_1_traditions"
			value = 1
		}
	}
	if = {
		limit = {
			current_age_or_later = { age = age_2_renaissance }
		}
		add = {
			desc = "age_2_renaissance"
			value = 1
		}
	}
	if = {
		limit = {
			current_age_or_later = { age = age_3_discovery }
		}
		add = {
			desc = "age_3_discovery"
			value = 1
		}
	}
	if = {
		limit = {
			current_age_or_later = { age = age_4_reformation }
		}
		add = {
			desc = "age_4_reformation"
			value = 1
		}
	}
	if = {
		limit = {
			current_age_or_later = { age = age_5_absolutism }
		}
		add = {
			desc = "age_5_absolutism"
			value = 1
		}
	}
	if = {
		limit = {
			current_age_or_later = { age = age_6_revolutions }
		}
		add = {
			desc = "age_6_revolutions"
			value = 1
		}
	}
}

# ================= CAPITOL (3 уровня, только в столице) =================

capitol_max_level = {
	add = { desc = "BUILDING_LEVEL_BASE" value = 1 }
	
	# Герцогства получают +1 уровень (итого 2)
	if = {
		limit = {
			owner = { 
				OR = {
					country_rank = country_rank:rank_duchy
					country_rank = country_rank:rank_kingdom
					country_rank = country_rank:rank_empire
				}
			}
		}
		add = { desc = "country_rank:rank_duchy" value = 1 }
	}	
	
	# Королевства И Империи получают +1 уровень
	if = {
		limit = {
			owner = { 
				OR = {
					country_rank = country_rank:rank_kingdom
					country_rank = country_rank:rank_empire
				}
			}
		}
		add = { desc = "country_rank:rank_kingdom" value = 1 }
	}
	
	# Королевства и Империи с достаточным населением получают +1 уровень
	if = {
		limit = {
			owner = { 
				OR = {
					country_rank = country_rank:rank_kingdom
					country_rank = country_rank:rank_empire
				}
				OR = {
					total_population > 15000
					total_true_faith_population > 7500
					total_accepted_culture_population > 5000
				}
			}
		}
		add = { desc = "BUILDING_LEVEL_POPULATION_BONUS" value = 1 }
	}
	
	# Только Империи получают +1 уровень
	if = {
		limit = {
			owner = { country_rank = country_rank:rank_empire }
		}
		add = { desc = "country_rank:rank_empire" value = 1 }
	}
	
	# Только Империи с достаточным населением получают +1 уровень
	if = {
		limit = {
			owner = { 
				country_rank = country_rank:rank_empire
				OR = {
					total_population > 20000
					total_true_faith_population > 10000
					total_accepted_culture_population > 7500
				}
			}
		}
		add = { desc = "BUILDING_LEVEL_POPULATION_BONUS" value = 1 }
	}
}


guild_max_level = {
	add = {
		desc = "BUILDING_LEVEL_DEVELOPMENT"
		value = development
		multiply = 0.1
	}
	add = {
		desc = "BUILDING_LEVEL_POPULATION"
		value = population
		multiply = 0.05
	}
	if = {
		limit = {
			location_rank ?= location_rank:city
		}
		add = {
			desc = "BUILDING_LEVEL_IS_CITY"
			value = 1.0
		}
	}
	if = {
		limit = {
			location_rank ?= location_rank:megalopolis
		}
		add = {
			desc = "BUILDING_LEVEL_IS_MEGAPOLIS"
			value = 5
		}
	}

	if = {
		limit = { market_access < 0.75 }
		multiply = {
			desc = "BUILDING_LEVEL_LOW_MARKET_ACCESS_PENALTY"
			value = market_access
			add = 0.25
		}
	}
	min = 1
}

workshop_max_level = {
	add = {
		desc = "BUILDING_LEVEL_DEVELOPMENT"
		value = development
		multiply = 0.15
	}
	add = {
		desc = "BUILDING_LEVEL_POPULATION"
		value = population
		multiply = 0.075
	}
	if = {
		limit = {
			location_rank = location_rank:city
		}
		add = {
			desc = "BUILDING_LEVEL_IS_CITY"
			value = 2.5
		}
	}
	if = {
		limit = {
			location_rank ?= location_rank:megalopolis
		}
		add = {
			desc = "BUILDING_LEVEL_IS_MEGAPOLIS"
			value = 5
		}
	}
	if = {
		limit = { market_access < 0.75 }
		multiply = {
			desc = "BUILDING_LEVEL_LOW_MARKET_ACCESS_PENALTY"
			value = market_access
			add = 0.25
		}
	}
	min = 1
}


manufactory_max_level = {
	add = {
		desc = "BUILDING_LEVEL_DEVELOPMENT"
		value = development
		multiply = 0.20
	}
	add = {
		desc = "BUILDING_LEVEL_POPULATION"
		value = population
		multiply = 0.1
	}
	if = {
		limit = {
			location_rank = location_rank:city
		}
		add = {
			desc = "BUILDING_LEVEL_IS_CITY"
			value = 5
		}
	}

	if = {
		limit = {
			location_rank ?= location_rank:megalopolis
		}
		add = {
			desc = "BUILDING_LEVEL_IS_MEGAPOLIS"
			value = 10
		}
	}
	if = {
		limit = { market_access < 0.75 }
		multiply = {
			desc = "BUILDING_LEVEL_LOW_MARKET_ACCESS_PENALTY"
			value = market_access
			add = 0.25
		}
	}
	min = 1

}

mills_max_level = {
	add = {
		desc = "BUILDING_LEVEL_DEVELOPMENT"
		value = development
		multiply = 0.30
	}
	add = {
		desc = "BUILDING_LEVEL_POPULATION"
		value = population
		multiply = 0.15
	}
	if = {
		limit = {
			location_rank = location_rank:city
		}
		add = {
			desc = "BUILDING_LEVEL_IS_CITY"
			value = 10
		}
	}

	if = {
		limit = {
			location_rank ?= location_rank:megalopolis
		}
		add = {
			desc = "BUILDING_LEVEL_IS_MEGAPOLIS"
			value = 25
		}
	}
	if = {
		limit = { market_access < 0.75 }
		multiply = {
			desc = "BUILDING_LEVEL_LOW_MARKET_ACCESS_PENALTY"
			value = market_access
			add = 0.25
		}
	}
	min = 1

}


# ================= CAPITOL TIER 2 / 3 (unlocked by later ages) =================
capitol_2_max_level = {
        add = { desc = "BUILDING_LEVEL_BASE" value = 1 }
        if = {
                limit = { owner = { country_rank = country_rank:rank_kingdom } }
                add = { desc = "country_rank:rank_kingdom" value = 1 }
                limit = {
                        owner = {
                                country_rank = country_rank:rank_empire
                                OR = {
                                        total_population > 50000
                                        total_true_faith_population > 10000
                                }
                        }
                }
        }
        if = {
                limit = { owner = { country_rank = country_rank:rank_empire } }
                add = { desc = "country_rank:rank_empire" value = 1 }
        }
}

capitol_3_max_level = {
        add = { desc = "BUILDING_LEVEL_BASE" value = 1 }
        if = {
                limit = { owner = { country_rank = country_rank:rank_empire } }
                add = { desc = "country_rank:rank_empire" value = 1 }
        }
        if = {
                limit = {
                        owner = {
                                country_rank = country_rank:rank_empire
                                OR = {
                                        total_population > 75000
                                        total_true_faith_population > 30000
                                }
                        }
                }
                add = { desc = "BUILDING_LEVEL_POPULATION_BONUS" value = 1 }
        }
}
