namespace = rg_event
# 灰风起源创建灰风事件
# Spawn L-Cluster
country_event = {
	id = rg_event.1
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		AND = {
			has_origin = origin_rg_gray
			# NOT = { has_global_flag = rg_origin_l_cluster }
		}
	}
	immediate = {
		if = {
			limit = {
				NOT = {
					has_global_flag = origin_rg_gray_1st_global
				}
			}
			set_global_flag = origin_rg_gray_1st_global
			set_country_flag = origin_rg_gray_1st
			set_country_flag = rg_gray_level_1
			country_event = {
				id = rg_event.3
				days = 30
			}
			add_modifier = {
				modifier = rg_distant_stars_modifier
			}
			save_global_event_target_as = origin_rg_gray_country
			rg_lcluster_spawn_effect = yes
		}
		else = {
			set_country_flag = origin_gray_dragon_country
			set_global_flag = has_origin_gray_dragon
			rg_create_fake_dragon = yes
			random_owned_leader = {
				limit = {
					has_leader_flag = rg_fake_dragon
				}
				remove_trait = RG_leader_trait_admiral_timed_life
				add_trait = RG_leader_trait_admiral_born_tobe_dragon
				set_leader_flag = rg_fake_dragon_reborn
				set_age = 0
			}
			set_country_flag = rg_fake_dragon_reborn_country
			set_variable = {
				which = rg_fake_dragon_timedlife_counter
				value = 0
			}
			start_lcluster_chain = yes
			add_event_chain_counter = {
				event_chain = l_cluster_chain
				counter = clues
				amount = 7
			}
			# increment variable
			change_variable = {
				which = num_lcluster_clues
				value = 7
			}
		}
	}
}

country_event = {
	id = rg_event.2
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		country_event = {
			id = graygoo.499
		}
	}
	# option = {
	# 	name = rg_event.2.a
	# 	hidden_effect = {
	# 		country_event = { id = graygoo.499 }
	# 	}
	# 	default_hide_option = yes
	# }
}

