## normal scopes(including posttitle scopes) ##
# ROOT = receiver
# FROM = giver
# <no scope change> = attacker or receiver
## title scopes ##
# ROOT = receiver
# FROM = giver
# <no scope change> = thirdparty landed title	
#
# the following effects/triggers exists (example execution order: on_success->on_success_title->on_success_posttitle):
# is_valid, is_valid_title, on_add, on_add_title, on_add_posttitle, on_success, on_success_title, on_success_posttitle, on_fail, on_fail_title, on_fail_posttitle, on_reverse_demand, on_reverse_demand_title, on_reverse_demand_posttitle
#
# Added on_attacker_leader_death, on_defender_leader_death and on_thirdparty_death, which all trigger when corresponding character dies
# These three all have war scopes, which currently has the following scope changes: 
# attacker, defender, thirdparty(only valid if thirdparty character is involved), thirdparty_title(only valid if thirdparty title is involved)

distance_war = {
	name = CB_DISTANCE_WAR
	war_name = WAR_DISTANCE_WAR
	sprite = 16
	truce_days = 365
	hostile_against_others = yes
	is_permanent = yes
	can_call_allies = yes # Can either side call allies
	can_attack_vassals = no
	press_claim = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	can_ask_to_join_war = no

	can_use = {
		always = yes
	}
	
	can_use_title = {
		tier = count
		holder_scope = {
			NOT = {
				character = ROOT
			}
			NOT = {
				any_liege = { character = ROOT }
			}
		}
		OR = {
			ROOT = { higher_tier_than = COUNT	}
			holder_scope = { num_of_count_titles = 2 }
		}
		location = {
			any_neighbor_province = {
				owner = {
					OR = {
						character = ROOT
						any_liege = { character = ROOT }
					}
				}
			}
				FROM = {
					capital_scope = {
						distance = {
							where = PREVPREV
							distance = 400
						}
					}
				}
			ROOT = {
				capital_scope = {
					OR = {
						NOT = {
							distance = {
								where = PREVPREV
								distance = 100
							}
						}
						any_neighbor_province = {
							province = PREVPREVPREV
						}
					}
				}
			}
		}
	}
	is_valid_title = {
		location = {
			ROOT = {
				capital_scope = {
					OR = {
						NOT = {
							distance = {
								where = PREVPREV
								distance = 100
							}
						}
						any_neighbor_province = {
							province = PREVPREVPREV
						}
					}
				}
			}
				FROM = {
					capital_scope = {
						distance = {
							where = PREVPREV
							distance = 400
						}
					}
				}
			any_neighbor_province = {
				owner = {
					OR = {
						character = ROOT
						any_liege = { character = ROOT }
					}
				}
			}
		}
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}	
	}
		
	on_success_title = {
		if = {
			limit = {
				holder_scope = {
					tier = count
					is_patrician = no
					NOT = {
						num_of_count_titles = 2
					}
				}
			}

			holder_scope = {
				set_defacto_liege = ROOT
			}
		}

		if = {
			limit = {
				holder_scope = {
					OR = {
						higher_tier_than = count
						num_of_count_titles = 2
						is_patrician = yes
					}
				}
			}

			usurp_title_plus_barony_if_unlanded = { target = ROOT type = claim }
			any_de_jure_vassal_title = { # take all baronies under the one we're fighting for
				limit = {
					has_holder = yes
					NOT = {
						de_facto_liege = PREV
					}
					holder_scope = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
				}

				usurp_title_plus_barony_if_unlanded = { target = ROOT type = claim }
			}
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	on_fail_title = {
		ROOT = {
			prestige = -100
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}

	ai_will_do = { 
		factor = 2 #higher desire. remember, the truce is only one year!
	}	
	
}
