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

claim = {
	name = CB_NAME_CLAIM
	war_name = WAR_NAME_CLAIM
	sprite = 1
	truce_days = 3650
	hostile_against_others = yes
	can_ask_to_join_war = no

	press_claim = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB claim." }

	can_use_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
		OR = { 
			ROOT = { has_strong_claim = PREV }
			ROOT = { has_character_flag = claimant_adventurer  }
			AND = {
				ROOT = { has_weak_claim = PREV }
				OR = {
					is_pretender = yes # Checks vs ROOT character
					holder_scope = { has_regent = yes }
					is_contested = yes # Is already being contested in some form of Claim or Succession War
				}
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
		ROOT = { has_claim = PREV }
	}

	on_success_title = {
		log = "[Root.GetBestName] won the claim war against [From.GetBestName]."
		usurp_title_plus_barony_if_unlanded = ROOT
		
		if = {
			limit = {
				higher_tier_than = BARON
				culture = FROM
				NOT = { culture = ROOT }
			}
			hidden_tooltip = { conquest_culture = ROOT }
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		
		FROM = { prestige = -100 }
		
		hidden_tooltip = { ROOT = { clr_character_flag = claimant_adventurer } }
	}

	on_fail_title = {
		ROOT = {
			prestige = -100
			hidden_tooltip = {
				disband_event_forces = yes
				clr_character_flag = claimant_adventurer
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -150
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		if = {
			limit = { ROOT = { has_character_flag = claimant_adventurer } }
			ROOT = { imprison = FROM }
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 150
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 150 }
		}
	}

	on_reverse_demand_title = {
		ROOT = {
			remove_claim = PREV
			hidden_tooltip = {
				disband_event_forces = yes
				clr_character_flag = claimant_adventurer
			}
		}
	}
	
	on_attacker_leader_death = {
		if = {
			limit = { ROOT = { has_character_flag = claimant_adventurer } }
			ROOT = {
				hidden_tooltip = {
					disband_event_forces = yes
					clr_character_flag = claimant_adventurer
				}
			}
			end_war = invalid
		}
	}

	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 = 1
		modifier = {
			factor = 0.5
			tier = baron
		}
		modifier = {
			factor = 2
			tier = duke
		}
		modifier = {
			factor = 4
			tier = king
		}
		modifier = {
			factor = 8
			tier = emperor
		}
		modifier = {
			factor = 0
			ROOT = {
				religion = colonial_separatist
				primary_title = { title = e_terran_confederation }
			}
		}
	}
}

other_claim = {
	name = CB_NAME_CLAIM
	war_name = WAR_NAME_OTHER_CLAIM
	sprite = 2
	truce_days = 3650
	hostile_against_others = yes
	can_ask_to_join_war = yes

	press_claim = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB other_claim." }

	can_use_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}

		NOT = { any_war = { attacker = { character = ROOT } } } # when used in title scope, checks all wars for that title
		
		OR = { 
			ROOT = { has_strong_claim = PREV }
			AND = {
				ROOT = { has_weak_claim = PREV }
				OR = {
					is_pretender = yes # Checks vs ROOT character
					holder_scope = { has_regent = yes }
					is_contested = yes # Is already being contested in some form of Claim or Succession War
				}
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
		ROOT = { has_claim = PREV }
	}

	on_success = {
		log = "[Root.GetBestName] won the other_claim war against [From.GetBestName]."
		hidden_tooltip = { ROOT = { opinion = { modifier = pressed_my_claim  who = PREV } } }
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		FROM = { prestige = -100 }
	}

	on_success_title = {
		if = {
			limit = {
				higher_tier_than = duke
				ROOT = {
					religion = FROMFROM
					NOT = { religion = FROM }
				}
			}
			FROMFROM = {
				religion_authority = { modifier = successful_regime_change years = 30 }
				piety = 100
			}
		}
		if = {
			limit = { controls_religion = yes }
			holder_scope = { abdicate_to = ROOT }
			if = {
				limit = { FROMFROM = { higher_tier_than = PREV } }
				ROOT = { set_defacto_liege = FROMFROM }
			}
			
			hidden_tooltip = { ROOT = { opinion = { modifier = pressed_my_claim  who = PREV multiplier = 2 } } }
		}
		if = {
			limit = { controls_religion = no }
			
			if = {
				limit = { holder_scope = { same_realm = FROMFROM } } # The current holder and the one pressing my claim are in the same larger realm
				ROOT = { set_character_flag = other_claim_tmp_flag }
			}
			
			if = {
				limit = {
					ROOT = {
						is_ruler = yes
						is_liege_or_above = FROMFROM # The claimant is a vassal ruler of the presser
					}
				}
				ROOT = { set_character_flag = claimant_is_vassal_ruler_flag }
			}

			usurp_title_plus_barony_if_unlanded = ROOT
			
			hidden_tooltip = {
				# If we were erroneously vassalized, break free
				if = {
					limit = {
						NOT = { ROOT = { has_character_flag = claimant_is_vassal_ruler_flag } }
						holder_scope = { is_liege_or_above = FROMFROM }
						NOT = { de_jure_liege_or_above = FROMFROM }
						ROOT = { NOT = { dynasty = FROMFROM } }
					}
					ROOT = { set_defacto_liege = ROOT }
				}
			
				# try and vassalize, but only conditionally
				if = {
					limit = {
						NOT = { holder_scope = { is_liege_or_above = FROMFROM } }
						OR = {
							de_jure_liege_or_above = FROMFROM
							ROOT = { has_character_flag = claimant_is_vassal_ruler_flag }
							ROOT = { dynasty = FROMFROM }
						}
					}
					ROOT = { set_defacto_liege = FROMFROM }
				}

				# check if the previous effect managed to make us part of the same realm
				# if not, we'll break the other realm
				if = {
					limit = {
						NOT = { ROOT = { has_character_flag = other_claim_tmp_flag } }
						FROM = { FROM = { top_liege = { ROOT = { top_liege = { NOT = { character = PREVPREV } } } } } }
					}
					ROOT = { set_defacto_liege = ROOT }
				}
				
				# If we have become independent from our mutual liege, restore that vassal tie
				if = {
					limit = {
						ROOT = { 
							has_character_flag = other_claim_tmp_flag 
							de_facto_liege = ROOT
						}
					}
					FROM = { FROM = { top_liege = { ROOT = { set_defacto_liege = PREV } } } }
				}
				
				ROOT = { 
					clr_character_flag = other_claim_tmp_flag 
					clr_character_flag = claimant_is_vassal_ruler_flag 
				}
			}
		}
		
		if = {
			limit = {
				higher_tier_than = BARON
				NOT = { culture = ROOT }
			}
			hidden_tooltip = { conquest_culture = ROOT }
		}
	}

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

	on_reverse_demand = {
		prestige = -150
		transfer_scaled_wealth = {
			to = FROM
			value = 4.0
		}
		ROOT = {
			prestige = -150
			imprison = FROM
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 150
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 150 }
		}
	}

	on_reverse_demand_title = {
		ROOT = { remove_claim = PREV }
	}

	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 = 1
		modifier = {
			factor = 0
			FROM = {
				FROM = {
					OR = {
						has_strong_claim = PREVPREV
						has_weak_claim = PREVPREV
					}
					NOT = { trait = content }
				}
			}
		}
		modifier = {
			factor = 2
			FROM = {
				FROM = {
					religion = ROOT
					NOT = { trait = pragmatic }
				}
			}
		}
		modifier = {
			factor = 2
			FROM = {
				FROM = {
					religion = ROOT
					trait = radical
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = {
				FROM = {
					religion = PREV
					NOT = { trait = pragmatic }
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = {
				FROM = {
					religion = PREV
					trait = radical
				}
			}
		}
	}
	
	ai_will_do = {
		factor = 1
		modifier = {
			factor = 0
			NOT = { higher_tier_than = count }
			NOT = { location = { any_neighbor_province = { any_realm_lord = { character = ROOT } } } }
		}
		modifier = {
			factor = 0
			ROOT = {
				religion = colonial_separatist
				primary_title = { title = e_terran_confederation }
			}
		}
	}
}

claim_all = {
	name = CB_NAME_CLAIM_ALL
	war_name = WAR_NAME_CLAIM_ALL
	sprite = 5
	truce_days = 3650
	is_permanent = yes
	can_ask_to_join_war = yes
	is_claim_all = yes

	can_use = {
		ROOT = {
			total_claims = {
				who = FROM
				strong = yes # Count only strong claims
				value = 2
			}
		}
	}

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

	on_add = {
		log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB claim_all." 
		ROOT = {
			any_claim = {
				limit = {
					holder_scope = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
					ROOT = { has_strong_claim = PREV }
				}
				press_claim = ROOT
			}
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the claim_all war against [From.GetBestName]."
		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 = ROOT
				if = {
					limit = {
						higher_tier_than = BARON
						NOT = { culture = ROOT }
					}
					hidden_tooltip = { conquest_culture = ROOT }
				}
			}
		}
		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
		}
		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 }
				}
				ROOT = {
					remove_claim = PREV
				}
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 200
		}
		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
	}
	
	ai_will_do = {
		factor = 10
	}
}

