CHI_unit_production = {
	allowed = { original_tag = CHI }
	enable = {
		always = yes
	}
	abort = {
		always = no
	}
	
	# Ragnarok added
	#ai_strategy = {
	#	type = role_ratio
	#	id = garrison
	#	value = 0
	#}


	ai_strategy = {
		type = role_ratio
		id = paratroopers
		value = 0
	}

	ai_strategy = {
		type = role_ratio
		id = mountaineers
		value = 0
	}

	ai_strategy = {
		type = role_ratio
		id = marines
		value = 0
	}

	ai_strategy = {
		type = role_ratio
		id = armor
		value = -10
	}

	ai_strategy = {
		type = role_ratio
		id = infantry
		value = 100
	}
	
	#Air unit factors
	ai_strategy = {
		type = unit_ratio
		id = fighter
		value = 75 # From 70 to 75
	}
	
	ai_strategy = {
		type = unit_ratio
		id = cas
		value = 0
	}
	
	ai_strategy = {
		type = unit_ratio
		id = tactical_bomber
		value = 0
	}
	
	ai_strategy = {
		type = unit_ratio
		id = strategic_bomber
		value = 0
	}
	
	ai_strategy = {
		type = unit_ratio
		id = naval_bomber
		value = 0
	}
	
	
	# Naval unit factors
	ai_strategy = {
		type = unit_ratio
		id = capital_ship
		value = 25 # from 15 to 25
	}

	ai_strategy = {
		type = unit_ratio
		id = submarine
		value = 40 #from 50 to 40
	}

	ai_strategy = {
		type = unit_ratio
		id = screen_ship
		value = 20
	}

	ai_strategy = {
		type = unit_ratio
		id = convoy
		value = 20
	}
	
	ai_strategy = {
		type = ignore_army_incompetence
		value = 20
	}
}

CHI_dont_waste_on_offensive_air_early = {
	allowed = { original_tag = CHI }
	enable = {
		date < 1940.1.1
	}
	abort = {
		date > 1940.1.1
	}

	ai_strategy = {
		type = equipment_variant_production_factor
		id = medium_plane_airframe
		value = -100
	}
	
	ai_strategy = {
		type = equipment_variant_production_factor
		id = large_plane_airframe
		value = -100
	}
}

CHI_armored_production = {
	allowed = { original_tag = CHI }
	enable = {
		ai_wants_divisions > 0 #Decreasing the amount of tanks the AI wants
	}
	abort = {
		ai_wants_divisions < 1 #Decreasing the amount of tanks the AI wants
	}

	ai_strategy = {
		type = role_ratio
		id = armor
		value = 0
	}
}

CHI_dont_upgrade_to_weapons_2_too_early = {
	allowed = {
		original_tag = CHI
	}
	enable = {
		is_historical_focus_on = yes
		has_equipment = { infantry_equipment < 0 }
	}

	abort_when_not_enabled = yes

	ai_strategy = { # It's going to be disastrous for us to switch this up in early 37. Let's wait until we have more gun
		type = production_upgrade_desire_offset
		id = infantry_equipment_2
		value = -100
	}
}

CHI_highered_armored_production = {
	allowed = { original_tag = CHI }
	enable = {
		num_of_military_factories > 109
	}
	abort = {
		num_of_military_factories < 110
	}

	ai_strategy = {
		type = role_ratio
		id = armor
		value = 0
	}
}

CHI_prio_military_even_at_peace = {
	allowed = { original_tag = CHI }
	enable = {
		always = yes
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = added_military_to_civilian_factory_ratio
		value = 50
	}
	
}
	
CHI_dont_mess_with_the_soviets = {

	allowed = { original_tag = CHI }
	enable = {	
		NOT = { has_war_with = SOV }
	}
	
	abort = {
		has_war_with = SOV
	}

	ai_strategy = {
		type = contain
		id = "SOV"			
		value = -200
	}
}

CHI_some_safer_places_to_build = {
	allowed = { original_tag = CHI }
	enable = {
		OR = {
			controls_state = 602
			controls_state = 605
		}
	}

	abort = {
		date > 1941.1.1
	}

	ai_strategy = {
        type = factory_build_score_factor
        target =  602
        value = 300
    }

	ai_strategy = {
        type = factory_build_score_factor
        target =  605
        value = 300
    }
}

