spanish_civil_war_GER_expatriate = {
	allowed = {
		NOT = { has_dlc = "La Resistance" }
	}
	enable = {
		GER = { has_completed_focus = GER_expatriate_the_communists }
		NOT = { has_government = fascism }
		SPR = { has_civil_war = yes }
		NOT = { has_global_flag = scw_over }
	}

	abort = {
		OR = {
			SPR = { has_civil_war = no }
			has_global_flag = scw_over
		}
	}

	ai_strategy = {
		type = befriend
		id = "SPR"
		value = 100
	}
}

spanish_civil_war_GER_expatriate_resistance = {
	allowed = { has_dlc = "La Resistance" }
	enable = {
		GER = { has_completed_focus = GER_expatriate_the_communists }
		NOT = { has_government = fascism }
		SPD = { has_civil_war = yes }
		NOT = { has_global_flag = scw_over }
	}

	abort = {
		OR = {
			SPD = { has_civil_war = no }
			has_global_flag = scw_over
		}
	}

	ai_strategy = {
		type = befriend
		id = "SPD"
		value = 100
	}
}

# make italy and germany want to send stuff to the fascist side of SCW
ITA_and_GER_help_SPA_win_civil_war = {
	allowed = {
		NOT = { has_dlc = "La Resistance" }
		OR = {
			original_tag = GER
			original_tag = ITA
		}
	}
	enable = {
		date < 1939.1.1
		SPR = { has_civil_war = yes }
		country_exists = SPA
		has_government = fascism
		NOT = { has_global_flag = scw_over }
	}
	abort = {
		OR = {
			date > 1939.1.1
			NOT = { has_government = fascism }
			SPR = { has_civil_war = no }
			has_global_flag = scw_over
		}
	}

	ai_strategy = {
		type = send_volunteers_desire
		id = SPA
		value = 50
	}
}

# make ussr want to send stuff to the communist side of SCW
SOV_help_SPD_win_civil_war = {
	allowed = {
		NOT = { has_dlc = "La Resistance" }
		original_tag = SOV
	}
	enable = {
		date < 1939.1.1
		SPR = { has_civil_war = yes }
		country_exists = SPD
		has_government = communism
		NOT = { has_global_flag = scw_over }
	}
	abort = {
		OR = {
			date > 1939.1.1
			NOT = { has_government = communism }
			SPR = { has_civil_war = no }
			has_global_flag = scw_over
		}
	}

	ai_strategy = {
		type = send_volunteers_desire
		id = SPD
		value = 50
	}
}

# Make nobody want to ally Spain during the civil war.
spanish_civil_war_ally_nobody = {
	allowed = { has_dlc = "La Resistance" }

	enable = {
		SPR_scw_in_progress = yes
		NOT = {
			original_tag = SPR
		}
	}
	abort = {
		has_global_flag = scw_over
	}

	ai_strategy = {
		type = alliance
		id = SPD
		value = -2000
	}
	ai_strategy = {
		type = alliance
		id = SPA
		value = -2000
	}
	ai_strategy = {
		type = alliance
		id = SPB
		value = -2000
	}
	ai_strategy = {
		type = alliance
		id = SPC
		value = -2000
	}
}

# Make countries less likely to support Carlist Spain
spanish_civil_war_isolate_carlists = {
	allowed = { has_dlc = "La Resistance" }
	enable = {
		country_exists = SPB
		SPR_scw_in_progress = yes
		NOT = {
			original_tag = SPR
		}
		NOT = { has_government = neutrality }
	}
	abort = {
		has_global_flag = scw_over
	}

	ai_strategy = {
		type = ignore
		id = SPB
		value = 100
	}
	ai_strategy = {
		type = alliance
		id = SPB
		value = -50
	}
	ai_strategy = {
		type = befriend
		id = SPB
		value = -50
	}
	ai_strategy = {
		type = support
		id = SPB
		value = -50
	}
	ai_strategy = {
		type = protect
		id = SPB
		value = -50
	}
	ai_strategy = {
		type = send_volunteers_desire
		id = SPB
		value = -50
	}
	ai_strategy = {
		type = send_lend_lease_desire
		id = SPB
		value = -50
	}
}

