rg_event_effect_event1_dragon = {
	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 = {
			trait = RG_leader_trait_admiral_born_tobe_dragon
			show_message = no
		}
		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
	}
}

#fired from rg_event.1
rg_event_effect_event1_cluster = {
	#第一个遥远约定起源的全局标记
	set_global_flag = origin_rg_gray_1st_global
	#第一个遥远约定起源的国家标记
	set_country_flag = origin_rg_gray_1st
	#遥远约定星团起源的国家标记
	set_country_flag = origin_rg_gray_cluster
	#设置小灰改造等级初始为1
	set_country_flag = rg_gray_level_1
	#给点初始资源免得开局饿死
	add_resource = {
		energy = 1000
		minerals = 1000
		alloys = 1000
		consumer_goods = 1000
	}
	#给遥远群星modifier减跃迁范围防止跳出去
	add_modifier = {
		modifier = rg_distant_stars_modifier
	}
	#保存成遥远约定起源国家全局target
	save_global_event_target_as = origin_rg_gray_country
	#调用小灰打招呼事件
	country_event = {
		id = rg_event.2
		days = 30
	}
	# 生成L星团 还没做TODO
	# rg_lcluster_spawn_effect = yes
	#计时器十年自动开门事件 还没做TODO
	# country_event = {
	# 	id = rg_event.18
	# 	days = 3600
	# 	random = 12800
	# }
}
#fired from rg_event.1
rg_event_effect_event1_galaxy = {
	#第一个遥远约定起源的全局标记
	set_global_flag = origin_rg_gray_1st_global
	#第一个遥远约定起源的国家标记
	set_country_flag = origin_rg_gray_1st
	#遥远约定银河起源的国家标记
	set_country_flag = origin_rg_gray_galaxy
	#设置小灰改造等级初始为1
	set_country_flag = rg_gray_level_1
	#由于这里用的是玩家自己选的开局星球所以不送资
	
	#保存成遥远约定起源国家全局target
	save_global_event_target_as = origin_rg_gray_country
	if = {
		limit = {
			#有遥远的故事起源国家,这个条件为什么在这我忘了
			any_country = {
				has_origin = origin_Asgray
			}
		}
	}
	#调用小灰打招呼事件
	country_event = {
		id = rg_event.2
		days = 30
	}
	#立刻开门，防止玩家再次进L星团再刨一个小灰出来
	else = {
		rg_lcluster_spawn_effect = yes
		capital_scope = {
			solar_system = {
				random_neighbor_system = {
					solar_system = {
						set_star_flag = lgate
						spawn_megastructure = {
							type = lgate_base
							orbit_angle = 225
							orbit_distance = 30
						}
					}
				}
			}
		}
	}
}


rg_event_effect_event1_gray_cluster = {
	set_global_flag = origin_rg_gray_1st_global
	set_country_flag = origin_rg_gray_cluster
	set_country_flag = origin_rg_gray_1st
	set_country_flag = rg_gray_level_1
	rg_event_effect_event1_to_event2_effect = yes
	add_resource = {
		energy = 1000
		minerals = 1000
		alloys = 1000
		consumer_goods = 1000
	}
	add_modifier = {
		modifier = rg_distant_stars_modifier
	}
	save_global_event_target_as = origin_rg_gray_country
	rg_lcluster_spawn_effect = yes
	country_event = {
		id = rg_event.18
		days = 3600
		random = 12800
	}
}

rg_event_effect_event1_gray_galaxy = {
	set_global_flag = origin_rg_gray_1st_global
	set_country_flag = origin_rg_gray_galaxy
	set_country_flag = origin_rg_gray_1st
	set_country_flag = rg_gray_level_1
	rg_event_effect_event1_to_event2_effect = yes
	save_global_event_target_as = origin_rg_gray_country
	if = {
		limit = {
			rg_has_ag_origin_trigger = yes
		}
	}
	else = {
		rg_lcluster_spawn_effect = yes
		capital_scope = {
			solar_system = {
				random_neighbor_system = {
					solar_system = {
						set_star_flag = lgate
						spawn_megastructure = {
							type = lgate_base
							orbit_angle = 225
							orbit_distance = 30
						}
					}
				}
			}
		}
	}
}

rg_event_effect_lcluster_spawn_selecter = {
	if = {
		limit = {
			event_target:origin_rg_gray_country = {
				OR = {
					has_civic = civic_rg_gray_cluster
				}
			}
		}
		country_event = {
			id = rg_cluster.9
			days = -1
		}
	}
	else_if = {
		limit = {
			event_target:origin_rg_gray_country = {
				has_civic = civic_rg_gray_non_cluster
			}
		}
		rg_event_effect_lcluster_open = yes
	}
	else = {
		country_event = {
			id = rg_cluster.9
			days = -1
		}
	}
}

rg_event_effect_lcluster_open = {
	if = {
		limit = {
			OR = {
				has_global_flag = l_cluster_origin						# l-cluster plus
				has_global_flag = rg_origin_l_cluster						# 遥远约定
				has_global_flag = gray_origin_activate						# 远星之歌
				has_global_flag = rg_origin_scion_l_cluster					# 未来追迹
				rg_has_ag_origin_trigger = yes	# 遥远的故事
			}

		}
		country_event = {
			id = rg_cluster.2
		}
	}
	else = {
		country_event = {
			id = distar.10950
		}
	}
}

#Species
rg_event_effect_planet2027_spawn_maid_species = {
	modify_species = {
		effect = {
			create_species = {
				is_mod = yes
				name = "RG_MACHINE"
				plural = this
				class = RG_MACHINE
				portrait = "rg_machine_maid"
				can_be_modified = yes
				homeworld = this
				namelist = this
				gender = this
				traits = {
					trait = trait_rg_machine_unit
					trait = rg_machine_maid_trait
					trait = trait_auto_mod_robotic
					trait = trait_robot_streamlined_protocols
					trait = trait_robot_luxurious
				}
				effect = {
					save_global_event_target_as = rg_owner_main_maid_species
					set_citizenship_type = {
						type = citizenship_full_rg_maid
						country = event_target:gray_owner
					}
				}
			}
		}
	}
}

#Species
rg_event_effect_planet2027_spawn_maid_species_non_gray = {
	modify_species = {
		effect = {
			create_species = {
				is_mod = yes
				name = "RG_MACHINE"
				plural = this
				class = RG_MACHINE
				portrait = "rg_machine_maid"
				can_be_modified = yes
				homeworld = this
				namelist = this
				gender = this
				traits = {
					trait = trait_rg_machine_unit
					trait = rg_machine_maid_trait
					trait = trait_auto_mod_robotic
					trait = trait_robot_streamlined_protocols
					trait = trait_robot_luxurious
				}
				effect = {
					set_citizenship_type = {
						type = citizenship_full_rg_maid
						country = event_target:gray_owner
					}
				}
			}
		}
	}
}