﻿piety_value = {
	add = var:piety_bar_point
}

ve_religious_state_value = {
	add = var:piety_bar_point
}

ve_national_insight_value = {
	add = var:idea_point_pool
}

# Player-facing doctrine-capacity readouts. Capacity itself is mutated by
# ve_update_idea_group_capacity; these values only explain the next milestone.
ve_idea_group_free_slots = {
	add = var:idea_group_cap
	subtract = var:idea_group_unlocked
	min = 0
	max = 7
	round = yes
}

ve_next_idea_group_slot = {
	add = var:idea_group_cap
	add = 1
	min = 2
	max = 7
	round = yes
}

ve_next_idea_group_capacity_threshold = {
	if = {
		limit = { var:idea_group_cap < 2 }
		value = 4
	}
	else_if = {
		limit = { var:idea_group_cap < 3 }
		value = 8
	}
	else_if = {
		limit = { var:idea_group_cap < 4 }
		value = 13
	}
	else_if = {
		limit = { var:idea_group_cap < 5 }
		value = 19
	}
	else_if = {
		limit = { var:idea_group_cap < 6 }
		value = 26
	}
	else = {
		value = 34
	}
}

ve_idea_group_capacity_remaining = {
	add = ve_next_idea_group_capacity_threshold
	subtract = var:ve_idea_capacity_progress
	min = 0
	max = 34
	round = yes
}

culture_reform_point_value = {
	add = var:culture_reform_point
}

ve_national_identity_value = {
	add = var:culture_reform_point
}

splender_points_value = {
	add = var:ve_splender_points
}

ve_era_momentum_value = {
	add = var:ve_splender_points
}

# Phase 1 compatibility values. GUI and update effects should migrate to these
# stable names before the underlying legacy formulas and variables are replaced.

ve_national_insight_base = 6

ve_national_insight_literacy = {
	if = {
		limit = { literacy_rate < 0.25 }
		add = 1
	}
	else_if = {
		limit = { literacy_rate < 0.50 }
		add = 2
	}
	else_if = {
		limit = { literacy_rate < 0.75 }
		add = 3
	}
	else = {
		add = 4
	}
}

ve_national_insight_education = {
	if = {
		limit = {
			institution_investment_level = {
				institution = institution_schools
				value >= 5
			}
		}
		add = 3
	}
	else_if = {
		limit = {
			institution_investment_level = {
				institution = institution_schools
				value >= 3
			}
		}
		add = 2
	}
	else_if = {
		limit = {
			institution_investment_level = {
				institution = institution_schools
				value >= 1
			}
		}
		add = 1
	}
}

# University requirements scale in broad population bands. This rewards
# educational capacity without making raw country size the dominant input.
ve_national_insight_universities = {
	if = {
		limit = { total_population < 5000000 }
		if = {
			limit = {
				country_has_building_type_levels = {
					target = bt:building_university
					value >= 3
				}
			}
			add = 2
		}
		else_if = {
			limit = {
				country_has_building_type_levels = {
					target = bt:building_university
					value >= 1
				}
			}
			add = 1
		}
	}
	else_if = {
		limit = { total_population < 20000000 }
		if = {
			limit = {
				country_has_building_type_levels = {
					target = bt:building_university
					value >= 5
				}
			}
			add = 2
		}
		else_if = {
			limit = {
				country_has_building_type_levels = {
					target = bt:building_university
					value >= 2
				}
			}
			add = 1
		}
	}
	else_if = {
		limit = { total_population < 50000000 }
		if = {
			limit = {
				country_has_building_type_levels = {
					target = bt:building_university
					value >= 10
				}
			}
			add = 2
		}
		else_if = {
			limit = {
				country_has_building_type_levels = {
					target = bt:building_university
					value >= 5
				}
			}
			add = 1
		}
	}
	else = {
		if = {
			limit = {
				country_has_building_type_levels = {
					target = bt:building_university
					value >= 20
				}
			}
			add = 2
		}
		else_if = {
			limit = {
				country_has_building_type_levels = {
					target = bt:building_university
					value >= 10
				}
			}
			add = 1
		}
	}
}

