﻿
adopt_imperial_administration_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_realm.dds"

	major = yes
	desc = adopt_imperial_administration_decision_desc

	is_shown = {
		OR = {
			has_government = clan_government
			has_government = feudal_government
		}	
		culture = { 
			OR = {
				has_cultural_era_or_later = culture_era_late_medieval
				has_innovation = innovation_imperial_administration
				has_innovation = innovation_roman_administration
			}
		}	
	}
	
	is_valid = {		
		is_independent_ruler = yes
		highest_held_title_tier >= tier_kingdom
		trigger_if = { #somehow lost government, and so can reinstate for free
			limit = { 
				any_held_title = { 
					exists = var:imperial_title 
					var:imperial_title = 1 
				}	
			}
			always = yes
		}
		trigger_else = {
			trigger_if = {
				limit = { culture = { has_innovation = innovation_roman_administration } }
				has_realm_law = crown_authority_1
			}	
			trigger_else = {
				has_realm_law = crown_authority_3
			}	
			stewardship >= 12
			is_at_war = no
			is_imprisoned = no
			is_incapable = no		
		}	
		culture = { 
			OR = {
				has_innovation = innovation_imperial_administration 
				has_innovation = innovation_roman_administration
			}	
		}
	}	

	effect = {
		add_character_flag = { flag = imperial_government_temp_override days = 50 }
		
		primary_title = { save_scope_as = root_primary_title }
		change_government = imperial_government	
		hidden_effect = {
			every_vassal_or_below = {
				limit = {
					primary_title.tier >= tier_county
					OR = {
						has_government = clan_government
						has_government = feudal_government
					}
				}
				add_character_flag = { flag = imperial_autonomy_override days = 7 }
				vassal_contract_set_obligation_level = { type = imperial_autonomy level = 1 }
			}
		}
		if = { #this is not restoring a lost gov type
			limit = {
				NOT = {
					any_held_title = { 
						exists = var:imperial_title 
						var:imperial_title = 1 
					}	
				}
			}
			trigger_event = imperial.0050	
			every_held_title = {
				limit = {
					tier = scope:root_primary_title
					OR = {
						has_title_law = feudal_elective_succession_law
						has_title_law = saxon_elective_succession_law
						has_title_law = scandinavian_elective_succession_law
						has_title_law = gaelic_elective_succession_law
						holder.culture_group = culture_group:byzantine_group
					}
				}
				add_title_law = imperial_elective_succession_law
			}
		}	
		hidden_effect = {
			every_held_title = {
				limit = { tier >= tier_kingdom }
				set_variable = { name = imperial_title value = 1 }
			}
		}
	}

	cost = { 
		prestige = imperial_decision_prestige_cost
		gold = imperial_decision_gold_cost
	}	

	ai_potential = {
		is_independent_ruler = yes
		highest_held_title_tier >= tier_kingdom
	}

	ai_will_do = {
		base = 100	
	}
	ai_check_interval = 6
}

name_co_emperor_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_dynasty_house.dds"

	major = yes
	ai_check_interval = 12

	is_shown = {
		is_landed = yes
		is_independent_ruler = yes
		has_government = imperial_government
		primary_title = {
			has_title_law = imperial_elective_succession_law
		}
		player_heir = { NOT = { has_relation_co_emperor = root } }
	}

	is_valid = {	
		is_physically_able_adult = yes
		custom_description = {
			text = name_co_emperor_decision_candidate
			primary_title = {
				any_election_candidate = {
					this = root.player_heir
				}
			}
		}		
		player_heir = {
			dynasty = root.dynasty
			is_imprisoned = no
			NOT = { has_trait = incapable }
		}	
		trigger_if = {
			limit = { has_culture_group = culture_group:byzantine_group }
			custom_description = {
				text = name_co_emperor_decision_byzantine_heir
				player_heir = {
					byzantine_elective_deformed_candidate_trigger = no
				}	
			}	
		}	
		trigger_if = {
			limit = {
				OR = {
					has_realm_law = male_only_law
					has_realm_law = male_preference_law
				}
			}
			player_heir = { is_female = no }
		}
		trigger_else_if = {
			limit = {
				OR = {
					has_realm_law = female_only_law
					has_realm_law = female_preference_law
				}
			}
			player_heir = { is_female = yes }
		}
		trigger_else = {
			always = yes
		}
	}

	cost = {					
		prestige = 500
		gold = 300
	}

	effect = {
		#for loc
		save_temporary_scope_as = the_emperor
		player_heir = { save_temporary_scope_as = the_player_heir }
		
		hidden_effect = {
			every_relation = { #remove previosu co-emperors
				type = co_emperor
				
				remove_relation_co_emperor = root
				root = { remove_relation_co_emperor = prev }
			}
			player_heir = {
				set_relation_co_emperor = root
				save_scope_as = new_co_emperor
			}
			set_relation_co_emperor = root.player_heir
			set_designated_heir = scope:new_co_emperor
		}
		player_heir = {
			custom_tooltip = name_co_emperor_EFFECT_A
		}	
		trigger_event = {
			id = imperial.0005
		}
	}
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
	
	ai_priority = 100
}