country_event = {
	id = rg_event.3
	title = "graygoo.500.title"
	desc = {
		trigger = {
			has_country_flag = RG_realgray
		}
		text = "RG_realgray.desc"
	}
	desc = {
		trigger = {
			has_country_flag = RG_sleepinggray
		}
		text = "RG_sleepinggray.desc"
	}
	desc = {
		trigger = {
			has_country_flag = RG_whitenoise
		}
		text = "RG_whitenoise.desc"
	}
	desc = {
		trigger = {
			has_country_flag = RG_dragon
		}
		text = "RG_dragon.desc"
	}
	desc = {
		trigger = {
			has_country_flag = RG_desanau
		}
		text = "RG_desanau.desc"
	}
	desc = {
		trigger = {
			has_country_flag = RG_pirate
		}
		text = "RG_pirate.desc"
	}
	desc = {
		trigger = {
			has_country_flag = RG_alienpoem
		}
		text = "RG_alienpoem.desc"
	}
	desc = {
		trigger = {
			has_country_flag = RG_gift
		}
		text = "RG_gift.desc"
	}
	desc = {
		trigger = {
			has_country_flag = RG_biggift
		}
		text = "RG_biggift.desc"
	}
	diplomatic = yes
	picture_event_data = {
		portrait = event_target:rg_gray_country_leader
		room = "ethic_spaceship_room"
	}
	is_triggered_only = yes
	immediate = {
		rg_gray_country_init = yes
		random_list = {
			# Real Gray!
			100 = {
				modifier = {
					factor = 0
					any_playable_country = {
						has_country_flag = gray_owner
					}
				}
				set_country_flag = RG_realgray
			}
			# Sleeping Beauty
			0 = {
				modifier = {
					factor = 0
					any_playable_country = {
						has_country_flag = gray_owner
					}
				}
				set_country_flag = RG_sleepinggray
			}
			# in fact..Empty
			0 = {
				random_list = {
					200 = {
						modifier = {
							factor = 100
							any_playable_country = {
								has_country_flag = gray_owner
							}
						}
						set_country_flag = RG_whitenoise
					}
					100 = {
						set_country_flag = RG_dragon
					}
					100 = {
						set_country_flag = RG_desanau
					}
					100 = {
						set_country_flag = RG_pirate
					}
					100 = {
						set_country_flag = RG_alienpoem
					}
					50 = {
						set_country_flag = RG_gift
					}
					10 = {
						set_country_flag = RG_biggift
					}
				}
			}
		}
	}
	after = {
		hidden_effect = {
			switch = {
				trigger = has_country_flag
				RG_realgray = {
					remove_country_flag = RG_realgray
				}
				RG_sleepinggray = {
					remove_country_flag = RG_sleepinggray
				}
				RG_whitenoise = {
					remove_country_flag = RG_whitenoise
				}
				RG_dragon = {
					remove_country_flag = RG_dragon
				}
				RG_desanau = {
					remove_country_flag = RG_desanau
				}
				RG_pirate = {
					remove_country_flag = RG_pirate
				}
				RG_alienpoem = {
					remove_country_flag = RG_alienpoem
				}
				RG_gift = {
					remove_country_flag = RG_gift
				}
				RG_biggift = {
					remove_country_flag = RG_biggift
				}
			}
		}
	}
	option = {
		custom_gui = "enclave_caravaneer_option"
		name = OK
		hidden_effect = {
			switch = {
				trigger = has_country_flag
				RG_realgray = {
					custom_tooltip = "RG_realgray"
					country_event = {
						id = rg_event.2
						days = 30
					}
					give_technology = {
						tech = tech_minilaser_gray_1
						message = no
					}
					give_technology = {
						tech = tech_object_gray_5
						message = no
					}
				}
				RG_sleepinggray = {
					custom_tooltip = "RG_sleepinggray"
					country_event = {
						id = rg_event.2
						days = 360
					}
					give_technology = {
						tech = tech_minilaser_gray_1
						message = no
					}
					give_technology = {
						tech = tech_object_gray_5
						message = no
					}
				}
				RG_whitenoise = {
					custom_tooltip = "RG_whitenoise"
					country_event = {
						id = rg_event.2
						days = 360
					}
					give_technology = {
						tech = tech_minilaser_gray_1
						message = no
					}
					give_technology = {
						tech = tech_object_gray_5
						message = no
					}
				}
				RG_dragon = {
					custom_tooltip = "RG_dragon"
					country_event = {
						id = rg_event.2
						days = 360
					}
					give_technology = {
						tech = tech_object_gray_5
					}
					add_monthly_resource_mult = {
						resource = society_research
						value = 24
						min = 2000
					}
					give_technology = {
						tech = tech_minilaser_gray_1
					}
					tooltip = {
						give_technology = {
							tech = tech_object_gray_5
						}
						give_technology = {
							tech = tech_minilaser_gray_1
						}
						add_monthly_resource_mult = {
							resource = society_research
							value = 24
							min = 2000
						}
					}
					give_technology = {
						tech = tech_minilaser_gray_1
					}
				}
				RG_desanau = {
					custom_tooltip = "RG_desanau"
					country_event = {
						id = rg_event.2
						days = 360
					}
					give_technology = {
						tech = tech_object_gray_5
					}
					add_monthly_resource_mult = {
						resource = society_research
						value = 24
						min = 2000
					}
					give_technology = {
						tech = tech_minilaser_gray_1
					}
					tooltip = {
						add_monthly_resource_mult = {
							resource = society_research
							value = 24
							min = 2000
						}
						give_technology = {
							tech = tech_minilaser_gray_1
						}
						give_technology = {
							tech = tech_object_gray_5
						}
					}
				}
				RG_pirate = {
					custom_tooltip = "RG_pirate"
					country_event = {
						id = rg_event.2
						days = 360
					}
					give_technology = {
						tech = tech_object_gray_5
					}
					add_monthly_resource_mult = {
						resource = society_research
						value = 24
						min = 2000
					}
					give_technology = {
						tech = tech_minilaser_gray_1
					}
					tooltip = {
						add_monthly_resource_mult = {
							resource = society_research
							value = 24
							min = 2000
						}
						give_technology = {
							tech = tech_minilaser_gray_1
						}
						give_technology = {
							tech = tech_object_gray_5
						}
					}
				}
				RG_alienpoem = {
					custom_tooltip = "RG_alienpoem"
					country_event = {
						id = rg_event.2
						days = 360
					}
					give_technology = {
						tech = tech_object_gray_5
					}
					add_monthly_resource_mult = {
						resource = society_research
						value = 24
						min = 2000
					}
					give_technology = {
						tech = tech_minilaser_gray_1
					}
					tooltip = {
						add_monthly_resource_mult = {
							resource = society_research
							value = 24
							min = 2000
						}
						give_technology = {
							tech = tech_minilaser_gray_1
						}
						give_technology = {
							tech = tech_object_gray_5
						}
					}
				}
				RG_gift = {
					custom_tooltip = "RG_gift"
					country_event = {
						id = rg_event.2
						days = 360
					}
					give_technology = {
						tech = tech_object_gray_5
					}
					add_resource = {
						minerals = 10000
					}
					give_technology = {
						tech = tech_minilaser_gray_1
					}
					tooltip = {
						add_resource = {
							minerals = 10000
						}
						give_technology = {
							tech = tech_minilaser_gray_1
						}
						give_technology = {
							tech = tech_object_gray_5
						}
					}
				}
				RG_biggift = {
					custom_tooltip = "RG_biggift"
					country_event = {
						id = rg_event.2
						days = 360
					}
					give_technology = {
						tech = tech_object_gray_5
					}
					give_technology = {
						tech = tech_minilaser_gray_1
					}
					add_resource = {
						minerals = 1000000
					}
					tooltip = {
						give_technology = {
							tech = tech_object_gray_5
						}
						give_technology = {
							tech = tech_minilaser_gray_1
						}
						add_resource = {
							minerals = 1000000
						}
					}
				}
			}
		}
	}
}

