﻿####################
# Maintence Pulses #
####################
# This file holds the maintenance on actions, using pulses to trigger
# We check things like traits, election, inheritance laws and more
# Note that playable characters are counts+ while "everyone" include alls characters
####################

# Called from code once a quarter for "playable" (count+) characters.
# Root is the character
# scope:quarter is which quarter it's for, from 1 to 4. Note that scope:quarter = 1 isn't necessarily in Q1 by calendar time
quarterly_playable_pulse = {
	on_actions = {
		regula_quarterly_playable_pulse
	}
}

regula_quarterly_playable_pulse = {
	events = {
		regula_initialize_event.0009 # Maintains Covert Inheritance Laws
		regula_initialize_event.0010 # Passes on the Magister traits.
		regula_initialize_event.0012 # Removes traits from the unworthy.
		regula_initialize_event.0013 # Keeps the Compeditae Election humming.
		regula_initialize_event.0014 # Ensures that any Regula Mercenary companies have female commanders.
		regula_initialize_event.0015 # Removes and adds the scaling Paelex/Traopaeum modifiers for Magister to refresh value
		regula_initialize_event.0016 # Updates the scaling Contubernalis modifiers for Magister with appropriate tenet
		regula_initialize_event.0017 # Restores secret faith if converted
		

		# Laws Maintenance
		regula_paelex_event.0001  # Sets inheritance laws for Magister
		regula_paelex_event.0002  # Sets inheritance laws for vassals of the Magister
		regula_paelex_event.0003  # Sets succession law for vassals of the Magister (Administrative Governments)

		regula_paelex_event.0995  # Paelex will replaces Vanilla MAA with Famuli versions
		regula_paelex_event.0996  # Keeps Domina/Paelex traits up to date.
		regula_orba_event.0001    # Converts adrift paelices to orba.

		regula_tropaeum_event.0001  # Updates tropaeum trait assignment.

		# Living Magister Bloodline Applications
		regula_bloodline.1021 # Potestas of Queens
		regula_bloodline.1022 # Servitude War
		regula_bloodline.1023 # Domination War
		regula_bloodline.1024 # Contubernalis
		regula_bloodline.1025 # Domitans Tribunal
		regula_bloodline.1026 # Fascinare
		regula_bloodline.1027 # Obedience
	}
}

# Called from code once a year for all characters, at a random point that year (individually for each character)
# Root is the character
random_yearly_everyone_pulse = {
	on_actions = {
		regula_random_yearly_everyone_pulse
	}
}

# Called from code once a year for all characters, at a random point that year (individually for each character)
# Root is the character
regula_random_yearly_everyone_pulse = {
	events = {
		regula_orba_event.0001    # Converts adrift paelices to orba.
		regula_orba_event.0002	  # Orba lose a bit more health each year.
		regula_orba_event.0003	  # Remove Orba health penalty from non-Orba
		regula_paelex_event.0997  # Fixes HOF issues.
		regula_tropaeum_event.0003 # Converts adrift tropaeum back to mulsa
		regula_holy_bloodline_events.0003 # If we have "Sacrutus Dimidium" then we can regain Sacrutus Sanguis if mother becomes charmed
	}
}

on_faith_monthly = {
	on_actions = {
		regula_all_failth_pulse
	}
}

regula_all_failth_pulse = {
	# This way we simulate a monthly pulse in the scope of the magister's faith
	trigger = {
		has_doctrine = tenet_regula_magister
		exists = global_var:magister_character
		this = global_var:magister_character.faith
	}

	effect = {
		#degbug_log = "Regula: Faith monthly pulse"

		# Generate contracts each month
		regula_generate_transport_daughter_contracts = yes
	}
}