###########################
# The Long Table (ap_long_table)
###########################
namespace = apb_longtable

# Summit check. on_decade_pulse_country (this = country).
# The visible event is delayed so it does not open on top of other decade events;
# it checks the same conditions again when it fires.
country_event = {
	id = apb_longtable.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_long_table
		apb_long_table_can_host = yes
	}

	immediate = {
		country_event = { id = apb_longtable.2 days = 5 random = 20 }
	}
}

# The summit
country_event = {
	id = apb_longtable.2
	title = apb_longtable.2.name
	desc = {
		trigger = { is_megacorp = yes }
		text = apb_longtable.2.desc.corp
	}
	desc = {
		trigger = { is_megacorp = no }
		text = apb_longtable.2.desc
	}
	picture = GFX_evt_diplomatic_visit
	show_sound = event_default
	is_triggered_only = yes

	trigger = {
		apb_long_table_can_host = yes
	}

	immediate = {
		apb_long_table_seat_guests = yes
	}

	# Trade round
	option = {
		name = {
			trigger = { is_megacorp = no }
			text = apb_longtable.2.trade
		}
		name = {
			trigger = { is_megacorp = yes }
			text = apb_longtable.2.trade.corp
		}
		custom_tooltip = apb_longtable.2.trade.tt
		add_resource = {
			energy = 250
			mult = apb_table_guests
		}
		if = {
			limit = { is_gestalt = yes }
			add_resource = {
				minerals = 150
				mult = apb_table_guests
			}
		}
		else = {
			add_resource = {
				consumer_goods = 100
				mult = apb_table_guests
			}
		}
		add_modifier = {
			modifier = apb_long_table_trade_round
			years = 10
		}
		ai_chance = {
			factor = 2
			modifier = {
				factor = 2
				is_megacorp = yes
			}
		}
	}

	# Open archives
	option = {
		name = {
			trigger = { is_megacorp = no }
			text = apb_longtable.2.archives
		}
		name = {
			trigger = { is_megacorp = yes }
			text = apb_longtable.2.archives.corp
		}
		custom_tooltip = apb_longtable.2.archives.tt
		hidden_effect = {
			every_relation = {
				limit = { has_country_flag = apb_table_scholar@root }
				save_event_target_as = apb_table_source
				root = { apb_long_table_copy_tech = yes }
			}
		}
		ai_chance = {
			factor = 3
		}
	}

	# Quiet words
	option = {
		name = {
			trigger = { is_megacorp = no }
			text = apb_longtable.2.favours
		}
		name = {
			trigger = { is_megacorp = yes }
			text = apb_longtable.2.favours.corp
		}
		custom_tooltip = apb_longtable.2.favours.tt
		hidden_effect = {
			every_relation = {
				limit = { has_country_flag = apb_table_guest@root }
				save_event_target_as = apb_table_fav_guest
				root = {
					add_favors = {
						target = event_target:apb_table_fav_guest
						value = 1
					}
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				is_galactic_community_member = yes
			}
		}
	}

	# A long toast
	option = {
		name = {
			trigger = { is_megacorp = no }
			text = apb_longtable.2.toast
		}
		name = {
			trigger = { is_megacorp = yes }
			text = apb_longtable.2.toast.corp
		}
		custom_tooltip = apb_longtable.2.toast.tt
		hidden_effect = {
			every_relation = {
				limit = { has_country_flag = apb_table_guest@root }
				add_trust = {
					amount = 25
					who = root
				}
				add_opinion_modifier = {
					who = root
					modifier = apb_opinion_long_table
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				is_xenophile = yes
			}
		}
	}

	# One summit in four has an incident.
	after = {
		hidden_effect = {
			random_list = {
				75 = { }
				9 = {
					country_event = { id = apb_longtable.10 }
				}
				8 = {
					country_event = { id = apb_longtable.11 }
				}
				8 = {
					country_event = { id = apb_longtable.12 }
				}
			}
		}
	}
}

# Incident: two rivals seated together
country_event = {
	id = apb_longtable.10
	title = apb_longtable.10.name
	desc = apb_longtable.10.desc
	picture = GFX_evt_arguing_senate
	show_sound = event_default
	is_triggered_only = yes

	trigger = {
		count_relation = {
			limit = { has_country_flag = apb_table_guest@root }
			count >= 2
		}
	}

	immediate = {
		apb_long_table_pick_guest = { TARGET = apb_table_rival_a }
		apb_long_table_pick_guest = { TARGET = apb_table_rival_b }
	}

	# Seat them apart
	option = {
		name = apb_longtable.10.a
		custom_tooltip = apb_longtable.10.a.tt
		hidden_effect = {
			event_target:apb_table_rival_a = {
				add_trust = {
					amount = 10
					who = root
				}
			}
			event_target:apb_table_rival_b = {
				add_trust = {
					amount = 10
					who = root
				}
			}
		}
		ai_chance = {
			factor = 2
		}
	}

	# Let them argue
	option = {
		name = apb_longtable.10.b
		add_monthly_resource_mult = {
			resource = unity
			value = 6
			min = 100
			max = 5000
		}
		custom_tooltip = apb_longtable.10.b.tt
		hidden_effect = {
			event_target:apb_table_rival_a = {
				add_opinion_modifier = {
					who = root
					modifier = apb_opinion_long_table_affront
				}
			}
			event_target:apb_table_rival_b = {
				add_opinion_modifier = {
					who = root
					modifier = apb_opinion_long_table_affront
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}
}

# Incident: a guest's delegate defects
country_event = {
	id = apb_longtable.11
	title = apb_longtable.11.name
	desc = apb_longtable.11.desc
	picture = GFX_evt_smugglers_in_bar
	show_sound = event_default
	is_triggered_only = yes

	trigger = {
		any_relation = { has_country_flag = apb_table_guest@root }
	}

	immediate = {
		apb_long_table_pick_guest = { TARGET = apb_table_source }
	}

	# Grant asylum
	option = {
		name = apb_longtable.11.a
		custom_tooltip = apb_longtable.11.a.tt
		hidden_effect = {
			apb_long_table_copy_tech = yes
			event_target:apb_table_source = {
				add_opinion_modifier = {
					who = root
					modifier = apb_opinion_long_table_affront
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	# Hand them back
	option = {
		name = apb_longtable.11.b
		custom_tooltip = apb_longtable.11.b.tt
		hidden_effect = {
			add_favors = {
				target = event_target:apb_table_source
				value = 1
			}
			event_target:apb_table_source = {
				add_trust = {
					amount = 10
					who = root
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}
}

# Incident: a gift turns out to be a relic fragment
country_event = {
	id = apb_longtable.12
	title = apb_longtable.12.name
	desc = apb_longtable.12.desc
	picture = GFX_evt_ancient_artifact
	show_sound = event_default
	is_triggered_only = yes

	trigger = {
		any_relation = { has_country_flag = apb_table_guest@root }
	}

	immediate = {
		apb_long_table_pick_guest = { TARGET = apb_table_giver }
	}

	# Keep it
	option = {
		name = apb_longtable.12.a
		add_resource = { minor_artifacts = 10 }
		ai_chance = {
			factor = 1
		}
	}

	# Send it back
	option = {
		name = apb_longtable.12.b
		custom_tooltip = apb_longtable.12.b.tt
		hidden_effect = {
			event_target:apb_table_giver = {
				add_trust = {
					amount = 20
					who = root
				}
				add_opinion_modifier = {
					who = root
					modifier = apb_opinion_long_table_courtesy
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}
}
