﻿
###THESE ON ACTIONS HAVE TO BE ADDED TO THE VANILLA FILES AS HAVING SEPERATE FILES FOR THE SAME ON ACTION DOES NOT WORK

# on_game_start = {
	# effect = {
		# ### BYZANTINE EMPIRE SETUP ###
		# culture:greek = { add_innovation = innovation_roman_administration }
		# if = {
			# limit = { exists = title:e_byzantium.holder }
			# title:e_byzantium.holder = {
				# every_vassal = {
					# limit = { has_government = feudal_government }
					# change_government = military_command
					# every_held_title = {
						# limit = { 
							# NAND = { #not county capital barony
								# tier = tier_barony
								# holder = { highest_held_title_tier > 1 }
							# }
						# }
						# add_title_law = military_appointment_succession_law
					# }
					# every_vassal = {
						# limit = { has_government = feudal_government }
						# change_government = military_command
						# every_held_title = {
							# limit = { 
								# NAND = { #not county capital barony
									# tier = tier_barony
									# holder = { highest_held_title_tier > 1 }
								# }
							# }
							# add_title_law = military_appointment_succession_law
						# }
						# every_vassal = {
							# limit = { has_government = feudal_government }
							# change_government = military_command
							# every_held_title = {
								# limit = { 
									# NAND = { #not county capital barony
										# tier = tier_barony
										# holder = { highest_held_title_tier > 1 }
									# }
								# }
								# add_title_law = military_appointment_succession_law
							# }
						# }
					# }
				# }
			# }
		# }
	# }	
# }

# # A title is transferred to a new character
# # root = the new holder
# # scope:title = the title that changes hands
# # scope:previous_holder = previous holder. Might be dead
# on_death = {
	# events = {
		# imperial.0001 #Imperial succession maintenance
		# imperial.0003 #Military succession maintenance
	# }	
# }

# # A title is transferred to a new character
# # root = the new holder
# # scope:title = the title that changes hands
# # scope:previous_holder = previous holder. Might be dead
# on_title_gain = {
	# effect = {
		# add_character_flag = TEST_0
		# if = {
			# limit = { can_get_military_command_trigger = yes }
			# change_government = military_command
			# every_held_title = {
				# limit = { 
					# NAND = { #not county capital barony
						# tier = tier_barony
						# holder = { highest_held_title_tier > 1 }
						# title_province = { is_county_capital = yes }
					# }
				# }
				# add_title_law = military_appointment_succession_law
			# }
		# }
		# if = { #if go over domain limit try and give title to the military candidate first
			# limit = {
				# highest_held_title_tier >= tier_kingdom
				# #is_ai = yes
				# domain_limit_available < 0			
				# any_targeting_faction = {
					# faction_is_type = military_faction
					# special_character = { 
						# OR = {
							# is_ruler = no
							# has_government = patrician_government
						# }	
						# eligible_for_military_appointment_trigger = yes
						# any_liege_or_above = { this = root }
					# }
				# }
			# }
			# add_character_flag = TEST_1
			# random_targeting_faction = {
				# limit = { faction_is_type = military_faction }
				# save_scope_as = faction_update
			# }
			# if = {
				# limit = {
					# is_character_interaction_valid = {
						# recipient = scope:faction_update.special_character
						# interaction = grant_titles_interaction
					# }
					# OR = {
						# AND = {
							# opinion = { target = scope:faction_update.special_character value > -30 }
							# reverse_opinion = { target = scope:faction_update.special_character value > -30 }
						# }	
						# scope:faction_update = { #faction is very discontent
							# faction_discontent >= 80
							# faction_power >= 75
						# }
					# }				
				# }
				# add_character_flag = TEST_2
				# trigger_event = imperial.0026
			# }
		# }
	# }	
# }

# on_war_won_attacker = {
	# # The war notifications are handled in `effect` instead of `events` due to order of operations.
	# # `effect` fires on THIS tick, `events` fires on the NEXT tick, and the war gets destroyed between this tick and the next.
	# effect = {
		# scope:defender = { 
			# if = {
				# limit = {
					# any_targeting_faction = {
						# faction_is_type = military_faction
					# }
				# }
				# send_interface_toast = {
					# title = military_faction_LOST_WAR_TITLE
					# right_icon = this
					# random_targeting_faction = {
						# limit = { faction_is_type = military_faction }
						# add_faction_discontent = 50
					# }
				# }				 
			# }	
		# }
	# }
# }

# on_war_won_defender = {
	# effect = {
		# scope:attacker = {
			# if = {
				# limit = {
					# any_targeting_faction = {
						# faction_is_type = military_faction
					# }
				# }
				# send_interface_toast = {
					# title = military_faction_LOST_WAR_TITLE
					# right_icon = this
					# random_targeting_faction = {
						# limit = { faction_is_type = military_faction }
						# add_faction_discontent = 50
					# }
				# }
			# }	
		# }
	# }
# }

random_yearly_playable_pulse = {
	on_actions = {
		new_bureaucrat
		military_career
	}
	
}
new_bureaucrat = {
	random_events = {	
		80 = 0
		delay = { months = { 2 4 } }
		20 = imperial.0041	 #New character emerges from bureaucracy	
	}
}
military_career = {
	random_events = {	
		50 = 0
		delay = { months = { 1 2 } }
		50 = military_career.0001	 #Character wants military career	
	}
}

three_year_playable_pulse = {
	events = {
		imperial.0070 #rich landless courtiers get patrician house
	}
}

# Used for handling the military_career guard
military_career_ongoing = {
	trigger = {
		has_character_flag = is_currently_military_career
	}
	effect = {
		#debug_log = "Fired the military_career_ongoing pulse"
		#debug_log_scopes = yes
		change_variable = { # NOTE: Will *not* be relevant to non-delayed trigger evaluations for the events below
			name = years_as_military_career
			add = 1
		}
		if = {
			limit = {
				AND = {
					OR = {
						has_government = imperial_government
						has_government = military_command
						has_government = feudal_government
						has_government = clan_government
					}	
					is_ruler = yes
				}
			}
			remove_character_flag = is_currently_military_career
			remove_character_flag = has_asked_for_military_career
		}
		else = {
			trigger_event = {
				on_action = military_career_ongoing
				days = { 340 380 }
			}
		}	
	}
	random_events = {
		500 = 0
		500 = military_career.1001 # Return home
		# 100 = military_career.2001 # Become Best Friends with another military_career
		# 100 = military_career.2002 # Become Lover with another military_career
		#100 = military_career.2003 # Become Friends with a local ruler
		#100 = military_career.2004 # Become Rival with a local ruler
		# 300 = military_career.2005 # Marry Lover
		#100 = military_career.2008 # Get wounded
		# 100 = military_career.2011 # Get local Lover
		#200 = military_career.2012 # Increase Prowess
		#200 = military_career.2013 # Increase Martial
		# 200 = military_career.2014 # Increase Learning
		# 200 = military_career.2015 # Increase Diplomacy
		# 50 = military_career.2016 # Become Brave
		# 50 = military_career.2017 # Become Ambitious
		# 50 = military_career.2018 # Become Diligent
	}
}