country_event = {
	id = rg_event.7
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		remove_country_flag = gray_alreadybegged
	}
}

country_event = {
	###月中
	id = rg_event.8
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		has_country_flag = gray_owner
	}
	immediate = {
		every_owned_leader = {
			if = {
				###等级检测
				limit = {
					has_leader_flag = rg_gray_leader
				}
				export_trigger_value_to_variable = {
					trigger = has_skill
					variable = rg_gray_level_temp
				}
				owner = {
					set_variable = {
						which = rg_gray_level
						value = prev.rg_gray_level_temp
					}
				}
				clear_variable = rg_gray_level_temp
			}
		}
	}
}

# 开始改造
country_event = {
	id = rg_event.9
	title = rg_event.9.title
	desc = rg_event.9.desc
	picture = GFX_evt_gray_goo_ships
	is_triggered_only = yes
	trigger = {
		NOR = {
			has_country_flag = rg_gray_level_2
			has_country_flag = rg_gray_level_3
		}
	}
	immediate = {
		event_target:gray_warship = {
			set_event_locked = yes
		}
		event_target:gray_owner = {
			set_country_flag = rg_modifing_gray
		}
	}
	option = {
		name = rg_event.9.a
		default_hide_option = yes
	}
}

# 取消改造项目1
country_event = {
	id = rg_event.10
	title = rg_event.10.title
	desc = rg_event.10.desc
	picture = GFX_evt_gray_goo_ships
	is_triggered_only = yes
	immediate = {
		if = {
			limit = {
				exists = event_target:gray_warship
			}
			event_target:gray_warship = {
				set_event_locked = no
			}
		}
		else = {
			every_controlled_fleet = {
				limit = {
					has_fleet_flag = gray_fleet
				}
				set_event_locked = no
			}
		}
		remove_country_flag = rg_modifing_gray
		abort_special_project = {
			type = RG_GRAY_MOD1
		}
	}
	option = {
		name = rg_event.10.a
		default_hide_option = yes
	}
}

# mod1完成改造
country_event = {
	id = rg_event.11
	title = rg_event.11.title
	desc = rg_event.11.desc
	picture = GFX_evt_gray_goo_ships
	is_triggered_only = yes
	immediate = {
		remove_country_flag = rg_modifing_gray
		remove_country_flag = rg_gray_level_1
		set_country_flag = rg_gray_level_2
		every_controlled_fleet = {
			limit = {
				has_fleet_flag = gray_fleet
			}
			delete_fleet = {
				target = this
				kill_leader = no
				destroy_template = yes
			}
		}
		rg_warship_init_mod1 = yes
		random_situation = {
			limit = {
				is_situation_type = situation_rg_gray_mod1
			}
			remove_situation_flag = rg_stage6_locked
			set_situation_locked = no
			remove_situation_flag = locked
		}
	}
	option = {
		name = OK
	}
}

# mod2完成改造
country_event = {
	id = rg_event.12
	title = rg_event.12.title
	desc = rg_event.12.desc
	picture = GFX_evt_gray_goo_ships
	is_triggered_only = yes
	immediate = {
		remove_country_flag = rg_modifing_gray
		remove_country_flag = rg_gray_level_1
		remove_country_flag = rg_gray_level_2
		set_country_flag = rg_gray_level_3
		every_controlled_fleet = {
			limit = {
				has_fleet_flag = gray_fleet
			}
			delete_fleet = {
				target = this
				kill_leader = no
				destroy_template = yes
			}
		}
		create_ship_design = {
			design = "NAME_gray_capitalship"
		}
		add_ship_design = last_created_design
		rg_warship_init_mod2 = yes
	}
	option = {
		name = OK
	}
}

