#################################
#
# Namarian Events (formerly Nomad Events)
# by Niclas Karlsson & Maximilian Olbers
#
#################################

namespace = namarian

#Create Nomads
country_event = {
	id = namarian.1
	hide_window = yes #DEBUG TO NO TO SEE WHERE THE NOMADS SPAWN
	location = event_target:nomad_spawn
	is_triggered_only = yes

	trigger = {
		has_megacorp = no # nomads can't compete with caravaneers
		NOT = { exists = event_target:nomad01_country }
	}

	immediate = {
		random_rim_system = {
			limit = {
				NOR = {
					any_playable_country = {
						intel_level = {
							level > low
							system = prev
						}
					}
					has_star_flag = hostile_system
				}
			}
			random_system = {
				limit = {
					NOT = {
						has_star_flag = hostile_system
					}
					distance = {
						source = PREV
						min_distance >= 250 #5
						max_distance <= 500 #50
					}
				}
				set_star_flag = nomad_mid_point
			}
			if = {
				limit = {
					NOT = {
						any_system = {
							has_star_flag = nomad_mid_point
						}
					}
				}
				random_system = {
					limit = {
						distance = {
							source = PREV
							min_distance >= 150
							max_distance <= 500
						}
					}
					set_star_flag = nomad_mid_point
				}
			}
			random_rim_system = {
				limit = {
					distance = {
						source = PREV
						min_distance >= 400 #50
						#Distance trigger distances are squared and stored in CFixedPoint which will overflow at values larger than +-2^31/1000 ~= +-2147483
						#Largest value for a distance trigger distance is therefore sqrt(2147483) ~= +-1465
						max_distance <= 1450 #9999 #100
					}
				}
				set_star_flag = nomad_end_point
			}
			if = {
				limit = {
					NOT = {
						any_system = {
							has_star_flag = nomad_end_point
						}
					}
				}
				random_rim_system = {
					limit = {
						distance = {
							source = PREV
							min_distance >= 250
							#Distance trigger distances are squared and stored in CFixedPoint which will overflow at values larger than +-2^31/1000 ~= +-2147483
							#Largest value for a distance trigger distance is therefore sqrt(2147483) ~= +-1465
							max_distance <= 1450 #9999
						}
					}
					set_star_flag = nomad_end_point
				}
			}
			create_species = {
				name = NAME_Namarian
				plural = "NAME_Namarian_plural"
				adjective = "NAME_Namarian"
				class = AVI
				portrait = random
				traits = {
					trait = "trait_nomadic"
					trait = "trait_venerable"
					trait = "trait_natural_engineers"
					trait = "trait_pc_desert_preference"
				}
				immortal = yes
			}
			last_created_species = {
				save_global_event_target_as = base_namarian
			}
			create_country = {
				name = "NAME_Galactic_Nomads"
				type = nomad
				species = last_created_species
				flag = {
					icon = {
						category = "spherical"
						file = "flag_spherical_8.dds"
					}
					background= {
						category = "backgrounds"
						file = "circle.dds"
					}
					colors={
						"purple"
						"indigo"
						"null"
						"null"
					}
				}
			}
			last_created_country = {
				set_country_flag = nomad01_country_flag
				save_global_event_target_as = nomad01_country
				add_modifier = {
					modifier = nomad_strength
					days = -1
				}
			}
			random_system_planet = {
				set_carrier_flag = nomad_starting_point
				save_event_target_as = nomad_spawn
			}
			event_target:nomad01_country = {
				create_leader = {
					class = commander
					species = owner_main_species
					name = random
					skill = 2
				}
				create_fleet = {
					name = "NAME_Nomadic_Armada"
					effect = {
						set_owner = PREV
						set_fleet_flag = nomad_main_fleet
						set_fleet_stance = passive
						set_aggro_range_measure_from = self
						set_aggro_range = 50
						#while = {
						#	count = 15
						#	create_ship = {
						#		name = "NAME_Defender"
						#		design = NAME_Defender
						#	}
						#}
						while = {
							#count = 6
							count = 20
							create_ship = {
								name = "NAME_Protector"
								design = NAME_Protector
							}
						}
						create_ship = {
							name = "NAME_Home_One"
							design = NAME_Diaspora
						}
						create_ship = {
							name = "NAME_Home_Two"
							design = NAME_Diaspora
						}
						create_ship = {
							name = "NAME_Home_Three"
							design = NAME_Diaspora
						}
						#create_ship = {
						#	name = "NAME_Home_Four"
						#	design = Diaspora
						#}
						#create_ship = {
						#	name = "NAME_Home_Five"
						#	design = Diaspora
						#}
						assign_leader = last_created_leader
						set_location = event_target:nomad_spawn
						set_fleet_flag = nomad_fleet
						set_formation_scale = 1.6
						fleet_event = { id = namarian.2 days = 1 } #Nomads fly towards current destination
						save_event_target_as = CustomCapital
					}
				}
			}
		}
	}
}

#Set ending destination
fleet_event = {
	id = namarian.2
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = { is_country_type = nomad }
		NOT = { has_fleet_flag = nomad_on_mission }
	}

	immediate = {
		clear_fleet_actions = this
		if = {
			limit = {
				owner = {
					NOT = { has_country_flag = nomad_mid_point_reached }
				}
			}
			queue_actions = {
				find_random_system = {
					trigger = {
						id = namarian.2.trigger.1
						has_star_flag = nomad_mid_point
					}
					found_system = {
						move_to = this
					}
				}
			}
		}
		else = {
			queue_actions = {
				find_random_system = {
					trigger = {
						id = namarian.2.trigger.2
						has_star_flag = nomad_end_point
					}
					found_system = {
						move_to = this
					}
				}
			}
		}
	}
}

