
# ishtarian county conquest
ishtarian_county_conquest = {
	name = CB_NAME_COUNTY_CONQUEST
	war_name = WAR_NAME_COUNTY_CONQUEST
	sprite = 22
	truce_days = 1095	# 3 years
	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
	can_ask_to_join_war = no
	
	allow_distant = yes
	allowed_to_target_tributaries = no
	
	sort_priority = 700
	
	can_use = {
		ROOT = {
			mercenary = no
		}
		OR = {
			ROOT = {
				is_nomadic = yes
				NOT = { same_realm = FROM }
				FROM = {
					OR = {
						is_nomadic = yes
						is_tribal = yes
					}
				}
			}
			AND = {
				ROOT = {
					religion_group = ishtarian_group
					NOT = { same_realm = FROM }
				}
				FROM = {
					NOT = { religion = ROOT }
				}
			}
			ROOT = {		# anunnaki can attack fellow anunnaki 
				religion = anunnaki
			}
		}
	}

	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 = {
				OR = {
					ROOT = { religion = norse_pagan }
					ROOT = { religion = norse_pagan_reformed }
				}
				location = {
					port = yes
				}
				has_global_flag = viking_age_started
			}
			location = {
				any_neighbor_province = {
					owner = {
						OR = {
							character = ROOT
							is_liege_or_above = ROOT
						}
					}
				}
			}
		}
	}

	is_valid_title = {
		OR = {
			ROOT = {
				is_nomadic = yes
			}
			AND = {
				ROOT = {
					religion_group = ishtarian_group
					NOT = { same_realm = FROM }
				}
				FROM = {
					NOT = { religion = ROOT }
				}
			}
			ROOT = {		# anunnaki can attack fellow anunnaki 
				religion = anunnaki
			}
		}
	
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}
	}

	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_title = { #winning the war
		usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
		
		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 = ROOT }
							NOT = { religion = ROOT }
						}
					}
				}
			}
			show_scope_change = no
			usurp_title = ROOT
		}
		
		ROOT = {
			show_scope_change = no
			participation_scaled_prestige = 100
			participation_scaled_piety = 50
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 100 
				participation_scaled_piety = 50
			}
		}
		
		if = {
			limit = {
				NOT = { FROM = { religion = ROOT } }
			}
			ROOT = {
				show_scope_change = no
				religion_authority = {
					modifier = won_county_conquest
				}
			}
		}

		#To handle Warrior Lodge mission "Wage War" completion...
		attacker = { save_event_target_as = attacker_target }
		defender = { save_event_target_as = defender_target }

		if = { 
			limit = {
				event_target:attacker_target = { has_quest = quest_warrior_lodge_war }
				is_quest_target_of = event_target:attacker_target
			}
			event_target:attacker_target = {
				show_scope_change = no
				tooltip = { clr_quest = quest_warrior_lodge_war }
				set_character_flag = won_war@event_target:defender_target
				#character_event = { id = HF.10514 days = 3 } #Sent from on_action instead
			}
		}
	}

	on_fail_title = { #white peace
		ROOT = {
			show_scope_change = no
			prestige = -100
		}
		
		if = {
			limit = {
				NOT = { FROM = { religion = ROOT } }
			}
			ROOT = {
				show_scope_change = no
				religion_authority = {
					modifier = lost_county_conquest
				}
			}
		}
	
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}

		#To handle Warrior Lodge mission "Wage War" completion...
		attacker = { save_event_target_as = attacker_target }
		defender = { save_event_target_as = defender_target }

		if = { 
			limit = {
				event_target:attacker_target = { has_quest = quest_warrior_lodge_war }
				is_quest_target_of = event_target:attacker_target
			}
			event_target:attacker_target = {
				show_scope_change = no
				tooltip = { clr_quest = quest_warrior_lodge_war }
				set_character_flag = white_peace@event_target:defender_target
				#character_event = { id = HF.10514 days = 3 } #Sent from on_action instead
			}
		}
	}

	on_reverse_demand = { #losing the war
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		
		if = {
			limit = {
				NOT = { FROM = { religion = ROOT } }
			}
			ROOT = {
				show_scope_change = no
				religion_authority = {
					modifier = lost_county_conquest
				}
			}
		}
		
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 100
			participation_scaled_piety = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = {
				participation_scaled_prestige = 100 
				participation_scaled_piety = 50
			}
		}
	}
	on_reverse_demand_title = {
		#To handle Warrior Lodge mission "Wage War" completion...
		attacker = { save_event_target_as = attacker_target }
		defender = { save_event_target_as = defender_target }

		if = { 
			limit = {
				event_target:attacker_target = { has_quest = quest_warrior_lodge_war }
				is_quest_target_of = event_target:attacker_target
			}
			event_target:attacker_target = {
				show_scope_change = no
				tooltip = { clr_quest = quest_warrior_lodge_war }
				set_character_flag = lost_war@event_target:defender_target
				#character_event = { id = HF.10514 days = 3 } #Sent from on_action instead
			}
		}
	}

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


