#########################################################
#
# Revolution Events 
# REV.1 to REV.5 are reserved (REV.3 in stock)
#
#########################################################

namespace = REV

# A revolution breaks out in the country (temporary rebel title created, with a leader and a war)
province_event = {
	id = REV.1
	desc = EVTDESC_REV_1
	picture = GFX_evt_revolution_ideologies
	border = GFX_event_normal_frame_war

	trigger = {
		OR = {
			has_province_modifier = stronghold_enlightment
			has_province_modifier = communist_stronghold
			has_province_modifier = totalitarist_stronghold
		}
		
		revolt_risk = 0.01

		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		owner = {
			top_liege = {
				NOT = { religion_group = ROOT }
			}
		}
		
		kingdom = {
			OR = {
				has_holder = no
				ROOT = {
					owner = {
						de_facto_liege = PREVPREV
					}
				}
			}
			culture = ROOT
		}
		
		# Heretic revolts have prio
		OR = { 
			is_heretic = no
			owner = {
				top_liege = {
					NOT = { religion_group = ROOT }
				}
			}
		}
		
		NOT = { # Not if there is already an ongoing revolt
			owner = {
				top_liege = {
					war = yes
					
					any_war = {
						defender = { character = PREV }
						OR = {
							AND = {
								using_cb = peasant_revolt
								war_title = ROOT # The county
							}
							AND = {
								using_cb = heretic_revolt
								attacker = { religion = ROOT }
							}
							AND = {
								using_cb = religious_revolt
								attacker = { religion = ROOT }
							}
							AND = {
								using_cb = liberation_revolt
								thirdparty_title_scope = {
									ROOT = {
										kingdom = {
											title = PREVPREV
										}
									}
								}
							}
							AND = {
								using_cb = revolution_war
								thirdparty_title_scope = {
									ROOT = {
										kingdom = {
											title = PREVPREV
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 180
		modifier = {
			factor = 2 
			NOT = { revolt_risk = 0.05 }
		}
		modifier = {
			factor = 0.75 
			revolt_risk = 0.1
		}
		modifier = {
			factor = 0.5 
			revolt_risk = 0.2
		}
		modifier = {
			factor = 0.25
			revolt_risk = 0.3
		}
	}
	
	immediate = {
		if = {
			limit = {
				NOT = { religion = anarcho-feminism }
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ROOT
				female = no
				age = 20
				health = 7
				fertility = 0.7
				attributes = {
					martial = 10
					diplomacy = 9
				}
				trait = just
				trait = brave
				trait = gregarious
				trait = ambitious
				trait = brilliant_strategist
				trait = inspiring_leader
			}
		}
		if = {
			limit = {
				religion = anarcho-feminism
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ROOT
				female = yes
				age = 20
				health = 7
				fertility = 0.7
				attributes = {
					martial = 10
					diplomacy = 9
				}
				trait = just
				trait = brave
				trait = gregarious
				trait = ambitious
				trait = brilliant_strategist
				trait = inspiring_leader
			}
		}
		
		new_character = {
			set_character_flag = revolutionary_leader
			
			create_title = {
				tier = DUKE
				landless = yes
				temporary = yes
				rebel = yes
				culture = ROOT
				name = "REVOLUTION_TITLE"
				holder = THIS
			}
			
			wealth = 100
			
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 3
				troops = {
					archers = { 6 6 }
					light_cavalry = { 3 3 }
					knights = { 1 1 }
					light_infantry = { 7 7 }
					heavy_infantry = { 3 3 }
				}
				attrition = 1.0
			}
			
			spawn_nationalist_army_effect = yes
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = powerful
					}
				}
				spawn_nationalist_army_effect = yes
				wealth = 150
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = very_powerful
					}
				}
				spawn_nationalist_army_effect = yes
				spawn_nationalist_army_effect = yes
				spawn_nationalist_army_effect = yes
				wealth = 250
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = extremely_powerful
					}
				}
				spawn_nationalist_army_effect = yes
				spawn_nationalist_army_effect = yes
				spawn_nationalist_army_effect = yes
				spawn_nationalist_army_effect = yes
				spawn_nationalist_army_effect = yes
				wealth = 350
			}
			
			# DoW on the province top liege
			ROOT = {
				owner = {
					top_liege = {
						reverse_war = {
							target = PREVPREVPREV
							casus_belli = revolution_war
							thirdparty_title = ROOT # The county...
							tier = KING # ... but really the de jure kingdom
						}
						reverse_opinion = {
							who = PREVPREVPREV
							modifier = opinion_evil_tyrant
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = REV.2
				}
			}
		}
	}
	
	option = {
		name = "EVTOPTA_REV_1"
	}
}

character_event = {
	id = REV.2
	desc = EVTDESC_REV_2
	picture = GFX_evt_revolution_ideologies
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_REV_2
	}
}

# More revolutionary forces rise up to reinforce an ongoing revolt
province_event = {
	id = REV.4
	desc = EVTDESC_REV_4
	picture = GFX_evt_revolution_reinforcements
	border = GFX_event_normal_frame_war

	trigger = {
		OR = {
			has_province_modifier = stronghold_enlightment
			has_province_modifier = communist_stronghold
			has_province_modifier = totalitarist_stronghold
		}

		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		# There is already an ongoing revolution in the same country
		owner = {
			top_liege = {
				war = yes
				any_war = {
					defender = { character = PREV }
					using_cb = revolution_war
					thirdparty_title_scope = {
						ROOT = {
							kingdom = {
								title = PREVPREV
							}
						}
					}
				}
			}
		}
		
		owner = {
			top_liege = {
				NOT = { religion_group = ROOT }
			}
		}
	}
	
	mean_time_to_happen = {
		months = 180
		modifier = {
			factor = 0.75 
			revolt_risk = 0.1
		}
		modifier = {
			factor = 0.75 
			revolt_risk = 0.2
		}
		modifier = {
			factor = 0.5
			revolt_risk = 0.3
		}
	}
	
	immediate = {
		add_province_modifier = {
			name = recent_county_uprising
			duration = 1825 # Five years of -100% revolt risk in this county
		}
		owner = {
			top_liege = {
				any_war = {
					limit = {
						defender = { character = PREV }
						using_cb = revolution_war
						thirdparty_title_scope = {
							ROOT = {
								kingdom = {
									title = PREVPREV
								}
							}
						}
					}
					attacker = {
						spawn_nationalist_reinforcements_effect = yes
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = powerful
								}
							}
							spawn_nationalist_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = very_powerful
								}
							}
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = extremely_powerful
								}
							}
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = REV.5
				}
			}
		}
	}
	
	option = {
		name = OK
	}
}

character_event = {
	id = REV.5
	desc = EVTDESC_REV_5
	picture = GFX_evt_revolution_reinforcements
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_REV_5
	}
}