﻿begin_conquer_hre_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 12
		empire = 0
		hegemony = 0
	}
	
	desc = begin_conquer_hre_decision_desc
	selection_tooltip = begin_conquer_hre_decision_tooltip
	
	is_shown = {
		is_ai = yes
		game_start_date <= 918.1.1
		game_start_date >= 815.1.1
		current_year > 940
		NOR = {
			has_game_rule = no_conquerors_frequency
			has_game_rule = default_hre_creation
			exists = title:e_hre.holder
		}
		# for partial encouragement rule, this can only be done once
		trigger_if = {
			limit = { has_game_rule = partial_encourage_hre_creation }
			NOT = {
				is_target_in_global_variable_list = {
					name = unavailable_unique_decisions
					target = flag:flag_begin_conquer_hre_decision
				}
			}
		}
		is_hre_candidate_ruler = yes
		can_be_histmod_conqueror = yes
		sub_realm_size >= 15
		# no other HRE candidates who are players or who have larger realms
		NOT = {
			any_independent_ruler = {
				NOT = { this = root }
				is_hre_candidate_ruler = yes
				OR = {
					has_trait = conqueror
					has_character_modifier = ai_weak_conqueror_modifier
					is_ai = no
					AND = {
						can_be_histmod_conqueror = yes
						sub_realm_size > root.sub_realm_size
					}
				}
			}
		}
	}
	
	is_valid_showing_failures_only = {
		is_at_war = no
		is_available_ai_adult = yes
	}
	
	effect = {
		add_gold = 500
		add_prestige = 800
		
		# start the histmod conqueror story
		add_character_flag = histmod_seeking_hre
		create_story = histmod_conqueror_story_cycle
		every_vassal = {
			limit = { has_vassal_stance = glory_hound }
			add_opinion = {
				modifier = approving_opinion
				target = root
				opinion = 20
			}
		}
		every_vassal = {
			limit = { has_vassal_stance = parochial }
			add_opinion = {
				modifier = disapproving_opinion
				opinion = -20
				target = root
			}
		}
		
		# add claims to core kingdoms, if holders exist
		if = {
			limit = {
				exists = title:k_east_francia.holder
				NOR = {
					has_title = title:k_east_francia
					has_claim_on = title:k_east_francia
				}
			}
			add_unpressed_claim = title:k_east_francia
		}
		if = {
			limit = {
				exists = title:k_bavaria.holder
				NOR = {
					has_title = title:k_bavaria
					has_claim_on = title:k_bavaria
				}
			}
			add_unpressed_claim = title:k_bavaria
		}
		if = {
			limit = {
				exists = title:k_italy.holder
				NOR = {
					has_title = title:k_italy
					has_claim_on = title:k_italy
				}
			}
			add_unpressed_claim = title:k_italy
		}
		if = {
			limit = {
				exists = title:k_lotharingia.holder
				NOR = {
					has_title = title:k_lotharingia
					has_claim_on = title:k_lotharingia
				}
			}
			add_unpressed_claim = title:k_lotharingia
		}
		
		# only happens once, if game rule is set to partial encourage
		if = {
			limit = { has_game_rule = partial_encourage_hre_creation }
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_begin_conquer_hre_decision
			}
		}
	}
	
	ai_potential = {
		is_landed = yes
		highest_held_title_tier > tier_duchy
	}

	ai_will_do = {
		base = 100
		modifier = {
			factor = 0
			can_execute_decision = restore_holy_roman_empire_decision
		}
	}
}

