﻿task_organize_levies = {
	default_task = yes
	position = councillor_marshal

	task_type = task_type_general
	task_progress = task_progress_infinite

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_organize_levies.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}

	effect_desc = {
		### Organized levies
		desc = task_organize_levies_effect_desc
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_organize_levies_erudition_bonus
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_organize_levies_family_business_bonus
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_organize_levies_consulted_house_bonus
		}
		triggered_desc = {
			trigger = {
				scope:councillor_liege = {
					has_title = title:c_byzantion
					title:c_byzantion = { has_county_modifier = pandidakterion_university_modifier }
				}
			}
			desc = task_organize_levies_pandidakterion_bonus_desc
		}

		### Army Maintenance
		desc = {
			desc = task_organize_levies_maintenance_effect_desc
			triggered_desc = {
				trigger = {
					councillor_liege_has_erudition_legacy_5_perk = yes
				}
				desc = task_organize_levies_maintenance_erudition_bonus_desc
			}
			triggered_desc = {
				trigger = {
					councillor_liege_has_family_business_bonus = yes
				}
				desc = task_organize_levies_maintenance_family_business_bonus_desc
			}
			triggered_desc = {
				trigger = {
					councillor_liege_has_consulted_house_bonus = yes
				}
				desc = task_organize_levies_maintenance_consulted_house_bonus_desc
			}
			triggered_desc = {
				trigger = {
					scope:councillor_liege = {
						has_title = title:c_byzantion
						title:c_byzantion = { has_county_modifier = pandidakterion_university_modifier }
					}
				}
				desc = task_organize_levies_maintenance_pandidakterion_bonus_desc
			}
		}

		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					scope:councillor_liege = {
						any_active_accolade = {
							accolade_parameter = accolade_organize_army_bonus
						}
					}
				}
				desc = task_train_commanders_acclaimed_knight_levy_captaincy
			}
			triggered_desc = {
				trigger = {
					scope:councillor_liege = { 
						any_sub_realm_county = {
							NOT = { has_county_modifier = marshal_task_organized_service_modifier }
						}
					}
					martial > mediocre_skill_rating
				}
				desc = task_organize_levies_well_organized_service
			}
			triggered_desc = {
				trigger = {
					scope:councillor_liege = { 
						any_sub_realm_county = {
							NOT = { has_county_modifier = marshal_task_military_presence_modifier }
						}
					}
					martial > mediocre_skill_rating
				}
				desc = task_organize_levies_increased_military_presence
			}
			triggered_desc = {
				trigger = {
					NOT = {
						has_character_modifier = marshal_task_levy_desertions_modifier
					}
					martial < high_skill_rating
				}
				desc = task_organize_levies_levy_desertion
			}
			triggered_desc = {
				trigger = {
					scope:councillor_liege = { 
						any_sub_realm_county = {
							NOT = { has_county_modifier = marshal_task_unused_farmland_modifier }
						}
					}
					martial < high_skill_rating
				}
				desc = task_organize_levies_unused_farmland
			}
			triggered_desc = {
				trigger = {
					scope:councillor_liege = { 
						any_sub_realm_county = {
							marshal_task_1003_county_trigger = yes
						}
					}	
					martial < high_skill_rating
				}
				desc = task_organize_levies_insufficient_guards
			}
		}
	}
	
	council_owner_modifier = {
		name = task_organize_levies_modifier
		garrison_size = 0.01
		levy_reinforcement_rate = 0.01
		scale = marshal_organize_levies_modifier_total
	}

	council_owner_modifier = {
		name = task_organize_levies_maintenance_modifier
		army_maintenance_mult = -0.01
		scale = marshal_organize_levies_maintenance_total
	}

	monthly_on_action = organize_the_levies_marshal_task_side_effects

	ai_will_do = {
		value = 1 # Always a good backup

		#AI prefers organizing levies over a low boost from Train Commanders if they are at war or have a negative income
		if = { 
			limit = {
				scope:councillor_liege = {
					OR = {
						monthly_character_income < monthly_character_expenses
						is_at_war = yes
					}
				}
			}
			add = 8
		}
		
		# Trying to get out of debt
		if = { 
			limit = {
				scope:councillor_liege = {
					is_at_war = yes
					gold < 0
					ai_rationality > 0
				}
			}
			add = scope:councillor_liege.ai_rationality
		}
		
		# Trying to avoid debt
		if = { 
			limit = {
				scope:councillor_liege = {
					is_at_war = yes
					monthly_character_income < monthly_character_expenses
					gold < 5
				}
			}
			add = 2000
		}

		# Trying to get the levy numbers bacc after the war
		if = { 
			limit = {
				scope:councillor_liege = {
					is_at_war = no
					current_military_strength < eighty_percent_of_max_military_strength
				}
			}
			add = 1000
		}
	}
}

