###########################################
#                                         #
# Charlemagne Religious Events            #
#                                         #
# ID CM.4000-CM.4999                      #
#                                         #
###########################################

# Written by Tobias Bodlund

# CleanSlate: Moved holy order events to soa_holy_order_events.txt

namespace = CM

###########################################
# Festival of the Sun  CM.4100-CM.4199    #
###########################################

# Invite vassals to festival
character_event = {
	id = CM.4100
	desc = EVTDESC_CM_4100
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # hold_zun_feast, minor_decisions.txt

	option = {
		name = EVTOPTA_CM_4100

		custom_tooltip = {
			text = EVTTOOLTIP1_RoI_1000

			any_vassal = {
				limit = {
					block_general_event_trigger = no
					war = no
				}

				letter_event = { id = CM.4101 }
			}
		}

		character_event = {
			id = CM.4120
			days = 12
		}
	}
}

# Vassal receives invitation
letter_event = {
	id = CM.4101
	desc = EVTDESC_CM_4101
	border = GFX_event_letter_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_4101 # Travel to the feast

		character_event = {
			id = CM.4105 # Hidden - arrives at feast
			days = 12
		}

		character_event = {
			id = CM.4199 # Safety event for clearing all flags
			days = 42
		}

		end_inaccessibility_effect = yes #removes in_hiding or in_seclusion
		set_character_flag = do_not_disturb

		ai_chance = {
			factor = 2

			mult_modifier = {
				factor = 10

				has_focus = focus_theology
				religion_openly_zun_or_reformed_trigger = yes
			}

			mult_modifier = {
				factor = 2

				opinion = {
					who = FROM
					value >= -30
				}
			}

			mult_modifier = {
				factor = 5

				opinion = {
					who = FROM
					value >= -15
				}
			}

			mult_modifier = {
				factor = 5

				opinion = {
					who = FROM
					value >= 0
				}
			}
		}
	}

	option = {
		name = EVTOPTB_RoI_1001 # Refuse invitation

		FROM = {
			show_scope_change = no

			letter_event = {
				id = CM.4102
				days = 3
				tooltip = EVTTOOLTIP1_RoI_2001
			}
		}

		ai_chance = {
			factor = 1

			trigger = {
				opinion = {
					who = FROM
					value < 25
				}
			}

			mult_modifier = {
				factor = 5
				religion_openly_zun_or_reformed_trigger = no
			}
		}
	}
}

# If vassal refuses to come to the feast
letter_event = {
	id = CM.4102
	desc = EVTDESC_CM_4102

	is_triggered_only = yes

	option = {
		name = I_SEE

		opinion = {
			name = opinion_dislike
			who = FROM
			years = 2
		}
	}
}

# Festival begins
character_event = {
	id = CM.4120
	desc = EVTDESC_CM_4120
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_4120

		set_character_flag = zun_feast_begun

		character_event = {
			id = CM.4195 # End festival
			days = 30
		}

		character_event = {
			id = CM.4199 # Clearing all flags and modifiers after feast
			days = 31
		}

		narrative_event = {
			id = CM.4130 # Walking in the sun
			days = 10
		}

		character_event = {
			id = CM.4190 # Temple ceremony
			days = 20
		}

		any_courtier = {
			limit = {
				religion_openly_zun_or_reformed_trigger = yes
				is_adult = yes
				is_ruler = no
				is_incapable = no
			}

			set_character_flag = attending_zun_feast

			narrative_event = {
				id = CM.4130 # Walking in the sun
				days = 10
			}

			character_event = {
				id = CM.4199 # Clearing all flags and modifiers after feast
				days = 31
			}
		}
	}
}

# Vassal arrives at festival
character_event = {
	id = CM.4105
	desc = EVTDESC_CM_4120
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_4120

		if = {
			limit = { religion_openly_zun_or_reformed_trigger = yes }

			narrative_event = {
				id = CM.4130 # Walking in the sun
				days = 10
			}
		}

		character_event = {
			id = CM.4190 # Temple ceremony
			days = 20
		}
	}
}

# Festival ends
character_event = {
	id = CM.4195

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		character_event = { id = CM.4196 }

		any_courtier_or_vassal = {
			limit = { has_character_flag = attending_zun_feast }
			character_event = { id = CM.4198 }
		}
	}
}

# Festival is over - host
character_event = {
	id = CM.4196
	desc = EVTDESC_CM_4196
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_4196

		add_character_modifier = {
			name = large_feast_timer
			years = 3
			hidden = yes
		}

		remove_character_modifier = holding_zun_feast
		clr_character_flag = zun_feast_begun
		clr_character_flag = do_not_disturb
	}
}

# Festival is over - guest
character_event = {
	id = CM.4198
	desc = EVTDESC_CM_4196
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_4196

		add_character_modifier = {
			name = large_feast_timer
			years = 1
			hidden = yes
		}

		opinion = {
			name = opinion_enjoyed_feast
			who = FROM
			years = 2
		}

		clr_character_flag = attending_zun_feast
		clr_character_flag = do_not_disturb
	}
}

