namespace = autobuild_control_events 
character_event = {
	id = autobuild_control_events.0 #ab_cf_init_event
	desc = autobuild_control_events.0.desc 
	picture = GFX_evt_council 
	is_triggered_only = yes 
	notification = yes 
	immediate = {
		IF = { limit = { NOT = { is_alive = yes}}  break = yes}
		IF = {
			limit = { has_character_flag = ab_is_enabled_for_this_character}
			IF = {
				  limit = { has_character_flag = ab_is_enabled_for_this_character}
				  save_event_target_as = abet_payee 
				  IF = {
					    limit = {
						      NOT = { 
							        has_character_flag = ab_cf_reacting
							        has_character_flag = ab_cf_repeat_enqueued
							        has_character_flag = ab_cf_built_something
							        has_character_flag = ab_cf_repeat_called_start
							        has_character_flag = ab_cf_selecting_something
							        }
						      }
					    character_event = { id = autobuild_control_events.1 days = 1}
					    }
				  }
			}
		IF = {
			limit = { NOT = { has_character_flag = ab_is_enabled_for_this_character}} 
			clr_all_autobuilding_flags = yes 
			ab_clr_province_tech_flags = yes 
			}
		}
	option = { name = "ACCEPT"}
	}
character_event = {
	id = autobuild_control_events.1 #ab_cf_start_event
	hide_window = yes 
	is_triggered_only = yes 
	immediate = {
		IF = { limit = { NOT = { is_alive = yes}}  break = yes}
		IF = {
			limit = { has_character_flag = ab_is_enabled_for_this_character}
			set_character_flag = ab_cf_selecting_something 
			IF = {
				limit = { has_character_flag = ab_cf_repeat_called_start}
				clr_character_flag = ab_cf_repeat_enqueued 
				clr_character_flag = ab_cf_repeat_called_start 
				}
			clr_character_flag = ab_cf_reacting 
			clr_character_flag = ab_cf_built_something 
			character_event = { id = auto_build_selection_events.1}
			}
		IF = {
			limit = { NOT = { has_character_flag = ab_is_enabled_for_this_character}} 
			clr_all_autobuilding_flags = yes 
			ab_clr_province_tech_flags = yes 
			}
		}
	option = {}
	}
character_event = {
	id = autobuild_control_events.2 #ab_cf_repeat_event
	hide_window = yes 
	is_triggered_only = yes 
	immediate = {
		IF = { limit = { NOT = { is_alive = yes}}  break = yes}
		IF = {
			limit = { has_character_flag = ab_is_enabled_for_this_character}
			IF = {
				limit = { NOT = { has_character_flag = ab_cf_selecting_something has_character_flag = ab_cf_reacting}} 
				IF = {
					limit = { has_character_flag = ab_cf_built_something}
					character_event = { id = autobuild_control_events.3 days = 1}
					break = yes 
					}
				}
			IF = {
				limit = { NOT = { has_character_flag = ab_cf_repeat_enqueued}} 
				set_character_flag = ab_cf_repeat_enqueued 
				character_event = { id = autobuild_control_events.2 days = 30}
				break = yes 
				}
			IF = {
				limit = { had_character_flag = { flag = ab_cf_repeat_enqueued days = 100}} 
				set_character_flag = ab_cf_repeat_called_start 
				character_event = { id = autobuild_control_events.1}
				break = yes 
				}
			}
		IF = {
			limit = { NOT = { has_character_flag = ab_is_enabled_for_this_character}} 
			clr_all_autobuilding_flags = yes 
			ab_clr_province_tech_flags = yes 
			}
		}
	option = {}
	}
character_event = {
	id = autobuild_control_events.3 #ab_cf_react_event
	hide_window = yes 
	is_triggered_only = yes 
	immediate = {
		IF = { limit = { NOT = { is_alive = yes}}  break = yes}
		IF = {
			limit = { has_character_flag = ab_is_enabled_for_this_character}
			IF = {
				limit = { NOT = { has_character_flag = ab_cf_reacting has_character_flag = ab_cf_selecting_something}} 
				set_character_flag = ab_cf_reacting 
				character_event = { id = autobuild_control_events.1 days = 1}
				}
			}
		IF = {
			limit = { NOT = { has_character_flag = ab_is_enabled_for_this_character}} 
			clr_all_autobuilding_flags = yes 
			ab_clr_province_tech_flags = yes 
			}
		}
	option = {}
	}
