﻿yearly_global_pulse = {
	on_actions = { RICE_BAP_shared_yearly_global_pulse }
}


yearly_playable_pulse = {
	on_actions = {
		delay = { days = { 8 288 } }
		RICE_BAP_shared_events_yearly_pulse
		delay = { days = { 8 288 } }
		RICE_BAP_shared_events_historical_pulse
	}
}
three_year_playable_pulse = {
	on_actions = {
		delay = { days = { 8 288 } }
		RICE_BAP_shared_events_tri_yearly_pulse
	}
}
five_year_playable_pulse = {
	on_actions = {
		delay = { days = { 8 288 } }
		RICE_BAP_shared_events_five_yearly_pulse
		delay = { days = { 8 288 } }
		RICE_BAP_events_courtier_yearly_pulse
	}
}

# Called from code once a year for all characters, at a random point that year (individually for each character)
# Root is the character
random_yearly_everyone_pulse = {
	on_actions = {
		RICE_BAP_shared_maintenance_pulse
	}
}

RICE_BAP_shared_yearly_global_pulse = {
	effect = {
		# Don't want it to be given randomly way after the decision is taken
		if = {
			limit = {
				is_target_in_global_variable_list = {
					name = unavailable_unique_decisions
					target = flag:declare_canarias_decision
				}
				NOT = { has_global_variable = RICE_guanche_kingdom_deadline_set }
			}
			set_global_variable = {
				name = RICE_guanche_kingdom_deadline_set
				value = yes
			}
			set_global_variable = {
				name = RICE_canarias_kingdom_decision_bonus_event_timer
				value = yes
				days = 1095
			}
		}
		if = {
			limit = {
				exists = title:k_canarias.holder
				title:k_canarias.holder = {
					OR = {
						religion = religion:north_african_religion
						culture = {
							OR = {
								this = culture:guanches
								any_parent_culture_or_above = {
									this = culture:guanches
								}
							}
						}
					}
				}
				is_target_in_global_variable_list = {
					name = unavailable_unique_decisions
					target = flag:declare_canarias_decision
				}
				has_global_variable = RICE_canarias_kingdom_decision_bonus_event_timer
			}
			remove_global_variable = RICE_canarias_kingdom_decision_bonus_event_timer
			title:k_canarias.holder = {
				trigger_event = guanche.0005
			}
		}



		# Fandaanano emerges if no one takes the decision
		if = {
			limit = {
				NOT = { has_global_variable = RICE_game_started_on_TFE_start_date }
				NOT = {
					is_target_in_global_variable_list = {
						name = unavailable_unique_decisions
						target = flag:south_ethiopia_fandaanano_established
					}
				}
				current_date >= 1250.1.1
				any_county_in_region = {
					region = RICE_south_ethiopia_region
					holder = {
						is_ai = no
					}
					OR = {
						religion = religion:islam_religion
						religion = religion:sidamic_religion
						religion = religion:waaqism_religion
					}
				}
			}
			
			random = {
				chance = 5 # 99
				modifier = {
					add = 10
					current_date >= 1350.1.1
				}
				modifier = {
					add = 10
					current_date >= 1375.1.1
				}
				modifier = {
					add = 20
					current_date >= 1400.1.1
				}
				modifier = {
					add = 20
					current_date >= 1425.1.1
				}
				RICE_fandaanano_appearance_effect = yes
			}
		}

	}
}

# RICE Flavor Events
RICE_BAP_shared_events_yearly_pulse = {
	trigger = {
		basic_is_valid_for_yearly_events_trigger = yes
	}
	random_events = {
		chance_of_no_event = {
			value = 25
		}
		
		2000 = 0
		
		# GUANCHE		
		10 = guanche.0061		# Meeting other important people at a tagoror
		10 = guanche.0063		# Observing a Shepherd's Leap competition
		10 = guanche.0064		# Guanche necklace
		10 = guanche.0065		# Guanche fire offerings - good
		10 = guanche.0066		# Guanche fire offerings - bad
		10 = guanche.0067		# Pass by a Guanche lithophone

		# NIGER DELTA
		10 = niger_delta.0100	# Elephant was recently killed by hunters - share the elephant meat or not? Based on a legend from Benin
		10 = niger_delta.0101	# Eating pounded yams
		10 = niger_delta.0104	# Woman collecting water for water pots at Yoruba shrine
		10 = niger_delta.0109	# Chew more kola nuts or not?
		10 = niger_delta.0110	# Breaking in the kola nut every morning
		10 = niger_delta.0111	# Welcome a prominent visitor with a kola nut

		# BOZO
		10 = bozo.0050		 			# Maintenance for an existing mud structure
		10 = bozo.0051		 			# Secrets of the mud masons?

		# TUAREG
		10 = tuareg.0052	 			# Eating Taguella

		# SOUTH ETHIOPIA
		10 = south_ethiopia.0091 		# Learning about "male" vs "female" enset varieties
		10 = south_ethiopia.0092 		# Discussing plans for agricultural walls with a local committee
		10 = south_ethiopia.0095 		# Eating Kocho
		
	}
}


