﻿cfp_headgear_special = {

	usage = game
	selection_behavior = weighted_random
	priority = 6

## Duplicate from vanilla to avoid priority issues

	no_hat = {
		usage = game
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = no_headgear
				value = 0
			}
		}
		outfit_tags = { no_clothes nightgown }
		weight = {
			base = 0
			modifier = {
				add = 10000
				OR = {
					portrait_wear_no_headgear_trigger = yes
					activity_tournament_shirtless_trigger = yes
				}
			}
		}
	}
	
## Junky fix for veils being assigned everywhere
    no_veil = {
        dna_modifiers = {
            accessory = {
                mode = add
                gene = additive_headgear
                template = no_additive
                range = { 0 1 } # For the randomness to work correctly
            }
        }
        weight = {
            base = 0
            modifier = {
                add = 100
				exists = this
				OR = {
					OR = { 
						portrait_wear_armor_trigger = yes
						portrait_wear_armor_currently_in_army_trigger = yes
					}
					portrait_wear_no_headgear_trigger = yes
					NOT = { is_adult = yes }
					AND = {
						is_landed = yes 
						government_has_flag = government_is_theocracy 
					}
				}
            }
        }
    }

## Crowns for specific titles

	### Croatia Kingdom titles	 ###
	croatian_title_royalty = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = epe_crown_titles
				accessory = male_crown_of_zvonimir_01	
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 100
				portrait_crown_of_zvonimir_trigger = yes
			}
			modifier = {
				add = 100
				portrait_crown_of_zvonimir_trigger = yes
				is_female = yes
			}
		}
	}

		### Sicilian Kingdom titles	 ###
		sicily_title_royalty = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = epe_crown_titles
				accessory = m_crown_of_roger_II_01	
			}
		}
			weight = {
				base = 0
				modifier = {
					add = 100
					portrait_crown_of_sicily_trigger = yes
				}
				modifier = {
					add = 100
					portrait_crown_of_sicily_trigger = yes
					is_female = yes
				}
			}
		}

	#Holy Crown of Hungary Late and Early
	
	hungarian_title_royalty_early = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = epe_crown_titles
				accessory = male_epe_holy_crown_of_hungary_01e	
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 100
				portrait_hch_trigger = yes
				has_ep2_dlc_trigger = yes
                OR = {
					portrait_era1_trigger = yes
					portrait_era2_trigger = yes
                }
			}
			modifier = {
				add = 100
				portrait_hch_trigger = yes
				has_ep2_dlc_trigger = yes
                OR = {
					portrait_era1_trigger = yes
					portrait_era2_trigger = yes
                }
				is_female = yes
			}
			
		}
	}	
	
	hungarian_title_royalty_late = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = epe_crown_titles
				accessory = male_epe_holy_crown_of_hungary_01	
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 100
				portrait_hch_trigger = yes
				has_ep2_dlc_trigger = yes
                OR = {
					portrait_era3_trigger = yes
					portrait_era4_trigger = yes
                }
			}
			modifier = {
				add = 100
				portrait_hch_trigger = yes
				has_ep2_dlc_trigger = yes
                OR = {
					portrait_era3_trigger = yes
					portrait_era4_trigger = yes
                }
				is_female = yes
			}
			
		}
	}

#	cfp_hungarian_royalty = {
#		dna_modifiers = {
#			accessory = {
#				mode = add
#				gene = headgear
#				template = cfp_hungarian_royalty
#				range = { 0 1 }
#			}
#		}	
#		weight = {
#			base = 0
#			modifier = {
#				add = 101
#				exists = this
#				NOR = {
#					portrait_wear_no_headgear_trigger = yes
#					portrait_wear_helmet_trigger = yes
#				}
#				portrait_religious_christian_trigger = yes
#				OR = {
#					AND = {
#						exists = this
#						has_primary_title = title:k_hungary
#					}
#					AND = {
#						exists = primary_title
#						has_primary_title = title:e_carpathia
#						has_title = title:k_hungary
#					}
#				}
#			}
#		}
#	}
	
	cfp_albanian_royalty = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = cfp_albanian_royalty
				range = { 0 1 }
			}
		}	
		weight = {
			base = 0
			modifier = {
				add = 101
				exists = this
				NOR = {
					portrait_wear_no_headgear_trigger = yes
					portrait_wear_helmet_trigger = yes
				}
				portrait_era4_trigger = yes
				OR = {
					AND = {
						exists = this
						has_primary_title = title:d_dyrrachion
					}
					AND = {
						exists = this
						has_primary_title = title:k_epirus
					}
				}
			}
		}
	}

