###########################
# Hot-Swap Augments (ap_hot_swap_augments)
###########################
namespace = apb_augments

# Worn In check, 3600 days after a frame was fitted (scheduled by apb_augments_fit_frame).
# apb_augment_start is the day of the LATEST fitting. A new fitting is only possible
# 720 days after the previous one, so a timer left from an earlier fitting always
# sees fewer than 2900 days here and does nothing.
country_event = {
	id = apb_augments.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_hot_swap_augments
		is_variable_set = apb_augment_start
		OR = {
			has_edict = apb_augments_labour
			has_edict = apb_augments_combat
			has_edict = apb_augments_research
		}
	}

	immediate = {
		set_variable = {
			which = apb_augment_elapsed
			value = trigger:days_passed
		}
		subtract_variable = {
			which = apb_augment_elapsed
			value = apb_augment_start
		}
		if = {
			limit = {
				check_variable = {
					which = apb_augment_elapsed
					value >= 3590
				}
			}
			if = {
				limit = {
					has_edict = apb_augments_labour
					NOT = { has_country_flag = apb_augment_worn_labour }
				}
				set_country_flag = apb_augment_worn_labour
				country_event = { id = apb_augments.10 }
			}
			else_if = {
				limit = {
					has_edict = apb_augments_combat
					NOT = { has_country_flag = apb_augment_worn_combat }
				}
				set_country_flag = apb_augment_worn_combat
				country_event = { id = apb_augments.11 }
			}
			else_if = {
				limit = {
					has_edict = apb_augments_research
					NOT = { has_country_flag = apb_augment_worn_research }
				}
				set_country_flag = apb_augment_worn_research
				country_event = { id = apb_augments.12 }
			}
		}
		clear_variable = apb_augment_elapsed
	}
}

# AI: Combat frame while at war, Labour frame otherwise. The AI does not use the
# edicts (script cannot switch a toggle edict off), so it gets the same numbers as
# a modifier, without Recalibrating or Worn In.
# An empire a player has taken over loses the AI frame here and uses the edicts.
# Hook: on_yearly_pulse_country, and the perk's on_enabled. This = country.
country_event = {
	id = apb_augments.4
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_hot_swap_augments
	}

	immediate = {
		if = {
			limit = { is_ai = no }
			apb_augments_clear_ai_frames = yes
		}
		else_if = {
			limit = { is_at_war = yes }
			if = {
				limit = {
					NOT = { has_modifier = apb_augments_ai_combat }
				}
				apb_augments_clear_ai_frames = yes
				add_modifier = {
					modifier = apb_augments_ai_combat
					days = -1
				}
			}
		}
		else = {
			if = {
				limit = {
					NOT = { has_modifier = apb_augments_ai_labour }
				}
				apb_augments_clear_ai_frames = yes
				add_modifier = {
					modifier = apb_augments_ai_labour
					days = -1
				}
			}
		}
	}
}

###########################
# Player notifications: a frame is Worn In
###########################

country_event = {
	id = apb_augments.10
	title = apb_augments.10.name
	desc = apb_augments.10.desc
	picture = GFX_evt_cybernetics
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_augments.10.a
		custom_tooltip = apb_augments_worn_in_labour_tt
	}
}

country_event = {
	id = apb_augments.11
	title = apb_augments.10.name
	desc = apb_augments.10.desc
	picture = GFX_evt_cybernetics
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_augments.10.a
		custom_tooltip = apb_augments_worn_in_combat_tt
	}
}

country_event = {
	id = apb_augments.12
	title = apb_augments.10.name
	desc = apb_augments.10.desc
	picture = GFX_evt_cybernetics
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_augments.10.a
		custom_tooltip = apb_augments_worn_in_research_tt
	}
}
