﻿###############################################################################
# 
# Miscellaneous Game Start Effects
# 
###############################################################################


# Few special cases where characters will NOT be landed unless the player chooses to
RICE_setup_character_picker_effect = {

	if = {
		limit = {
			#start_date = 867.1.1	
			current_date < 900.1.1
			current_date > 850.1.1		
		}
		# Play as Thabit ibn Qurra
		every_player = {
			limit = {
				OR = {
					has_title = title:c_harran
					has_title = title:d_sunni
				}
				
			}
			trigger_event = harran.0040
		}
	}

	if = {
		limit = {
			#start_date = 1066.9.15	
			current_date < 1100.1.1
			current_date > 1000.1.1		
		}
		# Play as Ibn Nabhan
		every_player = {
			limit = {
				OR = {
					has_title = title:c_harran
					has_title = title:d_sunni
				}
				
			}
			trigger_event = harran.0060
		}
	}

}

RICE_setup_optional_flavor_events_effect = {

	if = {
		limit = {
			#start_date = 867.1.1	
			current_date < 900.1.1
			current_date > 850.1.1
		}

		# Pamir chieftains
		character:RICE_pamir_001 = { # Puteshan
			trigger_event = pamir.0007
		}
		character:RICE_pamir_002 = { # Wakhan
			trigger_event = pamir.0007
		}
		character:RICE_pamir_003 = { # Shugnan
			trigger_event = pamir.0007
		}
		character:RICE_pamir_004 = { # Munjan
			trigger_event = pamir.0007
		}

		# Zunbils
		character:188710 = { 
			# Start off with a few Zunist characters
			if = {
				limit = {
					is_ruler = yes
				}
				every_courtier_or_guest = {
					limit = {
						is_lowborn = yes
					}
					random = {
						chance = 25
						set_character_faith = faith:zun_pagan
					}
				}
			}
			trigger_event = pamir.0017
		}
		character:188712 = { 
			trigger_event = pamir.0017
		}

		# Saffarid situation
		character:163101 = { # Saffirds and vassals
			trigger_event = yazd.0002
			every_vassal_or_below = {
				limit = { # Ignore the Zunbil, who gets his own unique text
					NOT = { has_title = title:c_bost }
				}
				trigger_event = yazd.0002
			}
		}
		character:163100 = { # Tahirids and vassals
			trigger_event = yazd.0002
			every_vassal_or_below = {
				trigger_event = yazd.0002
			}
		}
		# Abd-al-Rahman, Kharijite rebel in Herat c. 872
		character:azariqa_0009 = {
			trigger_event = yazd.0004
		}
		# Ismail Akhdar, follower of Abd-al-Rahman
		character:azariqa_0005 = {
			trigger_event = yazd.0004
		}
		# Esmail ibn Musa, last leader of the Kharijite remnants in Bam
		character:azariqa_0006 = {
			trigger_event = yazd.0004
		}

		# Tulunid/Egypt situation
		character:163115 = { # Tulunids and vassals
			trigger_event = upper_egypt.0001
			every_vassal_or_below = {
				trigger_event = upper_egypt.0001
			}
		}
		character:RICE_upper_egypt_013 = { # Ibn al-Sufi and vassals
			trigger_event = upper_egypt.0001
			every_vassal_or_below = {
				trigger_event = upper_egypt.0001
			}
		}
		character:RICE_upper_egypt_012 = { # al-Tabataba
			trigger_event = upper_egypt.0001
		}

		# Ibn Wahshiyya
		character:RICE_nabati_001 = {
			trigger_event = harran.0013 
		}

	}

	if = {
		limit = {
			#start_date = 1066.9.15	
			current_date < 1100.1.1
			current_date > 1000.1.1			
		}
		character:RICE_kashgar_001 = { # al-Kashgari
			trigger_event = tarim_basin.0200
		}		
		character:45016 = { # Badis ibn Habus
			trigger_event = granada.0001
		}		
		character:8400 = { # Budivoj
			trigger_event = polabian.0010
		}		
		character:20584 = { # Krutoj
			trigger_event = polabian.0011
		}		
		character:20579 = { # Isleifur
			trigger_event = north_atlantic.0270
		}	
		
		
		#sicily.0060
	}

}

