namespace = dvg_russian_anarchy

### Triggers ###

# 1850 or Nationalism
dvg_russian_anarchy.1 = {
	type = country_event
	placement = ROOT

	event_image = {
		video = "gfx/event_pictures/europenorthamerica_capitalists_meeting.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/capitalists_meeting"

	icon = "gfx/interface/icons/event_icons/event_default.dds"

	title = dvg_russian_anarchy.1.t
	desc = dvg_russian_anarchy.1.d
	flavor = dvg_russian_anarchy.1.f

	duration = 3

	trigger = {
		NOT = { has_global_variable = rus_anarchy_trigger }
		OR = {
			AND = {
				exists = c:MSO
				this = c:MSO
			}
			AND = {
				NOT = { exists = c:MSO }
				exists = c:TVE
				this = c:TVE
			}
			AND = {
				NOT = { exists = c:MSO }
				NOT = { exists = c:TVE }
				exists = c:NZH
				this = c:NZH
			}
		}
		OR = {
			year >= 1845 #Safeguard in case green prince is not resolved, should be done by 1845
			has_variable = green_prince_resolved
		}
		OR = {
			year >= 1850
			has_technology_researched = nationalism
		}
	}

	option = {
		name = dvg_russian_anarchy.1.a
		default_option = yes

		set_global_variable = rus_anarchy_trigger
	}
}

# 1848 and Finland exists
dvg_russian_anarchy.2 = {
	type = country_event
	placement = ROOT

	event_image = {
		video = "gfx/event_pictures/europenorthamerica_capitalists_meeting.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/capitalists_meeting"

	icon = "gfx/interface/icons/event_icons/event_default.dds"

	title = dvg_russian_anarchy.2.t
	desc = dvg_russian_anarchy.2.d
	flavor = dvg_russian_anarchy.2.f

	duration = 3

	trigger = {
		NOT = { has_global_variable = rus_anarchy_trigger }
		NOT = { has_technology_researched = nationalism }
		OR = {
			AND = {
				exists = c:MSO
				this = c:MSO
			}
			AND = {
				NOT = { exists = c:MSO }
				this = c:TVE
			}
			AND = {
				NOT = { exists = c:MSO }
				NOT = { exists = c:TVE }
				this = c:NZH
			}
		}
		exists = c:FIN
		year >= 1846
		year < 1850
	}

	option = {
		name = dvg_russian_anarchy.2.a
		default_option = yes

		set_global_variable = rus_anarchy_trigger
	}
}

# Aggresive SCA
dvg_russian_anarchy.3 = {
	type = country_event
	placement = ROOT

	event_image = {
		video = "gfx/event_pictures/europenorthamerica_capitalists_meeting.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/capitalists_meeting"

	icon = "gfx/interface/icons/event_icons/event_default.dds"

	title = dvg_russian_anarchy.3.t
	desc = dvg_russian_anarchy.3.d
	flavor = dvg_russian_anarchy.3.f

	duration = 3

	trigger = {
		NOT = { has_global_variable = rus_anarchy_trigger }
		NOT = { has_technology_researched = nationalism }
		OR = {
			AND = {
				exists = c:MSO
				this = c:MSO
			}
			AND = {
				NOT = { exists = c:MSO }
				this = c:TVE
			}
			AND = {
				NOT = { exists = c:MSO }
				NOT = { exists = c:TVE }
				this = c:NZH
			}
		}
		c:SCA = {
			OR = {
				owns_entire_state_region = STATE_EAST_KARELIA
				owns_entire_state_region = STATE_INGRIA
				owns_entire_state_region = STATE_SMOLENSK
				owns_entire_state_region = STATE_ORSHA
				AND = {
					exists = c:NOV
					has_diplomatic_pact = {
						who = c:NOV
						type = puppet
					}
				}
				AND = {
					exists = c:TVE
					has_diplomatic_pact = {
						who = c:TVE
						type = puppet
					}
				}
				AND = {
					exists = c:MSO
					has_diplomatic_pact = {
						who = c:MSO
						type = puppet
					}
				}
				AND = {
					exists = c:SMO
					has_diplomatic_pact = {
						who = c:SMO
						type = puppet
					}
				}
			}
		}
		#year >= 1846
		year < 1850
	}

	option = {
		name = dvg_russian_anarchy.3.a
		default_option = yes

		set_global_variable = rus_anarchy_trigger
	}
}

# Aggresive PLC
dvg_russian_anarchy.4 = {
	type = country_event
	placement = ROOT

	event_image = {
		video = "gfx/event_pictures/europenorthamerica_capitalists_meeting.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/capitalists_meeting"

	icon = "gfx/interface/icons/event_icons/event_default.dds"

	title = dvg_russian_anarchy.4.t
	desc = dvg_russian_anarchy.4.d
	flavor = dvg_russian_anarchy.4.f

	duration = 3

	trigger = {
		NOT = { has_global_variable = rus_anarchy_trigger }
		NOT = { has_technology_researched = nationalism }
		OR = {
			AND = {
				exists = c:MSO
				this = c:MSO
			}
			AND = {
				NOT = { exists = c:MSO }
				this = c:TVE
			}
			AND = {
				NOT = { exists = c:MSO }
				NOT = { exists = c:TVE }
				this = c:NZH
			}
		}
		OR = {
			exists = c:PLC
			AND = {
				exists = c:POL
				c:POL = {
					ruler = {
						NOT = { has_variable = is_maximilian_jagiello }
					}
					OR = {
						owns_entire_state_region = STATE_SMOLENSK
						owns_entire_state_region = STATE_ORSHA
						has_diplomatic_pact = {
							who = c:NOV
							type = puppet
						}
						has_diplomatic_pact = {
							who = c:TVE
							type = puppet
						}
						has_diplomatic_pact = {
							who = c:MSO
							type = puppet
						}
						has_diplomatic_pact = {
							who = c:SMO
							type = puppet
						}
					}
				}
			}
		}
		#year >= 1846
		year < 1850
	}

	option = {
		name = dvg_russian_anarchy.3.a
		default_option = yes

		set_global_variable = rus_anarchy_trigger
	}
}
###################### THE GREAT RUSSIAN ANARCHY BEGINS #####################

dvg_russian_anarchy.10 = {
	type = country_event
	placement = ROOT

	event_image = {
		video = "gfx/event_pictures/europenorthamerica_before_the_battle.bk2"
	}
	
	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/before_the_battle"

	icon = "gfx/interface/icons/event_icons/event_military.dds"

	title = dvg_russian_anarchy.10.t
	desc = dvg_russian_anarchy.10.d
	flavor = dvg_russian_anarchy.10.f

	duration = 3

	trigger = {
		has_global_variable = rus_anarchy_trigger
		NOT = { has_global_variable = rus_anarchy }
		OR = {
			AND = {
				exists = c:MSO
				this = c:MSO
			}
			AND = {
				NOT = { exists = c:MSO }
				exists = c:TVE
				this = c:TVE
			}
			AND = {
				NOT = { exists = c:MSO }
				NOT = { exists = c:TVE }
				exists = c:NZH
				this = c:NZH
			}
		}
	}

	option = {
		name = dvg_russian_anarchy.10.a
		default_option = yes

		set_global_variable = rus_anarchy

		add_journal_entry = {
            type = je_russian_anarchy
        }

		every_subject_or_below = {
			limit = { 
				is_subject_of = ROOT
				country_has_primary_culture = cu:russian
			}
			save_scope_as = subject_to_annex
			ROOT = {
				annex = scope:subject_to_annex
			}
		}

		add_modifier = {
            name = dvg_rus_enemies_all_sides
            months = 60
        }

		every_country = {
			if = {
				limit = {
					NOT = { this = ROOT }
					country_has_primary_culture = cu:russian
				}

				change_relations = { 
					country = ROOT
					value = -100 
				}
				trigger_event = {
					id = dvg_russian_anarchy.11
					days = 1
					popup = yes
				}
			}
		}

		every_country = {
			limit = {
				NOT = { this = ROOT }
				OR = {
					AND = {
						exists = c:SCA
						this = c:SCA
					}
					AND = {
						exists = c:POL
						this = c:POL
					}
					AND = {
						exists = c:PLC
						this = c:PLC
					}
					country_rank >= rank_value:major_power
				}
			}	
			change_relations = { 
				country = ROOT
				value = -200 
			}
		}

		every_state_region = {
			limit = {
				is_homeland = cu:russian
			}
			add_claim = ROOT
		}

		remove_modifier = diplomatic_plays_blocked
		remove_modifier = dvg_rock_and_hard_place

		add_modifier = {
            name = dvg_rock_and_hard_place
            months = 60
        }
		add_modifier = {
			name = dvg_rus_anarchy
			months = 60
		}
	}
}

dvg_russian_anarchy.11 = {
	type = country_event
	placement = ROOT

	event_image = {
		video = "gfx/event_pictures/europenorthamerica_before_the_battle.bk2"
	}
	
	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/before_the_battle"

	icon = "gfx/interface/icons/event_icons/event_military.dds"

	title = dvg_russian_anarchy.11.t
	desc = dvg_russian_anarchy.11.d
	flavor = dvg_russian_anarchy.11.f

	duration = 3

	option = {
		name = dvg_russian_anarchy.11.a
		default_option = yes

		add_journal_entry = {
            type = je_russian_anarchy
        }

		every_subject_or_below = {
			limit = { 
				is_subject_of = ROOT
				country_has_primary_culture = cu:russian
			}
			save_scope_as = subject_to_annex
			ROOT = {
				annex = scope:subject_to_annex
			}
		}

		every_country = {
			limit = {
				NOT = { this = ROOT }
				OR = {
					AND = {
						exists = c:SCA
						this = c:SCA
					}
					AND = {
						exists = c:POL
						this = c:POL
					}
					AND = {
						exists = c:PLC
						this = c:PLC
					}
					country_rank >= rank_value:major_power
				}
			}	
			change_relations = { 
				country = ROOT
				value = -100
			}
		}

		every_state_region = {
			limit = {
				is_homeland = cu:russian
			}
			add_claim = ROOT
		}

		remove_modifier = diplomatic_plays_blocked
		remove_modifier = dvg_rock_and_hard_place

		add_modifier = {
            name = dvg_rock_and_hard_place
            months = 60
        }
		add_modifier = {
			name = dvg_rus_anarchy
			months = 60
		}
	}
}

# AI event to attack
dvg_russian_anarchy.100 = {
	type = country_event
	placement = ROOT

	event_image = {
		video = "gfx/event_pictures/europenorthamerica_before_the_battle.bk2"
	}
	
	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/before_the_battle"

	icon = "gfx/interface/icons/event_icons/event_military.dds"

	title = dvg_russian_anarchy.100.t
	desc = dvg_russian_anarchy.100.d

	duration = 3

	trigger = {
		has_global_variable = rus_anarchy
		is_ai = yes
		is_at_war = no
		is_diplomatic_play_committed_participant = no
		is_subject = no
		country_has_primary_culture = cu:russian
		any_country = {
			NOT = { this = ROOT }
			country_has_primary_culture = cu:russian
			is_diplomatic_play_committed_participant = no
			is_subject = no
			any_neighbouring_state = { 
				owner = ROOT
			}
		}
	}

	immediate = {
		random_country = {
			limit = {
				NOT = { this = ROOT }
				country_has_primary_culture = cu:russian
				is_diplomatic_play_committed_participant = no
				is_subject = no
				any_neighbouring_state = { 
					owner = ROOT
				}
			}
			save_scope_as = war_target
		}
	}

	option = {
		name = dvg_russian_anarchy.100.a
		default_option = yes

		scope:war_target = {
			change_relations = { 
				country = ROOT
				value = -100
			}
		}

		create_diplomatic_play = {
			name = dp_unify_annex_russia
		
			target_country = scope:war_target
			
			war = no
			
			type = dp_annex_war

			add_war_goal = {
				holder = scope:war_target
				type = annex_country
				target_country = ROOT
			}
		}
	}
}

# Russian anarchy done
dvg_russian_anarchy.200 = {
	type = country_event
	placement = ROOT

	title = dvg_russian_anarchy.200.t
	desc = dvg_russian_anarchy.200.d
	flavor = dvg_russian_anarchy.200.f

	event_image = {
		video = "gfx/event_pictures/unspecific_signed_contract.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/unspecific/signed_contract"

	icon = "gfx/interface/icons/event_icons/event_portrait.dds"

	duration = 3

	trigger = {
	}

	option = {
		name = dvg_russian_anarchy.200.a
		default_option = yes
		every_interest_group = {
			limit = {
				is_in_government = yes
			}
			leader = {
				add_modifier = {
					name = russia_unification_popularity
					months = long_modifier_time
				}
			}
		}
		
		remove_modifier = diplomatic_plays_blocked
		remove_modifier = dvg_rock_and_hard_place
		remove_modifier = dvg_rus_enemies_all_sides
		remove_modifier = dvg_rus_anarchy

		every_subject_or_below = {
			limit = { 
				is_subject_of = ROOT
				country_has_primary_culture = cu:russian
			}
			save_scope_as = subject_to_annex
			ROOT = {
				annex = scope:subject_to_annex
			}
		}
		change_tag = MUS
	}
}
