﻿namespace = asp

#geocentrism #https://gall.dcinside.com/mgallery/board/view?id=stellaris&no=8943

#geocentric
ship_event = {
	id = asp.15
	title = "asp.15.name"
	desc = "asp.15.desc"
	picture = GFX_evt_clocks

	is_triggered_only = yes
	
	immediate = {
		from = { create_archaeological_site = ASP_site_geocentrism }
	}

	option = {
		name = asp.15.a
	}
}
#buried city
fleet_event = {
	id = asp.16
	title = "asp.16.name"
	desc = "asp.16.desc"
	picture = GFX_evt_junkheap
	show_sound = event_wind_ruins
	
	archaeology = yes

	is_triggered_only = yes
	
	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = { 
		from = { set_site_progress_locked = no }
	}

	option = {
		name = DIG
		small_artifact_reward = yes
	}
}
#road cannot be taken
fleet_event = {
	id = asp.17
	title = "asp.17.name"
	desc = "asp.17.desc"
	picture = GFX_evt_alien_ruins
	show_sound = event_ghost_town
	
	archaeology = yes

	is_triggered_only = yes
	
	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = { 
		from = { set_site_progress_locked = no }
	}

	option = {
		name = asp.17.a
		owner = { add_modifier = { modifier = aspmod_engineering_bonus years = 10 } }
	}
	option = {
		name = asp.17.b
		owner = { add_modifier = { modifier = aspmod_physics_bonus years = 10 } }
	}
	option = {
		name = asp.17.c
		owner = { add_modifier = { modifier = aspmod_society_bonus years = 10 } }
	}
}
#whimper of dead planet's inhabitant
fleet_event = {
	id = asp.18
	title = "asp.18.name"
	desc = "asp.18.desc"
	picture = GFX_evt_alien_segregation
	show_sound = event_whispering
	
	archaeology = yes

	is_triggered_only = yes
	
	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = { 
		from = { set_site_progress_locked = no }
	}

	option = {
		name = DIG
		small_artifact_reward = yes
	}
}
#the flat world religious society
fleet_event = {
	id = asp.19
	title = "asp.19.name"
	desc = "asp.19.desc"
	picture = GFX_evt_alien_propaganda
	show_sound = event_conversation
	
	archaeology = yes

	is_triggered_only = yes
	
	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = { 
		from = { set_site_progress_locked = no }
	}

	option = {
		name = DIG
		medium_artifact_reward = yes
	}
}
#faithful suicide
fleet_event = {
	id = asp.20
	title = "asp.20.name"
	desc = "asp.20.desc"
	picture = GFX_evt_asp.20
	show_sound = event_ship_explosion
	
	archaeology = yes

	is_triggered_only = yes
	
	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = { 
		from = { set_site_progress_locked = no }
		if = {
			limit = { owner = { has_policy_flag = aspmod_archaeology_cleanup_active } }
			destroy_archaeological_site = from
		}
	}

	option = {
		name = asp.20.a
		trigger = {
			owner = {
				OR = {
					has_ethic = ethic_spiritualist
					has_ethic = ethic_fanatic_spiritualist
				}
			}
		}
		owner = { add_modifier = { modifier = aspmod_bad_precedent years = 10 } }
		hidden_effect = {
			owner = { country_event = { id = asp.21 } }
		}
	}
	option = {
		name = asp.20.b
		trigger = {
			owner = {
				OR = {
					has_ethic = ethic_materialist
					has_ethic = ethic_fanatic_materialist
				}
			}
		}
		owner = { add_modifier = { modifier = aspmod_lesson_from_pools years = 20 } }
		hidden_effect = {
			owner = { country_event = { id = asp.21 } }
		}
	}
	option = {
		name = asp.20.c
		owner = { add_modifier = { modifier = aspmod_caution_of_fanatics years = 10 } }
		hidden_effect = {
			owner = { country_event = { id = asp.21 } }
		}
	}
}
country_event = {
	id = asp.21
	title = "asp.21.name"
	desc = "asp.21.desc"
	picture = GFX_evt_planet_beam
	
	is_triggered_only = yes

	option = {
		name = asp.21.a
		add_resource = {
			influence = 200
			alloys = 5000
		}
		add_monthly_resource_mult = {
			resource = unity
			value = 24
		}
	}
	option = {
		name = asp.21.b
		if = {
			limit = { NOT = { host_has_dlc = Apocalypse } }
			custom_tooltip = asp.21.b.tooltip
		}
		allow = { host_has_dlc = Apocalypse }
		add_relic = r_aspmod_geocentric_device
		give_technology = { tech = tech_aspmod_geocentric_device message = yes } #colossus weapon
	}
}

