## 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.)
#

cb_destruction = {
	name = CB_DESTRUCTION
	war_name = WAR_DESTRUCTION
	sprite = 12
	truce_days = 3650
	is_permanent = yes
	hostile_against_others = yes
	can_ask_to_join_war = yes
	
	infamy_modifier = 5
	
	can_use = {
		ROOT = {
			is_theocracy = no
			holy_order = no
			primary_title = {
				NOT = {is_landless_type_title = yes}
			}
			NOT = { is_vassal_or_below = FROM }
			NOT = { is_liege_or_above = FROM }
			NOT = {
				rightful_religious_head_scope = {
					character = FROM
				}
			}
		}
		FROM = {
			is_theocracy = no
			holy_order = no
			primary_title = {
				NOT = {is_landless_type_title = yes}
			}
			NAND = {
				holy_order = yes
				religion = ROOT
			}
			independent = yes
		}
		FROM = {
			any_demesne_title = {
				temporary = no
			}
		}
		ROOT = {
			any_demesne_title = {
				temporary = no
			}
		}
		FROM = {
			primary_title = {
				OR = {
					tier = king
					tier = emperor #King or emperor
				}
				OR = {
					AND = {
						FROM = {
							religion_group = muslim
							decadence = 80
						}
					}
					AND = {
						NOT = { has_dlc = "Zeus" }
						has_law = crown_authority_0
					}
					AND = {
						has_dlc = "Zeus"
						calc_true_if = {
							amount = 3
							has_law = law_voting_power_1
							has_law = banish_voting_power_1
							has_law = execution_voting_power_1
							has_law = revoke_title_voting_power_1
							has_law = grant_title_voting_power_1
							has_law = imprison_voting_power_1
							has_law = war_voting_power_1
						}
					}
					
				}
			}
		}
		# The attacker needs a border, or be at most two sea zones away from one of the target's counties
		FROM = {
			any_realm_province = {
				any_neighbor_province = {
					OR = {
						AND = {
							has_owner = yes
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
								}
							}
						}
						AND = {
							is_land = no
							any_neighbor_province = {
								OR = {
									AND = {
										has_owner = yes
										owner = {
											OR = {
												character = ROOT
												is_liege_or_above = ROOT
											}
										}
									}
									AND = {
										is_land = no
										any_neighbor_province = {
											owner = {
												OR = {
													character = ROOT
													is_liege_or_above = ROOT
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		

	}

	is_valid = {
		NOT = {
			ROOT = {
				rightful_religious_head_scope = {
					character = FROM 
				}
			}
		}
	}


	on_success = {
		FROM = {
			hidden_tooltip = {
				character_event = {id = CWN.500}
			}
			tooltip = {
				any_demesne_title = { # All titles
					limit = {
						OR = {
							tier = king
							tier = emperor
						}
					}
					destroy_landed_title = THIS
				}
			}
			imprison = ROOT
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 250
			add_trait = coalition
			hidden_tooltip = {
				disband_event_forces = faction_revolters
			}
		}

		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 250 }
			hidden_tooltip = {
				disband_event_forces = faction_revolters
			}
		}
	}

	on_fail = {
		ROOT = {
			prestige = -100
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			prisoner = FROM
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 250
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 250 }
		}
		hidden_tooltip = {
			any_attacker = {
				limit = { liege = { character = FROM } }
				prisoner = FROM
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}
	
	on_defender_leader_death = {
		hidden_tooltip = {
			any_attacker = {
				letter_event = {
					id = 251
				}
			}
		}
		end_war = invalid
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = { 
		factor = 1
		modifier = {
			factor = 0
			NOT = {ROOT = {is_rival = FROM}}
		}
	}
}

cb_coup = {
	name = CB_COUP
	war_name = WAR_COUP
	sprite = 12
	truce_days = 3650
	
	is_revolt_cb = no
	can_call_vassals = yes
	attacker_can_call_allies = no
	major_revolt = yes

	can_use = {
		ROOT = {
			OR = {
				is_feudal = yes
				is_tribal = yes
			}
			
		}
	}

	is_valid = {
		ROOT = {
			OR = {
				liege = {
					character = PREV # either independent
				}
				liege = { 
					FROM = { 
						is_liege_or_above = PREV # or have shared liege
					}
				}
			}
			any_demesne_title = {
				OR = {
					tier = count # has some land
					AND = {
						tier = BARON
						ROOT = {higher_tier_than = COUNT}
					}
					
				}
			}
		}
		FROM = {
			any_demesne_title = {
				NOT = { lower_tier_than = ROOT }
				temporary = no
			}
		}
	}

	on_success = {
		FROM = {	
			any_demesne_title = {
				limit = {
					OR = {
						tier = king
						tier = emperor
					}
					temporary = no
				}
				usurp_title = { target = ROOT type = faction_demand }
			}
			imprison = ROOT
			
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 250
			if = {
				limit = {has_plot = plot_coup}
				set_character_flag = won_coup
			}
			hidden_tooltip = {
				disband_event_forces = faction_revolters
			}
		}

		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 250 }
			hidden_tooltip = {
				disband_event_forces = faction_revolters
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = faction_imperial_timer
				hidden = yes
				duration = 3650
			}
		}
	}

	on_fail = {
		ROOT = {
			prestige = -100
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = faction_imperial_timer
				hidden = yes
				duration = 3650
			}
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			prisoner = FROM
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 250
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 250 }
		}
		hidden_tooltip = {
			any_attacker = {
				limit = { liege = { character = FROM } }
				prisoner = FROM
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = faction_imperial_timer
				hidden = yes
				duration = 3650
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}
	
	on_defender_leader_death = {
		hidden_tooltip = {
			any_attacker = {
				letter_event = {
					id = 251
				}
			}
		}
		
		end_war = invalid
	}

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


claim_all_succession = {
	name = CB_NAME_CLAIM_ALL
	war_name = WAR_NAME_CLAIM_ALL
	sprite = 5
	truce_days = 3650
	is_permanent = yes
	can_ask_to_join_war = no
	attacker_can_call_allies = no
	is_claim_all = yes

	allowed_to_target_tributaries = no
	allowed_to_target_suzerains = no

	can_use = {
		
		ROOT = {
			has_character_flag = using_claim_all
		}
		
	}

	is_valid = {
		ROOT = {
			total_claims = {
				who = FROM
				strong = yes # Count only strong claims
				value = 1 # must have at least one claim left
			}
		}
	}

	on_add = {
		ROOT = {
			any_claim = {
				limit = {
					holder_scope = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
					ROOT = { has_strong_claim = PREV }
				}
				press_claim = ROOT
			}
		}
	}

	on_success = {
		ROOT = {
			any_claim = {
				limit = {
					holder_scope = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
					ROOT = { has_strong_claim = PREV }
				}
				usurp_title_plus_barony_if_unlanded = { target = ROOT type = claim }
				if = {
					limit = {
						higher_tier_than = BARON
						NOT = { culture = ROOT }
					}
					hidden_tooltip = { conquest_culture = ROOT }
				}
			}
		}
		hidden_tooltip = {
			ROOT = {
				if = {
					limit = {
						has_dlc = "Legacy of Rome"
						OR = { 
							has_landed_title = e_byzantium
							has_landed_title = e_roman_empire
						}
						religion_group = christian
					}
					character_event = { id = LoR.30 days = 12 }
				}
			}
		}
		hidden_tooltip = {
			any_attacker = {
				limit = { NOT = { character = ROOT } }
				clr_character_flag = claim_supporter
				if = {
					limit = {ROOT = {higher_tier_than = PREV}}
					set_defacto_liege = FROM
				}
			}
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	on_fail = {
		ROOT = {
			prestige = -150
		}
		hidden_tooltip = {
			any_attacker = {
				limit = {
					has_character_flag = claim_supporter
				}
				any_demesne_title = {
					limit = {
						temporary = no
						OR = {
							tier = FROM
							higher_tier_than = FROM
						}
					}
					grant_title = FROM
				}
				clr_character_flag = claim_supporter
				hidden_tooltip = {
					reverse_opinion = {
						modifier = opinion_traitor
						who = FROM
					}
				}
				set_defacto_liege = FROM
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 75
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 75 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			any_claim = {
				limit = {
					holder_scope = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
					ROOT = { has_strong_claim = PREV }
				}
				remove_claim = ROOT
			}
		}
		hidden_tooltip = {
			any_attacker = {
				limit = {
					has_character_flag = claim_supporter
				}
				any_demesne_title = {
					limit = {
						temporary = no
						OR = {
							tier = FROM
							higher_tier_than = FROM
						}
					}
					grant_title = FROM
				}
				clr_character_flag = claim_supporter
				set_defacto_liege = FROM
				imprison = FROM
				hidden_tooltip = {
					reverse_opinion = {
						modifier = opinion_traitor
						who = FROM
					}
				}
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 200
		}
		FROM = {
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
					religion_group = christian
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
	}

	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
	}
}