namespace = lazy_shared_events

carrier_event = {
	id = lazy_shared_events.2
	title = "lazy_shared_events.2.name"
	desc = "lazy_shared_events.2.desc"
	picture = GFX_evt_machine_sapience
	show_sound = event_administrative_work
	hide_window = no

	is_triggered_only = yes

	option = {
		name = "lazy_shared_events.2.b"
		hidden_effect = {
			carrier_event = {
				id = lazy_pla_spe_events.1
			}
		}
	}

	option = {
		name = "lazy_shared_events.2.c"
		hidden_effect = {
			carrier_event = {
				id = lazy_pla_dec_events.1
			}
		}
	}
}

country_event = {
	id = lazy_shared_events.3
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_country_flag = auto_construct_outposts_flag
			}
			every_owned_fleet = {
				limit = {
					is_ship_size = constructor
					has_fleet_flag = auto_outpost_ship_flag
				}
				if = {
					limit = {
						is_variable_set = lazy_automation_month_timer
					}
					subtract_variable = {
						which = lazy_automation_month_timer
						value = 1
					}
				}
				else = {
					set_variable = {
						which = lazy_automation_month_timer
						value = 0
					}
				}

				if = {
					limit = {
						check_variable = {
							which = lazy_automation_month_timer
							value < 0
						}
					}
					set_variable = {
						which = lazy_automation_month_timer
						value = 0
					}
				}
			}
		}

		if = {
			limit = {
				has_country_flag = auto_construct_mega_flag
			}
			every_owned_fleet = {
				limit = {
					is_ship_size = constructor
					has_fleet_flag = auto_mega_ship_flag
				}
				if = {
					limit = {
						is_variable_set = lazy_automation_month_timer
					}
					subtract_variable = {
						which = lazy_automation_month_timer
						value = 1
					}
				}
				else = {
					set_variable = {
						which = lazy_automation_month_timer
						value = 0
					}
				}

				if = {
					limit = {
						check_variable = {
							which = lazy_automation_month_timer
							value < 0
						}
					}
					set_variable = {
						which = lazy_automation_month_timer
						value = 0
					}
				}
			}
		}

		if = {
			limit = {
				OR = {
					has_country_flag = auto_outfit_starbases_flag
					has_country_flag = auto_upgrade_starbases_flag
				}
			}
			every_owned_fleet = {
				limit = {
					is_ship_class = shipclass_starbase
					starbase = {
						OR = {
							has_starbase_flag = auto_outfitting_starbase_flag
							has_starbase_flag = auto_upgrading_starbase_flag
						}
					}
				}
				if = {
					limit = {
						is_variable_set = lazy_automation_month_timer
					}
					subtract_variable = {
						which = lazy_automation_month_timer
						value = 1
					}
				}
				else = {
					set_variable = {
						which = lazy_automation_month_timer
						value = 0
					}
				}

				if = {
					limit = {
						check_variable = {
							which = lazy_automation_month_timer
							value < 0
						}
					}
					set_variable = {
						which = lazy_automation_month_timer
						value = 0
					}
				}
			}
		}
	}
}

ship_event = {
	id = lazy_shared_events.4
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			is_ship_class = shipclass_constructor
			is_ship_class = shipclass_starbase
		}
		owner = {
			is_ai = no
		}
	}

	immediate = {
		fleet = {
			set_variable = {
				which = lazy_automation_month_timer
				value = 0
			}
		}
	}
}

fleet_event = {
	id = lazy_shared_events.5
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_ship_class = shipclass_constructor
		OR = {
			has_fleet_flag = auto_mega_ship_flag
			has_fleet_flag = auto_outpost_ship_flag
		}
	}

	immediate = {
		set_timed_fleet_flag = {
			flag = auto_construction_ship_watchdog_@from
			days = 150
		}
		fleet_event = {
			id = lazy_shared_events.6
			days = 140
		}
	}
}

fleet_event = {
    id = lazy_shared_events.6
    hide_window = yes
    is_triggered_only = yes

    trigger = {
        has_fleet_flag = auto_construction_ship_watchdog_@this.solar_system
        NOT = {
            has_fleet_flag = auto_construct_blocked_fleet_flag
		}
	}

    immediate = {
        clear_fleet_actions = this
        clear_orders = yes
		
        switch = {
            trigger = has_fleet_flag

            auto_outpost_ship_flag = {
				fleet_event = {
					id = lazy_con_events.1
				}
			}
            auto_construct_hyper_relays_flag = {
				fleet_event = {
					id = lazy_con_meg_events.2
				}
			}
            auto_construct_gateway_flag = {
				fleet_event = {
					id = lazy_con_meg_events.3
				}
			}
            auto_construct_habitat_central_flag = {
				fleet_event = {
					id = lazy_con_meg_events.4
				}
			}
            auto_construct_frameworld_outpost_flag = {
				fleet_event = {
					id = lazy_con_meg_events.5
				}
			}
            auto_construct_frameworld_harvest_flag = {
				fleet_event = {
					id = lazy_con_meg_events.6
				}
			}
            auto_construct_frameworld_salvage_habitat_flag = {
				fleet_event = {
					id = lazy_con_meg_events.7
				}
			}
            auto_construct_orbital_ring_flag = {
				fleet_event = {
					id = lazy_con_meg_events.8
				}
			}
            auto_construct_dyson_swarm_flag = {
				fleet_event = {
					id = lazy_con_meg_events.9
				}
			}
            auto_construct_arc_furnace_flag = {
				fleet_event = {
					id = lazy_con_meg_events.10
				}
			}
            auto_construct_deep_space_citadel_flag = {
				fleet_event = {
					id = lazy_con_meg_events.11
				}
			}
            auto_construct_sra_orbital_ring_flag = {
				fleet_event = {
					id = lazy_con_meg_events.12
				}
			}
            auto_construct_sra_barrier_guard_station_flag = {
				fleet_event = {
					id = lazy_con_meg_events.13
				}
			}
            auto_construct_sra_gz_platform_flag = {
				fleet_event = {
					id = lazy_con_meg_events.14
				}
			}
            auto_construct_planetary_computer_flag = {
				fleet_event = {
					id = lazy_con_meg_events.15
				}
			}
            auto_construct_terraform_site_flag = {
				fleet_event = {
					id = lazy_con_meg_events.16
				}
			}
            auto_construct_asteroid_manufactory_flag = {
				fleet_event = {
					id = lazy_con_meg_events.17
				}
			}
		}
	}
}