﻿# Returns the skill level of the harem manager on a scale from
# 0 (min skill) to 1 (most skill). In terms of stewardship level
# this translates to (10, 50).
# scope:councillor = councillor_harem_manager
harem_manager_skill_factor = {
	scope:councillor = {
		value = stewardship
		subtract = 10
		divide = 40
		min = 0
		max = 1
	}
}

# The percentage of harem skills to add to the magister.
# Range: [1%, 5%]
task_coordinate_harem_percentage = {
	value = 1
	add = {
		value = 4
		multiply = harem_manager_skill_factor
	}
}

# The cap on the total of each skill value which can be added by Coordinate
# Harem.
# Range: [+3, +15]
task_coordinate_harem_cap = {
	value = 3
	add = {
		value = 12
		multiply = harem_manager_skill_factor
	}
	floor = yes
}

# Calculates the diplomancy magister assistance value.
task_coordinate_harem_diplomacy = {
	value = 0

	liege = {
		every_spouse = {
			limit = {
				is_regula_leader_devoted_trigger = yes
			}
			add = diplomacy
		}
	}

	multiply = {
		value = task_coordinate_harem_percentage
		divide = 100
	}

	max = task_coordinate_harem_cap
	floor = yes
}

# Calculates the martial magister assistance value.
task_coordinate_harem_martial = {
	value = 0

	liege = {
		every_spouse = {
			limit = {
				is_regula_leader_devoted_trigger = yes
			}
			add = martial
		}
	}

	multiply = {
		value = task_coordinate_harem_percentage
		divide = 100
	}

	max = task_coordinate_harem_cap
	floor = yes
}

# Calculates the stewardship magister assistance value.
task_coordinate_harem_stewardship = {
	value = 0

	liege = {
		every_spouse = {
			limit = {
				is_regula_leader_devoted_trigger = yes
			}
			add = stewardship
		}
	}

	multiply = {
		value = task_coordinate_harem_percentage
		divide = 100
	}

	max = task_coordinate_harem_cap
	floor = yes
}

# Calculates the intrigue magister assistance value.
task_coordinate_harem_intrigue = {
	value = 0

	liege = {
		every_spouse = {
			limit = {
				is_regula_leader_devoted_trigger = yes
			}
			add = intrigue
		}
	}

	multiply = {
		value = task_coordinate_harem_percentage
		divide = 100
	}

	max = task_coordinate_harem_cap
	floor = yes
}

# Calculates the learning magister assistance value.
task_coordinate_harem_learning = {
	value = 0

	liege = {
		every_spouse = {
			limit = {
				is_regula_leader_devoted_trigger = yes
			}
			add = learning
		}
	}

	multiply = {
		value = task_coordinate_harem_percentage
		divide = 100
	}

	max = task_coordinate_harem_cap
	floor = yes
}

# Calculates the amount of progress on the family planning 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: [16.66, 50] aka duration of 180d to 60d.
task_family_planning_monthly_progress = {
	value = {
		value = 16.66
		desc = regula_council_base_progress
	}

	add = {
		value = 33.34
		multiply = harem_manager_skill_factor
		desc = regula_harem_manager_skill
	}

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

	max = {
		value = 50
		desc = regula_council_max_progress
	}
}

# Calculates the expected duration of task_family_planning for the current
# harem manager in days.
task_family_planning_duration_days = {
	value = 100
	divide = {
		value = task_family_planning_monthly_progress
		divide = 30
	}
}

# Weighting factor which reduces the chance of the same candidate being
# selected repeatedly for family planning by downweighting based on number
# of children the candidate already has with the liege.
#
# Reduces the chance of the candidate being selected by 10% per existing child
# with the liege, up to a max of 90% reduction.
#
# scope = the candidate being evaluated
# scope:councillor_liege = liege of the councillor_harem_manager
task_family_planning_previous_child_selection_factor = {
	value = 1
	subtract = {
		value = 0.1
		multiply = {
			value = 0
			every_child = {
				limit = {
					father = scope:councillor_liege
				}
				add = 1
			}
			max = 9
		}
	}
}