# Make nobody want to ally Anarchist Spain
spanish_civil_war_isolate_anarchists = {

	allowed = { has_dlc = "La Resistance" }
	enable = {
		country_exists = SPC
		SPC = { has_completed_focus = SPR_regional_defense_council_of_aragon }
		NOT = {
			tag = SPC
		}
	}

	abort = {
		has_global_flag = scw_over
	}

	ai_strategy = {
		type = ignore
		id = SPC
		value = 999
	}
	ai_strategy = {
		type = alliance
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = befriend
		id = SPC
		value = -100
	}
	ai_strategy = {
		type = support
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = protect
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = send_volunteers_desire
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = send_lend_lease_desire
		id = SPC
		value = -999
	}
}

# Make MEX/SOV not want to ally POUM Spain
spanish_civil_war_isolate_POUM = {
	allowed = {
		has_dlc = "La Resistance"
	}
	enable = {
		country_exists = SPC
		SPC = { has_completed_focus = SPR_the_anti_fascist_workers_revolution }
		OR = {
			tag = SOV
			is_in_faction_with = SOV
			AND = {
				tag = MEX
				has_country_leader = {
 					character = MEX_leon_trotsky
 				}
			}
			AND = {
				is_in_faction_with = MEX
				MEX = {
					has_country_leader = {
 						character = MEX_leon_trotsky
 					}
 				}
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = ignore
		id = SPC
		value = 999
	}
	ai_strategy = {
		type = alliance
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = befriend
		id = SPC
		value = -100
	}
	ai_strategy = {
		type = support
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = protect
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = send_volunteers_desire
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = send_lend_lease_desire
		id = SPC
		value = -999
	}
}

# Make nobody want to ally Anarchist Spain
#spanish_civil_war_anarchists_dont_like_other_states = {
#	enable = {
#		NOT = { tag = SPC }
#		country_exists = SPC
#		has_dlc = "La Resistance"
#	}
#
#	abort = {
#	}
#
#	reversed = yes
#
#	ai_strategy = {
#		type = alliance
#		id = SPC
#		value = -9999
#	}
#	ai_strategy = {
#		type = befriend
#		id = SPC
#		value = -9999
#	}
#	ai_strategy = {
#		type = support
#		id = SPC
#		value = -9999
#	}
#	ai_strategy = {
#		type = protect
#		id = SPC
#		value = -9999
#	}
#	ai_strategy = {
#		type = send_volunteers_desire
#		id = SPC
#		value = -9999
#	}
#	ai_strategy = {
#		type = send_lend_lease_desire
#		id = SPC
#		value = -9999
#	}
#	ai_strategy = {
#		type = dont_join_wars_with
#		id = SPC
#		value = 9999
#	}
#}

# Make other countries be unwilling to ally Anarchist Spain
spanish_civil_war_defriend_anarchists = {
	allowed = {
		has_dlc = "La Resistance"
	}
	enable = {
		country_exists = SPC
		SPC = { has_completed_focus = SPR_regional_defense_council_of_aragon }
		NOT = {
			original_tag = SPR
		}
		has_global_flag = scw_over
	}
	abort = {
		is_subject_of = SPC
	}

	ai_strategy = {
		type = alliance
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = befriend
		id = SPC
		value = -200
	}
	ai_strategy = {
		type = support
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = protect
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = send_volunteers_desire
		id = SPC
		value = -999
	}
	ai_strategy = {
		type = send_lend_lease_desire
		id = SPC
		value = -999
	}
}

# Make other countries be concerned about Anarchist Spain
spanish_civil_war_contain_anarchists = {
	allowed = {
		has_dlc = "La Resistance"
	}
	enable = {
		country_exists = SPC
		SPC = { has_completed_focus = SPR_regional_defense_council_of_aragon }
		NOT = {
			original_tag = SPR
		}
		has_global_flag = scw_over
		capital_scope = {
			any_state = {
				is_controlled_by = SPC
				distance_to = {
					target = PREV
					value < 2000
				}
			}
		}
	}
	abort = {
		is_subject_of = SPC
	}

	ai_strategy = {
		type = contain
		id = SPC
		value = 100
	}
}

# Make other countries be hostile to Anarchist Spain
spanish_civil_war_exterminate_anarchists = {

	allowed = { has_dlc = "La Resistance" }
	enable = {
		country_exists = SPC
		SPC = { has_completed_focus = SPR_regional_defense_council_of_aragon }
		NOT = {
			original_tag = SPR
		}
		has_global_flag = scw_over
		capital_scope = {
			any_state = {
				is_controlled_by = SPC
				distance_to = {
					target = PREV
					value < 2000
				}
			}
		}
		NOT = { has_global_flag = SPR_anarchist_victory_timer_flag }
	}
	abort = {
		OR = {
			is_subject_of = SPC
			has_war_with = SPC
		}
	}

	ai_strategy = {
		type = antagonize
		id = SPC
		value = 100
	}
	ai_strategy = {
		type = contain
		id = SPC
		value = 100
	}
	ai_strategy = {
		type = consider_weak
		id = SPC
		value = 50
	}
}

# Make other Major countries be very hostile to Anarchist Spain
spanish_civil_war_really_exterminate_anarchists = {
	allowed = { has_dlc = "La Resistance" }
	enable = {
		is_major = yes
		NOT = {
			any_other_country = {
				is_major = yes
				has_war_with = ROOT
			}
		}
		country_exists = SPC
		SPC = { has_completed_focus = SPR_regional_defense_council_of_aragon }
		NOT = {
			original_tag = SPR
		}
		has_global_flag = scw_over
		capital_scope = {
			any_state = {
				is_controlled_by = SPC
				distance_to = {
					target = PREV
					value < 2000
				}
			}
		}
		NOT = { has_global_flag = SPR_anarchist_victory_timer_flag }
	}
	abort = {
		OR = {
			is_subject_of = SPC
			has_war_with = SPC
		}
	}

	ai_strategy = {
		type = antagonize
		id = SPC
		value = 150
	}
	ai_strategy = {
		type = consider_weak
		id = SPC
		value = 150
	}
	ai_strategy = {
		type = prepare_for_war
		id = SPC
		value = 100
	}
}

SPR_dont_attack_at_startup_of_civil_war = {
	allowed = {
		original_tag = SPR
	}

	enable = {
		has_global_flag = SPR_civil_war_startup
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = front_control

		country_trigger = {
			original_tag = SPR
		}

		execute_order = no
		manual_attack = no
	}
}

# Prevent Nationalist Spain to join any faction on historical mode
nationalist_spain_allies_nobody_on_historical = {
	allowed = {
		tag = SPR
		has_dlc = "La Resistance"
	}
	enable = {
		has_global_flag = scw_over
		OR = {
			AND = {
				is_historical_focus_on = yes
				has_game_rule = {
					rule = SPR_ai_behavior
					option = DEFAULT
				}
			}
			has_country_flag = SPR_AI_RANDOM_NATIONALIST_HISTORICAL
			has_game_rule = {
				rule = SPR_ai_behavior
				option = NATIONALIST_HISTORICAL
			}
		}
	}
	abort = {
		OR = {
			GER = {
				AND = {
					is_historical_focus_on = yes
					date > 1944.1.1
					OR = { 
						NOT = { has_war_with = SOV } 
						SOV = { has_capitulated = yes }
					}
				}
			}
			SPR = { has_war = yes }
			SPR = { is_in_faction = yes }
			GER = { NOT = { has_government = fascism } }
			ENG = { NOT = { has_government = democratic } }
		}
	}

	ai_strategy = {
		type = alliance
		id = GER
		value = -500
	}

	ai_strategy = {
		type = alliance
		id = ENG
		value = -500
	}
	
	ai_strategy = {
		type = alliance
		id = SOV
		value = -500
	}

	ai_strategy = {
		type = alliance
		id = JAP
		value = -500
	}
	
}