## 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)
#
# ai_will_do: modifies value AI places on the CB compared to other CBs (default: 1)
# can_use_gui: If otherwise valid, the CB is listed in the Diplo View, but you can't declare war unless 'can_use_gui' is also valid (also shows a trigger tooltip.)

abolosh_title = {
	name = SM_ABOLISH
	war_name = WAR_NAME_SM_ABOLISH
	sprite = 6
	truce_days = 3650
	
	is_permanent = yes
	can_ask_to_join_war = no
	hostile_against_others = no
	check_all_titles = yes
	allowed_to_target_tributaries = no
	
	defender_unoccupied_warscore = yes
	
	can_use_gui = {
		FROM = {
			show_scope_change = no
			conditional_tooltip = {
				trigger = { 
					tier = DUKE
				}
				ROOT = {
					show_scope_change = no
					prestige = 500
				}
			}
			conditional_tooltip = {
				trigger = { 
					tier = KING
				}
				ROOT = {
					show_scope_change = no
					prestige = 1500
				}
			}
			conditional_tooltip = {
				trigger = { 
					tier = EMPEROR
				}
				ROOT = {
					show_scope_change = no
					prestige = 2500
				}
			}
		}
	}
	
	can_use = {
		ROOT = {
				NOT = { is_liege_or_above = FROM }
				#de_jure_liege_or_above = FROM
		}
		FROM = {
			is_landed = yes
			controls_religion = no
			holy_order = no
		}
		# If same realm support inter-vassal wars, otherwise must always be declared on top liege of the realm.
		OR = {
			AND = {
				ROOT = { NOT = { same_realm = FROM } }
				FROM = { independent = yes }
			}
			ROOT = { same_realm = FROM }
		}
	}
	
	can_use_title = {
		is_primary_type_title = no
		temporary = no
		higher_tier_than = COUNT
		
		# Title held by declarer must be a dejure vassal title of the target title
		ROOT = {
			#de_jure_liege_or_above = PREV
			any_realm_title = {
				PREVPREV = {
					any_de_jure_vassal_title = {
						title = PREVPREV
					}
				}
			}
		}
	}
	
	is_valid = {
		always = yes
	}
	
	is_valid_title = {
		FROM = { has_landed_title = PREV }
	}
	
	on_add = {

	}
	
	on_add_title = {
		if = {
			limit = {  tier = duke }
			ROOT = {
				prestige = -500
			}
		}
		if = {
			limit = { tier = king  }
			ROOT = {
				prestige = -1500
			}
		}
		if = {
			limit = { tier = emperor }
			ROOT = {
				prestige = -2500
			}
		}
	}
	
	on_success_title = {
		FROM = {
			destroy_landed_title = PREV
			add_claim = PREV
		}
		if = {
			limit = {  tier = duke }
			FROM = {
				prestige = -400
			}
		}
		if = {
			limit = { tier = king  }
			FROM = {
				prestige = -600
			}
		}
		if = {
			limit = { tier = emperor }
			FROM = {
				prestige = -1000
			}
		}
	}
	
	on_success = {
		#ROOT = {
		#	prestige = 100
		#}
		any_attacker = {
			limit = { not = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		FROM = {
			piety = -100
		}
	}
	
	on_fail = {
		FROM = {
			prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	on_reverse_demand = {
		
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			prestige = 200
		}
		any_defender = {
			limit = { not = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	attacker_ai_victory_worth = {
		factor = -1
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = {
		factor = 1
		modifier = {
			factor = 0.6 # costs prestige so less likely to use
		}
		modifier = {
			factor = 0.1 # Nomads care little to dejure rules
			ROOT = {
				is_nomadic = yes
			}
		}
		modifier = {
			factor = 0.3 # Reduce chance as more risky to take on
			ROOT = {
				NOT = {
					relative_power_including_allies_attacker = {
						who = FROM
						power = 0.9
					}
				}
			}
		}
	}
}