#frankokratia_story = {
#	# by Jason Cantalini
#	visible = yes
#	
#	icon = {
#		trigger = {
#			always = yes
#		}
#		reference = "gfx/interface/icons/story_cycles/story_icon_despoiler.dds"
#	}
#	
#	visualization = {
#		custom_string_key = "FRANKOKRATIA_STORY_PRACTICAL_INFORMATION_STRING"
#		character = { variable_name = "byz_claimant" label = "claimant" }
#		character_list = { variable_name = "frankokratia_leaders" label = "diverted_crusaders" }
#	}
#	
#	on_setup = {
#		set_variable = {
#			name = crusader_kingdom
#			value = story_owner.faith.great_holy_war.ghw_target_title
#		}
#		set_global_variable = {
#			name = byz_claimant_champion
#			value = story_owner
#		}
#		add_to_variable_list = {
#			name = frankokratia_leaders
#			target = story_owner
#		}
#	}
##
#	on_end = {
#		debug_log = "Frankokratia story ended on:"
#		debug_log_date = yes
#		remove_global_variable = byz_claimant_champion
#		if = {
#			limit = {
#				var:byz_claimant = {
#					is_alive = yes
#				}
#			}
#			var:byz_claimant = {
#				remove_character_flag = byz_claimant_flag
#			}
#		}
#	}
##
#	on_owner_death = {
#		story_owner = {
#			save_scope_as = dead_owner
#		}
#		if = {
#			limit = {
#				exists = story_owner.player_heir
#				story_owner.player_heir = {
#					faith = faith:catholic
#				}
#			}
#			set_global_variable = {
#				name = byz_claimant_champion
#				value = story_owner.player_heir
#			}
#			remove_list_variable = {
#				name = frankokratia_leaders
#				target = story_owner
#			}
#			add_to_variable_list = {
#				name = frankokratia_leaders
#				target = story_owner.player_heir
#			}
#			make_story_owner = story_owner.player_heir
#		}
#		else_if = {
#			limit = {
#				exists = story_owner.primary_heir
#				story_owner.primary_heir = {
#					faith = faith:catholic
#					highest_held_title_tier <= scope:dead_owner.highest_held_title_tier
#				}
#			}
#			set_global_variable = {
#				name = byz_claimant_champion
#				value = story_owner.primary_heir
#			}
#			remove_list_variable = {
#				name = frankokratia_leaders
#				target = story_owner
#			}
#			add_to_variable_list = {
#				name = frankokratia_leaders
#				target = story_owner.primary_heir
#			}
#			make_story_owner = story_owner.primary_heir
#		}
#		else_if = {
#			limit = {
#				any_in_list = {
#					variable = frankokratia_leaders
#					OR = {
#						exists = primary_heir
#						exists = player_heir
#					}
#					age >= 13
#					this != scope:dead_owner
#				}
#			}
#			ordered_in_list = {
#				variable = frankokratia_leaders
#				order_by = current_military_strength
#				limit = {
#					OR = {
#						exists = primary_heir
#						exists = player_heir
#					}
#					age >= 13
#					this != scope:dead_owner
#				}
#				save_scope_as = new_franko
#				
#				set_global_variable = {
#					name = byz_claimant_champion
#					value = scope:new_franko
#				}
#			}
#			remove_list_variable = {
#				name = frankokratia_leaders
#				target = story_owner
#			}
#			add_to_variable_list = {
#				name = frankokratia_leaders
#				target = scope:new_franko
#			}
#			make_story_owner = scope:new_franko
#		}
#		# Or destroy
#		else = {
#			end_story = yes
#			every_in_list = {
#				variable = frankokratia_leaders
#				limit = {
#					is_ai = no
#				}
#				trigger_event = ep3_frankokratia_events.0005
#			}
#		}
#	}
#
#	#Claimant dies... story cycle is over
#	effect_group = {
#		days = { 20 40 }
#
#		trigger = {
#			var:byz_claimant = { is_alive = no }
#			NOT = {
#				has_variable = franko_war_complete
#			}
#		}
#
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					var:byz_claimant = { is_alive = no }
#					NOT = {
#						has_variable = franko_war_complete
#					}
#				}
#				effect = {
#					every_in_list = {
#						variable = frankokratia_leaders
#						limit = {
#							is_ai = no
#						}
#						trigger_event = ep3_frankokratia_events.0005
#					}
#				}
#			}
#		}
#	}
#
#	#Owner's other wars should be wrapped up if they're not going well... by force
#	effect_group = {
#		days = { 20 40 }
#
#		trigger = {
#			#It's not post-war era
#			NOT = {
#				has_variable = franko_war_complete
#			}
#			global_var:byz_claimant_champion = {
#				#Is not in frankokratia war
#				any_character_war = {
#					NOT = {
#						using_cb = crusading_claim_cb
#					}
#				}
#				#Is risking losing a war
#				any_character_war = {
#					OR = {
#						AND = {
#							primary_attacker = {
#								this = global_var:byz_claimant_champion
#							}
#							attacker_war_score <= -50
#						}
#						AND = {
#							primary_defender = {
#								this = global_var:byz_claimant_champion
#							}
#							defender_war_score <= -50
#						}
#					}
#					NOR = {
#						any_war_defender = {
#							is_ai = no
#						}
#						any_war_attacker = {
#							is_ai = no
#						}
#					}
#				}
#				is_ai = yes
#			}
#			var:financier_title.holder = {
#				save_temporary_scope_as = financier
#			}
#			any_in_list = {
#				variable = frankokratia_leaders
#				NOR = {
#					this = global_var:byz_claimant_champion
#					this = scope:financier
#				}
#			}
#		}
#
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					#It's not post-war era
#					NOT = {
#						has_variable = franko_war_complete
#					}
#					global_var:byz_claimant_champion = {
#						#Is not in frankokratia war
#						any_character_war = {
#							NOT = {
#								using_cb = crusading_claim_cb
#							}
#						}
#						#Is risking losing a war
#						any_character_war = {
#							OR = {
#								AND = {
#									primary_attacker = {
#										this = global_var:byz_claimant_champion
#									}
#									attacker_war_score <= -50
#								}
#								AND = {
#									primary_defender = {
#										this = global_var:byz_claimant_champion
#									}
#									defender_war_score <= -50
#								}
#							}
#							NOR = {
#								any_war_defender = {
#									is_ai = no
#								}
#								any_war_attacker = {
#									is_ai = no
#								}
#							}
#						}
#						is_ai = yes
#					}
#					var:financier_title.holder = {
#						save_temporary_scope_as = financier
#					}
#					any_in_list = {
#						variable = frankokratia_leaders
#						NOR = {
#							this = global_var:byz_claimant_champion
#							this = scope:financier
#						}
#					}
#				}
#				effect = {
#					global_var:byz_claimant_champion = {
#						every_character_war = {
#							limit = {
#								NOT = {
#									using_cb = crusading_claim_cb
#								}
#								OR = {
#									AND = {
#										primary_attacker = {
#											this = global_var:byz_claimant_champion
#										}
#										attacker_war_score <= -50
#									}
#									AND = {
#										primary_defender = {
#											this = global_var:byz_claimant_champion
#										}
#										defender_war_score <= -50
#									}
#								}
#								NOR = {
#									any_war_defender = {
#										is_ai = no
#									}
#									any_war_attacker = {
#										is_ai = no
#									}
#								}
#							}
#							end_war = white_peace
#						}
#					}
#				}
#			}
#		}
#	}
#
#	#Re-save war attackers
#	effect_group = {
#		days = { 30 50 }
#
#		trigger = {
#			always = yes
#		}
#		first_valid = {
#			triggered_effect = {
#				trigger = { always = yes }
#				effect = {
#					save_scope_as = frank_story
#					story_owner = {
#						random_character_war = {
#							limit = { using_cb = crusading_claim_cb }
#							every_war_attacker = {
#								limit = {
#									faith = faith:catholic
#								}
#								scope:frank_story = {
#									add_to_variable_list = {
#										name = frankokratia_leaders
#										target = prev
#									}
#								}
#							}
#						}
#					}
#				}
#			}
#		}
#	}
#
#	#Need to find successor to byz emperor
#	effect_group = {
#		days = { 10 20 }
#
#		trigger = {
#			exists = title:e_byzantium.holder
#			NOR = {
#				var:byz_emperor ?= title:e_byzantium.holder
#				var:byz_claimant ?= title:e_byzantium.holder
#				global_var:byz_claimant_champion ?= title:e_byzantium.holder
#				var:financier_title.holder ?= title:e_byzantium.holder
#				var:ghw_sponsor ?= title:e_byzantium.holder
#			}
#		}
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					exists = title:e_byzantium.holder
#					NOR = {
#						var:byz_emperor ?= title:e_byzantium.holder
#						var:byz_claimant ?= title:e_byzantium.holder
#						global_var:byz_claimant_champion ?= title:e_byzantium.holder
#						var:financier_title.holder ?= title:e_byzantium.holder
#						var:ghw_sponsor ?= title:e_byzantium.holder
#					}
#				}
#				effect = {
#					set_variable = {
#						name = byz_emperor
#						value = title:e_byzantium.holder
#					}
#				}
#			}
#		}
#	}
#
#	#Fire events for pledged attackers for them to commit to leaving crusade when it launches
#	effect_group = {
#		days = { 10 20 }
#
#		trigger = {
#			exists = story_owner.faith.great_holy_war
#			story_owner.faith = faith:catholic
#			story_owner.faith.religious_head = {
#				NOT = {
#					any_character_war = {
#						using_cb = undirected_great_holy_war
#					}
#				}
#			}
#			story_owner.faith.great_holy_war = {
#				any_pledged_attacker = {
#					ep3_frankokratia_valid_joiner_trigger = yes
#				}
#			}
#		}
#
#		first_valid = {
#			triggered_effect = { 
#				trigger = {
#					exists = story_owner.faith.great_holy_war
#					story_owner.faith.religious_head = {
#						NOT = {
#							any_character_war = {
#								using_cb = undirected_great_holy_war
#							}
#						}
#					}
#					story_owner.faith.great_holy_war = {
#						any_pledged_attacker = {
#							ep3_frankokratia_valid_joiner_trigger = yes
#						}
#					}
#				}
#				effect = {
#					story_owner.faith.great_holy_war = {
#						#trigger join event for important players first
#						if = {
#							limit = {
#								any_pledged_attacker = {
#									is_ai = no
#									highest_held_title_tier >= tier_kingdom
#									ep3_frankokratia_valid_joiner_trigger = yes
#								}
#							}
#							random_pledged_attacker = {
#								limit = {
#									is_ai = no
#									highest_held_title_tier >= tier_kingdom
#									ep3_frankokratia_valid_joiner_trigger = yes
#								}
#								trigger_event = ep3_frankokratia_events.0020
#							}
#						}
#						#Then players
#						else_if = {
#							limit = {
#								any_pledged_attacker = {
#									is_ai = no
#									ep3_frankokratia_valid_joiner_trigger = yes
#								}
#							}
#							random_pledged_attacker = {
#								limit = {
#									is_ai = no
#									ep3_frankokratia_valid_joiner_trigger = yes
#								}
#								trigger_event = ep3_frankokratia_events.0020
#							}
#						}
#						#Then others
#						else = {
#							random_pledged_attacker = {
#								limit = {
#									ep3_frankokratia_valid_joiner_trigger = yes
#								}
#								trigger_event = ep3_frankokratia_events.0020
#							}
#						}
#					}
#				}
#			}
#		}
#	}
#
#	#save player war contribution to see if they get to be emp
#	effect_group = {
#		days = { 10 20 }
#
#		trigger = {
#			story_owner = {
#				any_character_war = {
#					using_cb = crusading_claim_cb
#					any_war_attacker = {
#						is_ai = no
#						save_temporary_scope_as = player_temp
#					}
#					war_contribution = {
#						target = scope:player_temp
#						value > 100
#					}
#				}
#			}
#		}
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					story_owner = {
#						any_character_war = {
#							using_cb = crusading_claim_cb
#							any_war_attacker = {
#								is_ai = no
#								save_temporary_scope_as = player_temp
#							}
#							war_contribution = {
#								target = scope:player_temp
#								value > 100
#							}
#						}
#					}
#				}
#				effect = {
#					story_owner = {
#						random_character_war = {
#							limit = {
#								using_cb = crusading_claim_cb
#							}
#							save_scope_as = franko_war
#							every_war_attacker = {
#								limit = {
#									is_ai = no
#									scope:franko_war = {
#										war_contribution = {
#											target = prev
#											value > 100
#										}
#									}
#								}
#								add_character_flag = {
#									flag = frankokratia_sufficient_warscore
#									years = 30
#								}
#							}
#							every_war_attacker = {
#								limit = {
#									is_ai = no
#									scope:franko_war = {
#										war_contribution = {
#											target = prev
#											value > 1000
#										}
#									}
#								}
#								add_character_flag = {
#									flag = frankokratia_high_warscore
#									years = 30
#								}
#							}
#						}
#					}
#				}
#			}
#		}
#	}
#
#	#Maintenance group
#	effect_group = {
#		days = 1
#		trigger = {
#			story_owner = { is_playable_character = no }
#		}
#		triggered_effect = {
#			trigger = { always = yes }
#			effect = {
#				story_owner = { save_scope_as = story_owner }
#				debug_log = "4th Crusader invalidated"
#				debug_log_scopes = yes
#				end_story = yes
#			}
#		}
#	}
#}
#