# Comprehensive Sandbox Control - core scripted effects
#
# Initialization and no-op adapter hooks. Hooks are intentionally empty in the
# core; adapters extend behavior by adding their own csc_adapter_<mod>_* files
# and by setting csc_cap_* state inside csc_hook_register_capabilities. Adapters
# must never edit this file (see docs/adapter-contract.md).

# Runs once per game via on_startup. Idempotent: guarded by a global flag so a
# save/reload or repeated call sets defaults only when CSC has not initialized.
csc_initialize_defaults = {
	if = {
		limit = { NOT = { has_global_flag = csc_initialized } }
		set_global_flag = csc_initialized
		csc_hook_on_init = yes
		csc_hook_register_capabilities = yes

		# Default the shared State Resources increment selector to 1.
		set_variable = { global.csc_resource_step = 1 }

		# Overhaul detection is live via csc_detect_* triggers (see
		# csc_adapter_detection.txt); no startup resource heuristic is needed.
	}
}

# Runs at startup/load. AI countries must not retain CSC buff ideas or saved
# control state from older saves.
csc_cleanup_ai_access_state = {
	every_country = {
		limit = { is_ai = yes }

		remove_ideas = {
			csc_buff_politics_off
			csc_buff_politics_low
			csc_buff_politics_medium
			csc_buff_politics_high
			csc_buff_politics_extreme
			csc_buff_diplomacy_off
			csc_buff_diplomacy_low
			csc_buff_diplomacy_medium
			csc_buff_diplomacy_high
			csc_buff_diplomacy_extreme
			csc_buff_research_off
			csc_buff_research_low
			csc_buff_research_medium
			csc_buff_research_high
			csc_buff_research_extreme
			csc_buff_construction_off
			csc_buff_construction_low
			csc_buff_construction_medium
			csc_buff_construction_high
			csc_buff_construction_extreme
			csc_buff_production_off
			csc_buff_production_low
			csc_buff_production_medium
			csc_buff_production_high
			csc_buff_production_extreme
			csc_buff_manpower_off
			csc_buff_manpower_low
			csc_buff_manpower_medium
			csc_buff_manpower_high
			csc_buff_manpower_extreme
			csc_buff_army_off
			csc_buff_army_low
			csc_buff_army_medium
			csc_buff_army_high
			csc_buff_army_extreme
			csc_buff_navy_off
			csc_buff_navy_low
			csc_buff_navy_medium
			csc_buff_navy_high
			csc_buff_navy_extreme
			csc_buff_air_off
			csc_buff_air_low
			csc_buff_air_medium
			csc_buff_air_high
			csc_buff_air_extreme
			csc_buff_training_off
			csc_buff_training_low
			csc_buff_training_medium
			csc_buff_training_high
			csc_buff_training_extreme
			csc_buff_special_forces_off
			csc_buff_special_forces_low
			csc_buff_special_forces_medium
			csc_buff_special_forces_high
			csc_buff_special_forces_extreme
			csc_buff_intel_off
			csc_buff_intel_low
			csc_buff_intel_medium
			csc_buff_intel_high
			csc_buff_intel_extreme
		}

		clr_country_flag = csc_cheats_shown
		clr_country_flag = csc_state_sandbox_open
		clr_country_flag = csc_state_resources_tab_active
		clr_country_flag = csc_country_sandbox_open
		clr_country_flag = csc_confirmation_pending
		clr_country_flag = csc_consent_request_pending
		clr_country_flag = csc_pending_action_transfer_owner
		clr_country_flag = csc_pending_action_transfer_controller
		clr_country_flag = csc_pending_action_add_core
		clr_country_flag = csc_pending_action_remove_core
		clr_country_flag = csc_pending_action_add_claim
		clr_country_flag = csc_pending_action_remove_claim
		clr_country_flag = csc_pending_action_move_capital
		clr_country_flag = csc_pending_action_build_slots
		clr_country_flag = csc_pending_action_repair_buildings
		clr_country_flag = csc_pending_action_give_resource_rights
		clr_country_flag = csc_pending_action_remove_resource_rights
		clr_country_flag = csc_pending_action_annex
		clr_country_flag = csc_pending_action_puppet
		clr_country_flag = csc_pending_action_release_subject
		clr_country_flag = csc_pending_action_grant_independence
		clr_country_flag = csc_pending_action_set_autonomy
		clr_country_flag = csc_pending_action_white_peace
		clr_country_flag = csc_pending_action_faction_invite
		clr_country_flag = csc_pending_action_faction_remove
		clr_country_flag = csc_pending_action_leave_faction
		clr_country_flag = csc_pending_action_create_faction
		clr_country_flag = csc_pending_action_dismantle_faction
		clr_country_flag = csc_pending_action_set_faction_leader
		clear_array = csc_marked_states_array
		clear_variable = csc_marked_count
	}
}

# --- adapter hooks (no-op defaults) ---

# One-time adapter setup at game start.
csc_hook_on_init = {
}

# Adapters set csc_cap_* flags/variables for detected overhaul systems here.
csc_hook_register_capabilities = {
}

# Adapters translate a generic "add currency" request to the overhaul's own
# public effect. Core default does nothing.
csc_hook_adjust_currency = {
	# Route a generic "add currency" request (the temp variable
	# csc_currency_delta, set by the caller) to the detected overhaul's
	# parse-safe money store. Append-only dispatch: a new currency overhaul adds
	# one branch; existing branches stay untouched. Every path uses a VARIABLE
	# (parse-safe in vanilla) -- never OWB's add_caps effect, whose token errors
	# when OWB is absent.
	if = {
		limit = { csc_detect_md = yes }
		add_to_variable = { treasury = csc_currency_delta }
	}
	else_if = {
		limit = { csc_detect_owb = yes }
		add_to_variable = { caps_number_display = csc_currency_delta }
	}
}

# Adapters route state-resource operations through overhaul-specific systems.
# Core default does nothing; the generic core uses vanilla add_resource directly.
csc_hook_adjust_state_resource = {
}

# Adapters add overhaul-specific sandbox state actions.
csc_hook_extra_state_actions = {
}

# Adapters add overhaul-specific sandbox country actions.
csc_hook_extra_country_actions = {
}