RICE_setup_non_optional_flavor_events_effect = {

	if = {
		limit = {
			#start_date = 867.1.1	
			current_date < 900.1.1
			current_date > 850.1.1	
		}
		# al-Umari
		character:bedouin0018 = {
			trigger_event = red_sea.0020
		}
		# Azur Jamshid
		character:RICE_pamir_013 = { # Azur Jamshid
			trigger_event = pamir.0013
		}		
		# Guiyi Circuit switcheroo
		# character:244004 = {
		# 	trigger_event = tarim_basin.0050
		# }
		# Rollo of Normandy
		if = {
			limit = {
				character:242 = {
					is_playable_character = yes
				}
			}
			character:242 = {
				trigger_event = normandy.0080
			}
		}
		else = {
			character:242 = {
				random_list = {
					10 = {
						dynasty = {
							set_dynasty_name = "dynn_RICE_rollo_af_more"
						}
						house = {
							set_house_name = "dynn_RICE_rollo_af_more"
						}
					}
					10 = {
						dynasty = {
							set_dynasty_name = "dynn_RICE_rollo_af_fasge"
						}
						house = {
							set_house_name = "dynn_RICE_rollo_af_fasge"
						}
					}
					10 = {
						dynasty = {
							set_dynasty_name = "dynn_RICE_rollo_placeholder"
						}
						house = {
							set_house_name = "dynn_RICE_rollo_placeholder"
						}
					}
					10 = {
						
					}
				}
			}
		}
		# Bamian kings (Muslim)
		character:RICE_bamian_005 = {
			trigger_event = bamian.0001
		}
		# Bamian kings (Buddhist)
		character:RICE_bamian_008 = {
			trigger_event = bamian.0001
		}
		# Sawdan
		character:163094 = {
			trigger_event = sicily.0064
		}
		# Thabit ibn Qurra
		character:RICE_harran_001 = {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				trigger_event = harran.0041
			}
		}
	}

	if = {
		limit = {
			#start_date = 1066.9.15	
			current_date < 1100.1.1
			current_date > 1000.1.1			
		}
		# Nur Kayani, Azur Jamshid's descendant
		character:RICE_pamir_021 = {
			trigger_event = pamir.0016
		}
		# Ali ibn Asad
		character:badakhshanids_2 = {
			trigger_event = pamir.0009
		}
		# Kakuyids
		character:1231053 = {
			remove_trait = deceitful 	# Let the player choose between deceitful and content
			trigger_event = yazd.0005
		}
		# Qawurd/Qavort, senior Seljuk Prince
		character:3041 = {
			trigger_event = yazd.0008
		}
		# Bartholomew Leslie
		character:RICE_north_atlantic_scottish_001 = {
			trigger_event = north_atlantic.0272
		}
	}

	if = {
		limit = {
			current_date < 1091.1.1
			current_date > 1040.1.1			
		}
		# Non-optional in case a custom ruler is made
		every_ruler = {
			limit = {
				#religion = religion:islam_religion
				highest_held_title_tier >= tier_county
				capital_province ?= {
					geographical_region = RICE_insular_sicily
				}
				any_held_title = {
					tier = tier_county
					any_county_province = {
						geographical_region = RICE_insular_sicily
					}
				}
			}
			trigger_event = sicily.0060
		}
	}

	if = {
		limit = {
			#start_date = 867.1.1	
			current_date < 1180.1.1
			current_date > 1170.1.1	
		}

		# Constance of Brittany
		character:205740 = {
			trigger_event = breton.0001
		}

	}

}