# on_entering_system_fleet:
#Check if there's anyone to take contact with in new system, otherwise go check other stuff
fleet_event = {
	id = namarian.3
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = { is_country_type = nomad }
		NOT = { has_fleet_flag = nomad_on_mission }
	}

	immediate = {
		clear_fleet_actions = this
		save_event_target_as = nomad_fleet
		owner = {
			save_event_target_as = nomad_owner
		}
		if = {
			limit = {
				from = {
					exists = space_owner
					space_owner = {
						OR = {
							is_country_type = default
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
						NOR = {
							is_hostile = event_target:nomad_owner
							has_communications = event_target:nomad_owner
						}
					}
				}
			}
			from = {
				space_owner = {
					save_event_target_as = nomad_contact_country
				}
			}
		}
		if = { # If the current space is owned stay put within borders and contact owners after 100 days
			limit = {
				from = {
					exists = space_owner
					space_owner = {
						OR = {
							is_country_type = default
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
						NOR = {
							is_hostile = event_target:nomad_owner
							has_communications = event_target:nomad_owner
						}
					}
				}
			}
			queue_actions = {
				repeat = {
					max_iterations = 1
					find_closest_planet = {
						trigger = {
							id = namarian.3.trigger.1
							is_capital = no
						}
						found_planet = {
							orbit_planet = this
						}
					}
					effect = {
						id = namarian.3.begin_contact
						event_target:nomad_owner = {
							set_variable = {
								which = nomad_waited_days_translation
								value = 0
							}
							#country_event = { id = namarian.991 }
						}
					}
				}
				effect = {
					id = "namarian.3.translation_time_out"
					if = {
						limit = {
							event_target:nomad_contact_country = {
								NOT = { is_hostile = event_target:nomad_owner }
							}
							from = {
								NOT = { has_star_flag = hostile_system }
							}
							exists = space_owner
						}
						fleet_event = { id = namarian.4 days = 1 } #Take action inside system
					}
					else = {
						fleet_event = { id = namarian.2 days = 1 } #Fly somewhere else
					}
				}
			}
		}
		else_if = {
			# If space owner is hostile
			limit = {
				from = {
					exists = space_owner
					space_owner = {
						OR = {
							is_country_type = default
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
						is_hostile = event_target:nomad_owner
					}
				}
			}
			fleet_event = { id = namarian.2 } #Nomads fly towards current destination
			owner = {
				#country_event = { id = namarian.992 }
			}
		}
		else_if = {
			# If space owner should be ignored by Nomads
			limit = {
				from = {
					exists = space_owner
					space_owner = {
						OR = {
							is_country_type = default
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
					}
				}
			}
			fleet_event = { id = namarian.2 } #Nomads fly towards current destination
			owner = {
				#country_event = { id = namarian.993 }
			}
		}
		else = { #If no country owns this system
			fleet_event = { id = namarian.5 } #Nomads hang out in ownerless system
			owner = {
				#country_event = { id = namarian.994 }
			}
		}
	}
}

# Take actions in owned system after establishing contact
fleet_event = {
	id = namarian.4
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			is_country_type = nomad
			NOT = {
				reverse_has_relation_flag = { flag = nomad_relation_hate who = root.space_owner }
			}
		}
		solar_system = {
			exists = space_owner
			NOT = {
				has_star_flag = hostile_system
			}
		}
	}

	immediate = {
		clear_fleet_actions = this
		owner = {
			save_event_target_as = nomad_country
		}
		random_list = {
			30 = { #Ask for owner to take in pops
				modifier = {
					factor = 0
					event_target:nomad_contact_country = {
						NOR = {
							any_owned_planet = {
								#free_housing > 0
								OR = {
									is_planet_class = pc_desert
									is_planet_class = pc_arid
									is_planet_class = pc_savannah
								}
							}
							is_hive_empire = yes
						}
					}
				}
				modifier = {
					factor = 0.75
					owner = {
						has_country_flag = nomad_left_stragglers
					}
				}
				modifier = {
					factor = 1.5
					event_target:nomad_contact_country = {
						OR = {
							is_xenophile = yes
							is_egalitarian = yes
							is_spiritualist = yes
						}
					}
					owner = {
						NOT = {
							has_country_flag = nomad_left_stragglers
						}
					}
				}
				modifier = {
					factor = 0.30
					event_target:nomad_contact_country = {
						allows_slavery = yes
					}
				}
				fleet_event = { id = namarian.20 }
			}
			30 = { #Ask for a planet to settle on
				modifier = {
					factor = 0
					event_target:nomad_contact_country = {
						NOR = {
							any_planet_within_border = {
								is_colony = no
								OR = {
									is_planet_class = pc_tundra
									is_planet_class = pc_arid
									is_planet_class = pc_desert
									is_planet_class = pc_tropical
									is_planet_class = pc_continental
									is_planet_class = pc_gaia
								}
							}
							is_hive_empire = yes
						}
					}
				}
				modifier = {
					factor = 0.5
					owner = {
						has_country_flag = nomad_settled
					}
				}
				modifier = {
					factor = 1.75
					event_target:nomad_contact_country = {
						OR = {
							is_xenophile = yes
							is_egalitarian = yes
							is_spiritualist = yes
						}
					}
					owner = {
						NOT = {
							has_country_flag = nomad_settled
						}
					}
				}
				fleet_event = { id = namarian.40 }
			}
			30 = { #Sell ships
				modifier = {
					factor = 0
					event_target:nomad_contact_country = {
						has_country_flag = nomad_ship_trade
					}
				}
				modifier = {
					factor = 0.25
					event_target:nomad_contact_country = {
						OR = {
							has_ethic = ethic_fanatic_militarist
							has_ethic = ethic_fanatic_xenophobe
						}
					}
				}
				modifier = {
					factor = 0.5
					owner = {
						has_country_flag = nomad_ships_sold
					}
				}
				modifier = {
					factor = 1.75
					event_target:nomad_contact_country = {
						OR = {
							is_xenophile = yes
							is_egalitarian = yes
							is_spiritualist = yes
						}
					}
					owner = {
						NOT = {
							has_country_flag = nomad_ships_sold
						}
					}
				}
				fleet_event = { id = namarian.499 }
			}
			10 = { #Ignore country
				fleet_event = { id = namarian.2 }
				owner = {
					#country_event = { id = namarian.996 }
				}
			}
		}
	}
}

#Actions taken in peaceful system without owner
fleet_event = {
	id = namarian.5
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = { is_country_type = nomad }
		NOT = { has_fleet_flag = nomad_on_mission }
		solar_system = {
			NOR = {
				exists = space_owner
				has_star_flag = hostile_system
				has_star_flag = nomad_mid_point
				has_star_flag = nomad_end_point
			}
		}
	}

	immediate = {
		random_list = {
			10 = { #Fly to random planet and construct more ships
				modifier = {
					factor = 10
					owner = { fleet_power < 3000 }
				}
				modifier = {
					factor = 5
					owner = { fleet_power < 5000 }
				}
				#modifier = {
				#	factor = 0.5
				#	owner = { fleet_power > 5000 }
				#}
				modifier = {
					factor = 0
					OR = {
						owner = { fleet_power > 10000 }
						has_fleet_flag = nomad_built_new_ships
					}
				}
				owner = {
					if = {
						limit = {
							check_variable = {
								which = nomads_built_ships
								value > 0
							}
						}
						change_variable = {
							which = nomads_built_ships
							value = 0
						}
					}
					else_if = {
						limit = {
							NOT = {
								check_variable = {
									which = nomads_built_ships
									value = 0
								}
							}
						}
						set_variable = {
							which = nomads_built_ships
							value = 0
						}
					}
				}
				queue_actions = {
					repeat = {
						max_iterations = 1
						find_random_planet = {
							found_planet = {
								orbit_planet = this
							}
							failed = {
								effect = {
									id = "namarian.5.leaving_safe_system_3"
									root = {
										fleet_event = { id = namarian.2 } #Nomads fly towards current destination
										owner = {
											#country_event = { id = namarian.995 }
										}
									}
								}
							}
						}
					}
					repeat = {
						while = {
							id = namarian.5.trigger.1
							NOT = { has_fleet_flag = nomad_built_new_ships }
						}
						wait = {
							duration = 30
							random = 10
						}
						effect = {
							id = "namarian.5.repairing_ships"
							owner = {
								every_controlled_ship = {
									limit = {
										fleet = {
											has_fleet_flag = nomad_main_fleet
										}
									}
									repair_ship = yes
								}
							}
						}
						wait = {
							duration = 30
							random = 10
						}
						effect = {
							id = "namarian.5.building_ships"
							owner = {
								change_variable = {
									which = nomads_built_ships
									value = 1
								}
							}
							create_ship = {
								name = "NAME_Defender"
								design = NAME_Defender
							}
							create_ship = {
								name = "NAME_Defender"
								design = NAME_Defender
							}
							create_ship = {
								name = "NAME_Defender"
								design = NAME_Defender
							}
							create_ship = {
								name = "NAME_Defender"
								design = NAME_Defender
							}
							create_ship = {
								name = "NAME_Protector"
								design = NAME_Protector
							}
							create_ship = {
								name = "NAME_Protector"
								design = NAME_Protector
							}
							random_list = {
								50 = {
									modifier = {
										factor = 0
										owner = {
											fleet_power < 1500
										}
									}
									modifier = {
										factor = 5
										owner = {
											check_variable = {
												which = nomads_built_ships
												value > 4
											}
										}
									}
									set_timed_fleet_flag = { flag = nomad_built_new_ships days = 120 }
								}
								50 = {
									modifier = {
										factor = 10
										owner = {
											fleet_power < 3000
										}
									}
									modifier = {
										factor = 0.5
										owner = {
											fleet_power > 3000
										}
									}
									modifier = {
										factor = 0.2
										owner = {
											fleet_power > 5000
										}
									}
									modifier = {
										factor = 0
										owner = {
											fleet_power > 10000
										}
									}
								}
							}
						}
					}
					repeat = {
						max_iterations = 1
						effect = {
							id = "namarian.5.built_ships"
							fleet_event = { id = namarian.2 } #Nomads fly towards current destination
							owner = {
								#country_event = { id = namarian.995 }
							}
						}
					}
				}
			}
			80 = { #Fly to random planet and hang around for a bit
				modifier = {
					factor = 0
					owner = {
						fleet_power < 1500
					}
				}
				queue_actions = {
					repeat = {
						max_iterations = 3
						while = {
							id = namarian.5.trigger.2
							owner = {
								NOT = { has_country_flag = nomad_exploring_done }
							}
						}
						find_random_planet = {
							found_planet = {
								orbit_planet = this
							}
							failed = {
								effect = {
									id = "namarian.5.leaving_safe_system_2"
									root = {
										fleet_event = { id = namarian.2 } #Nomads fly towards current destination
										owner = {
											#country_event = { id = namarian.995 }
										}
									}
								}
							}
						}
						wait = {
							duration = 40
							random = 10
						}
						effect = {
							id = "namarian.5.keep_looking_or_not"
							owner = {
								random_list = {
									25 = {
										set_timed_country_flag = { flag = nomad_exploring_done days = 3 }
									}
									75 = {}
								}
							}
						}
					}
					effect = {
						id = "namarian.5.leaving_safe_system_1"
						root = {
							fleet_event = { id = namarian.2 } #Nomads fly towards current destination
							owner = {
								#country_event = { id = namarian.995 }
							}
						}
					}
				}
			}
			10 = { } #Do nothing
		}
	}
}

# Nomads reach mid point and set sails for next destination if not busy
fleet_event = {
	id = namarian.7
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = { is_country_type = nomad }
		has_fleet_flag = nomad_main_fleet
		solar_system = {
			has_star_flag = nomad_mid_point
		}
	}

	immediate = {
		#clear_fleet_actions = this
		owner = { set_country_flag = nomad_mid_point_reached }
		if = {
			limit = {
				NOT = {
					has_fleet_flag = nomad_on_mission
				}
			}
			fleet_event = { id = namarian.2 }
		}
	}
}
# Nomads reach end point and disappear
fleet_event = {
	id = namarian.8
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = { is_country_type = nomad }
		has_fleet_flag = nomad_main_fleet
		solar_system = {
			has_star_flag = nomad_end_point
		}
	}

	immediate = {
		#clear_fleet_actions = this
		destroy_fleet = this
		every_country = {
			limit = {
				has_country_flag = nomads_contacted
			}
			country_event = { id = namarian.9 } #Nomads send their last regards
		}
	}
}