task_train_commanders = {
	position = councillor_marshal

	task_type = task_type_general
	task_progress = task_progress_infinite

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_train_commanders.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}
	
	is_shown = {
		trigger_if = {
			limit = {
				scope:councillor_liege = { tgp_has_access_to_ministry_trigger = yes }
			}
			has_council_position = minister_grand_marshal
		}
	}
	
	effect_desc = {
		### Commander Improvement
		desc = task_train_commanders_maa_boost_effect_desc

		desc = task_train_commanders_effect_desc
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_train_commanders_commander_erudition_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_train_commanders_commander_family_business_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_train_commanders_commander_consulted_house_bonus_desc
		}
		triggered_desc = {
			trigger = {
				scope:councillor_liege = { has_character_modifier = employer_booner_master_of_horse_2_modifier }
			}
			desc = task_train_commanders_master_of_horse_2_bonus_desc
		}
		triggered_desc = {
			trigger = {
				scope:councillor_liege = { has_character_modifier = employer_booner_master_of_horse_3_modifier }
			}
			desc = task_train_commanders_master_of_horse_3_bonus_desc
		}

		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					scope:councillor_liege = {
						any_active_accolade = {
							OR = {
								has_accolade_parameter = accolade_train_commanders_bonus
								has_accolade_parameter = accolade_train_commanders_bonus_high
							}
						}
					}
				}
				desc = task_train_commanders_acclaimed_knight_drills_hastiludes
			}
			triggered_desc = {
				trigger = {
					martial > mediocre_skill_rating
				}
				desc = task_train_commanders_commander_learns_from_commander
			}
			triggered_desc = {
				trigger = {
					martial > mediocre_skill_rating
				}
				desc = task_train_commanders_knight_improved
			}
			triggered_desc = {
				trigger = {
					martial < high_skill_rating
				}
				desc = task_train_commanders_commander_wounded
			}
			triggered_desc = {
				trigger = {
					martial < high_skill_rating
				}
				desc = task_train_commanders_commander_maimed
			}
			triggered_desc = {
				trigger = {
					martial < high_skill_rating
				}
				desc = task_train_commanders_commander_killed
			}
		}
	}


	council_owner_modifier = {
		name = task_boost_knights_modifier

		knight_effectiveness_mult = 1
		scale = {
			value = marshal_knights_overtime_boost_scale
			divide = 100
		}
	}

	council_owner_modifier = {
		name = task_boost_maa_modifier

		skirmishers_damage_mult = 1
		skirmishers_toughness_mult = 1
		pikemen_damage_mult = 1
		pikemen_toughness_mult = 1
		heavy_infantry_damage_mult = 1
		heavy_infantry_toughness_mult = 1

		archers_damage_mult = 1
		archers_toughness_mult = 1

		light_cavalry_damage_mult = 1
		light_cavalry_toughness_mult = 1
		heavy_cavalry_damage_mult = 1
		heavy_cavalry_toughness_mult = 1

		archer_cavalry_damage_mult = 1
		archer_cavalry_toughness_mult = 1
		camel_cavalry_damage_mult = 1
		camel_cavalry_toughness_mult = 1
		elephant_cavalry_damage_mult = 1
		elephant_cavalry_toughness_mult = 1
		
		gunpowder_damage_mult = 1
		gunpowder_toughness_mult = 1

		siege_weapon_damage_mult = 1
		siege_weapon_toughness_mult = 1
		
		scale = {
			value = marshal_maa_overtime_boost_scale
			divide = 100
		}
	}

	councillor_modifier = {
		name = minister_grand_marshal_modifier

		skirmishers_damage_mult = 1
		skirmishers_toughness_mult = 1
		pikemen_damage_mult = 1
		pikemen_toughness_mult = 1
		heavy_infantry_damage_mult = 1
		heavy_infantry_toughness_mult = 1

		archers_damage_mult = 1
		archers_toughness_mult = 1

		light_cavalry_damage_mult = 1
		light_cavalry_toughness_mult = 1
		heavy_cavalry_damage_mult = 1
		heavy_cavalry_toughness_mult = 1

		archer_cavalry_damage_mult = 1
		archer_cavalry_toughness_mult = 1
		camel_cavalry_damage_mult = 1
		camel_cavalry_toughness_mult = 1
		elephant_cavalry_damage_mult = 1
		elephant_cavalry_toughness_mult = 1
		
		gunpowder_damage_mult = 1
		gunpowder_toughness_mult = 1

		siege_weapon_damage_mult = 1
		siege_weapon_toughness_mult = 1
		
		scale = {
			value = marshal_maa_overtime_boost_scale
			divide = 100
			if = {
				limit = {
					scope:councillor_liege = { tgp_has_access_to_ministry_trigger = no }
				}
				multiply = 0
			}
		}
	}
	

	on_start_task = {
		set_variable = { 
			name = marshal_maa_overtime_boost
			value = 0 
		}
		if = {
			limit = {
				any_task_contract = {
					task_contract_type = laamp_help_train_commanders_contract
					NOT = {	task_contract_target = scope:councillor_liege }
				}
				any_player = {
					has_government = landless_adventurer_government
					is_within_diplo_range = { CHARACTER = scope:councillor }
					any_character_task_contract = {
						task_contract_type = laamp_help_train_commanders_contract
						count <= council_task_contracts_limit_value
					}
					can_create_task_contract = {
						type_name = laamp_help_train_commanders_contract
						employer = scope:councillor
					}
					save_temporary_scope_as = player_laamp
				}
			}
			scope:player_laamp = {
				create_task_contract = {
					task_contract_type = laamp_help_train_commanders_contract
					task_contract_tier = scope:councillor.task_contract_tier_value
					location = scope:councillor.councillor_task_target
					task_contract_employer = scope:councillor
					target = scope:councillor_liege
				}
			}
		}
	}

	on_cancel_task = {
		remove_variable = marshal_maa_overtime_boost
	}

	monthly_on_action = train_commanders_monthly_on_action

	on_monthly = {
		if = {
			limit = {
				has_variable = marshal_maa_overtime_boost
				martial > var:marshal_maa_overtime_boost 
			}
			change_variable = {
				name = marshal_maa_overtime_boost
				add = 1
			}
		}
	}

	ai_will_do = {
		value = 0

		#AI does it when they have enough gold
		if = {
			limit = {
				scope:councillor_liege = {
					gold > ai_war_chest_desired_gold_value
					number_of_maa_regiments >= 1
				}
			}
			add = martial
		}

		#AI keeps doing it once it started except if it will go in debt during a war
		if = {
			limit = {
				is_performing_council_task = task_train_commanders
			}
			add = martial
		}
		
		# AI directive
		if = {
			limit = {
				scope:councillor_liege = {
					has_character_flag = vassal_directive_train_commanders
					vassal_is_valid_and_follows_directive_trigger = { VASSAL = this LIEGE = liege }
				}
			}
			add = 10000
		}
	}
}

