############################################################################################################
#	Expert AI mod - scripted volunteer AI triggers
############################################################################################################

# ROOT = SENDER, THIS = TARGET
# conditions for sending volunteers to a country

EAI_VOLUNTEERS_enable = {

	has_war = no

	# NOT = { 
	# 	num_divisions < 30
	# }
	
	# OR = {
	# 	AND = { has_government = neutrality NOT = { threat < 0.4 } }
	# 	AND = { has_government = fascism }
	# 	AND = { has_government = communism }
	# 	AND = { has_government = democratic NOT = { threat < 0.5 } }
	# }

	# any_other_country = { has_war = yes }
}

EAI_VOLUNTEERS_THIS_is_valid_target_of_ROOT = {

	NOT = { EAI_VOLUNTEERS_block_volunteer_strategies = yes }

	THIS = { # target
		has_war = yes
		
		NOT = { has_war_with = ROOT }
		
		NOT = { tag = ROOT }

		###

		OR = {
			### anti aggression script

			AND = {
				ROOT = { has_country_flag = EAI_supports_@PREV }
				has_country_flag = EAI_receives_support_@THIS
			}

			### historical volunteers

			EAI_VOLUNTEERS_send_volunteer_strategies = yes
 
			### ahistorical mode

			AND = {
				is_historical_focus_on = no

				ROOT = { has_opinion = { target = PREV value > 25 } } # friendly countries

				OR = {
					AND = { ROOT = { EAI_democratic_nation = yes }
						EAI_democratic_nation = yes
					}

					AND = { ROOT = { EAI_communist_nation = yes }
						EAI_communist_nation = yes
					}

					AND = { ROOT = { EAI_fascist_nation = yes }
						EAI_fascist_nation = yes
					}

					AND = { ROOT = { EAI_nonaligned_nation = yes }
						EAI_nonaligned_nation = yes
					}
				}

				OR = {
					AND = {
						any_enemy_country = { EAI_fascist_nation = yes }
						ROOT = { NOT = { EAI_fascist_nation = yes } }
					}
					AND = {
						any_enemy_country = { EAI_communist_nation = yes }
						ROOT = { NOT = { EAI_communist_nation = yes } }
					}
					AND = {
						any_enemy_country = { EAI_democratic_nation = yes }
						ROOT = { NOT = { EAI_democratic_nation = yes } }
					}
				}
			}
		}

		## # why should it NOT send volunteers
		
		NOT = { 
			AND = { # the enemy of this country has a NAP with ROOT or faction member
				NOT = { any_enemy_country = { has_war_with = ROOT } }
				
				any_enemy_country = { 
					OR = {
						has_non_aggression_pact_with = ROOT
						
						any_country = { OR = { is_subject_of = ROOT ROOT = { is_subject_of = PREV } is_in_faction_with = ROOT } has_non_aggression_pact_with = PREV }
					}
				}
			}
		}
	}
}

#####################################################
#	Strategies
#####################################################

EAI_VOLUNTEERS_send_volunteer_strategies = { # ROOT = SENDER, THIS = TARGET

	OR = {
		AND = {
			ROOT = { original_tag = POR }

			THIS = {
				tag = SPA
				has_civil_war = yes
			}
		}

		AND = {
			ROOT = { original_tag = SOV has_government = communism }

			OR = {
				AND = { original_tag = CHI has_war_with = JAP date < 1940.1.1 }
				AND = { tag = SPD has_civil_war = yes }
			}
		}

		AND = {
			ROOT = { OR = { original_tag = GER original_tag = ITA } has_government = fascism }

			OR = {
				AND = { OR = { original_tag = JAP is_subject_of = JAP } has_government = fascism has_war_with = CHI }
				AND = { tag = SPA has_civil_war = yes }
			}
		}

		AND = {
			ROOT = { OR = { original_tag = SPR original_tag = HUN } has_government = fascism }

			OR = { original_tag = ITA original_tag = GER } has_government = fascism
		}

		AND = {
			ROOT = { original_tag = USA has_government = democratic }

			OR = { original_tag = ENG is_subject_of = ENG } has_government = democratic

			date > 1941.1.1
		}
	}
}

EAI_VOLUNTEERS_block_volunteer_strategies = { # ROOT = SENDER, THIS = TARGET

	OR = {

		# Japan shouldnt send volunteers to europe
		AND = {
			ROOT = {
				JAP = { EAI_PREV_on_same_side_with_THIS = yes }
			}

			THIS = {
				capital_scope = { is_on_continent = asia }
			}
		}
	}
}

############################################################################################################
#	Expert AI mod - scripted expeditionary AI triggers
############################################################################################################

EAI_EXPEDITIONARY_enable = {

	has_war = yes
}

EAI_EXPEDITIONARY_THIS_is_valid_target_of_ROOT = { # hardcoded ai blocks this in some situations

	ROOT = {

		NOT = { surrender_progress > 0 has_country_flag = EAI_MILITARY_trend_losing_war }

		NOT = {
			any_neighbor_country = {
				has_war_with = ROOT
			}
		}

		NOT = {
			any_of_scopes = { array = controlled_states
				
				any_state = {
					
					CONTROLLER = { has_war_with = ROOT }
					distance_to = { target = PREV value < 800 } 
				}
			}
		}
	}

	THIS = { has_war_together_with = ROOT }

	OR = {

		# minors send to majors/overlord
		AND = {
			ROOT = { is_major = no }

			THIS = {
				OR = {
					AND = { is_in_faction_with = ROOT is_major = yes }
					ROOT = { is_subject_of = PREV }
				}
			}
		}

		# warlords send to china
		AND = {
			ROOT = { EAI_asian_minor = yes }

			THIS = { original_tag = CHI }
		}
	}

	EAI_EXPEDITIONARY_send_expeditionary_strategies = yes
}

#####################################################
#	Strategies
#####################################################

EAI_EXPEDITIONARY_send_expeditionary_strategies = {

	NOT = {

		#
		AND = {
			ROOT = { OR = { tag = EGY tag = MAL tag = RAJ } }
			THIS = { OR = { tag = ENG is_in_faction_with = ENG } }
		}
	}
}