# Nomads send parting message to countries they've contacted
country_event = {
	id = namarian.9
	title = namarian.10.name
	desc = namarian.9.desc
	picture = GFX_evt_federation_fleet
	show_sound = event_radio_chatter
	location = fromfrom

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		is_ai = no
		exists = capital_scope
		has_country_flag = nomads_contacted
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = "namarian.9.a"
		trigger = {
			NOR = {
				is_xenophile = yes
				is_xenophobe = yes
			}
		}
	}
	option = {
		name = "namarian.9.a.phobe"
		trigger = {
			is_xenophobe = yes
		}
	}
	option = {
		name = "namarian.9.c.phile"
		trigger = {
			is_xenophile = yes
		}
	}
}

# Nomads take contact
country_event = {
	id = namarian.10
	title = namarian.10.name
	desc = namarian.10.desc

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	diplomatic = yes
	is_triggered_only = yes

	immediate = {
		from.contact_country = {
			save_event_target_as = contact_speaker
			save_event_target_as = contact_empire
			random_controlled_ship = {
				fleet = {
					leader = { save_event_target_as = contact_speaker_leader }
				}
			}
		}
		event_target:contact_speaker = {
			establish_communications_no_message = root
		}
		set_country_flag = nomads_contacted
	}

	option = { #friendly
		name = {
			text = action.1.selective
			trigger = {
				has_valid_civic = civic_selective_kinship
				event_target:contact_empire = {
					is_same_species_class = root
				}
			}
		}
		name = {
			text = action.1.e
			trigger = {
				NOT = { is_same_species = event_target:contact_empire }
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.c
			trigger = {
				NOT = { is_same_species = event_target:contact_empire }
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.h
			trigger = {
				is_egalitarian = yes
			}
		}
		name = {
			text = action.1.n
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = { is_machine_empire = no }
			}
		}
		name = {
			text = action.1.ag
			trigger = {
				is_materialist = yes
			}
		}
		name = {
			text = action.1.ah
			trigger = {
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.ai
			trigger = {
				is_xenophile = yes
				is_egalitarian = yes
			}
		}
		name = {
			text = action.1.aj
			trigger = {
				is_xenophile = yes
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.ak
			trigger = {
				OR = {
					is_xenophile = yes
					is_militarist = yes
				}
			}
		}
		name = {
			text = action.1.al
			trigger = {
				is_egalitarian = yes
			}
		}
		name = {
			text = action.1.am
			trigger = {
				is_spiritualist = yes
			}
		}
		name = {
			text = action.1.j
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = action.1.l
			trigger = {
				is_pacifist = yes
			}
		}
		name = {
			text = action.1.p
			trigger = {
				is_materialist = yes
			}
		}
		name = {
			text = action.1.av
			trigger = {
				is_spiritualist = yes
			}
		}
		name = {
			text = action.1.aag
			trigger = {
				has_origin = origin_lost_colony
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = {
			text = action.1.hm
			trigger = {
				is_hive_empire = yes
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
			}
		}
		name = {
			text = action.1.me
			trigger = {
				is_machine_empire = yes
				NOT = { has_valid_civic = civic_machine_terminator }
			}
		}
		name = {
			text = action.1.mtm
			trigger = {
				has_valid_civic = civic_machine_terminator
				event_target:contact_empire = { is_machine_empire = yes }
			}
		}
		name = {
			text = action.1.o
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = { is_machine_empire = no }
			}
		}
		name = {
			text = action.1.as
			trigger = {
				is_pacifist = yes
			}
		}
		name = {
			text = action.1.af
			trigger = {
				is_xenophobe = yes
			}
		}

		icon = {
			icon = GFX_option_icon_friendly
			text = seek_friends_tt
		}

		allow = {
			custom_tooltip_fail = {
				text = friendship_already_precluded
				event_target:contact_empire = {
					NOR = {
						has_opinion_modifier = {
							who = root
							modifier = opinion_caught_hacking
						}
						has_opinion_modifier = {
							who = root
							modifier = opinion_hostile_first_contact
						}
						has_opinion_modifier = {
							who = root
							modifier = opinion_hostile_first_contact_vivisection
						}
						has_opinion_modifier = {
							who = root
							modifier = opinion_hostile_first_contact_hungry
						}
					}
				}
			}
		}

		if = {
			limit = {
				OR = {
					NOT = { is_country_type = default }
					event_target:contact_empire = { is_country_type = fallen_empire }
				}
			}
			custom_tooltip = action.1.fe_option
		}
		else = {
			custom_tooltip = seek_friends_tt

			event_target:contact_empire = {
				add_opinion_modifier = {
					who = root
					modifier = opinion_friendly_first_comms_greeting
				}
			}
		}

		trigger = {
			OR = {
				is_homicidal = no
				AND = {
					has_valid_civic = civic_machine_terminator
					event_target:contact_empire = { is_machine_empire = yes }
				}
			}
			NOT = { has_valid_civic = civic_inwards_perfection }
			NAND = {
				has_valid_civic = civic_selective_kinship
				event_target:contact_empire = { NOT = { is_same_species_class = root } }
			}
			NAND = {
				is_fanatic_spiritualist = yes
				event_target:contact_empire = { is_machine_empire = yes }
			}
			OR = {
				NOT = { is_fanatic_xenophobe = yes }
				event_target:contact_empire = { is_same_species = root }
				AND = {
					has_valid_civic = civic_selective_kinship
					event_target:contact_empire = { is_same_species_class = root }
				}
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				is_xenophile = yes
			}
			modifier = {
				factor = 0.5
				OR = {
					is_xenophobe = yes
					is_gestalt = yes
				}
			}
			modifier = {
				factor = 4 #actually *2 as it is multiplied by *0.5 in the above modifier
				OR = {
					AND = {
						is_machine_empire = yes
						event_target:contact_empire = { is_machine_empire = yes }
					}
					AND = {
						is_hive_empire = yes
						event_target:contact_empire = { is_hive_empire = yes }
					}
				}
			}
			modifier = {
				factor = 0.1
				first_contact_custom_greeting = yes #basically, various hostility
			}
		}
	}
	option = { #hostile - isolationist
		name = {
			text = action.1.ac
			trigger = {
				is_xenophobe = yes
			}
		}
		name = {
			text = action.1.aab
			trigger = {
				OR = {
					is_xenophobe = yes
					is_materialist = yes
				}
				NOT = { is_same_species = event_target:contact_empire }
			}
		}
		name = {
			text = action.1.ad
			trigger = {
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.d
			trigger = {
				NOT = { is_same_species = event_target:contact_empire }
				is_xenophobe = yes
			}
		}
		name = {
			text = action.1.i
			trigger = {
				is_egalitarian = yes
			}
		}
		name = {
			text = action.1.m
			trigger = {
				is_pacifist = yes
			}
		}
		name = {
			text = action.1.r
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = { is_machine_empire = yes }
			}
		}
		name = {
			text = action.1.aa
			trigger = {
				is_materialist = yes
			}
		}
		name = {
			text = action.1.ao
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = action.1.aaa
			trigger = {
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.aae
			trigger = {
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.t1
			trigger = {
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.t2
			trigger = {
				is_spiritualist = yes
			}
		}
		name = {
			text = action.1.t3
			trigger = {
				is_hive_empire = yes
			}
		}
		name = {
			text = action.1.t4
			trigger = {
				is_machine_empire = yes
				NOR = {
					has_valid_civic = civic_machine_assimilator
					has_valid_civic = civic_machine_terminator
				}
			}
		}
		name = {
			text = action.1.t5
			trigger = {
				has_valid_civic = civic_machine_assimilator
			}
		}
		name = {
			text = action.1.t6
			trigger = {
				has_valid_civic = civic_machine_terminator
			}
		}

		icon = {
			icon = GFX_option_icon_isolationist
			text = seek_isolation_tt_short
		}

		if = {
			limit = {
				OR = {
					NOT = { is_country_type = default }
					event_target:contact_empire = { NOT = { is_country_type = default } }
				}
			}
			custom_tooltip = action.1.fe_option
		}
		else = {
			custom_tooltip = seek_isolation_tt

			hidden_effect = {
				event_target:contact_empire = {
					random_spynetwork = {
						limit = { target = { is_same_value = root } }
						add_modifier = {
							modifier = first_comms_defensive
							years = 15
						}
					}
				}
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				is_xenophobe = yes
				is_militarist = no
			}
			modifier = {
				factor = 2
				has_valid_civic = civic_inwards_perfection
			}
		}
	}
	option = { #hostile - expansionist
		name = {
			text = action.1.ae
			trigger = {
				OR = {
					is_xenophobe = yes
					is_militarist = yes
				}
			}
		}
		name = {
			text = action.1.ds
			trigger = {
				has_valid_civic = civic_hive_devouring_swarm
			}
		}
		name = {
			text = action.1.mt
			trigger = {
				is_machine_empire = yes
			}
		}
		name = {
			text = action.1.aac
			trigger = {
				is_militarist = yes
				OR = {
					is_spiritualist = yes
					is_authoritarian = yes
				}
			}
		}
		name = {
			text = action.1.aad
			trigger = {
				is_spiritualist = yes
				NOT = { is_same_species = event_target:contact_empire }
			}
		}
		name = {
			text = action.1.b
			trigger = {
				NOT = { is_same_species = event_target:contact_empire }
				is_xenophobe = yes
			}
		}
		name = {
			text = action.1.s
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = { is_machine_empire = yes }
			}
		}
		name = {
			text = action.1.ab
			trigger = {
				is_spiritualist = yes
				NOT = { is_same_species = event_target:contact_empire }
			}
		}
		name = {
			text = action.1.an
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = action.1.at
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = action.1.au
			trigger = {
				is_spiritualist = yes
				is_militarist = yes
			}
		}
		name = {
			text = action.1.k
			trigger = {
				OR = {
					is_militarist = yes
					is_authoritarian = yes
				}
			}
		}
		name = {
			text = action.1.ax
			trigger = {
				OR = {
					is_materialist = yes
					is_egalitarian = yes
					is_pacifist = yes
				}
			}
		}
		name = {
			text = action.1.u1
			trigger = {
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.u2
			trigger = {
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.u3
			trigger = {
				is_gestalt = yes
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
			}
		}

		icon = {
			icon = GFX_option_icon_hostile
			text = seek_enemies_tt_short
		}

		if = {
			limit = {
				OR = {
					NOT = { is_country_type = default }
					event_target:contact_empire = { NOT = { is_country_type = default } }
				}
			}
			custom_tooltip = action.1.fe_option
		}
		else = {
			custom_tooltip = seek_enemies_tt

			event_target:contact_empire = {
				add_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_comms_greeting
				}
			}
			hidden_effect = {
				random_spynetwork = {
					limit = {
						owner = { is_same_value = root }
						target = { is_same_value = event_target:contact_empire }
					}
					add_modifier = {
						modifier = first_comms_hostility_preparations
						years = 15
					}
				}
			}
		}

		trigger = {
			NOR = {
				is_fanatic_pacifist = yes
				has_valid_civic = civic_inwards_perfection
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 100
				is_homicidal = yes
			}
			modifier = {
				factor = 2
				is_militarist = yes
			}
			modifier = {
				factor = 0.5
				is_pacifist = yes
			}
			modifier = {
				factor = 2
				first_contact_custom_greeting = yes #basically, various hostility
			}
			modifier = {
				factor = 0.1
				is_in_federation_with = event_target:contact_empire #just in case
			}
		}
	}

	after = {
		if = {
			limit = {
				NOT = {
					event_target:contact_speaker = { has_relation_flag = { flag = no_coms who = root } }
				}
			}
			hidden_effect = { country_event = { id = story.7 days = 30 } }
		}
		hidden_effect = {
			end_event_chain = "nomads_observation_chain"
		}
	}
}

#Set war mission
fleet_event = {
	id = namarian.15
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = { is_country_type = nomad }
	}

	immediate = {
		owner = {
			save_event_target_as = nomad_country
			if = {
				limit = {
					check_variable = {
						which = nomads_attacked_systems
						value > 0
					}
				}
				change_variable = {
					which = nomads_attacked_systems
					value = 0
				}
			}
			else_if = {
				limit = {
					NOT = {
						check_variable = {
							which = nomads_attacked_systems
							value = 0
						}
					}
				}
				set_variable = {
					which = nomads_attacked_systems
					value = 0
				}
			}
		}
		clear_fleet_actions = this
		queue_actions = {
			repeat = {
				max_iterations = 1
				find_random_system = {
					trigger = {
						id = namarian.15.trigger.1
						exists = space_owner
						event_target:nomad_country = {
							fleet_power > 1500
						}
						space_owner = { has_country_flag = nomad_hates_you }
						any_system_planet = {
							OR = {
								has_mining_station = yes
								has_research_station = yes
							}
							is_owned_by = event_target:attacker_country
						}
					}
					found_system = {
						move_to = this
					}
				}
			}
			repeat = {
				while = {
					id = namarian.15.trigger.2
					event_target:nomad_country = {
						fleet_power > 1500
					}
					solar_system = {
						any_system_planet = {
							OR = {
								has_mining_station = yes
								has_research_station = yes
							}
							is_owned_by = event_target:attacker_country
						}
					}
				}
				find_closest_planet = {
					trigger = {
						id = namarian.15.trigger.3
						event_target:nomad_country = {
							fleet_power > 1500
						}
						OR = {
							has_mining_station = yes
							has_research_station = yes
						}
						is_owned_by = event_target:attacker_country
					}
					found_planet = {
						move_to = this
					}
					failed = {
						effect = {
							id = "namarian.15.failed"
							event_target:attacker_country = {
								remove_country_flag = nomad_hates_you
							}
							if = {
								limit = {
									has_fleet_flag = nomad_on_mission
								}
								remove_fleet_flag = nomad_on_mission
							}
							fleet_event = { id = namarian.2 } #Nomads fly towards current destination
							owner = {
								#country_event = { id = namarian.995 }
							}
						}
					}
				}
			}
			effect = {
				id = namarian.15.attack_done
				owner = {
					if = {
						limit = {
							check_variable = {
								which = nomads_attacked_systems
								value < 3
							}
						}
						change_variable = {
							which = nomads_attacked_systems
							value = 1
						}
					}
				}
				random_list = {
					50 = {
						modifier = {
							factor = 2
							owner = {
								check_variable = {
									which = nomads_attacked_systems
									value > 2
								}
							}
						}
						modifier = {
							factor = 10
							owner = {
								OR = {
									check_variable = {
										which = nomads_attacked_systems
										value > 4
									}
									fleet_power < 1500
								}
							}
						}
						if = {
							limit = {
								has_fleet_flag = nomad_on_mission
							}
							remove_fleet_flag = nomad_on_mission
						}
						fleet_event = { id = namarian.2 } #Set sail for destination
						event_target:attacker_country = {
							remove_country_flag = nomad_hates_you
						}
					}
					50 = {
						fleet_event = { id = namarian.15 } #Find new system and keep attacking the enemy
					}
				}
			}
		}
	}
}

### Nomads wants to leave pops ###
fleet_event = {
	id = namarian.20
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		owner = {
			save_event_target_as = nomad_fleet_country
		}
		set_fleet_flag = nomad_on_mission
		clear_fleet_actions = this
		event_target:nomad_contact_country = {
			random_owned_planet = {
				limit = {
					#free_housing > 0
					OR = {
						is_planet_class = pc_desert
						is_planet_class = pc_arid
						is_planet_class = pc_savannah
					}
				}
				weights = {
					base = 1
					modifier = {
						add = 5
						free_housing > 0
					}
					modifier = {
						add = 10
						free_housing > 100
					}
				}
				set_carrier_flag = nomad_mission_location
				solar_system = { set_star_flag = nomad_mission_waypoint }
			}
		}
		queue_actions = {
			repeat = {
				max_iterations = 1
				find_random_system = {
					trigger = {
						id = namarian.20.trigger.1
						has_star_flag = nomad_mission_waypoint
					}
					found_system = {
						move_to = this
					}
				}
				find_closest_planet = {
					trigger = {
						id = namarian.20.trigger.2
						has_carrier_flag = nomad_mission_location
					}
					found_planet = {
						move_to = this
						orbit_planet = this
						wait = {
							duration = 7
						}
						effect = {
							id = namarian.20.orbit_pop_planet
							event_target:nomad_contact_country = {
								country_event = { id = namarian.21 }
							}
							solar_system = {
								remove_star_flag = nomad_mission_waypoint
							}
						}
					}
					failed = {
						effect = {
							id = "namarian.20.failed"
							remove_fleet_flag = nomad_on_mission
							fleet_event = { id = namarian.2 } #Nomads fly towards current destination
							owner = {
								#country_event = { id = namarian.995 }
							}
						}
					}
				}
			}
		}
	}
}
#Nomads contact planet owner and asks them to take in pops
country_event = {
	id = namarian.21
	title = namarian.10.name
	desc = namarian.21.desc
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	trigger = {
		NOR = {
			has_country_flag = nomad_ignores
			is_hive_empire = yes
		}
	}

	immediate = {
		event_target:nomad_fleet_country = {
			random_controlled_ship = {
				fleet = {
					leader = { save_event_target_as = contact_speaker_leader }
					save_event_target_as = nomad_fleet
				}
			}
			owner_species = { save_event_target_as = nomad_fleet_species }
		}
		random_owned_planet = {
			limit = {
				has_carrier_flag = nomad_mission_location
			}
			save_event_target_as = NomadMissionPlanet
			remove_carrier_flag = nomad_mission_location
		}
	}

	option = {
		name = namarian.21.c
		response_text = namarian.21.c.response
		is_dialog_only = yes
	}
	option = {
		name = namarian.21.d
		response_text = namarian.21.d.response
		is_dialog_only = yes
	}
	option = {
		name = namarian.21.a
		response_text = namarian.21.a.response
		#is_dialog_only = yes
		custom_tooltip = namarian.21.a.tooltip
		give_specimen = {
			key = namarian_sculpture
			targets = { event_target:NomadMissionPlanet this }
		}
		hidden_effect = {
			solar_system = {
				remove_star_flag = nomad_mission_waypoint
			}
			event_target:NomadMissionPlanet = {
				while = {
					count = 3
					create_pop_group = {
						species = event_target:nomad_fleet_species
						ethos = {
							ethic = "ethic_egalitarian"
						}
					}
				}
			}
			event_target:nomad_fleet = {
				remove_fleet_flag = nomad_on_mission
				fleet_event = { id = namarian.2 }
				owner = {
					set_country_flag = nomad_left_stragglers
				}
			}
		}
	}
	option = {
		name = namarian.21.b
		response_text = namarian.21.b.response
		#is_dialog_only = yes
		add_resource = { influence = -50 }
		hidden_effect = {
			event_target:nomad_fleet = {
				remove_fleet_flag = nomad_on_mission
				fleet_event = { id = namarian.2 }
			}
		}
	}
}

# Nomad Diplomacy
country_event = {
	id = namarian.30
	title = "namarian.30.name"
	desc = {
		text = namarian.30.desc_01
		trigger = {
			from = {
				NOR = {
					has_relation_flag = { who = root flag = nomad_relation_like }
					#has_relation_flag = { who = root flag = nomad_relation_neutral }
					has_relation_flag = { who = root flag = nomad_relation_dislike }
					has_relation_flag = { who = root flag = nomad_relation_hate }
				}
			}
		}
	}
	desc = {
		text = namarian.30.desc_02
		trigger = {
			from = {
				has_relation_flag = { who = root flag = nomad_relation_like }
			}
		}
	}
	desc = {
		text = namarian.30.desc_03
		trigger = {
			from = {
				OR = {
					has_relation_flag = { who = root flag = nomad_relation_dislike }
					has_relation_flag = { who = root flag = nomad_relation_hate }
				}
			}
		}
	}
	location = event_target:nomad_fleet
	diplomatic = yes

	picture_event_data = {
		portrait = event_target:nomad_speaker
		room = ethic_spaceship_room
	}

	is_triggered_only = yes

	trigger = {
		from = {
			is_country_type = nomad
		}
		NOT = { has_country_flag = nomad_diplomacy_engaged }
	}

	immediate = {
		set_country_flag = nomad_diplomacy_engaged
		from = {
			random_controlled_ship = {
				fleet = {
					save_event_target_as = nomad_fleet
					leader = { save_event_target_as = nomad_speaker }
				}
			}
		}
	}

	option = {
		name = namarian.30.a
		is_dialog_only = yes
		response_text = namarian.30.a.response
		trigger = {
			from = {
				NOR = {
					has_relation_flag = { who = root flag = nomad_relation_dislike }
					has_relation_flag = { who = root flag = nomad_relation_hate }
				}
			}
		}
	}
	option = {
		name = namarian.30.a
		is_dialog_only = yes
		response_text = namarian.30.b.response_no_trust
		trigger = {
			from = {
				OR = {
					has_relation_flag = { who = root flag = nomad_relation_dislike }
					has_relation_flag = { who = root flag = nomad_relation_hate }
				}
			}
		}
	}
	option = {
		name = namarian.30.b
		is_dialog_only = yes
		response_text = namarian.30.b.response
		trigger = {
			from = {
				NOR = {
					has_relation_flag = { who = root flag = nomad_relation_dislike }
					#has_relation_flag = { who = root flag = nomad_relation_neutral }
					has_relation_flag = { who = root flag = nomad_relation_like }
					has_relation_flag = { who = root flag = nomad_relation_hate }
				}
			}
		}
	}
	option = {
		name = namarian.30.b
		is_dialog_only = yes
		response_text = namarian.30.b.response_trust
		trigger = {
			from = {
				has_relation_flag = { who = root flag = nomad_relation_like }
			}
		}
	}
	option = {
		name = namarian.30.b
		is_dialog_only = yes
		response_text = namarian.30.b.response_no_trust
		trigger = {
			from = {
				OR = {
					has_relation_flag = { who = root flag = nomad_relation_dislike }
					has_relation_flag = { who = root flag = nomad_relation_hate }
				}
			}
		}
	}
	option = {
		name = namarian.30.c
		response_text = namarian.30.c.response
		default_hide_option = yes
		hidden_effect = {
			remove_country_flag = nomad_diplomacy_engaged
		}
	}
}

### Nomads wants to take a country's unused planet as a colony ###
fleet_event = {
	id = namarian.40
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		owner = {
			save_event_target_as = nomad_fleet_country
		}
		set_fleet_flag = nomad_on_mission
		clear_fleet_actions = this
		event_target:nomad_contact_country = {
			random_planet_within_border = {
				limit = {
					is_colony = no
					OR = {
						is_planet_class = pc_gaia
						is_planet_class = pc_tropical
						is_planet_class = pc_desert
						is_planet_class = pc_ocean
						is_planet_class = pc_arid
					}
					solar_system = {
						NOT = {
							any_system_planet = {
								is_colony = yes
							}
						}
					}
				}
				set_carrier_flag = nomad_mission_location
				solar_system = { set_star_flag = nomad_mission_waypoint }
			}
		}
		queue_actions = {
			repeat = {
				max_iterations = 1
				find_random_system = {
					trigger = {
						id = namarian.40.trigger.1
						has_star_flag = nomad_mission_waypoint
					}
					found_system = {
						move_to = this
					}
				}
				find_closest_planet = {
					trigger = {
						id = namarian.40.trigger.2
						has_carrier_flag = nomad_mission_location
					}
					found_planet = {
						move_to = this
						orbit_planet = this
						wait = {
							duration = 7
						}
						effect = {
							# Try to establish communications
							id = namarian.40.orbit_colony_planet
							root = {
								fleet_event = { id = namarian.50 }
							}
						}
					}
					failed = {
						effect = {
							id = "namarian.40.failed"
							remove_fleet_flag = nomad_on_mission
							fleet_event = { id = namarian.2 } #Nomads fly towards current destination
							owner = {
								#country_event = { id = namarian.995 }
							}
						}
					}
				}
			}
		}
	}
}
#Nomads contact planet owner and asks to take over one of player's systems
country_event = {
	id = namarian.41
	title = namarian.10.name
	desc = namarian.41.desc
	diplomatic = yes
	location = event_target:NomadMissionPlanet
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
		exists = from
		from = {
			owner = { is_country_type = nomad }
		}
	}

	immediate = {
		save_event_target_as = planet_owners
		event_target:nomad_fleet_country = {
			random_controlled_ship = {
				fleet = {
					leader = { save_event_target_as = contact_speaker_leader }
					save_event_target_as = nomad_fleet
				}
			}
			owner_species = { save_event_target_as = nomad_fleet_species }
		}
		random_galaxy_planet = {
			limit = {
				has_carrier_flag = nomad_mission_location
			}
			save_event_target_as = NomadMissionPlanet
			remove_carrier_flag = nomad_mission_location
		}
	}

	option = {
		name = namarian.41.b
		response_text = namarian.41.b.response
		custom_tooltip = namarian.41.b.tooltip
		trigger = {
			NOR = {
				is_xenophobe = yes
				is_spiritualist = yes
			}
		}
		add_resource = { influence = -50 }
		hidden_effect = {
			event_target:nomad_fleet = {
				remove_fleet_flag = nomad_on_mission
				fleet_event = { id = namarian.2 }
				owner = {
					set_relation_flag = { who = event_target:planet_owners flag = nomad_relation_dislike }
				}
			}
		}
	}
	option = {
		name = namarian.41.b.phobe
		response_text = namarian.41.b.response
		custom_tooltip = namarian.41.b.tooltip
		trigger = {
			is_xenophobe = yes
		}
		add_resource = { influence = -50 }
		hidden_effect = {
			event_target:nomad_fleet = {
				remove_fleet_flag = nomad_on_mission
				fleet_event = { id = namarian.2 }
				owner = {
					set_relation_flag = { who = event_target:planet_owners flag = nomad_relation_dislike }
				}
			}
		}
	}
	option = {
		name = namarian.41.b.spirit
		response_text = namarian.41.b.response
		custom_tooltip = namarian.41.b.tooltip
		trigger = {
			is_spiritualist = yes
			is_xenophobe = no
		}
		add_resource = { influence = -50 }
		hidden_effect = {
			event_target:nomad_fleet = {
				remove_fleet_flag = nomad_on_mission
				fleet_event = { id = namarian.2 }
				owner = {
					set_relation_flag = { who = event_target:planet_owners flag = nomad_relation_dislike }
				}
			}
		}
	}
	option = {
		name = namarian.41.a
		response_text = namarian.41.a.response
		custom_tooltip = namarian.41.a.tooltip
		add_monthly_resource_mult = {
			resource = influence
			value = @tier4influencereward
			min = @tier4influencemin
			max = @tier4influencemax
		}
		hidden_effect = {
			event_target:planet_owners = { set_timed_country_flag = { flag = day_0 days = 1 } }
			event_target:NomadMissionPlanet = {
				create_country = {
					name = random
					type = default
					species = event_target:base_namarian
					ignore_initial_colony_error = yes
					exclude_day_zero_contact = event_target:planet_owners
					authority = auth_democratic
					ethos = {
						ethic = "ethic_xenophile"
						ethic = "ethic_spiritualist"
						ethic = "ethic_egalitarian"
					}
					civics = random
					flag = {
						icon = {
							category = "spherical"
							file = "flag_spherical_8.dds"
						}
						background= {
							category = "backgrounds"
							file = "00_solid.dds"
						}
						colors={
							"pink"
							"purple"
							"null"
							"null"
						}
					}
					effect = {
						establish_communications_no_message = event_target:planet_owners

						event_target:planet_owners = {
							every_federation_ally = {
								establish_communications = prevprev
							}
						}
					}
				}
				last_created_country = {
					set_graphical_culture = mammalian_01
					set_country_flag = nomad02_country_flag
					add_resource = {
						energy = 1000
						minerals = 1000
						influence = 500
					}
					#add_opinion_modifier = {
					#	who = event_target:planet_owners
					#	modifier = opinion_liberated_us
					#}
					add_opinion_modifier = {
						who = root
						modifier = opinion_shade_giver
					}
					if = {
						limit = {
							has_opinion_modifier = {
								who = event_target:planet_owners
								modifier = opinion_new_contact
							}
						}
						remove_opinion_modifier = {
							who = event_target:planet_owners
							modifier = opinion_new_contact
						}
					}
					event_target:planet_owners = {
						if = {
							limit = {
								has_opinion_modifier = {
									who = prev
									modifier = opinion_new_contact
								}
							}
							remove_opinion_modifier = {
								who = prev
								modifier = opinion_new_contact
							}
						}
					}
					save_event_target_as = nomad_new_country
					prevprev = {
						give_specimen = {
							key = namarian_colonist_standard
							targets = { event_target:nomad_new_country event_target:NomadMissionPlanet this }
						}
					}
				}
				create_colony = {
					owner = event_target:nomad_new_country
					species = event_target:base_namarian
					ethos = {
						ethic = "ethic_xenophile"
						ethic = "ethic_spiritualist"
						ethic = "ethic_egalitarian"
					}
				}

				create_pop_group = {
					species = owner_main_species
					ethos = {
						ethic = "ethic_egalitarian"
					}
					size = 1400
				}
				set_owner = event_target:nomad_new_country
				event_target:nomad_new_country = {
					every_owned_pop_group = {
						modify_species = {
							species = prev
							ideal_planet_class = prevprev
						}
					}
				}
				set_surveyed = {
					surveyed = yes
					surveyor = root
				}
				solar_system = {
					if = {
						limit = { exists = starbase }
						starbase = {
							set_owner = event_target:nomad_new_country
						}
					}
					else = {
						create_starbase = {
							size = starbase_outpost
							owner = event_target:nomad_new_country
						}
					}
				}
			}
			event_target:nomad_fleet = {
				owner = {
					set_country_flag = nomad_settled
					set_relation_flag = { who = event_target:planet_owners flag = nomad_relation_like }
				}
				remove_fleet_flag = nomad_on_mission
				queue_actions = {
					repeat = {
						max_iterations = 1
						wait = {
							duration = 30
							random = 5
						}
						effect = {
							id = namarian.41.waiting
							fleet_event = { id = namarian.2 }
						}
					}
				}
			}
		}
	}
	option = {
		name = namarian.41.c
		response_text = namarian.41.c.response
		is_dialog_only = yes
	}
}


# Orbiting planet, try to make contact for up to a year before giving up.
fleet_event = {
	id = namarian.50
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		queue_actions = {
			# Wait up to 1 year for Communications to be established.
			repeat = {
				while = {
					id = namarian.50.wait_for_communication
					exists = space_owner
					space_owner = {
						OR = {
							is_country_type = default
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
						NOR = {
							is_hostile = root.owner
							has_communications = root.owner
						}
					}
				}
				max_iterations = 30
				wait = {
					duration = 12
				}
			}
			effect = {
				id = namarian.50.stopped_waiting
				solar_system = {
					remove_star_flag = nomad_mission_waypoint
				}
				if = {
					# Are communications established?
					limit = {
						space_owner = {
							has_communications = root.owner
							NOT = {
								is_hostile = root.owner
							}
						}
					}
					# Start talking
					space_owner = {
						country_event = { id = namarian.41 }
					}
				}
				else = {
					# Give up and try something else
					remove_fleet_flag = nomad_on_mission
					fleet_event = { id = namarian.2 } #Nomads fly towards current destination
				}
			}
		}
	}
}


### Nomads have many ships destroyed and change fleet stance ###
country_event = {
	id = namarian.95
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = nomad
		fleet_power < 1000
		fromfrom = {
			fleet = {
				has_fleet_flag = nomad_main_fleet
				NOT = { has_fleet_flag = nomad_fleeing }
			}
		}
	}

	immediate = {
		fromfrom = {
			fleet = {
				set_fleet_flag = nomad_fleeing
				set_fleet_stance = evasive
			}
		}
	}
}
### Nomads get attacked when weak and change fleet stance ###
country_event = {
	id = namarian.96
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = nomad
		fleet_power < 1000
		fromfrom = {
			has_fleet_flag = nomad_main_fleet
			NOT = { has_fleet_flag = nomad_fleeing }
		}
	}

	immediate = {
		fromfrom = {
			set_fleet_flag = nomad_fleeing
			set_fleet_stance = evasive
		}
	}
}
### Nomads get attacked when weak and change fleet stance ###
fleet_event = {
	id = namarian.97
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			is_country_type = nomad
		}
		has_fleet_flag = nomad_main_fleet
		has_fleet_flag = nomad_fleeing
	}

	immediate = {
		remove_fleet_flag = nomad_fleeing
		set_fleet_stance = passive
	}
}