CHI_some_safer_places_to_build_2 = {
	allowed = { original_tag = CHI }
	enable = {
		always = yes
	}

	abort = {
		date > 1941.1.1
	}

	ai_strategy = {
        type = factory_build_score_factor
        target =  748
        value = 300
    }

	ai_strategy = {
        type = factory_build_score_factor
        target =  603
        value = 300
    }

	ai_strategy = {
        type = factory_build_score_factor
        target =  750
        value = 300
    }
}

CHI_you_should_be_prepared_for_war = {
	allowed = { 
		is_literally_china = yes
		NOT = { has_dlc = "No Compromise, No Surrender"}
	}
	enable = {
		date < 1938.6.1
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
        type = force_build_armies
        value = 100
    }
}

CHI_buffer_in_mainland = {
	allowed = {
		NOT = { has_dlc = "No Compromise, No Surrender"}
		is_literally_china_not_prc = yes
	}
	enable = {
		date < 1941.1.1
	}
	abort = {
		has_war_with = GER # Ragnarok added
	}
	
	ai_strategy = {
		type = put_unit_buffers
		states = {
			620 #Mainland china, without coast. This should slow down japanese advance due to tendency for china to retreat in disarray.
			602
			600
			750
			603
			748
			605
		}
		ratio = 0.15
		area = asia
		subtract_invasions_from_need = no
		subtract_fronts_from_need = yes
	}
}

#We need to protect all of our northern front and coastline because Japan is *knock knock konishiwa* soon
CHI_buffer_on_northern_borders_and_coast = {
	allowed = {
		has_dlc = "No Compromise, No Surrender"
		is_literally_china_not_prc = yes
	}
	enable = {
		date < 1941.1.1
		OR = {
			original_tag = CHI
			is_in_faction_with = CHI
		}
		has_war = no
	}
	abort = {
		has_war_with = GER # Ragnarok added
	}
	
	ai_strategy = {
		type = put_unit_buffers
		states = {
			598
			607
			1034
			596
			595
			606
		}
		ratio = 0.2
		area = asia
		subtract_invasions_from_need = no
		subtract_fronts_from_need = yes
	}
}

#We need to have a buffer in interior states so we don't get steamrolled if Japan breaks through our front lines
CHI_buffer_in_interior_china = {
	allowed = {
		has_dlc = "No Compromise, No Surrender"
		is_literally_china_not_prc = yes
	}
	enable = {
		date < 1941.1.1
		OR = {
			original_tag = CHI
			is_in_faction_with = CHI
		}
	}
	abort = {
		has_war_with = GER # Ragnarok added
	}
	
	ai_strategy = {
		type = put_unit_buffers
		states = {
			1035
		}
		ratio = 0.1
		area = asia
		subtract_invasions_from_need = no
		subtract_fronts_from_need = yes
	}
}

#China shouldn't push that hard because Japan has other places to invade too
CHI_hunker_down_now  = {
	allowed = {
		original_tag = CHI
	}

	enable = {
		date < 1938.6.1
		has_war_with = JAP
		is_historical_focus_on = yes
		has_defensive_war = yes
	}

	abort = {
		has_war_with = GER # Ragnarok added
	}

	ai_strategy = {
		type = front_control

		tag = JAP

		ratio = 0.35

		priority = 50
		ordertype = front
		execution_type = careful
	}

}

CHI_hunker_down_now_2  = {
	allowed = {
		original_tag = CHI
	}

	enable = {
		date > 1938.6.1
		has_war_with = JAP
		is_historical_focus_on = yes
		has_defensive_war = yes
	}

	abort = {
		has_war_with = GER # Ragnarok added
	}

	ai_strategy = {
		type = front_control

		tag = JAP

		ratio = 0.35

		priority = 50
		ordertype = front
		execution_type = balanced
	}

}

CHI_dont_join_ENG_if_not_democratic = {
	allowed = {
		WTT_is_chinese_country = yes 
	}

	enable = {
		NOT = { has_war_with = GER } # Ragnarok added
		WTT_is_chinese_country = yes 
		NOT = { has_government = democratic }
		ENG = { has_government = democratic }
	}

	abort_when_not_enabled = yes 

	ai_strategy = {
		type =  alliance
		id = ENG
		value = -250
	}

}

CHI_dont_join_USA_if_not_democratic = {
	allowed = {
		WTT_is_chinese_country = yes 
	}

	enable = {
		NOT = { has_war_with = GER } # Ragnarok added
		WTT_is_chinese_country = yes 
		NOT = { has_government = democratic }
		USA = { has_government = democratic }
	}

	abort_when_not_enabled = yes 

	ai_strategy = {
		type =  alliance
		id = USA
		value = -250
	}

}