#	cfp_croatian_royalty = {
#		dna_modifiers = {
#			accessory = {
#				mode = add
#				gene = headgear
#				template = cfp_croatian_royalty
#				range = { 0 1 }
#			}
#		}
#		weight = {
#			base = 0
#			modifier = {
#				add = 101
#				exists = this
#				NOR = {
#					portrait_wear_no_headgear_trigger = yes
#					portrait_wear_helmet_trigger = yes
#				}
#				portrait_religious_christian_trigger = yes
#				has_primary_title = title:k_croatia
#			}
#		}
#	}
	
	cfp_anglo_saxon_royalty = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = cfp_anglo_saxon_royalty
				range = { 0 1 }
			}
		}	
		weight = {
			base = 0
			modifier = {
				add = 101
				exists = this
				NOR = {
					portrait_wear_no_headgear_trigger = yes
					portrait_wear_helmet_trigger = yes
					has_game_rule = never_cfp_fullplate_helmets
					culture = { has_cultural_era_or_later = culture_era_early_medieval }
				}
				portrait_cfp_anglo_saxon_clothing_trigger = yes
				AND = {
					exists = this
					has_primary_title = title:d_norfolk # East Anglia
				}
			}
		}
	}
	
	cfp_latin_venetian_royalty = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = cfp_latin_venetian_royalty
				range = { 0 1 }
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 101
				exists = this
				NOR = { 
					is_female = yes
					portrait_wear_no_headgear_trigger = yes
					portrait_wear_helmet_trigger = yes
				}
				AND = { 
					exists = this
					has_primary_title = title:k_venice
				}
			}
		}
	}
	
	cfp_iberian_castilian_royalty = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = cfp_iberian_castilian_royalty
				range = { 0 1 }
			}
			accessory = {
				mode = add
				gene = additive_headgear
				template = western_veils
				range = { 0 1 }
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 101
				exists = this
				NOR = {
					portrait_wear_no_headgear_trigger = yes
					portrait_wear_helmet_trigger = yes
				}
				portrait_religious_christian_trigger = yes
				OR = {
					AND = {
						exists = this
						has_primary_title = title:k_castille
					}
					AND = {
						exists = primary_title
						has_primary_title = title:e_spain
						has_title = title:k_castille
					}
				}
			}
		}
	}

	cfp_iberian_aragonese_royalty = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = cfp_iberian_aragonese_royalty
				range = { 0 1 }
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 101
				exists = this
				portrait_era4_trigger = yes
				NOR = {
					portrait_wear_no_headgear_trigger = yes
					portrait_wear_helmet_trigger = yes
				}
				portrait_religious_christian_trigger = yes
				OR = {
					AND = {
						exists = this
						has_primary_title = title:k_aragon
					}
					AND = {
						exists = primary_title
						has_primary_title = title:e_spain
						has_title = title:k_aragon
					}
				}
			}
		}
	}

## Traits ##
	
	cfp_rre_imperial = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = cfp_rre_imperial
				range = { 0 1 }
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 60
				exists = this
				NOR = {
					portrait_wear_no_headgear_trigger = yes
					portrait_wear_helmet_trigger = yes
				}
				portrait_has_trait_trigger = { TRAIT = augustus }
				AND = {
					NOT = { AND = { is_ruler = yes government_has_flag = government_is_mercenary  } } # Blocked for mercenaries
					NOT = { government_has_flag = government_is_republic }
				}
			}
		}
	}

	cfp_trait_laurel_headgear = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = cfp_trait_laurel
				range = { 0 1 }
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 60
				exists = this
				has_personality_extroverted_trigger = yes
				NOR = {
					portrait_wear_no_headgear_trigger = yes
					portrait_wear_helmet_trigger = yes
					government_has_flag = government_is_theocracy
				}
				OR = {
					AND = {
						portrait_has_trait_trigger = { TRAIT = scholar }
						learning >= 26
					}
					AND = {
						portrait_has_trait_trigger = { TRAIT = august }
						diplomacy >= 21
					}
				}
				AND = {
					OR = {
						portrait_western_clothing_trigger = yes
						portrait_byzantine_clothing_trigger = yes
						AND = {
							portrait_northern_clothing_trigger = yes
							NOT = { portrait_cfp_norse_clothing_trigger = yes }
						}
					}
				}
			}
		}
	}

## CFP Fantasy ##

	cfp_fantasy_witches = {
		dna_modifiers = {
			accessory = {
				mode = add
				gene = headgear
				template = cfp_fantasy_witches
				range = { 0 1 }
			}
		}
		weight = {
			base = 0
			modifier = {
				add = 110
				exists = this
				portrait_has_trait_trigger = { TRAIT = witch }
				has_game_rule = ai_cfp_fantasy
				OR = {
					portrait_western_clothing_trigger = yes
					AND = {
						portrait_northern_clothing_trigger = yes
						NOT = { is_theocratic_lessee = yes }
					}
				}
			}
		}
	}
	
}
