﻿# Phase 6: Cultural Projects

ve_has_active_cultural_project = {
	has_variable = ve_cultural_project_type
	var:ve_cultural_project_type > 0
}

# Reading var:ve_cultural_project_type without this guard throws a script error
# every time it is evaluated while no project runs, and the country panel
# evaluates the project name/description for every country it draws.
ve_cultural_project_type_is = {
	has_variable = ve_cultural_project_type
	var:ve_cultural_project_type == $TYPE$
}

ve_has_no_active_cultural_project = {
	NOT = { ve_has_active_cultural_project = yes }
}

# Mirrors ve_religious_project_target_state_check in ve_religious_state_triggers.txt.
# `var:ve_cultural_project_target_state ?= { <state-only trigger> }` fails
# Jomini's static scope validation (logged as "Wrong scope for trigger: country,
# expected state") even though the variable holds a valid state at runtime;
# routing through a saved scope sidesteps it. Pass the state-only check as CHECK.
ve_cultural_project_target_state_check = {
	AND = {
		var:ve_cultural_project_target_state ?= {
			save_scope_as = ve_cultural_project_target_state_check_scope
		}
		scope:ve_cultural_project_target_state_check_scope ?= {
			$CHECK$
		}
	}
}

ve_can_begin_cultural_project = {
	ve_has_no_active_cultural_project = yes
	NOT = { has_modifier = ve_cultural_project_backlash_mdf }
	# Avoid rebinding a JE that is still resolving the previous project.
	NOT = { has_journal_entry = ve_je_cultural_project }
}

ve_can_begin_national_curriculum = {
	ve_can_begin_cultural_project = yes
	# A completed countrywide project cannot be renewed while its existing
	# implementation benefit is still in force.
	NOT = { has_modifier = ve_national_curriculum_result_mdf }
	# Use the actual spendable stock so the project button and alerts cannot
	# disagree because of a derived script-value evaluation.
	var:culture_reform_point >= 100
}

ve_can_begin_shared_symbols = {
	ve_can_begin_cultural_project = yes
	NOT = { has_modifier = ve_shared_symbols_result_mdf }
	var:culture_reform_point >= 75
}

ve_can_begin_ethnic_campaign = {
	ve_can_begin_cultural_project = yes
	ve_is_ethnic_identity = yes
	var:culture_reform_point >= 125
}

ve_can_begin_civic_initiative = {
	ve_can_begin_cultural_project = yes
	ve_is_civic_identity = yes
	var:culture_reform_point >= 100
}

ve_can_begin_composite_compact = {
	ve_can_begin_cultural_project = yes
	ve_is_composite_identity = yes
	var:culture_reform_point >= 150
	var:ve_national_cohesion >= 40
}

ve_can_begin_model_project = {
	OR = {
		ve_can_begin_ethnic_campaign = yes
		ve_can_begin_civic_initiative = yes
		ve_can_begin_composite_compact = yes
	}
}

# Scope: state
# Deliberately prev-relative, never ROOT-relative: the alert path reaches this
# through a country-scope trigger's any_scope_state, where ROOT is still the
# country. Reading culture_percent_state off that ROOT logged a "wrong scope"
# script error for every state of every evaluation.
ve_state_has_cultural_project_target = {
	owner = {
		OR = {
			ve_can_begin_ethnic_campaign = yes
			ve_can_begin_civic_initiative = yes
			ve_can_begin_composite_compact = yes
		}
	}
	any_scope_culture = {
		NOT = { is_primary_culture_of = prev.owner }
		prev = {
			NOT = {
				is_target_in_variable_list = {
					name = ve_completed_cultural_project_cultures
					target = prev
				}
			}
		}
		prev = {
			culture_percent_state = {
				target = prev
				value >= 0.05
			}
		}
		OR = {
			prev.owner = {
				NOT = { ve_is_composite_identity = yes }
			}
			prev.owner = {
				NOT = {
					is_target_in_variable_list = {
						name = ve_recognized_constituent_cultures
						target = prev
					}
				}
			}
		}
	}
}

ve_project_is_countrywide = {
	OR = {
		ve_cultural_project_type_is = { TYPE = 1 }
		ve_cultural_project_type_is = { TYPE = 2 }
	}
}

ve_project_is_targeted = {
	OR = {
		ve_cultural_project_type_is = { TYPE = 3 }
		ve_cultural_project_type_is = { TYPE = 4 }
		ve_cultural_project_type_is = { TYPE = 5 }
	}
}

# Just the Cultural Mandate threshold (+ cohesion floor for Composite) for the
# active identity model, without the base no-active-project/backlash checks -
# used to itemize the "why is this disabled" tooltip on the state button
# instead of one flat requirements line.
ve_country_meets_cultural_project_cost = {
	OR = {
		AND = {
			ve_is_ethnic_identity = yes
			var:culture_reform_point >= 125
		}
		AND = {
			ve_is_civic_identity = yes
			var:culture_reform_point >= 100
		}
		AND = {
			ve_is_composite_identity = yes
			var:culture_reform_point >= 150
			var:ve_national_cohesion >= 40
		}
	}
}

# Scope: state. Just the "is there an eligible non-primary culture here"
# check from ve_state_has_cultural_project_target, without the owner
# affordability check - the itemized tooltip checks that separately.
ve_state_has_eligible_target_culture = {
	any_scope_culture = {
		NOT = { is_primary_culture_of = prev.owner }
		prev = {
			NOT = {
				is_target_in_variable_list = {
					name = ve_completed_cultural_project_cultures
					target = prev
				}
			}
		}
		prev = {
			culture_percent_state = {
				target = prev
				value >= 0.05
			}
		}
		OR = {
			prev.owner = {
				NOT = { ve_is_composite_identity = yes }
			}
			prev.owner = {
				NOT = {
					is_target_in_variable_list = {
						name = ve_recognized_constituent_cultures
						target = prev
					}
				}
			}
		}
	}
}

# Scope: state. Is this state the one the owner's active project is running
# against? Used to show a live progress bar directly on the state panel.
ve_state_is_active_cultural_project_target = {
	save_temporary_scope_as = ve_check_state
	owner = {
		ve_has_active_cultural_project = yes
		var:ve_cultural_project_target_state ?= {
			this = scope:ve_check_state
		}
	}
}

ve_has_cultural_movement_pressure = {
	any_political_movement = {
		OR = {
			is_political_movement_type = movement_cultural_minority
			is_political_movement_type = movement_cultural_majority
		}
		political_movement_radicalism >= 0.25
	}
}
