﻿# Scripted Effects for BP2

# Scripted effect to generate a list of relevant characters that might interact with a child
generate_characters_relevant_to_child_list = {
	# Grab any family that's around
	$CHILD$ = {
		every_close_or_extended_family_member = {
			limit = { is_relevant_to_child = yes }
			add_to_list = relevant_characters_to_child_list
		}
	}
	# Grab relevant court folks
	$CHILD$.liege_or_court_owner = {
		every_courtier_or_guest = {
			limit = {
				is_relevant_to_child = yes
			}
			add_to_list = relevant_characters_to_child_list
		}
		every_knight = {
			limit = {
				is_relevant_to_child = yes
			}
			add_to_list = relevant_characters_to_child_list
		}
		every_councillor = {
			limit = { is_relevant_to_child = yes }
			add_to_list = relevant_characters_to_child_list
		}
		every_court_position_holder = {
			limit = { is_relevant_to_child = yes }
			add_to_list = relevant_characters_to_child_list
		}
	}
	$CHILD$ = {
		every_courtier_or_guest = {
			limit = {
				is_relevant_to_child = yes
			}
			add_to_list = relevant_characters_to_child_list
		}
		every_knight = {
			limit = {
				is_relevant_to_child = yes
			}
			add_to_list = relevant_characters_to_child_list
		}
		every_councillor = {
			limit = { is_relevant_to_child = yes }
			add_to_list = relevant_characters_to_child_list
		}
		every_court_position_holder = {
			limit = { is_relevant_to_child = yes }
			add_to_list = relevant_characters_to_child_list
		}
	}
}

# Grab random char relevant to a given child 
grab_char_relevant_to_child = {
	generate_characters_relevant_to_child_list = { CHILD = $CHILD$ }
	random_in_list = {
		list = relevant_characters_to_child_list
		save_scope_as = $SCOPE_OUTPUT$
	}
}

# Grab martial character relevant to a given child
grab_martial_char_relevant_to_child = {
	generate_characters_relevant_to_child_list = { CHILD = $CHILD$ }
	ordered_in_list = {
		list = relevant_characters_to_child_list
		order_by = {
			value = 0
			add = martial
			if = {
				limit = { is_knight = yes }
				add = 25
			}
			if = {
				limit = { has_court_position = bodyguard_court_position }
				add = 20
			}
			if = {
				limit = { has_court_position = akolouthos_court_position }
				add = 20
			}
			if = {
				limit = { has_court_position = master_of_hunt_court_position }
				add = 10
			}
			if = {
				limit = { this = $CHILD$.liege_or_court_owner.cp:councillor_marshal }
				add = 30
			}
			if = {
				limit = { is_close_or_extended_family_of = $CHILD$ }
				add = 10
			}
		}
		save_scope_as = $SCOPE_OUTPUT$
	}
}

# Grab learning character relevant to a given child
grab_learning_char_relevant_to_child = {
	generate_characters_relevant_to_child_list = { CHILD = $CHILD$ }
	ordered_in_list = {
		list = relevant_characters_to_child_list
		order_by = {
			value = 0
			add = learning
			if = {
				limit = { has_court_position = court_physician_court_position }
				add = 20
			}
			if = {
				limit = { has_court_position = court_tutor_court_position }
				add = 20
			}
			if = {
				limit = { has_court_position = court_guru_court_position }
				add = 20
			}
			if = {
				limit = {
					exists = $CHILD$.liege_or_court_owner.cp:councillor_court_chaplain
					this = $CHILD$.liege_or_court_owner.cp:councillor_court_chaplain
				}
				add = 30
			}
			if = {
				limit = {
					$CHILD$ = { is_ruler = yes }
					exists = $CHILD$.cp:councillor_court_chaplain
					this = $CHILD$.cp:councillor_court_chaplain
				}
				add = 50
			}
			if = {
				limit = { is_close_or_extended_family_of = $CHILD$ }
				add = 15
			}
		}
		save_scope_as = $SCOPE_OUTPUT$
	}
}

