﻿je_india_non_cooperation_movement = {
	should_be_pinned_by_default = yes
	icon = "gfx/interface/icons/event_icons/waving_flag.dds"

	group = je_group_historical_content

	modifiers_while_active = {
		national_swadeshi_movement # boost of political activity from discriminated pops
	}

	is_shown_when_inactive = {
		has_dlc_feature = ip2_content
		c:BIC ?= this
		is_subject = yes
		has_technology_researched = pan-nationalism
	}

	possible = {
		any_political_movement = { 
			is_political_movement_type = movement_india_pan_national
			political_movement_radicalism >= 0.35
		}
		is_subject = yes
		NOT = {
			any_primary_culture = {
				has_discrimination_trait = south_asian_heritage
			}
		}
		hidden_trigger = {
			exists = top_overlord
		}
		trigger_if = {
			limit = {
				ROOT.market_capital = {
					NOT = { owner = root.top_overlord }
				}
			}
			market = {
				any_trade_route = {
					is_trade_route_productive = yes
					exporter.owner = root.top_overlord
					level >= 5
				}
			}
		}
		trigger_if = {
			limit = {
				ROOT.market_capital = {
					owner = root.top_overlord
				}
			}
			"ROOT.economic_dependence(top_overlord)" > 3
		}
	}

	immediate = {
		top_overlord = {
			save_scope_as = probably_britain_scope
		}
		ROOT = {
			save_scope_as = india_scope

			if = {
				limit = {
					ROOT.market_capital = {
						NOT = { owner = root.top_overlord }
					}
					market = {
						any_trade_route = {
							is_trade_route_productive = yes
							exporter.owner = root.top_overlord
							level >= 5
						}
					}
				}
				market = {
					ordered_trade_route = {
						limit = {
							is_trade_route_productive = yes
							exporter.owner = root.top_overlord
						}
						order_by = level
						save_scope_as = british_trade_route
						lock_trade_route = {
							years = 2 			# to prevent immediate cheesing
						}
	
						goods = {
							save_scope_as = british_trade_route_goods
						}
					}
				}
				set_variable = non_cooperation_trade_route
			}
			else_if = {
				limit = {
					ROOT.market_capital = {
						owner = root.top_overlord
					}
					"ROOT.economic_dependence(top_overlord)" > 3
				}
				market = {
					ordered_market_goods = {
						limit = {
							is_tradeable = yes
							market_goods_sell_orders > 500
						}
						order_by = market_goods_pricier

						goods = {
							save_scope_as = british_trade_route_goods	# need a good to be called on for loc in the non-trade-route path
						}
					}
				}
				set_variable = non_cooperation_common_market
			}
		}
		random_political_movement = { 
			limit = {
				is_political_movement_type = movement_india_pan_national
				political_movement_radicalism >= 0.35
			}
			save_scope_as = indian_independence_movement
		}
		trigger_event = { id = india_non_cooperation.1 popup = yes }
	}

	timeout = 3650 # ten years

	complete = {
		trigger_if = {
			limit = {
				has_variable = non_cooperation_trade_route
			}
			scope:british_trade_route = {
				is_trade_route_productive = no
			}
		}
		trigger_else_if = {
			limit = {
				has_variable = non_cooperation_common_market
			}
			"ROOT.economic_dependence(top_overlord)" < 2.5
		}
	}

	on_complete = {
		trigger_event = { id = india_non_cooperation.7 popup = yes }
		remove_variable = non_cooperation_trade_route
		remove_variable = non_cooperation_common_market
	}

	fail = {
		OR = {
			custom_tooltip = {
				text = india_independence_movement_defeated_tt
				OR = {
					NOT = {
						any_political_movement = { 
							is_political_movement_type = movement_india_pan_national
						}
					}
					any_political_movement = {
						is_political_movement_type = movement_india_pan_national
						political_movement_radicalism <= 0.1
					}
				}
			}
			trigger_if = {
				limit = {
					exists = scope:indian_independence_movement
				}
				custom_tooltip = {
					text = india_non_cooperation_violence_escalates_tt
					any_political_movement = {
						is_political_movement_type = movement_india_pan_national
						political_movement_radicalism >= define:NPolitics|MIN_RADICALISM_FOR_CIVIL_WAR_PROGRESSION # Minimum radicalism threshhold to trigger civil war. 0.75 as of time of writing, but linking it directly to that value should make maintenance easier.
					}
				}
			}
		}
	}

	on_fail = {
		if = {
			limit = {
				any_political_movement = {
					is_political_movement_type = movement_india_pan_national
					political_movement_radicalism >= define:NPolitics|MIN_RADICALISM_FOR_CIVIL_WAR_PROGRESSION
				}
			}
			trigger_event = india_non_cooperation.5
		}
		else_if = {
			limit = {
				OR = {
					NOT = {
						any_political_movement = { 
							is_political_movement_type = movement_india_pan_national
						}
					}
					any_political_movement = {
						is_political_movement_type = movement_india_pan_national
						political_movement_radicalism <= 0.1
					}
				}
			}
			if = {
				limit = { has_journal_entry = je_india_home_rule }
				custom_tooltip = india_bar_retreat_25_tt
			}
			trigger_event = india_non_cooperation.6
		}
		remove_variable = non_cooperation_trade_route
		remove_variable = non_cooperation_common_market
	}

	on_timeout = {
		trigger_event = india_non_cooperation.6
		if = {
			limit = { has_journal_entry = je_india_home_rule }
			custom_tooltip = india_bar_retreat_25_tt
		}
		remove_variable = non_cooperation_trade_route
		remove_variable = non_cooperation_common_market
	}

	invalid = {
		OR = {
			AND = {
				ROOT.market_capital = {
					NOT = { owner = root.top_overlord }
				}
				NOT = { exists = scope:british_trade_route }
			}

			ROOT = {
				is_subject = no
			}

			AND = {
				has_variable = non_cooperation_trade_route
				ROOT.market_capital = {
					owner = root.top_overlord
				}
			}
			
			AND = {
				has_variable = non_cooperation_common_market
				ROOT.market_capital = {
					NOT = { owner = root.top_overlord }
				}
			}
		}
	}

	on_invalid = {
		remove_variable = non_cooperation_trade_route
		remove_variable = non_cooperation_common_market
	}

	on_monthly_pulse = {
		random_events = {
			60 = 0
			20 = india_non_cooperation.3
			20 = india_non_cooperation.4
		}
	}
}