claim_on_vassal_plot = {
	name = CB_NAME_CLAIM_VASSAL
	war_name = WAR_NAME_CLAIM_VASSAL
	sprite = 3
	truce_days = 3650
	hostile_against_others = yes
	reflect_titleholder_change = no

	press_claim = yes
	attacker_can_call_allies = no
	can_attack_vassals = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB claim_on_vassal_plot." }

	can_use_title = {
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				de_facto_liege = ROOT
			}
		}
	}

	is_valid_title = {
		FROM = {
			has_landed_title = PREV
		}
		ROOT = {
			has_plot = plot_gain_vassal_title
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the claim_on_vassal_plot war against [From.GetBestName]."
		ROOT = {
			prestige = 50
		}
	}
	
	on_success_title = {
		usurp_title_plus_barony_if_unlanded = ROOT
		ROOT = { plot_succeeds = yes }
	}

	on_fail = {
		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
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	on_attacker_leader_death = {
		hidden_tooltip = {
			any_defender = {
				letter_event = {
					id = 251
				}
			}
		}
		
		end_war = invalid
	}
	
	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
	}
}


invasion = {
	name = CB_NAME_INVASION
	war_name = WAR_NAME_INVASION
	sprite = 7
	truce_days = 3650
	hostile_against_others = yes
	can_ask_to_join_war = no
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB invasion." }
	
	can_use_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}
	
	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the invasion war against [From.GetBestName]."
		ROOT = { prestige = 200 }
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 200
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		
		hidden_tooltip = {
			ROOT = {
				occupy_minors_of_occupied_settlements = FROM
				gain_all_occupied_titles = FROM			
				give_nickname = nick_the_conqueror
			}
		}
		FROM = { hidden_tooltip = { any_vassal = { opinion = { who = PREV modifier = opinion_lost_defensive_war } } } }
		
		FROM = { prestige = -200 }
	}

	on_success_title = {
		custom_tooltip = {
			text = invasion_succ_tip
			hidden_tooltip = {
				usurp_title_plus_barony_if_unlanded = ROOT
				FROM = { set_defacto_liege = ROOT }
				if = {
					limit = { FROM = { is_liege_or_above = ROOT } }
					FROM = { imprison = ROOT }
				}
			}
		}
		
		if = {
			limit = {
				higher_tier_than = BARON
				NOT = { culture = ROOT }
			}
			hidden_tooltip = { conquest_culture = ROOT }
		}
	}

	on_fail = {
		ROOT = { prestige = -200 }
		FROM = { prestige = 100 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 8.0
			}
		}
		FROM = { prestige = 200 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		FROM = { hidden_tooltip = { any_vassal = { opinion = { who = PREV modifier = opinion_won_defensive_war } } } }
	}

	on_reverse_demand_title = {
		ROOT = { remove_claim = PREV }
	}

	on_attacker_leader_death = {
		hidden_tooltip = { any_defender = { letter_event = { id = 251 } } }

		end_war = whitepeace
	}

	attacker_ai_victory_worth = {
		factor = 150
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

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

tribal_invasion = {
	name = CB_NAME_INVASION
	war_name = WAR_NAME_INVASION
	sprite = 8
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	can_ask_to_join_war = yes
	check_de_jure_tier = KING

	can_use_gui = { ROOT = { prestige = 500 } }
	
	on_add = {
		log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB tribal_invasion." 
		ROOT = { prestige = -500 }
	}

	can_use_title = {
		ROOT = {
			OR = {
				AND = {
					independent = yes
					religion = hiver
					NOT = { religion = FROM }
					higher_tier_than = COUNT
				}
				AND = {
					mercenary = yes
					NOT = { num_of_titles = 2 }
				}
			}
		}
		
		ROOT = { NOT = { is_liege_or_above = FROM } }
	}
	
	is_valid_title = { FROM = { any_realm_title = { de_jure_liege_or_above = PREVPREV } } }

	on_success = {
		log = "[Root.GetBestName] won the tribal_invasion war against [From.GetBestName]."
		ROOT = { prestige = 200 }
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 200
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		FROM = { prestige = -200 }
		hidden_tooltip = {
			ROOT = {
				occupy_minors_of_occupied_settlements = FROM
				gain_all_occupied_titles = FROM
			}
		}
		FROM = { hidden_tooltip = { any_vassal = { opinion = { who = PREV modifier = opinion_lost_defensive_war } } } }
	}
	
	on_success_title = {
		custom_tooltip = {
			text = tribal_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title_destroy_duchies = {
						title = PREV
						enemy = FROM
						is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
					}
				}
			}
		}
	}

	on_fail = {
		FROM = { prestige = 100 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		ROOT = { prestige = -200 }
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = { prestige = 200 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		FROM = { hidden_tooltip = { any_vassal = { opinion = { who = PREV modifier = opinion_won_defensive_war } } } }
	}

	attacker_ai_victory_worth = {
		factor = 200
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

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

crusade = {
	name = CB_NAME_CRUSADE
	war_name = WAR_NAME_CRUSADE
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	battle_warscore_mult = 0.5
	check_de_jure_tier = KING
	
	can_use_gui = {
		ROOT = {
			has_called_crusade = no
			religion_authority = 0.05
			OR = {
				religion = terran_imperial
				religion = orthodox
				religion = machine_cultist
				religion = hiver
			}
		}
	}

	can_use = {
		ROOT = { can_call_crusade = yes }
		FROM = { NOT = { religion = ROOT } }
	}

	can_use_title = {
		FROM = {
			any_realm_title = { de_jure_liege_or_above = PREVPREV }
			
			independent = yes # Don't declare Crusades on revolters - chances are high the war will invalidate
			
			num_of_realm_counties = {
				value = 6
				title = PREV
			}
		}
	}
	
	is_valid = {
		ROOT = { can_call_crusade = yes }
		FROM = { NOT = { religion = ROOT } }
	}

	is_valid_title = { FROM = { any_realm_title = { de_jure_liege_or_above = PREVPREV } } }

	on_add = {
		log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB crusade."
		if = {
			limit = { ROOT = { religion = hiver } }
			FROM = { narrative_event = { id = hiver.3000 } }
		}
	}
	
	on_success_title = {
		log = "[Root.GetBestName] won the crusade war against [From.GetBestName]."
		# Should we give the seized land to its current king?
		if = {
			limit = {
				has_holder = yes
				holder_scope = { religion = ROOT }
			}
			holder_scope = {
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
					is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
				}
			}
		}
		
		# Should we give the seized land to a claimant of our faith?
		if = {
			limit = {
				OR = {
					has_holder = no
					holder_scope = { NOT = { religion = ROOT } }
				}
				
				best_crusade_claimant = {
					always = yes # There is a "best" claimant
				}
			}
			
			# Claimants must be of ROOT's religion, and are ranked by strength of claim and actual contribution to the war
			best_crusade_claimant = {
				if  = {
					limit = {
						PREV = { has_holder = no }
						OR = {
							independent = yes
							is_ruler = no
							liege = { tier = EMPEROR }
						}
					}
					usurp_title = PREV
				}
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
					is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
				}
			}
		}
		
		# Give the seized land to the main contributor of the Crusade
		if = {
			limit = {
				OR = {
					has_holder = no
					NOT = { holder_scope = { religion = ROOT } }
				}
				NOT = { best_crusade_claimant = { always = yes } }
			}
			
			most_participating_attacker = {
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
				}
				if  = {
					limit = {
						primary_title = { is_primary_type_title = no } # Mercs, the Pope, Holy Orders, etc
						PREV = { has_holder = no }
						NOT = { character = ROOT }
						OR = {
							independent = yes
							liege = { tier = EMPEROR }
						}
					}
					usurp_title = PREV
					
					if = {
						limit = { NOT = { culture = PREV } }
						hidden_tooltip = { PREV = { conquest_culture = THIS } }
					}
				}
			}
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 500
			participation_scaled_piety = 1000
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 500
				participation_scaled_piety = 1000
			}
		}
		any_attacker = {
			limit = {
				ai = no
				NOT = { has_character_flag = achievement_crusader }
			}
			set_character_flag = achievement_crusader
		}
		
		ROOT = {
			religion_authority = {
				modifier = won_crusade
				years = 20
			}
		}
		
		FROM = {
			piety = -100
			religion_authority = {
				modifier = lost_crusade
				years = 20
			}			
		}
	}

	on_fail = {
		ROOT = {
			piety = -100
		}
		
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
			}
		}
		
	}

	on_reverse_demand = {
		ROOT = {
			piety = -200
			religion_authority = {
				modifier = lost_crusade
				years = 20
			}
		}
		FROM = {
			piety = 100
			religion_authority = {
				modifier = won_crusade
				years = 20
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 300
			participation_scaled_prestige = 150
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 300
				participation_scaled_prestige = 150
			}
		}
	}

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

