war_planning = {
	south_america_civil_war_purchase_spanish_support = {
		icon = power_struggle
		
		allowed = {
			OR = {
				TAG = D01
				TAG = D02
				TAG = D03
				TAG = D04
				TAG = COL
				TAG = VEN
				TAG = ECU
				TAG = PRU
				TAG = CHL
				TAG = BOL
				TAG = URG
				TAG = BUE
				TAG = ARG
				TAG = MEC
			}
		}
		
		available = { 
			set_temp_variable = { loan_size_to_check = 200 }
			has_less_than_specific_loan_size = yes 
			SPR = { 
				set_temp_variable = { loan_size_to_check = 200 }
				has_less_than_specific_loan_size = yes 
			}
			custom_trigger_tooltip = {
				tooltip = SPR_loan_support_limit_tooltip
				check_variable = { var = SPR_debt_repayments_level value = 15 compare = less_than_or_equals }
			}
			set_temp_variable = { amount_of_money_to_check = 0.5 }
			has_specific_amount_of_money_with_inflation_included = yes
		}
		
		visible = { 
			if = { 
				limit = { TAG = MEC }
				has_country_flag = SPR_gives_loan_support_flag
			}
			else = { has_civil_war = yes }
			
			# Check if at war with relevant South American nations
			if = {
				limit = { 
					OR = { TAG = D01 TAG = D02 TAG = D03 TAG = D04 }
				}
				OR = {
					has_war_with = COL
					has_war_with = VEN
					has_war_with = ECU
					has_war_with = PRU
					has_war_with = CHL
					has_war_with = BOL
					has_war_with = URG
					has_war_with = BUE
					has_war_with = ARG
				}
			}
		}
		
		custom_cost_trigger = {
			set_temp_variable = { amount_of_money_to_check = 0.5 }
		}
		custom_cost_text = eoanb_money_cost_text
		
		fire_only_once = no
		days_re_enable = 45
		days_remove = 7
		
		complete_effect = {
			set_temp_variable = { money_to_gain = -0.5 }
			add_money_with_tooltip_effect = yes
			
			# Double cost for non-D0X tags
			if = {
				limit = { NOT = { OR = { TAG = D01 TAG = D02 TAG = D03 TAG = D04 } } }
				set_temp_variable = { money_to_gain = -0.5 }
				add_money_with_tooltip_effect = yes
			}
		}
		
		remove_effect = {
			add_equipment_to_stockpile = {
				type = infantry_equipment_rifle_1
				amount = 500
				producer = SPR
			}
			add_equipment_to_stockpile = {
				type = uniform_equipment_1
				amount = 500
				producer = SPR
			}
			add_equipment_to_stockpile = {
				type = cavalry_equipment_0
				amount = 250
				producer = SPR
			}
			add_war_support = 0.01
		}
		
		ai_will_do = {
			base = 10
			modifier = {
				factor = 0
				set_temp_variable = { loan_size_to_check = 45 }
				has_less_than_specific_loan_size = yes
			}
		}
	}
}