begin_hre_war_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 12
		empire = 0
		hegemony = 0
	}

	desc = begin_hre_war_decision_desc
	selection_tooltip = begin_hre_war_decision_tooltip

	is_shown = {
		is_ai = yes
		game_start_date <= 918.1.1
		game_start_date >= 815.1.1
		is_hre_candidate_ruler = yes
		OR = {
			sub_realm_size >= 25
			ai_boldness >= high_positive_ai_value
			has_trait = conqueror
		}
		any_neighboring_top_liege_realm_owner = {
			is_appropriate_hre_war_target = yes
		}
		NOR = {
			exists = title:e_hre.holder
			any_neighboring_top_liege_realm_owner = {
				is_hre_claim_war_target = yes
			}
		}
	}
	
	is_valid_showing_failures_only = {
		is_at_war = no
		is_available_ai_adult = yes
	}
	
	effect = {
		every_neighboring_top_liege_realm_owner = {
			limit = {
				NOR = {
					primary_title = title:e_france
					primary_title = title:k_france
					primary_title = title:k_burgundy
					primary_title = title:k_east_francia
					primary_title = title:k_bavaria
					primary_title = title:k_italy
					primary_title = title:k_lotharingia
				}
				is_better_hre_war_target = yes
			}
			alternative_limit = {
				is_better_hre_war_target = yes
			}
			alternative_limit = {
				NOR = {
					primary_title = title:e_france
					primary_title = title:k_france
					primary_title = title:k_burgundy
					primary_title = title:k_east_francia
					primary_title = title:k_bavaria
					primary_title = title:k_italy
					primary_title = title:k_lotharingia
				}
				is_appropriate_hre_war_target = yes
			}
			alternative_limit = {
				is_appropriate_hre_war_target = yes
			}
			add_to_list = war_targets
		}
		ordered_in_list = {
			list = war_targets
			order_by = military_strength_inverted_hre_score
			save_scope_as = target
			random_realm_county = {
				limit = { is_hre_county_target = yes }
				weight = {
					base = 1
					modifier = {
						add = 250
						duchy = title:d_julich
					}
					modifier = {
						add = 50
						OR = {
							AND = {
								root.capital_county.title_province = { geographical_region = world_europe_west_germania }
								title_province = { geographical_region = world_europe_west_germania }
							}
							AND = {
								root.capital_county.title_province = { geographical_region = custom_northern_italy }
								title_province = { geographical_region = custom_northern_italy }
							}
							AND = {
								root.capital_county.title_province = { geographical_region = custom_burgundy }
								title_province = { geographical_region = custom_burgundy }
							}
						}
					}
					modifier = {
						add = 25
						title_province = { geographical_region = custom_northern_italy }
					}
					modifier = {
						add = 10
						is_better_hre_county_target = yes
					}
				}
				duchy = { save_scope_as = target_duchy }
			}
		}
		start_war = {
			casus_belli = hre_conquest_cb
			target = scope:target
			target_title = scope:target_duchy
		}
		if = {
			limit = {
				scope:target = { highest_held_title_tier > tier_duchy }
			}
			add_gold = 500
		}
		else = {
			add_gold = 250
		}
	}
	
	ai_potential = {
		is_landed = yes
		highest_held_title_tier > tier_duchy
	}
	
	ai_will_do = {
		base = 100
		modifier = {
			factor = 0.5
			is_married = yes
			fertility > 0.10
			primary_spouse = {
				fertility > 0.10
				NOT = { has_trait = pregnant }
			}
			NOR = {
				has_trait = pregnant
				any_child = {
					is_male = yes
					NOT = { has_trait = bastard }
					count > 1
				}
			}
		}
		modifier = {
			factor = 0
			OR = {
				days_of_continuous_peace < 180
				current_military_strength < eighty_percent_of_max_military_strength
			}
		}
		modifier = {
			factor = 0
			gold < 0
		}
		modifier = {
			factor = 0
			has_ongoing_grand_activity_trigger = yes
		}
		modifier = {
			factor = 0
			sub_realm_size >= 140
		}
		modifier = {
			factor = 0
			has_title = title:k_france
		}
		modifier = {
			factor = 0
			OR = {
				can_execute_decision = restore_holy_roman_empire_decision
				can_execute_decision = begin_conquer_hre_decision
			}
		}
	}
}

begin_hre_claim_war_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 12
		empire = 0
		hegemony = 0
	}

	desc = begin_hre_claim_war_decision_desc
	selection_tooltip = begin_hre_claim_war_decision_tooltip

	is_shown = {
		is_ai = yes
		game_start_date <= 918.1.1
		game_start_date >= 815.1.1
		is_hre_candidate_ruler = yes
		OR = {
			sub_realm_size >= 25
			ai_boldness >= high_positive_ai_value
			has_trait = conqueror
		}
		any_neighboring_top_liege_realm_owner = {
			is_hre_claim_war_target = yes
		}
		NOT = { exists = title:e_hre.holder }
	}
	
	is_valid_showing_failures_only = {
		is_at_war = no
		is_available_ai_adult = yes
	}
	
	effect = {
		every_neighboring_top_liege_realm_owner = {
			limit = {
				is_hre_claim_war_target = yes
				save_temporary_scope_as = potential_target
				root = {
					can_declare_war = {
						defender = scope:potential_target
						claimant = root
						casus_belli = claim_cb
						target_titles = { scope:potential_target.primary_title }
					}
				}
			}
			add_to_list = war_targets
		}
		ordered_in_list = {
			list = war_targets
			order_by = military_strength_inverted_hre_score
			save_scope_as = target
		}
		start_war = {
			casus_belli = claim_cb
			target = scope:target
			claimant = root
			target_title = scope:target.primary_title
		}
		add_gold = 500
	}
	
	ai_potential = {
		is_landed = yes
		highest_held_title_tier > tier_duchy
	}
	
	ai_will_do = {
		base = 100
		modifier = {
			factor = 0.5
			is_married = yes
			fertility > 0.10
			primary_spouse = {
				fertility > 0.10
				NOT = { has_trait = pregnant }
			}
			NOR = {
				has_trait = pregnant
				any_child = {
					is_male = yes
					NOT = { has_trait = bastard }
					count > 1
				}
			}
		}
		modifier = {
			factor = 0
			OR = {
				days_of_continuous_peace < 180
				current_military_strength < eighty_percent_of_max_military_strength
			}
		}
		modifier = {
			factor = 0
			gold < 0
		}
		modifier = {
			factor = 0
			has_ongoing_grand_activity_trigger = yes
		}
		modifier = {
			factor = 0
			sub_realm_size >= 140
		}
		modifier = {
			factor = 0
			has_title = title:k_france
		}
		modifier = {
			factor = 0
			OR = {
				can_execute_decision = restore_holy_roman_empire_decision
				can_execute_decision = begin_conquer_hre_decision
			}
		}
	}
}

