#namespaces have to be declared else only the last defined event in the file can fire
namespace=missionaryguard
namespace=piraterep

character_event = { #Create a new missionary guard using a temporary title, to use on landless courtiers at the intended liege's court
	id = missionaryguard.1
	hide_window = yes
	
	is_triggered_only = yes

	immediate = {
		host = {
			primary_title = {
				create_title = {
					tier = COUNT #BARON doesn't work
					name = DYNAMIC_MISSIONARY_GUARD
					landless = yes
					temporary = no
					custom_created = yes
					culture = ROOT
					holder = ROOT
					base_title = THIS
					mercenary = yes
					army_template = default_missionary_guard_composition
					replace_captain_on_death = no
					siphons_income_to_creator = 0.2
					ruler = "CAPTAIN"
					ruler_female = "CAPTAIN"
					foa = "CAPTAIN_FOA"
				}
				new_title = {
					religion = ROOT
					set_flag = force_missionary_guard_government
					make_primary_title = yes
					de_jure_liege = PREV
					#Mercenary upgrades "inheritance" setup
					set_flag = missionary_guard_count_upgrades
					set_variable = { which = upgrade_light1 value = 0 }
					set_variable = { which = upgrade_light2 value = 0 }
					set_variable = { which = upgrade_light3 value = 0 }
					set_variable = { which = upgrade_heavy1 value = 0 }
					set_variable = { which = upgrade_heavy2 value = 0 }
					set_variable = { which = upgrade_heavy3 value = 0 }
					set_variable = { which = upgrade_cav1 value = 0 }
					set_variable = { which = upgrade_cav2 value = 0 }
					set_variable = { which = upgrade_cav3 value = 0 }
					set_variable = { which = upgrade_boats1 value = 0 }
					set_variable = { which = upgrade_boats2 value = 0 }
					set_variable = { which = upgrade_ltoh value = 0 }
					set_variable = { which = upgrade_ltop value = 0 }
					set_variable = { which = upgrade_ctok value = 0 }
				}
			}
			set_defacto_vassal = ROOT #if done here vassal is shown in menus immediately
			reverse_opinion = {
				name = opinion_missionary_guard_formed
				who = ROOT
			}
		}
		set_government_type = missionary_guard_government
	}
}

character_event = { #Guard management Event, ROOT = liege, various FROMs = guard vassal
	id = missionaryguard.2
	picture = GFX_evt_group_hf
	desc = EVTDESC_missionaryguard_2

	is_triggered_only = yes

	option = {
		name = EVTOPTA_missionaryguard_2
		character_event = { id = missionaryguard.201 }
	}
	option = {
		name = EVTOPTB_missionaryguard_2
		character_event = { id = missionaryguard.202 }
	}
	option = {
		name = EVTOPTD_ZE_23101
	}
}

character_event = {
	id = missionaryguard.201
	picture = GFX_evt_group_hf
	desc = EVTDESC_missionaryguard_201

	is_triggered_only = yes

	option = {
		name = EVTOPTA_missionaryguard_201
		character_event = { id = missionaryguard.211 }
	}
	option = {
		name = EVTOPTB_missionaryguard_201
		character_event = { id = missionaryguard.212 }
	}
	option = {
		name = EVTOPTC_missionaryguard_201
		character_event = { id = missionaryguard.213 }
	}
	option = {
		name = EVTOPTD_missionaryguard_201
		character_event = { id = missionaryguard.214 }
	}
}

