namespace = marshal

##############################
# MARSHAL
#
# Job: action_advance_mil_tech
# 	938: Military Accident
# 	939: Military Secrets Revealed!
#
# Job: action_train_troops
# 	941: Reinforcements Arrives
# 	942: Marshal tries to train troops, noble interferes
#
# Job: action_assist_arrest
# 	944: Vassal is tipped off: Starts with Marshal
#
##############################


##############################
# MARSHAL
# JOB: action_advance_mil_tech
##############################

# 938: Military Accident
character_event = {
	id = marshal.001
	title = evt_marshal_001_title
	desc = evt_marshal_001_desc_a
	picture = GFX_evt_bloody_man

	has_job_title = yes

	trigger = {
		has_job_action = action_advance_mil_tech
		can_be_maimed_trigger = yes
		in_seclusion = no

		NOT = {
			has_character_modifier = bedridden_illness
			trait = wounded
		}

		location = {
			owner = {
				job_marshal = {
					character = ROOT
				}
			}
		}
	}

	mean_time_to_happen = {
		years = 20

		job_event_mtth_modifier_inverted_martial_score = yes
		plus_councillor_job_events_opinion_inverted_score = yes

		# CK2Plus
		mult_modifier = {
			factor = 1.33

			ai = no
			has_global_flag = hardcore_mode
		}
	}

	immediate = {
		random_list = {
			75 = {
				trigger = { NOT = { trait = wounded } }
				set_character_flag = marshal_wounded
			}

			25 = { set_character_flag = marshal_maimed  }
		}
	}

	option = {
		name = evt_marshal_001_option_a

		trigger = { has_character_flag = marshal_wounded }

		add_trait_silently_wounded_effect = yes

		liege = {
			show_scope_change = no

			letter_event = {
				id = marshal.002
				days = 7
				tooltip = evt_marshal_001_option_tooltip
			}
		}

		clr_character_flag = marshal_wounded
	}

	option = {
		name = evt_marshal_001_option_b

		trigger = { has_character_flag = marshal_maimed }

		add_maimed_trait_effect = yes

		liege = {
			show_scope_change = no

			letter_event = {
				id = marshal.003
				days = 7
				tooltip = evt_marshal_001_option_tooltip
			}
		}

		clr_character_flag = marshal_maimed
		set_character_flag = limb_removed
	}
}

# 20380: Liege gets a letter about Marshal being wounded
letter_event = {
	id = marshal.002
	desc = evt_marshal_002_desc_a

	is_triggered_only = yes

	option = {
		name = evt_marshal_002_option_a

		tooltip = {
			FROM = {
				show_scope_change = no

				add_trait = wounded
			}
		}
	}
}

# 20381: Liege gets a letter about Marshal being maimed
letter_event = {
	id = marshal.003
	desc = evt_marshal_003_desc_a

	is_triggered_only = yes

	option = {
		name = evt_marshal_003_option_a

		tooltip = {
			FROM = {
				show_scope_change = no

				add_maimed_trait_effect = yes
			}
		}
	}
}


# 939: Military Secrets Revealed!
character_event = {
	id = marshal.101
	title = evt_marshal_101_title
	desc = evt_marshal_101_desc_a
	picture = GFX_evt_large_army

	has_job_title = yes

	trigger = {
		has_job_action = action_advance_mil_tech
		in_seclusion = no
		NOT = { has_character_modifier = bedridden_illness }

		location = {
			owner = {
				job_marshal = {
					character = ROOT
				}
			}

			any_province_lord = {
				martial >= 8
				NOT = { is_liege_of = ROOT }

				OR = {
					trait = gregarious
					diplomacy >= 7
				}

				opinion = {
					who = ROOT
					value >= 30
				}
			}
		}
	}

	mean_time_to_happen = {
		months = 1000

		job_event_mtth_modifier_martial_score = yes
		plus_councillor_job_events_opinion_score = yes

		mult_modifier = {
			factor = 0.5

			OR = {
				has_focus = focus_scholarship
				liege = { has_focus = focus_scholarship }
			}
		}

		mult_modifier = {
			factor = 2
			has_religion_feature = religion_dogmatic
		}
	}

	option = {
		name = evt_marshal_101_option_a

		location = {
			show_scope_change = no

			random_province_lord = {
				show_scope_change = no

				limit = {
					martial >= 8
					NOT = { is_liege_of = ROOT }

					OR = {
						trait = gregarious
						diplomacy >= 7
					}

					opinion = {
						who = ROOT
						value >= 30
					}
				}

				character_event = {
					id = marshal.102
					days = 3
					tooltip = evt_marshal_101_option_a_tooltip
				}
			}
		}
	}
}

