#################################
#
# Nomad Events
# by Maximilian Olbers
#
#################################

namespace = nomad

country_event = {
	id = nomad.1
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		OR = {
			is_country_type = default
			is_country_type = fallen_empire
		}
		from = {
			exists = owner
			owner = {
				is_country_type = nomad
			}
		}
	}

	immediate = {
		#from = { owner = { save_event_target_as = nomad_owner } }
		#establish_communications_no_message = event_target:nomad_owner
	}
}

# Nomads spread comms
country_event = {
	id = nomad.10
	title = nomad.10.name
	desc = {
		text = nomad.10.desc.comms
		trigger = {
			any_country = {
				has_communications = fromfrom
				NOT = { has_communications = root }
			}
		}
	}
	desc = {
		text = nomad.10.desc.nocomms
		trigger = {
			NOT = {
				any_country = {
					has_communications = fromfrom
					NOT = { has_communications = root }
				}
			}
		}
	}
	
	picture_event_data = {
		portrait = fromfrom
		room = ethic_spaceship_room
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		#exists = event_target:contact_speaker
		#event_target:contact_speaker = {
		#	is_country_type = nomad
		#}
	}

	immediate = {
		fromfrom = { save_event_target_as = contact_speaker }
		if = {
			limit = {
				any_country = {
					has_communications = event_target:contact_speaker
					NOT = { has_communications = root }
				}
			}
			every_country = {
				limit = {
					has_communications = event_target:contact_speaker
				}
				establish_communications = root
			}
		}
	}

	option = {
		name = action.1.a
		if = {
			limit = {
				NOT = {
					event_target:contact_speaker = { has_relation_flag = { flag = no_coms who = root } }
				}
			}
			hidden_effect = { country_event = { id = story.7 days = 30 } }
		}
		trigger = {
			NOT = {
				OR = {
					has_ethic = ethic_xenophile
					has_ethic = ethic_fanatic_xenophile
					has_ethic = ethic_xenophobe
					has_ethic = ethic_fanatic_xenophobe
				}
			}
		}
	}
	option = {
		name = action.1.b
		if = {
			limit = {
				NOT = {
					event_target:contact_speaker = { has_relation_flag = { flag = no_coms who = root } }
				}
			}
			hidden_effect = { country_event = { id = story.7 days = 30 } }
		}
		trigger = {
			OR = {
				has_ethic = ethic_xenophobe
				has_ethic = ethic_fanatic_xenophobe
			}
		}
	}
	option = {
		name = action.1.c
		if = {
			limit = {
				NOT = {
					event_target:contact_speaker = { has_relation_flag = { flag = no_coms who = root } }
				}
			}
			hidden_effect = { country_event = { id = story.7 days = 30 } }
		}
		trigger = {
			OR = {
				has_ethic = ethic_xenophile
				has_ethic = ethic_fanatic_xenophile
			}
		}
	}
}

# Nomads share Communications with others
country_event = {
	id = nomad.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 = nomad.12 }
			}
		}
	}
}

country_event = {
	id = nomad.12
	title = nomad.10.name
	desc = nomad.12.desc
	
	picture_event_data = {
		portrait = from
		room = ethic_spaceship_room
	}

	diplomatic = yes

	is_triggered_only = yes

	option = {
		name = nomad.12.a
		every_country = {
			limit = {
				has_communications = from
				NOT = { has_communications = root }
			}
			establish_communications = root
		}
	}
}


# Repeating roaming action queue
fleet_event = {
	id = nomad.100
	hide_window = yes

	mean_time_to_happen = { days = 360 }

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

	immediate = {
		queue_actions = {
			find_random_system = {
				trigger = {
					id = nomad.2.trigger.1
					distance = {
						source = PREV
						max_distance = 100
						min_distance = 20
					}
					NOT = { has_star_flag = hostile_system }
				}
				found_system = {
					move_to = this
				}
			}
			find_random_system = {
				trigger = {
					id = nomad.2.trigger.2
					NOT = {
						any_neighbor_system = {
							any_planet = {
								is_capital = yes
							}
						}
						has_star_flag = hostile_system
					}
				}
				found_system = {
					move_to = this
				}
			}
		}
	}
}