adopt_cultural_fashion_culture_effect = {
	if = {
		limit = {
			culture = {
				NOT = { has_clothing_gfx = $CULTURE$_clothing_gfx }
			}
			scope:advanced_culture = { has_clothing_gfx = $CULTURE$_clothing_gfx }
		}
		set_variable = {
			name = adopted_cultural_fashion
			value = flag:$CULTURE$
		}
		if = {
			limit = {
				exists = primary_heir
				reverse_opinion = { target = primary_heir value >= 50 }
			}
			primary_heir ?= {
				set_variable = {
					name = adopted_cultural_fashion
					value = flag:$CULTURE$
				}
				custom_tooltip = bp2_yearly.6070.change_clothes_heir
			}
		}
		else = { custom_tooltip = bp2_yearly.6070.change_clothes }
	}
}

adopt_cultural_fashion_effect = {
	save_scope_as = culture_adopter
	if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = byzantine_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = byzantine_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = byzantine }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = indian_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = indian_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = indian }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = mena_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = mena_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = mena }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = african_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = african_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = african }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = northern_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = northern_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = northern }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = iberian_muslim_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = iberian_muslim_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = iberian_muslim }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = iberian_christian_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = iberian_christian_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = iberian_christian }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = mongol_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = mongol_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = mongol }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = fp1_norse_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = fp1_norse_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = fp1_norse }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = western_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = western_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = western }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = dde_hre_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = dde_hre_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = dde_hre }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = dde_abbasid_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = dde_abbasid_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = dde_abbasid }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = iranian_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = iranian_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = iranian }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = turkic_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = turkic_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = turkic }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = afr_berber_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = afr_berber_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = afr_berber }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = west_slavic_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = west_slavic_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = west_slavic }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = french_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = french_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = french }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = east_slavic_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = east_slavic_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = east_slavic }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = sami_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = sami_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = sami }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = ugro_permian_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = ugro_permian_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = ugro_permian }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = chinese_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = chinese_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = chinese }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = japanese_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = japanese_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = japanese }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = malay_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = malay_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = malay }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = southeast_asian_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = southeast_asian_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = southeast_asian }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = korean_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = korean_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = korean }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = papuan_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = papuan_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = papuan }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = viet_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = viet_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = viet }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = tai_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = tai_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = tai }
	}
	else_if = {
		limit = {
			NOT = { culture = { has_clothing_gfx = ainu_clothing_gfx } }
			scope:advanced_culture = { has_clothing_gfx = ainu_clothing_gfx }
		}
		adopt_cultural_fashion_culture_effect = { CULTURE = ainu }
	}
}

