﻿# On actions for army events, triggered automatically by the game

# called for armies every 30 days; exact date dependent on army ID
# root is the owner of the army
# scope:army is the army

on_army_monthly = {
	on_actions = {
		on_besieging_in_difficult_terrain
	}
}

on_besieging_in_difficult_terrain = {
	trigger = {
		NOT = { has_game_rule = besiegeing_slows_down_none }
		trigger_if = {
			limit = { has_game_rule = besiegeing_slows_down_player }
			root = { is_ai = no }
		}
		scope:army ?= {
			exists = army_commander
			OR = {
				is_army_in_siege = yes
				AND = {
					has_game_rule = even_raids_take_time
					is_army_in_raid = yes
				}
			}
			location = {
				OR = {
					terrain = forest
					terrain = taiga
					terrain = jungle
					terrain = hills
					terrain = mountains
					terrain = desert_mountains
				}
			}
		}
	}
	effect = {
		scope:army ?= {
			if = {
				limit = {
					exists = army_commander
					army_commander = {
						NOR = {
							has_character_modifier = besieging_army_in_forest
							has_character_modifier = besieging_army_in_taiga
							has_character_modifier = besieging_army_in_jungle
							has_character_modifier = besieging_army_in_hills
							has_character_modifier = besieging_army_in_mountains
							has_character_modifier = besieging_army_in_desert_mountains
						}
					}
				}
				location = {
					switch = {
						trigger = terrain
						forest = { add_army_commander_modifier = { MODIFIER = besieging_army_in_forest } }
						taiga = { add_army_commander_modifier = { MODIFIER = besieging_army_in_taiga } }
						jungle = { add_army_commander_modifier = { MODIFIER = besieging_army_in_jungle } }
						hills = { add_army_commander_modifier = { MODIFIER = besieging_army_in_hills } }
						mountains = { add_army_commander_modifier = { MODIFIER = besieging_army_in_mountains } }
						desert_mountains = { add_army_commander_modifier = { MODIFIER = besieging_army_in_desert_mountains } }
					}
				}
			}
		}
	}
}

# called when a siege completes. Does *not* fire on reoccupation by province order
# root is the occupant
# scope:barony is the barony title that got occupied
# scope:county is the county title for the barony
# scope:previous_controller is the previous controller of the county
# scope:war is the war causing the previous controller and the occupant to be hostile
# occupied_baronies is a list of all baronies that the siege caused the occupier to control (I.E., can include baronies with no fort level)
on_siege_completion = {
	on_actions = {
		on_complete_besieging_in_difficult_terrain
	}
}

# Called when a siege loots a holding
# root is sieging character
# scope:barony is the barony title that got looted
# scope:county is the county title for the barony
# scope:previous_controller is the previous controller
on_siege_looting = {
	on_actions = {
		on_complete_besieging_in_difficult_terrain
	}
}

on_complete_besieging_in_difficult_terrain = {
	trigger = {
		NOT = { has_game_rule = besiegeing_slows_down_none }
		trigger_if = {
			limit = { has_game_rule = besiegeing_slows_down_player }
			root = { is_ai = no }
		}
	}
	effect = {
		scope:barony.title_province = {
			every_army_in_location = {
				army_commander ?= {
					switch = {
						trigger = has_character_modifier
						besieging_army_in_forest = { remove_character_modifier = besieging_army_in_forest }
						besieging_army_in_taiga = { remove_character_modifier = besieging_army_in_taiga }
						besieging_army_in_jungle = { remove_character_modifier = besieging_army_in_jungle }
						besieging_army_in_hills = { remove_character_modifier = besieging_army_in_hills }
						besieging_army_in_mountains = { remove_character_modifier = besieging_army_in_mountains }
						besieging_army_in_desert_mountains = { remove_character_modifier = besieging_army_in_desert_mountains }
					}
				}
			}
		}
	}
}

# Called when a raid action finishes
# root is the raid army
# scope:raider is the person owning the raid army
# scope:barony is the barony title that got raided
# scope:county is the county title for the barony
on_raid_action_completion = {
	on_actions = {
		on_complete_raid_in_difficult_terrain
	}
}

on_complete_raid_in_difficult_terrain = {
	trigger = {
		has_game_rule = even_raids_take_time
	}
	on_actions = {
		on_complete_besieging_in_difficult_terrain
	}
}