RICE_make_clan_effect = {
	if = {
		limit = {
			OR = {
				culture = {
					OR = {
						has_cultural_pillar = heritage_arabic
						has_cultural_pillar = heritage_iranian
						has_cultural_pillar = heritage_turkic
					}
				}
				religion = religion:islam_religion
			}
			OR = {
				government_has_flag = government_is_feudal
				government_has_flag = government_is_clan
			}
		}
		change_government = clan_government
	}
}

RICE_setup_new_granted_ruler_bonuses_effect = {

	random_list = {
		5 = { add_gold = 20 }
		5 = { add_gold = 30 }
		10 = { add_gold = 40 }
		20 = { add_gold = 50 }
		10 = { add_gold = 60 }
		5 = { add_gold = 70 }
		5 = { add_gold = 80 }
	}

	random_list = {
		10 = { add_piety = 25 }
		10 = { add_piety = 50 }
		5 = { add_piety = 75 }
		5 = { add_piety = 100 }
	}

	random_list = {
		10 = { add_prestige = 25 }
		10 = { add_prestige = 50 }
		5 = { add_prestige = 75 }
		5 = { add_prestige = 100 }
	}

	RICE_make_clan_effect = yes


}




RICE_setup_music_effect = {
	if = {
		limit = {
			NOT = { has_game_rule = RICE_music_off }
			OR = {
				has_game_rule = RICE_music_unrestricted
				culture_has_south_european_heritage_pillar_trigger = yes
				culture_has_north_african_heritage_pillar_trigger = yes
				capital_province = {
					OR = {
						geographical_region = world_europe_west_iberia
						geographical_region = world_europe_south
						geographical_region = world_asia_minor
						geographical_region = world_africa_north
						geographical_region = world_middle_east_jerusalem
					}
				}
				religion = religion:hellenism_religion
			}
		}
		play_music_cue = mx_aegean_sunrise
	}
}


# RICE_setup_admin_government_effect = {
# 	# Rajas of Asia presumably does its own thing
# 	if = {
# 		limit = {
# 			roa_is_active = no
# 		}
# 		if = {
# 			limit = {
# 				exists = title:e_kara_khitai
# 			}
# 			title:e_kara_khitai.holder ?= { RICE_convert_to_administrative_from_feudalism_game_start_khitan_effect = yes }
# 		}
# 		if = {
# 			limit = {
# 				exists = title:k_xia
# 			}
# 			title:k_xia.holder ?= { convert_to_administrative_from_feudalism_game_start_effect = yes }
# 		}
# 		if = {
# 			limit = {
# 				exists = title:k_guiyi
# 			}
# 			title:k_guiyi.holder ?= { RICE_convert_to_administrative_from_feudalism_game_start_dunhuang_effect = yes }
# 		}
# 	}
# }



###############################################################################
# 
# Override Other Mods Game Start Effects
# 	When it is necessary to override other mods that  also use the patented on_game_start effects method of tweaking stuff
# 
###############################################################################