namespace = asprelic

#geocentric device weapon effect
planet_event = {
	id = asprelic.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		exists = from.owner
		from.owner = { has_relic = r_aspmod_geocentric_device }
	}

	immediate = {
		# modifiers for victim
		if = {
			limit = {
				exists = owner
				owner = { NOT = { is_same_value = from.owner } }
			}
			owner = {
				if = {
					limit = { root = { is_colony = no } }
					add_opinion_modifier = {
						modifier = opinion_cracked_my_uninhabited_world
						who = from.owner
					}
				}
				else = {
					add_opinion_modifier = {
						modifier = opinion_cracked_my_world
						who = from.owner
					}
				}
				if = {
					limit = { NOT = { has_ethic = ethic_gestalt_consciousness } }
					add_modifier = {
						modifier = colossus_victim
						days = 10800 # 30 years
					}
				}
			}
		}
		# Generate threat
		if = {
			limit = {
				exists = owner
				owner = { NOT = { is_same_value = from.owner } }
				is_colony = yes
			}
			add_threat = { who = from.owner amount = 3 }
			# modifier for allies + those upset by genocide
			every_country = {
				limit = {
					NOR = {
						is_same_value = from.owner
						AND = { root = { exists = owner } is_same_value = root.owner }
						AND = {
							has_federation = yes
							is_in_federation_with = from.owner
						}
					}
					OR = {
						has_communications = from.owner
						AND = { root = { exists = owner } has_communications = root.owner }
					}
					OR = {
						AND = {
							has_federation = yes
							AND = { root = { exists = owner } is_in_federation_with = root.owner }
						}
						has_ai_personality = awakened_fallen_empire_xenophile
						AND = {
							is_country_type = default
							OR = {
								is_egalitarian = yes
								is_xenophile = yes
							}
						}
					}
				}
				if = {
					limit = { root = { is_colony = no } }
					add_opinion_modifier = {
						modifier = opinion_cracked_an_uninhabited_world
						who = from.owner
					}
				}
				else = {
					add_opinion_modifier = {
						modifier = opinion_cracked_a_world
						who = from.owner
					}
				}
			}
		}
		else_if = {
			limit = {
				exists = owner
				owner = { NOT = { is_same_value = from.owner } }
			}
			add_threat = { who = from.owner amount = 1 }
		}
		if = {
			limit = {
				exists = owner
				owner = {
					is_country_type = primitive
					NOT = { is_same_value = from.owner }
				}
			}
			# modifier for allies + those upset by genocide
			every_country = {
				limit = {
					NOT = { is_same_value = from.owner }
					OR = {
						has_communications = from.owner
						AND = { root = { exists = owner } has_communications = root.owner }
					}
					OR = {
						has_ai_personality = awakened_fallen_empire_xenophile
						AND = {
							is_country_type = default
							NOR = {
								is_xenophobe = yes
								is_homicidal = yes
								is_xenophile = yes
							}
						}
					}
				}
				add_opinion_modifier = {
					modifier = opinion_cracked_a_primitive_world
					who = from.owner
				}
			}
			every_country = {
				limit = {
					NOT = { is_same_value = from.owner }
					OR = {
						has_communications = from.owner
						AND = { root = { exists = owner } has_communications = root.owner }
					}
					OR = {
						has_ai_personality = awakened_fallen_empire_xenophile
						AND = {
							is_country_type = default
							is_xenophile = yes
						}
					}
				}
				add_opinion_modifier = {
					modifier = opinion_cracked_a_primitive_world_phile
					who = from.owner
				}
			}
		}
		# Add war exhaustion to planet owner
		if = {
			limit = {
				exists = owner
				exists = from.fleet
				exists = from.fleet.owner
			}
			owner = {
				if = {
					limit = { is_at_war_with = from.fleet.owner }
					add_static_war_exhaustion = {
						attacker = from.fleet.owner
						location = root
						value_for_planet_destruction = 1.0
					}
				}
			}
		}
		aspmod_geo_centralizer_colossus_effect = yes
	}
}
#in case of the relic has stolen
planet_event = {
	id = asprelic.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		exists = from.owner
		from.owner = { NOT = { has_relic = r_aspmod_geocentric_device } }
	}

	immediate = {
		# modifiers for victim
		if = {
			limit = {
				exists = owner
				owner = { NOT = { is_same_value = from.owner } }
			}
			owner = {
				if = {
					limit = { root = { is_colony = no } }
					add_opinion_modifier = {
						modifier = opinion_cracked_my_uninhabited_world
						who = from.owner
					}
				}
				else = {
					add_opinion_modifier = {
						modifier = opinion_cracked_my_world
						who = from.owner
					}
				}
				if = {
					limit = { NOT = { has_ethic = ethic_gestalt_consciousness } }
					add_modifier = {
						modifier = colossus_victim
						days = 10800 # 30 years
					}
				}
			}
		}
		# Generate threat
		if = {
			limit = {
				exists = owner
				owner = { NOT = { is_same_value = from.owner } }
				is_colony = yes
			}
			add_threat = { who = from.owner amount = 3 }
			# modifier for allies + those upset by genocide
			every_country = {
				limit = {
					NOR = {
						is_same_value = from.owner
						AND = { root = { exists = owner } is_same_value = root.owner }
						AND = {
							has_federation = yes
							is_in_federation_with = from.owner
						}
					}
					OR = {
						has_communications = from.owner
						AND = { root = { exists = owner } has_communications = root.owner }
					}
					OR = {
						AND = {
							has_federation = yes
							AND = { root = { exists = owner } is_in_federation_with = root.owner }
						}
						has_ai_personality = awakened_fallen_empire_xenophile
						AND = {
							is_country_type = default
							OR = {
								is_egalitarian = yes
								is_xenophile = yes
							}
						}
					}
				}
				if = {
					limit = { root = { is_colony = no } }
					add_opinion_modifier = {
						modifier = opinion_cracked_an_uninhabited_world
						who = from.owner
					}
				}
				else = {
					add_opinion_modifier = {
						modifier = opinion_cracked_a_world
						who = from.owner
					}
				}
			}
		}
		else_if = {
			limit = {
				exists = owner
				owner = { NOT = { is_same_value = from.owner } }
			}
			add_threat = { who = from.owner amount = 1 }
		}
		if = {
			limit = {
				exists = owner
				owner = {
					is_country_type = primitive
					NOT = { is_same_value = from.owner }
				}
			}
			# modifier for allies + those upset by genocide
			every_country = {
				limit = {
					NOT = { is_same_value = from.owner }
					OR = {
						has_communications = from.owner
						AND = { root = { exists = owner } has_communications = root.owner }
					}
					OR = {
						has_ai_personality = awakened_fallen_empire_xenophile
						AND = {
							is_country_type = default
							NOR = {
								is_xenophobe = yes
								is_homicidal = yes
								is_xenophile = yes
							}
						}
					}
				}
				add_opinion_modifier = {
					modifier = opinion_cracked_a_primitive_world
					who = from.owner
				}
			}
			every_country = {
				limit = {
					NOT = { is_same_value = from.owner }
					OR = {
						has_communications = from.owner
						AND = { root = { exists = owner } has_communications = root.owner }
					}
					OR = {
						has_ai_personality = awakened_fallen_empire_xenophile
						AND = {
							is_country_type = default
							is_xenophile = yes
						}
					}
				}
				add_opinion_modifier = {
					modifier = opinion_cracked_a_primitive_world_phile
					who = from.owner
				}
			}
		}
		# Add war exhaustion to planet owner
		if = {
			limit = {
				exists = owner
				exists = from.fleet
				exists = from.fleet.owner
			}
			owner = {
				if = {
					limit = { is_at_war_with = from.fleet.owner }
					add_static_war_exhaustion = {
						attacker = from.fleet.owner
						location = root
						value_for_planet_destruction = 1.0
					}
				}
			}
		}
			# Apply the physical destruction only after opinion/threat/war-exhaustion logic.
			# Run this after the colony checks so they evaluate on the original planet state.
			if = {
				limit = {
					NOR = {
						is_planet_class = pc_habitat
						is_planet_class = pc_ringworld_habitable
					}
				}
				every_owned_pop_group = {
					kill_pop_group = {
						pop_group = this
						percentage = 1 # Current vanilla uses 1.0 for a complete effect.
					}
				}
				remove_all_buildings = yes
				change_pc = pc_barren_cold
			}
			if = {
				limit = { is_planet_class = pc_habitat }
				spawn_habitat_cracker_effect = yes
				remove_planet = yes
			}
			if = {
				limit = { is_planet_class = pc_ringworld_habitable }
				spawn_ringworld_cracker_effect = yes
				change_pc = pc_ringworld_habitable_damaged
			}
		}
	}