# Clear all character flags and modifiers - safety catch
character_event = {
	id = CM.4199

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		remove_character_modifier = holding_zun_feast
		clr_character_flag = attending_zun_feast
		clr_character_flag = zun_feast_begun
		clr_character_flag = do_not_disturb
	}
}

# Walking in the sun
narrative_event = {
	id = CM.4130
	title = EVTTITLE_CM_4130
	desc = EVTDESC_CM_4130
	picture = GFX_evt_sun_temple
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes

	only_capable = yes

	option = {
		name = EVTOPTA_CM_4130

		piety = 30

		hidden_effect = {
			random_list = {
				  5 = { character_event = { id = CM.4131 } } # Weak or old character becomes ill
				  5 = { character_event = { id = CM.4133 } } # Character goes insane
				  5 = { character_event = { id = CM.4135 } } # Character becomes possessed
				 10 = { character_event = { id = CM.4137 } } # Character becomes zealous
				 10 = { character_event = { id = CM.4139 } } # Character becomes stronger
				 10 = { character_event = { id = CM.4141 } } # Character becomes wiser
				  5 = { character_event = { id = CM.4143 } } # Zealous character stares into sun and goes blind
				300 = { } # No event
			}
		}
	}
}

# Weak or old character becomes ill or incapable
character_event = {
	id = CM.4131
	desc = EVTDESC_CM_4131
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	trigger = {
		OR = {
			age >= 70
			health_traits >= 1
		}

		immortal = no
	}

	option = {
		name = EVTOPTA_CM_4131

		if = {
			limit = { is_ill = yes }
			add_trait = incapable
		}
		else = {
			if = {
				limit = { has_dlc = "Reapers" }
				add_symptom_effect = yes
			}
			else = {
				add_trait = ill
			}
		}
	}
}

# Character goes insane
character_event = {
	id = CM.4133
	desc = EVTDESC_CM_4133
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	trigger = {
		OR = {
			trait = stressed
			trait = depressed

			trigger_if = {
				limit = { health_traits >= 1 }
				trait = zealous
			}
		}

		NOT = { trait = lunatic }
	}

	option = {
		name = EVTOPTA_CM_4133

		add_trait = lunatic
	}
}

# Character becomes possessed
character_event = {
	id = CM.4135
	desc = EVTDESC_CM_4135
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	trigger = {
		trait = zealous
		NOT = { trait = possessed }
	}

	option = {
		name = EVTOPTA_CM_4135
		add_trait = possessed
	}
}

# Character becomes zealous
character_event = {
	id = CM.4137
	desc = EVTDESC_CM_4137
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	trigger = {
		NOR = {
			trait = zealous
			trait = cynical
		}
	}

	option = {
		name = EVTOPTA_CM_4137

		add_trait = zealous
	}
}

# Character becomes stronger
character_event = {
	id = CM.4139
	desc = EVTDESC_CM_4139
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	trigger = {
		is_strong_trigger = no
		is_weak_trigger = no
		NOT = { trait = slothful }
		health_traits < 1
	}

	option = {
		name = EVTOPTA_CM_4137

		add_trait = brawny
	}
}

# Character becomes wiser
character_event = {
	id = CM.4141
	desc = EVTDESC_CM_4141
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	trigger = {
		is_smart_trigger = no
	}

	option = {
		name = EVTOPTA_CM_4141

		add_trait = shrewd
	}
}

# Character stares into sun and becomes blind
character_event = {
	id = CM.4143
	desc = EVTDESC_CM_4143
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	trigger = {
		trait = zealous
		NOT = { trait = blinded }
	}

	option = {
		name = EVTOPTA_CM_4143

		if = {
			limit = { trait = one_eyed }
			remove_trait = one_eyed
		}

		add_trait = blinded
	}
}


# Temple ceremony - host and guests
character_event = {
	id = CM.4190
	desc = EVTDESC_CM_4190
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_4190

		piety = 20

		add_character_modifier = {
			name = large_feast_timer
			years = 1
			hidden = yes
		}
	}
}

###########################################
# Byzantine religious events              #
###########################################

# Byzantine Emperor renounces iconoclasm
character_event = {
	id = CM.4200
	desc = EVTDESC_CM_4200
	picture = GFX_evt_icon
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # renounce_iconoclasm, conversion_decisions.txt

	option = {
		name = EVTOPTA_CM_4200

		if = {
			limit = { religion = chalcedonian }

			remove_trait = iconoclast_rites
			add_trait = greek_rites
		}
		else = {
			# Workaround for automatic usurption of theocratic characters
			FROM = {
				religion_scope = {
					save_event_target_as = target_religion
				}
			}

			convert_religion_failsafe_effect = yes
		}

		if = {
			limit = { trait = zealous }

			remove_trait = zealous
			piety = -50
		}

		ai_chance = {
			factor = 1

			trigger = {
				trigger_if = {
					limit = { trait = zealous }
					intrigue >= 3
				}
			}

			mult_modifier = {
				factor = 0.3

				trait = zealous
				intrigue >= 3
			}
		}
	}

	option = {
		name = EVTOPTB_CM_4200

		piety = 100

		ai_chance = {
			factor = 1

			trigger = { trait = zealous }
		}
	}
}
