﻿on_game_start = {
	on_actions = {
		hth_game_start_setup_effect
	}
}
on_birth_child  = {
	on_actions = {
		hth_highborn_effect
	}
}
on_16th_birthday = {
	on_actions = {
		hth_dynasty_of_swords_effect
	}
}
on_combat_end_winner = {
	on_actions = {
		hth_call_of_the_sheep_effect
	}
}
on_title_gain = {
	on_actions = {
		hth_call_of_the_sheep_variable_effect
	}
}
hth_game_start_setup_effect = {
	effect = {
		set_global_variable = {
			name = hth_enabled
			value = 1
		}
		every_ruler = {
			if = {
				limit = { 
					NOT = { has_variable = hth_battles_won_counter } 	
				}
				set_variable = {
					name = hth_battles_won_counter
					value = 0
				}
			}
		}
	}
}
hth_call_of_the_sheep_variable_effect = {
	effect = {
		if = {
			limit = { 
				NOT = { has_variable = hth_battles_won_counter } 	
			}
			set_variable = {
				name = hth_battles_won_counter
				value = 0
			}
		}
	}
}
hth_highborn_effect = {
	effect = {
		if = {
			limit = {
				exists = scope:child.dynasty
				scope:child.dynasty = { has_dynasty_perk = ep3_administrative_legacy_3 }
				OR = {
					scope:mother.dynasty = scope:child.dynasty
					scope:real_father.dynasty = scope:child.dynasty
				}
			}
			add_trait = hth_highborn
		}
	}
}
hth_dynasty_of_swords_effect = {
	effect = {
		if = {
			limit = {
				exists = dynasty
				dynasty = { has_dynasty_perk = hth_warfare_legacy_3 }
			}
			assign_commander_trait_effect = yes
		}
	}
}
hth_call_of_the_sheep_effect = {
	effect = {
		if = {
			limit = {
				side_primary_participant = { 
					has_global_variable = hth_enabled # exists only to get rid of errors for an unused variable
					NOT = { has_variable = hth_battles_won_counter }
				}
			}
			side_primary_participant = {
				set_variable = {
					name = hth_battles_won_counter
					value = 1
				}
			}
		}
		else_if = {
			limit = {
				side_primary_participant = { has_variable = hth_battles_won_counter }
			}
			side_primary_participant = {
				change_variable = {
					name = hth_battles_won_counter
					add = 1
				}
			}
		}
	}
}