promote_from_bureaucracy_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_realm.dds"
	
	desc = promote_from_bureaucracy_decision_desc

	cooldown = { days = 1095 }

	is_shown = {
		has_government = imperial_government
	}
	
	is_valid = {
	}	

	effect = {
		trigger_event = {
			id = imperial.0040
			days = { 2 5 }
		}

		#Effect tooltip
		custom_tooltip = promote_from_bureaucracy_decision.tt
	}

	cost = { 
		prestige = 100
	}	

	ai_potential = {
		is_at_war = no
		is_imprisoned = no
		gold > 100
	}

	ai_will_do = {
		base = 0
		modifier = {
			add = 100
			OR = {
				cp:councillor_chancellor = {
					diplomacy < very_high_skill_rating
				}
				cp:councillor_steward = {
					stewardship < very_high_skill_rating
				}
				cp:councillor_spymaster = {
					intrigue < very_high_skill_rating
				}
			}
		}		
	}
	ai_check_interval = 60
}
start_military_career_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_invite_knights.dds"

	ai_check_interval = 0

	#cooldown = { days = 3650 }
	
	desc = start_military_career_decision_desc
	
	is_shown = {
		top_liege = { has_government = imperial_government }
		NOT = { has_character_flag = has_asked_for_military_career }
	}
	
	is_valid = {	
		eligible_for_military_career_trigger = yes
		is_at_war = no
	}

	effect = {
		add_character_flag = has_asked_for_military_career
		save_scope_as = military_career_candidate
		custom_tooltip = start_military_career_decision_START
		top_liege = { #find destination court
			random_vassal_or_below = {
				limit = { 
					has_government = military_command
					highest_held_title_tier >= tier_county
					NOT = { this = root }
				}
				show_as_tooltip = {
					root = {
						visit_court_of = prev
					}
				}
				save_scope_as = military_host
			}
		}
		if = {
			limit = { NOT = { scope:military_host = { always = yes } } }
			top_liege = { save_scope_as = military_host }
		}		
		hidden_effect = {
			scope:military_host = {
				trigger_event = military_career.0003
			}
		}
		stress_impact = {
			craven = massive_stress_impact_gain
			brave = medium_stress_impact_loss
			
			lazy = medium_stress_impact_gain
			diligent = medium_stress_impact_loss
			
			content = minor_stress_impact_gain
			ambitious = minor_stress_impact_loss	
		}
	}

	cost = { gold = { value = minor_gold_value } }	

	ai_potential = { #AI uses event
		always = no
	}

	ai_will_do = {
		base = 0
	}
}
retire_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_misc.dds"
	
	desc = retire_decision_desc

	is_shown = {
		OR = {
			has_government = patrician_government
			has_government = military_command
		}	
		is_ruler = yes
	}
	
	is_valid = {
		is_in_an_activity = no
		is_imprisoned = no
		is_at_war = no
		can_retire_military_command_trigger = yes
	}	

	effect = {	
		save_scope_as = retiree
		stress_impact = {	
			lazy = medium_stress_impact_loss
			diligent = medium_stress_impact_gain
			
			arrogant = minor_stress_impact_gain
			humble = minor_stress_impact_loss
			
			content = medium_stress_impact_loss
			ambitious = medium_stress_impact_gain	
		}
		player_heir = {
			stress_impact = {	
				lazy = medium_stress_impact_gain
				diligent = medium_stress_impact_loss
				
				arrogant = minor_stress_impact_loss
				humble = minor_stress_impact_gain
				
				content = medium_stress_impact_gain
				ambitious = medium_stress_impact_loss	
			}
			save_scope_as = player_heir
		}
		hidden_effect = { #Inform relevent characters
			every_player = {
				limit = {
					NOT = { this = scope:retiree }
					OR = {
						is_vassal_or_below_of = scope:retiree
						dynasty = scope:retiree
						this = scope:retiree.player_heir
						AND = {
							scope:retiree = { is_powerful_vassal = yes }
							this = scope:retiree.liege
							liege = scope:retiree.liege						
						}
					}
				}
				send_interface_toast = {
					title = retire_decision_INFORM_TITLE
					left_icon = scope:retiree
					
					custom_tooltip = retire_decision_INFORM_DESC
				}
			}
		}
		custom_tooltip = retire_decision_EFFECT
		hidden_effect = {
			retire_effect = yes
		}
		if = {
			limit = {
				exists = dynasty
			}
			dynasty = {
				add_dynasty_prestige = major_dynasty_prestige_loss
			}
		}
		
		hidden_effect = {
			scope:player_heir = { #move to heir's court
				if = {
					limit = { is_ruler = yes }
					recruit_courtier = scope:retiree
				}
			}
		}
	}

	cost = { 
	}	

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 0
		
		#AI personality
		modifier = { 
			add = { 
				value = root.ai_greed
				multiply = -0.3
				min = -30
				max = 30
			}
		}
		modifier = { 
			add = { 
				value = root.ai_energy
				multiply = -0.3
				min = -30
				max = 30
			}
		}
		modifier = { 
			add = { 
				value = root.ai_honor
				multiply = 0.3
				min = -30
				max = 30
			}
		}
		modifier = {
			add = 10
			stress >= medium_stress
		}
		modifier = {
			add = 10
			stress >= high_stress
		}
		modifier = {
			add = 10
			stress >= very_high_stress
		}
		modifier = {
			add = -10
			age < 50
		}
		modifier = {
			add = 15
			age >= 60
		}
		modifier = {
			add = 10
			age >= 70
		}
		modifier = {
			add = 15
			has_trait = depressed
		}
		modifier = {
			add = 25
			has_trait = incapable
		}
		modifier = {
			add = 10
			OR = {
				has_trait = consumption #2
				has_trait = cancer #3
				has_trait = great_pox #1		
				has_trait = gout_ridden #1.5 	
				has_trait = leper #1.5	  						
			}
		}			
		modifier = {
			add = 10
			has_trait = maimed
		}
		modifier = {
			add = 10
			has_trait = infirm
		}
		modifier = {
			add = 10
			has_trait = blind
		}
	}
	ai_check_interval = 60
}
expand_estates_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_misc.dds"
	
	desc = expand_estates_decision_desc

	cooldown = { days = 1095 }

	is_shown = {
		OR = {
			has_government = imperial_government
			has_government = patrician_government
			has_government = military_command
		}	
		is_ruler = yes
	}
	
	is_valid = {
		NOT = { has_character_modifier = patrician_estate_modifier_6 }
	}	

	effect = {
		gain_one_estate_level_effect = yes
	}

	cost = { 
		gold = estate_buy_value
	}	

	ai_potential = {
		is_at_war = no
		is_imprisoned = no
		short_term_gold > estate_buy_value
	}

	ai_will_do = {
		base = 100
	}
	ai_check_interval = 12
}
sell_estates_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_misc.dds"
	
	desc = sell_estates_decision_desc

	cooldown = { days = 1095 }

	is_shown = {
		has_estates_trigger = yes	
		is_ruler = yes
	}
	
	is_valid = {
		custom_description = {
			text = sell_estates_decision_PATRICIAN_1
			NAND = { 
				has_character_modifier = patrician_estate_modifier_1
				has_government = patrician_government
			}
		}	
	}	

	effect = {
		add_gold = estate_sell_value
		lose_one_estate_level_effect = yes
	}

	cost = { 
	}	

	ai_potential = {
		OR = { #need the gold
			AND = {
				is_at_war = yes
				gold < 50
				monthly_character_balance < 0
			}	
			time_in_prison = { years >= 2 }
			gold < -50
		}
	}

	ai_will_do = {
		base = 100
	}
	ai_check_interval = 36
}