eoanb_category_war_measures = {

	# Bolivia 1857 Civil War - Win condition mission
	BOL_1857_civil_war_decision = {
		icon = generic_prepare_civil_war
		
		allowed = {
			OR = {
				TAG = D01
				TAG = D02
				TAG = D03
				TAG = D04
				TAG = BOL
			}
		}
		
		available = {
			controls_province = 8240
			controls_province = 5230
		}
		
		activation = { 
			date < 1858.1.1
			has_civil_war = yes 
			if = {
				limit = { OR = { TAG = D01 TAG = D02 TAG = D03 TAG = D04 } }
				has_war_with = BOL
			}
		}
		
		selectable_mission = no
		is_good = no
		fire_only_once = yes
		days_mission_timeout = 7200
		
		highlight_states = {
			highlight_state_targets = {
				STATE = 1325
				STATE = 302
			}
		}
		
		complete_effect = {
			custom_effect_tooltip = BOL_1857_civil_war_decision_win_war_tooltip
			hidden_effect = {
				# Transfer all Bolivian states to ROOT
				ROOT = {
					set_state_controller = 1304
					set_state_controller = 753
					set_state_controller = 1082
					set_state_controller = 302
					set_state_controller = 487
					set_state_controller = 1071
					set_state_controller = 688
					set_state_controller = 1325
					set_state_controller = 1095
					set_state_controller = 1322
					set_state_controller = 924
					set_state_controller = 1100
				}
			}
		}
		
		ai_will_do = { factor = 1 }
	}

	# Paraguayan War - Triggers intervention event
	PAR_Paraguayan_War_decision = {
		icon = generic_prepare_civil_war
		
		allowed = { TAG = PAR }
		
		available = {
			URG = { surrender_progress > 0.2 }
			has_war = no
		}
		
		activation = {
			has_government = chauvinist_populism
			OR = {
				BRA = { has_completed_focus = BRA_direct_intervention }
				BRA = { has_completed_focus = BRA_the_second_cisplatine_war }
			}
			has_war = no
			URG = { surrender_progress > 0.2 }
			NOT = { has_country_flag = Paraguayan_War }
		}
		
		cancel_trigger = {
			URG = { has_war = no }
		}
		
		selectable_mission = no
		is_good = yes
		fire_only_once = no
		days_mission_timeout = 100
		
		complete_effect = {
			if = {
				limit = { BRA = { has_completed_focus = BRA_direct_intervention } }
				country_event = { id = par.6 }
			}
			else_if = {
				limit = { BRA = { has_completed_focus = BRA_the_second_cisplatine_war } }
				country_event = { id = par.18 }
			}
		}
		
		timeout_effect = {
			activate_mission = PAR_Paraguayan_War_decision
		}
		
		ai_will_do = { factor = 100 }
	}

	# Triple Alliance Formation (Brazil initiates)
	BRA_triple_alliance_decision = {
		icon = generic_prepare_civil_war
		
		allowed = { original_tag = BRA }
		
		available = {
			BRA = { is_in_faction_with = URC }
			ARG = { is_in_faction = no }
		}
		
		activation = {
			BRA = { 
				is_in_faction_with = URC 
				has_war_with = PAR
			}
			URC = { has_war_with = PAR }
			ARG = { 
				is_in_faction = no
				has_war_with = PAR
				NOT = { has_war_with = BRA }
			}
		}
		
		cancel_trigger = {
			PAR = { has_war = no }
		}
		
		highlight_states = {
			highlight_state_targets = { state = capital_scope }
		}
		
		selectable_mission = no
		is_good = yes
		fire_only_once = no
		days_mission_timeout = 100
		
		complete_effect = {
			BRA = { country_event = { id = par.12 } }
		}
		
		timeout_effect = {
			activate_mission = BRA_triple_alliance_decision
		}
		
		ai_will_do = { factor = 100 }
	}

	# Triple Alliance Formation (Paraguay counter-alliance)
	PAR_triple_alliance_decision = {
		icon = generic_prepare_civil_war
		
		allowed = { TAG = PAR }
		
		available = {
			BRA = { is_in_faction = no }
			ARG = { is_in_faction = no }
		}
		
		activation = {
			PAR = { has_war_with = BRA }
			ARG = { 
				has_war_with = BRA
				NOT = { has_war_with = PAR }
			}
			URG = { has_war_with = URC }
			BRA = { is_in_faction = no }
			ARG = { is_in_faction = no }
		}
		
		cancel_trigger = {
			BRA = { has_war = no }
		}
		
		highlight_states = {
			highlight_state_targets = { state = capital_scope }
		}
		
		selectable_mission = no
		is_good = yes
		fire_only_once = no
		days_mission_timeout = 100
		
		complete_effect = {
			country_event = { id = par.13 }
		}
		
		timeout_effect = {
			activate_mission = PAR_triple_alliance_decision
		}
		
		ai_will_do = { factor = 100 }
	}

	# Haiti-Spain War Mission
	HAI_spain_war_decision = {
		icon = generic_prepare_civil_war
		
		allowed = {
			OR = { TAG = HAI TAG = DOM TAG = SPR TAG = USA TAG = FRA }
		}
		
		available = {
			OR = {
				# Haiti victory condition
				AND = {
					TAG = HAI
					OR = {
						1318 = { is_fully_controlled_by = HAI }
						DOM = { has_country_flag = HAI_spain_war_decision_lost_flag }
					}
				}
				# Spain/Allies victory condition
				AND = {
					OR = { TAG = DOM TAG = SPR TAG = USA TAG = FRA }
					OR = {
						any_country = {
							NOT = { TAG = HAI }
							318 = { is_fully_controlled_by = PREV }
						}
						HAI = {
							OR = {
								has_capitulated = yes
								exists = no
								surrender_progress > 0.9
								has_country_flag = HAI_spain_war_decision_lost_flag
							}
						}
					}
				}
			}
		}
		
		activation = { has_country_flag = HAI_spain_war }
		cancel_trigger = { NOT = { has_country_flag = HAI_spain_war } }
		
		highlight_states = {
			highlight_state_targets = {
				STATE = 1318
				STATE = 318
			}
		}
		
		selectable_mission = no
		is_good = no
		fire_only_once = yes
		days_mission_timeout = 720
		
		complete_effect = {
			# Haiti wins
			if = {
				limit = {
					TAG = HAI
					country_exists = HAI
					OR = {
						1318 = { is_fully_controlled_by = HAI }
						DOM = { has_country_flag = HAI_spain_war_decision_lost_flag }
					}
				}
				country_event = { id = dom.41 }
				custom_effect_tooltip = HAI_spain_war_decision_HAI_WIN
			}
			# Spain/Allies win
			else_if = {
				limit = {
					OR = {
						any_country = {
							NOT = { TAG = HAI }
							318 = { is_fully_controlled_by = PREV }
						}
						HAI = { has_country_flag = HAI_spain_war_decision_lost_flag }
						NOT = { country_exists = HAI }
						HAI = { 
							OR = {
								has_capitulated = yes
								surrender_progress > 0.9
							}
						}
					}
				}
				if = {
					limit = {
						DOM = {
							OR = {
								is_subject_of = SPR
								is_subject_of = USA
								is_subject_of = FRA
							}
						}
					}
					DOM = { OVERLORD = { country_event = { id = dom.42 } } }
				}
				else = {
					1318 = { OWNER = { country_event = { id = dom.42 } } }
				}
				custom_effect_tooltip = HAI_spain_war_decision_SPR_WIN
			}
		}
		
		timeout_effect = {
			# Spain wins on timeout
			if = {
				limit = {
					OR = {
						any_country = {
							NOT = { TAG = HAI }
							318 = { is_fully_controlled_by = PREV }
						}
						NOT = { country_exists = HAI }
						HAI = { has_country_flag = HAI_spain_war_decision_lost_flag }
					}
				}
				if = {
					limit = {
						DOM = {
							OR = {
								is_subject_of = SPR
								is_subject_of = USA
								is_subject_of = FRA
							}
						}
					}
					DOM = { OVERLORD = { country_event = { id = dom.42 } } }
				}
				else = {
					1318 = { OWNER = { country_event = { id = dom.42 } } }
				}
			}
			# White peace if Haiti survives
			else = {
				every_country = {
					limit = {
						has_war_with = HAI
						NOT = { original_tag = HAI }
					}
					white_peace = HAI
				}
				HAI = {
					remove_ideas = HAI_liberation_of_hispaniola
					clr_country_flag = HAI_spain_war
				}
			}
		}
		
		ai_will_do = { factor = 1 }
	}

	# Dominican Restoration War
	DOM_spain_war_decision = {
		icon = generic_prepare_civil_war
		
		allowed = {
			OR = { TAG = DOM TAG = SPR }
		}
		
		available = {
			OR = {
				AND = {
					TAG = DOM
					1318 = { is_fully_controlled_by = DOM }
				}
				AND = {
					TAG = SPR
					OR = {
						1318 = { is_fully_controlled_by = DOM }
						NOT = { country_exists = DOM }
					}
				}
			}
		}
		
		activation = {
			DOM = {
				OR = {
					has_idea = DOM_restoration_war2
					has_idea = DOM_restoration_war
				}
			}
		}
		
		highlight_states = {
			highlight_state_targets = {
				STATE = 1318
				STATE = 319
			}
		}
		
		selectable_mission = no
		is_good = no
		fire_only_once = no
		days_mission_timeout = 720
		
		complete_effect = {
			# Dominican victory
			if = {
				limit = {
					TAG = DOM
					country_exists = DOM
					1318 = { is_fully_controlled_by = DOM }
				}
				country_event = { id = dom.46 }
				custom_effect_tooltip = DOM_spain_war_decision_DOM_WIN
			}
			# Spanish victory
			else_if = {
				limit = {
					TAG = SPR
					319 = { is_fully_controlled_by = SPR }
				}
				remove_ideas = DOM_restoration_war
				remove_ideas = DOM_restoration_war2
				custom_effect_tooltip = DOM_spain_war_decision_SPR_WIN
			}
		}
		
		timeout_effect = {
			activate_mission = DOM_spain_war_decision
		}
		
		ai_will_do = { factor = 1 }
	}

	# Jamaica Independence War
	JAM_english_war_decision = {
		icon = generic_prepare_civil_war
		
		allowed = {
			OR = { TAG = JAM TAG = ENG }
		}
		
		available = {
			OR = {
				AND = {
					TAG = JAM
					689 = { is_fully_controlled_by = JAM }
				}
				AND = {
					TAG = ENG
					OR = {
						689 = { is_fully_controlled_by = ENG }
						NOT = { country_exists = JAM }
					}
				}
			}
		}
		
		activation = {
			JAM = {
				has_war_with = ENG
				has_country_flag = JAM_KINGSTON_1
			}
		}
		
		highlight_states = {
			highlight_state_targets = { STATE = 689 }
		}
		
		selectable_mission = no
		is_good = no
		fire_only_once = no
		days_mission_timeout = 720
		
		complete_effect = {
			# Jamaican victory
			if = {
				limit = {
					TAG = JAM
					country_exists = JAM
					689 = { is_fully_controlled_by = JAM }
					has_country_flag = JAM_KINGSTON_1
				}
				country_event = { id = britishcaribbean.13 }
				custom_effect_tooltip = JAM_english_war_decision_JAM_WIN
			}
			# English victory
			else_if = {
				limit = {
					TAG = ENG
					689 = { is_fully_controlled_by = ENG }
				}
				country_event = { id = britishcaribbean.12 }
				custom_effect_tooltip = JAM_english_war_decision_ENG_WIN
			}
		}
		
		timeout_effect = {
			activate_mission = JAM_english_war_decision
		}
		
		ai_will_do = { factor = 1 }
	}

	# Puerto Rico - Lares Revolt
	PRT_spain_war_decision = {
		icon = generic_prepare_civil_war
		
		allowed = { TAG = SPR }
		
		available = {
			OR = {
				686 = { is_fully_controlled_by = JAM }
				NOT = { country_exists = PRT }
			}
		}
		
		activation = {
			SPR = { has_war_with = PRT }
			PRT = { has_country_flag = PRT_Lares }
		}
		
		highlight_states = {
			highlight_state_targets = { STATE = 686 }
		}
		
		selectable_mission = no
		is_good = no
		fire_only_once = no
		days_mission_timeout = 900
		
		complete_effect = {
			SPR = { transfer_state = 686 }
			SPR = { set_country_flag = SPR_Lares_end }
			PRT = { clr_country_flag = PRT_Lares }
			custom_effect_tooltip = PRT_spain_war_decision_SPR_WIN
			country_event = { id = spain_caribbean.6 days = 3 }
		}
		
		timeout_effect = {
			activate_mission = PRT_spain_war_decision
		}
		
		ai_will_do = { factor = 1 }
	}

	# Brazil-France Guyana War 1857
	BRA_guyana_war_1857_decision = {
		icon = generic_prepare_civil_war
		
		allowed = {
			OR = { TAG = BRA TAG = FRA }
		}
		
		available = {
			OR = {
				AND = {
					TAG = BRA
					has_full_control_of_state = 310
				}
				AND = {
					TAG = FRA
					OR = {
						has_full_control_of_state = 1323
						NOT = { country_exists = BRA }
					}
				}
			}
		}
		
		activation = {
			BRA = { has_country_flag = BRA_guyana_war_1857 }
			FRA = { has_country_flag = BRA_guyana_war_1857 }
		}
		
		highlight_states = {
			highlight_state_targets = { STATE = 310 }
		}
		
		selectable_mission = no
		is_good = no
		fire_only_once = no
		days_mission_timeout = 300
		
		complete_effect = {
			# Brazilian victory
			if = {
				limit = {
					TAG = BRA
					country_exists = BRA
					310 = { is_fully_controlled_by = BRA }
				}
				country_event = { id = brazil.21 }
				custom_effect_tooltip = BRA_guyana_war_decision_BRA_WIN
			}
			# French victory
			else_if = {
				limit = {
					TAG = FRA
					1323 = { is_fully_controlled_by = FRA }
				}
				country_event = { id = brazil.22 }
				custom_effect_tooltip = BRA_guyana_war_decision_FRA_WIN
			}
		}
		
		timeout_effect = {
			activate_mission = BRA_guyana_war_1857_decision
		}
		
		ai_will_do = { factor = 1 }
	}
}
