on_actions = {
	#ROOT is new controller #FROM is old controller #FROM.FROM is state ID
	on_state_control_changed = {

		 ##  #    ##   ## ###     ###   ##   ##  ###  
		#  # #   #  # #   #       #  # #  # #  # #  # 
		#    #   #  #  #  ##      ###  #  # #### #  # 
		#  # #   #  #   # #       #  # #  # #  # #  # 
		 ##  ###  ##  ##  ###     #  #  ##  #  # ###  

		effect = {

			###  #  # ###  #   #  ##  
			#  # #  # #  # ## ## #  # 
			###  #  # ###  # # # #### 
			#  # #  # #  # #   # #  # 
			###   ##  #  # #   # #  # 
			if = {
				limit = {
					FROM.FROM = { has_state_flag = CHI_needed_for_burma_road }

					#Country that grabbed control should be interested in closing the road
					ROOT = {
						OR = {
							has_war_with = FROM
							any_country = {
								has_war_with = FROM
								OR = {
									is_in_faction_with = ROOT
									is_subject_of = ROOT								
								}
							}
						}
					}
				}
				FROM.FROM = {
					save_event_target_as = state_occupied
					set_state_flag = CHI_burma_road_closed_state
				}
				ROOT = { save_event_target_as = occupying_country }

				random_country = {
					limit = { check_variable = { CHI_burma_road_current_level > 0 } }
					set_variable = { tempvar = 0 }
					subtract_from_variable = { var = tempvar value = CHI_burma_road_current_level }

					#Country that had the burma road open
					add_offsite_building = { type = arms_factory level = tempvar }
					#In case we need to reopen
					set_variable = { CHI_burma_road_closed_level = CHI_burma_road_current_level }
					set_variable = { CHI_burma_road_current_level = 0 }
					clear_variable = tempvar
					country_event = { id = wtt_burma_road.1 }
				}

			}

			#   ### ###   ##  
			#   #   #  # #  # 
			#   ##  #  # #  # 
			#   #   #  # #  # 
			### ### ###   ##  
			if = {
				limit = {
					FROM.FROM = { has_state_flag = CHI_needed_for_ledo_road }

					#Country that grabbed control should be interested in closing the road
					ROOT = {
						OR = {
							has_war_with = FROM
							any_country = {
								has_war_with = FROM
								OR = {
									is_in_faction_with = ROOT
									is_subject_of = ROOT								
								}
							}
						}
					}
				}
				FROM.FROM = {
					save_event_target_as = state_occupied
					set_state_flag = CHI_ledo_road_closed_state
				}
				ROOT = { save_event_target_as = occupying_country }

				random_country = {
					limit = { check_variable = { CHI_ledo_road_current_level > 0 } }
					set_variable = { tempvar = 0 }
					subtract_from_variable = { var = tempvar value = CHI_ledo_road_current_level }

					#Country that had the ledo road open
					add_offsite_building = { type = arms_factory level = tempvar }
					#In case we need to reopen
					set_variable = { CHI_ledo_road_closed_level = CHI_ledo_road_current_level }
					set_variable = { CHI_ledo_road_current_level = 0 }
					clear_variable = tempvar
					country_event = { id = wtt_ledo_road.1 }
				}

			}

			#  #  ##  #  #  ##  ### 
			#  # #  # ## # #  #  #  
			#### #### # ## #  #  #  
			#  # #  # #  # #  #  #  
			#  # #  # #  #  ##  ### 
			if = {
				limit = {
					FROM.FROM = { has_state_flag = CHI_needed_for_hanoi_route }

					#Country that grabbed control should be interested in closing the road
					ROOT = {
						OR = {
							has_war_with = FROM
							any_country = {
								has_war_with = FROM
								OR = {
									is_in_faction_with = ROOT
									is_subject_of = ROOT								
								}
							}
						}
					}
				}
				FROM.FROM = { save_event_target_as = state_occupied }
				ROOT = { save_event_target_as = occupying_country }

				random_country = {
					limit = { check_variable = { CHI_hanoi_route_current_level > 0 } }
					set_variable = { tempvar = 0 }
					subtract_from_variable = { var = tempvar value = CHI_hanoi_route_current_level }

					#Country that had the burma road open
					add_offsite_building = { type = arms_factory level = tempvar }					
					set_variable = { CHI_hanoi_route_current_level = 0 }
					clear_variable = tempvar
					country_event = { id = wtt_hanoi_route.1 }
				}

			}

			### #  # ###     #  # #  # #   # ###  
			 #  #  # #       #  # #  # ## ## #  # 
			 #  #### ##      #### #  # # # # ###  
			 #  #  # #       #  # #  # #   # #    
			 #  #  # ###     #  #  ##  #   # #    
			if = {
				limit = {
					FROM.FROM = { has_state_flag = CHI_needed_for_the_hump }

					#Country that grabbed control should be interested in closing the road
					ROOT = {
						OR = {
							has_war_with = FROM
							any_country = {
								has_war_with = FROM
								OR = {
									is_in_faction_with = ROOT
									is_subject_of = ROOT								
								}
							}
						}
					}
				}
				FROM.FROM = {
					save_event_target_as = state_occupied
					set_state_flag = CHI_the_hump_closed_state
				}
				ROOT = { save_event_target_as = occupying_country }

				random_country = {
					limit = { check_variable = { CHI_the_hump_current_level > 0 } }
					set_variable = { tempvar = 0 }
					subtract_from_variable = { var = tempvar value = CHI_the_hump_current_level }

					#Country that had the airlift road open
					add_offsite_building = { type = arms_factory level = tempvar }
					#In case we need to reopen
					set_variable = { CHI_the_hump_closed_level = CHI_the_hump_current_level }
					set_variable = { CHI_the_hump_current_level = 0 }
					clear_variable = tempvar
					country_event = { id = wtt_the_hump.1 }
				}

			}


		###   ##  #   ### ### ###  ##   ##  #        ## ### ###  #  #  ##   ##  #   ### 
		#  # #  # #    #   #   #  #  # #  # #       #    #  #  # #  # #    #    #   #   
		###  #  # #    #   #   #  #    #### #        #   #  ###  #  # # ## # ## #   ##  
		#    #  # #    #   #   #  #  # #  # #         #  #  #  # #  # #  # #  # #   #   
		#     ##  ### ###  #  ###  ##  #  # ###     ##   #  #  #  ##   ##   ##  ### ### 
					
		}
	}

	#FROM is war target
	on_declare_war = {
		effect = {
		}
	}
	#FROM is faction leader on join faction requests.
	on_offer_join_faction = {
		effect = {
		}
	}

	on_leave_faction = {
		effect = {
		}
	}

	#ROOT is subject FROM is overlord
	on_subject_annexed = {
		effect = {
		}
	}

	on_nuke_drop = {
		effect = {			
		}
	}

	#ROOT is winner #FROM gets annexed - For civil wars on_civil_war_end is also fired
	on_annex = {
		effect = {
		}
	}

	#ROOT is winner #FROM gets annexed - This will also fire on_annex
	on_civil_war_end = {
		effect = {
		}
	}

	#ROOT is winner #FROM is loser
	on_peaceconference_ended = {
		effect = {
		}
	}
}