set_current_age = {
	set_temp_variable = { current_age_temp_temp = global.current_age }
	clear_variable = global.current_age
	if = {
		limit = {
			are_triggers_met_for_age_1 = yes
		}
		set_variable = { global.current_age = 1 }
		set_global_flag = age_has_begun_1
		meta_effect = {
			text = {
				set_variable = { global.age_1_start_year = [YEAR] }
			}
			YEAR = "[GetYear]"
		}
	}
	if = {
		limit = {
			are_triggers_met_for_age_2 = yes
		}
		set_variable = { global.current_age = 2 }
		set_global_flag = age_has_begun_2
		meta_effect = {
			text = {
				set_variable = { global.age_2_start_year = [YEAR] }
			}
			YEAR = "[GetYear]"
		}
		hidden_effect = {
			every_country = {
				every_owned_state = {
					set_state_flag = owned_by_@PREV
				}
			}
		}
	}
	if = {
		limit = {
			are_triggers_met_for_age_3 = yes
		}
		set_variable = { global.current_age = 3 }
		set_global_flag = age_has_begun_3
		meta_effect = {
			text = {
				set_variable = { global.age_3_start_year = [YEAR] }
			}
			YEAR = "[GetYear]"
		}
	}
	if = {
		limit = {
			are_triggers_met_for_age_4 = yes
		}
		set_variable = { global.current_age = 4 }
		set_global_flag = age_has_begun_4
		meta_effect = {
			text = {
				set_variable = { global.age_4_start_year = [YEAR] }
			}
			YEAR = "[GetYear]"
		}
	}
	if = {
		limit = {
			are_triggers_met_for_age_5 = yes
		}
		set_variable = { global.current_age = 5 }
		set_global_flag = age_has_begun_5
		meta_effect = {
			text = {
				set_variable = { global.age_5_start_year = [YEAR] }
			}
			YEAR = "[GetYear]"
		}
	}
	if = {
		limit = {
			are_triggers_met_for_age_6 = yes
		}
		set_variable = { global.current_age = 6 }
		set_global_flag = age_has_begun_6
		meta_effect = {
			text = {
				set_variable = { global.age_6_start_year = [YEAR] }
			}
			YEAR = "[GetYear]"
		}
	}
	if = {
		limit = {
			has_variable = global.current_age
			NOT = { check_variable = { current_age_temp_temp = global.current_age } }
		}
		hidden_effect = {
			every_country = {
				country_event = { id = eu4_like_ages_events.1000 }
			}
		}
	}
	set_age_abilities = yes
	set_age_objectives = yes
	if = {
		limit = {
			has_variable = global.current_age
			NOT = { check_variable = { current_age_temp_temp = global.current_age } }
		}
		every_country = {
			limit = {
				is_ai = no
			}
			set_variable = { show_eu4_like_ages_new_age_popup_alert_window = 1 }
		}
	}
}

set_age_abilities = {
	clear_array = global.current_age_abilities
	if = {
		limit = {
			check_variable = { global.current_age = 1 }
		}
		add_to_array = { global.current_age_abilities = 34 }
		add_to_array = { global.current_age_abilities = 35 }
		add_to_array = { global.current_age_abilities = 36 }
		add_to_array = { global.current_age_abilities = 37 }
		add_to_array = { global.current_age_abilities = 38 }
		add_to_array = { global.current_age_abilities = 39 }
		add_to_array = { global.current_age_abilities = 40 }
		add_to_array = { global.current_age_abilities = 41 }
		add_to_array = { global.current_age_abilities = 42 }
		add_to_array = { global.current_age_abilities = 43 }
		add_to_array = { global.current_age_abilities = 44 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 2 }
		}
		add_to_array = { global.current_age_abilities = 45 }
		add_to_array = { global.current_age_abilities = 46 }
		add_to_array = { global.current_age_abilities = 47 }
		add_to_array = { global.current_age_abilities = 48 }
		add_to_array = { global.current_age_abilities = 49 }
		add_to_array = { global.current_age_abilities = 50 }
		add_to_array = { global.current_age_abilities = 51 }
		add_to_array = { global.current_age_abilities = 52 }
		add_to_array = { global.current_age_abilities = 53 }
		add_to_array = { global.current_age_abilities = 54 }
		add_to_array = { global.current_age_abilities = 55 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 3 }
		}
		add_to_array = { global.current_age_abilities = 1 }
		add_to_array = { global.current_age_abilities = 2 }
		add_to_array = { global.current_age_abilities = 3 }
		add_to_array = { global.current_age_abilities = 4 }
		add_to_array = { global.current_age_abilities = 5 }
		add_to_array = { global.current_age_abilities = 6 }
		add_to_array = { global.current_age_abilities = 7 }
		add_to_array = { global.current_age_abilities = 8 }
		add_to_array = { global.current_age_abilities = 9 }
		add_to_array = { global.current_age_abilities = 10 }
		add_to_array = { global.current_age_abilities = 11 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 4 }
		}
		add_to_array = { global.current_age_abilities = 12 }
		add_to_array = { global.current_age_abilities = 13 }
		add_to_array = { global.current_age_abilities = 14 }
		add_to_array = { global.current_age_abilities = 15 }
		add_to_array = { global.current_age_abilities = 16 }
		add_to_array = { global.current_age_abilities = 17 }
		add_to_array = { global.current_age_abilities = 18 }
		add_to_array = { global.current_age_abilities = 19 }
		add_to_array = { global.current_age_abilities = 20 }
		add_to_array = { global.current_age_abilities = 21 }
		add_to_array = { global.current_age_abilities = 22 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 5 }
		}
		add_to_array = { global.current_age_abilities = 23 }
		add_to_array = { global.current_age_abilities = 24 }
		add_to_array = { global.current_age_abilities = 25 }
		add_to_array = { global.current_age_abilities = 26 }
		add_to_array = { global.current_age_abilities = 27 }
		add_to_array = { global.current_age_abilities = 28 }
		add_to_array = { global.current_age_abilities = 29 }
		add_to_array = { global.current_age_abilities = 30 }
		add_to_array = { global.current_age_abilities = 31 }
		add_to_array = { global.current_age_abilities = 32 }
		add_to_array = { global.current_age_abilities = 33 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 6 }
		}
		add_to_array = { global.current_age_abilities = 56 }
		add_to_array = { global.current_age_abilities = 57 }
		add_to_array = { global.current_age_abilities = 58 }
		add_to_array = { global.current_age_abilities = 59 }
		add_to_array = { global.current_age_abilities = 60 }
		add_to_array = { global.current_age_abilities = 61 }
		add_to_array = { global.current_age_abilities = 62 }
		add_to_array = { global.current_age_abilities = 63 }
		add_to_array = { global.current_age_abilities = 64 }
		add_to_array = { global.current_age_abilities = 65 }
		add_to_array = { global.current_age_abilities = 66 }
	}
	if = {
		limit = {
			check_variable = { global.current_age_abilities^num < 1 }
		}
		clear_variable = global.current_age
		clear_array = global.current_age_abilities
		clear_array = global.current_age_objectives
		clear_variable = global.age_1_start_year
		clear_variable = global.age_2_start_year
		clear_variable = global.age_3_start_year
		clear_variable = global.age_4_start_year
		clear_variable = global.age_5_start_year
		clear_variable = global.age_6_start_year
	}
}