# RICE Flavor Events
RICE_BAP_shared_events_tri_yearly_pulse = {
	trigger = {
		basic_is_valid_for_yearly_events_trigger = yes
	}
	random_events = {
		chance_of_no_event = {
			value = 25
		}
		
		2000 = 0
		
		# GUANCHE		
		10 = guanche.0060		# Rumors of tibicena nearby
		10 = guanche.0062		# Got new whistlers (el silbo - once widespread in the Canaries but now limited to La Gomera)
		10 = guanche.0068		# What to do about Guanche mummies found nearby?

		# NIGER DELTA
		10 = niger_delta.0102 	# Ọmọge omi / Daughter of the water
		10 = niger_delta.0105 	# Wooden decor, Yoruba style?
		10 = niger_delta.0106 	# Ancient bronze head is discovered - what to do with it?
		10 = niger_delta.0107 	# Glassmakers doing well
		10 = niger_delta.0108 	# Envoys return from trip to Ife

		# BOZO
		10 = bozo.0053		 			# Extra protection for a new site or not?

		# TUAREG
		10 = tuareg.0050	 			# Kel Tagelmust is not approved by other cultures
		10 = tuareg.0053	 			# Inadan artisans/smiths gain renown
		10 = tuareg.0054	 			# Encounter tifnagh inscriptions

		# SOUTH ETHIOPIA
		10 = south_ethiopia.0093		# Locals demand you move undesirable artisans elsewhere
		10 = south_ethiopia.0094		# Sitting with a council of local leaders to determine how to make use of collective land, in the Sidama fashion
		10 = south_ethiopia.0096		# Planting more enset trees?
		
	}
}


# RICE Flavor Events
RICE_BAP_shared_events_five_yearly_pulse = {
	trigger = {
		basic_is_valid_for_yearly_events_trigger = yes
	}
	random_events = {
		chance_of_no_event = {
			value = 25
		}
		
		2000 = 0
		
		# NIGER DELTA		
		10 = niger_delta.0103 	# Prominent blacksmith claims to have met a water spirit
		10 = niger_delta.0112 	# Judgment using a kola nut

		# BOZO
		10 = bozo.0052		 			# New mason contract

		# TUAREG
		10 = tuareg.0051	 			# Courtier has takarakit, or reserve

		# SOUTH ETHIOPIA
		10 = south_ethiopia.0090		# Courtier gains the Cattle Counting trait
		
	}
}

# RICE historical events
RICE_BAP_shared_events_historical_pulse = {
	random_events = {
		chance_of_no_event = {
			value = 20
		}
		
		1000 = 0
		
		# GUANCHE
		100 = guanche.0052		# Sugarcane industry on Madeira crashes due to deforestation
		100 = guanche.0054		# Sugarcane industry spreads to the Canary Islands
		
	}
}

# Misc cleanup and failsafe effects
RICE_BAP_shared_maintenance_pulse = {
	effect = {
		root = {
			# Failsafe in case character has Uncrowned modifier when they shouldn't
			if = {
				limit = {
					has_character_modifier = RICE_niger_delta_uncrowned
					OR = {
						has_character_flag = RICE_niger_delta_received_beaded_crown
						any_held_title = { is_head_of_faith = yes }
						NOT = { religion = religion:west_african_orisha_religion }
						is_landed = no
						has_title = title:d_ooni_of_ife
						primary_title.tier = tier_barony
						is_landless_adventurer = yes
					}
				}
				remove_character_modifier = RICE_niger_delta_uncrowned
			}
		}
	}
}


# # RICE Courtier spawn events
# RICE_BAP_events_courtier_yearly_pulse = {
# 	trigger = {
# 		RICE_basic_is_available_adult_trigger = yes
# 	}
# 	random_events = {
# 		chance_of_no_event = {
# 			value = 30
# 			if = {
# 				limit = {
# 					has_game_rule = RICE_courtier_spawn_frequency_low
# 				}
# 				add = 10
# 			}
# 			if = {
# 				limit = {
# 					has_game_rule = RICE_courtier_spawn_frequency_very_low
# 				}
# 				add = 20
# 			}
# 			if = {
# 				limit = {
# 					has_game_rule = RICE_courtier_spawn_frequency_high
# 				}
# 				subtract = 10
# 			}
# 			if = {
# 				limit = {
# 					has_game_rule = RICE_courtier_spawn_frequency_very_high
# 				}
# 				subtract = 20
# 			}
# 		}
		
# 		1000 = 0

# 		# SOUTH ETHIOPIA
# 		50 = south_ethiopia.0010 	# Aari/South Omotic
# 		50 = south_ethiopia.0011 	# Oropom
		
# 	}
# }