#### FORCE CONCENTRATION

# We defend all our country, right
CHI_aifc_incompetent_officers = {
	allowed = { original_tag = CHI }
	enable = {
		OR = {
			has_idea = CHI_incompetent_officers
			NOT = { has_completed_focus = CHI_serve_the_country_with_utmost_loyalty }
			NOT = { has_completed_focus = CHI_prepare_the_war_zones }
		}
	}
	
	abort_when_not_enabled = yes 

	ai_strategy = {
		type = force_concentration_factor
		value = -30  # if we have enough doctrines, we can do a little.... 
	}
}

#SEA

#The north needs to fall quickly
CHI_dont_defend_HBC = {
	allowed = {
		has_dlc = "No Compromise, No Surrender"
		is_literally_china = yes
	}

	enable = {
		is_in_faction_with = HBC
		OR = {	
			1039 = {
				is_controlled_by = HBC
			}
			608 = {
				is_controlled_by = HBC
			}
		}
		CHI = {
			NOT = { has_completed_focus = CHI_strengthening_our_resolve }
		}
	}

	abort_when_not_enabled = yes 

	ai_strategy = {
		type = dont_defend_ally_borders
		id = HBC
		value = 100
	}
}

##The north needs to fall quickly
CHI_dont_defend_SND = {
	allowed = {
		has_dlc = "No Compromise, No Surrender"
		is_literally_china = yes
	}

	enable = {
		is_in_faction_with = SND
		597 = {
			is_controlled_by = SND
		}
		1038 = {
			is_controlled_by = SND
		}
	}

	abort_when_not_enabled = yes 

	ai_strategy = {
		type = dont_defend_ally_borders
		id = SND
		value = 100
	}
}

#We don't want to die of attrition up in the mountains
CHI_dont_defend_northern_warlords = {
	allowed = {
		has_dlc = "No Compromise, No Surrender"
		original_tag = CHI
	}

	enable = {
		num_faction_members > 3
	}

	abort_when_not_enabled = yes 

	ai_strategy = {
		type = dont_defend_ally_borders
		id = HBC
		value = 150
	}
	ai_strategy = {
		type = dont_defend_ally_borders
		id = SND
		value = 150
	}
	ai_strategy = {
		type = dont_defend_ally_borders
		id = SHX
		value = 150
	}
}

#The coast is a lost cause, so build inland instead
CHI_build_factories_inland = {
	allowed = {
		has_dlc = "No Compromise, No Surrender"
		original_tag = CHI
	}

	enable = {
		date < 1941.1.1
	}

	abort = {
		date > 1938.6.1
		NOT = {
			has_war_with = JAP
		}
	}

	#Build in Wuhan
	ai_strategy = {
		type = build_building
		id = arms_factory
		target = 1036
		value = 25
	}
	ai_strategy = {
		type = build_building
		id = industrial_complex
		target = 1036
		value = 25
	}
	#Build in Changde
	ai_strategy = {
		type = build_building
		id = arms_factory
		target = 750
		value = 25
	}
	ai_strategy = {
		type = build_building
		id = industrial_complex
		target = 750
		value = 25
	}
	#Build in Sichuan
	ai_strategy = {
		type = build_building
		id = arms_factory
		target = 605
		value = 25
	}
	ai_strategy = {
		type = build_building
		id = industrial_complex
		target = 605
		value = 25
	}
	#Build in Chengdu
	ai_strategy = {
		type = build_building
		id = arms_factory
		target = 1041
		value = 25
	}
	ai_strategy = {
		type = build_building
		id = industrial_complex
		target = 1041
		value = 25
	}
	#Build in Chongqing
	ai_strategy = {
		type = build_building
		id = arms_factory
		target = 1037
		value = 35
	}
	ai_strategy = {
		type = build_building
		id = industrial_complex
		target = 1037
		value = 35
	}
	#Build in Zunyi
	ai_strategy = {
		type = build_building
		id = arms_factory
		target = 748
		value = 15
	}
	ai_strategy = {
		type = build_building
		id = industrial_complex
		target = 748
		value = 15
	}
	#Build in Hubei
	ai_strategy = {
		type = build_building
		id = arms_factory
		target = 620
		value = 15
	}
	ai_strategy = {
		type = build_building
		id = industrial_complex
		target = 620
		value = 15
	}
	#Build in Hunan
	ai_strategy = {
		type = build_building
		id = arms_factory
		target = 602
		value = 15
	}
	ai_strategy = {
		type = build_building
		id = industrial_complex
		target = 602
		value = 15
	}
}