### Nomads get attacked by a neutral party they don't have contact with ###
country_event = {
	id = namarian.98
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		NOT = { has_communications = from }
		from = {
			is_country_type = nomad
			NOT = { has_relation_flag = { flag = nomad_relation_hate who = root } }
		}
		fromfromfrom = { has_fleet_flag = nomad_main_fleet }
	}

	immediate = {
		save_event_target_as = attacker_country
		if = {
			limit = {
				NOT = {	has_country_flag = nomad_ignores }
			}
			set_country_flag = nomad_ignores
		}
		from = {
			set_relation_flag = {
				flag = nomad_relation_hate
				who = root
			}
		}
		fromfromfrom = {
			if = {
				limit = {
					has_fleet_flag = nomad_on_mission
					solar_system = {
						space_owner = {
							is_same_value = event_target:attacker_country
						}
					}
				}
				remove_fleet_flag = nomad_on_mission
			}
			fleet_event = { id = namarian.2 }
		}
	}
}
### Nomads get attacked by a neutral party they have contact with ###
country_event = {
	id = namarian.99
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_communications = from
		from = {
			is_country_type = nomad
			NOT = { has_relation_flag = { flag = nomad_relation_hate who = root } }
		}
		fromfromfrom = { has_fleet_flag = nomad_main_fleet }
	}

	immediate = {
		save_event_target_as = attacker_country
		from = { save_event_target_as = nomad_country }
		fromfromfrom = {
			save_event_target_as = nomad_fleet
			leader = {
				save_event_target_as = contact_speaker_leader
			}
		}
		if = {
			limit = {
				NOT = { has_country_flag = nomad_ignore }
			}
			set_country_flag = nomad_ignore
		}
		event_target:nomad_country = {
			if = {
				limit = {
					has_relation_flag = { flag = nomad_relation_like who = root }
				}
				remove_relation_flag = {
					flag = nomad_relation_like
					who = root
				}
			}
			if = {
				limit = {
					has_relation_flag = { flag = nomad_relation_dislike who = root }
				}
				remove_relation_flag = {
					flag = nomad_relation_dislike
					who = root
				}
			}
			set_relation_flag = {
				flag = nomad_relation_hate
				who = root
			}
		}
		random_list = {
			50 = {
				country_event = { id = namarian.100 } #Nomads tell you you are a meanie and leave
			}
			50 = { #Nomads retaliate
				modifier = {
					factor = 0
					OR = {
						from = {
							fleet_power < 1000
						}
						fleet_power > 10000
					}
				}
				modifier = {
					factor = 0.5
					fleet_power > 5000
				}
				modifier = {
					factor = 1.5
					OR = {
						AND = {
							from = { fleet_power > 3000 }
							fleet_power < 4000
						}
						AND = {
							from = { fleet_power > 1500 }
							fleet_power < 2000
						}
					}
				}
				country_event = { id = namarian.105 }
				#if = {
				#	limit = {
				#		any_country = {
				#			has_communications = from
				#			has_relation_flag = { flag = nomad_relation_like who = from }
				#			NOT = { is_same_value = root }
				#		}
				#	}
				#	root = { save_event_target_as = attacker_country }
				#	country_event = { id = namarian.110 }
				#}
			}
		}
	}
}
#Nomads declare their dislike for the hostile action
country_event = {
	id = namarian.100
	title = namarian.100.name
	desc = namarian.100.desc
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	immediate = {
		event_target:nomad_fleet = {
			if = {
				limit = {
					has_fleet_flag = nomad_on_mission
					solar_system = {
						space_owner = {
							is_same_value = event_target:attacker_country
						}
					}
				}
				remove_fleet_flag = nomad_on_mission
			}
			fleet_event = { id = namarian.2 }
		}
		remove_country_flag = nomad_hates_you
	}

	option = {
		name = OK
		trigger = {
			NOR = {
				is_xenophile = yes
				is_xenophobe = yes
			}
		}
	}
	option = {
		name = EXCELLENT
		trigger = {
			is_xenophobe = yes
		}
	}
	option = {
		name = UNFORTUNATE
		trigger = {
			is_xenophile = yes
		}
	}
}
#Nomads declare "war" on the attacker
country_event = {
	id = namarian.105
	title = namarian.105.name
	desc = namarian.105.desc
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	immediate = {
		set_country_flag = nomad_hates_you
		event_target:nomad_fleet = {
			fleet_event = { id = namarian.15 }
		}
	}

	option = {
		name = OK
		trigger = {
			NOR = {
				is_xenophile = yes
				is_xenophobe = yes
			}
		}
	}
	option = {
		name = EXCELLENT
		trigger = {
			is_xenophobe = yes
		}
	}
	option = {
		name = UNFORTUNATE
		trigger = {
			OR = {
				is_xenophile = yes
			}
		}
	}
}
#Nomads declare "war" on the attacker
#country_event = {
#	id = namarian.110
#	title = namarian.110.name
#	desc = namarian.110.desc
#	diplomatic = yes
#	is_triggered_only = yes
#
#	picture_event_data = {
#		portrait = event_target:contact_speaker_leader
#		room = ethic_spaceship_room
#	}
#
#	immediate = {
#	}
#
#
#	option = {
#		name = namarian.110.a
#		response_text = namarian.110.a .reply
#		declare_war = {
#
#		}
#	}
#	option = {
#		name = namarian.110.b
#		response_text = namarian.110.b.reply
#	}
#	option = {
#		name = namarian.110.c
#		response_text = namarian.110.c.reply
#	}
#}