# 取消改造项目2
country_event = {
	id = rg_event.13
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		if = {
			limit = {
				exists = event_target:gray_warship
			}
			event_target:gray_warship = {
				set_event_locked = no
			}
		}
		else = {
			every_controlled_fleet = {
				limit = {
					has_fleet_flag = gray_fleet
				}
				set_event_locked = no
			}
		}
		remove_country_flag = rg_modifing_gray
		abort_special_project = {
			type = RG_GRAY_MOD2
		}
	}
}

# 取消改造项目3
country_event = {
	id = rg_event.14
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		if = {
			limit = {
				exists = event_target:gray_warship
			}
			event_target:gray_warship = {
				set_event_locked = no
			}
		}
		else = {
			every_controlled_fleet = {
				limit = {
					has_fleet_flag = gray_fleet
				}
				set_event_locked = no
			}
		}
		remove_country_flag = rg_modifing_gray
		abort_special_project = {
			type = RG_GRAY_MOD3
		}
	}
}

# mod3完成改造
country_event = {
	id = rg_event.15
	title = rg_event.15.title
	desc = rg_event.15.desc
	picture = GFX_evt_gray_goo_ships
	is_triggered_only = yes
	immediate = {
		remove_country_flag = rg_modifing_gray
		set_country_flag = rg_juggernaut_fired
	}
	option = {
		name = OK
	}
}

# 小灰陆军入侵完成替换回压制舰
country_event = {
	id = rg_event.16
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		has_country_flag = gray_army_active
		any_owned_army = {
			army_type = gray_army
			fleet = {
				NOT = {
					is_ship_size = RG_armed_transport_ship
				}
			}
		}
		NOT = {
			any_owned_army = {
				army_type = gray_army
				exists = planet
			}
		}
	}
	immediate = {
		every_owned_army = {
			limit = {
				army_type = gray_army
			}
			fleet = {
				save_event_target_as = gray_transport_location
			}
		}
		create_ship_design = {
			design = "NAME_RG_armed_transport_ship"
		}
		add_ship_design = last_created_design
		create_fleet = {
			name = "NAME_Gray"
			effect = {
				set_owner = prev
				create_army_transport = {
					ship_name = "NAME_Gray"
					army_name = "NAME_Gray"
					army_type = "gray_army"
				}
				set_location = {
					target = event_target:gray_transport_location
					distance = 0
					angle = random
				}
				set_fleet_stance = aggressive
			}
		}
		last_created_army = {
			assign_leader = event_target:gray_leader_general
		}
		remove_ship_design = last_created_design
		every_owned_army = {
			limit = {
				army_type = gray_army
				fleet = {
					NOT = {
						is_ship_size = RG_armed_transport_ship
					}
				}
			}
			if = {
				limit = {
					exists = leader
				}
				unassign_leader = leader
			}
			remove_army = yes
		}
	}
}

country_event = {
	# 年检补开门
	id = rg_event.17
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		any_megastructure = {
			is_megastructure_type = lgate_base
			has_megastructure_flag = lgate_activated
		}
	}
	immediate = {
		every_megastructure = {
			limit = {
				is_megastructure_type = lgate_base
				NOT = {
					has_megastructure_flag = lgate_activated
				}
			}
			activate_gateway = this
			set_megastructure_flag = lgate_activated
		}
	}
}

country_event = {
	# 中期开门
	id = rg_event.18
	title = rg_event.18.title
	desc = rg_event.18.desc
	is_triggered_only = yes
	fire_only_once = yes
	picture = GFX_evt_drifting_gateway
	trigger = {
		mid_game_years_passed >= 0
		NOT = {
			is_multiplayer = yes
			has_global_flag = has_origin_gray_dragon
		}
		has_country_flag = origin_rg_gray
		OR = {
			any_system_megastructure = {
				is_megastructure_type = lgate_base
				NOT = {
					has_megastructure_flag = lgate_activated
				}
			}
			NOT = {
				has_special_project = RG_LCLUSTER_PROJECT
			}
			has_special_project = LCLUSTER_PROJECT
		}
	}
	immediate = {
		give_technology = tech_lgate_activation
		if = {
			limit = {
				any_system_within_border = {
					OR = {
						has_star_flag = lcluster_lgate
						has_star_flag = lgate_originating_system
					}
					any_system_megastructure = {
						is_megastructure_type = l_gate_base
					}
				}
			}
			every_system_within_border = {
				limit = {
					OR = {
						has_star_flag = lcluster_lgate
						has_star_flag = lgate_originating_system
					}
					any_system_megastructure = {
						is_megastructure_type = l_gate_base
					}
				}
				save_event_target_as = candidate_gateway
			}
			country_event = {
				id = distar.10905
			}			# enable project
		}
		else = {
			country_event = {
				id = rg_event.21
				days = 120
			}
		}
	}
}