bp2_save_traditions_to_consider_effect = {
 	#Choose a category of tradition root is ready to reform and save a valid tradition from that category
    random_list = {
        10 = {
            trigger = {
            	AND = {
    				has_character_flag = foreign_realm_reforms
    				scope:advanced_culture = {
    					any_tradition = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = realm
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    						}
    					}
    				}
    			}
    		}
            scope:advanced_culture = {
    			random_tradition = {
    				limit = {
    					root = {
	    		 			can_embrace_tradition = {
	    		 				tradition = prev
	    		 			}
	    		 		}
    					has_tradition_category = realm
    					NOR = {
    						root = {
    							is_target_in_variable_list = {
    								name = rejected_traditions
    								target = prev
    							}
    						}
    		 				root.culture = {
    		 					has_cultural_tradition = prev
    		 				}
    					}
    				}
    				save_scope_as = considered_tradition_1
    			}
    		}
    		add_character_flag = considering_reform_realm
    	}
    	10 = {
            trigger = {
            	AND = {
    				has_character_flag = foreign_maa_reforms
    				scope:advanced_culture = {
    					any_tradition = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = combat
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    						}
    					}
    				}
    			}
    		}
            scope:advanced_culture = {
    			random_tradition = {
    				limit = {
    					root = {
	    		 			can_embrace_tradition = {
	    		 				tradition = prev
	    		 			}
	    		 		}
    					has_tradition_category = combat
    					NOR = {
    						root = {
    							is_target_in_variable_list = {
    								name = rejected_traditions
    								target = prev
    							}
    						}
    		 				root.culture = {
    		 					has_cultural_tradition = prev
    		 				}
    					}
    				}
    				save_scope_as = considered_tradition_1
    			}
    		}
    		add_character_flag = considering_reform_maa
    	}
    	10 = {
            trigger = {
            	AND = {
    				has_character_flag = foreign_social_reforms
    				scope:advanced_culture = {
    					any_tradition = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = societal
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    						}
    					}
    				}
    			}
    		}
            scope:advanced_culture = {
    			random_tradition = {
    				limit = {
    					root = {
	    		 			can_embrace_tradition = {
	    		 				tradition = prev
	    		 			}
	    		 		}
    					has_tradition_category = societal
    					NOR = {
    						root = {
    							is_target_in_variable_list = {
    								name = rejected_traditions
    								target = prev
    							}
    						}
    		 				root.culture = {
    		 					has_cultural_tradition = prev
    		 				}
    					}
    				}
    				save_scope_as = considered_tradition_1
    			}
    		}
    		add_character_flag = considering_reform_social
    	}
    	10 = {
            trigger = {
            	AND = {
    				has_character_flag = foreign_ritual_reforms
    				scope:advanced_culture = {
    					any_tradition = {
	    		 			root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = ritual
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    						}
    					}
    				}
    			}
    		}
            scope:advanced_culture = {
    			random_tradition = {
    				limit = {
    					root = {
	    		 			can_embrace_tradition = {
	    		 				tradition = prev
	    		 			}
	    		 		}
    					has_tradition_category = ritual
    					NOR = {
    						root = {
    							is_target_in_variable_list = {
    								name = rejected_traditions
    								target = prev
    							}
    						}
    		 				root.culture = {
    		 					has_cultural_tradition = prev
    		 				}
    					}
    				}
    				save_scope_as = considered_tradition_1
    			}
    		}
    		add_character_flag = considering_reform_ritual
    	}
    	10 = {
            trigger = {
            	AND = {
    				scope:advanced_culture = {
    					any_tradition = {
	    		 			root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = regional
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    						}
    					}
    				}
    			}
    		}
            scope:advanced_culture = {
    			random_tradition = {
    				limit = {
    					root = {
	    		 			can_embrace_tradition = {
	    		 				tradition = prev
	    		 			}
	    		 		}
    					has_tradition_category = regional
    					NOR = {
    						root = {
    							is_target_in_variable_list = {
    								name = rejected_traditions
    								target = prev
    							}
    						}
    		 				root.culture = {
    		 					has_cultural_tradition = prev
    		 				}
    					}
    				}
    				save_scope_as = considered_tradition_1
    			}
    		}
    		add_character_flag = considering_reform_regional
    	}
    }
    #PICK A SECOND
    if = {
    	limit = {
    		scope:advanced_culture = {
    			any_tradition = {
	    		 	root = {
	    		 		can_embrace_tradition = {
	    		 			tradition = prev
	    		 		}
	    		 	}
    				NOR = {
    					root = {
    						is_target_in_variable_list = {
    							name = rejected_traditions
    							target = prev
    						}
    					}
    		 			root.culture = {
    		 				has_cultural_tradition = prev
    		 			}
    				}
    				scope:considered_tradition_1 != this
    			}
    		}
    	}
    	random_list = {
        	10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_realm_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = realm
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = realm
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    						}
    					}
    					save_scope_as = considered_tradition_2
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_maa_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = combat
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = combat
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    						}
    					}
    					save_scope_as = considered_tradition_2
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_social_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = societal
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = societal
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    							root.culture = {
    		 							has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    						}
    					}
    					save_scope_as = considered_tradition_2
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_ritual_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = ritual
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = ritual
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    						}
    					}
    					save_scope_as = considered_tradition_2
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = regional
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = regional
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    						}
    					}
    					save_scope_as = considered_tradition_2
    					#this will be the overall flavor
    				}
    			}
    		}
    	}
    }
    # PICK A THIRD
    if = {
    	limit = {
    		scope:advanced_culture = {
    			any_tradition = {
	    		 	root = {
	    		 		can_embrace_tradition = {
	    		 			tradition = prev
	    		 		}
	    		 	}
    				NOR = {
    					root = {
    						is_target_in_variable_list = {
    							name = rejected_traditions
    							target = prev
    						}
    					}
    		 			root.culture = {
    		 				has_cultural_tradition = prev
    		 			}
    				}
    				NOT = {
    					scope:considered_tradition_1 = this
    					scope:considered_tradition_2 = this
    				}
    			}
    		}
    	}
    	random_list = {
        	10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_realm_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = realm
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = realm
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    						}
    					}
    					save_scope_as = considered_tradition_3
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_maa_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = combat
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = combat
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    						}
    					}
    					save_scope_as = considered_tradition_3
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_social_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = societal
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = societal
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    							root.culture = {
    		 							has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    						}
    					}
    					save_scope_as = considered_tradition_3
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_ritual_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = ritual
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = ritual
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    						}
    					}
    					save_scope_as = considered_tradition_3
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = regional
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = regional
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    						}
    					}
    					save_scope_as = considered_tradition_3
    					#this will be the overall flavor
    				}
    			}
    		}
    	}
    }
    #PICK FOURTH
    if = {
    	limit = {
    		scope:advanced_culture = {
    			any_tradition = {
	    		 	root = {
	    		 		can_embrace_tradition = {
	    		 			tradition = prev
	    		 		}
	    		 	}
    				NOR = {
    					root = {
    						is_target_in_variable_list = {
    							name = rejected_traditions
    							target = prev
    						}
    					}
    		 			root.culture = {
    		 				has_cultural_tradition = prev
    		 			}
    				}
    				NOT = {
    					scope:considered_tradition_1 = this
    					scope:considered_tradition_2 = this
    					scope:considered_tradition_3 = this
    				}
    			}
    		}
    	}
    	random_list = {
        	10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_realm_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = realm
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    								scope:considered_tradition_3 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = realm
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    							scope:considered_tradition_3 = this
    						}
    					}
    					save_scope_as = considered_tradition_4
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_maa_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = combat
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    								scope:considered_tradition_3 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = combat
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    							scope:considered_tradition_3 = this
    						}
    					}
    					save_scope_as = considered_tradition_4
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_social_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = societal
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    								scope:considered_tradition_3 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = societal
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    							root.culture = {
    		 							has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    							scope:considered_tradition_3 = this
    						}
    					}
    					save_scope_as = considered_tradition_4
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					has_character_flag = foreign_ritual_reforms
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = ritual
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    								scope:considered_tradition_3 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = ritual
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    							scope:considered_tradition_3 = this
    						}
    					}
    					save_scope_as = considered_tradition_4
    					#this will be the overall flavor
    				}
    			}
    		}
    		10 = {
    	        trigger = {
    	        	AND = {
    					scope:advanced_culture = {
    						any_tradition = {
	    		 				root = {
	    		 					can_embrace_tradition = {
	    		 						tradition = prev
	    		 					}
	    		 				}
    							has_tradition_category = regional
    							NOR = {
    								root = {
    									is_target_in_variable_list = {
    										name = rejected_traditions
    										target = prev
    									}
    								}
    		 						root.culture = {
    		 							has_cultural_tradition = prev
    		 						}
    		 						scope:considered_tradition_1 = this
    								scope:considered_tradition_2 = this
    								scope:considered_tradition_3 = this
    							}
    						}
    					}
    				}
    			}
    	        scope:advanced_culture = {
    				random_tradition = {
    					limit = {
    						root = {
	    		 				can_embrace_tradition = {
	    		 					tradition = prev
	    		 				}
	    		 			}
    						has_tradition_category = regional
    						NOR = {
    							root = {
    								is_target_in_variable_list = {
    									name = rejected_traditions
    									target = prev
    								}
    							}
    		 					root.culture = {
    		 						has_cultural_tradition = prev
    		 					}
    		 					scope:considered_tradition_1 = this
    							scope:considered_tradition_2 = this
    							scope:considered_tradition_3 = this
    						}
    					}
    					save_scope_as = considered_tradition_4
    					#this will be the overall flavor
    				}
    			}
    		}
    	}
    }
}


