DJI_collapse = {
	set_global_flag = DJI_collapse
	#End of the DKAEB railway
	every_country = {
		limit = {
			OR = {
				tag = DJI
				tag = ETH
				tag = SOM
				tag = GER
				tag = MAF
				tag = UGA
				tag = COG
				tag = KTG
				tag = KIV
				tag = SUD
				tag = KEN
			}
		}
		country_event = {
			id = djibouti.12
			days = 1 random_days = 3
		}
	}
	#Give events to neighbours
	every_country = {
		limit = {
			OR = {
				tag = BRM
				tag = YEM
				tag = TUR
				tag = ETH
				tag = SOM
				tag = SAU
				tag = OMA
				tag = PRF
				tag = BHC
			}
		}
		country_event = {
			id = sharedafrika.71
			days = 3 random_days = 3
		}
	}
	#First give away any owned states to their controller, if we're at war
	every_owned_state = {
		limit = { NOT = { is_controlled_by = DJI } }
		save_event_target_as = giveaway
		controller = { transfer_state = event_target:giveaway }
	}
	#Now mark all existing breakaways
	every_country = {
		limit = {
			exists = yes
		}
		set_country_flag = DJI_already_exists
	}
	#Special people
	if = {
		limit = { owns_state = 753 } #Suez Canal
		var:446.owner = { country_event = sharedafrika.133 } #neighbour offered to take
	}
	if = {
		limit = { owns_state = 921 } #Aussa
		AFA = { transfer_state = 921 }
		ETH = {
			country_event = {
				id = sharedafrika.126 #ETH attack Aussa Sultanate?
				days = 2
			}
		}
		ERI = {
			country_event = {
				id = sharedafrika.126 #ERI attack Aussa Sultanate?
				days = 2
			}
		}
	}
	if = {
		limit = { owns_state = 961 } #Aussa take Denkel if DJI held onto it
		AFA = { transfer_state = 961 }
	}
	#Demilitarise them if still demilitarized
	if = {
		limit = {
			921 = {
				is_demilitarized_zone = yes
			}
		}
		921 = {
			set_demilitarized_zone = no
		}
	}
	if = {
		limit = {
			961 = {
				is_demilitarized_zone = yes
			}
		}
		961 = {
			set_demilitarized_zone = no
		}
	}
	if = {
		limit = { owns_state = 269 } #Hargeisa goes to SOM
		var:559.owner = { country_event = sharedafrika.133 } #neighbour offered to take
	}
	#Hand back Omani states if relevant
	if = {
		limit = { owns_state = 294 }
		OMA = { transfer_state = PREV }
	}
	if = {
		limit = { owns_state = 859 }
		OMA = { transfer_state = PREV }
	}
	if = {
		limit = { owns_state = 1024 }
		OMA = { transfer_state = PREV }
	}
	if = {
		limit = { owns_state = 347 }
		OMA = { transfer_state = PREV }
	}
	if = {
		limit = { owns_state = 907 } #Trucial States region
		var:812.owner = { country_event = sharedafrika.133 } #neighbour offered to take
	}
	if = {
		limit = { owns_state = 659 } #Aden
		var:293.owner = { country_event = sharedafrika.133 } #neighbour offered to take
	}
	if = {
		limit = {
			owns_state = 422 #Ceylon
		}
		CEY = {
			transfer_state = 422
			load_oob = CEY_AFR
			add_ideas = Generic_Colonial_Nation
		}
		DJI = {
			CEY = {
				transfer_technology = yes
			}
		}
	}
	if = {
		limit = {
			owns_state = 281 #Maldives
			country_exists = CEY
		}
		CEY = {
			transfer_state = 281
		}
	}
	if = {
		limit = {
			owns_state = 733 #Andamans
			country_exists = CEY
		}
		CEY = {
			transfer_state = 733
		}
	}
	if = {
		limit = {
			owns_state = 710 #Diego Garcia
			country_exists = CEY
		}
		CEY = {
			transfer_state = 710
		}
	}
	if = {
		limit = { owns_state = 1095 } #Pondicherry
		var:320.owner = { country_event = sharedafrika.133 } #neighbour offered to take
	}
	if = {
		limit = { owns_state = 790 } #Rakhine
		var:288.owner = { country_event = sharedafrika.133 } #neighbour offered to take
	}
	if = {
		limit = {
			owns_state = 706 #Reunion
		}
		MAG = {
			transfer_state = 706
		}
	}
	if = {
		limit = {
			owns_state = 707 #Mauritius
		}
		MAG = {
			transfer_state = 707
		}
	}
	#Anything left, give it to a random neighbor
	every_owned_state = {
		limit = {
			NOT = {
				state = 268
			}
			any_neighbor_state = {
				NOT = {
					is_owned_by = DJI
					}
				}
			}
		save_event_target_as = giveaway
		random_neighbor_state = {
			limit = {
				NOT = {
					is_owned_by = DJI
					}
				}
			owner = {
				transfer_state = event_target:giveaway
			}
		}
	}
	every_owned_state = {
		limit = {
			NOT = {
				state = 268
			}
			any_neighbor_state = {
				NOT = { is_owned_by = DJI }
				}
			}
		save_event_target_as = giveaway
		random_neighbor_state = {
			limit = {
				NOT = {
					is_owned_by = DJI
					}
				}
			owner = {
				transfer_state = event_target:giveaway
			}
		}
	}
	#Still stuff left? Give it to GER
	if = {
		limit = {
			country_exists = DJI
		}
		every_owned_state = {
		limit = {
			NOT = {
				state = 268
				}
			}
			GER = {
				transfer_state = PREV
			}
		}
	}
	every_country = {
		limit = { has_country_flag = DJI_already_exists }
		clr_country_flag = DJI_already_exists
	}
	every_state = {
		limit = { is_core_of = DJI }
		remove_core_of = DJI
	}
	every_state = {
		limit = { is_claimed_by = DJI }
		remove_claim_by = DJI
	}
	#Now set up Dschibouti
	add_named_threat = {
		threat = 1
		name = Vestasien_collapse
	}
	#Remove from faction and autonomy, as it will later get sorted
	GER = {
			set_autonomy = {
			target = DJI
			autonomous_state = autonomy_free
		}
	}
	GER = {
		remove_from_faction = DJI
	}
	DJI = {
		load_focus_tree = african_republic_authoritarian
		delete_unit_template_and_units = {
			division_template = "Miliztruppe"
			division_template = "Infanterie-Division"
			division_template = "Auslands-Festungskommando"
		}
		add_state_core = 268
		country_event = {
			id = djibouti.1
			days = 1 random_days = 3
		}
		country_event = {
			id = djibouti.11
			days = 5 random_days = 3
		}
		add_ideas = {
			DJI_chaos_n_shit
		}
		remove_ideas = {
			DJI_chaotic_governance
			DJI_east_of_suez
			DJI_aog_backing
		}
		drop_cosmetic_tag = yes
		set_cosmetic_tag = DJI_GER
	}
}