character_event = {
	id = autobuild_control_events.4 #ab_cf_on_death_event
	desc = autobuild_control_events.4.desc 
	picture = GFX_evt_council 
	is_triggered_only = yes 
	notification = yes 
	has_character_flag = ab_is_enabled_for_this_character 
	immediate = {
		ROOT = { 
			clr_dynasty_flag = ab_enable_vassal_baron_flag
			clr_dynasty_flag = ab_enable_county_baron_flag
			clr_dynasty_flag = ab_enable_all_vassal_flag
			clr_dynasty_flag = ab_gold_reserve_500_flag
			clr_dynasty_flag = ab_gold_reserve_1000_flag
			clr_dynasty_flag = ab_gold_reserve_100_flag
			clr_dynasty_flag = ab_gold_reserve_2500_flag
			clr_dynasty_flag = ab_gold_reserve_250_flag
			clr_dynasty_flag = ab_gold_reserve_5000_flag
			clr_dynasty_flag = ab_gold_reserve_10000_flag
			clr_dynasty_flag = ab_prestige_reserve_500_flag
			clr_dynasty_flag = ab_prestige_reserve_5000_flag
			clr_dynasty_flag = ab_prestige_reserve_100_flag
			clr_dynasty_flag = ab_prestige_reserve_2500_flag
			clr_dynasty_flag = ab_prestige_reserve_250_flag
			clr_dynasty_flag = ab_prestige_reserve_1000_flag
			clr_dynasty_flag = ab_prestige_reserve_10000_flag
			if = { 
				limit = { has_character_flag = ab_enable_vassal_baron_flag }
				set_dynasty_flag = ab_enable_vassal_baron_flag
				}
			if = { 
				limit = { has_character_flag = ab_enable_county_baron_flag }
				set_dynasty_flag = ab_enable_county_baron_flag
				}
			if = { 
				limit = { has_character_flag = ab_enable_all_vassal_flag }
				set_dynasty_flag = ab_enable_all_vassal_flag
				}
			if = { 
				limit = { has_character_flag = ab_gold_reserve_500_flag }
				set_dynasty_flag = ab_gold_reserve_500_flag
				}
			if = { 
				limit = { has_character_flag = ab_gold_reserve_1000_flag }
				set_dynasty_flag = ab_gold_reserve_1000_flag
				}
			if = { 
				limit = { has_character_flag = ab_gold_reserve_100_flag }
				set_dynasty_flag = ab_gold_reserve_100_flag
				}
			if = { 
				limit = { has_character_flag = ab_gold_reserve_2500_flag }
				set_dynasty_flag = ab_gold_reserve_2500_flag
				}
			if = { 
				limit = { has_character_flag = ab_gold_reserve_250_flag }
				set_dynasty_flag = ab_gold_reserve_250_flag
				}
			if = { 
				limit = { has_character_flag = ab_gold_reserve_5000_flag }
				set_dynasty_flag = ab_gold_reserve_5000_flag
				}
			if = { 
				limit = { has_character_flag = ab_gold_reserve_10000_flag }
				set_dynasty_flag = ab_gold_reserve_10000_flag
				}
			if = { 
				limit = { has_character_flag = ab_prestige_reserve_500_flag }
				set_dynasty_flag = ab_prestige_reserve_500_flag
				}
			if = { 
				limit = { has_character_flag = ab_prestige_reserve_5000_flag }
				set_dynasty_flag = ab_prestige_reserve_5000_flag
				}
			if = { 
				limit = { has_character_flag = ab_prestige_reserve_100_flag }
				set_dynasty_flag = ab_prestige_reserve_100_flag
				}
			if = { 
				limit = { has_character_flag = ab_prestige_reserve_2500_flag }
				set_dynasty_flag = ab_prestige_reserve_2500_flag
				}
			if = { 
				limit = { has_character_flag = ab_prestige_reserve_250_flag }
				set_dynasty_flag = ab_prestige_reserve_250_flag
				}
			if = { 
				limit = { has_character_flag = ab_prestige_reserve_1000_flag }
				set_dynasty_flag = ab_prestige_reserve_1000_flag
				}
			if = { 
				limit = { has_character_flag = ab_prestige_reserve_10000_flag }
				set_dynasty_flag = ab_prestige_reserve_10000_flag
				}
			any_dynasty_member = {
				#find my dynastic heir, I don't care about actual heir.
				limit = {is_heir=yes}
				character_event = { id=autobuild_control_events.5 days=1}
				}
			}
		}
	option = { name = "ACCEPT"}
	}
