﻿# Returns the skill level of the raid leader on a scale from
# 0 (min skill) to 1 (most skill). In terms of martial level
# this translates to (10, 50).
# scope:councillor = councillor_raid_leader
raid_leader_skill_factor = {
	scope:councillor = {
		value = martial
		subtract = 10
		divide = 40
		min = 0
		max = 1
	}
}

# The increase in movement_speed_land_raiding granted by
# task_enforce_discipline.
# Range: [10%, 50%]
task_enforce_discipline_raid_move_speed = {
	value = 0.1
	add = {
		value = 0.4
		multiply = raid_leader_skill_factor
	}
}

# The increase in raid_speed granted by task_enforce_discipline.
# Range: [20%, 100%]
task_enforce_discipline_raid_speed = {
	value = 0.2
	add = {
		value = 0.8
		multiply = raid_leader_skill_factor
	}
}

# The decrease in hostile_county_attrition_raiding granted by
# task_enforce_discipline.
# Range: [10%, 50%]
task_enforce_discipline_raid_attrition = {
	value = -0.1
	add = {
		value = -0.4
		multiply = raid_leader_skill_factor
	}
}

# Calculates the amount of progress on the scout targets task which the
# councillor should make per 30 days. 1/30th of this value will be applied
# daily, and once the value reaches 100, the task is completed.
# Base Range: [25, 100] aka duration of 120d to 30d.
# Contested Range: [25, 100] aka duration of 120d to 30d
task_scout_targets_monthly_progress = {
	value = {
		value = 25
		desc = regula_council_base_progress
	}

	add = {
		value = 75
		multiply = raid_leader_skill_factor
		desc = regula_raid_leader_skill
	}

	# Digging for dirt also improves scout targets speed.
	if = {
		limit = {
			exists = scope:councillor_liege
			scope:councillor_liege = { has_perk = digging_for_dirt_perk }
		}
		multiply = {
			value = 1.25
			desc = ESPIONAGE_PERK_BONUS_VALUE
		}
	}

	if = {
		limit = {
				councillor_liege_has_erudition_legacy_5_perk = yes
		}
		multiply = {
			value = 1.1
			desc = ERUDITION_DYNASTY_PERK_BONUS_VALUE
		}
	}

	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		multiply = {
			value = 1.1
			desc = FAMILY_BUSINESS_BONUS_VALUE
		}
	}

	if = {
		limit = {
			exists = scope:county
			exists = scope:county.holder
		}

		subtract = {
			value = 25
			multiply = scope:county.holder.character_intrigue_skill_factor
			desc = regula_council_target_intrigue_skill
		}

		if = {
			limit = {
				exists = scope:county.holder.cp:councillor_spymaster
				NOT = { scope:county.holder.cp:councillor_spymaster = scope:councillor_liege }
				scope:county.holder.cp:councillor_spymaster = {
					is_performing_council_task = task_disrupt_schemes
				}
			}
			multiply = {
				value = scope:county.holder.cp:councillor_spymaster.spymaster_find_secrets_disrupt_schemes_modifier_factor
				desc = TARGET_SPYMASTER_disrupt_schemes
			}
		}

		if = {
			limit = {
				target_is_liege_or_above = scope:county.holder
			}
			multiply = {
				value = 0.5
				desc = TARGET_IS_LIEGE_penalty
			}
		}
	}

	max = {
		value = 100
		desc = regula_council_max_progress
	}

	min = {
		value = 25
		desc = regula_council_min_progress
	}
}

# Calculates the expected duration of task_scout_targets for the current
# raid leader in days.
task_scout_targets_duration_days = {
	value = 100
	divide = {
		value = task_scout_targets_monthly_progress
		divide = 30
	}
}

# Calculates the number of targets which can be scouted in a single task
# completion.
# Range: [1, 5]
task_scout_targets_num_targets = {
	value = 1
	add = {
		value = 4
		multiply = raid_leader_skill_factor
	}
	floor = yes
}

# Success chance for task_scout_targets to investigate targets in a court.
# Base Range: [60, 100]
# Contested Range [20, 100]
task_scout_targets_success_chance = {
	value = 60
	add = {
		value = 40
		multiply = raid_leader_skill_factor
	}

	if = {
		limit = {
			exists = scope:county
			exists = scope:county.holder
		}

		subtract = {
			value = 40
			multiply = scope:county.holder.character_intrigue_skill_factor
		}
	}
}

# Decrease in the rate of levy reinforcement for the council owner while
# the councillor is tasked with performing border raids.
# Range: [-0.25, 0]
task_border_raids_levy_reinforcement_rate_penalty = {
	value = -0.25
	add = {
		value = 0.25
		multiply = raid_leader_skill_factor
	}
}

# Calculates the amount of progress on the border targets task which the
# councillor should make per 30 days. 1/30th of this value will be applied
# daily, and once the value reaches 100, the task is completed.
# Range: [20, 40] aka duration of 150d to 75d.
task_border_raids_monthly_progress = {
	value = {
		value = 20
		desc = regula_council_base_progress
	}

	add = {
		value = 20
		multiply = raid_leader_skill_factor
		desc = regula_raid_leader_skill
	}
}

# Calculates the expected duration of task_border_raids for the current
# raid leader in days.
task_border_raids_duration_days = {
	value = 100
	divide = {
		value = task_border_raids_monthly_progress
		divide = 30
	}
}

# Calculates the amount of gold which should be acquired as a result of border
# raids.
# Range: [tiny_gold_value - 10%, minor_gold_value + 10%]
task_border_raids_gold_gain = {
	integer_range = {
		min = task_border_raids_min_gold_gain
		max = task_border_raids_max_gold_gain
	}
}

# Min gold gain for a border raid.
# Range: [tiny_gold_value - 10%, minor_gold_value - 10%]
task_border_raids_min_gold_gain = {
	value = task_border_raids_base_gold_gain
	multiply = 0.9
	floor = yes
}

# Max gold gain for a border raid.
# Range: [tiny_gold_value + 10%, minor_gold_value + 10%]
task_border_raids_max_gold_gain = {
	value = task_border_raids_base_gold_gain
	multiply = 1.1
	ceiling = yes
}

# Base gold gain for a border raid.
# Range: [tiny_gold_value, minor_gold_value]
task_border_raids_base_gold_gain = {
	value = tiny_gold_value
	add = {
		value = minor_gold_value
		subtract = tiny_gold_value
		multiply = raid_leader_skill_factor
	}
}

# The chance that a captive will be captured by task_border_raids.
# Range: [70%, 100%]
task_border_raids_captive_chance = {
	value = 70
	add = {
		value = 30
		multiply = raid_leader_skill_factor
	}
}

# The chance that the targeted liege will be angered by
# task_border_raids.
# Range: [0%, 10%]
task_border_raids_anger_liege_chance = {
	value = 10
	add = {
		subtract = 10
		multiply = raid_leader_skill_factor
	}
}
