# AlwaysConquest mod - conquest_invasion CB
# Allows independent rulers of any rank to declare conquest on neighboring counties.
# AI is blocked from using this CB.
# Multiplayer safe: no RNG outside hidden_tooltips, deterministic scoping throughout.

conquest_invasion = {
	name = CB_NAME_ALWAYS_CONQUEST
	war_name = WAR_NAME_CONQUEST
	sprite = 8
	truce_days = 2922
	hostile_against_others = yes
	is_permanent = yes
	is_holy_war = no
	can_ask_to_join_war = yes

	# COUNT (not COUNTY) is the correct CK2 tier keyword.
	# This makes the declare-war menu list each county as a separate entry.
	check_de_jure_tier = COUNT

	allowed_to_target_tributaries = no
	allowed_to_target_suzerains = no

	can_use_gui = {
		ROOT = {
			prestige = 400
		}
	}

	on_add = {
		ROOT = { prestige = -400 }
	}

	can_use = {
		ROOT = {
			ai = no
			independent = yes
			mercenary = no
			NOT = { same_realm = FROM }
			NOT = { is_liege_or_above = FROM }
		}
	}

	can_use_title = {
		# tier = COUNT required here to match check_de_jure_tier = COUNT above.
		tier = COUNT
		# County must not already be in ROOT's realm.
		NOT = { holder_scope = { same_realm = ROOT } }
		# County capital must border a province owned by ROOT or a subject of ROOT.
		# same_realm works for all government types (feudal, tribal, nomadic, republic).
		location = {
			any_neighbor_province = {
				owner = { same_realm = ROOT }
			}
		}
	}

	is_valid = {
	}

	is_valid_title = {
		holder_scope = {
			same_realm = FROM
		}
	}

	on_success = {
		ROOT = {
			prestige = 100
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = {
				participation_scaled_prestige = 100
			}
		}
		FROM = {
			prestige = -250
		}
	}

	on_success_title = {
		custom_tooltip = {
			text = other_invasion_succ_tip
			hidden_tooltip = {
				# PREV in on_success_title scope is exactly the war-goal county.
				# gain_title transfers only that one county — nothing else.
				ROOT = { gain_title = PREV }
				if = {
					limit = { ROOT = { has_nickname = no } }
					random_list = {
						10 = { ROOT = { give_nickname = nick_the_conqueror } }
					}
				}
			}
		}
	}

	on_fail = {
		FROM = {
			prestige = 300
			if = {
				limit = {
					has_dlc = "Legacy of Rome"
					OR = {
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
					religion_group = christian
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
				}
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		ROOT = {
			prestige = -500
			# War indemnity: roughly 2 months of ROOT's income paid to the defender.
			transfer_scaled_wealth = {
				to = FROM
				value = 2.0
			}
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -500
			piety = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 40.0
			}
		}
		FROM = {
			prestige = 500
			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 } }
			}
			if = {
				limit = { has_nickname = no }
				random_list = {
					10 = { give_nickname = nick_the_holy }
					10 = { give_nickname = nick_the_glorious }
					10 = { give_nickname = nick_the_lionheart }
					10 = { give_nickname = nick_the_great }
					10 = { give_nickname = nick_the_hammer }
					10 = { give_nickname = nick_the_magnificent }
					10 = { give_nickname = nick_the_avenger }
				}
			}
		}
		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 = 100
	}

	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1
	}

	defender_ai_defeat_worth = {
		factor = 150
	}

	ai_will_do = {
		factor = 0
		modifier = {
			factor = 0
		}
	}
}