character_event = {
	id = missionaryguard.211
	picture = GFX_evt_group_hf
	desc = EVTDESC_missionaryguard_211

	is_triggered_only = yes

	option = {
		name = EVTOPTA_missionaryguard_211
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = light_infantry
					change = 40
				}
				change_mercenary_composition = {
					type = archers
					change = 20
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_light1 value = 1 }
					}
				}
			}
		}
		wealth = -50
	}
	option = {
		name = EVTOPTB_missionaryguard_211
		trigger = { wealth = 100 }
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = light_infantry
					change = 60
				}
				change_mercenary_composition = {
					type = archers
					change = 40
				}
				change_mercenary_composition = {
					type = light_cavalry
					change = 20
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_light2 value = 1 }
					}
				}
			}
		}
		wealth = -100
	}
	option = {
		name = EVTOPTC_missionaryguard_211
		trigger = { wealth = 150 }
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = light_infantry
					change = 80
				}
				change_mercenary_composition = {
					type = archers
					change = 60
				}
				change_mercenary_composition = {
					type = light_cavalry
					change = 40
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_light3 value = 1 }
					}
				}
			}
		}
		wealth = -150
	}
	option = {
		name = EVTOPTD_ZE_23101
	}
}

character_event = {
	id = missionaryguard.212
	picture = GFX_evt_group_hf
	desc = EVTDESC_missionaryguard_211

	is_triggered_only = yes

	option = {
		name = EVTOPTA_missionaryguard_211
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = pikemen
					change = 25
				}
				change_mercenary_composition = {
					type = heavy_infantry
					change = 15
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_heavy1 value = 1 }
					}
				}
			}
		}
		wealth = -50
	}
	option = {
		name = EVTOPTB_missionaryguard_211
		trigger = { wealth = 100 }
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = pikemen
					change = 50
				}
				change_mercenary_composition = {
					type = heavy_infantry
					change = 30
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_heavy2 value = 1 }
					}
				}
			}
		}
		wealth = -100
	}
	option = {
		name = EVTOPTC_missionaryguard_211
		trigger = { wealth = 150 }
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = pikemen
					change = 60
				}
				change_mercenary_composition = {
					type = heavy_infantry
					change = 40
				}
				change_mercenary_composition = {
					type = knights
					change = 20
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_heavy3 value = 1 }
					}
				}
			}
		}
		wealth = -150
	}
	option = {
		name = EVTOPTD_ZE_23101
	}
}

character_event = {
	id = missionaryguard.213
	picture = GFX_evt_group_hf
	desc = EVTDESC_missionaryguard_211

	is_triggered_only = yes

	option = {
		name = EVTOPTA_missionaryguard_211
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = light_cavalry
					change = 40
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_cav1 value = 1 }
					}
				}
			}
		}
		wealth = -50
	}
	option = {
		name = EVTOPTB_missionaryguard_211
		trigger = { wealth = 120 }
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = light_cavalry
					change = 60
				}
				change_mercenary_composition = {
					type = knights
					change = 20
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_cav2 value = 1 }
					}
				}
			}
		}
		wealth = -120
	}
	option = {
		name = EVTOPTC_missionaryguard_211
		trigger = { wealth = 180 }
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = light_cavalry
					change = 80
				}
				change_mercenary_composition = {
					type = knights
					change = 40
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_cav3 value = 1 }
					}
				}
			}
		}
		wealth = -180
	}
	option = {
		name = EVTOPTD_ZE_23101
	}
}

character_event = {
	id = missionaryguard.214
	picture = GFX_evt_group_hf
	desc = EVTDESC_missionaryguard_211

	is_triggered_only = yes

	option = {
		name = EVTOPTA_missionaryguard_214
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = galleys
					change = 20
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_boats1 value = 1 }
					}
				}
			}
		}
		wealth = -25
	}
	option = {
		name = EVTOPTB_missionaryguard_214
		FROMFROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					type = galleys
					change = 40
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_boats2 value = 1 }
					}
				}
			}
		}
		wealth = -50
	}
	option = {
		name = EVTOPTD_ZE_23101
	}
}

