﻿capitulate_to_revolution = {
	scope:ongoing_revolution_movement = { #Can't trigger if they want governance reforms anyway.
		this.desired_law = {
			save_scope_as = revolutionaries_law
		}
	}
	every_interest_group = {
		limit = {
			is_insurrectionary = yes
		}
		set_variable = { name = revolutionary_ig days = 7 }
	}
	ordered_interest_group = {
		limit = {
			is_insurrectionary = yes
		}
		order_by = ig_clout
		save_scope_as = revolution_leader_ig
	}
	if = { # Never activate Governance Principles twice.
		limit = {
			NOR = {
				scope:revolutionaries_law = law_type:law_presidential_republic
				scope:revolutionaries_law = law_type:law_parliamentary_republic
				scope:revolutionaries_law = law_type:law_monarchy
				scope:revolutionaries_law = law_type:law_council_republic
				scope:revolutionaries_law = law_type:law_theocracy
			}
		}
		if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_council_republic
						value = strongly_approve
					}
				}
				NOT = {
					has_law = law_type:law_council_republic
				}
			}
			activate_law = law_type:law_council_republic
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_monarchy
						value = strongly_approve
					}
				}
				NOT = {
					has_law = law_type:law_monarchy
				}
			}
			activate_law = law_type:law_monarchy
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_parliamentary_republic
						value = strongly_approve
					}
				}
				NOT = {
					has_law = law_type:law_parliamentary_republic
				}
			}
			activate_law = law_type:law_parliamentary_republic
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_presidential_republic
						value = strongly_approve
					}
				}
				NOT = {
					has_law = law_type:law_presidential_republic
				}
			}
			activate_law = law_type:law_presidential_republic
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_theocracy
						value = strongly_approve
					}
				}
				NOT = {
					has_law = law_type:law_theocracy
				}
			}
			activate_law = law_type:law_theocracy
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_council_republic
						value = approve
					}
				}
				NOT = {
					has_law = law_type:law_council_republic
				}
			}
			activate_law = law_type:law_council_republic
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_monarchy
						value = approve
					}
				}
				NOT = {
					has_law = law_type:law_monarchy
				}
			}
			activate_law = law_type:law_monarchy
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_parliamentary_republic
						value = approve
					}
				}
				NOT = {
					has_law = law_type:law_parliamentary_republic
				}
			}
			activate_law = law_type:law_parliamentary_republic
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_presidential_republic
						value = approve
					}
				}
				NOT = {
					has_law = law_type:law_presidential_republic
				}
			}
			activate_law = law_type:law_presidential_republic
		}
		else_if = {
			limit = {
				scope:revolution_leader_ig = {
					law_stance = {
						law = law_type:law_theocracy
						value = approve
					}
				}
				NOT = {
					has_law = law_type:law_theocracy
				}
			}
			activate_law = law_type:law_theocracy
		}
	}

	if = {
		limit = {
			scope:ongoing_revolution_movement = {
				is_political_movement_type = movement_to_preserve
			}
		}
		cancel_enactment = yes
	}
	else = {
		activate_law = scope:revolutionaries_law
	}

	add_radicals = {
		value = 0.4
	}
	
	every_interest_group = {
		limit = {
			has_variable = revolutionary_ig
		}
		owner = {
			add_loyalists = {
				value = 1
				interest_group = PREV
			}
		}
	}

	if = {
		limit = {
			country_has_voting_franchise = yes
		}
		call_election = {
			months = 6
		}
	}
	if = {
		limit = {
			NOT = {
				has_law = law_type:law_monarchy
			}
		}
		hidden_effect = {
			scope:revolution_leader_ig = {
				leader = {
					set_character_as_ruler = yes
				}
			}
		}
	}
	
	every_interest_group = {
		limit = {
			is_in_government = yes
		}
		remove_ruling_interest_group = yes
		add_modifier = {
			name = modifier_revolution_defeated_light
			months = normal_modifier_time
			is_decaying = yes
		}
	}

	every_interest_group = {
		limit = {
			has_variable = revolutionary_ig
		}
		hidden_effect = {
			abandon_revolution = yes
		}
		add_modifier = {
			name = modifier_revolution_victorious_light
			months = normal_modifier_time
			is_decaying = yes
		}
		if = {
			limit = {
				is_insurrectionary = no
			}
			add_ruling_interest_group = yes
		}
	}
}