### START - Nomads want to sell you ships chain ###
fleet_event = {
	id = namarian.499
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		event_target:nomad_contact_country = {
			NOT = { has_country_flag = nomad_ignores }
		}
	}

	immediate = {
		save_event_target_as = nomad_fleet
		set_fleet_flag = nomad_on_mission
		clear_fleet_actions = this
		queue_actions = {
			repeat = {
				max_iterations = 1
				find_closest_planet = {
					found_planet = {
						move_to = this
						orbit_planet = this
						wait = {
							duration = 14
						}
						effect = {
							id = namarian.499.orbit_planet
							event_target:nomad_contact_country = {
								country_event = { id = namarian.500 }
							}
						}
					}
					failed = {
						effect = {
							id = "namarian.499.failed"
							event_target:nomad_fleet = {
								remove_fleet_flag = nomad_on_mission
								fleet_event = { id = namarian.2 } #Nomads fly towards current destination
							}
							owner = {
								#country_event = { id = namarian.995 }
							}
						}
					}
				}
			}
		}
	}
}
country_event = {
	id = namarian.500
	title = namarian.500.title
	desc = namarian.500.desc

	is_triggered_only = yes # either by nomad fleet action or pulse

	trigger = {
		exists = event_target:nomad01_country
		NOT = { has_country_flag = nomad_ignores }
		# is reasonably friendly with nomads
		# nomads do not need to be near
	}

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	immediate = {
		set_country_flag = nomad_ship_trade
		event_target:nomad01_country = {
			random_controlled_ship = {
				fleet = {
					leader = { save_event_target_as = contact_speaker_leader }
				}
			}
		}
	}

	option = {
		name = namarian.500.a
		is_dialog_only = yes
		response_text = namarian.500.a.reply
	}

	option = {
		name = namarian.500.b
		hidden_effect = {
			country_event = { id = namarian.505 }
		}
	}

	option = {
		name = namarian.500.c
		hidden_effect = {
			country_event = { id = namarian.505 }
		}
	}
}

