﻿#story_cycle_harrying_of_the_north = {
#	# by Nick Meredith
#	
#	on_setup = {
#		set_variable = {
#			name = ruler_england
#			value = story_owner
#		}
#		set_global_variable = {
#			name = ruler_england
#			value = story_owner
#		}
#		set_variable = {
#			name = pacification
#			value = 0
#		}
#		set_variable = {
#			name = resistance
#			value = 5
#		}
#		set_global_variable = {
#			name = harrying_of_the_north
#			value = this
#		}
#	}
#
#	on_end = {
#		debug_log = "Harrying of the North ended on:"
#		debug_log_date = yes
#	}
#
#	on_owner_death = {
#		if = {
#			limit = {
#				exists = story_owner.player_heir
#			}
#			set_global_variable = {
#				name = ruler_england
#				value = story_owner.player_heir
#			}
#			make_story_owner = story_owner.player_heir
#		}
#		## This shouldn't be needed; should be handled by the effect group below
#		#else = {
#		#	end_story = yes
#		#	remove_global_variable = harrying_of_the_north
#		#}
#	}
#
#	#End the Story Cycle if there are no longer any Anglo-Saxon lords left, or if Normans no longer rule England
#	#Put it on a long timer so William player can't just kick them all out and weather the storm for a month
#	effect_group = {
#		months = 1
#
#		trigger = {
#			OR = { #Either of these can be untrue
#				story_owner = {
#					any_vassal = {
#						NOR = {
#							culture = culture:anglo_saxon
#							primary_title.tier >= tier_duchy
#						}
#					}
#				}
#				NOT = {
#					var:ruler_england = {
#						culture = culture:norman
#					}
#				}
#			}
#		}
#
#		first_valid = {
#			triggered_effect = { #The Aethelings are no more - Norman victory
#				trigger = {
#					story_owner = {
#						NOR = {
#							any_vassal = {
#								culture = culture:anglo_saxon
#								primary_title.tier >= tier_duchy
#							}
#						}
#					}
#				}
#				effect = {
#					remove_global_variable = harrying_of_the_north
#					every_ruler = {
#						limit = {
#							capital_province = {
#								geographical_region = world_europe_west_britannia
#							}
#						}
#						trigger_event = ep3_story_cycle_harrying.0001
#					}
#					end_story = yes
#				}
#			}
#			triggered_effect = { #An Anglo-Saxon rules - Aetheling victory
#				trigger = {
#					story_owner = {
#						culture = culture:anglo_saxon
#					}
#				}
#				effect = {
#					remove_global_variable = harrying_of_the_north
#					every_ruler = {
#						limit = {
#							capital_province = {
#								geographical_region = world_europe_west_britannia
#							}
#						}
#						trigger_event = ep3_story_cycle_harrying.0002
#					}
#					end_story = yes
#				}
#			}
#			triggered_effect = { #The Normans no longer rule - Aethelings avoid defeat
#				trigger = {
#					story_owner = {
#						NOR = {
#							culture = culture:norman
#							culture = culture:english
#						}
#					}
#				}
#				effect = {
#					remove_global_variable = harrying_of_the_north
#					every_ruler = {
#						limit = {
#							capital_province = {
#								geographical_region = world_europe_west_britannia
#							}
#						}
#						trigger_event = ep3_story_cycle_harrying.0003
#					}
#					end_story = yes
#				}
#			}
#		}
#	}
#
#	effect_group = {
#		years = 50
#
#		triggered_effect = { #The Normans still rule, but it has been generations - Norman victory by attrition
#			trigger = {
#				var:ruler_england = {
#					culture = culture:norman
#				}
#			}
#			effect = {
#				remove_global_variable = harrying_of_the_north
#				every_ruler = {
#					limit = {
#						capital_province = {
#							geographical_region = world_europe_west_britannia
#						}
#					}
#					trigger_event = ep3_story_cycle_harrying.0004
#				}
#				end_story = yes
#			}
#		}
#	}
#
#	# Events for William/King of England
#	effect_group = {
#		days = { 20 40 }
#
#		trigger = {
#			story_owner = {
#				is_alive = yes
#			}
#		}
#
#		first_valid = {
#			triggered_effect = {
#				trigger = { always = yes }
#				effect = {
#					save_scope_as = story_scope
#					story_owner = {
#						trigger_event = {
#							on_action = ongoing_harrying_owner_events
#						}
#					}
#				}
#			}
#		}
#	}
#
#	# Events for Aethelings
#	effect_group = {
#		days = { 20 40 }
#
#		trigger = {
#			story_owner = {
#				any_vassal = {
#					culture = culture:anglo_saxon
#				}
#			}
#		}
#
#		first_valid = {
#			triggered_effect = {
#				trigger = { always = yes }
#				effect = {
#					save_scope_as = story_scope
#					story_owner = {
#						random_vassal= {
#							limit = {
#								culture = culture:anglo_saxon
#							}
#							trigger_event = {
#								on_action = ongoing_harrying_aetheling_events
#							}
#						}
#					}
#				}
#			}
#		}
#	}
#
#	# Events for Hereward the Wake
#	effect_group = {
#		days = { 20 40 }
#
#		trigger = {
#			character:90028 = {
#				is_alive = yes
#				NOT = {
#					has_character_flag = hereward_settled_flag
#				}
#			}
#		}
#
#		first_valid = {
#			triggered_effect = {
#				trigger = { always = yes }
#				effect = {
#					save_scope_as = story_scope
#					character:90028 = {
#						trigger_event = {
#							on_action = ongoing_harrying_hereward_events
#						}
#					}
#				}
#			}
#		}
#	}
#
#	### Harrying ongoing effects
#	# Set the Pacification variable every month if possible
#	# This checks for the Embrace English Culture decision
#	effect_group = {
#		months = 1
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					var:pacification > 15
#					var:pacification > var:resistance
#				}
#				effect = {
#					if = {
#						limit = {
#							AND = {
#								NOT = {
#									has_variable = embrace_culture_decision_counter
#								}
#								var:pacification > 15
#								var:pacification > var:resistance								
#							}
#						}
#						set_variable = {
#							name = embrace_culture_decision_counter
#							value = 0
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					OR = {
#						var:pacification < 15
#						var:pacification < var:resistance
#					}
#				}
#				effect = {
#					if = {
#						limit = {
#							has_variable = embrace_culture_decision_counter
#						}
#						remove_variable = embrace_culture_decision_counter
#					}
#				}
#			}
#		}
#	}
#
#	# Check to see if you've had pacification over resistance for a year
#	effect_group = {
#		months = 1
#		triggered_effect = {
#			trigger = {
#				var:pacification > 15
#				var:pacification > var:resistance
#				has_variable = embrace_culture_decision_counter
#			}
#			effect = {
#				if = {
#					limit = {
#						AND = {
#							has_variable = embrace_culture_decision_counter
#							var:pacification > 15
#							var:pacification > var:resistance									
#						}
#					}
#					change_variable = {
#						name = embrace_culture_decision_counter
#						add = 1
#					}
#				}
#			}
#		}
#	}
#
#	# Tick cultural acceptance every three months
#	effect_group = {
#		months = 3
#
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					var:resistance > 16
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						culture = {
#							change_cultural_acceptance = {
#								target = culture:anglo_saxon
#								value = major_cultural_acceptance_loss
#								desc = harrying_of_the_north_tt_resistance_level_4
#							}
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:resistance > 13
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						culture = {
#							change_cultural_acceptance = {
#								target = culture:anglo_saxon
#								value = medium_cultural_acceptance_loss
#								desc = harrying_of_the_north_tt_resistance_level_3
#							}
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:resistance > 10
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						culture = {
#							change_cultural_acceptance = {
#								target = culture:anglo_saxon
#								value = minor_cultural_acceptance_loss
#								desc = harrying_of_the_north_tt_resistance_level_2
#							}
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:resistance > 7
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						culture = {
#							change_cultural_acceptance = {
#								target = culture:anglo_saxon
#								value = miniscule_cultural_acceptance_loss
#								desc = harrying_of_the_north_tt_resistance_level_1
#							}
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:pacification > 14
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						culture = {
#							change_cultural_acceptance = {
#								target = culture:anglo_saxon
#								value = major_cultural_acceptance_gain
#								desc = harrying_of_the_north_tt_pacification_level_4
#							}
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:pacification > 11
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						culture = {
#							change_cultural_acceptance = {
#								target = culture:anglo_saxon
#								value = medium_cultural_acceptance_gain
#								desc = harrying_of_the_north_tt_pacification_level_3
#							}
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:pacification > 8
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						culture = {
#							change_cultural_acceptance = {
#								target = culture:anglo_saxon
#								value = minor_cultural_acceptance_gain
#								desc = harrying_of_the_north_tt_pacification_level_2
#							}
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:pacification > 5
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						culture = {
#							change_cultural_acceptance = {
#								target = culture:anglo_saxon
#								value = miniscule_cultural_acceptance_gain
#								desc = harrying_of_the_north_tt_pacification_level_1
#							}
#						}
#					}
#				}
#			}
#		}
#	}
#
#	# Tick dread every month
#	effect_group = {
#		months = 1
#
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					var:pacification > 14
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						add_dread = 3
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:pacification > 13
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						add_dread = 2
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:pacification > 10
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						add_dread = 1
#					}
#				}
#			}
#		}
#	}
#
#	# Add discontent to targeting factions every 2 months
#	effect_group = {
#		months = 2
#
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					var:resistance > 16
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						if = {
#							limit = {
#								has_targeting_faction = yes
#							}
#							add_targeting_factions_discontent = 5
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:resistance > 13
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						if = {
#							limit = {
#								has_targeting_faction = yes
#							}
#							add_targeting_factions_discontent = 3
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:resistance > 10
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						if = {
#							limit = {
#								has_targeting_faction = yes
#							}
#							add_targeting_factions_discontent = 1
#						}
#					}
#				}
#			}
#		}
#	}
#
#	# Erode Norman County Control every 3 months
#	effect_group = {
#		months = 3
#
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					var:resistance > 16
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						every_sub_realm_county = {
#							limit = {
#								holder = {
#									NOT = {
#										culture = culture:anglo_saxon
#									}
#								}
#							}
#							change_county_control = medium_discontent_loss
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:resistance > 13
#					var:resistance > var:pacification
#				}
#				effect = {
#					story_owner = {
#						every_sub_realm_county = {
#							limit = {
#								holder = {
#									NOT = {
#										culture = culture:anglo_saxon
#									}
#								}
#							}
#							change_county_control = minor_discontent_loss
#						}
#					}
#				}
#			}
#		}
#	}
#
#	# Add Norman County Control every 3 months
#	effect_group = {
#		months = 3
#
#		first_valid = {
#			triggered_effect = {
#				trigger = {
#					var:pacification > 14
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						every_sub_realm_county = {
#							limit = {
#								holder = {
#									NOT = {
#										culture = culture:anglo_saxon
#									}
#								}
#							}
#							change_county_control = medium_discontent_gain
#						}
#					}
#				}
#			}
#			triggered_effect = {
#				trigger = {
#					var:pacification > 11
#					var:pacification > var:resistance
#				}
#				effect = {
#					story_owner = {
#						every_sub_realm_county = {
#							limit = {
#								holder = {
#									NOT = {
#										culture = culture:anglo_saxon
#									}
#								}
#							}
#							change_county_control = minor_discontent_gain
#						}
#					}
#				}
#			}
#		}
#	}
#
#	#Maintenance group
#	effect_group = {
#		days = 1
#		#Give the story cycle to any Norman ruler of England if the original one sods off
#		triggered_effect = {
#			trigger = {
#				story_owner = {
#					NOT = {
#						has_title = title:k_england
#					}
#				}
#			}
#			effect = {
#				title:k_england.holder = {
#					save_scope_as = new_ruler
#				}
#				make_story_owner = scope:new_ruler
#				set_variable = {
#					name = ruler_england
#					value = story_owner
#				}
#				set_global_variable = {
#					name = ruler_england
#					value = story_owner
#				}
#			}
#		}
#	}
#}
#