CHI_bog_them_down_and_war_zones_concentrations = {
	allowed = {
		original_tag = CHI
	}
	enable = {
		OR = {
			has_completed_focus = CHI_bog_them_down_in_the_centre
			has_completed_focus = CHI_prepare_the_war_zones
		}
		any_core_state = {
			has_state_flag = CHI_holding_state_mission_flag
		}
	}
	abort = {
		has_war_with = GER # Ragnarok added
	}
	
	ai_strategy = {
		type = front_unit_request
		state_trigger = {
			has_state_flag = CHI_holding_state_mission_flag
		}
		value = 50
	}
}

CHI_prioritize_coast_garrisons = {
	allowed = {
		is_literally_china = yes
	}
	enable = {
		date < 1941.1.1
		any_core_state = {
			is_coastal = yes
			is_fully_controlled_by = ROOT
		}
		OR = {
			has_war_with = JAP
			has_war_with = USA
			has_war_with = ENG
			has_war_with = FRA
		}
		CHI = {
			NOT = { has_completed_focus = CHI_strengthening_our_resolve }
		}
	}
	abort = {
		has_war_with = GER # Ragnarok added
	}
	
	ai_strategy = {
		type = garrison_reinforcement_priority
		value = 100
	}
}

CHI_prioritize_coast_garrisons_low_effort = { # Specifically for fasc-chi
	allowed = {
		original_tag = CHI 
	}
	enable = {
		date < 1941.1.1
		any_core_state = {
			is_coastal = yes
			is_fully_controlled_by = ROOT
		}
		OR = {
			has_war_with = JAP
			has_war_with = USA
			has_war_with = ENG
			has_war_with = FRA
		}
		has_completed_focus = CHI_strengthening_our_resolve 
	}
	abort = {
		has_war_with = GER # Ragnarok added
	}
	
	ai_strategy = {
		type = garrison_reinforcement_priority
		value = 50
	}
}

#CHI_defend_southern_china = {
#	allowed = {
#		OR = {
#			original_tag = SIC
#			original_tag = YUN
#			original_tag = GXC
#			original_tag = GDC
#		}
#	}
#	enable = {
#		is_in_faction_with = CHI
#		has_war = yes		
#		date < 1943.1.1
#	}
#	abort_when_not_enabled = yes
#	
#	ai_strategy = {
#		type = front_unit_request
#		id = JAP
#		value = 50
#		state_trigger = {
#			is_owned_by = CHI
#			OR = {
#				any_state_in = {
#					strategic_region = 164
#				}
#				any_state_in = {
#					strategic_region = 165
#				}
#				any_state_in = {
#					strategic_region = 248
#				}
#				any_state_in = {
#					strategic_region = 249
#				}
#			}
#		}
#	}
#}

# Make sure Sinkiang tries to push aggressively 
SIK_push_khotan = {
	allowed = {
		original_tag = SIK
	}
	enable = {
		#is_historical_focus_on = yes
		OR = {
			focus_progress = {
				focus = SIK_march_into_khotan
				progress > 0.01
			}
			has_war_with = KHM
		}
	}
	abort = {
		KHM = {
			OR = {
				has_capitulated = yes
				exists = no
			}
		}
	}

	ai_strategy = {
		type = front_unit_request
		tag = KHM
		value = 75
	}

	ai_strategy = {
		type = conquer
		id = KHM
		value = 200
	}

	ai_strategy = {
		type = antagonize
		id = KHM
		value = 200
	}

	ai_strategy = {
		type = front_control

		tag = KHM

		ratio = 0.7

		priority = 100
		ordertype = front
		execution_type = rush
		execute_order = yes
	}

}