# used for the Ishtar bloodline 
ishtarian_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 # 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
	
	allowed_to_target_tributaries = no
	
	sort_priority = 2000

	can_use_gui = {
		ROOT = {
			prestige = 500
		}
		check_if_crusader_trigger = yes
	}
	
	on_add = {
		ROOT = { show_scope_change = no prestige = -500 }
		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 
			}
		}
		if = {
			limit = { 
				attacker = { 
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_great_conquerors
					} 
				} 
			}
			attacker = {  
				set_character_flag = flag_declared_bloodline_invasion
			}
		}
	}

	can_use_title = {
		ROOT = {
			OR = {
				ai = yes
				multiplayer = no
				NOT = {
					has_game_rule = {
						name = multiplayer_invasions
						value = off
					}
				}
			}
			is_nomadic = no
			AND = {
				has_character_modifier = the_ishtar_modifier		# unique to single character 
				any_owned_bloodline = {
					has_bloodline_flag = ishtar_bloodline
				}
			}
		}
		
		ROOT = {
			NOT = { same_realm = FROM }
		}
		
		OR = { # This ensures that the AI doesn't declare this type of war against someone who only holds a few counties within the targeted title...
			ROOT = {
				ai = no
			}
			ROOT = {
				OR = {
					has_landed_title = e_mongol_empire
					has_landed_title = e_mexikha
				}
			}
			FROM = {
				num_of_realm_counties = {
					value = 3
					title = PREV
				}
			}
		}
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_success = {
		ROOT = {
			show_scope_change = no
			prestige = 200
			participation_scaled_prestige = 200
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
		FROM = {
			show_scope_change = no
			prestige = -200
		}
		hidden_tooltip = {
			ROOT = {
				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_victorious }
						10 = { give_nickname = nick_the_conqueror }
						10 = { give_nickname = nick_the_brave }
						10 = { give_nickname = nick_the_dragon }
						10 = { give_nickname = nick_the_terrible }
					}
				}
			}
		}
	}
	
	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 = {
			show_scope_change = no
			prestige = 100
			
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_avenger }
						10 = { give_nickname = nick_the_lion }
						10 = { give_nickname = nick_the_bold }
					}
				}
			}
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		ROOT = {
			show_scope_change = no
			prestige = -200
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			show_scope_change = no
			prestige = 200
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					random_list = {
						10 = { give_nickname = nick_the_great }
						10 = { give_nickname = nick_the_hammer }
						10 = { give_nickname = nick_the_avenger }
						10 = { give_nickname = nick_the_lion }
						10 = { give_nickname = nick_the_bold }
					}
				}
			}
			
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
	}

	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
		
		modifier = {
			factor = 0.9 # Prefer using CB's without on_add costs
		}
		
		# Try to guide the Hordes in the right direction
		modifier = {
			factor = 0.1
			ROOT = {
				OR = {
					dynasty = 613 # Seljuks
					dynasty = 800 # Timurids
					primary_title = { title = e_il-khanate }
				}
			}
			OR = {
				empire = {
					NOT = {
						OR = {
							title = e_persia
							title = e_byzantium
							title = e_arabia
						}
					}
				}
				FROM = {
					primary_title = { title = e_golden_horde }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				primary_title = { title = e_golden_horde }
			}
			OR = {
				empire = {
					OR = {
						title = e_persia
						title = e_byzantium
						title = e_arabia
					}
				}
				FROM = {
					primary_title = { title = e_il-khanate }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				culture = hungarian
				primary_title = {
					OR = {
						title = k_hungary
						title = e_carpathia
					}
				}
			}
			empire = {
				OR = {
					title = e_tartaria
					title = e_russia
				}
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				has_character_flag = is_temujin
				has_landed_title = e_mongol_empire
				demesne_size = 1
			}
			FROM = {
				has_landed_title = e_china_west_governor
			}
		}
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_nomadic = no
				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
			FROM = {
				is_nomadic = yes
			}
			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
						}
					}
				}
			}
		}
	}
}
















