#This feature did not get fully implemented for 1.2 so scoping is still very primitive
# scopes that the triggers and the effect will get will have the player's country set in both THIS and FROM
# In the future this will be expanded on so that the value in THIS is context sensetive

# Hack until buttons work properly
isbs_ebutton_select_fleet = {
	potential = {
		has_country_flag = flag_blink_button
		NOT = { has_country_flag = flag_blink_mode }
		NOT = { has_country_flag = flag_rag_mode }
	}
	allow = {
		always = yes
	}

	effect = {
		custom_tooltip = "isbs_blink_fleet_selector_tip"
		if = {
			limit = {
				check_variable = {
					which = "blink_fleet_selector"
					value < 100
				}
			}

			set_variable = {
				which = "blink_fleet_selector"
				value = 100
			}

			else = {
				change_variable = {
					which = "blink_fleet_selector"
					value = 1
				}
			}
		}

		if = {
			limit = {
				check_variable = {
					which = "blink_fleet_selector"
					value > 103
				}
			}

			set_variable = {
				which = "blink_fleet_selector"
				value = 100
			}
		}

		# Selector
		if = {
			limit = {
				check_variable = {
					which = "blink_fleet_selector"
					value = 100
				}
			}
			random_owned_fleet = {
				limit = {
					is_in_combat = yes
					has_fleet_flag = flag_can_blink
					NOT = { has_fleet_flag = flag_blink_cooldown }
					check_variable = {
						which = "blink_fleet_id"
						value = 100
					}
					SOLAR_SYSTEM = {
						any_ship_in_system = {
							is_ship_size = blink_ship
							FLEET = { is_same_value = PREVPREVPREV }
						}
					}
				}
				fleet_event = { id = isbs_blink.199 }
				if = {
					limit = {
						has_fleet_flag = flag_blink_auto_on
					}
					PREV = { set_country_flag = flag_blink_auto_on_country }

					else = {
						PREV = {
							if = {
								limit = {
									has_country_flag = flag_blink_auto_on_country
								}
								remove_country_flag = flag_blink_auto_on_country
							}
						}
					}
				}
			}
			else = {
				if = {
					limit = {
						check_variable = {
							which = "blink_fleet_selector"
							value = 101
						}
					}
					random_owned_fleet = {
						limit = {
							is_in_combat = yes
							has_fleet_flag = flag_can_blink
							NOT = { has_fleet_flag = flag_blink_cooldown }
							check_variable = {
								which = "blink_fleet_id"
								value = 101
							}
							SOLAR_SYSTEM = {
								any_ship_in_system = {
									is_ship_size = blink_ship
									FLEET = { is_same_value = PREVPREVPREV}
								}
							}
						}
						fleet_event = { id = isbs_blink.199 }
						if = {
							limit = {
								has_fleet_flag = flag_blink_auto_on
							}
							PREV = { set_country_flag = flag_blink_auto_on_country }

							else = {
								PREV = {
									if = {
										limit = {
											has_country_flag = flag_blink_auto_on_country
										}
										remove_country_flag = flag_blink_auto_on_country
									}
								}
							}
						}
					}
					else = {
						if = {
							limit = {
								check_variable = {
									which = "blink_fleet_selector"
									value = 102
								}
							}
							random_owned_fleet = {
								limit = {
									is_in_combat = yes
									has_fleet_flag = flag_can_blink
									NOT = { has_fleet_flag = flag_blink_cooldown }
									check_variable = {
										which = "blink_fleet_id"
										value = 102
									}
									SOLAR_SYSTEM = {
										any_ship_in_system = {
											is_ship_size = blink_ship
											FLEET = { is_same_value = PREVPREVPREV}
										}
									}
								}
								fleet_event = { id = isbs_blink.199 }
								if = {
									limit = {
										has_fleet_flag = flag_blink_auto_on
									}
									PREV = { set_country_flag = flag_blink_auto_on_country }

									else = {
										PREV = {
											if = {
												limit = {
													has_country_flag = flag_blink_auto_on_country
												}
												remove_country_flag = flag_blink_auto_on_country
											}
										}
									}
								}
							}
							else = {
								if = {
									limit = {
										check_variable = {
											which = "blink_fleet_selector"
											value = 103
										}
									}
									random_owned_fleet = {
										limit = {
											is_in_combat = yes
											has_fleet_flag = flag_can_blink
											NOT = { has_fleet_flag = flag_blink_cooldown }
											check_variable = {
												which = "blink_fleet_id"
												value = 103
											}
											SOLAR_SYSTEM = {
												any_ship_in_system = {
													is_ship_size = blink_ship
													FLEET = { is_same_value = PREVPREVPREV}
												}
											}
										}
										fleet_event = { id = isbs_blink.199 }
										if = {
											limit = {
												has_fleet_flag = flag_blink_auto_on
											}
											PREV = { set_country_flag = flag_blink_auto_on_country }

											else = {
												PREV = {
													if = {
														limit = {
															has_country_flag = flag_blink_auto_on_country
														}
														remove_country_flag = flag_blink_auto_on_country
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

isbs_ebutton_create_marker = {
	potential = {
		has_country_flag = flag_blink_button
		NOT = { has_country_flag = flag_blink_mode }
		NOT = { has_country_flag = flag_rag_mode }
	}
	allow = {
		NOT = { has_country_flag = flag_fleet_blinking }
	}

	effect = {
		custom_tooltip = "isbs_blink_create_marker_tip"

		every_ambient_object = {
			limit = { has_ambient_object_flag = isbs_blink_marker }
			destroy_ambient_object = THIS
		}

		if = {
			limit = {
				check_variable = {
					which = "blink_fleet_selector"
					value = 100
				}
			}

			random_owned_fleet = {
				limit = {
					is_in_combat = yes
					has_fleet_flag = flag_can_blink
					NOT = { has_fleet_flag = flag_blink_cooldown }
					check_variable = {
						which = "blink_fleet_id"
						value = 100
					}
				}

				PREV = { set_country_flag = flag_blink_mode }
				fleet_event = { id = isbs_blink.101 }
			}

			else = {
				if = {
					limit = {
						check_variable = {
							which = "blink_fleet_selector"
							value = 101
						}
					}

					random_owned_fleet = {
						limit = {
							is_in_combat = yes
							has_fleet_flag = flag_can_blink
							NOT = { has_fleet_flag = flag_blink_cooldown }
							check_variable = {
								which = "blink_fleet_id"
								value = 101
							}
						}

						PREV = { set_country_flag = flag_blink_mode }
						fleet_event = { id = isbs_blink.101 }
					}

					else = {
						if = {
							limit = {
								check_variable = {
									which = "blink_fleet_selector"
									value = 102
								}
							}

							random_owned_fleet = {
								limit = {
									is_in_combat = yes
									has_fleet_flag = flag_can_blink
									NOT = { has_fleet_flag = flag_blink_cooldown }
									check_variable = {
										which = "blink_fleet_id"
										value = 102
									}
								}

								PREV = { set_country_flag = flag_blink_mode }
								fleet_event = { id = isbs_blink.101 }
							}

							else = {
								if = {
									limit = {
										check_variable = {
											which = "blink_fleet_selector"
											value = 103
										}
									}

									random_owned_fleet = {
										limit = {
											is_in_combat = yes
											has_fleet_flag = flag_can_blink
											NOT = { has_fleet_flag = flag_blink_cooldown }
											check_variable = {
												which = "blink_fleet_id"
												value = 103
											}
										}

										PREV = { set_country_flag = flag_blink_mode }
										fleet_event = { id = isbs_blink.101 }
									}
								}
							}
						}
					}
				}
			}
		}

		if = {
			limit = {
				has_country_flag = flag_blink_mode
			}
			# Ensure the blink locator is properly spawned
			set_timed_country_flag = { flag = flag_blink_mode_delay days = 1 }
			# Timeout for blink mode
			set_timed_country_flag = { flag = flag_blink_mode_new days = 30 }
			country_event = { id = isbs_blink.2 days = 30 }

			set_variable = {
				which = "blink_marker_x"
				value = 0
			}
			set_variable = {
				which = "blink_marker_y"
				value = 0
			}

			else = {
				# no fleet found / selected error
				country_event = { id = isbs_blink.197 }
			}
		}
	}
}

isbs_ebutton_blink_cancel = {
	potential = {
		has_country_flag = flag_blink_mode
	}
	allow = {
		NOT = { has_country_flag = flag_blink_mode_delay }
	}

	effect = {
		custom_tooltip = "isbs_blink_cancel_tip"
		remove_country_flag = flag_blink_mode
		remove_country_flag = flag_blink_mode_new

		every_ambient_object = {
			limit = { has_ambient_object_flag = isbs_blink_marker }
			destroy_ambient_object = THIS
		}
	}
}

isbs_ebutton_marker_right = {
	potential = {
		has_country_flag = flag_blink_mode
	}
	allow = {
		NOT = { has_country_flag = flag_blink_mode_delay }
	}

	effect = {
		if = {
			limit = {
				check_variable = {
					which = "blink_marker_x"
					value < 5
				}
			}

			change_variable = {
				which = "blink_marker_x"
				value = 1
			}

			every_ambient_object = {
				limit = { has_ambient_object_flag = isbs_blink_marker }
				set_location = {
					target = THIS
					distance = 10
					angle = 0
				}
			}
		}
	}
}

isbs_ebutton_marker_left = {
	potential = {
		has_country_flag = flag_blink_mode
	}
	allow = {
		NOT = { has_country_flag = flag_blink_mode_delay }
	}

	effect = {
		if = {
			limit = {
				check_variable = {
					which = "blink_marker_x"
					value > -5
				}
			}
			change_variable = {
				which = "blink_marker_x"
				value = -1
			}

			every_ambient_object = {
				limit = { has_ambient_object_flag = isbs_blink_marker }
				set_location = {
					target = THIS
					distance = 10
					angle = 180
				}
			}
		}
	}
}

isbs_ebutton_marker_forw = {
	potential = {
		has_country_flag = flag_blink_mode
	}
	allow = {
		NOT = { has_country_flag = flag_blink_mode_delay }
	}

	effect = {
		if = {
			limit = {
				check_variable = {
					which = "blink_marker_y"
					value < 5
				}
			}

			change_variable = {
				which = "blink_marker_y"
				value = 1
			}

			every_ambient_object = {
				limit = { has_ambient_object_flag = isbs_blink_marker }
				set_location = {
					target = THIS
					distance = 10
					angle = 90
				}
			}
		}
	}
}

isbs_ebutton_marker_back = {
	potential = {
		has_country_flag = flag_blink_mode
	}
	allow = {
		NOT = { has_country_flag = flag_blink_mode_delay }
	}

	effect = {
		if = {
			limit = {
				check_variable = {
					which = "blink_marker_y"
					value > -5
				}
			}

			change_variable = {
				which = "blink_marker_y"
				value = -1
			}

			every_ambient_object = {
				limit = { has_ambient_object_flag = isbs_blink_marker }
				set_location = {
					target = THIS
					distance = 10
					angle = 270
				}
			}
		}
	}
}

isbs_ebutton_blink = {
	potential = {
		has_country_flag = flag_blink_mode
	}
	allow = {
		NOT = { has_country_flag = flag_blink_mode_delay }
		NOT = { has_country_flag = flag_fleet_blinking }
	}

	effect = {
		custom_tooltip = "isbs_blink_blink"	#blink
		remove_country_flag = flag_blink_mode
		remove_country_flag = flag_blink_mode_new

		random_ambient_object = {
			limit = { has_ambient_object_flag = isbs_blink_marker }

			# Ambient object scope bugs out sometimes if you spam pause/unpause on creation
			save_global_event_target_as = blink_loc
		}

		if = {
			limit = {
				check_variable = {
					which = "blink_fleet_selector"
					value = 100
				}
			}
			random_owned_fleet = {
				limit = {
					is_in_combat = yes
					has_fleet_flag = flag_can_blink
					NOT = { has_fleet_flag = flag_blink_cooldown }
					check_variable = {
						which = "blink_fleet_id"
						value = 100
					}
					SOLAR_SYSTEM = {
						any_ship_in_system = {
							FLEET = { is_same_value = PREVPREVPREV }
							is_ship_size = blink_ship
						}
					}
				}

				create_ambient_object = {
					type = "isbs_blink_in_marker_bunny_object"
				}
				last_created_ambient_object = {
					set_ambient_object_flag = "isbs_blink_in"
					set_location = {
						target = event_target:blink_loc
						distance = 0.1
						angle = random
					}
				}

				create_ambient_object = {
					type = "isbs_blink_out_bunny_object"
				}
				last_created_ambient_object = {
					set_ambient_object_flag = "isbs_blink_out"
				}

				# delayed blink
				fleet_event = { id = isbs_blink.7 days = 5}
				set_timed_fleet_flag = { flag = flag_blink_cooldown days = 60 }
				PREV = { set_timed_country_flag = { flag = flag_fleet_blinking days = 6 } }
				set_event_locked = yes
			}

			else = {
				if = {
					limit = {
						check_variable = {
							which = "blink_fleet_selector"
							value = 101
						}
					}
					random_owned_fleet = {
						limit = {
							is_in_combat = yes
							has_fleet_flag = flag_can_blink
							NOT = { has_fleet_flag = flag_blink_cooldown }
							check_variable = {
								which = "blink_fleet_id"
								value = 101
							}
							SOLAR_SYSTEM = {
								any_ship_in_system = {
									FLEET = { is_same_value = PREVPREVPREV }
									is_ship_size = blink_ship
								}
							}
						}
						create_ambient_object = {
							type = "isbs_blink_in_marker_bunny_object"
						}
						last_created_ambient_object = {
							set_ambient_object_flag = "isbs_blink_in"
							set_location = {
								target = event_target:blink_loc
								distance = 0.1
								angle = random
							}
						}

						create_ambient_object = {
							type = "isbs_blink_out_bunny_object"
						}
						last_created_ambient_object = {
							set_ambient_object_flag = "isbs_blink_out"
						}

						# delayed blink
						fleet_event = { id = isbs_blink.7 days = 5}
						set_timed_fleet_flag = { flag = flag_blink_cooldown days = 60 }
						PREV = { set_timed_country_flag = { flag = flag_fleet_blinking days = 6 } }
						set_event_locked = yes
					}

					else = {
						if = {
							limit = {
								check_variable = {
									which = "blink_fleet_selector"
									value = 102
								}
							}
							random_owned_fleet = {
								limit = {
									is_in_combat = yes
									has_fleet_flag = flag_can_blink
									NOT = { has_fleet_flag = flag_blink_cooldown }
									check_variable = {
										which = "blink_fleet_id"
										value = 102
									}
									SOLAR_SYSTEM = {
										any_ship_in_system = {
											FLEET = { is_same_value = PREVPREVPREV }
											is_ship_size = blink_ship
										}
									}
								}
								create_ambient_object = {
									type = "isbs_blink_in_marker_bunny_object"
								}
								last_created_ambient_object = {
									set_ambient_object_flag = "isbs_blink_in"
									set_location = {
										target = event_target:blink_loc
										distance = 0.1
										angle = random
									}
								}

								create_ambient_object = {
									type = "isbs_blink_out_bunny_object"
								}
								last_created_ambient_object = {
									set_ambient_object_flag = "isbs_blink_out"
								}

								# delayed blink
								fleet_event = { id = isbs_blink.7 days = 5}
								set_timed_fleet_flag = { flag = flag_blink_cooldown days = 60 }
								PREV = { set_timed_country_flag = { flag = flag_fleet_blinking days = 6 } }
								set_event_locked = yes
							}

							else = {
								if = {
									limit = {
										check_variable = {
											which = "blink_fleet_selector"
											value = 103
										}
									}
									random_owned_fleet = {
										limit = {
											is_in_combat = yes
											has_fleet_flag = flag_can_blink
											NOT = { has_fleet_flag = flag_blink_cooldown }
											check_variable = {
												which = "blink_fleet_id"
												value = 103
											}
											SOLAR_SYSTEM = {
												any_ship_in_system = {
													FLEET = { is_same_value = PREVPREVPREV }
													is_ship_size = blink_ship
												}
											}
										}
										create_ambient_object = {
											type = "isbs_blink_in_marker_bunny_object"
										}
										last_created_ambient_object = {
											set_ambient_object_flag = "isbs_blink_in"
											set_location = {
												target = event_target:blink_loc
												distance = 0.1
												angle = random
											}
										}

										create_ambient_object = {
											type = "isbs_blink_out_bunny_object"
										}
										last_created_ambient_object = {
											set_ambient_object_flag = "isbs_blink_out"
										}

										# delayed blink
										fleet_event = { id = isbs_blink.7 days = 5}
										set_timed_fleet_flag = { flag = flag_blink_cooldown days = 60 }
										PREV = { set_timed_country_flag = { flag = flag_fleet_blinking days = 6 } }
										set_event_locked = yes
									}
									# blink failed
									else = {
										country_event = { id = isbs_blink.198 }
									}
								}
							}
						}
					}
				}
			}
		}

		if = {
			limit = {
				exists = event_target:blink_loc
			}
			clear_global_event_target = blink_loc
		}

		every_ambient_object = {
			limit = { has_ambient_object_flag = isbs_blink_marker }
			destroy_ambient_object = THIS
		}
	}
}

isbs_ebutton_blink_auto_turn_on = {
	potential = {
		has_country_flag = flag_blink_button
		NOT = { has_country_flag = flag_blink_mode }
		NOT = { has_country_flag = flag_blink_auto_on_country }
		NOT = { has_country_flag = flag_rag_mode }
	}
	allow = {
		NOT = { has_country_flag = flag_fleet_blinking }
	}

	effect = {
		custom_tooltip = "isbs_blink_auto_fail"
		if = {
			limit = {
				check_variable = {
					which = "blink_fleet_selector"
					value = 100
				}
			}
			random_owned_fleet = {
				limit = {
					is_in_combat = yes
					has_fleet_flag = flag_can_blink
					check_variable = {
						which = "blink_fleet_id"
						value = 100
					}
					SOLAR_SYSTEM = {
						any_ship_in_system = {
							FLEET = { is_same_value = PREVPREVPREV }
							is_ship_size = blink_ship
						}
					}
				}

				if = {
					limit = { has_fleet_flag = flag_blink_auto_on }
					remove_fleet_flag = flag_blink_auto_on
					PREV = { remove_country_flag = flag_blink_auto_on_country }
					# Auto blink is on right now
					custom_tooltip = "isbs_blink_auto_off"	#blink

					else = {
						set_fleet_flag = flag_blink_auto_on
						PREV = { set_country_flag = flag_blink_auto_on_country }
						custom_tooltip = "isbs_blink_auto_on"	#blink

						fleet_event = { id = isbs_blink.9 days = 15 }
					}
				}
			}

			else = {
				if = {
					limit = {
						check_variable = {
							which = "blink_fleet_selector"
							value = 101
						}
					}
					random_owned_fleet = {
						limit = {
							is_in_combat = yes
							has_fleet_flag = flag_can_blink
							check_variable = {
								which = "blink_fleet_id"
								value = 101
							}
							SOLAR_SYSTEM = {
								any_ship_in_system = {
									FLEET = { is_same_value = PREVPREVPREV }
									is_ship_size = blink_ship
								}
							}
						}
						if = {
							limit = { has_fleet_flag = flag_blink_auto_on }
							remove_fleet_flag = flag_blink_auto_on
							PREV = { remove_country_flag = flag_blink_auto_on_country }
							#Auto blink is on right now
							custom_tooltip = "isbs_blink_auto_off"	#blink

							else = {
								set_fleet_flag = flag_blink_auto_on
								PREV = { set_country_flag = flag_blink_auto_on_country }
								custom_tooltip = "isbs_blink_auto_on"	#blink

								fleet_event = { id = isbs_blink.9 days = 15 }
							}
						}
					}

					else = {
						if = {
							limit = {
								check_variable = {
									which = "blink_fleet_selector"
									value = 102
								}
							}
							random_owned_fleet = {
								limit = {
									is_in_combat = yes
									has_fleet_flag = flag_can_blink
									check_variable = {
										which = "blink_fleet_id"
										value = 102
									}
									SOLAR_SYSTEM = {
										any_ship_in_system = {
											FLEET = { is_same_value = PREVPREVPREV }
											is_ship_size = blink_ship
										}
									}
								}
								if = {
									limit = { has_fleet_flag = flag_blink_auto_on }
									remove_fleet_flag = flag_blink_auto_on
									PREV = { remove_country_flag = flag_blink_auto_on_country }
									# Auto blink is on right now
									custom_tooltip = "isbs_blink_auto_off"	#blink

									else = {
										set_fleet_flag = flag_blink_auto_on
										PREV = { set_country_flag = flag_blink_auto_on_country }
										custom_tooltip = "isbs_blink_auto_on"	#blink

										fleet_event = { id = isbs_blink.9 days = 15 }
									}
								}
							}

							else = {
								if = {
									limit = {
										check_variable = {
											which = "blink_fleet_selector"
											value = 103
										}
									}
									random_owned_fleet = {
										limit = {
											is_in_combat = yes
											has_fleet_flag = flag_can_blink
											check_variable = {
												which = "blink_fleet_id"
												value = 103
											}
											SOLAR_SYSTEM = {
												any_ship_in_system = {
													FLEET = { is_same_value = PREVPREVPREV }
													is_ship_size = blink_ship
												}
											}
										}
										if = {
											limit = { has_fleet_flag = flag_blink_auto_on }
											remove_fleet_flag = flag_blink_auto_on
											PREV = { remove_country_flag = flag_blink_auto_on_country }
											# Auto blink is ON, clicking will turn it off
											custom_tooltip = "isbs_blink_auto_off"

											else = {
												set_fleet_flag = flag_blink_auto_on
												PREV = { set_country_flag = flag_blink_auto_on_country }
												custom_tooltip = "isbs_blink_auto_on"	#blink

												fleet_event = { id = isbs_blink.9 days = 15 }
											}
										}
									}
									# Invalid Fleet
									else = {
										custom_tooltip = "isbs_blink_auto_invalid"
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
isbs_ebutton_blink_auto_turn_off = {
	potential = {
		has_country_flag = flag_blink_button
		NOT = { has_country_flag = flag_blink_mode }
		NOT = { has_country_flag = flag_rag_mode }
		has_country_flag = flag_blink_auto_on_country
	}
	allow = {
		NOT = { has_country_flag = flag_fleet_blinking }
	}

	effect = {
		custom_tooltip = "isbs_blink_auto_fail"
		if = {
			limit = {
				check_variable = {
					which = "blink_fleet_selector"
					value = 100
				}
			}
			random_owned_fleet = {
				limit = {
					is_in_combat = yes
					has_fleet_flag = flag_can_blink
					check_variable = {
						which = "blink_fleet_id"
						value = 100
					}
					SOLAR_SYSTEM = {
						any_ship_in_system = {
							FLEET = { is_same_value = PREVPREVPREV }
							is_ship_size = blink_ship
						}
					}
				}

				if = {
					limit = { has_fleet_flag = flag_blink_auto_on }
					remove_fleet_flag = flag_blink_auto_on
					PREV = { remove_country_flag = flag_blink_auto_on_country }
					custom_tooltip = "isbs_blink_auto_off"	#blink

					else = {
						set_fleet_flag = flag_blink_auto_on
						PREV = { set_country_flag = flag_blink_auto_on_country }
						custom_tooltip = "isbs_blink_auto_on"	#blink

						fleet_event = { id = isbs_blink.9 days = 15 }
					}
				}
			}

			else = {
				if = {
					limit = {
						check_variable = {
							which = "blink_fleet_selector"
							value = 101
						}
					}
					random_owned_fleet = {
						limit = {
							is_in_combat = yes
							has_fleet_flag = flag_can_blink
							check_variable = {
								which = "blink_fleet_id"
								value = 101
							}
							SOLAR_SYSTEM = {
								any_ship_in_system = {
									FLEET = { is_same_value = PREVPREVPREV }
									is_ship_size = blink_ship
								}
							}
						}
						if = {
							limit = { has_fleet_flag = flag_blink_auto_on }
							remove_fleet_flag = flag_blink_auto_on
							PREV = { remove_country_flag = flag_blink_auto_on_country }
							custom_tooltip = "isbs_blink_auto_off"	#blink

							else = {
								set_fleet_flag = flag_blink_auto_on
								PREV = { set_country_flag = flag_blink_auto_on_country }
								custom_tooltip = "isbs_blink_auto_on"	#blink

								fleet_event = { id = isbs_blink.9 days = 15 }
							}
						}
					}

					else = {
						if = {
							limit = {
								check_variable = {
									which = "blink_fleet_selector"
									value = 102
								}
							}
							random_owned_fleet = {
								limit = {
									is_in_combat = yes
									has_fleet_flag = flag_can_blink
									check_variable = {
										which = "blink_fleet_id"
										value = 102
									}
									SOLAR_SYSTEM = {
										any_ship_in_system = {
											FLEET = { is_same_value = PREVPREVPREV }
											is_ship_size = blink_ship
										}
									}
								}
								if = {
									limit = { has_fleet_flag = flag_blink_auto_on }
									remove_fleet_flag = flag_blink_auto_on
									PREV = { remove_country_flag = flag_blink_auto_on_country }
									custom_tooltip = "isbs_blink_auto_off"	#blink

									else = {
										set_fleet_flag = flag_blink_auto_on
										PREV = { set_country_flag = flag_blink_auto_on_country }
										custom_tooltip = "isbs_blink_auto_on"	#blink

										fleet_event = { id = isbs_blink.9 days = 15 }
									}
								}
							}

							else = {
								if = {
									limit = {
										check_variable = {
											which = "blink_fleet_selector"
											value = 103
										}
									}
									random_owned_fleet = {
										limit = {
											is_in_combat = yes
											has_fleet_flag = flag_can_blink
											check_variable = {
												which = "blink_fleet_id"
												value = 103
											}
											SOLAR_SYSTEM = {
												any_ship_in_system = {
													FLEET = { is_same_value = PREVPREVPREV }
													is_ship_size = blink_ship
												}
											}
										}
										if = {
											limit = { has_fleet_flag = flag_blink_auto_on }
											remove_fleet_flag = flag_blink_auto_on
											PREV = { remove_country_flag = flag_blink_auto_on_country }
											custom_tooltip = "isbs_blink_auto_off"	#blink

											else = {
												set_fleet_flag = flag_blink_auto_on
												PREV = { set_country_flag = flag_blink_auto_on_country }
												custom_tooltip = "isbs_blink_auto_on"	#blink

												fleet_event = { id = isbs_blink.9 days = 15 }
											}
										}
									}
									# Invalid Fleet
									else = {
										custom_tooltip = "isbs_blink_auto_invalid"
									}
								}
							}
						}
					}
				}
			}
		}
	}
}