######################################
# 
# Crisis Triggering Events
#
######################################

namespace = crisis_trigger

event = {
	id = crisis_trigger.1
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_crises_allowed = yes
		end_game_years_passed >= 5
	}

	immediate = {
		random_country = {
			limit = { is_country_type = global_event } # global_event country is always around

			random_list = {

				### Prethoryn Scourge (Swarm)
				10 = { 
					modifier = {
						factor = 2
						end_game_years_passed >= 6
					}
					modifier = {
						factor = 3
						end_game_years_passed >= 8
					}
					modifier = {
						factor = 4
						end_game_years_passed >= 10
					}
					country_event = { id = crisis.10 days = 200 random = 800 }
					set_global_flag = galactic_crisis_happened
				}

				### Unbidden (Extradimensionals)
				10 = {
					modifier = {
						factor = 0
						NOT = {
							any_country = {
								is_country_type = default
								OR = {
									has_technology = "tech_psi_jump_drive_1"
									has_technology = "tech_jump_drive_1"
								}							
							}						
						}
					}				
					modifier = {
						factor = 4
						any_country = {
							is_country_type = default
							has_technology = "tech_psi_jump_drive_1"
						}
					}
					modifier = {
						factor = 1.5
						any_country = {
							is_country_type = default
							has_country_flag = completed_rogue_scientist
						}
					}
					country_event = { id = crisis.1000 days = 200 random = 800 }
					set_global_flag = galactic_crisis_happened
				}

				### Contingency (AI)
				10 = {
					modifier = {
						factor = 1.3
						any_country = {
							is_country_type = default
							pop_percentage = {
								percentage > 0.1
								limit = {
									has_trait = "trait_robotic_3" 
									is_growing = no
								}
							}
						}
					}
					modifier = {
						factor = 1.2
						any_country = {
							is_country_type = fallen_empire
							has_authority = auth_machine_intelligence
						}
					}	
					modifier = {
						factor = 1.25
						any_country = {
							has_authority = auth_machine_intelligence
						}
					}
					modifier = {
						factor = 1.5
						any_country = {
							has_authority = auth_machine_intelligence
							count_owned_pops = {
								limit = { has_trait = trait_machine_unit }
								count > 99
							}
						}
					}
					modifier = {
						factor = 2
						any_country = {
							has_authority = auth_machine_intelligence
							count_owned_pops = {
								limit = { has_trait = trait_machine_unit }
								count > 199
							}
						}
					}
					modifier = {
						factor = 3
						any_country = {
							has_authority = auth_machine_intelligence
							count_owned_pops = {
								limit = { has_trait = trait_machine_unit }
								count > 299
							}
						}
					}
					modifier = {
						factor = 2
						any_country = {
							is_country_type = default
							pop_percentage = {
								percentage > 0.25
								limit = {
									has_trait = "trait_robotic_3" 
									is_growing = no
								}
							}
						}
					}
					modifier = {
						factor = 2
						any_country = {
							is_country_type = default
							pop_percentage = {
								percentage > 0.50
								limit = {
									has_trait = "trait_robotic_3" 
									is_growing = no
								}
							}
						}
					}
					modifier = {
						factor = 2
						any_country = {
							is_country_type = default
							pop_percentage = {
								percentage > 0.75
								limit = {
									has_trait = "trait_robotic_3" 
									is_growing = no
								}
							}
						}
					}
					country_event = { id = crisis.2005 days = 200 random = 800 }
					set_global_flag = galactic_crisis_happened
				}

				### Nothing
				120 = {}
			}
		}
	}
}
