﻿RICE_setup_guanche_flavor_pack_effect = {

	# For other mods that add in Guanche
	culture:guanches = {
		if = {
			limit = { NOT = { has_cultural_tradition = tradition_guanche_warrior } }
			add_culture_tradition = tradition_guanche_warrior
			remove_variable = tradition_cooldown
		}
		# Volcanic Veneration tenet fulfills this more or less
		# if = {
		# 	limit = { NOT = { has_cultural_tradition = tradition_sacred_mountains } }
		# 	add_culture_tradition = tradition_sacred_mountains
		# 	remove_variable = tradition_cooldown
		# }
		set_culture_pillar = language_guanche
	}

	if = {
		limit = {
			exists = culture:guanche
		}
		culture:guanche = {
			add_culture_tradition = tradition_guanche_warrior
			remove_variable = tradition_cooldown
		}
	}

	# Ahaggar holy site
	title:b_ahaggar.title_province = {
		set_holding_type = church_holding
	}

	# Culture and Religion map
	title:c_canarias.holder = {
		make_learn_guanche_language_effect = yes
	}
	title:c_fuerteventura.holder = {
		make_learn_guanche_language_effect = yes
	}
	title:c_madeira.holder = {
		make_learn_guanche_language_effect = yes
	}
	
	# Set up rulers and geography
	# if = {
	# 	limit = {
	# 		title:b_madeira = {
	# 			title_province = { has_special_building = no }
	# 		}
	# 	}
	# 	title:b_madeira.title_province = {
	# 		add_special_building_slot = RICE_guanche_madeira_levadas
	# 	}
	# }	

	# For some reason this is the only way for this to work
	# I think it's stupid as hell jank but gotta do what you gotta do
	# title:c_madeira.title_province = {
	# 	add_building = holy_site_pagan_grand_temple_01
	# 	remove_building = holy_site_pagan_grand_temple_01
	# 	add_special_building_slot = RICE_guanche_madeira_levadas
	# 	add_building = RICE_guanche_madeira_levadas
	# }
	
	# title:c_madeira = {
	# 	add_county_modifier = {
	# 		modifier = RICE_guanche_madeira_timber
	# 	}
	# }

	# Guanche religion tweaks based on BlackEmperor's original Guanche faith in BAP
	# Notes are from BlackEmperor's original implementation as well
	if = {
		limit = {
			has_game_rule = default_gender_equality
		}
		faith:north_african_acham_pagan = {
			#No sign of female rulers in Canarias
			if = {
				limit = { has_doctrine = doctrine_gender_equal }
				remove_doctrine = doctrine_gender_equal
				add_doctrine = doctrine_gender_male_dominated
			}
		}
	}
	faith:north_african_acham_pagan = {
		#Inbreeding between royal families is noted by historians but divine marriage is abit too memey
		if = {
			limit = { has_doctrine = doctrine_consanguinity_cousins }
			remove_doctrine = doctrine_consanguinity_cousins
			add_doctrine = doctrine_consanguinity_unrestricted
		}
	}
	
}

# unite_canary_islands_effect = {
# 	#Create the title and make it primary
# 	create_title_and_vassal_change = {
# 		type = created
# 		save_scope_as = title_change
# 		add_claim_on_loss = no
# 	}
# 	title:k_canary_islands = {
# 		change_title_holder = {
# 			holder = root
# 			change = scope:title_change
# 		}
# 	}
# 	resolve_title_and_vassal_change = scope:title_change
# 	set_primary_title_to = title:k_canary_islands	
# 	set_realm_capital = title:c_canarias
# }

# canary_islands_de_jure_effect = {
# 	title:k_canary_islands = {
# 		set_de_jure_liege_title = title:e_maghreb
# 	}

# 	title:d_canarias = {
# 		set_de_jure_liege_title = title:k_canary_islands
# 	}
	
# 	# Split up de facto Canarias territories
# 	create_character = {
# 		location = root.location
# 		gender = male
# 		faith = root.faith
# 		culture = culture:guanches
# 		random_traits = yes
# 		save_scope_as = fuerteventura_ruler
# 	}
# 	scope:fuerteventura_ruler = {	
# 		get_title = title:c_fuerteventura
# 		add_gold = 25
# 		add_prestige = 100
# 		add_piety = 100
# 	}
# 	create_character = {
# 		location = root.location
# 		gender = male
# 		faith = root.faith
# 		culture = culture:guanches
# 		random_traits = yes
# 		save_scope_as = madeira_ruler
# 	}
# 	scope:madeira_ruler = {	
# 		get_title = title:c_madeira
# 		add_gold = 25
# 		add_prestige = 100
# 		add_piety = 100
# 	}
	
