﻿je_uneasy_raj = {
	icon = "gfx/interface/icons/event_icons/event_protest.dds"

	group = je_group_historical_content

	scripted_progress_bar = sepoy_mutiny_progress_bar_bengal
	scripted_progress_bar = sepoy_mutiny_progress_bar_bombay
	scripted_progress_bar = sepoy_mutiny_progress_bar_madras

	immediate = {
		sr:region_bengal = {
			save_scope_as = bengal_sr_scope
		}
		sr:region_bombay = {
			save_scope_as = bombay_sr_scope
		}
		sr:region_madras = {
			save_scope_as = madras_sr_scope
		}
		sr:region_punjab = {
			save_scope_as = punjab_sr_scope
		}
		sr:region_central_india = {
			save_scope_as = central_india_sr_scope
		}
		set_variable = {
			name = sepoy_mutiny_timer_var
			value = 0
		}
	}

	complete = {
		custom_tooltip = {
			text = je_avert_sepoy_mutiny_tt_1
			has_variable = consolidated_colonial_rule
		}
		root.average_sol >= 10
		radical_fraction = {
			value <= 0.10
		}
	}

	fail = {
		custom_tooltip = {
			text = je_uneasy_raj_tt_2
			var:sepoy_mutiny_timer_var >= 100
		}		
	}

	timeout = 9000

	on_timeout = {
		trigger_event = { id = sepoy_mutiny_events.3 popup = yes }
		add_journal_entry = { type = je_sepoy_mutiny }
		# Bengal Presidency
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" <= 25
				}
			}
			set_variable = sepoy_mutiny_bengal_effect_critical
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" > 25
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" <= 50
				}
			}
			set_variable = sepoy_mutiny_bengal_effect_high
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" > 50
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" <= 75
				}
			}
			set_variable = sepoy_mutiny_bengal_effect_medium
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" > 75
				}
			}
			set_variable = sepoy_mutiny_bengal_effect_low
		}
		# Bombay Presidency
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" <= 25
				}
			}
			set_variable = sepoy_mutiny_bombay_effect_critical
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" > 25
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" <= 50
				}
			}
			set_variable = sepoy_mutiny_bombay_effect_high
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" > 50
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" <= 75
				}
			}
			set_variable = sepoy_mutiny_bombay_effect_medium
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" > 75
				}
			}
			set_variable = sepoy_mutiny_bombay_effect_low
		}
		# Madras Presidency
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" <= 25
				}
			}
			set_variable = sepoy_mutiny_madras_effect_critical
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" > 25
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" <= 50
				}
			}
			set_variable = sepoy_mutiny_madras_effect_high
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" > 50
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" <= 75
				}
			}
			set_variable = sepoy_mutiny_madras_effect_medium
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" > 75
				}
			}
			set_variable = sepoy_mutiny_madras_effect_low
		}		
	}

	invalid = {
	}

	on_complete = {
	}

	on_fail = {
		trigger_event = { id = sepoy_mutiny_events.3 popup = yes }
		add_journal_entry = { type = je_sepoy_mutiny }
		# Bengal Presidency
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" <= 25
				}
			}
			set_variable = sepoy_mutiny_bengal_effect_critical
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" > 25
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" <= 50
				}
			}
			set_variable = sepoy_mutiny_bengal_effect_high
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" > 50
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" <= 75
				}
			}
			set_variable = sepoy_mutiny_bengal_effect_medium
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" > 75
				}
			}
			set_variable = sepoy_mutiny_bengal_effect_low
		}
		# Bombay Presidency
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" <= 25
				}
			}
			set_variable = sepoy_mutiny_bombay_effect_critical
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" > 25
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" <= 50
				}
			}
			set_variable = sepoy_mutiny_bombay_effect_high
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" > 50
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" <= 75
				}
			}
			set_variable = sepoy_mutiny_bombay_effect_medium
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" > 75
				}
			}
			set_variable = sepoy_mutiny_bombay_effect_low
		}
		# Madras Presidency
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" <= 25
				}
			}
			set_variable = sepoy_mutiny_madras_effect_critical
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" > 25
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" <= 50
				}
			}
			set_variable = sepoy_mutiny_madras_effect_high
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" > 50
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" <= 75
				}
			}
			set_variable = sepoy_mutiny_madras_effect_medium
		}
		if = {
			limit = {
				je:je_uneasy_raj = { 
					"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" > 75
				}
			}
			set_variable = sepoy_mutiny_madras_effect_low
		}
	}

	on_weekly_pulse = {
		events = {
		}
		effect = {
		}
	}

	on_monthly_pulse = {
		effect = {
			if = {
				limit = {
					OR = {
						je:je_uneasy_raj = { 
							"scripted_bar_progress(sepoy_mutiny_progress_bar_bengal)" < 75
						}
						je:je_uneasy_raj = { 
							"scripted_bar_progress(sepoy_mutiny_progress_bar_bombay)" < 75
						}
						je:je_uneasy_raj = { 
							"scripted_bar_progress(sepoy_mutiny_progress_bar_madras)" < 75
						}
					}
				}
				change_variable = {
					name = sepoy_mutiny_timer_var
					add = 1
				}
			}
		}
		random_events = {
			11 = 0
			1 = sepoy_mutiny_events.6
			1 = raj.4
			1 = raj.5
		}
	}

	weight = 100
	should_be_pinned_by_default = yes
}

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

	group = je_group_historical_content

	complete = {
		trigger_if = {
			limit = { 
				c:MUG ?= {
					has_variable = sepoy_mutiny_revolter_var
				}
			}
			c:MUG = { is_country_alive = no }
		}
		trigger_if = {
			limit = { 
				c:BGL ?= {
					has_variable = sepoy_mutiny_revolter_var
				}
			}
			c:BGL = { is_country_alive = no }
		}
		trigger_if = {
			limit = { 
				c:SAT ?= {
					has_variable = sepoy_mutiny_revolter_var
				}
			}
			c:SAT = { is_country_alive = no }
		}
		trigger_if = {
			limit = { 
				c:PAN ?= {
					has_variable = sepoy_mutiny_revolter_var
				}
			}
			c:PAN = { is_country_alive = no }
		}
		highest_secession_progress < 0.3
		has_any_secessionists_broken_out = no
		is_at_war = no
	}

	on_complete = {
		if = {
			limit = {
				exists = c:GBR
				is_subject_of = c:GBR
				c:GBR = {
					is_country_alive = yes
					NOT = { has_variable = british_raj_var }
				}
			}
			c:GBR = {
				trigger_event = { id = raj.1 days = 0 popup = yes }
			}
		}
		else = {
			add_modifier = {
				name = company_crushed_mutiny
				months = normal_modifier_time
			}
		}
		hidden_effect = {
			every_scope_state = {
				limit = {
					owner = ROOT
					has_variable = bic_incorporated_state
				}
				set_state_type = incorporated
				remove_variable = bic_incorporated_state
			}
		}
	}

	fail = {
		OR = {
			trigger_if = {
				limit = { 
					c:MUG ?= {
						has_variable = sepoy_mutiny_revolter_var
					}
				}
				exists = c:MUG
				NOT = { 
					has_war_with = c:MUG 
					has_state_in_state_region = STATE_DELHI
					has_state_in_state_region = STATE_AGRA
				}
			}
			trigger_if = {
				limit = { 
					c:BGL ?= {
						has_variable = sepoy_mutiny_revolter_var
					}
				}
				exists = c:BGL
				NOT = { 
					has_war_with = c:BGL
					has_state_in_state_region = STATE_EAST_BENGAL
					has_state_in_state_region = STATE_WEST_BENGAL
				}
			}
			trigger_if = {
				limit = { 
					c:SAT ?= {
						has_variable = sepoy_mutiny_revolter_var
					}
				}
				exists = c:SAT
				NOT = { 
					has_war_with = c:SAT
					has_state_in_state_region = STATE_BOMBAY
				}
			}
			trigger_if = {
				limit = { 
					c:PAN ?= {
						has_variable = sepoy_mutiny_revolter_var
					}
				}
				exists = c:PAN
				NOT = { 
					has_war_with = c:PAN
					has_state_in_state_region = STATE_PUNJAB
					has_state_in_state_region = STATE_HILL_PUNJAB
				}
			}
			trigger_if = {
				limit = { 
					c:KNO ?= {
						has_variable = sepoy_mutiny_revolter_var
					}
				}
				exists = c:KNO
				NOT = { 
					has_war_with = c:KNO
					has_state_in_state_region = STATE_MADRAS
				}
			}
		}
		hidden_trigger = {
			NOT = {
				any_diplomatic_play = {
					any_scope_play_involved = { this = root }
					is_diplomatic_play_type = dp_annex_war
					target = {
						capital = {
							OR = {
								region = sr:region_bengal
								region = sr:region_bombay
								region = sr:region_madras
								region = sr:region_punjab
								region = sr:region_central_india
							}
						}
					}
				}
			}
		}
	}

	on_fail = {
		trigger_event = { id = sepoy_mutiny_events.2 days = 0 popup = yes }
	}

	weight = 100
	should_be_pinned_by_default = yes
}#