task_increase_control = {
	position = councillor_marshal

	task_type = task_type_county
	county_target = realm
	ai_county_target = domain
	task_progress = task_progress_value
	task_current_value = scope:councillor_liege.marshal_increase_control_current_progress
	task_max_value = 100 # Highest possible county control
	highlight_own_realm = yes
	restart_on_finish = yes # If it "finishes" by removing a corruption modifier, there'll still be control to regain

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_increase_control.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}

	effect_desc = {
		desc = task_increase_control_effect_desc
		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					scope:councillor_liege = {
						any_active_accolade = {
							accolade_parameter = accolade_increase_control_bonus
						}
					}
				}
				desc = task_increase_control_acclaimed_knight_subdues_peasantry
			}
			triggered_desc = {
				trigger = {
					martial > mediocre_skill_rating
				}
				desc = task_increase_control_increase_opinion
			}
			triggered_desc = {
				trigger = {
					martial > mediocre_skill_rating
				}
				desc = task_increase_control_baron_opinion_increase
			}
			triggered_desc = {
				trigger = {
					martial < high_skill_rating
				}
				desc = task_increase_control_lose_opinion
			}
			triggered_desc = {
				trigger = {
					martial < high_skill_rating
				}
				desc = task_increase_control_lose_control
			}
			triggered_desc = {
				trigger = {
					martial < high_skill_rating
				}
				desc = task_increase_control_baron_opinion_loss
			}
		}
	}
	
	# TOTAL PROGRESS MUST MATCH THE TOTAL OF THE COUNTY MODIFIERS BELOW
		# Add all new progress values to the script value marshal_increase_control_total
		# Note that for Increase Control, the County Modifiers apply the actual values, while progress is for player info only
	progress = {
		value = 0
		add = {
			value = marshal_increase_control_base
			desc = INCREASE_CONTROL_BASE
		}
		add = {
			value = scope:councillor.marshal_increase_county_control_monthly_change
			desc = SCALED_COUNCILLOR_MARTIAL_VALUE
		}
		# Relation Bonuses/Penalties
		if = { # Friend
			limit = {
				scope:councillor_liege = {
					has_relation_friend = scope:councillor
					NOT = { has_relation_best_friend = scope:councillor }
				}
			}
			add = {
				value = scope:councillor.marshal_increase_control_monthly_increase_friend_bonus
				desc = COUNCILLOR_IS_YOUR_FRIEND
			}
		}
		if = { # Best Friend
			limit = {
				scope:councillor_liege = {
					has_relation_best_friend = scope:councillor
				}
			}
			add = {
				value = scope:councillor.marshal_increase_control_monthly_increase_best_friend_bonus
				desc = COUNCILLOR_IS_YOUR_BEST_FRIEND
			}
		}
		if = { # Rival
			limit = {
				scope:councillor_liege = {
					has_relation_rival = scope:councillor
					NOT = { has_relation_nemesis = scope:councillor }
				}
			}
			add = {
				value = scope:councillor.marshal_increase_control_monthly_increase_rival_bonus
				desc = COUNCILLOR_IS_YOUR_RIVAL
			}
		}
		if = { # Nemesis
			limit = {
				scope:councillor_liege = {
					has_relation_nemesis = scope:councillor
				}
			}
			add = {
				value = scope:councillor.marshal_increase_control_monthly_increase_nemesis_bonus
				desc = COUNCILLOR_IS_YOUR_NEMESIS
			}
		}
		if = {
			limit = {
				scope:councillor_liege = { has_perk = strict_organization_perk }
			}
			add = {
				value = scope:councillor.marshal_increase_county_control_perk_bonus_monthly_change
				desc = INCREASE_CONTROL_PERK_BONUS_VALUE
			}
		}
		if = {
			limit = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			add = {
				value = scope:councillor.marshal_increase_county_control_erudition_bonus_monthly_change
				desc = ERUDITION_DYNASTY_PERK_BONUS_VALUE
			}
		}
		if = {
			limit = {
				councillor_liege_has_family_business_bonus = yes
			}
			add = {
				value = scope:councillor.marshal_increase_county_control_family_business_bonus_monthly_change
				desc = FAMILY_BUSINESS_BONUS_VALUE
			}
		}
		if = {
			limit = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			add = {
				value = scope:councillor.marshal_increase_county_control_consulted_house_bonus_monthly_change
				desc = CONSULTED_HOUSE_BONUS_VALUE
			}
		}
		if = {
			limit = {
				scope:councillor = { has_character_modifier = event_bonus_to_county_control }
			}
			add = {
				value = scope:councillor.marshal_increase_county_control_experience_bonus_monthly_change
				desc = INCREASE_COUNTY_CONTROL_EXPERIENCE_BONUS_VALUE
			}
		}
		if = {
			limit = { exists = scope:county }
			multiply = {
				value = scope:county.monthly_county_control_growth_factor
				desc = MARSHAL_COUNTY_SPEED_MODIFIERS
			}
		}
		if = {
			limit = {
				exists = scope:county
				scope:county = { has_county_modifier = petition_liege_county_control_modifier }
			}
			add = {
				value = scope:councillor.petition_liege_county_control_modifier_value
				desc = MARSHAL_INCREASE_CONTROL_LOCAL_COUNTY_MODIFIERS
			}
		}
		#EP3
		if = {
			limit = {
				scope:councillor_liege = {
					employs_court_position = court_jester_court_position
					court_position:court_jester_court_position = {
						has_character_flag = famous_mime_control
					}
				}
			}
			add = {
				value = scope:councillor_liege.court_position:court_jester_court_position.marshal_court_jester_contribution_value
				desc = MARSHAL_INCREASE_CONTROL_MIME_MODIFIER
			}
		}
	}

	full_progress = marshal_increase_control_full_progress
	custom_other_loc = MARSHAL_COUNTY_SPEED_OTHER

	potential_county = {
		scope:county = {
			is_landless_type_title = no
			custom_description = {
				text = potential_county_control_task_trigger
				OR = {
					has_county_corruption_trigger = yes
					county_control < full_county_control
				}
			}
			# If the growth factor is 0, no amount of trying to control helps
			# (happens when the county is under siege/occupied most likely)
			monthly_county_control_growth_factor > 0
		}
	}

	county_modifier = {
		name = marshal_increase_control_modifier
		monthly_county_control_growth_add = 1
		scale = marshal_increase_control_total
	}

	on_start_task_county = {
		#spawn a task contract
		if = {
			limit = {
				scope:councillor_liege = {
					top_liege = this					
				}
				any_player = {
					has_government = landless_adventurer_government
					is_within_diplo_range = { CHARACTER = scope:councillor }
					any_character_task_contract = {
						task_contract_type = laamp_help_increase_control_contract
						count <= council_task_contracts_limit_value
					}
					can_create_task_contract = {
						type_name = laamp_help_increase_control_contract
						employer = scope:councillor
					}
					save_temporary_scope_as = player_laamp
				}
			}
			scope:player_laamp = {
				create_task_contract = {
					task_contract_type = laamp_help_increase_control_contract
					task_contract_tier = scope:councillor.task_contract_tier_value
					location = scope:county.title_province
					task_contract_employer = scope:councillor
					target = scope:councillor.liege
					destination = scope:county.title_province
					save_scope_as = task_contract					
				}
			}
		}
	}
	on_finish_task_county = {
		if = {
			limit = {
				scope:county = {
					has_county_corruption_trigger = yes
				}
			}
			scope:county = {
				marshal_remove_random_county_corruption_modifier_effect = yes
				change_county_control = -25
			}
		}
	}

	monthly_on_action = increase_control_monthly_on_action

	on_monthly_county = {
		random = {
			chance = scope:councillor.marshal_remove_county_corruption_chance
			scope:county = {
				marshal_remove_random_county_corruption_modifier_effect = yes
			}
		}
	}

	ai_will_do = {
		value = 1000 # Highest prio
		if = { # Keep doing Organize levies if you're at war
			limit = {
				scope:councillor_liege = {
					is_at_war = no
				}
			}
			add = 19000
		}
		if = { # Keep doing Organize levies if you're at war
			limit = {
				is_performing_council_task = task_organize_levies
				scope:councillor_liege = {
					is_at_war = yes
				}
			}
			add = -1000
		}
		if = { # Stop doing this if Organize levies could help you lose less gold during a war
			limit = {
				NOT = {
					is_performing_council_task = task_organize_levies
				}
				scope:councillor_liege = {
					is_at_war = yes
					monthly_character_income < monthly_character_expenses
				}
			}
			add = -1000
		}
	}
}