# 20390: Noble helps
character_event = {
	id = marshal.102
	desc = evt_marshal_102_desc_a
	picture = GFX_evt_large_army

	is_triggered_only = yes

	option = {
		name = evt_marshal_102_option_a

		FROM = {
			show_scope_change = no

			character_event = {
				id = marshal.103
				days = 3
				tooltip = evt_marshal_102_option_a_tooltip
			}
		}

		ai_chance = {
			factor = 75

			mult_modifier = {
				factor = 1.5

				opinion = {
					who = FROM
					value >= 40
				}
			}

			mult_modifier = {
				factor = 1.5

				opinion = {
					who = FROM
					value >= 50
				}
			}

			mult_modifier = {
				factor = 1.5

				opinion = {
					who = FROM
					value >= 60
				}
			}
		}
	}

	option = {
		name = evt_marshal_102_option_b

		ai_chance = { factor = 25 }
	}
}

# 20391: Inform Marshal
character_event = {
	id = marshal.103
	desc = evt_marshal_103_desc_a
	picture = GFX_evt_large_army

	is_triggered_only = yes

	option = {
		name = evt_marshal_103_option_a

		opinion = {
			name = opinion_grateful
			who = FROM
			years = 5
		}

		liege = {
			show_scope_change = no

			letter_event = {
				id = marshal.104
				tooltip = evt_marshal_103_option_a_tooltip
			}
		}
	}
}

# 20392: Inform Liege
letter_event = {
	id = marshal.104
	desc = evt_marshal_104_desc_a

	is_triggered_only = yes

	option = {
		name = evt_marshal_104_option_a

		military_techpoints = 50

		opinion = {
			name = opinion_grateful
			who = FROM
			years = 5
		}
	}
}


##############################
# MARSHAL
# JOB: action_train_troops
##############################

# 941: Reinforcements Arrive
character_event = {
	id = marshal.201
	title = evt_marshal_201_title
	desc = evt_marshal_201_desc_a
	picture = GFX_evt_large_army

	has_job_title = yes

	trigger = {
		has_job_action = action_train_troops
		in_seclusion = no
		NOT = { has_character_modifier = bedridden_illness }

		location = {
			owner = {
				job_marshal = {
					character = ROOT
				}
			}

			NOT = { has_province_modifier = levy_reinforcements }
		}
	}

	mean_time_to_happen = {
		years = 10

		job_event_mtth_modifier_martial_score = yes
		plus_councillor_job_events_opinion_score = yes

		# CK2Plus
		mult_modifier = {
			factor = 1.33

			ai = no
			has_global_flag = hardcore_mode
		}
	}

	option = {
		name = evt_marshal_201_option_a

		liege = {
			show_scope_change = no

			letter_event = {
				id = marshal.202
				tooltip = EVTTOOLTIP20410
			}
		}
	}
}

# 20410: Inform Liege
letter_event = {
	id = marshal.202
	desc = evt_marshal_202_desc_a

	is_triggered_only = yes
	notification = yes

	immediate = {
		FROM = {
			location = {
				add_province_modifier = {
					name = levy_reinforcements
					years = 1
				}

				increase_prosperity_variable_effect = yes
			}
		}
	}

	option = {
		name = evt_marshal_202_option_a
	}
}

# 942: Marshal tries to train troops, noble interferes
character_event = {
	id = marshal.301
	title = evt_marshal_301_title
	desc = evt_marshal_301_desc_a
	picture = GFX_evt_large_army

	has_job_title = yes

	trigger = {
		has_job_action = action_train_troops
		in_seclusion = no
		NOT = { has_character_modifier = bedridden_illness }

		location = {
			owner = {
				job_marshal = {
					character = ROOT
				}
			}

			any_province_lord = {
				independent = no

				OR = {
					trait = ambitious
					trait = deceitful
				}

				NOR = {
					is_liege_of = ROOT
					character = ROOT
				}
			}

			NOT = { has_province_modifier = levy_reinforcements }
		}
	}

	mean_time_to_happen = {
		years = 60

		job_event_mtth_modifier_inverted_martial_score = yes
		plus_councillor_job_events_opinion_inverted_score = yes
	}

	option = {
		name = evt_marshal_301_option_a

		location = {
			show_scope_change = no

			random_province_lord = {
				show_scope_change = no

				limit = {
					independent = no

					OR = {
						trait = ambitious
						trait = deceitful
					}

					NOR = {
						is_liege_of = ROOT
						character = ROOT
					}
				}

				character_event = {
					id = marshal.302
					days = 7
					tooltip = EVTTOOLTIP20420
				}
			}
		}
	}
}

