﻿historical_figure_save_skill_effect = {

	$TEMP$  = { historical_figure_clear_trait_effect = yes }
	$TEMP2$ = { historical_figure_clear_trait_effect = yes }
	$TEMP3$ = { historical_figure_clear_trait_effect = yes }

	$TEMP$  = { historical_figure_adjust_skill_effect = yes }
	$TEMP$  = { historical_figure_adjust_modifier_effect = yes }

	historical_figure_save_each_skill_effect = { TEMP = $TEMP$ TEMP2 = $TEMP2$ TEMP3 = $TEMP3$ TYPE = diplomacy }
	historical_figure_save_each_skill_effect = { TEMP = $TEMP$ TEMP2 = $TEMP2$ TEMP3 = $TEMP3$ TYPE = martial }
	historical_figure_save_each_skill_effect = { TEMP = $TEMP$ TEMP2 = $TEMP2$ TEMP3 = $TEMP3$ TYPE = stewardship }
	historical_figure_save_each_skill_effect = { TEMP = $TEMP$ TEMP2 = $TEMP2$ TEMP3 = $TEMP3$ TYPE = intrigue }
	historical_figure_save_each_skill_effect = { TEMP = $TEMP$ TEMP2 = $TEMP2$ TEMP3 = $TEMP3$ TYPE = learning }
	historical_figure_save_each_skill_effect = { TEMP = $TEMP$ TEMP2 = $TEMP2$ TEMP3 = $TEMP3$ TYPE = prowess }

}


historical_figure_save_each_skill_effect = {

	if = {
		limit = {
			$TEMP$.$TYPE$ = $TEMP2$.$TYPE$
			$TEMP$.$TYPE$ = $TEMP3$.$TYPE$
		}
		set_variable = {
			name = historical_figure_$TYPE$
			value = $TEMP$.$TYPE$
		}
	}

}


historical_figure_load_skill_effect = {

	historical_figure_save_temporary_skill_effect = yes

	historical_figure_adjust_skill_effect = yes
	historical_figure_adjust_modifier_effect = yes
	historical_figure_adjust_modifier_misc_effect = yes

	force_character_skill_recalculation = yes

	historical_figure_load_each_skill_effect = { TYPE = diplomacy }
	historical_figure_load_each_skill_effect = { TYPE = martial }
	historical_figure_load_each_skill_effect = { TYPE = stewardship }
	historical_figure_load_each_skill_effect = { TYPE = intrigue }
	historical_figure_load_each_skill_effect = { TYPE = learning }
	historical_figure_load_each_skill_effect = { TYPE = prowess }

}


historical_figure_load_each_skill_effect = {

	# Calculate difference between each base

	if = {
		limit = {
			has_variable = historical_figure_$TYPE$
		}
		set_variable = {
			name = difference
			value = var:historical_figure_$TYPE$
		}
		change_variable = {
			name = difference
			subtract = $TYPE$
		}
	}

	# Restore skill before adjustment

	if = {
		limit = {
			has_variable = historical_figure_temporary_$TYPE$
		}
		set_variable = {
			name = temporary_difference
			value = var:historical_figure_temporary_$TYPE$
		}
		change_variable = {
			name = temporary_difference
			subtract = $TYPE$
		}
		add_$TYPE$_skill = var:temporary_difference
		force_character_skill_recalculation = yes

		remove_variable = temporary_difference
		remove_variable = historical_figure_temporary_$TYPE$
	}

	# Modify skill by difference if needed

	if = {
		limit = {
			exists = var:difference
		}
		if = {
			limit = {
				var:difference > 0
			}
			add_$TYPE$_skill = var:difference
			force_character_skill_recalculation = yes
		}
		remove_variable = difference
		remove_variable = historical_figure_$TYPE$
	}

}


historical_figure_adjust_skill_effect = {

	historical_figure_adjust_each_skill_effect = { TYPE = diplomacy }
	historical_figure_adjust_each_skill_effect = { TYPE = martial }
	historical_figure_adjust_each_skill_effect = { TYPE = stewardship }
	historical_figure_adjust_each_skill_effect = { TYPE = intrigue }
	historical_figure_adjust_each_skill_effect = { TYPE = learning }

	force_character_skill_recalculation = yes

}


historical_figure_adjust_each_skill_effect = {

	if = {
		limit = { has_focus = education_$TYPE$ }
		add_$TYPE$_skill = -1
	}

}


historical_figure_save_temporary_skill_effect = {

	historical_figure_save_each_temporary_skill_effect = { TYPE = diplomacy }
	historical_figure_save_each_temporary_skill_effect = { TYPE = martial }
	historical_figure_save_each_temporary_skill_effect = { TYPE = stewardship }
	historical_figure_save_each_temporary_skill_effect = { TYPE = intrigue }
	historical_figure_save_each_temporary_skill_effect = { TYPE = learning }
	historical_figure_save_each_temporary_skill_effect = { TYPE = prowess }

}


historical_figure_save_each_temporary_skill_effect = {

	set_variable = {
		name = historical_figure_temporary_$TYPE$
		value = $TYPE$
	}

}
