shattered_world_county_conquest = {
	name = CB_NAME_SHATTERED_COUNTY_CONQUEST
	war_name = WAR_NAME_SHATTERED_COUNTY_CONQUEST
	sprite = 27
	truce_days = 1825
	hostile_against_others = yes
	full_hostility = 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
	can_ask_to_join_war = no
	allowed_to_target_tributaries = no
	
	infamy_modifier = 2
	
	sort_priority = 795
	
	can_use_gui = {
		conditional_tooltip = {
			trigger = {
				has_alternate_start_setting = {
					setting = shattered_cbs
					option = on_limited
				}
			}
			NOT = {
				total_years_played = 25
			}
		}
		conditional_tooltip = {
			trigger = {
				has_alternate_start_setting = {
					setting = shattered_cbs
					option = on_long
				}
			}
			NOT = {
				total_years_played = 100
			}
		}
	}
	
	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		ROOT = {
			show_scope_change = no
			if = {
				limit = { defender = { is_offmap_governor = offmap_china } }
				attacker = {  
					sound_effect = china_angered_emperor
					detract_grace_super_huge_effect = yes
				}
			}
		}
	}
	
	can_use = {
		is_shattered_world = yes
		ROOT = { NOT = { government = dragon_tribal_gov } }
		NOT = {
			has_alternate_start_setting = {
				setting = shattered_cbs
				option = off
			}
		}
		conditional_tooltip = {
			trigger = {
				has_alternate_start_setting = {
					setting = shattered_cbs
					option = on_limited
				}
			}
			NOT = {
				total_years_played = 25
			}
		}
		conditional_tooltip = {
			trigger = {
				has_alternate_start_setting = {
					setting = shattered_cbs
					option = on_long
				}
			}
			NOT = {
				total_years_played = 100
			}
		}
		ROOT = {
			NOT = { is_liege_or_above = FROM }
			mercenary = no
		}
	}

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

		NOR = {
			ROOT = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = ROOT
			}
		}
		
		location = {
			#any_neighbor_province = {
			#	owner = {
			#		OR = {
			#			character = ROOT
			#			is_liege_or_above = ROOT
			#		}
			#	}
			#}
			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
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

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

	on_success_title = {
		if = {
			limit = {
				holder_scope = {
					tier = count
					NOT = { num_of_count_titles = 2 }
					lower_tier_than = ROOT
				}
			}

			holder_scope = {
				set_defacto_liege = ROOT
			}
		}

		if = {
			limit = {
				holder_scope = {
					OR = {
						higher_tier_than = count
						num_of_count_titles = 2
						NOT = { lower_tier_than = ROOT }
					}
				}
			}

			usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
			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 = {
						is_liege_or_above = FROM
					}
				}

				usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
			}
		}
		
		add_pressed_claim = FROM
		
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

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

	on_reverse_demand = {
		ROOT = {
			prestige = -100
			transfer_scaled_wealth = {
				to = FROM
				value = 2.0
			}
		}
		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
		modifier = {
			factor = 0.1
			ROOT = {
				independent = no
				same_liege = FROM
			}
		}
	}
}