character_event = {
	id = autobuild_control_events.5 #ab_cf_restart_event
	desc = autobuild_control_events.5.desc 
	picture = GFX_evt_council 
	is_triggered_only = yes 
	notification = yes 
	immediate = {
		if = {
			#on the off chance that more than one person of the same dynasty are autobuilding, and a heir.
			limit={ NOT = {has_character_flag = ab_is_enabled_for_this_character} }
			if = { 
				limit = { has_dynasty_flag = ab_enable_vassal_baron_flag }
				set_character_flag = ab_enable_vassal_baron_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_enable_county_baron_flag }
				set_character_flag = ab_enable_county_baron_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_enable_all_vassal_flag }
				set_character_flag = ab_enable_all_vassal_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_gold_reserve_500_flag }
				set_character_flag = ab_gold_reserve_500_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_gold_reserve_1000_flag }
				set_character_flag = ab_gold_reserve_1000_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_gold_reserve_100_flag }
				set_character_flag = ab_gold_reserve_100_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_gold_reserve_2500_flag }
				set_character_flag = ab_gold_reserve_2500_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_gold_reserve_250_flag }
				set_character_flag = ab_gold_reserve_250_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_gold_reserve_5000_flag }
				set_character_flag = ab_gold_reserve_5000_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_gold_reserve_10000_flag }
				set_character_flag = ab_gold_reserve_10000_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_prestige_reserve_500_flag }
				set_character_flag = ab_prestige_reserve_500_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_prestige_reserve_5000_flag }
				set_character_flag = ab_prestige_reserve_5000_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_prestige_reserve_100_flag }
				set_character_flag = ab_prestige_reserve_100_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_prestige_reserve_2500_flag }
				set_character_flag = ab_prestige_reserve_2500_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_prestige_reserve_250_flag }
				set_character_flag = ab_prestige_reserve_250_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_prestige_reserve_1000_flag }
				set_character_flag = ab_prestige_reserve_1000_flag
				}
			if = { 
				limit = { has_dynasty_flag = ab_prestige_reserve_10000_flag }
				set_character_flag = ab_prestige_reserve_10000_flag
				}
			set_character_flag = ab_is_enabled_for_this_character
			character_event = {id=autobuild_control_events.0}
			}
		}
	option = { name = "ACCEPT"}
	}
character_event = {
	id = autobuild_control_events.6 #ab_cf_yearly_pulse_event
	hide_window = yes 
	is_triggered_only = yes 
	has_character_flag = ab_is_enabled_for_this_character 
	immediate = {
		IF = { limit = { NOT = { is_alive = yes}}  break = yes}
		IF = {
			limit = { has_character_flag = ab_is_enabled_for_this_character}
			
			if = { limit = {had_character_flag={ flag=ab_cf_reacting days=110}}
				  clr_character_flag = ab_cf_reacting
				  }
			if = { limit = {had_character_flag={ flag=ab_cf_repeat_enqueued days=110}}
				  clr_character_flag = ab_cf_repeat_enqueued
				  }
			if = { limit = {had_character_flag={ flag=ab_cf_built_something days=110}}
				  clr_character_flag = ab_cf_built_something
				  }
			if = { limit = {had_character_flag={ flag=ab_cf_repeat_called_start days=110}}
				  clr_character_flag = ab_cf_repeat_called_start
				  }
			if = { limit = {had_character_flag={ flag=ab_cf_selecting_something days=110}}
				  clr_character_flag = ab_cf_selecting_something
				  }
			character_event ={ id=autobuild_control_events.2}
			}
		IF = {
			limit = { NOT = { has_character_flag = ab_is_enabled_for_this_character}} 
			clr_all_autobuilding_flags = yes 
			ab_clr_province_tech_flags = yes 
			}
		}
	option = {}
	}