country_event = {
	id = namarian.505
	title = namarian.500.title
	desc = namarian.505.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.505.a
		is_dialog_only = yes
		response_text = namarian.505.a.reply
	}

	option = {
		name = namarian.505.b
		hidden_effect = {
			country_event = { id = namarian.510 }
		}
	}

	option = {
		name = namarian.505.c
		hidden_effect = {
			country_event = { id = namarian.525 }
		}
	}
}

country_event = {
	id = namarian.510
	title = namarian.500.title
	desc = namarian.510.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.510.a
		is_dialog_only = yes
		response_text = namarian.510.a.reply
	}

	option = {
		name = namarian.510.b
		hidden_effect = {
			country_event = { id = namarian.511 }
		}
	}

	option = {
		name = namarian.510.c
		hidden_effect = {
			country_event = { id = namarian.525 }
		}
	}
}

country_event = {
	id = namarian.511
	title = namarian.500.title
	desc = namarian.511.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.511.a
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
		}
		give_specimen = { key = namarian_vessel_heraldry }
		hidden_effect = {
			add_resource = { energy = -2000 }
			country_event = { id = namarian.514 }
		}
	}

	option = {
		name = namarian.511.e
		allow = {
			resource_stockpile_compare = { resource = minerals value >= 2000 }
		}
		give_specimen = { key = namarian_vessel_heraldry }
		hidden_effect = {
			add_resource = { minerals = -2000 }
			country_event = { id = namarian.514 }
		}
	}

	option = {
		name = namarian.511.b
		hidden_effect = {
			random_list = {
				50 = { country_event = { id = namarian.512 } }
				50 = { country_event = { id = namarian.513 } }
			}
		}
	}

	option = {
		name = namarian.511.c
		trigger = {
			NOR = {
				resource_stockpile_compare = { resource = energy value >= 2000 }
				resource_stockpile_compare = { resource = minerals value >= 2000 }
			}
		}
		hidden_effect = {
			country_event = { id = namarian.525 }
		}
	}

	option = {
		name = namarian.511.d
		allow = {
			OR = {
				resource_stockpile_compare = { resource = energy value >= 2000 }
				resource_stockpile_compare = { resource = minerals value >= 2000 }
			}
		}
		hidden_effect = {
			country_event = { id = namarian.525 }
		}
	}
}