# Stuff that needs to be run after game start for whatever reason
RICE_setup_misc_after_effect = {

	# Landless Adventurer Stuff
	if = {
		limit = {
			has_ep3_dlc_trigger = yes
		}

		### 867 ###

		# Thabit Ibn Qurra
		character:RICE_harran_001 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}
		# Ibn Wahshiyya
		character:RICE_nabati_001 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}	
		# Hiwi al-Balkhi
		character:RICE_bamian_jewish_005 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}
		# al-Balkhi
		character:RICE_afghan_misc_001 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}	
		# Ohthere of Hålogaland
		character:186000 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_explorers
			}
		}	
		# Wulfstan of Hedeby
		character:RICE_north_atlantic_anglo_saxon_001 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_explorers
			}
		}	
		# Ali Kalbid
		character:159195 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_mercenaries
			}
		}	
		# Tughj al-Ikhshid
		character:RICE_ikhshidid_002 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_mercenaries
			}
		}	

		### 1066 ###
		# Bartholomew Leslie
		character:RICE_north_atlantic_scottish_001 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_mercenaries
			}
		}
		# Chakrapani Datta
		character:RICE_magadha_001 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}
		# Ibn Nabhan
		character:RICE_harran_031 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}
		# Nasir Khusraw
		character:persian_scholars_3 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}
		# Longibardopoulos
		character:RICE_sicily_latin_005 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_mercenaries
			}
		}
		# Mahmud al-Kashgari
		character:RICE_kashgar_001 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}
		# Tzachas
		character:34262 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_brigands
			}
		}
		# Ibn al-Qatta' al-Siqilli
		character:RICE_sicily_arabic_006 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}
		# Solomon ibn Gabirol
		character:RICE_granada_008 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}

		### 1178 ###

		# Michael Scot
		character:RICE_north_atlantic_scottish_002 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_scholars
			}
		}
		# Oranmiyan
		character:RICE_niger_delta_001 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_mercenaries
			}
		}
		# Trapelicino
		character:RICE_sicily_latin_009 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_brigands
			}
		}
		# Ikhtiyar al-Din
		character:170252 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_mercenaries
			}
		}
		# Guglielmo Grasso
		character:211532 ?= {
			if = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
				}
				add_realm_law_skip_effects = camp_purpose_brigands
			}
		}
	}

	# Kill off easter egg characters if the game rule to disable them is on
	if = {
		limit = {
			has_game_rule = RICE_easter_egg_characters_removed
		}
		if = {
			limit = {
				exists = character:cybrxkhan_001
				character:cybrxkhan_001 = {
					is_alive = yes
				}			
			}
			character:cybrxkhan_001 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:cybrxkhan_002
				character:cybrxkhan_002 = {
					is_alive = yes
				}			
			}
			character:cybrxkhan_002 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:RICE_easter_egg_001
				character:RICE_easter_egg_001 = {
					is_alive = yes
				}			
			}
			character:RICE_easter_egg_001 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:RICE_easter_egg_002
				character:RICE_easter_egg_002 = {
					is_alive = yes
				}			
			}
			character:RICE_easter_egg_002 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:RICE_easter_egg_003
				character:RICE_easter_egg_003 = {
					is_alive = yes
				}			
			}
			character:RICE_easter_egg_003 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:RICE_easter_egg_004
				character:RICE_easter_egg_004 = {
					is_alive = yes
				}			
			}
			character:RICE_easter_egg_004 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:RICE_easter_egg_005
				character:RICE_easter_egg_005 = {
					is_alive = yes
				}			
			}
			character:RICE_easter_egg_005 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:RICE_easter_egg_006
				character:RICE_easter_egg_006 = {
					is_alive = yes
				}			
			}
			character:RICE_easter_egg_006 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:RICE_easter_egg_007
				character:RICE_easter_egg_007 = {
					is_alive = yes
				}			
			}
			character:RICE_easter_egg_007 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}
		if = {
			limit = {
				exists = character:RICE_easter_egg_008
				character:RICE_easter_egg_008 = {
					is_alive = yes
				}			
			}
			character:RICE_easter_egg_008 = {
				death = {
					death_reason = death_vanished
				}			
			}
		}

	}


	# Spawn a few Mandaean characters
	random_county_in_region = {
		region = RICE_mandaean_heartland
		holder = {
			trigger_event = khuzestan.0001
		}
	}
	random = {
		chance = 66
		random_county_in_region = {
			region = RICE_mandaean_heartland
			holder = {
				trigger_event = khuzestan.0001
			}
		}
	}
	random = {
		chance = 33
		random_county_in_region = {
			region = RICE_mandaean_heartland
			holder = {
				trigger_event = khuzestan.0001
			}
		}
	}

	# Roundabout way to ensure Lady Godiva doesn't get a randomly generated family despite already having one when she gets a landed title
	if = {
		limit = {
			exists = character:161279
			character:161279 = {
				has_trait = celibate
			}
		}
		character:161279 = {
			remove_trait = celibate
		}
	}

	# If player doesn't want to play as Rollo, and doesn't have the game rule where Rollo is always landed, return the title to Rognvaldr
	# if = {
	# 	limit = {
	# 		exists = character:242
	# 		exists = character:186004
	# 		game_start_date = 867.1.1
	# 		NOT = { has_game_rule = RICE_normandy_rollo_always_landed }
	# 		character:242 = {
	# 			is_ai = yes
	# 			# Only if Rollo actually has the title
	# 			# This is for cases where player makes custom character in Trondheim
	# 			has_title = title:c_trandheim 
	# 		}
	# 	}
	# 	character:186004 = {
	# 		get_title = title:c_trandheim
	# 	}
	# 	character:186004 = {
	# 		add_courtier = character:242
	# 	}
	# 	# If Rollo is married or has children
	# 	if = {
	# 		limit = {
	# 			character:242 = {
	# 				is_married = yes
	# 			}
	# 		}
	# 		character:242 = {
	# 			every_spouse = {
	# 				character:186004 = {
	# 					add_courtier = prev
	# 				}					
	# 			}
	# 		}
	# 	}
	# 	if = {
	# 		limit = {
	# 			character:242 = {
	# 				any_child = {
	# 					count >= 1
	# 					is_adult = no
	# 				}
	# 			}
	# 		}
	# 		character:242 = {
	# 			every_child = {
	# 				character:186004 = {
	# 					add_courtier = prev
	# 				}					
	# 			}
	# 		}
	# 	}
	# }

	if = {
		limit = {
			has_game_rule = RICE_yazidi_emergence_default
		}
		# Yazidi appearance event won't happen for a number of years normally
		# Randomized somewhat for some variety
		random_list = {
			# 50 Years
			10 = {
				set_global_variable = {
					name = RICE_yazidi_start_timer
					value = yes
					days = 18250
				}
			}
			# 100 Years
			10 = {
				set_global_variable = {
					name = RICE_yazidi_start_timer
					value = yes
					days = 36500
				}
			}
			# 150 Years
			10 = {
				set_global_variable = {
					name = RICE_yazidi_start_timer
					value = yes
					days = 54750
				}
			}
		}
	}

	if = {
		limit = {
			has_game_rule = RICE_yarsani_emergence_default
		}
		# Yarsani appearance event won't happen for a number of years normally
		# Randomized somewhat for some variety
		random_list = {
			# 50 Years
			10 = {
				set_global_variable = {
					name = RICE_yarsani_start_timer
					value = yes
					days = 18250
				}
			}
			# 100 Years
			25 = {
				set_global_variable = {
					name = RICE_yarsani_start_timer
					value = yes
					days = 36500
				}
			}
			# 150 Years
			25 = {
				set_global_variable = {
					name = RICE_yarsani_start_timer
					value = yes
					days = 54750
				}
			}
		}
	}

	# Move courtiers to the right court since they refuse to go to it for some reason
	# For 1066 bookmark
	if = {
		limit = {
			exists = character:RICE_khuzestan_011
			exists = character:RICE_khuzestan_020
			exists = character:RICE_khuzestan_027
			game_start_date = 1066.9.15
		}
		# Bursuq
		character:RICE_khuzestan_020 = {
			add_courtier = character:RICE_khuzestan_021
			add_courtier = character:RICE_khuzestan_022
			add_courtier = character:RICE_khuzestan_024
			add_courtier = character:RICE_khuzestan_025
			add_courtier = character:RICE_khuzestan_026
		}
		# Hazarasp
		character:RICE_khuzestan_011 = {
			add_courtier = character:1229919
		}
		# Fakhr
		character:RICE_khuzestan_027 = {
			add_courtier = character:RICE_khuzestan_023
		}
	}
	if = {
		limit = {
			current_date < 1075.1.1
			current_date > 1050.1.1		
			character:RICE_kurdish_pagan_001 = {
				is_alive = yes
				is_landed = yes
				is_independent_ruler = no
			}
		}
		# Tirahaye Kurds
		character:RICE_kurdish_pagan_001 = {
			RICE_jizya_contract_at_start_effect = yes
		}
	}
	
	# Clean up Yazidis who shouldn't exist before Yazidism appears
	if = {
		limit = {
			NOT = { has_global_variable = RICE_yazidi_appearance }
		}
		every_county_in_region = {
			region = world_middle_east
			holder = {
				every_courtier_or_guest = {
					limit = {
						faith = faith:yazidi
					}
					set_character_faith = faith:kitebacilweism
				}
			}
		}

		# Can't figure out a way to get rid of pool characters

	}

	# Prevent characters from converting for those who shouldn't be converting
	if = {
		limit = {
			game_start_date = 867.1.1
		}
		character:RICE_bamian_jewish_005 = {
			trigger_event = RICEmisc.0002
		}
		character:RICE_sicily_jewish_001 = {
			trigger_event = RICEmisc.0002
		}
	}
	else_if = {
		limit = {
			game_start_date = 1066.9.15
		}
		character:RICE_bamian_jewish_003 = {
			trigger_event = RICEmisc.0002
		}
	}


	# Change struggle involvement
	if = {
		limit = {
			exists = struggle:iberian_struggle
		}
		# Faiths
		if = {
			limit = {
				NOT = { struggle:iberian_struggle = { is_faith_involved_in_struggle = faith:rabbinism } }
			}
			struggle:iberian_struggle = { set_faith_as_involved = faith:rabbinism }
		}
		if = {
			limit = {
				NOT = { struggle:iberian_struggle = { is_faith_involved_in_struggle = faith:karaism } }
			}
			struggle:iberian_struggle = { set_faith_as_involved = faith:karaism }
		}
	}
	if = {
		limit = {
			exists = struggle:persian_struggle
		}
		# Cultures
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_culture_involved_in_struggle = culture:turco_hephthalite } }
			}
			struggle:persian_struggle = { set_culture_as_involved = culture:turco_hephthalite }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_culture_involved_in_struggle = culture:hephthalite } }
			}
			struggle:persian_struggle = { set_culture_as_involved = culture:hephthalite }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_culture_involved_in_struggle = culture:pamiri } }
			}
			struggle:persian_struggle = { set_culture_as_involved = culture:pamiri }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_culture_involved_in_struggle = culture:khuzi } }
			}
			struggle:persian_struggle = { set_culture_as_involved = culture:khuzi }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_culture_involved_in_struggle = culture:parsim } }
			}
			struggle:persian_struggle = { set_culture_as_involved = culture:parsim }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_culture_involved_in_struggle = culture:bavlim } }
			}
			struggle:persian_struggle = { set_culture_as_involved = culture:bavlim }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_culture_involved_in_struggle = culture:assyrian } }
			}
			struggle:persian_struggle = { set_culture_as_involved = culture:assyrian }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_culture_involved_in_struggle = culture:nabati } }
			}
			struggle:persian_struggle = { set_culture_as_involved = culture:nabati }
		}
		# Faiths
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:rabbinism } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:rabbinism }
		}
		if = {
			limit = {
				NOT = { struggle:iberian_struggle = { is_faith_involved_in_struggle = faith:karaism } }
			}
			struggle:iberian_struggle = { set_faith_as_involved = faith:karaism }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:zun_pagan } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:zun_pagan }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:nuristani_pagan } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:nuristani_pagan }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:manichean } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:manichean }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:mandeaism } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:mandeaism }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:yazidi } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:yazidi }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:meshefaresism } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:meshefaresism }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:kitebacilweism } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:kitebacilweism }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:harranian_pagan } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:harranian_pagan }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:shamsi_pagan } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:shamsi_pagan }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:gayomarthianism } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:gayomarthianism }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:zurvanism } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:zurvanism }
		}
		if = {
			limit = {
				NOT = { struggle:persian_struggle = { is_faith_involved_in_struggle = faith:south_mesopotamian_pagan } }
			}
			struggle:persian_struggle = { set_faith_as_involved = faith:south_mesopotamian_pagan }
		}
	}

	# # Guiyi state religion
	# if = {
	# 	limit = {
	# 		has_dlc_feature = roads_to_power
	# 		exists = title:k_guiyi.holder
	# 	}
	# 	title:k_guiyi = {
	# 		set_state_faith = faith:mahayana
	# 	}
	# }

	# # Xixia state religion
	# if = {
	# 	limit = {
	# 		has_dlc_feature = roads_to_power
	# 		exists = title:k_xia.holder
	# 	}
	# 	title:k_xia = {
	# 		set_state_faith = faith:vajrayana
	# 	}
	# }



}


