﻿je_pedro_brazil = {
	icon = "gfx/interface/icons/law_icons/monarchy.dds"

	group = je_group_historical_content

	on_monthly_pulse = {
		events = {
			# Landowners become republicans
			pedro.2
			# Pedro comes of age
			pedro.3
			# AF/LA are marginalized
			pedro.5
			# AF/LA are powerful and not in government
			pedro.6
			# Republicans ask Pedro to be President
			pedro.9
			# Pedro signs the constitution
			pedro.11
		}
		random_events = {
			100 = 0
			10 = pedro.4 # Pedro becomes ill
			10 = pedro.12 # Death of Pedro's heirs
			10 = pedro.14 # To the Highest Standards
		}
		effect = {
			if = {
				limit = {
					any_civil_war = {
						civil_war_progress > 0.5
					}
					NOT = { has_variable = je_pedro_civilwar_point }
				}
				change_variable = { name = pedropoints subtract = 1 }
				set_variable = { name = je_pedro_civilwar_point years = 3 }
			}
			if = {
				limit = {
					OR = {
						in_default = yes
						has_modifier = declared_bankruptcy
					}
					NOT = { has_variable = je_pedro_default_point }
				}
				change_variable = { name = pedropoints subtract = 1 }
				set_variable = { name = je_pedro_default_point }
			}
			if = {
				limit = {
					country_rank >= rank_value:great_power
					NOT = { has_variable = je_pedro_gp_point }
				}
				change_variable = { name = pedropoints add = 1 }
				set_variable = { name = je_pedro_gp_point }
			}
		}
	}

	on_weekly_pulse = {
		events = {
			# startup event
			pedro.1
		}
	}

	immediate = {
		set_variable = {
			name = pedropoints
			value = 0
		}
		root = {
			save_scope_as = brazil_scope
		}
		ig:ig_intelligentsia = {
			save_scope_as = intelligentsia_ig
		}
	}

	complete = {
		has_law = law_type:law_monarchy
		AND = {
			custom_tooltip = {
				text = je_pedro_success
				var:pedropoints > 5
			}
			custom_tooltip = {
				text = pedro_dead
				ruler = {
					NOT = {
						has_variable = is_pedro
					}
				}
			}
		}
	}

	on_complete = {
		hidden_effect = {
			ruler ?= { set_character_immortal = no }
			if = {
				limit = {
					exists = heir
				}
				heir = { set_character_immortal = no }
			}
		}
		custom_tooltip = {
			text = pedro_heir_empowered_tt
		}
		custom_tooltip = {
			text = pedro_je_royalists_more_common_tt
			set_variable = brz_enduring_empire
		}
		# Monarchy survives
		trigger_event = {
			id = pedro.7
			popup = yes
		}
	}

	fail = {
		OR = {
			AND = {
				custom_tooltip = {
					text = je_pedro_fail
					var:pedropoints <= 0
				}
				ig:ig_landowners = {
					is_marginal = no
				}
				ig:ig_armed_forces = {
					is_marginal = no
				}
			}
			AND = {
				custom_tooltip = {
					text = je_pedro_fail_2
					var:pedropoints <= 5
				}
				custom_tooltip = {
					text = pedro_dead
					ruler = {
						NOT = {
							has_variable = is_pedro
						}
					}
				}
			}
		}
	}

	on_fail = {
		hidden_effect = {
			ruler ?= { set_character_immortal = no }
			if = {
				limit = {
					exists = heir
				}
				heir = { set_character_immortal = no }
			}
			if = {
				limit = {
					any_scope_state = {
						state_region = s:STATE_SANTA_CATARINA
					}
				}
				random_scope_state = {
					limit = { state_region = s:STATE_SANTA_CATARINA }
			        set_hub_name = {
			            type = port
			            name = HUB_NAME_STATE_SANTA_CATARINA_port_bra_republic
			        }
		        }
			}
		}
		# Monarchy ended by coup
		trigger_event = {
			id = pedro.8
			popup = yes
		}
		show_as_tooltip = {
			if = {
				limit = {
					NOT = { has_law = law_type:law_landed_voting }
				}
				activate_law = law_type:law_landed_voting
			}
			activate_law = law_type:law_presidential_republic
			if = {
				limit = {
					ig:ig_landowners = {
						is_in_government = no
						is_marginal = no
					}
				}
				ig:ig_landowners = {
					add_ruling_interest_group = yes
				}
			}
			if = {
				limit = {
					ig:ig_armed_forces = {
						is_in_government = no
						is_marginal = no
					}
				}
				ig:ig_armed_forces = {
					add_ruling_interest_group = yes
				}
			}
		}
	}

	invalid = {
		NOT = { has_law = law_type:law_monarchy }
	}

	on_invalid = {
		hidden_effect = {
			ruler ?= { set_character_immortal = no }
			if = {
				limit = {
					exists = heir
				}
				heir = { set_character_immortal = no }
			}
		}
	}

	current_value = {
		value = root.var:pedropoints
	}

	goal_add_value = {
		add = 10
	}

	progressbar = yes

	weight = 100

	can_revolution_inherit = no
	transferable = no
	should_be_pinned_by_default = yes
}

