﻿INJECT:building_government_administration = {
	ai_value = {
		# KAI: Excess bureaucracy should have lower priority than everything else
		value = 0

		if = { # Bureaucratic Reform agenda - only the agenda's target states, while they still lack tax capacity
			limit = {
				owner ?= {
					has_journal_entry = je_tp_pool_bureaucratic_reform
					is_target_in_variable_list = {
						name = tp_bureaucratic_reform_states
						target = prev
					}
				}
				tax_capacity < tax_capacity_usage
			}
			add = 1000
		}

		# KAI: Prioritize states with insufficient tax capacity
		if = {
			limit = {
				is_incorporated = yes
			}
			# States that can use more bureaucracy
			add = {
				value = 10
				multiply = {
					# Scale inversely with surplus from -45 to 5
					value = tax_capacity_usage
					subtract = tax_capacity
					add = 5
				}
				min = 0
				max = 500
			}
			# States that can REALLY use more bureaucracy
			add = {
				value = 250
				multiply = tax_capacity_usage
				divide = {
					value = tax_capacity
					min = 100
				}
				min = 0
				max = 500
			}
		}
	}
}

INJECT:building_university = {
	ai_value = {
		value = 2000 # Higher base value

		if = { # British dictates
			limit = {
				owner = {
					has_journal_entry = je_british_dictate_universities
				}
				OR = {
					state_region = s:STATE_WEST_BENGAL
					state_region = s:STATE_BOMBAY
					state_region = s:STATE_MADRAS
				}
				NOR = {
					has_building = building_university
					any_scope_building = {
						is_building_type = building_university
						level > 3
					}
				}
			}
			add = 2000
		}
		
		if = { # Taming the North
			limit = {
				owner = {
					has_journal_entry = je_taming_the_north
				}
				state_region = s:STATE_HOKKAIDO
				NOT = {
					has_building = building_university
				}
			}
			add = 10000
		}

		if = { # Educational Reform agenda - only while innovation is below cap
			limit = {
				owner = {
					has_journal_entry = je_tp_pool_educational_reform
					country_innovation < max_innovation
				}
			}
			add = 2000
		}

		if = {
			limit = {
				OR = {
					AND = {
						owner ?= { has_variable = ai_ukraine_renaissance_accelerate }
						state_region = { is_homeland = cu:ukrainian }
					}
					AND = {
						owner ?= { has_variable = ai_belarus_renaissance_accelerate }
						state_region = { is_homeland = cu:byelorussian }
					}
				}
			}
			add = 1000
		}

		if = {
			limit = {
				has_building = building_university
				owner ?= {
					has_variable = ai_poland_white
					has_journal_entry = je_congress_poland
					NOT = { has_variable = poland_university_requirement_met_var }
				}
			}
			add = 1000
		}

		# KAI: For whatever reason, when innovation is below the innovation cap, it is considered critical
		# Slashing the building score until a better solution is found
		if = {
			limit = {
				owner ?= {
					country_innovation < max_innovation
				}
			}
			subtract = 1250
			divide = define:NAI|MONEY_SPENDING_BELOW_CRITICAL_THRESHOLD_MULTIPLIER
		}
	}
}

INJECT:building_construction_sector = {
	ai_value = {
		value = 1000

		# KAI: Prefer states with iron
		if = {
			limit = {
				state_population >= 250000
				has_potential_resource = building_iron_mine
			}
			add = 500
		}
	}
}

INJECT:building_power_bloc_statue = {
	ai_value = {
		value = 0

		if = {
			limit = {
				is_incorporated = yes
				state_population >= 500000
			}

			add = {
				value = state_population
				divide = 2500
				max = 5000
			}
		}

		if = {
			limit = { is_capital = yes }
			add = 2500
		}

		owner = {
			if = {
				limit = { is_power_bloc_leader = yes }
				multiply = 2.0
			}

			if = {
				limit = { country_rank < rank_value:major_power }
				multiply = 0.0
			}
			else_if = {
				limit = { country_rank < rank_value:great_power }
				multiply = 0.5
			}
		}

		if = {
			limit = {
				not = { has_game_rule = allow_monument_effects }
			}
			multiply = 0
		}
	}
}