# Holy War CB
religious = {
	name = CB_NAME_RELIGIOUS
	war_name = WAR_NAME_RELIGIOUS
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	check_de_jure_tier = DUKE
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB religious." }

	can_use = {
		ROOT = {
			OR = {
				religion = orthodox
				religion = xenoterran
				religion = solarian
				religion = machine_cultist
				religion = imperial_cult
				AND = {
					religion_group = religious_group
					FROM = {
						OR = {
							trait = hiver_implant
							trait = full_cybernetic_conversion
						}
					}
				}
			}
			NOT = { same_realm = FROM }
			OR = {
				religion = imperial_cult
				NOT = { religion = FROM }
			}
			top_liege = {
				religion_group = ROOT
				OR = {
					religion = imperial_cult
					NOT = { religion = FROM }
				}
			}
		}
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target kingdom or a border
		any_direct_de_jure_vassal_title = {
			OR = {
				holder_scope = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
				}
				location = {
					any_neighbor_province = {
						has_owner = yes
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			OR = {
				religion = orthodox
				religion = xenoterran
				religion = solarian
				religion = machine_cultist
				religion = imperial_cult
				AND = {
					religion_group = religious_group
					FROM = {
						OR = {
							trait = hiver_implant
							trait = full_cybernetic_conversion
						}
					}
				}
			}
			NOT = { same_realm = FROM }
			OR = {
				religion = imperial_cult
				NOT = { religion = FROM }
			}
			top_liege = {
				religion_group = ROOT
				OR = {
					religion = imperial_cult
					NOT = { religion = FROM }
				}
			}
		}
	}
	
	on_success = {
		log = "[Root.GetBestName] won the religious war against [From.GetBestName]."
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_piety = 100
			participation_scaled_prestige = 50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
			}
		}
		
		ROOT = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}		
		}
		FROM = { piety = -100 }
		FROM = { prestige = -50 }
		FROM = {
			hidden_tooltip = {
				any_vassal = {
					limit = { religion = PREV }
					opinion = { who = PREV modifier = opinion_lost_defensive_war }
				}
			}
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = religious_cb_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
						same_religion = yes # Only vassalize rulers of my religion
					}
				}
			}
		}
	}

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

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -75
			prestige = -150
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}		
		}
		FROM = {
			hidden_tooltip = {
				any_vassal = {
					limit = { religion = PREV }
					opinion = { who = PREV modifier = opinion_won_defensive_war }
				}
			}
		}
	}

	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
	}
}
# Liberation CBs
religious_liberation = {
	name = CB_NAME_RELIGIOUS_LIBERATION
	war_name = WAR_NAME_RELIGIOUS_LIBERATION
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	check_de_jure_tier = DUKE
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB religious_liberation." }

	can_use = {
		ROOT = {
			NOT = { same_realm = FROM }
			NOT = { religion = FROM }
			NOT = { religion = space_pirate }
			top_liege = {
				religion_group = ROOT
				NOT = { religion = FROM }
			}
		}
	}
	
	can_use_title = {
		# Must be liberating same-ideology populace
		FROM = {
			any_realm_province = {
				religion = ROOT
				duchy = { title = PREVPREVPREV }
			}
		}
		# The attacker needs at least one county in the target kingdom or a border
		any_direct_de_jure_vassal_title = {
			OR = {
				holder_scope = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
				}
				location = {
					any_neighbor_province = {
						has_owner = yes
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			NOT = { same_realm = FROM }
			NOT = { religion = FROM }
			top_liege = {
				religion_group = ROOT
				NOT = { religion = FROM }
			}
		}
	}
	
	on_success = {
		log = "[Root.GetBestName] won the religious_liberation war against [From.GetBestName]."
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_piety = 100
			participation_scaled_prestige = 50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
			}
		}
		
		ROOT = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}		
		}
		FROM = { piety = -100 }
		FROM = { prestige = -50 }
		FROM = {
			hidden_tooltip = {
				any_vassal = {
					limit = { religion = PREV }
					opinion = { who = PREV modifier = opinion_lost_defensive_war }
				}
			}
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = religious_cb_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
						same_religion = yes # Only vassalize rulers of my religion
					}
				}
			}
		}
	}

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

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -75
			prestige = -150
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}		
		}
		FROM = {
			hidden_tooltip = {
				any_vassal = {
					limit = { religion = PREV }
					opinion = { who = PREV modifier = opinion_won_defensive_war }
				}
			}
		}
	}

	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
	}
}
cultural_liberation = {
	name = CB_NAME_CULTURAL_LIBERATION
	war_name = WAR_NAME_CULTURAL_LIBERATION
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	check_de_jure_tier = DUKE
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB cultural_liberation." }

	can_use = {
		ROOT = {
			NOT = { same_realm = FROM }
			NOT = { culture_group = FROM }
			NOT = { religion = space_pirate }
		}
	}
	
	can_use_title = {
		# Must be liberating same-ideology populace
		FROM = {
			any_realm_province = {
				culture_group = ROOT
				duchy = { title = PREVPREVPREV }
			}
		}
		# The attacker needs at least one county in the target kingdom or a border
		any_direct_de_jure_vassal_title = {
			OR = {
				holder_scope = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
				}
				location = {
					any_neighbor_province = {
						has_owner = yes
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			NOT = { same_realm = FROM }
			NOT = { culture_group = FROM }
		}
	}
	
	on_success = {
		log = "[Root.GetBestName] won the cultural_liberation war against [From.GetBestName]."
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_piety = 100
			participation_scaled_prestige = 50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
			}
		}
		
		ROOT = {
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { piety = -100 }
		FROM = { prestige = -50 }
		FROM = {
			hidden_tooltip = {
				any_vassal = {
					limit = { culture_group = PREV }
					opinion = { who = PREV modifier = opinion_lost_defensive_war }
				}
			}
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = religious_cb_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
					}
				}
			}
		}
	}

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

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -75
			prestige = -150
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}		
		}
		FROM = {
			hidden_tooltip = {
				any_vassal = {
					limit = { culture_group = PREV }
					opinion = { who = PREV modifier = opinion_won_defensive_war }
				}
			}
		}
	}

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

