namespace = martial_strategy

##################################################

#Martial Strategy Lifestyle events

	# 4000		- You visit some baronies or go partying.
	# 4010		- Rebuild the walls of a lesser domain county.
	# 7000		- Why do we keep always charging in a straight line?

##################################################

##################################################
# Stocking the Stores
# by Ewan Cowhig Croft
# 4000
##################################################

#A bumper harvest lets you either eat richly or heavily-stock the stores of your capital.
martial_strategy.4000 = { #by Ewan Cowhig Croft
	type = character_event
	title = martial_strategy.4000.t
	desc = martial_strategy.4000.desc
	theme = martial_strategy_focus
	override_background = {
		reference = feast
	}
	left_portrait = {
		character = root
		animation = drink_goblet
	}

	trigger = {
		is_at_war = no
		is_landed = yes
		NOT = { has_character_flag = had_event_martial_strategy_4000 }
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = martial_strategy_focus }
		upweight_for_focus_modifier = { FOCUS = stewardship_domain_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_martial_strategy_4000
			days = 1825
		}
		capital_county = {
			county = { save_scope_as = harvest_county }
		}
	}

	option = {
		name = martial_strategy.4000.a
		capital_county = {
			add_county_modifier = {
				modifier = strategy_stocked_larders_modifier
				years = 15
			}
		}
		stress_impact = { gluttonous = medium_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_greed_target_modifier = { VALUE = -75 }
			ai_rationality_target_modifier = { VALUE = 75 }
		}
	}
	option = {
		name = martial_strategy.4000.b
		capital_county = {
			add_county_modifier = {
				modifier = strategy_emptied_larders_modifier
				years = 15
			}
		}
		stress_impact = {
			temperate = medium_stress_impact_gain
			gluttonous = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_greed_target_modifier = { VALUE = -50 }
			ai_rationality_target_modifier = { VALUE = 100 }
		}
	}
	option = {
		name = martial_strategy.4000.c
		scope:harvest_county = {
			add_county_modifier = {
				modifier = strategy_fed_peasants_larders_modifier
				years = 15
			}
			add_county_modifier = {
				modifier = strategy_emptied_larders_modifier
				years = 15
			}
		}
		stress_impact = {
			callous = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_greed_target_modifier = { VALUE = 100 }
			ai_rationality_target_modifier = { VALUE = -50 }
		}
	}
	option = {
		name = martial_strategy.4000.d
		trigger = {
			OR = {
				has_trait = cannibal
				has_trait = lunatic
				has_trait = sadistic
				any_secret = { type = secret_cannibal }
				faith = { has_doctrine_parameter = cannibalism_legal }
			}
		}
		trait = cannibal
		trait = lunatic_1
		trait = lunatic_genetic
		trait = sadistic
		capital_county = {
			add_county_modifier = {
				modifier = strategy_human_meat_larders_modifier
				years = 15
			}
			add_county_modifier = {
				modifier = strategy_entirely_unrelated_disappearances_modifier
				years = 15
			}
		}
		if = {
			limit = {
				faith = { has_doctrine_parameter = cannibalism_legal }
			}
			add_piety = major_piety_gain	#Cannibalistic faiths are pretty in to this whole idea.
		}
		else = {
			add_piety = {	#Non-cannibalistic faiths tend to look down on mass-cannibalism.
				value = major_piety_loss
				subtract = medium_piety_value
			}
		}
		if = {
			limit = {
				NOT = { has_trait = cannibal }
			}
			give_cannibal_secret_or_trait_effect = yes
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		if = {
			limit = {
				NOR = {
					has_trait = compassionate
					has_trait = just
				}
			}
			add_stress = major_stress_loss
		}
		ai_chance = {
			base = 100
			ai_compassion_target_modifier = { VALUE = -75 }
			ai_rationality_target_modifier = { VALUE = -75 }
		}
	}
}

##################################################
# The Walls of [Title County Capital]
# by Ewan Cowhig Croft
# 4010
##################################################

scripted_trigger martial_strategy_4010_trigger_evaluation = {
	this != province_owner.capital_province
	is_county_capital = yes
}

