# Dynasty decisions are listed for each living dynasty member. The ruler is in the FROM scope.

dynasty_decisions = {

	legitimize_bastard = {
		from_potential = {
			religion_group = christian
			is_playable = yes
		}
		
		potential = {
			trait = bastard
			is_child_of = FROM
			is_liege_or_above = FROM
		}
		allow = {
			FROM = { piety = 20 }
		}
		effect = {
			dynasty = FROM
			remove_trait = bastard
			add_trait = legit_bastard
			recalc_succession = yes
			FROM = { piety = -20 }
			if = {
				limit = {
					prisoner = yes
					host = { character = FROM }
				}
				imprison = no
			}
			
			mother = {
				opinion = {
					who = FROM
					modifier = legitimized_child
					years = 10
				}
			}
			FROM = {
				spouse = {
					if = {
						limit = {
							NOT = {
								any_child = {
									character = ROOT
								}	
							}
						}
						opinion = {
							who = FROM
							modifier = legitimized_bastard
							years = 20
						}
					}
				}
				any_child = {
					limit = {
						NOT = { character = ROOT }
						dynasty = FROM
						NOT = { trait = bastard }
					}
					opinion = {
						who = FROM
						modifier = legitimized_bastard
						months = 12
					}
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	# Muslim ruler tries to convince a dynasty member to lose the 'Decadent' Trait
	convince_to_straighten_up = {
	
		hide_in_decisions_list = yes # This decision is only shown in the Religion View for each decadent character
		
		from_potential = {
			is_playable = yes
			religion_group = muslim
			father_even_if_dead = {
				OR = {
					is_alive = no
					is_playable = no
				}
			}
		}
		
		potential = {
			is_female = no
			prisoner = no
			trait = decadent
			has_regent = no
			lower_tier_than = FROM
		}
		
		allow = {
			FROM = {
				piety = 100
				prisoner = no
				has_regent = no
				NOT = { trait = decadent }
				# Additional check so only head of dynasty can do this
				# This is not perfect, but might be the best check scripting can do for this
				NOT = {
					custom_tooltip = {
						text = "REQUIREMENT_HEAD_OF_DYNASTY"
						any_dynasty_member = {
							higher_tier_than = PREV
							is_playable = yes
							religion_group = muslim
							father_even_if_dead = {
								OR = {
									is_alive = no
									is_playable = no
								}
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = "NOT_ALREADY_NEGOTIATED"
				# NOT = { has_character_flag = negotiated_to_drop_decadence }
				NOT = {
					has_opinion_modifier = { who = FROM modifier = opinion_negotiated_to_drop_decadence }
				}
			}
		}
		effect = {
			FROM = { piety = -100 }
			
			# set_character_flag = negotiated_to_drop_decadence
			opinion = {
				modifier = opinion_negotiated_to_drop_decadence
				who = FROM
				months = 2400
			}
			# remove_opinion = { who = FROM modifier = opinion_negotiated_to_drop_decadence }
			
			# Moved character event to the bottom to fix sticky flag on instant cleanup as well
			character_event = {
				id = 91350
			}
		}
		
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
			# This was added in the hotfix, but it clashes with the "head of dynasty" limit in this mod
			#modifier = {
			#	factor = 0
			#	NOT = {
			#		is_liege_or_above = FROM
			#	}
			#}
		}
	}

}