# added by pedro.9
je_pedro_republic = {
	icon = "gfx/interface/icons/law_icons/presidential_republic.dds"

	group = je_group_historical_content

	complete = {
		has_law = law_type:law_presidential_republic
	}

	timeout = 3600

	on_complete = {
		# the actual ending event needs to be triggered from on_law_enactment_pass
		show_as_tooltip = {
			ruler = {
				set_character_as_ruler = yes
				set_as_interest_group_leader = yes
			}
		}
	}

	fail = {
		OR = {
			NOT = { has_journal_entry = je_pedro_brazil }
			custom_tooltip = {
				text = pedro_dead
				ruler = {
					NOT = {
						has_variable = is_pedro
					}
				}
			}
		}
	}

	on_timeout = {
		remove_pedropoint_effect = yes
	}

	invalid = {
		NOR = {
			has_law = law_type:law_monarchy
			has_law = law_type:law_presidential_republic
		}
	}

	weight = 100
	can_revolution_inherit = no
	transferable = no
	should_be_pinned_by_default = yes
}

# Added by pedro.13
je_isabel = {
	icon = "gfx/interface/icons/law_icons/monarchy.dds"

	group = je_group_historical_content

	immediate = {
		heir = {
			save_scope_as = isabel_scope
		}
	}	

	complete = {
		NOT = {
			has_law = law_type:law_no_womens_rights
		}
		scope:journal_entry = { is_goal_complete = yes }
	}

	on_complete = {
		trigger_event = {
			id = pedro.13
			popup = yes
		}
		custom_tooltip = {
			text = isabel_je_tt
		}
		show_as_tooltip = {
			ruler = { remove_modifier = isabel_heir_popularity }
			heir = { remove_modifier = isabel_heir_popularity }
		}
	}

	fail = {
		OR = {
			NOT = { has_journal_entry = je_pedro_brazil }
			heir ?= {
				custom_tooltip = {
					text = is_isabella_tt
					NOT = {
						has_variable = isabel_var
					}
				}
			}
			NOT = {
				exists = heir
			}
		}
	}

	on_monthly_pulse = {
		effect = {
			if = {
				limit = {
					NOT = {
						has_law = law_type:law_no_womens_rights
					}
				}
			}
			change_variable = {
				name = isabel_points
				add = 1
			}
		}
	}

	is_progressing = {
		has_journal_entry = je_pedro_brazil
		scope:target ?= {
			is_heir = yes
		}
		NOT = {
			has_law = law_type:law_no_womens_rights
		}
	}

	current_value = {
		value = root.var:isabel_points
	}

	goal_add_value = {
		add = 120
	}

	progressbar = yes

	weight = 100
	can_revolution_inherit = no
	transferable = no
	should_be_pinned_by_default = yes
}