set_age_objectives = {
	clear_array = global.current_age_objectives
	if = {
		limit = {
			check_variable = { global.current_age = 1 }
		}
		add_to_array = { global.current_age_objectives = 22 }
		add_to_array = { global.current_age_objectives = 23 }
		add_to_array = { global.current_age_objectives = 24 }
		add_to_array = { global.current_age_objectives = 25 }
		add_to_array = { global.current_age_objectives = 26 }
		add_to_array = { global.current_age_objectives = 27 }
		add_to_array = { global.current_age_objectives = 28 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 2 }
		}
		add_to_array = { global.current_age_objectives = 29 }
		add_to_array = { global.current_age_objectives = 30 }
		add_to_array = { global.current_age_objectives = 31 }
		add_to_array = { global.current_age_objectives = 32 }
		add_to_array = { global.current_age_objectives = 33 }
		add_to_array = { global.current_age_objectives = 34 }
		add_to_array = { global.current_age_objectives = 35 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 3 }
		}
		add_to_array = { global.current_age_objectives = 1 }
		add_to_array = { global.current_age_objectives = 2 }
		add_to_array = { global.current_age_objectives = 3 }
		add_to_array = { global.current_age_objectives = 4 }
		add_to_array = { global.current_age_objectives = 5 }
		add_to_array = { global.current_age_objectives = 6 }
		add_to_array = { global.current_age_objectives = 7 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 4 }
		}
		add_to_array = { global.current_age_objectives = 8 }
		add_to_array = { global.current_age_objectives = 9 }
		add_to_array = { global.current_age_objectives = 10 }
		add_to_array = { global.current_age_objectives = 11 }
		add_to_array = { global.current_age_objectives = 12 }
		add_to_array = { global.current_age_objectives = 13 }
		add_to_array = { global.current_age_objectives = 14 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 5 }
		}
		add_to_array = { global.current_age_objectives = 15 }
		add_to_array = { global.current_age_objectives = 16 }
		add_to_array = { global.current_age_objectives = 17 }
		add_to_array = { global.current_age_objectives = 18 }
		add_to_array = { global.current_age_objectives = 19 }
		add_to_array = { global.current_age_objectives = 20 }
		add_to_array = { global.current_age_objectives = 21 }
	}
	else_if = {
		limit = {
			check_variable = { global.current_age = 6 }
		}
		add_to_array = { global.current_age_objectives = 36 }
		add_to_array = { global.current_age_objectives = 37 }
		add_to_array = { global.current_age_objectives = 38 }
		add_to_array = { global.current_age_objectives = 39 }
		add_to_array = { global.current_age_objectives = 40 }
		add_to_array = { global.current_age_objectives = 41 }
		add_to_array = { global.current_age_objectives = 42 }
	}
	if = {
		limit = {
			check_variable = { global.current_age_objectives^num < 1 }
		}
		clear_variable = global.current_age
		clear_array = global.current_age_abilities
		clear_array = global.current_age_objectives
		clear_variable = global.age_1_start_year
		clear_variable = global.age_2_start_year
		clear_variable = global.age_3_start_year
		clear_variable = global.age_4_start_year
		clear_variable = global.age_5_start_year
		clear_variable = global.age_6_start_year
	}
}

enact_age_ability_effect = {
	if = {
		limit = {
			check_variable = { age_ability = 8 }
		}
		add_named_threat = {
			threat = -10
			name = age_ability_8
		}
	}
	else_if = {
		limit = {
			check_variable = { age_ability = 65 }
		}
		add_offsite_building = { type = industrial_complex level = 2 }
	}
	hidden_effect = {
		meta_effect = {
			text = {
				add_ideas = age_ability_[ABILITY]
			}
			ABILITY = "[?age_ability]"
		}
		subtract_from_variable = { current_splendor = 800 }
		add_to_array = { currently_selected_age_abilities = age_ability }
	}
}