# }

# make_guanche_culture_effect = {
# 	#Convert your, and your whole family's, culture
# 	set_culture = culture:guanches
# 	set_character_faith_with_conversion = faith:north_african_acham_pagan
# 	if = {
# 		limit = {
# 			knows_language = language_berber
# 		}
# 		unlearn_language = language_berber
# 	}
# 	if = {
# 		limit = {
# 			is_married = yes
# 			any_spouse = {
# 				exists = yes
# 				is_landed = no
# 			}
# 		}
# 		every_spouse = {
# 			set_culture = culture:guanches
# 			set_character_faith_with_conversion = faith:north_african_acham_pagan
# 			if = {
# 				limit = {
# 					knows_language = language_berber
# 				}
# 				unlearn_language = language_berber
# 			}
# 		}
# 	}
# 	if = {
# 		limit = {
# 			any_close_family_member = {
# 				exists = yes
# 				is_landed = no
# 			}
# 		}
# 		every_close_family_member = {
# 			custom = all_family_members
# 			limit = {
# 				is_landed = no
# 			}
# 			set_culture = culture:guanches
# 			set_character_faith_with_conversion = faith:north_african_acham_pagan
# 			if = {
# 				limit = {
# 					knows_language = language_berber
# 				}
# 				unlearn_language = language_berber
# 			}
# 		}
# 	}

# 	#Convert appropriate vassals, and their family
# 	if = {
# 		limit = {
# 			any_vassal = {
# 				exists = yes
# 				is_ai = yes
# 				#culture = scope:canary_ruler.culture
# 			}
# 		}
# 		every_vassal = {
# 			limit = {
# 				is_ai = yes
# 				#culture = scope:canary_ruler.culture
# 			}
# 			set_culture = culture:guanches
# 			if = {
# 				limit = {
# 					knows_language = language_berber
# 				}
# 				unlearn_language = language_berber
# 			}
# 			hidden_effect = {
# 				if = {
# 					limit = {
# 						any_spouse = {
# 							exists = yes
# 							is_landed = no
# 						}
# 					}
# 					every_spouse = {
# 						set_culture = culture:guanches
# 						if = {
# 							limit = {
# 								knows_language = language_berber
# 							}
# 							unlearn_language = language_berber
# 						}
# 					}
# 				}
# 				if = {
# 					limit = {
# 						any_close_family_member = {
# 							exists = yes
# 							is_landed = no
# 						}
# 					}
# 					every_close_family_member = {
# 						limit = {
# 							is_landed = no
# 						}
# 						set_culture = culture:guanches
# 						if = {
# 							limit = {
# 								knows_language = language_berber
# 							}
# 							unlearn_language = language_berber
# 						}
# 					}
# 				}
# 			}
# 		}
# 	}
# }

introduce_sugarcane_to_madeira_effect = {
	add_prestige = 200
	title:c_madeira = {
		add_county_modifier = {
			modifier = RICE_guanche_madeira_sugarcane_beginning
			years = 50 #50
		}
	}
}

madeira_sugarcane_crash_effect = {
	remove_character_modifier = RICE_guanche_madeira_owner_timber
	title:c_madeira = {
		remove_county_modifier = RICE_guanche_madeira_timber
		add_county_modifier = {
			modifier = RICE_guanche_madeira_sugarcane_crash
			years = 20
		}
	}
}


