# Settlement decisions are possible vs _all_ settlements and are shown in the Settlement Diplomacy View, not the Intrigue View. The taker is in the FROM scope.
#
# filter = [capital/owned/vassal_owned/sub_realm_owned/realm_owned/dynasty_owned/all]
# ai_target_filter = [capital/owned/vassal_owned/sub_realm_owned/realm_owned/dynasty_owned/all] (which settlements for which the AI evaluates the decision.)
#	owned: all settlements owned by the AI
#	vassal_owned: all settlements owned by direct vassal rulers of the AI's employer
#	sub_realm_owned: all settlements below the AI's employer
#	realm_owned: all settlements in the same top realm as the AI
#	dynasty_owned: all settlements owned by members of the same dynasty
#	all: all settlements (Avoid if possible. VERY CPU-HEAVY!)
#	

settlement_decisions = {

	expd_pill_instant_full_pillage_settlement = {
		# This is a shortcut for the exploit where you pause then repeatedly:
		#  --- Pillage
		#  --- Hire a holy man and leave the dialog on-screen
		#  --- Grant the holy man all the pillaged land (which resets the pillaging flags)
		#  --- Kill the holy man via the dialog, inheriting his land
		# This costs 25 per loop, but that flat rate is excessively harsh because you can give multiple holdings to the same holy man before autokilling him.
		#  --- Therefore, the instant-pillage effect keeps track of the quantity of piety recently spent on pillaging,
		#         and refunds the lesser of {max amount of piety recently spent on pillaging any holding} and
		#         {amount of piety spent on pillaging this holding}.
		
		#Currently disabled for the AI by the pre-filter and the ai_will_do section. Could potentially be enabled, if we could be sure the AI would be sensible about it.
		ai = no
		
		filter = owned
		ai_target_filter = owned
		is_high_prio = yes
		ai_check_interval = 3
		
		from_potential = {
			is_playable = yes
			OR = {
				is_tribal = yes
				is_nomadic = yes
			}
			has_dlc = "Horse Lords"
		}
		
		potential = {
			FROM = { ROOT = { expd_pill_this_holding_is_potentially_pillageable_by_prev_character = yes } }
		}
		
		allow = {
			FROM = { ROOT = { expd_pill_this_holding_is_allowed_to_be_pillaged_by_prev_character = yes } }
		}
		
		effect = {
			FROM = { ROOT = { expd_pill_this_holding_is_fully_pillaged_by_prev_character = yes } }
		}
		ai_will_do = {
			factor = 0
		}
	}

	expd_pill_tribal_pillage_settlement = {
		#Allows tribal characters to pillage non-tribal holdings when there's only one in the province
		#Also allows tribal characters to pillage tribal holdings of other cultures (if they are a human player)
		
		#Currently disabled for the AI by the pre-filter and the ai_will_do section. Could potentially be enabled, if we could be sure the AI would be sensible about it. (Eg: Not give it away to a vassal mid-pillage.)
		
		ai = no
		
		filter = owned
		ai_target_filter = owned
		ai_check_interval = 3
		
		from_potential = {
			is_playable = yes
			is_tribal = yes
			has_dlc = "Horse Lords"
		}
		
		potential = {
			
			#Pillaging nomadic holdings is not permitted (should be impossible, but you never know...)
			NOT = { holding_type = nomad }
			
			
			OR = {
				#Pillaging a non-tribal holding is always permitted, as long as there are no other holdings in the county
				#(If there are other holdings then the vanilla decision is available)
				AND = {
					NOT = { holding_type = tribal }
					location = { num_of_settlements < 2 }
				}
				
				#Pillaging tribal holdings is only permitted if you are the player and the province is of a different culture group
				#(There are valid reasons to pillage owned tribal holdings, but the AI is not capable of making that kind of decision.)
				AND = {
					holding_type = tribal
					NOT = { location = { culture_group = FROM } }
				}
			}
			
			#Can only pillage holdings you own personally
			owner = { character = FROM }
		}
		
		allow = {
			custom_tooltip = {
				text = EXPD_PILL_TOOLTIP_PILLAGING_BLOCKED_BY_DECISION
				NOT = { FROM = { has_character_flag = expd_pill_decisions_blocked } }
			}
			NOT = { has_holding_modifier = recently_burnt_the_land }
			has_siege = no
			custom_tooltip = {
				text = stop_pillaging_custom_tooltip
				hidden_tooltip = {
					NOT = { has_holding_modifier = stop_burning_land }
				}
			}
		}
		
		effect = {
			
			#Nickname grant is slightly modified from vanilla so the Validator doesn't complain
			hidden_tooltip = {
				location = { save_event_target_as = expd_pill_nickname_target }
				if = {
					limit = {
						owner = { 
							has_nickname = no
							is_adult = yes
							NOT = { trait = incapable }
						}
					}
					random_list = {
						5 = {
							owner = { give_nickname = nick_the_destroyer }
						}
						5 = {
							owner = { give_nickname = nick_the_scourge_of_god }
							modifier = {
								factor = 0
								event_target:expd_pill_nickname_target = { religion = FROM }
							}
						}
						5 = {
							owner = { give_nickname = nick_the_slayer_of_culture }
							modifier = {
								factor = 0
								event_target:expd_pill_nickname_target = { culture = FROM }
							}
						}
						5 = {
							owner = { give_nickname = nick_the_terror_of_provincename }
						}
						5 = {
							owner = { give_nickname = nick_the_culture_marauder }
							modifier = {
								factor = 0
								event_target:expd_pill_nickname_target = { culture = FROM }
							}
						}
						75 = {}
					}
				}
			}
			
			if = {
				limit = { NOT = { holding_type = tribal } }
				FROM = {
					wealth = 50
				}
				custom_tooltip = {
					text = gain_tech_custom_tooltip
					hidden_tooltip = {
						FROM = {
							random_list = {
								10 = { military_techpoints = 5 }
								10 = { economy_techpoints = 5 }
								10 = { culture_techpoints = 5 }
							}
						}
					}
				}
			}
			if = {
				limit = { holding_type = tribal }
				FROM = { wealth = 25 }
				if = {
					limit = { is_nomadic = yes}
					FROM = { population = 150 }
				}
			}
			
			custom_tooltip = {
				text = "PILLAGE_DESTROY_BUILDINGS"
				hidden_tooltip = {
					destroy_random_building = THIS
					destroy_random_building = THIS
					add_holding_modifier = {
						modifier = recently_burnt_the_land
						months = 7
					}
				}
			}
			
			hidden_tooltip = {
			
				location = {
					add_province_modifier = {
						modifier = rampaging_nomads
						years = 10
					}
				}

				location = {
					add_province_modifier = {
						modifier = burnt_the_land
						years = 10
					}
				}
			
				if = {
					limit = {
						OR = {
							FROM = { 
								NOT = { has_character_modifier = pillage_cooldown } 
							}
							FROM = {
								NOT = {
									any_realm_province = {
										any_province_holding = {
											owner = { character = FROM }
											has_holding_modifier = recently_burnt_the_land
											NOT = { has_holding_modifier = stop_burning_land }
										}
									}
								}
							}
						}
					}
					FROM = { character_event = { id = HL.4800 days = 180 } }
					FROM = {
						add_character_modifier = {
							modifier = pillage_cooldown
							hidden = yes
							months = 6
						}
					}
				}
			}
			
			if = {
				limit = {
					NOT = { has_any_building = yes }
					owner = {
						character = FROM
					}
				}
				hidden_tooltip = {
					#Fix the event code so HL.4814 triggers properly and/or so that the Validator doesn't complain
					location = {
						province_event = { id = HL.4810 days = 1 }
						save_event_target_as = target_location
						FROM = { character_event = { id = HL.4814 days = 2 random = 2 } }
					}
				}
				destroy_settlement = THIS
			}
			
		}
		ai_will_do = {
			factor = 0
		}
	}
}