je_uneasy_raj_tracker = {
	icon = "gfx/interface/icons/event_icons/event_protest.dds"

	group = je_group_historical_content

	scripted_progress_bar = sepoy_mutiny_progress_bar_bengal
	scripted_progress_bar = sepoy_mutiny_progress_bar_bombay
	scripted_progress_bar = sepoy_mutiny_progress_bar_madras

	is_shown_when_inactive = {
		is_princely_state = yes
        country_is_in_india = yes
		c:BIC ?= {
			has_journal_entry = je_uneasy_raj
		}
	}

	possible = {
		is_princely_state = yes
        is_subject = yes
        country_is_in_india = yes
	}

	immediate = {
		c:BIC = {
			save_scope_as = british_india_scope
		}
		sr:region_bengal = {
			save_scope_as = bengal_sr_scope
		}
		sr:region_bombay = {
			save_scope_as = bombay_sr_scope
		}
		sr:region_madras = {
			save_scope_as = madras_sr_scope
		}
		sr:region_punjab = {
			save_scope_as = punjab_sr_scope
		}
		sr:region_central_india = {
			save_scope_as = central_india_sr_scope
		}
	}

	complete = {
		c:BIC ?= {
			NOT = {
				has_journal_entry = je_uneasy_raj
			}
		}
	}

	timeout = 9000

	invalid = {
		NOT = {
			exists = c:BIC
		}
	}

	weight = 100
	should_be_pinned_by_default = yes
}