country_event = {
	id = namarian.512
	title = namarian.500.title
	desc = namarian.512.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.511.a
		allow = {
			resource_stockpile_compare = { resource = energy value >= 2000 }
		}
		add_resource = { energy = -2000 }
		hidden_effect = {
			country_event = { id = namarian.514 }
		}
	}

	option = {
		name = namarian.511.e
		allow = {
			resource_stockpile_compare = { resource = minerals value >= 2000 }
		}
		add_resource = { minerals = -2000 }
		hidden_effect = {
			country_event = { id = namarian.514 }
		}
	}

	option = {
		name = namarian.511.c
		trigger = {
			NOR = {
				resource_stockpile_compare = { resource = energy value >= 2000 }
				resource_stockpile_compare = { resource = minerals value >= 2000 }
			}
		}
		hidden_effect = {
			country_event = { id = namarian.525 }
		}
	}

	option = {
		name = namarian.511.d
		allow = {
			OR = {
				resource_stockpile_compare = { resource = energy value >= 2000 }
				resource_stockpile_compare = { resource = minerals value >= 2000 }
			}
		}
		hidden_effect = {
			country_event = { id = namarian.525 }
		}
	}
}

country_event = {
	id = namarian.513
	title = namarian.500.title
	desc = namarian.513.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.513.b
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1500 }
		}
		add_resource = { energy = -1500 }
		give_specimen = { key = namarian_vessel_heraldry }
		hidden_effect = {
			country_event = { id = namarian.514 }
		}
	}

	option = {
		name = namarian.513.d
		allow = {
			resource_stockpile_compare = { resource = minerals value >= 1500 }
		}
		add_resource = { minerals = -1500 }
		give_specimen = { key = namarian_vessel_heraldry }
		hidden_effect = {
			country_event = { id = namarian.514 }
		}
	}

	option = {
		name = namarian.513.c
		trigger = {
			NOR = {
				resource_stockpile_compare = { resource = energy value >= 1500 }
				resource_stockpile_compare = { resource = minerals value >= 1500 }
			}
		}
		hidden_effect = {
			country_event = { id = namarian.525 }
		}
	}

	option = {
		name = namarian.511.d
		trigger = {
			OR = {
				resource_stockpile_compare = { resource = energy value >= 1500 }
				resource_stockpile_compare = { resource = minerals value >= 1500 }
			}
		}
		hidden_effect = {
			country_event = { id = namarian.525 }
		}
	}
}

country_event = {
	id = namarian.514
	title = namarian.500.title
	desc = namarian.514.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	immediate = {
		event_target:contact_speaker_leader = {
			owner = {
				save_event_target_as = nomads
			}
		}
	}

	option = {
		name = namarian.514.a
		hidden_effect = {
			if = {
				limit = {
					any_neighbor_country = {
						opinion ={
							who = root
							value < -500
						}
						is_country_type = default
						has_communications = root
					}
				}
				random_neighbor_country = {
					limit = {
						opinion ={
							who = root
							value < -500
						}
						is_country_type = default
						has_communications = root
					}
					set_country_flag = nomad_doublecrossing
					#save_event_target_as = other_empire
				}
				random_list = {
					30 = { country_event = { id = namarian.520 days = 10 } }
					70 = { country_event = { id = namarian.530 days = 30 } }
				}
			}
			else_if = {
				limit = {
					any_neighbor_country = {
						opinion ={
							who = root
							value < -200
						}
						is_country_type = default
						has_communications = root
					}
				}
				random_neighbor_country = {
					limit = {
						opinion ={
							who = root
							value < -200
						}
						is_country_type = default
						has_communications = root
					}
					set_country_flag = nomad_doublecrossing
					#save_event_target_as = other_empire
				}
				random_list = {
					30 = { country_event = { id = namarian.520 days = 10 } }
					70 = { country_event = { id = namarian.530 days = 30 } }
				}
			}
			else_if = {
				limit = {
					any_neighbor_country = {
						opinion ={
							who = root
							value < -50
						}
						is_country_type = default
						has_communications = root
					}
				}
				random_neighbor_country = {
					limit = {
						opinion ={
							who = root
							value < -50
						}
						is_country_type = default
						has_communications = root
					}
					set_country_flag = nomad_doublecrossing
					#save_event_target_as = other_empire
				}
				random_list = {
					30 = { country_event = { id = namarian.520 days = 10 } }
					70 = { country_event = { id = namarian.530 days = 30 } }
				}
			}
			else = {
				country_event = { id = namarian.530 days = 30 }
			}
		}
	}
}