RICE_setup_override_CE_effect = {

	############################################################
	#
	# HARRAN FLAVOR PACK
	#
	############################################################	

	if = {
		limit = {
			current_date < 1095.1.1
		}
		title:c_harran = {
			set_county_faith = faith:harranian_pagan
		}
	}


	############################################################
	#
	# SAMI PAGAN
	#
	############################################################

	title:c_harjadalen = {
		set_county_faith = faith:sami_pagan
	}
	if = {
		limit = {
			title:c_harjadalen.holder = {
				culture = culture:sami
			}
		}
		title:c_harjadalen.holder = {
			set_character_faith = faith:sami_pagan
			every_courtier_or_guest = {
				limit = {
					culture = culture:sami
				}
				set_character_faith = faith:sami_pagan
			}
		}
	}
	title:c_morarna = {
		set_county_faith = faith:sami_pagan
	}
	if = {
		limit = {
			title:c_morarna.holder = {
				culture = culture:sami
			}
		}
		title:c_morarna.holder = {
			set_character_faith = faith:sami_pagan
			every_courtier_or_guest = {
				limit = {
					culture = culture:sami
				}
				set_character_faith = faith:sami_pagan
			}
		}
	}
	title:c_helgum = {
		set_county_faith = faith:sami_pagan
	}
	if = {
		limit = {
			title:c_helgum.holder = {
				culture = culture:sami
			}
		}
		title:c_helgum.holder = {
			set_character_faith = faith:sami_pagan
			every_courtier_or_guest = {
				limit = {
					culture = culture:sami
				}
				set_character_faith = faith:sami_pagan
			}
		}
	}
	title:c_jamtfir = {
		set_county_faith = faith:sami_pagan
	}
	if = {
		limit = {
			title:c_jamtfir.holder = {
				culture = culture:sami
			}
		}
		title:c_jamtfir.holder = {
			set_character_faith = faith:sami_pagan
			every_courtier_or_guest = {
				limit = {
					culture = culture:sami
				}
				set_character_faith = faith:sami_pagan
			}
		}
	}

}