HBC_do_everything_possible_to_allow_japan_to_invade = {
	allowed = {
		original_tag = HBC
	}
	enable = {	
		has_war = no
		date < 1938.1.1
		CHI = {
			NOT = { has_completed_focus = CHI_strengthening_our_resolve }
		}
	}
	abort_when_not_enabled = yes
	
	#We don't need to keep a watch over Japan, right?
	ai_strategy = {
		type = front_control
		id = JAP
		value = -50
	}
	#Who even cares about Mengchukuo?
	ai_strategy = {
		type = front_control
		id = MEN
		value = -50
	}
	#China sounds very sus, let's watch THEM
	ai_strategy = {
		type = front_control
		id = CHI
		value = 50
	}
	#We're watching you Shanxi!
	ai_strategy = {
		type = front_control
		id = SHX
		value = 50
	}
	#Who's dis then? Better keep a close eye on.... *looks in notes* Shandong
	ai_strategy = {
		type = front_control
		id = SND
		value = 50
	}
	#Don't Garrison our Victory Points - they're too close to Japan!
	ai_strategy = {
		type = garrison
		value = -25
	}
	#Put our troops literally anywhere but close to Japan
	ai_strategy = {
		type = put_unit_buffers
		states = {
			614 #Hebei
		}
		ratio = 2
		area = asia
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

#Japan will be gunning for us from the south soon!
CHI_southern_warlords_should_prioritize_southern_borders = {
	allowed = {
		has_dlc = "No Compromise, No Surrender"
		OR = {
			original_tag = YUN 
			original_tag = GXC
			original_tag = GDC
		}
	}
	enable = {
		date < 1942.1.1
		is_in_faction_with = CHI
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = garrison_reinforcement_priority
		value = 100
	}

	ai_strategy = {
		type = put_unit_buffers
		states = {
			1033
			594
			325
		}
		ratio = 0.5
		area = asia
		subtract_invasions_from_need = no
		subtract_fronts_from_need = no
	}
}

#PRC wants to preserve its manpower because of... reasons - muahahaha
PRC_let_everyone_else_do_the_fighting = {
	allowed = {
		has_dlc = "No Compromise, No Surrender"
		original_tag = PRC
	}
	enable = {
		date < 1940.8.20
		is_in_faction_with = CHI
		NOT = {
			any_controlled_state = {
				any_neighbor_state = {
					controller = {
						has_war_with = PRC
					}
				}
			}
		}
	}
	abort_when_not_enabled = yes
	
	ai_strategy = {
		type = garrison
		value = 1000
	}
	ai_strategy = {
		type = front_unit_request
		value = -100
	}
}

#Building Mils and Infantry Equipment 0 is faster and cheaper and we gonna need everything we can get
PRC_military_factories_and_production = {
	allowed = { 
		original_tag = PRC 
	}
	enable = {
		date < 1939.1.1
	}
	abort_when_not_enabled = yes

	ai_strategy = { #All you need is guns - Guns is all you need
		type = building_target
		id = arms_factory
		value = 50
	}
	ai_strategy = { #Skip infantry_equipment_1 and jump straight to infantry_equipment_2 - we need quantity!
   		type = production_upgrade_desire_offset
 	 	id = infantry_equipment_1
  	 	value = -100
	}
}


PRC_focus_militias_early_game = {
	allowed = { 
		original_tag = PRC 
	}
	enable = {
		date < 1944.1.1
	}

	abort_when_not_enabled = yes
	ai_strategy = { #All you need is militias in early game
		type = role_ratio
		id = militias
		value = 300
	}

}

warlords_hunker_down_now  = {
	allowed = {
		is_chinese_warlord = yes
	}

	enable = {
		date < 1938.6.1 #We accept our fate after this point
		has_war_with = JAP
		is_historical_focus_on = yes
		has_defensive_war = yes
	}

	abort_when_not_enabled = yes 

	ai_strategy = {
		type = front_control

		tag = JAP

		ratio = 0.35

		priority = 50
		ordertype = front
		execution_type = careful
	}
}

warlords_hunker_down_now_2  = {
	allowed = {
		is_chinese_warlord = yes
	}

	enable = {
		date > 1938.6.1
		has_war_with = JAP
		is_historical_focus_on = yes
		has_defensive_war = yes
	}

	abort_when_not_enabled = yes 

	ai_strategy = {
		type = front_control

		tag = JAP

		ratio = 0.35

		priority = 50
		ordertype = front
		execution_type = balanced
	}
}

warlords_help_pls  = {
	allowed = {
		is_chinese_warlord = yes
	}

	enable = {
		has_war_with = JAP
		is_historical_focus_on = yes
		is_in_faction_with = CHI
	}

	abort_when_not_enabled = yes 

	ai_strategy = {
		type = force_defend_ally_borders
		id = CHI
		value = 100
	}
}

CHI_stop_disbanding_your_army = {
	allowed = { 
		original_tag = CHI
		has_dlc = "No Compromise, No Surrender"
	}
	enable = {
		date < 1940.6.1
		has_war = no
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = ai_wanted_divisions_factor
		value = 1000
	}
} 
CHI_stop_disbanding_your_army = {
	allowed = { 
		original_tag = CHI
		has_dlc = "No Compromise, No Surrender"
	}
	enable = {
		has_war = yes
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = ai_wanted_divisions_factor
		value = 100
	}
} 