war_planning = {
	SPR_morocco_expedition_fortify_ceuta_decision = {
		icon = generic_construction
		available = {
			custom_trigger_tooltip = {
				tooltip = SPR_morocco_expedition_has_not_began 
				has_country_flag = SPR_morocco_expedition_flag
			}
			1029 = {
				custom_trigger_tooltip = {
					tooltip = SPR_owns_state_tooltip
					OR = { 
						ROOT = { owns_state = PREV }
						THIS = { OWNER = { is_subject_of = ROOT } }
					}
				}
			}
			set_temp_variable = { loan_size_to_check = 200}
			has_less_than_specific_loan_size = yes
		}
		highlight_states = {
			STATE = 1029
		}
		custom_cost_trigger = {
			set_temp_variable = { amount_of_money_to_check = 0.5 }
		}
		custom_cost_text = eoanb_money_cost_text
		visible = { 
			has_country_flag = SPR_fortify_ceuta_flag
			has_country_flag = SPR_morocco_expedition_flag
		}
		allowed = { tag = SPR }
		fire_only_once = yes
		days_remove = 45
		cancel_trigger = {
			1029 = {
				custom_trigger_tooltip = {
					tooltip = SPR_does_not_own_state_tooltip
					AND = { 
						NOT = { ROOT = { owns_state = PREV } }
						NOT = { THIS = { OWNER = { is_subject_of = ROOT } } }
					}
				}
			}
			custom_trigger_tooltip = {
				tooltip = SPR_has_declared_bankruptcy_tooltip
				always = no
			}
		}
		complete_effect = {
			hidden_effect = { 
				set_temp_variable = { money_to_gain = -0.5 }
				add_money_with_tooltip_effect = yes	
				clr_country_flag = SPR_fortify_ceuta_flag
			}
		}
		remove_effect = {
			1029 = { 
				add_building_construction = { type = bunker level = 2 instant_build = yes province = 13720 } 
				add_building_construction = { type = naval_base level = 1 instant_build = yes province = 13720 }
			}
			add_war_support = 0.01
		}
		ai_will_do = {
			base = 10
			modifier = {
				factor = 0
				set_temp_variable = { loan_size_to_check = 40}
				has_less_than_specific_loan_size = no				
			}
		}
	}
	
	SPR_morocco_expedition_fortify_melilla_decision = {
		icon = generic_construction
		available = {
			custom_trigger_tooltip = {
				tooltip = SPR_morocco_expedition_has_not_began 
				has_country_flag = SPR_morocco_expedition_flag
			}
			1029 = {
				custom_trigger_tooltip = {
					tooltip = SPR_owns_state_tooltip
					OR = { 
						ROOT = { owns_state = PREV }
						THIS = { OWNER = { is_subject_of = ROOT } }
					}
				}
			}
			set_temp_variable = { loan_size_to_check = 200}
			has_less_than_specific_loan_size = yes
		}
		highlight_states = {
			STATE = 1029
		}
		custom_cost_trigger = {
			set_temp_variable = { amount_of_money_to_check = 0.5 }
		}
		custom_cost_text = eoanb_money_cost_text
		visible = { 
			has_country_flag = SPR_fortify_melilla_flag
			has_country_flag = SPR_morocco_expedition_flag
		}
		allowed = { tag = SPR }
		fire_only_once = yes
		days_remove = 45
		cancel_trigger = {
			1029 = {
				custom_trigger_tooltip = {
					tooltip = SPR_does_not_own_state_tooltip
					AND = { 
						NOT = { ROOT = { owns_state = PREV } }
						NOT = { THIS = { OWNER = { is_subject_of = ROOT } } }
					}
				}
			}
			custom_trigger_tooltip = {
				tooltip = SPR_has_declared_bankruptcy_tooltip
				always = no
			}
		}
		complete_effect = {
			hidden_effect = { 
				set_temp_variable = { money_to_gain = -0.5 }
				add_money_with_tooltip_effect = yes	
				clr_country_flag = SPR_fortify_melilla_flag
			}
		}
		remove_effect = {
			1029 = { 
				add_building_construction = { type = bunker level = 2 instant_build = yes province = 13721 } 
				add_building_construction = { type = naval_base level = 1 instant_build = yes province = 13721 }
			}
			add_war_support = 0.01
		}
		ai_will_do = {
			base = 10
			modifier = {
				factor = 0
				set_temp_variable = { loan_size_to_check = 40}
				has_less_than_specific_loan_size = no				
			}
		}
	}
	
	SPR_morocco_expedition_begin_invasion = {
		icon = generic_prepare_civil_war
		available = {
			custom_trigger_tooltip = {
				tooltip = SPR_morocco_expedition_has_not_began 
				has_country_flag = SPR_morocco_expedition_flag
			}
			has_completed_focus = SPR_war_in_africa
			set_temp_variable = { loan_size_to_check = 200}
			has_less_than_specific_loan_size = yes
		}
		highlight_states = {
			STATE = 290
		}
		visible = {
			has_country_flag = SPR_morocco_expedition_flag
		}
		allowed = { tag = SPR }
		fire_only_once = yes
		complete_effect = {
			hidden_effect = { 
				MOR = { country_event = { id = SPR_morocco_expedition.6 } } 
				SPR = { set_country_flag = SPR_morocco_intervention_flag }
				MOR = { set_country_flag = MOR_morocco_intervention_flag }
				clr_country_flag = SPR_morocco_expedition_flag
			}
			declare_war_on = {
				target = MOR
				type = annex_everything
			}
		}
		ai_will_do = {
			base = 25
		}
	}
	
	SPR_morocco_expedition_take_er_rif_mission = {
		icon = generic_prepare_civil_war
		ai_will_do = { factor = 100 }
		available = {
			if = {
				limit = {
					TAG = SPR
				}
				290 = {
					custom_trigger_tooltip = {
						tooltip = SPR_morocco_expedition_state_not_controlled_trigger
						OR = {
							MOR = { NOT = { controls_state = PREV } }
							MOR = { has_country_flag = SPR_morocco_expedition_MOR_capitulated }
						}
					}
					custom_trigger_tooltip = {
						tooltip = SPR_morocco_expedition_state_controlled_trigger
						OR = {
							any_country = {
								controls_state = PREV
								OR = {
									AND = {
										is_subject = yes
										OVERLORD = {
											OR = {
												has_country_flag = SPR_morocco_intervention_flag
											}
										}
									}
									has_country_flag = SPR_morocco_intervention_flag
								}
							}
							MOR = { has_country_flag = SPR_morocco_expedition_MOR_capitulated }
						}
					}
				}
			}
			else = {
				hidden_trigger = { always = no }
				1029 = { MOR = { controls_state = PREV } }
				1029 = { MOR = { controls_state = PREV } }
			}
		}
		
		allowed = { 
			OR = { 
				TAG = SPR
				TAG = MOR
			}
		}
		activation = { 
			OR = {
				has_country_flag = SPR_morocco_intervention_flag
				has_country_flag = MOR_morocco_intervention_flag
			}
			NOT = { has_global_flag = SPR_morocco_expedition_take_er_rif_mission_flag }
		}
		selectable_mission = no
		is_good = no
		
		fire_only_once = yes

		#cost = 0
		
		days_mission_timeout = 360
		
		highlight_states = {
			STATE = 290	
		}
		
		complete_effect = {
			#Europeans Take the Port
			hidden_effect = {
				set_global_flag = SPR_morocco_expedition_take_er_rif_mission_flag
				if = {
					limit = {
						TAG = SPR
					}
					MOR = { country_event = { id = SPR_morocco_expedition.8 } }
					MOR = { remove_mission = SPR_morocco_expedition_take_er_rif_mission }
				}
				if = {
					limit = { MOR = { has_country_flag = SPR_morocco_expedition_MOR_capitulated } }
					MOR = { clr_country_flag = SPR_morocco_expedition_MOR_capitulated }
				}
			}
		}
		timeout_effect = {
			#Morocco Holds Out
			hidden_effect = {
				every_country = {
					limit = {
						OR = {
							TAG = SPR
							is_subject_of = SPR
						}
					}
					if = {
						limit = { is_subject = yes }
						if = {
							limit = { 
								OR = {
									OVERLORD = { has_country_flag = SPR_cochinchina_intervention_flag }
									has_country_flag = SPR_cochinchina_intervention_flag
								}
							}
							every_country = {
								limit = { 
									OR = {
										is_subject_of = MOR 
										TAG = MOR
									}
								}
								white_peace = PREV
							}
						}
					}
					else = {
						if = {
							limit = { has_country_flag = SPR_cochinchina_intervention_flag }
							every_country = {
								limit = { 
									OR = {
										is_subject_of = MOR 
										TAG = MOR
									}
								}
								white_peace = PREV
							}
						}
					}
				}
				#Morocco controls both cities
				if = {
					limit = { 
						1029 = { MOR = { controls_state = PREV } }
						1029 = { MOR = { controls_state = PREV } }
					}
					if = {
						limit = {
							TAG = SPR 
						}
						clr_country_flag = SPR_morocco_intervention_flag
						SPR = { country_event = { id = SPR_morocco_expedition.13 } }
					}
					if = {
						limit = { 
							TAG = MOR
						}
						clr_country_flag = MOR_morocco_intervention_flag
						MOR = { country_event = { id = SPR_morocco_expedition.14 } }
					}
				}
				#stalemate
				else = {
					if = {
						limit = { TAG = SPR }
						clr_country_flag = SPR_morocco_intervention_flag
						SPR = { country_event = { id = SPR_morocco_expedition.12 } }
					}
					if = {
						limit = { TAG = MOR }
						clr_country_flag = MOR_morocco_intervention_flag
						MOR = { country_event = { id = SPR_morocco_expedition.12 } }
					}
				}
			}
		}
	}
	
	SPR_morocco_expedition_take_casablanca_mission = {
		icon = generic_prepare_civil_war
		ai_will_do = { factor = 100 }
		available = {
			if = {
				limit = {
					TAG = SPR
				}
				461 = {
					custom_trigger_tooltip = {
						tooltip = SPR_morocco_expedition_state_not_controlled_trigger
						OR = {
							MOR = { NOT = { controls_state = PREV } }
							MOR = { has_country_flag = SPR_morocco_expedition_MOR_capitulated }
						}
					}
					custom_trigger_tooltip = {
						tooltip = SPR_morocco_expedition_state_controlled_trigger
						OR = {
							any_country = {
								controls_state = PREV
								OR = {
									AND = {
										is_subject = yes
										OVERLORD = {
											OR = {
												has_country_flag = SPR_morocco_intervention_flag
											}
										}
									}
									has_country_flag = SPR_morocco_intervention_flag
								}
							}
							MOR = { has_country_flag = SPR_morocco_expedition_MOR_capitulated }
						}
					}
				}
			}
			else = {
				hidden_trigger = { always = no }
				1029 = { MOR = { controls_state = PREV } }
				1029 = { MOR = { controls_state = PREV } }
			}
		}
		
		allowed = { 
			OR = { 
				TAG = SPR
				TAG = MOR
			}
		}
		activation = { 
			OR = {
				has_country_flag = SPR_morocco_intervention_flag
				has_country_flag = MOR_morocco_intervention_flag
			}
			has_global_flag = MOR_morocco_intervention_continues_flag
			NOT = { has_global_flag = SPR_morocco_expedition_take_casablanca_mission }
		}
		selectable_mission = no
		is_good = no
		
		fire_only_once = yes

		#cost = 0
		
		days_mission_timeout = 360
		
		highlight_states = {
			STATE = 290	
		}
		
		complete_effect = {
			#Spain Takes the Casablanca
			hidden_effect = {
				set_global_flag = SPR_morocco_expedition_take_casablanca_mission
				if = {
					limit = {
						TAG = SPR
					}
					MOR = { country_event = { id = SPR_morocco_expedition.10 } }
					MOR = { remove_mission = SPR_morocco_expedition_take_casablanca_mission }
				}
				if = {
					limit = { MOR = { has_country_flag = SPR_morocco_expedition_MOR_capitulated } }
					MOR = { clr_country_flag = SPR_morocco_expedition_MOR_capitulated }
				}
			}
		}
		timeout_effect = {
			hidden_effect = {
				every_country = {
					limit = {
						OR = {
							TAG = SPR
							is_subject_of = SPR
						}
					}
					if = {
						limit = { is_subject = yes }
						if = {
							limit = { 
								OR = {
									OVERLORD = { has_country_flag = SPR_cochinchina_intervention_flag }
									has_country_flag = SPR_cochinchina_intervention_flag
								}
							}
							every_country = {
								limit = { 
									OR = {
										is_subject_of = MOR 
										TAG = MOR
									}
								}
								white_peace = PREV
							}
						}
					}
					else = {
						if = {
							limit = { has_country_flag = SPR_cochinchina_intervention_flag }
							every_country = {
								limit = { 
									OR = {
										is_subject_of = MOR 
										TAG = MOR
									}
								}
								white_peace = PREV
							}
						}
					}
				}
				#Morocco controls both cities
				if = {
					limit = { 
						1029 = { MOR = { controls_state = PREV } }
						1029 = { MOR = { controls_state = PREV } }
					}
					if = {
						limit = {
							TAG = SPR 
						}
						clr_country_flag = SPR_morocco_intervention_flag
						SPR = { country_event = { id = SPR_morocco_expedition.13 } }
					}
					if = {
						limit = { 
							TAG = MOR
						}
						clr_country_flag = MOR_morocco_intervention_flag
						MOR = { country_event = { id = SPR_morocco_expedition.14 } }
					}
				}
				#morocco loses from timeout
				else = {
					if = {
						limit = { TAG = SPR }
						clr_country_flag = SPR_morocco_intervention_flag
						SPR = { country_event = { id = SPR_morocco_expedition.12 } }
					}
					if = {
						limit = { TAG = MOR }
						clr_country_flag = MOR_morocco_intervention_flag
						MOR = { country_event = { id = SPR_morocco_expedition.12 } }
					}
				}
			}
		}
	}
}