ROM_change_sides = {
	
	# Allies

	ROM_change_sides_to_allies = {

		icon = decision_generic_nationalism

		allowed = {
			original_tag = ROM
		}

		available = {
			is_faction_leader = no
			has_capitulated = no
			any_country = {
				is_faction_leader = yes
				has_war_with = ROM
				OR = {
					has_government = democratic
					original_tag = ENG
					original_tag = USA
				}
			}
			OR = {
				has_country_leader = {
					character = ROM_king_michael
					ruling_only = yes
				}
				has_government = neutrality
				has_government = democratic
			}
			NOT = {
				FACTION_LEADER  = {
					has_government = democratic
				}
			}
			hidden_trigger = {
				NOT = { has_country_flag = romania_has_flipped_sides } #Romania shouldn't be able to keep switching sides all the time
			}
		}
		
		visible = {
			is_faction_leader = no # you shouldn't be able to betray your own faction
			original_tag = ROM
			NOT = { has_country_flag = romania_has_flipped_sides }
			hidden_trigger = { has_country_flag = can_change_sides_dem }
		}

		cost = 0
		
		fire_only_once = yes
		
		remove_effect = {
			hidden_effect = { clr_country_flag = can_change_sides_dem }
		}

		complete_effect = {
			#save current faction leader for use in the event
			hidden_effect = {
				random_country = {
					limit = {
						is_in_faction_with = ROOT
						is_faction_leader = yes
					}
					save_global_event_target_as = romania_former_ally_target
				}
			}
			#top priority is joining the Allies if they still exist
			if = {
				limit = {
					any_country = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = democratic
						OR = {
							original_tag = ENG
							is_in_faction_with = ENG
						}
					}
				}
				random_enemy_country = {
					limit = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = democratic
						OR = {
							original_tag = ENG
							is_in_faction_with = ENG
						}
					}
					save_event_target_as = romania_new_ally_target
				}
			}
			#then attempts to join the USA's faction
			else_if = {
				limit = {
					any_country = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = democratic
						OR = {
							original_tag = USA
							is_in_faction_with = USA
						}
					}
				}
				random_enemy_country = {
					limit = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = democratic
						OR = {
							original_tag = USA
							is_in_faction_with = USA
						}
					}
					save_event_target_as = romania_new_ally_target
				}
			}
			#then attempts to join any democratic faction
			else = {
				random_enemy_country = {
					limit = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = democratic
					}
					save_event_target_as = romania_new_ally_target
				}
			}
			event_target:romania_new_ally_target = {
				country_event = { id = DOD_romania.16 }
			}
			hidden_effect = {
				set_country_flag = romania_has_flipped_sides
			}
		}

		ai_will_do = {
			factor = 100
			modifier = {
				is_historical_focus_on = no
				factor = 0
			}
			modifier = {
				is_historical_focus_on = yes
				NOT = { date > 1944.08.08 }
				factor = 0
			}
		}

	}
	
	# Commintern

	ROM_change_sides_to_commintern = {

		icon = decision_generic_nationalism

		allowed = {
			original_tag = ROM
		}

		available = {
			is_faction_leader = no
			has_capitulated = no
			any_country = {
				is_faction_leader = yes
				has_war_with = ROM
				OR = {
					has_government = communism
					original_tag = SOV
				}
			}
			OR = {
				has_country_leader = {
					character = ROM_king_michael
					ruling_only = yes
				}
				has_government = communism
			}
			NOT = {
				FACTION_LEADER  = {
					has_government = communism
				}
			}
			hidden_trigger = {
				NOT = { has_country_flag = romania_has_flipped_sides } #Romania shouldn't be able to keep switching sides all the time
			}
		}
		
		visible = {
			is_faction_leader = no # you shouldn't be able to betray your own faction
			original_tag = ROM
			NOT = { has_country_flag = romania_has_flipped_sides }
			hidden_trigger = { has_country_flag = can_change_sides_com }
		}

		cost = 0
		
		fire_only_once = yes
		
		remove_effect = {
			hidden_effect = { clr_country_flag = can_change_sides_com }
		}

		complete_effect = {
			#save current faction leader for use in the event
			hidden_effect = {
				random_country = {
					limit = {
						is_in_faction_with = ROOT
						is_faction_leader = yes
					}
					save_global_event_target_as = romania_former_ally_target
				}
			}
			#top priority is joining the Commintern if they still exist
			if = {
				limit = {
					any_country = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = communism
						OR = {
							original_tag = SOV
							is_in_faction_with = SOV
						}
					}
				}
				random_enemy_country = {
					limit = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = communism
						OR = {
							original_tag = SOV
							is_in_faction_with = SOV
						}
					}
					save_event_target_as = romania_new_ally_target
				}
			}
			#then attempts to join any communist faction
			else = {
				random_enemy_country = {
					limit = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = communism
					}
					save_event_target_as = romania_new_ally_target
				}
			}
			event_target:romania_new_ally_target = {
				country_event = { id = DOD_romania.16 }
			}
			hidden_effect = {
				set_country_flag = romania_has_flipped_sides
			}
		}

		ai_will_do = {
			factor = 0
		}

	}
	
	# Axis

	ROM_change_sides_to_axis = {

		icon = decision_generic_nationalism

		allowed = {
			original_tag = ROM
		}

		available = {
			is_faction_leader = no
			has_capitulated = no
			any_country = {
				is_faction_leader = yes
				has_war_with = ROM
				OR = {
					has_government = fascism
					original_tag = GER
					original_tag = ITA
				}
			}
			OR = {
				has_country_leader = {
					character = ROM_king_michael
					ruling_only = yes
				}
				has_government = fascism
			}
			NOT = {
				FACTION_LEADER  = {
					has_government = fascism
				}
			}
			hidden_trigger = {
				NOT = { has_country_flag = romania_has_flipped_sides } #Romania shouldn't be able to keep switching sides all the time
			}
		}
		
		visible = {
			is_faction_leader = no # you shouldn't be able to betray your own faction
			original_tag = ROM
			NOT = { has_country_flag = romania_has_flipped_sides }
			hidden_trigger = { has_country_flag = can_change_sides_fas }
		}

		cost = 0
		
		fire_only_once = yes
		
		remove_effect = {
			hidden_effect = { clr_country_flag = can_change_sides_fas }
		}

		complete_effect = {
			#save current faction leader for use in the event
			hidden_effect = {
				random_country = {
					limit = {
						is_in_faction_with = ROOT
						is_faction_leader = yes
					}
					save_global_event_target_as = romania_former_ally_target
				}
			}
			#top priority is joining the Axis if they still exist
			if = {
				limit = {
					any_country = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = fascism
						OR = {
							original_tag = GER
							is_in_faction_with = GER
						}
					}
				}
				random_enemy_country = {
					limit = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = fascism
						OR = {
							original_tag = GER
							is_in_faction_with = GER
						}
					}
					save_event_target_as = romania_new_ally_target
				}
			}
			#then attempts to join Italy's faction
			else_if = {
				limit = {
					any_country = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = fascism
						OR = {
							original_tag = ITA
							is_in_faction_with = ITA
						}
					}
				}
				random_enemy_country = {
					limit = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = fascism
						OR = {
							original_tag = ITA
							is_in_faction_with = ITA
						}
					}
					save_event_target_as = romania_new_ally_target
				}
			}
			#then attempts to join any fascist faction
			else = {
				random_enemy_country = {
					limit = {
						is_faction_leader = yes
						has_war_with = ROM
						has_government = fascism
					}
					save_event_target_as = romania_new_ally_target
				}
			}
			event_target:romania_new_ally_target = {
				country_event = { id = DOD_romania.16 }
			}
			hidden_effect = {
				set_country_flag = romania_has_flipped_sides
			}
		}

		ai_will_do = {
			factor = 0
		}

	}
	
}