ve_national_insight_administration = {
	if = {
		limit = {
			bureaucracy >= 0
			approaching_bureaucracy_shortage = no
		}
		add = 1
	}
	else = {
		subtract = 2
	}
}

ve_national_insight_legitimacy = {
	if = {
		limit = { government_legitimacy >= 75 }
		add = 2
	}
	else_if = {
		limit = { government_legitimacy >= 50 }
		add = 1
	}
	else_if = {
		limit = { government_legitimacy < 25 }
		subtract = 2
	}
	else = {
		subtract = 1
	}
}

ve_national_insight_intelligentsia = {
	if = {
		limit = {
			ig:ig_intelligentsia = { ig_approval >= 5 }
		}
		add = 1
	}
	else_if = {
		limit = {
			ig:ig_intelligentsia = { ig_approval <= -5 }
		}
		subtract = 1
	}
}

ve_national_insight_stability = {
	if = {
		limit = { taking_loans = yes }
		subtract = 1
	}
	if = {
		limit = { country_turmoil >= 0.25 }
		subtract = 2
	}
	else_if = {
		limit = { country_turmoil >= 0.10 }
		subtract = 1
	}
	if = {
		limit = {
			has_modifier = ve_national_insight_implementation_strain
		}
		subtract = 2
	}
}

ve_national_insight_cap_multiplier = {
	if = {
		limit = { var:idea_point_pool >= 1000 }
		value = 0
	}
	else_if = {
		limit = { var:idea_point_pool >= 900 }
		value = 0.25
	}
	else_if = {
		limit = { var:idea_point_pool >= 750 }
		value = 0.50
	}
	else = {
		value = 1
	}
}

ve_monthly_national_insight = {
	add = ve_national_insight_base
	add = ve_national_insight_literacy
	add = ve_national_insight_education
	add = ve_national_insight_universities
	add = ve_national_insight_administration
	add = ve_national_insight_legitimacy
	add = ve_national_insight_intelligentsia
	add = ve_national_insight_stability
	min = 2
	max = 18
	multiply = ve_national_insight_cap_multiplier
	round = yes
}


ve_monthly_era_momentum = {
	add = ve_era_objectives_satisfied
	add = ve_era_momentum_idea_bonus
}




ve_set_citizenship_law_effects = {
	if = {
		limit = {
			has_law = law_type:law_ethnostate
		}
		add = 4
	}
	else_if = {
		limit = {
			has_law = law_type:law_national_supremacy
		}
		add = 3
	}
	else_if = {
		limit = {
			has_law = law_type:law_racial_segregation
		}
		add = 2
	}
	else_if = {
		limit = {
			has_law = law_type:law_cultural_exclusion
		}
		add = 1
	}
	else_if = {
		limit = {
			has_law = law_type:law_multicultural
		}
		add = 0
	}
}

ve_change_religion_law_effects = {
	if = {
		limit = {
			has_law = law_type:law_state_religion
		}
		value = 3
	}
	else_if = {
		limit = {
			has_law = law_type:law_freedom_of_conscience
		}
		value = 1
	}
	else_if = {
		limit = {
			has_law = law_type:law_state_atheism
		}
		value = 3
	}
	else_if = {
		limit = {
			has_law = law_type:law_total_separation
		}
		value = 0
	}
}

ve_change_citizenship_law_effects = {
	if = {
		limit = {
			has_law = law_type:law_ethnostate
		}
		value = 4
	}
	else_if = {
		limit = {
			has_law = law_type:law_national_supremacy
		}
		value = 3
	}
	else_if = {
		limit = {
			has_law = law_type:law_racial_segregation
		}
		value = 2
	}
	else_if = {
		limit = {
			has_law = law_type:law_cultural_exclusion
		}
		value = 1
	}
	else_if = {
		limit = {
			has_law = law_type:law_multicultural
		}
		value = 0
	}
}