character_event = {
	id = missionaryguard.202
	picture = GFX_evt_large_army
	desc = EVTDESC_missionaryguard_202

	is_triggered_only = yes

	option = {
		name = EVTOPTA_ZE_23101
		FROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					from = light_infantry
					type = heavy_infantry
					change = 50
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_ltoh value = 1 }
					}
				}
			}
		}
		wealth = -50
	}
	option = {
		name = EVTOPTB_ZE_23101
		FROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					from = light_infantry
					type = pikemen
					change = 50
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_ltop value = 1 }
					}
				}
			}
		}
		wealth = -50
	}
	option = {
		name = EVTOPTC_ZE_23101
		FROMFROM = {
			primary_title = {
				change_mercenary_composition = {
					from = light_cavalry
					type = knights
					change = 50
				}
				hidden_tooltip = {
					if = {
						limit = { has_flag = missionary_guard_count_upgrades }
						change_variable = { which = upgrade_ctok value = 1 }
					}
				}
			}
		}
		wealth = -50
	}
	option = {
		name = EVTOPTD_ZE_23101
	}
}

character_event = { # Summon Pirate Conscripts
	id = piraterep.1
	desc = EVTDESC_piraterep_1
    picture = GFX_evt_norse_tempest
    border = GFX_event_normal_frame_war

    is_triggered_only = yes
    
	immediate = { 
		random_list = { 
			33 = { sound_effect = warriors_of_ukko_01 } 
			33 = { sound_effect = warriors_of_ukko_02 } 
			33 = { sound_effect = warriors_of_ukko_03 } 
		}
	}
    option = {
        name = EVTOPTA_piraterep_1
		capital_scope = {
			show_scope_change = no
			ROOT = {
				show_scope_change = no
				spawn_unit = { 
					province = PREV
					owner = ROOT
					troops = { 
						light_infantry = { 500 500 }
						archers = { 300 300 }
					}
					earmark = pirate_conscripts
					attrition = 0.5
					disband_on_peace = yes
				}
				spawn_fleet = {
					province = closest
					owner = ROOT
					troops = {
						galleys = { 10 10 }
					}
					earmark = pirate_conscripts_ships
					disband_on_peace = yes
				}
			}
		}
		add_character_modifier = {
			name = pirate_conscription_small
			years = 5
		}
		prestige = -200
		wealth = -30
		ai_chance = {
			factor = 30
		}
	}
    option = {
        name = EVTOPTB_piraterep_1
		trigger = { prestige = 400 wealth = 60 }
		capital_scope = {
			show_scope_change = no
			ROOT = {
				show_scope_change = no
				spawn_unit = { 
					province = PREV
					owner = ROOT
					troops = { 
						light_infantry = { 1000 1000 }
						archers = { 600 600 }
					}
					earmark = pirate_conscripts
					attrition = 0.5
					disband_on_peace = yes
				}
				spawn_fleet = {
					province = closest
					owner = ROOT
					troops = {
						galleys = { 20 20 }
					}
					earmark = pirate_conscripts_ships
					disband_on_peace = yes
				}
			}
		}
		add_character_modifier = {
			name = pirate_conscription_medium
			years = 5
		}
		prestige = -400
		wealth = -60
		ai_chance = {
			factor = 30
		}
	}
    option = {
        name = EVTOPTC_piraterep_1
		trigger = { prestige = 1000 wealth = 150 higher_tier_than = DUKE }
		capital_scope = {
			show_scope_change = no
			ROOT = {
				show_scope_change = no
				spawn_unit = { 
					province = PREV
					owner = ROOT
					troops = { 
						light_infantry = { 2500 2500 }
						archers = { 1500 1500 }
					}
					earmark = pirate_conscripts
					attrition = 0.5
					disband_on_peace = yes
				}
				spawn_fleet = {
					province = closest
					owner = ROOT
					troops = {
						galleys = { 50 50 }
					}
					earmark = pirate_conscripts_ships
					disband_on_peace = yes
				}
			}
		}
		add_character_modifier = {
			name = pirate_conscription_large
			years = 5
		}
		prestige = -1000
		wealth = -150
		ai_chance = {
			factor = 30
		}
	}
	option = { #Changed my mind
		name = EVTOPTDHF25001
		ai_chance = {
			factor = 0
		}
	}
}