#Effect to start the story and show the right modifier
start_rock_story_cycle_effect = {
	show_as_tooltip = {
		add_character_modifier = {
			modifier = rock_story_modifier
		}
	}
	hidden_effect = {
		create_story = story_cycle_pet_rock
	}
}

#Pick out name options to show
assign_name_options_rock_story_cycle_effect = {
	random_list = {
		1 = {
			trigger = { NOT = { has_character_flag = name_cliff } }
			add_character_flag = name_cliff
		}
		1 = {
			trigger = {
				NOT = { has_character_flag = name_sandy }
				scope:story.var:rock_color = flag:sandy
			}
			add_character_flag = name_sandy
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_rocky } }
			add_character_flag = name_rocky
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_crag } }
			add_character_flag = name_crag
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_flint } }
			add_character_flag = name_flint
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_gritty } }
			add_character_flag = name_gritty
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_rubble } }
			add_character_flag = name_rubble
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_tuff } }
			add_character_flag = name_tuff
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_roxanne } }
			add_character_flag = name_roxanne
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_rosetta } }
			add_character_flag = name_rosetta
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_chip } }
			add_character_flag = name_chip
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_fluffy } }
			add_character_flag = name_fluffy
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_sten } }
			add_character_flag = name_sten
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_barney } }
			add_character_flag = name_barney
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_ariadne } }
			add_character_flag = name_ariadne
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_dwayne } }
			add_character_flag = name_dwayne
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_potapczyk } }
			add_character_flag = name_potapczyk
		}
		1 = {
			trigger = { NOT = { has_character_flag = name_gemma } }
			add_character_flag = name_gemma
		}
	}
}