# RICE_setup_BAP_effect = {	
# 	# faith:oloku_pagan = {
# 	# 	set_variable = { name = has_been_reformed }
# 	# 	remove_doctrine = west_african_unreformed_faith_doctrine
# 	# 	remove_doctrine = doctrine_no_head
# 	# 	add_doctrine = doctrine_temporal_head
# 	# 	set_religious_head_title = title:d_ooni_of_ife
# 	# }
# 	faith:nuristani_pagan = {
# 		add_doctrine = tenet_adaptive
# 	}

# }

# Variation of vanilla's scripted effect "convert_to_administrative_from_feudalism_game_start_effect"
# This one makes it so the Khitan's non-Chinese/Sinic/Khitan vassals remain feudal 
RICE_convert_to_administrative_from_feudalism_game_start_khitan_effect = {
	if = {
		limit = { has_dlc_feature = roads_to_power }
		# Because we run this twice, since folks can change in the lobby.
		if = {
			limit = {
				NOT = { government_has_flag = government_is_administrative }
				house.house_head = {
					NOT = {
						any_held_title = { is_noble_family_title = yes }
					}
				}
			}
			change_government = administrative_government
			create_noble_family_effect = yes
			add_to_list = estatified_list
		}

		every_vassal_or_below = {
			limit = {
				highest_held_title_tier >= tier_county
				OR = {
					culture = culture:khitan
					culture = { has_cultural_pillar = heritage_chinese }
					culture = { has_cultural_pillar = heritage_korean }
					culture = { has_cultural_pillar = heritage_vietic }
				}
				# OR = {
				# 	government_has_flag = government_is_feudal
				# 	government_has_flag = government_is_clan
				# 	government_has_flag = government_is_tribal
				# }
				NOR = {
					faith.religious_head ?= this
					liege = {
						faith.religious_head ?= this
						is_independent_ruler = no
					}
					AND = {
						exists = scope:ignore_culture
						culture = scope:ignore_culture
					}
				}
			}
			change_to_administrative_effect = yes
		}

	}

}

