# The Long Table

# Scope: country (the host), called from the summit event's immediate.
# Seats up to six guests. Each gets apb_table_guest@root for 120 days; the first
# three also get apb_table_scholar@root (the "Open archives" outcome copies from them).
# The guest count is kept in the host's variable apb_table_guests.
apb_long_table_seat_guests = {
	set_variable = { which = apb_table_guests value = 0 }
	while = {
		count = 6
		random_relation = {
			limit = {
				apb_long_table_can_attend = yes
				NOT = { has_country_flag = apb_table_guest@root }
			}
			set_timed_country_flag = { flag = apb_table_guest@root days = 120 }
			if = {
				limit = {
					root = { check_variable = { which = apb_table_guests value < 3 } }
				}
				set_timed_country_flag = { flag = apb_table_scholar@root days = 120 }
			}
			root = { change_variable = { which = apb_table_guests value = 1 } }
		}
	}
}

# Scope: country (the host). Needs event_target:apb_table_source (a guest).
# Copies one random technology the guest has and we can research but lack, from a
# random field that has one (form: first_contact_grant_random_tech_option in vanilla's
# first_contact_effects.txt, without `progress`, so the whole technology is granted).
# If the guest has nothing to teach us: 4 months of our research in each field,
# between 100 and 5000 per field.
apb_long_table_copy_tech = {
	random_list = {
		1 = {
			modifier = {
				factor = 0
				NOT = {
					can_copy_random_tech_from = {
						who = event_target:apb_table_source
						area = physics
					}
				}
			}
			copy_random_tech_from = {
				who = event_target:apb_table_source
				area = physics
			}
		}
		1 = {
			modifier = {
				factor = 0
				NOT = {
					can_copy_random_tech_from = {
						who = event_target:apb_table_source
						area = society
					}
				}
			}
			copy_random_tech_from = {
				who = event_target:apb_table_source
				area = society
			}
		}
		1 = {
			modifier = {
				factor = 0
				NOT = {
					can_copy_random_tech_from = {
						who = event_target:apb_table_source
						area = engineering
					}
				}
			}
			copy_random_tech_from = {
				who = event_target:apb_table_source
				area = engineering
			}
		}
		1 = {
			modifier = {
				factor = 0
				OR = {
					can_copy_random_tech_from = {
						who = event_target:apb_table_source
						area = physics
					}
					can_copy_random_tech_from = {
						who = event_target:apb_table_source
						area = society
					}
					can_copy_random_tech_from = {
						who = event_target:apb_table_source
						area = engineering
					}
				}
			}
			add_monthly_resource_mult = {
				resource = physics_research
				value = 4
				min = 100
				max = 5000
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = 4
				min = 100
				max = 5000
			}
			add_monthly_resource_mult = {
				resource = engineering_research
				value = 4
				min = 100
				max = 5000
			}
		}
	}
}

# Scope: country (the host). Picks one guest at random and saves it as $TARGET$.
apb_long_table_pick_guest = {
	random_relation = {
		limit = {
			has_country_flag = apb_table_guest@root
			NOT = { has_country_flag = apb_table_picked@root }
		}
		set_timed_country_flag = { flag = apb_table_picked@root days = 10 }
		save_event_target_as = $TARGET$
	}
}