country_event = {
	id = namarian.520
	title = namarian.520.title
	desc = namarian.520.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.520.a
		is_dialog_only = yes
		response_text = namarian.520.a.reply
	}

	option = {
		name = namarian.520.b
		hidden_effect = {
			country_event = { id = namarian.521 }
		}
	}
}

country_event = {
	id = namarian.521
	title = namarian.520.title
	desc = namarian.521.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	immediate = {
		random_country = {
			limit = {
				has_country_flag = nomad_doublecrossing
			}
			save_event_target_as = other_empire
			remove_country_flag = nomad_doublecrossing
		}
	}

	option = {
		name = namarian.521.a
		hidden_effect = {
			country_event = { id = namarian.522 }
		}
	}

	option = {
		name = namarian.521.b
		hidden_effect = {
			country_event = { id = namarian.522 }
		}
	}
}

country_event = {
	id = namarian.522
	title = namarian.520.title
	desc = namarian.522.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.522.b
		is_dialog_only = yes
		response_text = namarian.522.b.reply
	}

	option = {
		name = namarian.522.c
		is_dialog_only = yes
		response_text = namarian.522.c.reply
	}

	option = {
		name = namarian.522.d
		hidden_effect = {
			country_event = { id = namarian.523 }
		}
	}

	option = {
		name = namarian.522.e
		hidden_effect = {
			country_event = { id = namarian.526 }
		}
	}
}

country_event = {
	id = namarian.523
	title = namarian.520.title
	desc = namarian.523.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.523.c
		hidden_effect = {
			country_event = { id = namarian.524 }
		}
		trigger = {
			resource_stockpile_compare = { resource = energy value >= 1000 }
		}
	}

	option = {
		name = namarian.523.a
		hidden_effect = {
			country_event = { id = namarian.526 }
		}
	}

	option = {
		name = namarian.523.b
		hidden_effect = {
			country_event = { id = namarian.526 }
		}
		trigger = {
			resource_stockpile_compare = { resource = energy value < 1000 }
		}
	}
}

country_event = {
	id = namarian.524
	title = namarian.520.title
	desc = namarian.524.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	option = {
		name = namarian.524.a
		hidden_effect = {
			set_country_flag = double_fleet
			country_event = { id = namarian.530 days = 20 }
		}
	}
}

country_event = {
	id = namarian.525
	title = namarian.500.title
	desc = {
		text = namarian.525.desc
		trigger = {
			OR = {
				resource_stockpile_compare = { resource = energy value >= 2000 }
				resource_stockpile_compare = { resource = minerals value >= 2000 }
			}
		}
	}
	desc = {
		text = namarian.525.desc.poor
		trigger = {
			NOR = {
				resource_stockpile_compare = { resource = energy value >= 2000 }
				resource_stockpile_compare = { resource = minerals value >= 2000 }
			}
		}
	}
	is_triggered_only = yes

	diplomatic = yes

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	picture_event_data = {
		portrait = event_target:contact_speaker_leader
		room = ethic_spaceship_room
	}

	option = {
		name = namarian.525.a
		hidden_effect = {
			event_target:nomad_fleet = {
				remove_fleet_flag = nomad_on_mission
				fleet_event = { id = namarian.2 }
			}
		}
	}
}

country_event = {
	id = namarian.526
	title = namarian.520.title
	desc = namarian.525.desc

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	immediate = {
		event_target:nomad01_country = {
			random_controlled_ship = {
				limit = {
					fleet = {
						has_fleet_flag = nomad_fleet
					}
				}
				fleet = {
					save_event_target_as = nomad_fleet
				}
			}
		}
	}

	option = {
		name = namarian.525.a
		hidden_effect = {
			event_target:nomad_fleet = {
				remove_fleet_flag = nomad_on_mission
				fleet_event = { id = namarian.2 }
			}
		}
	}
}

country_event = {
	id = namarian.530
	title = namarian.500.title
	desc = {
		text = namarian.530.desc.15ships
		trigger = {
			NOT = { has_country_flag = double_fleet }
		}
	}
	desc = {
		text = namarian.530.desc.30ships
		trigger = {
			has_country_flag = double_fleet
		}
	}
	picture = GFX_evt_unknown_ships
	show_sound = event_ship_thrusters
	location = root.capital_scope

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = nomad_ignores }
	}

	immediate = {
		event_target:nomad01_country = {
			set_country_flag = nomad_ships_sold
			random_controlled_ship = {
				limit = {
					fleet = {
						has_fleet_flag = nomad_fleet
					}
				}
				fleet = {
					save_event_target_as = nomad_fleet
				}
			}
		}

		create_fleet = {
			name = "NAME_Nomad_Delivery"
			effect = {
				set_owner = root
				create_ship_design = {
					design = "NAME_Nomad_Cruiser"
				}
				while = {
					count = 5
					create_ship = {
						design = last_created_design
						upgradable = no
					}
				}
				set_location = {
					target = root.capital_scope
					distance = 5
					angle = random
				}
			}
		}

		if = {
			limit = {
				has_country_flag = double_fleet
			}
			create_fleet = {
				name = "NAME_Redirected_Nomad_Delivery"
				effect = {
					set_owner = root
					create_ship_design = {
						design = "NAME_Nomad_Cruiser"
					}
					while = {
						count = 10
						create_ship = {
							design = last_created_design
							upgradable = no
						}
					}
					set_location = {
						target = root.capital_scope
						distance = 15
						angle = random
					}
				}
			}
		}
	}

	option = {
		name = OK
		hidden_effect = {
			event_target:nomad_fleet = {
				remove_fleet_flag = nomad_on_mission
				fleet_event = { id = namarian.2 }
			}
		}
	}
}
### END - Nomads want to sell you ships chain ###



## Nomads share Communications with others
#country_event = {
#	id = namarian.11
#	hide_window = yes
#
#	trigger = {
#		is_country_type = nomad
#		any_country = {
#			is_country_type = default
#			exists = capital_scope
#			capital_scope = {
#				colony_age > 48
#			}
#			has_communications = root
#		}
#	}
#
#	mean_time_to_happen = { days = 800 }
#
#	immediate = {
#		random_country = {
#			limit = {
#				is_country_type = default
#				has_communications = root
#			}
#			save_event_target_as = receiver
#		}
#		if = {
#			limit = {
#				any_country = {
#					has_communications = root
#					NOT = { has_communications = event_target:receiver }
#				}
#			}
#			event_target:receiver = {
#				country_event = { id = namarian.12 }
#			}
#		}
#	}
#}
#
#country_event = {
#	id = namarian.12
#	title = namarian.10.name
#	desc = namarian.12.desc
#
#	picture_event_data = {
#		portrait = from
#		room = ethic_spaceship_room
#	}
#
#	diplomatic = yes
#
#	is_triggered_only = yes
#
#	option = {
#		name = namarian.12.a
#		every_country = {
#			limit = {
#				has_communications = from
#				NOT = { has_communications = root }
#			}
#			establish_communications = root
#		}
#	}
#}

###DEBUG STUFF
#country_event = {
#	id = namarian.991
#	title = "namarian.991"
#	desc = "TRY AND TAKE CONTACT"
#	picture = GFX_evt_star_chart
#	is_triggered_only = yes
#
#	option = {
#		name = ok
#	}
#}
#country_event = {
#	id = namarian.992
#	title = "namarian.992"
#	desc = "FLEE FROM HOSTILE"
#	picture = GFX_evt_star_chart
#	is_triggered_only = yes
#
#	option = {
#		name = ok
#	}
#}
#country_event = {
#	id = namarian.993
#	title = "namarian.993"
#	desc = "IGNORE COUNTRY AND KEEP GOING TO GOAL"
#	picture = GFX_evt_star_chart
#	is_triggered_only = yes
#
#	option = {
#		name = ok
#	}
#}
#country_event = {
#	id = namarian.994
#	title = "namarian.994"
#	desc = "EXPLORE EMPTY SYSTEM"
#	picture = GFX_evt_star_chart
#	is_triggered_only = yes
#
#	option = {
#		name = ok
#	}
#}
#country_event = {
#	id = namarian.995
#	title = "namarian.995"
#	desc = "SET SAIL FOR END DESTINATION"
#	picture = GFX_evt_star_chart
#	is_triggered_only = yes
#
#	option = {
#		name = ok
#	}
#}
#country_event = {
#	id = namarian.996
#	title = "namarian.996"
#	desc = "RANDOM DO NOT DO QUEST"
#	picture = GFX_evt_star_chart
#	is_triggered_only = yes
#
#	option = {
#		name = ok
#	}
#}
