alexander_invasion_war = {
	icon = invasion
	group = invasion
	
	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }
	
	allow_hostages = no
	allowed_for_character = {
		can_use_conquest_cbs_trigger = yes
		religion = religion:hellenism_religion
		has_title = title:b_sthlanitza
		title:b_sthlanitza = {
			religion = religion:hellenism_religion
			title_province = { has_building_or_higher = basilikoi_paides_01 }
		}
	}
	
	allowed_against_character = {
		scope:attacker = {
			ALL_FALSE = {
				top_liege = scope:defender.top_liege
				liege = scope:defender
			}
		}
	}
	target_titles = neighbor_land_or_water
	target_title_tier = all
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder
	
	valid_to_start = {
		scope:target = {
			tier = tier_kingdom
		}
	}
	
	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						target_is_same_character_or_above = scope:defender
					}
				}
			}
		}
	}
	
	on_invalidated_desc = invasion_war_invalidated_message
	
	on_invalidated = {}
	
	cost = {
		piety = {
			value = 0
			add = common_cb_impious_piety_cost
		}
		prestige = {
			add = {
				value = 1000
				desc = CB_BASE_COST
			}
			add = {
				value = 20
				multiply = scope:attacker.realm_size
				desc = CB_REALM_SIZE_COST
				max = 14000
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}
	
	on_declaration = {
		on_declared_war = yes
	}
	
	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = invasion_war_victory_desc_attacker
			}
			desc = invasion_war_victory_desc
		}
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes
		
		# Influence
		add_influence_attacker_victory_effect = yes
		
		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_high_effect = yes }
		
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		
		
		# go through the dejure hierarchy under target titles, transfer titles with same or worse tolerance holders (their religion equaly or less tolerated than the defender's),
		# take the holder as vassal otherwise and don't go deeper
		every_in_list = {
			list = target_titles
			custom_tooltip = CONQUEST_CB_TITLE
			every_in_de_jure_hierarchy = {
				continue = {
					OR = {
						NOT = {
							exists = holder
						}
						NOT = {
							holder = {
								target_is_liege_or_above = scope:defender
							}
						}
						AND = {
							scope:attacker.faith = {
								faith_hostility_level_comparison = {
									prev.holder.faith <= scope:defender.faith
								}
							}
							holder = {
								OR = {
									this = scope:defender
									target_is_liege_or_above = scope:defender
								}
							}
						}
					}
					tier > tier_county
				}
				limit = {
					exists = holder
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
				
				if = {
					limit = {
						OR = {
							scope:attacker.faith = {
								faith_hostility_level_comparison = {
									prev.holder.faith >= scope:defender.faith
								}
							}
							holder.primary_title.tier >= scope:attacker.primary_title.tier
						}
					}
					add_to_temporary_list = titles_taken
				}
				else = {
					holder = {
						add_to_temporary_list = vassals_taken
					}
				}
			}
		}
		
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:attacker
				change = scope:change
				take_baronies = yes
			}
		}
		
		every_in_list = {
			list = vassals_taken
			change_liege = {
				liege = scope:attacker
				change = scope:change
			}
		}
		
		hidden_effect = { resolve_title_and_vassal_change = scope:change }
		
		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = mongol_invasion_cb_ally_prestige
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}
		
		# Prestige level progress for the attacker
		scope:attacker = {
			add_prestige_experience = {
				value = mongol_invasion_cb_prestige_experience_gain
			}
		}
		
		# Truce
		add_truce_attacker_victory_effect = yes
		
		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }
	}
	
	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = invasion_war_white_peace_desc_defender
			}
			desc = invasion_war_white_peace_desc
		}
	}
	
	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		#EP2 accolade glory gain for doing ok against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }
		scope:defender = { accolade_defender_war_end_glory_gain_med_effect = yes }
		
		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # Not important as the scales are identical
			FAME_BASE = mongol_invasion_cb_ally_prestige
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}
		
		add_truce_white_peace_effect = yes
		
		scope:attacker = {
			add_prestige = mongol_invasion_cb_prestige_white_peace
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
		}
		
		scope:defender = {
			stress_impact = {
				arrogant = medium_stress_impact_gain
			}
		}
	}
	
	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = invasion_war_white_peace_desc_defender
			}
			desc = invasion_war_white_peace_desc
		}
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes
		
		# Influence
		add_influence_attacker_defeat_effect = yes
		
		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_high_effect = yes }
		
		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender # Not important as the scales are identical
			FAME_BASE = mongol_invasion_cb_ally_prestige
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}
		
		# Truce
		add_truce_attacker_defeat_effect = yes
		
		# piety change
		every_in_list = {
			list = target_titles
			
			scope:defender = {
				add_prestige = mongol_invasion_cb_prestige_gain
			}
			
			scope:attacker = {
				if = {
					limit = {
						scope:defender = { is_ai = no }
					}
					if = {
						limit = {
							monthly_character_income > 0
						}
						pay_short_term_income = {
							years = 3
							target = scope:defender
						}
					}
					else = {
						pay_short_term_gold = {
							target = scope:defender
							gold = medium_gold_value
						}
					}
				}
			}
		}
		
		scope:attacker = {
			every_vassal = {
				custom = custom.every_vassal
				add_opinion = {
					modifier = liege_lost_mongol_invasion_war
					target = prev
				}
			}
		}
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}
	
	transfer_behavior = transfer
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "ALEXANDER_INVASION_WAR_NAME"
	cb_name = "ALEXANDER_INVASION_KINGDOM_CB_NAME"
	
	interface_priority = 100
	
	use_de_jure_wargoal_only = yes
	
	attacker_wargoal_percentage = 0.8
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
	
	max_ai_diplo_distance_to_title = 500
	
	ai_score_mult = {
		#Declaring war on the frankokratia leader can really ruin the whole thing
		if = {
			limit = {
				scope:defender = {
					any_owned_story = {
						story_type = frankokratia_story
						NOT = { has_variable = franko_war_complete }
					}
				}
			}
			multiply = 0
		}
	}
}