#shattered_world_duchy_conquest = {
#	name = CB_NAME_SHATTERED_DUCHY_CONQUEST
#	war_name = WAR_NAME_SHATTERED_DUCHY_CONQUEST
#	sprite = 8
#	truce_days = 3650
#	is_permanent = yes
#	check_de_jure_tier = DUKE # this scans all dejure duchies for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
#	allowed_to_target_tributaries = no
#	
#	infamy_modifier = 2
#	
#	can_use_gui = {
#		conditional_tooltip = {
#			trigger = {
#				has_alternate_start_setting = {
#					setting = shattered_cbs
#					option = on_limited
#				}
#			}
#			NOT = {
#				total_years_played = 25
#			}
#		}
#		conditional_tooltip = {
#			trigger = {
#				has_alternate_start_setting = {
#					setting = shattered_cbs
#					option = on_long
#				}
#			}
#			NOT = {
#				total_years_played = 100
#			}
#		}
#		ROOT = {
#			show_scope_change = no
#			prestige = 500
#			NOR = {
#				higher_tier_than = DUKE
#				num_of_count_titles = 20
#			}
#		}
#	}
#	
#	can_use = {
#		is_shattered_world = yes
#		NOT = {
#			has_alternate_start_setting = {
#				setting = shattered_cbs
#				option = off
#			}
#		}
#		conditional_tooltip = {
#			trigger = {
#				has_alternate_start_setting = {
#					setting = shattered_cbs
#					option = on_limited
#				}
#			}
#			NOT = {
#				total_years_played = 25
#			}
#		}
#		conditional_tooltip = {
#			trigger = {
#				has_alternate_start_setting = {
#					setting = shattered_cbs
#					option = on_long
#				}
#			}
#			NOT = {
#				total_years_played = 100
#			}
#		}
#		ROOT = {
#			NOT = { is_liege_or_above = FROM }
#			mercenary = no
#		}
#	}
#	
#	can_use_title = {
#		# The attacker needs at least one county in the target kingdom, or a border, or be only two sea zones away from one of your counties
#		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
#							}
#						}
#					}
#				}
#			}
#		}
#		
#		any_de_jure_vassal_title = { # Can only liberate Duchies that are either outside of the Steppe region, or contains a Castle/City/Tribe
#			tier = COUNT
#			OR = {
#				holder_scope = {
#					character = FROM
#				}
#				holder_scope = {
#					any_liege = {
#						character = FROM
#					}
#				}
#			}
#			OR = {
#				location = {
#					NOT = {
#						region = world_steppe
#					}
#				}
#				location = {
#					any_province_holding = {
#						OR = {
#							holding_type = city
#							holding_type = castle
#							holding_type = tribal
#						}
#					}
#				}
#			}
#		}
#	}
#
#	is_valid = {
#		ROOT = {
#			NOT = { same_realm = FROM }
#			mercenary = no
#		}
#	}
#
#	on_add = {
#		ROOT = {
#			show_scope_change = no
#			prestige = -500
#		}
#		if = {
#			limit = { defender = { is_offmap_governor = offmap_china } }
#			attacker = {  
#				sound_effect = china_angered_emperor
#				detract_grace_super_huge_effect = yes 
#			}
#		}
#	}
#	
#	on_success = {
#		any_attacker = {
#			limit = { NOT = { character = ROOT } }
#			hidden_tooltip = { 
#				participation_scaled_prestige = 100
#			}
#		}
#		
#		FROM = { prestige = -100 }
#	}
#
#	on_success_title = {
#		ROOT = {
#			vassalize_or_take_under_title = {
#				title = PREV
#				enemy = FROM
#				anti_nomad = yes
#				type = invasion
#			}
#		}
#	}
#
#	on_fail = {
#		ROOT = { 
#			prestige = -200
#		}
#	}
#
#	on_reverse_demand = {
#		ROOT = {
#			transfer_scaled_wealth = {
#				to = FROM
#				value = 4.0
#			}
#			prestige = -200
#		}
#		FROM = {
#			participation_scaled_prestige = 300
#		}
#		any_defender = {
#			limit = { NOT = { character = FROM } }
#			hidden_tooltip = { 
#				participation_scaled_prestige = 300
#			}
#		}
#	}
#
#	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
#			ROOT = {
#				NOT = {
#					is_tribal = yes
#				}
#			}
#			NOT = {
#				any_direct_de_jure_vassal_title = {
#					any_direct_de_jure_vassal_title = {
#						OR = {
#							holding_type = castle
#							holding_type = city
#						}
#					}
#				}
#			}
#		}
#		modifier = {
#			factor = 0
#			ROOT = {
#				is_tribal = yes
#			}
#			NOT = {
#				any_direct_de_jure_vassal_title = {
#					any_direct_de_jure_vassal_title = {
#						OR = {
#							holding_type = castle
#							holding_type = city
#							holding_type = tribal
#						}
#					}
#				}
#			}
#		}
#	}
#}


shattered_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 = no
	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
	
	sort_priority = 1100
	
	can_use = {
		ROOT = { NOT = { government = dragon_tribal_gov } }
		ROOT = {
			has_character_flag = great_conqueror
		}
		
		ROOT = {
			NOT = { is_liege_or_above = FROM }
			mercenary = no
		}
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target kingdom, or a border
		any_direct_de_jure_vassal_title = {
			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
								}
							}
						}
					}
				}
			}
		}
	}
	
	is_valid = {
		always = yes
	}
	
	is_valid_title = {
		FROM = {
			any_realm_title = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	on_success = {
		ROOT = {
			prestige = 200
			
			hidden_tooltip = {
				occupy_minors_of_occupied_settlements = FROM
				gain_all_occupied_titles = { who = FROM type = invasion }
				
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_magnificent }
						10 = { give_nickname = nick_the_glorious }
						10 = { give_nickname = nick_the_conqueror }
					}
				}
			}
			participation_scaled_prestige = 200
			
			if = {
				limit = {
					uses_decadence = yes
					FROM = { NOT = { uses_decadence = yes } }
				}
				participation_scaled_decadence = -20
			}
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 200 
				if = {
					limit = {
						uses_decadence = yes
						FROM = { NOT = { uses_decadence = yes } }
					}
					participation_scaled_decadence = -20
				}
			}
		}
		FROM = {
			prestige = -200
		}
	}
	
	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
						type = invasion
					}
				}
			}
		}
	}

	on_fail = {
		FROM = {
			prestige = 100
		}
		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 } }
			}
			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
			}
			decadence = 10
		}
		FROM = {
			prestige = 200
			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 } }
			}
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
	}

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

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