namespace = bm
event = {
	id = bm.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_lithoids = yes
		any_playable_country = {
			has_valid_civic = civic_bm_void_machines
		}
	}

	immediate = {
		every_playable_country = {
			limit = {
				has_valid_civic = civic_bm_void_machines
				NOT = { has_country_flag = void_tactical_machine_cooldown }
			}
			random_system_within_border = {
				limit = {
					any_system_planet = {
						NOT = {
							has_planet_flag = has_megastructure
						}
						OR = {
							AND = {
								has_deposit_for = shipclass_mining_station
								has_mining_station = no
							}
							AND = {
								has_deposit_for = shipclass_research_station
								has_research_station = no
							}
						}
					}
				}
				system_event = { id = action.725 }
			}
			set_timed_country_flag = {
				flag = void_tactical_machine_cooldown
				days = 95
			}
		}
	}
}


country_event = {
	id = bm.2
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_valid_civic = civic_bm_void_machines
		OR = {
			last_increased_tech = tech_mine_exotic_gases
			last_increased_tech = tech_mine_rare_crystals
			last_increased_tech = tech_mine_volatile_motes
			last_increased_tech = tech_mine_zro
			last_increased_tech = tech_mine_dark_matter
			last_increased_tech = tech_mine_living_metal
		}
	}

	immediate = {
		if = {
			limit = {
				last_increased_tech = tech_mine_exotic_gases
			}
			remove_modifier = reduce_gas_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_rare_crystals
			}
			remove_modifier = reduce_crystal_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_volatile_motes
			}
			remove_modifier = reduce_motes_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_zro
			}
			remove_modifier = reduce_zro_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_dark_matter
			}
			remove_modifier = reduce_dark_matter_output
		}
		if = {
			limit = {
				last_increased_tech = tech_mine_living_metal
			}
			remove_modifier = reduce_living_metal_output
		}
	}
}

country_event = {
	id = bm.3
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		NOT = {
			has_valid_civic = civic_bm_void_machines
		}
		OR = {
			has_modifier = reduce_gas_output
			has_modifier = reduce_crystal_output
			has_modifier = reduce_motes_output
			has_modifier = reduce_zro_output
			has_modifier = reduce_dark_matter_output
			has_modifier = reduce_living_metal_output
		}
	}

	immediate = {
		if = {
			limit = {
				has_modifier = reduce_gas_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = exotic_gases amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_gas_output
		}
		if = {
			limit = {
				has_modifier = reduce_crystal_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = rare_crystals amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_crystal_output
		}
		if = {
			limit = {
				has_modifier = reduce_motes_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = volatile_motes amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_motes_output
		}
		if = {
			limit = {
				has_modifier = reduce_zro_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = sr_zro amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_zro_output
		}
		if = {
			limit = {
				has_modifier = reduce_dark_matter_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = sr_dark_matter amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_dark_matter_output
		}
		if = {
			limit = {
				has_modifier = reduce_living_metal_output
			}
			every_planet_within_border = {
				limit = {
					has_mining_station = yes
					has_resource = { type = sr_living_metal amount > 0 }
				}
				mining_station = {
					dismantle = yes
				}
			}
			remove_modifier = reduce_living_metal_output
		}
	}
}