task_manage_guards = {
	position = councillor_marshal

	task_type = task_type_general
	task_progress = task_progress_infinite

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_manage_guards.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}
	
	effect_desc = {
		desc = task_manage_guards_knights_desc
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_manage_guards_erudition_bonus_knights
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_manage_guards_family_business_bonus_knights
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_manage_guards_consulted_house_bonus_knights
		}
		desc = task_manage_guards_scheme_desc
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_manage_guards_erudition_bonus_scheme
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_manage_guards_family_business_bonus_scheme
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_manage_guards_consulted_house_bonus_scheme
		}

		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					martial > mediocre_skill_rating
				}
				desc = task_manage_guards_knight_improved
			}
			triggered_desc = {
				trigger = {
					martial > mediocre_skill_rating
				}
				desc = task_manage_guards_scheme_disrupted
			}
			triggered_desc = {
				trigger = {
					martial < high_skill_rating
				}
				desc = task_manage_guards_knight_wounded
			}
			triggered_desc = {
				trigger = {
					martial < high_skill_rating
				}
				desc = task_manage_guards_disorganized
			}
		}
	}

	is_shown = {
		has_dlc_feature = royal_court
	}

	council_owner_modifier = {
		name = task_manage_guards_knight_modifier
		knight_effectiveness_mult = 1
		scale = {
			value = marshal_overtime_boost_scale
			divide = 100
		}
	}
	council_owner_modifier = {
		name = task_manage_guards_scheme_modifier
		enemy_hostile_scheme_success_chance_add = -1
		scale = {
			value = marshal_overtime_decrease_scale
		}
	}
	
	is_valid_showing_failures_only = {
		scope:councillor_liege = {
			court_grandeur_current_level >= 3
		}
	}

	on_start_task = {
		liege = {
			set_variable = { 
				name = marshal_overtime_boost
				value = 0 
			}
			set_variable = { 
				name = marshal_overtime_decrease
				value = 0 
			}
		}
	}

	on_cancel_task = {
		liege = {
			remove_variable = marshal_overtime_boost
			remove_variable = marshal_overtime_decrease
		}
	}

	monthly_on_action = manage_guards_marshal_task_side_effects

	on_monthly = {
		if = {
			limit = {
				liege = { is_ai = no }
			}
			if = {
				limit = {
					liege = {
						has_variable = marshal_overtime_boost
						var:marshal_overtime_boost < marshal_overtime_boost_max
					}
				}
				liege = {
					change_variable = {
						name = marshal_overtime_boost
						add = root.marshal_overtime_boost_monthly_increase
					}
				}
			}
			if = {
				limit = {
					liege = {
						has_variable = marshal_overtime_decrease
						var:marshal_overtime_decrease > marshal_overtime_decrease_max
					}
				}
				liege = {
					change_variable = {
						name = marshal_overtime_decrease
						add = root.marshal_overtime_decrease_monthly_increase
					}
				}
			}
		}
		else = {
			liege = {
				set_variable = {
					name = marshal_overtime_boost
					value = root.marshal_overtime_boost_monthly_increase
				}
				set_variable = {
					name = marshal_overtime_decrease
					value = root.marshal_overtime_decrease_monthly_increase
				}
			}
		}
	}

	ai_will_do = {
		value = 0

		#AI is more likely to do it the higher the court grandeur level
		if = {
			limit = {
				scope:councillor_liege = {
					court_grandeur_current_level = 3
				}
			}
			add = 1
		}
		if = {
			limit = {
				scope:councillor_liege = {
					court_grandeur_current_level = 4
				}
			}
			add = 5
		}
		if = {
			limit = {
				scope:councillor_liege = {
					court_grandeur_current_level = 5
				}
			}
			add = 10
		}
		if = {
			limit = {
				scope:councillor_liege = {
					court_grandeur_current_level = 6
				}
			}
			add = 15
		}
		if = {
			limit = {
				scope:councillor_liege = {
					court_grandeur_current_level = 7
				}
			}
			add = 20
		}
		if = {
			limit = {
				scope:councillor_liege = {
					court_grandeur_current_level = 8
				}
			}
			add = 25
		}
		if = {
			limit = {
				scope:councillor_liege = {
					court_grandeur_current_level = 9
				}
			}
			add = 30
		}
		if = {
			limit = {
				scope:councillor_liege = {
					court_grandeur_current_level = 10
				}
			}
			add = 35
		}

		#AI keeps doing it once it started
		if = {
			limit = {
				is_performing_council_task = task_manage_guards
			}
			add = martial
		}
	}
}
