targetted_decisions = {
	
	expd_ct_chinese_training_decision = {
		
		only_playable = yes
		
		filter = sub_realm_including_me
		ai_target_filter = sub_realm_including_me
		
		ai_check_interval = 12
		
		from_potential = {
			
			# Chinese training is only available with the relevant DLC
			has_dlc = "Jade Dragon"
			
			# Only show if FROM has a Chinese strategist
			any_courtier_or_vassal = { has_character_modifier = jd_strategist }
			
		}
		
		potential = {
			# Only show if FROM is targeting someone who can lead one of their armies
			expd_ct_root_can_lead_rootfroms_armies = yes
		}
		
		allow = {
			
			# Duplicate the potential block, so that the player can understand who is targetable
			expd_ct_root_can_lead_rootfroms_armies = yes
			
			# It must be possible to train ROOT
			ROOT = { expd_ct_this_character_is_a_valid_target_for_chinese_training = yes }
			
			# FROM must have sufficient grace and not be in timeout
			FROM = {
				
				# Half-price for golden age strategists!
				trigger_if = {
					limit = {
						any_courtier_or_vassal = {
							has_character_modifier = jd_strategist
							has_character_flag = jd_strategist_golden_age
						}
					}
					has_offmap_currency = {
						offmap =  offmap_china
						value  >= 100 # Keep in sync with logic below
					}
				}
				trigger_else = {
					has_offmap_currency = {
						offmap =  offmap_china
						value  >= 200 # Keep in sync with logic below
					}
				}
				
				# Additional cost for self-targeted decision
				trigger_if = {
					limit = { character = ROOT }
					prestige >= 1000 # Keep in sync with logic below
				}
				
				# Has not recently asked for Chinese training
				trigger_if = {
					limit = { has_character_modifier = expd_ct_block_chinese_training }
					custom_tooltip = {
						text = expd_ct_block_chinese_training_blocked_tt
						always = no
					}
				}
				trigger_else = {
					custom_tooltip = {
						text = expd_ct_block_chinese_training_allowed_tt
						always = yes
					}
				}
				
			}
		}
		
		effect = {
			
			# Do the training
			hidden_tooltip = {
				FROM = {
					random_courtier_or_vassal = {
						limit = { has_character_modifier = jd_strategist }
						preferred_limit = { has_character_flag = jd_strategist_golden_age }
						save_event_target_as = commander_teacher
					}
				}
				ROOT = {
					save_event_target_as = commander_student
				}
			}
			custom_tooltip = { text = expd_ct_name_of_chinese_strategist_tt }
			ROOT = { expd_ct_this_character_receives_chinese_training_random = yes }
			
			custom_tooltip = { text = expd_ct_blank_line_tt }
			
			# Deduct grace (& prestige?) & set blocker
			FROM = {
				if = {
					limit = {
						any_courtier_or_vassal = {
							has_character_modifier = jd_strategist
							has_character_flag = jd_strategist_golden_age
						}
					}
					add_offmap_currency = {
						offmap = offmap_china
						value  = -100 # Keep in sync with logic above
					}
				}
				else = {
					add_offmap_currency = {
						offmap = offmap_china
						value  = -200 # Keep in sync with logic above
					}
				}
				
				if = {
					limit = { character = ROOT }
					prestige = -1000 # Keep in sync with logic above
				}
				
				# Base cooldown is 2 years (golden age) or 3 years (not golden age)
				# Remove 1 year if you have an additional strategist of the relevant type
				if = {
					limit = {
						any_courtier_or_vassal = {
							has_character_modifier = jd_strategist
							has_character_flag = jd_strategist_golden_age
							liege = {
								any_courtier_or_vassal = {
									has_character_modifier = jd_strategist
									has_character_flag = jd_strategist_golden_age
									NOT = { character = PREVPREV }
								}
							}
						}
					}
					add_character_modifier     = { name = expd_ct_block_chinese_training years = 1 }
					hidden_tooltip = {
						remove_character_modifier       = expd_ct_block_chinese_training
						add_character_modifier = { name = expd_ct_block_chinese_training years = 1 hidden = yes }
					}
					custom_tooltip = { text = expd_ct_chinese_training_cooldown_reduced_2_golden_age_strategists_tt }
				}
				else_if = {
					limit = {
						any_courtier_or_vassal = {
							has_character_modifier = jd_strategist
							has_character_flag = jd_strategist_golden_age
						}
					}
					add_character_modifier     = { name = expd_ct_block_chinese_training years = 2 }
					hidden_tooltip = {
						remove_character_modifier       = expd_ct_block_chinese_training
						add_character_modifier = { name = expd_ct_block_chinese_training years = 2 hidden = yes }
					}
					custom_tooltip = { text = expd_ct_chinese_training_cooldown_reduced_golden_age_strategist_tt }
				}
				else_if = {
					limit = {
						any_courtier_or_vassal = {
							has_character_modifier = jd_strategist
							liege = {
								any_courtier_or_vassal = {
									has_character_modifier = jd_strategist
									NOT = { character = PREVPREV }
								}
							}
						}
					}
					add_character_modifier     = { name = expd_ct_block_chinese_training years = 2 }
					hidden_tooltip = {
						remove_character_modifier       = expd_ct_block_chinese_training
						add_character_modifier = { name = expd_ct_block_chinese_training years = 2 hidden = yes }
					}
					custom_tooltip = { text = expd_ct_chinese_training_cooldown_reduced_2_strategists_tt }
				}
				else = {
					add_character_modifier     = { name = expd_ct_block_chinese_training years = 3 }
					hidden_tooltip = {
						remove_character_modifier       = expd_ct_block_chinese_training
						add_character_modifier = { name = expd_ct_block_chinese_training years = 3 hidden = yes }
					}
				}
				
			}
			
		}
		
		ai_will_do = {
			factor = 0.1
			
			# AI is more likely to use this decision on itself, its heir, and on its better commanders
			modifier = {
				factor = 5
				ROOT = { character = FROM }
			}
			modifier = {
				factor = 2
				FROM = { current_heir = { character = ROOT } }
			}
			modifier = { factor = 1.2 ROOT = { martial = 10 } }
			modifier = { factor = 1.2 ROOT = { martial = 12 } }
			modifier = { factor = 1.2 ROOT = { martial = 14 } }
			modifier = { factor = 1.4 ROOT = { martial = 16 } }
			modifier = { factor = 1.4 ROOT = { martial = 18 } }
			modifier = { factor = 1.4 ROOT = { martial = 20 } }
			modifier = { factor = 1.6 ROOT = { martial = 22 } }
			modifier = { factor = 1.6 ROOT = { martial = 24 } }
			modifier = { factor = 1.6 ROOT = { martial = 26 } }
			modifier = { factor = 1.8 ROOT = { martial = 28 } }
			modifier = { factor = 1.8 ROOT = { martial = 30 } }
			modifier = { factor = 1.8 ROOT = { martial = 32 } }
			modifier = { factor = 2.0 ROOT = { martial = 34 } }
			modifier = { factor = 2.0 ROOT = { martial = 36 } }
			modifier = { factor = 2.0 ROOT = { martial = 38 } }
			modifier = { factor = 2.0 ROOT = { martial = 40 } }
			
			# AI with little Grace is unlikely to take the decision
			modifier = { factor = 0.2 FROM = { has_offmap_currency = { offmap = offmap_china value <=   500 } } }
			modifier = { factor = 0.3 FROM = { has_offmap_currency = { offmap = offmap_china value <=  1000 } } }
			modifier = { factor = 0.4 FROM = { has_offmap_currency = { offmap = offmap_china value <=  1500 } } }
			modifier = { factor = 0.5 FROM = { has_offmap_currency = { offmap = offmap_china value <=  2000 } } }
			
			# AI with a lot of Grace is more likely to take the decision
			modifier = { factor = 1.5 FROM = { has_offmap_currency = { offmap = offmap_china value >=  5000 } } }
			modifier = { factor = 1.5 FROM = { has_offmap_currency = { offmap = offmap_china value >=  6000 } } }
			modifier = { factor = 1.5 FROM = { has_offmap_currency = { offmap = offmap_china value >=  7000 } } }
			modifier = { factor = 1.5 FROM = { has_offmap_currency = { offmap = offmap_china value >=  8000 } } }
			modifier = { factor = 1.5 FROM = { has_offmap_currency = { offmap = offmap_china value >=  9000 } } }
			modifier = { factor = 1.5 FROM = { has_offmap_currency = { offmap = offmap_china value >= 10000 } } }
			
			# AI threatened by China is very unlikely to waste Grace on this decision
			# (But not completely excluded, in case an AI has excessively huge amounts of grace but for some reason isn't spending it on protection)
			modifier = {
				factor = 0.05
				
				# Expansionist China is the main problem we want to protect against
				# Open China will probably only declare tributary wars, and we don't care too much about those
				# Isolationist China is definitely not a threat!
				offmap_china = { has_policy = china_expansionist }
				
				FROM = {
					
					# Independent, landed, not a Chinese tributary, no peace deal
					independent = yes
					is_landed = yes # Only landed characters are threatened by China!
					NOT = { any_suzerain = { primary_title = { title = e_china_west_governor } } }
					NOT = { has_character_modifier = peace_deal_with_china }
					
					# Not already at war with China
					NOT = {
						any_war = {
							OR = {
								AND = {
									attacker = { primary_title = { title = e_china_west_governor } }
									defender = { character = FROM }
								}
								AND = {
									attacker = { character = FROM }
									defender = { primary_title = { title = e_china_west_governor } }
								}
							}
						}
					}
					
					# Vaguely close to China
					any_realm_province = { region = custom_chinese_invasion_target_region } # Not actually checked, but I suspect you won't be targeted by a Chinese invasion if you're wholly outside this region
					OR = {
						
						# WP is unlanded (we could be targeted!)
						e_china_west_governor = { holder_scope = { is_landed = no } }
						
						# Adjacent to China or a Chinese tributary
						any_neighbor_independent_ruler = {
							OR = {
								primary_title = { title = e_china_west_governor }
								any_suzerain = { primary_title = { title = e_china_west_governor } }
							}
						}
						
						# Adjacent to a state who is adjacent to China or a Chinese tributary
						any_neighbor_independent_ruler = {
							any_neighbor_independent_ruler = {
								OR = {
									primary_title = { title = e_china_west_governor }
									any_suzerain = { primary_title = { title = e_china_west_governor } }
								}
							}
						}
						
					}
				}
			}
			
		}
		
	}
	
	
}