# Variation of vanilla's scripted effect "convert_to_administrative_from_feudalism_game_start_effect"
# This one makes it so the Guiyi's non-Chinese/Sinic/Sogdian vassals remain feudal 
# RICE_convert_to_administrative_from_feudalism_game_start_dunhuang_effect = {
# 	if = {
# 		limit = { has_dlc_feature = roads_to_power }
# 		# Because we run this twice, since folks can change in the lobby.
# 		if = {
# 			limit = {
# 				NOT = { government_has_flag = government_is_administrative }
# 			}
# 			change_government = administrative_government
# 			add_to_list = estatified_list
# 		}

# 		if = {
# 			limit = {
# 				house.house_head = {
# 					NOT = {
# 						any_held_title = { is_noble_family_title = yes }
# 					}
# 				}
# 			}
# 			create_noble_family_effect = yes
# 		}

# 		every_vassal_or_below = {
# 			limit = {
# 				highest_held_title_tier >= tier_county
# 				OR = {
# 					culture = culture:khitan
# 					culture = { has_cultural_pillar = heritage_chinese }
# 					culture = { has_cultural_pillar = heritage_korean }
# 					culture = { has_cultural_pillar = heritage_vietic }
# 					#culture = culture:sogdian
# 				}
# 				NOT = { culture = culture:wenmo } # They should not be admin to reflect their weird situation
# 				# OR = {
# 				# 	government_has_flag = government_is_feudal
# 				# 	government_has_flag = government_is_clan
# 				# 	government_has_flag = government_is_tribal
# 				# }
# 				NOR = {
# 					faith.religious_head ?= this
# 					liege = {
# 						faith.religious_head ?= this
# 						is_independent_ruler = no
# 					}
# 					AND = {
# 						exists = scope:ignore_culture
# 						culture = scope:ignore_culture
# 					}
# 				}
# 			}
# 			change_to_administrative_effect = yes
# 			if = {
# 				limit = {
# 					primary_title.tier = tier_county
# 					OR = {
# 						culture = culture:khitan
# 						culture = { has_cultural_pillar = heritage_chinese }
# 						culture = { has_cultural_pillar = heritage_korean }
# 						culture = { has_cultural_pillar = heritage_vietic }
# 						culture = culture:sogdian
# 					}
# 					house.house_head = {
# 						NOT = {
# 							any_held_title = { is_noble_family_title = yes }
# 						}
# 					}
# 				}
# 				create_noble_family_effect = yes
# 			}
# 		}

# 	}

# }