make_learn_guanche_language_effect = {
	if = {
		limit = {
			NOT = { knows_language = language_guanche }
		}
		learn_language = language_guanche
	}
	if = {
		limit = {
			knows_language = language_berber
		}
		unlearn_language = language_berber
	}
	if = {
		limit = {
			is_married = yes
			any_spouse = {
				exists = yes
				is_landed = no
			}
		}
		every_spouse = {
			if = {
				limit = {
					NOT = { knows_language = language_guanche }
				}
				learn_language = language_guanche
			}
			if = {
				limit = {
					knows_language = language_berber
				}
				unlearn_language = language_berber
			}
		}
	}
	if = {
		limit = {
			any_close_family_member = {
				exists = yes
				is_landed = no
			}
		}
		every_close_family_member = {
			custom = all_family_members
			limit = {
				is_landed = no
			}
			if = {
				limit = {
					NOT = { knows_language = language_guanche }
				}
				learn_language = language_guanche
			}
			if = {
				limit = {
					knows_language = language_berber
				}
				unlearn_language = language_berber
			}
		}
	}

	#Convert appropriate vassals, and their family
	if = {
		limit = {
			any_vassal = {
				exists = yes
				is_ai = yes
				#culture = scope:canary_ruler.culture
			}
		}
		every_vassal = {
			limit = {
				is_ai = yes
				#culture = scope:canary_ruler.culture
			}
			if = {
				limit = {
					NOT = { knows_language = language_guanche }
				}
				learn_language = language_guanche
			}
			if = {
				limit = {
					knows_language = language_berber
				}
				unlearn_language = language_berber
			}
			hidden_effect = {
				if = {
					limit = {
						any_spouse = {
							exists = yes
							is_landed = no
						}
					}
					every_spouse = {
						if = {
							limit = {
								NOT = { knows_language = language_guanche }
							}
							learn_language = language_guanche
						}
						if = {
							limit = {
								knows_language = language_berber
							}
							unlearn_language = language_berber
						}
					}
				}
				if = {
					limit = {
						any_close_family_member = {
							exists = yes
							is_landed = no
						}
					}
					every_close_family_member = {
						limit = {
							is_landed = no
						}
						if = {
							limit = {
								NOT = { knows_language = language_guanche }
							}
							learn_language = language_guanche
						}
						if = {
							limit = {
								knows_language = language_berber
							}
							unlearn_language = language_berber
						}
					}
				}
			}
		}
	}
}




RICE_guanche_rain_ritual_completed_log_entry_effect = {
	scope:activity = {
		add_activity_log_entry = {
			key = RICE_guanche_rain_ritual_completed_log
			tags = { completed }
			# this line below adds the entry to the Effects section of the conclusion UI
			show_in_conclusion = yes
			character = root
			show_as_tooltip = {
				if = {
					limit = {
						scope:host = {
							has_character_flag = RICE_guanche_rain_ritual_result_amazing
						}
					}
					scope:host = {
						add_piety = 100
					}
					scope:activity.activity_location.county = {
						add_county_modifier = {
							modifier = RICE_guanche_rain_blessing_amazing
							years = 5
						}		
					}
				}
				else_if = {
					limit = {
						scope:host = {
							has_character_flag = RICE_guanche_rain_ritual_result_great
						}
					}
					scope:host = {
						add_piety = 75
					}
					scope:activity.activity_location.county = {
						add_county_modifier = {
							modifier = RICE_guanche_rain_blessing_great
							years = 5
						}		
					}
				}
				else_if = {
					limit = {
						scope:host = {
							has_character_flag = RICE_guanche_rain_ritual_result_good
						}
					}
					scope:host = {
						add_piety = 50
					}
					scope:activity.activity_location.county = {
						add_county_modifier = {
							modifier = RICE_guanche_rain_blessing_good
							years = 5
						}		
					}
				}
				else = {
					scope:host = {
						add_piety = 25
						custom_tooltip = RICE_guanche_rain_blessing_nothing_tooltip
					}
				}
				every_attending_character = {
					limit = { NOT = { this = scope:host } }
					custom = EVERY_ACTIVITY_PARTICIPANT_EFFECT
					add_piety = 25
				}
			}
		}
	}
}





RICE_guanche_benesmen_festival_completed_log_entry_effect = {
	scope:activity = {
		add_activity_log_entry = {
			key = RICE_guanche_benesmen_festival_completed_log
			tags = { completed }
			# this line below adds the entry to the Effects section of the conclusion UI
			show_in_conclusion = yes
			character = root
			show_as_tooltip = {
				add_piety = 25
				add_prestige = 25
				scope:host = {
					add_character_modifier = {
						modifier = RICE_guanche_recently_celebrated_benesmen
						years = 5
					}
				}
				every_attending_character = {
					limit = { NOT = { this = scope:host } }
					custom = EVERY_ACTIVITY_PARTICIPANT_EFFECT
					add_piety = 25
				}
			}
		}
	}
}