# 20420: Noble reacts
character_event = {
	id = marshal.302
	desc = evt_marshal_302_desc_a
	picture = GFX_evt_council

	is_triggered_only = yes

	option = {
		name = evt_marshal_302_option_a

		FROM = {
			show_scope_change = no

			liege = {
				show_scope_change = no

				# random = {
				#	chance = 50

					opinion = {
						name = opinion_angry
						who = ROOT
						years = 5
					}

					letter_event = {
						id = marshal.303
						tooltip = EVTTOOLTIP20421
					}
				# }
			}
		}
	}

	option = {
		name = evt_marshal_302_option_b

		ai_chance = { factor = 0 }
	}
}

# 20421: Marshal writes to Liege
letter_event = {
	id = marshal.303
	desc = evt_marshal_303_desc_a

	is_triggered_only = yes
	show_from_from = yes

	option = {
		name = evt_marshal_303_option_a

		FROMFROM = {
			show_scope_change = no

			location = {
				show_scope_change = no

				add_province_modifier = {
					name = missing_reinforcements
					years = 5
				}
			}
		}

		tooltip = {
			opinion = {
				name = opinion_angry
				who = FROM
				years = 5
			}
		}
	}
}

##############################
# MARSHAL
# JOB: action_organize_raid
##############################

# 20221: The Marshal has managed to raise an eager force of raiders
character_event = {
	id = marshal.401
	title = evt_marshal_401_title
	desc = evt_marshal_401_desc_a
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_war

	has_job_title = yes

	trigger = {
		has_job_action = action_organize_raid
		in_seclusion = no
		NOT = { has_character_modifier = bedridden_illness }

		liege = {
			is_adult = yes
			prisoner = no
			is_incapable = no
			war = no

			trigger_if = {
				limit = { has_character_flag = tribal_organize_raid_troops }

				had_character_flag = {
					flag = tribal_organize_raid_troops
					years >= 10
				}
			}
		}

		location = {
			county = {
				is_occupied = no
			}

			ROOT = {
				liege = {
					is_capital = PREVPREV
				}
			}
		}
	}

	mean_time_to_happen = {
		years = 10

		job_event_mtth_modifier_martial_score = yes
		plus_councillor_job_events_opinion_score = yes

		mult_modifier = {
			factor = 3.0
			liege = { real_tier = COUNT }
		}

		mult_modifier = {
			factor = 0.75

			liege = {
				any_owned_bloodline = {
					has_bloodline_flag = more_raiders_bloodline
					bloodline_is_active_for = PREV
				}
			}
		}
	}

	option = {
		name = evt_marshal_401_option_a

		prestige = 50

		liege = {
			character_event = { id = marshal.402 } # Inform liege
		}
	}
}

# 20222: The liege is informed
character_event = {
	id = marshal.402
	desc = evt_marshal_402_desc_a
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				any_owned_bloodline = {
					has_bloodline_flag = more_raiders_bloodline
					bloodline_is_active_for = PREV
				}
			}

			while = {
				count = 3

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = THIS
					match_character = THIS
					match_mult = 0.03
					match_min = 250
					match_max = 5000
					attrition = 1.0
					earmark = tribal_organize_raid
					cannot_inherit = yes
					is_looter = yes
					can_toggle_looting = no
				}
			}
		}

		else = {
			while = {
				count = 3

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = THIS
					match_character = THIS
					match_mult = 0.025
					match_min = 100
					match_max = 3000
					attrition = 1.0
					earmark = tribal_organize_raid
					cannot_inherit = yes
					is_looter = yes
					can_toggle_looting = no
				}
			}
		}

		clr_character_flag = tribal_organize_raid_troops
		set_character_flag = tribal_organize_raid_troops

		character_event = {
			id = marshal.403 # check if troops are raiding
			days = 182
			random = 30
		}
	}

	option = {
		name = evt_marshal_402_option_a

		opinion = {
			name = opinion_grateful
			who = FROM
			years = 5
		}
	}
}

# 20223: Hidden ping event to check the status of the raiders
character_event = {
	id = marshal.403

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		if = {
			limit = { has_earmarked_regiments_not_raiding = tribal_organize_raid }

			if = {
				limit = {
					had_character_flag = {
						flag = tribal_organize_raid_troops
						months >= 4
					}
				}

				character_event = { id = marshal.404 } # Troops disband
			}
			else = {
				repeat_event = {
					id = marshal.403 # check again next month
					days = 30
				}
			}
		}
	}
}

# 20224: The men are displeased and disband
character_event = {
	id = marshal.404
	desc = evt_marshal_404_desc_a
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	option = {
		name = evt_marshal_404_option_a

		scaled_wealth = -0.5
		clr_character_flag = tribal_organize_raid_troops
		disband_event_forces = tribal_organize_raid
	}
}