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
		}
	}
	
	can_use = {
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }

		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 = {
		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_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 = {
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		
		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 }
	}

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