bid_for_independence = {
	name = CB_NAME_INDEPENDENCE
	war_name = WAR_NAME_INDEPENDENCE
	sprite = 12
	truce_days = 3650
	
	is_revolt_cb = yes
	is_permanent = yes
	is_independence = yes
	hostile_against_others = no
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB bid_for_independence." }

	can_use = {
		ROOT = {
			de_facto_liege = FROM
			higher_tier_than = BARON
			OR = {
				is_patrician = no
				higher_tier_than = COUNT
			}
			NOT = { any_demesne_title = { is_tribal_type_title = yes } }
		}
		
		FROM = {
			NOT = {
				any_war = {
					attacker = { character = FROM }
					using_cb = bid_for_independence
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			OR = {
				liege = { character = PREV } # either independent
				liege = { FROM = { is_liege_or_above = PREV } } # or have shared liege
			}
		}
		FROM = {
			any_demesne_title = {
				NOT = { lower_tier_than = ROOT }
				temporary = no
			}
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the bid_for_independence war against [From.GetBestName]."
		if = {
			limit = { FROM = { independent = no } }
			FROM = {
				if = {
					limit = { in_revolt = yes }
					liege_before_war = { ROOT = { set_defacto_liege = PREV } }
				}
				if = {
					limit = { in_revolt = no }
					liege = { ROOT = { set_defacto_liege = PREV } }
				}
				hidden_tooltip = {
					any_vassal = {
						limit = {
							OR = {
								culture_group = PREV
								religion = terran_imperial
								religion = terran_republican
								religion = terran_federalist
								religion = pilgrim
								religion = orthodox
								religion = solarian
								religion = solar_cultist
							}
						}
						opinion = { who = PREV modifier = opinion_lost_defensive_war }
					}
				}
			}
		}

		if = {
			limit = { FROM = { independent = yes } }
			ROOT = { set_defacto_liege = ROOT }
		}

		hidden_tooltip = {
			ROOT = {
				prestige = 100
				any_demesne_title = { add_pressed_claim = FROM }
			}
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}

		FROM = {
			any_demesne_title = { # All titles
				limit = {
					OR = {
						tier = king
						tier = emperor
					}
#					is_titular = no
					NOT = { has_law = centralization_0 }
				}
				if = {
					limit = { has_law = centralization_1 }
					add_law = centralization_0
				}
				if = {
					limit = { has_law = centralization_2 }
					add_law = centralization_1
				}
				if = {
					limit = { has_law = centralization_3 }
					add_law = centralization_2
				}
				if = {
					limit = { has_law = centralization_4 }
					add_law = centralization_3
				}
			}
		}
		# Eliminate any feudal merchant republics
		hidden_tooltip = { ROOT = { character_event = { id = maintenance.550 } } }
	}

	on_fail = {
		ROOT = {
			prestige = -50
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = -50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = -50 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -100
			prisoner = FROM
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = -100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = -100 }
		}
		FROM = {
			prestige = 50
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 150
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = {
		factor = 1
		modifier = {
			factor = 0
			ROOT = { opinion = { who = FROM value = 0 } }
			NOT = { trait = cold }
		}
		modifier = {
			factor = 0
			ROOT = {
				OR = {
					religion = terran_imperial
					religion = terran_republican
					religion = astrist
				}
				religion = FROM
				religion_authority = 0.25
				NOT = { trait = pragmatic }
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				crownlaw_title = { holder_scope = { character = FROM } }
				culture_group = FROM
				religion = FROM
				NOT = { trait = lunatic }
				NOT = { trait = ambitious }
			}
		}
		modifier = {
			factor = 2
			ROOT = {
				OR = {
					religion = colonial_separatist
					religion = neo_feudal
				}
				religion_authority = 0.25
			}
		}
		modifier = {
			factor = 2
			ROOT = {
				OR = {
					religion = colonial_separatist
					religion = neo_feudal
				}
				religion_authority = 0.25
				trait = radical
			}
		}
	}
}

overthrow_ruler = {
	name = CB_NAME_OVERTHROWRULER
	war_name = WAR_NAME_OVERTHROWRULER
	sprite = 12
	truce_days = 3650
	
	is_revolt_cb = yes
	can_call_vassals = yes
	attacker_can_call_allies = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB overthrow_ruler." }

	can_use = { ROOT = { de_facto_liege = FROM } }

	is_valid = {
		ROOT = {
			OR = {
				liege = { character = PREV } # either independent
				liege = { FROM = { is_liege_or_above = PREV } } # or have shared liege
			}
		}
		FROM = {
			any_demesne_title = {
				NOT = { lower_tier_than = ROOT }
				temporary = no
			}
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the overthrow_ruler war against [From.GetBestName]."
		ROOT = { primary_title = { add_pressed_claim = FROM } }
		FROM = {
			prestige = -500
			remove_opinion = { who = ROOT modifier = declared_war }
			any_demesne_title = { # All titles
				limit = {
					OR = {
						tier = king
						tier = emperor
					}
#					is_titular = no
					NOT = { has_law = centralization_0 }
				}
				if = {
					limit = { has_law = centralization_1 }
					add_law = centralization_0
				}
				if = {
					limit = { has_law = centralization_2 }
					add_law = centralization_0
				}
				if = {
					limit = { has_law = centralization_3 }
					add_law = centralization_1
				}
				if = {
					limit = { has_law = centralization_4 }
					add_law = centralization_2
				}
			}
			hidden_tooltip = {
				character_event = { id = nepotism.0 }
				character_event = { id = nepotism.1 }
			}
			abdicate = yes
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 250
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 250 }
		}
	}

	on_fail = {
		ROOT = { prestige = -100 }
		FROM = { remove_opinion = { who = ROOT modifier = declared_war } }
	}

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

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

overthrow_ruler_no_calls = {
	name = CB_NAME_OVERTHROWRULER_NC
	war_name = WAR_NAME_OVERTHROWRULER_NC
	sprite = 12
	truce_days = 3650
	
	is_revolt_cb = yes
	can_call_vassals = no
	can_ask_to_join_war = no
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB overthrow_ruler_no_calls." }

	can_use = { ROOT = { de_facto_liege = FROM } }

	is_valid = {
		ROOT = {
			OR = {
				liege = { character = PREV } # either independent
				liege = { FROM = { is_liege_or_above = PREV } } # or have shared liege
			}
		}
		FROM = { higher_tier_than = ROOT }
	}

	on_success = {
		log = "[Root.GetBestName] won the overthrow_ruler_no_calls war against [From.GetBestName]."
		ROOT = {
			prestige = 200
			primary_title = { add_pressed_claim = FROM }
		}
		FROM = {
			prestige = -500
			remove_opinion = { who = ROOT modifier = declared_war }
			any_demesne_title = { # All titles
				limit = {
					OR = {
						tier = king
						tier = emperor
					}
					NOT = { has_law = centralization_0 }
				}
				if = {
					limit = { has_law = centralization_1 }
					add_law = centralization_0
				}
				if = {
					limit = { has_law = centralization_2 }
					add_law = centralization_0
				}
				if = {
					limit = { has_law = centralization_3 }
					add_law = centralization_1
				}
				if = {
					limit = { has_law = centralization_4 }
					add_law = centralization_2
				}
			}
			hidden_tooltip = {
				character_event = { id = nepotism.0 }
				character_event = { id = nepotism.1 }
			}
			abdicate = yes
		}
	}

	on_fail = {
		ROOT = { prestige = -100 }
		
		FROM = {
			prestige = -100
			remove_opinion = { who = ROOT modifier = declared_war }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			prisoner = FROM
		}
		FROM = { prestige = 50 }
	}

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

cb_faction_independence = {
	name = CB_NAME_INDEPENDENCE
	war_name = WAR_NAME_FACTION_INDEPENDENCE
	sprite = 12
	truce_days = 3650
	hostile_against_others = no
	
	is_independence = yes
	
	can_use = {
		ROOT = { vassal_of = FROM }
	}
	
	on_add = {
		log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB cb_faction_independence."
		any_attacker = {
			limit = { primary_title = { tier = king } }
			FROM = { religion_authority = { modifier = allowed_major_rebellion years = 30 } }
		}
	}

	is_valid = {
		ROOT = {
			OR = {
				liege = { character = PREV } # either independent
				liege = { FROM = { is_liege_or_above = PREV } } # or have shared liege
			}
		}
		FROM = {
			any_demesne_title = {
				NOT = { lower_tier_than = ROOT }
				temporary = no
			}
			independent = yes
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the cb_faction_independence war against [From.GetBestName]."
		any_attacker = {
			limit = {
				OR = {
					vassal_of = FROM
					liege_before_war = { character = FROM }
				}
			}
			if = {
				limit = {
					OR = {
						real_tier = emperor
						real_tier = king
					}
				}
				FROM = { religion_authority = { modifier = fell_to_major_rebellion years = 60 } }
				religion_authority = { modifier = successful_major_rebellion years = 60 }
				FROM = {
					hidden_tooltip = {
						any_vassal = {
							limit = {
								OR = {
									culture_group = PREV
									religion = terran_imperial
									religion = terran_republican
									religion = terran_federalist
									religion = pilgrim
									religion = orthodox
									religion = solarian
									religion = solar_cult
									religion = imperial_cult
								}
							}
							opinion = { who = PREV modifier = opinion_lost_defensive_war }
						}
					}
				}
			}
			if = {
				limit = {
					OR = {
						real_tier = duke
						real_tier = count
						real_tier = baron
					}
				}
				FROM = { religion_authority = { modifier = fell_to_minor_rebellion years = 10 } }
				religion_authority = { modifier = successful_minor_rebellion years = 10 }
			}
		}
		if = {
			limit = {
				FROM = { independent = yes }
			}
			any_attacker = {
				limit = {
					OR = {
						vassal_of = FROM
						liege_before_war = { character = FROM }
					}
				}
				set_defacto_liege = THIS
				hidden_tooltip = {
					prestige = 100
					any_demesne_title = {
						limit = {
							controls_religion = no
							higher_tier_than = BARON
							FROM = {
								OR = { # If the old liege can use the subjugation CB, give no claims
									NOT = { religion_group = outlaw_group }
									NOT = { culture_group = PREVPREV }
								}
							}
						}
						add_weak_pressed_claim = FROM
					}
				}
			}		
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
			hidden_tooltip = { disband_event_forces = faction_revolters }
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = {
				participation_scaled_prestige = 100
				disband_event_forces = faction_revolters
			}
		}

		FROM = {
			hidden_tooltip = { disband_event_forces = faction_loyalists }
		
			any_demesne_title = { # All titles
				limit = {
					OR = {
						tier = king
						tier = emperor
					}
					NOT = { has_law = centralization_0 }
				}
				if = {
					limit = { has_law = centralization_1 }
					add_law = centralization_0
				}
				if = {
					limit = { has_law = centralization_2 }
					add_law = centralization_1
				}
				if = {
					limit = { has_law = centralization_3 }
					add_law = centralization_2
				}
				if = {
					limit = { has_law = centralization_4 }
					add_law = centralization_3
				}
			}
		}
		
		# Eliminate the Infinite Money Property if present
		hidden_tooltip = { any_attacker = { character_event = { id = maintenance.550 } } }
	}

	on_fail = {
		ROOT = {
			prestige = -50
#			prisoner = FROM
			add_character_modifier = {
				name = faction_independence_ultimatum_timer
				hidden = yes
				duration = 3650
			}
			hidden_tooltip = { disband_event_forces = faction_revolters }
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = -50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = {
				participation_scaled_prestige = -50 
				disband_event_forces = faction_revolters
			}
			add_character_modifier = {
				name = faction_independence_ultimatum_timer
				hidden = yes
				duration = 3650
			}
		}
		FROM = { hidden_tooltip = { disband_event_forces = faction_loyalists } }
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -100
			prisoner = FROM
			add_character_modifier = {
				name = faction_independence_ultimatum_timer
				hidden = yes
				duration = 3650
			}
			hidden_tooltip = { disband_event_forces = faction_revolters }
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = -100
			if = {
				limit = {
					OR = {
						real_tier = emperor
						real_tier = king
					}
				}
				FROM = { religion_authority = { modifier = crushed_major_rebellion years = 60 } }
				religion_authority = { modifier = failed_major_rebellion years = 60 }
				FROM = {
					hidden_tooltip = {
						any_vassal = {
							limit = {
								OR = {
									culture_group = PREV
									religion = terran_imperial
									religion = terran_republican
									religion = terran_federalist
									religion = pilgrim
									religion = orthodox
									religion = solarian
									religion = solar_cult
									religion = imperial_cult
								}
							}
							opinion = { who = PREV modifier = opinion_won_defensive_war }
						}
					}
				}
			}
			if = {
				limit = {
					OR = {
						real_tier = duke
						real_tier = count
						real_tier = baron
					}
				}
				FROM = { religion_authority = { modifier = crushed_minor_rebellion years = 10 } }
				religion_authority = { modifier = failed_minor_rebellion years = 10 }
			}
		}
		
		any_attacker = {
			limit = { 
				NOT = { character = ROOT }
				OR = {
					vassal_of = FROM
					liege_before_war = { character = FROM }
				}
			}
			if = {
				limit = {
					OR = {
						real_tier = emperor
						real_tier = king
					}
				}
				FROM = { religion_authority = { modifier = crushed_major_rebellion years = 60 } }
				religion_authority = { modifier = failed_major_rebellion years = 60 }
				FROM = {
					hidden_tooltip = {
						any_vassal = {
							limit = {
								OR = {
									culture_group = PREV
									religion = terran_imperial
									religion = terran_republican
									religion = terran_federalist
									religion = pilgrim
									religion = orthodox
									religion = solarian
									religion = solar_cult
									religion = imperial_cult
								}
							}
							opinion = { who = PREV modifier = opinion_won_defensive_war }
						}
					}
				}
			}
			if = {
				limit = {
					OR = {
						real_tier = duke
						real_tier = count
						real_tier = baron
					}
				}
				FROM = { religion_authority = { modifier = crushed_minor_rebellion years = 10 } }
				religion_authority = { modifier = failed_minor_rebellion years = 10 }
			}
			prisoner = FROM
			participation_scaled_prestige = -100
			hidden_tooltip = {
				disband_event_forces = faction_revolters
				add_character_modifier = {
					name = faction_independence_ultimatum_timer
					hidden = yes
					duration = 3650
				}
			}
		}
		
		FROM = {
			prestige = 50
			hidden_tooltip = { disband_event_forces = faction_loyalists }
		}
	}

	# on_attacker_leader_death = {
		# hidden_tooltip = { any_defender = { letter_event = { id = 251 } } }

		# end_war = invalid
	# }

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 150
	}

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

# Embargo Merchant Republic CB
embargo_cb = {
	name = CB_NAME_EMBARGO
	war_name = WAR_NAME_EMBARGO
	sprite = 11
	truce_days = 3650
	
	is_permanent = yes
	can_ask_to_join_war = no
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB embargo_cb." }

	can_use = {
		ROOT = {
			independent = yes
			NOT = { has_embargo = FROM }
		}
		FROM = {
			OR = {
				is_merchant_republic = yes
				AND = {
					higher_tier_than = DUKE
					any_realm_lord = { is_merchant_republic = yes }
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			independent = yes
			NOT = { has_embargo = FROM }
		}
		FROM = {
			OR = {
				is_merchant_republic = yes
				AND = {
					higher_tier_than = DUKE
					any_realm_lord = { is_merchant_republic = yes }
				}
			}
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the embargo_cb war against [From.GetBestName]."
		ROOT = {
			embargo = FROM
			if = {
				limit = { NOT = { religion = FROM } }
				piety = 200
			}
		}
		FROM = {
			hidden_tooltip = {
				any_vassal = {
					limit = { is_patrician = yes }
					opinion = { who = PREV modifier = opinion_lost_defensive_war }
				}
			}
		}
	}

	on_fail = {
		if = {
			limit = {
				NOT = {
					any_attacker = {
						NOT = { character = ROOT } 
						is_merchant_republic = yes
					}
				}
			}
			ROOT = { prestige = -100 }
		}
		
		if = {
			limit = {
				any_attacker = {
					NOT = { character = ROOT } 
					is_merchant_republic = yes
				}
			}
			any_attacker = {
				limit = { 
					NOT = { character = ROOT } 
					is_merchant_republic = yes
				}
				prestige = -100
			}
		}
		
		FROM = { prestige = 50 }
	}

	on_reverse_demand = {
		if = {
			limit = {
				NOT = {
					any_attacker = {
						NOT = { character = ROOT } 
						is_merchant_republic = yes
					}
				}
			}
			
			ROOT = {
				prestige = -200
				transfer_scaled_wealth = {
					to = FROM
					value = 4.0
				}
			}
		}
		
		if = {
			limit = {
				any_attacker = {
					NOT = { character = ROOT } 
					is_merchant_republic = yes
				}
			}
			any_attacker = {
				limit = { 
					NOT = { character = ROOT } 
					is_merchant_republic = yes
				}
				prestige = -200
				transfer_scaled_wealth = {
					to = FROM
					value = 4.0
				}
			}
		}
		
		FROM = { prestige = 100 }
		FROM = {
			hidden_tooltip = {
				any_vassal = {
					limit = { is_patrician = yes }
					opinion = { who = PREV modifier = opinion_won_defensive_war }
				}
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 50
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 50
	}
	
	# ai importance placed on this CB: scope is the targeted title, ROOT is the attacking character, FROM is the defending character
	ai_will_do = {
		factor = 1
		modifier = {
			factor = 0
			ROOT = { opinion = { who = FROM value = 25 } }
		}
		modifier = {
			factor = 0.5
			ROOT = { opinion = { who = FROM value = 0 } }
		}		
		modifier = {
			factor = 0.5
			ROOT = { opinion = { who = FROM value = -25 } }
		}			
	}		
}

seize_trade_post = {
	name = CB_NAME_SEIZE_TRADE_POST
	war_name = WAR_NAME_SEIZE_TRADE_POST
	sprite = 1
	truce_days = 1825
	is_permanent = yes
#	check_all_titles = yes
	check_all_trade_posts = yes
	can_ask_to_join_war = no
	
	allow_distant = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB seize_trade_post." }

	can_use = {
		ROOT = {
			OR = {
				is_merchant_republic = yes
				is_patrician = yes
			}
			NOT = { is_liege_or_above = FROM }

			OR = {
				NOT = { same_realm = FROM }
				
				# We cannot overtly attack much weaker Patricians in the same republic
				NOT = { 
					num_of_trade_post_diff = {
						character = FROM
						value = 3
					}
				}
			}
		}
		FROM = {
			OR = {
				is_merchant_republic = yes
				is_patrician = yes
			}
			NOT = { is_liege_or_above = ROOT }
		}
	}

	can_use_title = {
		tier = COUNT
		location = {
			port = yes
		}
		has_trade_post = yes
		trade_post_owner = {
			OR = {
				character = FROM
				is_liege_or_above = FROM
			}
		}
		holder_scope = { NOT = { character = FROM } }
	}

	is_valid = {
		ROOT = {
			OR = {
				is_merchant_republic = yes
				is_patrician = yes
			}
			NOT = { is_liege_or_above = FROM }
		}
		FROM = {
			OR = {
				is_merchant_republic = yes
				is_patrician = yes
			}
			NOT = { is_liege_or_above = ROOT }
		}
	}
	
	is_valid_title = {
		has_trade_post = yes
		trade_post_owner = {
			OR = {
				character = FROM
				is_liege_or_above = FROM
			}
		}
		holder_scope = { NOT = { character = FROM } }
	}

	on_success_title = {
		log = "[Root.GetBestName] won the seize_trade_post war against [From.GetBestName]."
		
		seize_trade_post = ROOT
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_fail = {
		ROOT = { prestige = -50 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 25
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 25 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -100
			transfer_scaled_wealth = {
				to = FROM
				value = 2.0
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 25
	}

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

	# ai importance placed on this CB: scope is the targeted title, ROOT is the attacking character, FROM is the defending character
	ai_will_do = { 
		factor = 1
		modifier = {
			factor = 0.25
			ROOT = { NOT = { same_realm = FROM } }
		}
	}
}

# The Prepared Invasion CB of Norse Heathens
viking_invasion = {
	name = CB_NAME_VIKING_INVASION
	war_name = WAR_NAME_VIKING_INVASION
	sprite = 8
	truce_days = 365
	hostile_against_others = no # Vikings share in the spoils...
	is_permanent = yes
	is_holy_war = yes
	can_ask_to_join_war = yes
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
	apply_short_occ_mod = no # Do not apply the 'recently_conquered' modifier to Holdings
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB viking_invasion." }

	can_use = {
		ROOT = {
			has_opinion_modifier = { who = FROM modifier = preparing_to_invade }
			NOT = { is_liege_or_above = FROM }
		}
	}
	
	can_use_title = { is_valid_viking_invasion_target = FROM } # Checks that FROM holds the right amount of territory in the kingdom
	
	is_valid_title = { FROM = { any_realm_title = { de_jure_liege_or_above = PREVPREV } } }

	on_success = {
		log = "[Root.GetBestName] won the viking_invasion war against [From.GetBestName]."
		ROOT = {
			prestige = 500
			piety = 250
			religion_authority = { modifier = won_viking_invasion }
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 300
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 300 }
		}
		FROM = { prestige = -500 }
	}
	
	on_success_title = {
		custom_tooltip = { 
			text = tribal_invasion_succ_tip
			hidden_tooltip = {
				FROM = {
					random_realm_province = {
						limit = {
							de_jure_liege_or_above = PREVPREV
							OR = {
								NOT = { culture = ROOT }
								NOT = { religion = ROOT }
							}
						}
						culture = ROOT
						religion = ROOT
					}
				}
				ROOT = {
					occupy_minors_of_occupied_settlements = FROM
					gain_all_occupied_titles = FROM
					vassalize_or_take_under_title_destroy_duchies = {
						title = PREV
						enemy = FROM
					}
					
					# Settle the special invasion forces
					disband_event_forces = prepared_invasion
					any_demesne_title = {
						limit = { tier = BARON }
						remove_holding_modifier = recently_conquered
						refill_holding_levy = yes
					}
				}
				
				if = {
					limit = {
						FROM = { is_liege_or_above = ROOT }
					}
					FROM = { imprison = ROOT }
				}
			}
		}
	}

	on_fail = {
		FROM = { prestige = 200 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		ROOT = {
			prestige = -300
			piety = -100
			hidden_tooltip = { disband_event_forces = prepared_invasion }
			religion_authority = { modifier = lost_viking_invasion }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -500
			piety = -250
			transfer_scaled_wealth = {
				to = FROM
				value = 2.0
			}
			hidden_tooltip = { disband_event_forces = prepared_invasion }
			religion_authority = { modifier = lost_viking_invasion }
		}
		FROM = { prestige = 300 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 250
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 250 }
		}
	}

	attacker_ai_victory_worth = {
		factor = 200
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

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

county_conquest = {
	name = CB_NAME_COUNTY_CONQUEST
	war_name = WAR_NAME_COUNTY_CONQUEST
	sprite = 16
	truce_days = 1825
	hostile_against_others = yes
	is_permanent = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	press_claim = yes
	can_ask_to_join_war = no
	
	allow_distant = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB county_conquest." }
	
	can_use = {
		ROOT = {
			OR = {
				religion = terran_imperial
				religion = astrist
				religion = neo_feudal
				religion_group = outlaw_group
			}
			NOT = { same_realm = FROM }
		}
	}

	can_use_title = {
		tier = count
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = {
				is_liege_or_above = FROM
				NOT = { same_realm = ROOT }
			}
		}

		NOT = {
			OR = {
				ROOT = { has_landed_title = PREV }
				holder_scope = { is_liege_or_above = ROOT }
			}
		}
		
		OR = {
			AND = {
				ROOT = { religion_group = outlaw_group }
				FROM = { NOT = { religion_group = outlaw_group } }
			}
			location = {
				any_neighbor_province = {
					owner = {
						OR = {
							character = ROOT
							is_liege_or_above = ROOT
						}
					}
				}
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = {
				is_liege_or_above = FROM
				NOT = { same_realm = ROOT }
			}
		}

		NOT = {
			OR = {
				ROOT = { has_landed_title = PREV }
				holder_scope = { is_liege_or_above = ROOT }
			}
		}
	
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}
	}

	on_success_title = {
		log = "[Root.GetBestName] won the county_conquest war against [From.GetBestName]."
		usurp_title_plus_barony_if_unlanded = ROOT
		
		any_de_jure_vassal_title = { # take all baronies too
			limit = {
				has_holder = yes
				holder_scope = {
					OR = {
						character = FROM
						is_liege_or_above = FROM
						AND = {
							is_liege_or_above = ROOT
							NOT = { culture_group = ROOT }
							NOT = { religion = ROOT }
						}
					}
				}
			}

			usurp_title = ROOT
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
			participation_scaled_piety = 50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 100 
				participation_scaled_piety = 50
			}
		}
		
		ROOT = {
			if = {
				limit = { NOT = { religion = FROM } }
				religion_authority = { modifier = won_county_conquest }
			}
		}
	}

	on_fail_title = {
		ROOT = {
			prestige = -100
			if = {
				limit = { NOT = { religion = FROM } }
				religion_authority = { modifier = lost_county_conquest }
			}
		}
		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
			}
			if = {
				limit = { NOT = { religion = FROM } }
				religion_authority = { modifier = lost_county_conquest }
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
			participation_scaled_piety = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = {
				participation_scaled_prestige = 100 
				participation_scaled_piety = 50
			}
		}
	}

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

dejure_duchy_claim = {
	name = CB_NAME_DEJURECLAIM
	war_name = WAR_NAME_DEJUREDUCHYCLAIM
	sprite = 16
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	press_claim = yes
	can_ask_to_join_war = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB dejure_duchy_claim." }

	can_use_title = {
		tier = duke
		is_tribal_type_title = no
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
		
		OR = {
			kingdom = { holder = ROOT }
			empire = { holder = ROOT }
		}

		NOT = {
			OR = {
				ROOT = { has_landed_title = PREV }
				holder_scope = { is_liege_or_above = ROOT }
			}
		}
		
		FROM = {
			OR = {
				holy_order = no
				NOT = { religion = ROOT }
				NOT = { has_dlc = "Sons of Abraham" }
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	on_success_title = {
		log = "[Root.GetBestName] won the dejure_duchy_claim war against [From.GetBestName]."
		if = {
			limit = {
				holder_scope = {
					tier = duke
					OR = {
						is_patrician = no
						is_merchant_republic = yes
					}
					NOT = { num_of_duke_titles = 2 }
				}
			}

			holder_scope = { set_defacto_liege = ROOT }
		}

		if = {
			limit = {
				holder_scope = {
					OR = {
						higher_tier_than = duke
						num_of_duke_titles = 2
						AND = {
							is_patrician = yes
							is_merchant_republic = no
						}
					}
				}
			}

			usurp_title_plus_barony_if_unlanded = ROOT
			any_de_jure_vassal_title = { # take all counties 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 = ROOT
				any_de_jure_vassal_title = { # And all the baronies
					limit = {
						has_holder = yes
						NOT = { de_facto_liege = PREVPREV }
						holder_scope = {
							OR = {
								character = FROM
								is_liege_or_above = FROM
							}
						}
					}
					usurp_title_plus_barony_if_unlanded = ROOT
				}
			}
		}
		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
		# Reclaim Sol at all costs!
		modifier = {
			factor = 5
			title = d_sol
			ROOT = {
				OR = {
					religion = terran_federalist
					religion = terran_republican
					religion = terran_imperial
					religion = pilgrim
					religion = orthodox
					religion = solarian
					religion = solar_cultist
				}
				NOT = { trait = pragmatic }
			}
		}
		modifier = {
			factor = 5
			title = d_sol
			ROOT = {
				OR = {
					religion = terran_federalist
					religion = terran_republican
					religion = terran_imperial
					religion = pilgrim
					religion = orthodox
					religion = solarian
					religion = solar_cultist
				}
				trait = radical
			}
		}
		# Prefer border duchies
		modifier = {
			factor = 0.2
			NOT = {
				any_direct_de_jure_vassal_title = {
					OR = {
						holder_scope = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							any_neighbor_province = {
								owner = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

dejure_county_claim = {
	name = CB_NAME_DEJURECLAIM
	war_name = WAR_NAME_DEJURECLAIM
	sprite = 16
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	press_claim = yes
	can_ask_to_join_war = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB dejure_county_claim." }

	can_use_title = {
		tier = count
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
		
		OR = {
			kingdom = { holder = ROOT }
			empire = { holder = ROOT }
			dejure_liege_title = { holder = ROOT }
		}

		NOT = {
			OR = {
				ROOT = { has_landed_title = PREV }
				holder_scope = { is_liege_or_above = ROOT }
			}
		}
		
		FROM = {
			OR = {
				holy_order = no
				NOT = { religion = ROOT }
				NOT = { has_dlc = "Sons of Abraham" }
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	on_success_title = {
		log = "[Root.GetBestName] won the dejure_county_claim war against [From.GetBestName]."
		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 = ROOT
			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 = ROOT
			}
		}
		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 = 1
		# Reclaim Sol at all costs!
		modifier = {
			factor = 5
			title = c_sol
			ROOT = {
				OR = {
					religion = terran_federalist
					religion = terran_republican
					religion = terran_imperial
					religion = pilgrim
					religion = orthodox
					religion = solarian
					religion = solar_cultist
				}
				NOT = { trait = pragmatic }
			}
		}
		modifier = {
			factor = 5
			title = c_sol
			ROOT = {
				OR = {
					religion = terran_federalist
					religion = terran_republican
					religion = terran_imperial
					religion = pilgrim
					religion = orthodox
					religion = solarian
					religion = solar_cultist
				}
				trait = radical
			}
		}
		# Prefer border counties
		modifier = {
			factor = 0.2
			NOT = { location = { any_neighbor_province = { any_realm_lord = { character = ROOT } } } }
		}
		# Don't attack counties when you could attack a duchy
		modifier = {
			factor = 0
			duchy = {
				OR = {
					FROM = { has_landed_title = PREV }
					holder_scope = { is_liege_or_above = FROM }
				}
				
				OR = {
					kingdom = { holder = ROOT }
					empire = { holder = ROOT }
				}

				NOT = {
					OR = {
						ROOT = { has_landed_title = PREV }
						holder_scope = { is_liege_or_above = ROOT }
					}
				}
				
				FROM = {
					OR = {
						holy_order = no
						NOT = { religion = ROOT }
						NOT = { has_dlc = "Sons of Abraham" }
					}
				}
			}
		}
	}
}

dejure_barony_claim = {
	name = CB_NAME_DEJUREBARONYCLAIM
	war_name = WAR_NAME_DEJUREBARONYCLAIM
	sprite = 16
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	press_claim = yes
	can_ask_to_join_war = no
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB dejure_barony_claim." }

	can_use_title = {
		tier = baron
		dejure_liege_title = {
			AND = {
				has_holder = yes
				ROOT = { has_landed_title = PREV }
			}
		}

		NOT = {
			OR = {
				ROOT = { has_landed_title = PREV }
				holder_scope = { is_liege_or_above = ROOT }
			}
		}

		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}

		NOT = { holder_scope = { liege = { ROOT = { liege = { character = PREVPREV } } } } }
		
		FROM = {
			OR = {
				holy_order = no
				NOT = { religion = ROOT }
				NOT = { has_dlc = "Sons of Abraham" }
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	on_success_title = {
		log = "[Root.GetBestName] won the dejure_barony_claim war against [From.GetBestName]."
		usurp_title_plus_barony_if_unlanded = ROOT
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

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

	on_reverse_demand = {
		ROOT = {
			prestige = -100
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 75
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 75
	}
	
	ai_will_do = {
		factor = 1
		modifier = {
			factor = 0.5
		}
		# Reclaim Earth at all costs!
		modifier = {
			factor = 5
			title = b_earth
			ROOT = {
				OR = {
					religion = terran_federalist
					religion = terran_republican
					religion = terran_imperial
					religion = pilgrim
					religion = orthodox
					religion = solarian
					religion = solar_cultist
				}
				NOT = { trait = pragmatic }
			}
		}
		modifier = {
			factor = 5
			title = b_earth
			ROOT = {
				OR = {
					religion = terran_federalist
					religion = terran_republican
					religion = terran_imperial
					religion = pilgrim
					religion = orthodox
					religion = solarian
					religion = solar_cultist
				}
				trait = radical
			}
		}
		# Don't attack baronies when you could attack a duchy or county
		modifier = {
			factor = 0
			duchy = {
				OR = {
					FROM = { has_landed_title = PREV }
					holder_scope = { is_liege_or_above = FROM }
				}
				
				OR = {
					kingdom = { holder = ROOT }
					empire = { holder = ROOT }
				}

				NOT = {
					OR = {
						ROOT = { has_landed_title = PREV }
						holder_scope = { is_liege_or_above = ROOT }
					}
				}
				
				FROM = {
					OR = {
						holy_order = no
						NOT = { religion = ROOT }
						NOT = { has_dlc = "Sons of Abraham" }
					}
				}
			}
		}
		modifier = {
			factor = 0
			county = {
				OR = {
					FROM = { has_landed_title = PREV }
					holder_scope = { is_liege_or_above = FROM }
				}
				
				OR = {
					kingdom = { holder = ROOT }
					empire = { holder = ROOT }
					dejure_liege_title = { holder = ROOT }
				}

				NOT = {
					OR = {
						ROOT = { has_landed_title = PREV }
						holder_scope = { is_liege_or_above = ROOT }
					}
				}
				
				FROM = {
					OR = {
						holy_order = no
						NOT = { religion = ROOT }
						NOT = { has_dlc = "Sons of Abraham" }
					}
				}
			}
		}
	}
}

other_dejure_barony_claim = {
	name = CB_NAME_DEJUREBARONYCLAIM
	war_name = WAR_NAME_OTHER_DEJUREBARONYCLAIM
	sprite = 16
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	other_de_jure_claim = yes # Optimization for de jure claims of vassals
	press_claim = yes
	can_ask_to_join_war = no
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB other_dejure_barony_claim." }

	can_use = { NOT = { ROOT = { character = PREV } } }

	can_use_title = {
		tier = baron

		dejure_liege_title = {
			AND = {
				has_holder = yes
				ROOT = { has_landed_title = PREV }
			}
		}

		NOT = {
			OR = {
				ROOT = { has_landed_title = PREV }
				holder_scope = { is_liege_or_above = ROOT }
			}
		}

		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}

		NOT = { holder_scope = { liege = { ROOT = { liege = { character = PREVPREV } } } } }
		
		FROM = {
			OR = {
				holy_order = no
				NOT = { religion = ROOT }
				NOT = { has_dlc = "Sons of Abraham" }
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the other_dejure_barony_claim war against [From.GetBestName]."
		ROOT = {
			opinion = { modifier = pressed_my_claim who = PREV }
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_success_title = { usurp_title_plus_barony_if_unlanded = ROOT }

	on_fail = {
		prestige = -50
		ROOT = { prestige = -50 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 25
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 25 }
		}
	}

	on_reverse_demand = {
		prestige = -50
		transfer_scaled_wealth = {
			to = FROM
			value = 4.0
		}
		ROOT = { prestige = -50 }
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

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

other_dejure_county_claim = {
	name = CB_NAME_DEJURECLAIM
	war_name = WAR_NAME_OTHER_DEJURECLAIM
	sprite = 16
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	other_de_jure_claim = yes # Optimization for de jure claims of vassals
	press_claim = yes
	can_ask_to_join_war = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB other_dejure_county_claim." }

	can_use = {
		NOT = { ROOT = { character = PREV } }
		
		FROM = {
			OR = {
				holy_order = no
				NOT = { religion = ROOT }
				NOT = { has_dlc = "Sons of Abraham" }
			}
		}
	}

	can_use_title = {
		tier = count
		dejure_liege_title = {
			AND = {
				has_holder = yes
				ROOT = { has_landed_title = PREV }
			}
		}

		NOT = {
			OR = {
				ROOT = { has_landed_title = PREV }
				holder_scope = { is_liege_or_above = ROOT }
			}
		}

		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the other_dejure_county_claim war against [From.GetBestName]."
		ROOT = { opinion = { modifier = pressed_my_claim  who = PREV } }
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	on_success_title = {
		if = {
			limit = {
				holder_scope = {
					tier = count
					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
					}
				}
			}

			usurp_title_plus_barony_if_unlanded = ROOT
			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 = ROOT
			}
		}
	}

	on_fail = {
		prestige = -50
		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 = {
		prestige = -100
		transfer_scaled_wealth = {
			to = FROM
			value = 4.0
		}
		ROOT = { prestige = -200 }
		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
	}
}

other_dejure_duchy_claim = {
	name = CB_NAME_DEJURECLAIM
	war_name = WAR_NAME_OTHER_DEJUREDUCHYCLAIM
	sprite = 16
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	other_de_jure_claim = yes # Optimization for de jure claims of vassals
	press_claim = yes
	can_ask_to_join_war = yes
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB other_dejure_duchy_claim." }

	can_use = {
		NOT = { ROOT = { character = PREV } }
		
		FROM = {
			OR = {
				holy_order = no
				NOT = { religion = ROOT }
				NOT = { has_dlc = "Sons of Abraham" }
			}
		}
	}

	can_use_title = {
		tier = duke
		is_tribal_type_title = no
		dejure_liege_title = {
			AND = {
				has_holder = yes
				ROOT = { has_landed_title = PREV }
			}
		}

		NOT = {
			OR = {
				ROOT = { has_landed_title = PREV }
				holder_scope = { is_liege_or_above = ROOT }
			}
		}

		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	is_valid_title = {
		OR = {
			FROM = { has_landed_title = PREV }
			holder_scope = { is_liege_or_above = FROM }
		}
	}

	on_success = {
		log = "[Root.GetBestName] won the other_dejure_county_claim war against [From.GetBestName]."
		ROOT = { opinion = { modifier = pressed_my_claim who = PREV } }
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	on_success_title = {
		if = {
			limit = {
				holder_scope = {
					tier = duke
					NOT = { num_of_duke_titles = 2 }
				}
			}

			holder_scope = { set_defacto_liege = ROOT }
		}

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

			usurp_title_plus_barony_if_unlanded = ROOT
			any_de_jure_vassal_title = { # take all counties 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 = ROOT
				any_de_jure_vassal_title = { # and all baronies, too
					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 = ROOT
				}
			}
		}
	}

	on_fail = {
		prestige = -50
		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 = {
		prestige = -100
		transfer_scaled_wealth = {
			to = FROM
			value = 4.0
		}
		ROOT = { prestige = -200 }
		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
	}
}

duchy_adventure = {
	name = CB_NAME_DUCHY_ADVENTURE
	war_name = WAR_DUCHY_ADVENTURE
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	hostile_against_others = yes
	check_de_jure_tier = DUKE
	
	on_add = { log = "[Root.GetBestName] declared war on [From.GetBestName] using the CB duchy_adventure." }

	can_use = {
		ROOT = { has_character_flag = duchy_adventurer }
	}

	is_valid = {
		always = yes
	}
	
	on_success = {
		log = "[Root.GetBestName] won the duchy_adventure war against [From.GetBestName]."
		ROOT = { 
			prestige = 250
			hidden_tooltip = {
				clr_character_flag = duchy_adventurer
				give_nickname = nick_the_conqueror
			}
		}
		FROM = {
			prestige = -250 
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = tribal_invasion_succ_tip
			hidden_tooltip = {
				ROOT = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
					}
				}
			}
		}
	}

	on_fail = {
		FROM = {
			prestige = 100
			hidden_tooltip = {
				opinion = {
					modifier = opinion_rebel_traitor 
					who = ROOT
					months = 1200
				}
			}
		}
		ROOT = {
			imprison = FROM 
			hidden_tooltip = {
				disband_event_forces = yes
				clr_character_flag = duchy_adventurer
			}
		}
	
		ROOT = { prestige = -100 }
	}

	on_reverse_demand = {
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		
		FROM = {
			prestige = 200
		}
		
		ROOT = {
			imprison = FROM
			prestige = -200
			hidden_tooltip = {
				disband_event_forces = yes
				clr_character_flag = duchy_adventurer
			}
		}
	}
	
	on_attacker_leader_death = {
		ROOT = {
			hidden_tooltip = {
				disband_event_forces = yes
				clr_character_flag = duchy_adventurer
			}
		}
		end_war = invalid
	}

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