#Assign the colour of your rock
assign_rock_color_effect = {
	save_temporary_scope_value_as = {
		name = rock_color
		value = flag:$COLOR$
	}
	if = {
		limit = { scope:rock_color = flag:random }
		hidden_effect = {
			random_list = {
				50 = {
					set_variable = {
						name = rock_color
						value = flag:brown
					}
				}
				50 = {
					set_variable = {
						name = rock_color
						value = flag:gray
					}
				}
				50 = {
					set_variable = {
						name = rock_color
						value = flag:black
					}
				}
				50 = {
					set_variable = {
						name = rock_color
						value = flag:white
					}
				}
				50 = {
					set_variable = {
						name = rock_color
						value = flag:sandy
					}
				}
			}
		}
	}
	else_if = {
		limit = {
			OR = {
				scope:rock_color = flag:brown
				scope:rock_color = flag:gray
				scope:rock_color = flag:black
				scope:rock_color = flag:white
				scope:rock_color = flag:sandy
			}
		}
		set_variable = {
			name = rock_color
			value = flag:$COLOR$
		}
	}
}

#Assign the gender of your rock
assign_rock_gender_effect = {
	save_temporary_scope_value_as = {
		name = gender
		value = flag:$GENDER$
	}
	if = {
		limit = { scope:gender = flag:random }
		hidden_effect = {
			random_list = {
				50 = {
					set_variable = {
						name = rock_gender
						value = flag:female
					}
				}
				50 = {
					set_variable = {
						name = rock_gender
						value = flag:male
					}
				}
			}
		}
	}
	else_if = {
		limit = {
			OR = {
				scope:gender = flag:male
				scope:gender = flag:female
			}
		}
		set_variable = {
			name = rock_gender
			value = flag:$GENDER$
		}
	}
}

#Remove everything related to the rock story
remove_rock_story_modifiers_effect = {
	if = {
		limit = {
			has_character_modifier = rock_story_modifier
		}
		remove_character_modifier = rock_story_modifier
	}
}

remove_rock_name_effect = {
	remove_variable = story_cycle_rock_name
	remove_localized_text = story_cycle_rock_name
}