#Rebuild the walls of a lesser domain county, or let them crumble.
martial_strategy.4010 = { #by Ewan Cowhig Croft
	type = character_event
	title = martial_strategy.4010.t
	desc = martial_strategy.4010.desc
	theme = martial_strategy_focus
	override_background = {
		reference = study
	}
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:r_architect
		animation = interested
	}

	trigger = {
		is_at_war = no
		NOT = { has_character_flag = had_event_martial_strategy_4010 }
		any_directly_owned_province = { martial_strategy_4010_trigger_evaluation = yes }
		NOT = { government_has_flag = government_is_nomadic }
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = martial_strategy_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_martial_strategy_4010
			days = 1825
		}
		random_directly_owned_province = {
			limit = {
				county.county_control < full_county_control
				martial_strategy_4010_trigger_evaluation = yes
			}
			alternative_limit = {
				always = yes
				martial_strategy_4010_trigger_evaluation = yes
			}
			weight = {
				base = 1
				modifier = {
					add = {
						value = 120
						subtract = county.county_control
					}
				}
			}
			county = { save_scope_as = crumbling_county }
			barony = { save_scope_as = crumbling_holding }
		}
		if = {
			limit = {
				has_royal_court = yes
				employs_court_position = royal_architect_court_position
				any_court_position_holder = {
					type = royal_architect_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = royal_architect_court_position
				limit = { is_available_ai_adult = yes }
				save_scope_as = r_architect
			}
		}
	}

	option = {
		name = martial_strategy.4010.a
		trigger = {
			trigger_if = {
				limit = { is_ai = yes }
				short_term_gold >= major_gold_value
			}
		}
		scope:crumbling_county = {
			add_county_modifier = {
				modifier = strategy_paid_for_walls_modifier
				years = 20
			}
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		add_stewardship_lifestyle_xp = minor_lifestyle_xp
		ai_chance = {
			base = 100
			ai_greed_target_modifier = { VALUE = -100 }
			ai_compassion_target_modifier = { VALUE = 100 }
		}
	}
	option = {
		name = martial_strategy.4010.b
		trigger = {
			OR = {
				has_ep1_court_positions_dlc_trigger = no
				NOT = { exists = scope:r_architect }
			}
		}
		duel = {
			skill = stewardship
			value = high_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.0
				}
				desc = martial_strategy.4010.b.tt_crit_success
				send_interface_toast = {
					title = martial_strategy.4010.b.tt_crit_success
					left_icon = scope:crumbling_county
					scope:crumbling_county = {
						add_county_modifier = {
							modifier = strategy_successfully_supervised_walls_modifier
							years = 100
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.2
				}
				desc = martial_strategy.4010.b.tt_success
				send_interface_toast = {
					title = martial_strategy.4010.b.tt_success
					left_icon = scope:crumbling_county
					scope:crumbling_county = {
						add_county_modifier = {
							modifier = strategy_successfully_supervised_walls_modifier
							years = 20
						}
					}
				}
			}
			10 = {
				desc = martial_strategy.4010.b.tt_botch
				send_interface_toast = {
					title = martial_strategy.4010.b.tt_botch
					left_icon = scope:crumbling_county
					scope:crumbling_county = {
						add_county_modifier = {
							modifier = strategy_botched_supervised_walls_modifier
							years = 20
						}
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { has_trait = architect }
			}
			add_stress = medium_stress_gain
		}
		add_martial_lifestyle_xp = medium_lifestyle_xp
		stress_impact = { architect = medium_stress_impact_loss }
		ai_chance = {
			base = 100
			ai_energy_target_modifier = { VALUE = 100 }
			# Rational characters reasonably estimate their own skill level here.
			modifier = {
				trigger = {
					ai_rationality >= low_positive_ai_value
				}
				add = {
					value = stewardship
					add = -10
					multiply = 10 # -100 at 0 Stewardship, +0 at 10 Stewardship, +100 at 20 Stewardship.
				}
			}
		}
	}

	option = {
		name = martial_strategy.4010.d
		trigger = {
			exists = scope:r_architect
		}
		scope:r_architect = {
			duel = {
				skill = stewardship
				value = high_skill_rating
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.0
					}
					desc = martial_strategy.4010.d.tt_crit_success
					send_interface_toast = {
						title = martial_strategy.4010.d.tt_crit_success
						left_icon = scope:crumbling_county
						scope:crumbling_county = {
							add_county_modifier = {
								modifier = strategy_successfully_supervised_walls_modifier
								years = 100
							}
						}
					}
				}
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.2
					}
					desc = martial_strategy.4010.d.tt_success
					send_interface_toast = {
						title = martial_strategy.4010.d.tt_success
						left_icon = scope:crumbling_county
						scope:crumbling_county = {
							add_county_modifier = {
								modifier = strategy_successfully_supervised_walls_modifier
								years = 20
							}
						}
					}
				}
				5 = {
					desc = martial_strategy.4010.d.tt_botch
					send_interface_toast = {
						title = martial_strategy.4010.d.tt_botch
						left_icon = scope:crumbling_county
						scope:crumbling_county = {
							add_county_modifier = {
								modifier = strategy_botched_supervised_walls_modifier
								years = 20
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = martial_strategy.4010.c
		scope:crumbling_county = {
			add_county_modifier = {
				modifier = strategy_let_walls_crumble_modifier
				years = 20
			}
		}
		add_gold = medium_gold_value
		ai_chance = {
			base = 100
			ai_greed_target_modifier = { VALUE = 100 }
			ai_vengefulness_target_modifier = { VALUE = 100 }
		}
	}
}

namespace = martial_strategy


# Tactics?
# By Isabella Welch

scripted_trigger has_war_elephants = {
	"number_maa_regiments_of_type(war_elephant)" > 0
}

scripted_trigger has_heavy_cavalry = {
	number_maa_regiments_of_base_type = {
		type = heavy_cavalry
		value > 0
	}
}

martial_strategy.7000 = {
	type = character_event
	title = martial_strategy.7000.t
	desc = {
		desc = martial_strategy.7000.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					has_war_elephants = yes
				}
				desc =  martial_strategy.7000.desc_elephantry
			}
			desc = martial_strategy.7000.desc_cavalry
		}

		desc = martial_strategy.7000.desc_middle

		first_valid = {
			triggered_desc = {
				trigger = {
					has_war_elephants = yes
				}
				desc =  martial_strategy.7000.desc_war_elephant
			}
			desc = martial_strategy.7000.desc_armored_horse
		}
		desc = martial_strategy.7000.desc_cont
	}
	theme = martial_strategy_focus
	left_portrait = {
		character = root
		animation = disapproval
	}
	right_portrait = {
		character = scope:worried_knight
		animation = worry
	}
	trigger = {
		any_knight = {
			is_alive = yes
			NOT = { has_trait = brave }
		}
		OR = {
			has_heavy_cavalry = yes
			has_war_elephants = yes
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		random_knight = {
			limit = { NOT = { has_trait = brave } }
			weight = {
				base = 1
				modifier = {
					add = 8
					prowess >= high_skill_rating
				}
				modifier = {
					factor = 4
					is_powerful_vassal = yes
				}
			}
			save_scope_as = worried_knight
		}
	}


	option = {
		name = martial_strategy.7000.a
		trigger = {
			NOT = {
				has_trait = sadistic
			}
		}
		scope:worried_knight = {
			if = {
				limit = {
					is_landed = yes
				}
				add_opinion = {
					target = root
					opinion = -10
					modifier = insulted_opinion
				}
			}
			else = {
				add_opinion = {
					target = root
					opinion = -20
					modifier = insulted_opinion
				}
			}
		}
		add_dread = 10
		add_martial_lifestyle_xp = medium_lifestyle_xp
		ai_chance = {
			base = 100
		}
	}

	option = {
		trigger = {
			NOR = {
				has_trait = strategist
				has_trait_rank = {
					trait = education_martial
					rank >= 2
				}
				"number_maa_regiments_of_type(war_elephant)" > 0
			}
		}
		name = martial_strategy.7000.b
		add_martial_lifestyle_xp = medium_lifestyle_xp
		scope:worried_knight = {
			add_opinion = {
				target = root
				opinion = -15
				modifier = scared_opinion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
			}
		}
		add_prestige = minor_prestige_gain
	}
	option = {
		trigger = {
			has_war_elephants = yes
			NOR = {
				has_trait = strategist
				has_trait_rank = {
					trait = education_martial
					rank >= 2
				}
			}
		}
		name = martial_strategy.7000.c
		add_martial_lifestyle_xp = medium_lifestyle_xp
		scope:worried_knight = {
			if = {
				limit = {
					is_landed = yes
				}
				add_opinion = {
					target = root
					opinion = -20
					modifier = scared_opinion
				}
			}
			else = {
				add_opinion = {
					target = root
					opinion = -40
					modifier = scared_opinion
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 3
			}
		}
		add_prestige = minor_prestige_gain
	}

	option = {
		trigger = {
			OR = {
				has_trait = strategist
				has_trait_rank = {
					trait = education_martial
					rank >= 2
				}
			}
		}
		add_prestige = medium_prestige_gain
		trait = strategist
		trait = education_martial_5
		trait = education_martial_4
		trait = education_martial_3
		name = martial_strategy.7000.d
		add_character_modifier = {
			modifier = crushing_charge_modifier
			years = 10
		}
		add_martial_lifestyle_xp = major_lifestyle_xp
		scope:worried_knight = {
			if = {
				limit = {
					is_landed = yes
				}
				add_opinion = {
					target = root
					opinion = -20
					modifier = annoyed_opinion
				}
			}
			else = {
				add_opinion = {
					target = root
					opinion = -40
					modifier = annoyed_opinion
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 5
			}
		}
	}

	option = {
		name = martial_strategy.7000.e
		add_prestige = minor_prestige_loss
		scope:worried_knight = {
			if = {
				limit = {
					is_landed = yes
						}
				add_opinion = {
					target = root
					opinion = 20
					modifier = pleased_opinion
				}
			}
			else = {
				add_opinion = {
				target = root
				opinion = 40
				modifier = pleased_opinion
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -3
			}
		}
	}
	option = {
		name = martial_strategy.7000.f
		trigger = {
			has_trait = sadistic
		}
		trait = sadistic
		scope:worried_knight = {
			add_opinion = {
				target = root
				opinion = -40
				modifier = hate_opinion
			}
			increase_wounds_effect = { REASON = crushed }
		}
		stress_impact = {
			sadistic = minor_stress_loss
		}
	}
}
