﻿# invader appears, before story
spawn_al-qays_invader_effect = {
	random_county_in_region = {
		region = special_$INVADER_DYNN$_conquest_region_start
		title_province = { save_scope_as = invader_spawn_location }
	}

	# grandmother
	create_character = {
		template = muhammad_al-qays_mother_character_template
		location = scope:invader_spawn_location
		save_scope_as = invader_grandmother
	}

	# mother
	create_character = {
		template = hi_random_spouse_character_template
		dynasty = none
		gender = female
		location = scope:invader_spawn_location
		faith = faith:ashari
		culture = culture:bedouin
		save_scope_as = invader_mother
	}

	# father
	create_character = {
		template = muhammad_al-qays_character_template
		location = scope:invader_spawn_location
		mother = scope:invader_grandmother
		save_scope_as = invader_father
		after_creation = {
			marry = scope:invader_mother
			death = natural
			scope:invader_mother = { death = natural }
		}
	}

	# INVADER
	create_character = {
		template = ali_al-qays_character_template
		dynasty = inherit
		mother = scope:invader_mother
		father = scope:invader_father
		location = scope:invader_spawn_location
		save_scope_as = invader
	}
	scope:invader = {
		add_gold = 350
		add_prestige = 75
		add_piety = 50

		dynasty = {
			set_dynasty_name = hi_dynn_al-qays
			add_dynasty_prestige_level = 0
			add_dynasty_prestige = 150

			$INVADER_DYNN$_add_dynasty_perks_effect = yes
		}
		house = {
			set_house_name = hi_dynn_al-qays
		}
	}

	every_player = {
		trigger_event = $INVADER_DYNN$_invasion.1001 # Notification: Start of invasion
	}
}

al-qays_add_dynasty_perks_effect = {}

al-qays_maintenance_effect = {
	apply_invader_modifiers_effect = {
		INVADER_DYNN = $INVADER_DYNN$
	}
	give_invader_land_effect = {
		INVADER_DYNN = $INVADER_DYNN$
		INVADER_CHAR = $INVADER_CHAR$
		STARTING_TIER = $STARTING_TIER$
	}
	spawn_$INVADER_DYNN$_family_effect = {
		INVADER_CHAR = $INVADER_CHAR$
	}
	spawn_invader_servants_effect = {
		INVADER_CHAR = $INVADER_CHAR$
	}
	form_the_invader_title_effect = {
		INVADER_DYNN = $INVADER_DYNN$
		INVADER_CHAR = $INVADER_CHAR$
		INVADER_TITLE = $INVADER_TITLE$
		LANDLESS_YES_NO = $LANDLESS_YES_NO$
	}
}

### populating the life of the invader character
spawn_al-qays_family_effect = {
	# random spouse
	create_character = {
		template = hi_random_spouse_character_template
		dynasty = none
		employer = $INVADER_CHAR$
		faith = $INVADER_CHAR$.faith
		culture = $INVADER_CHAR$.culture
		after_creation = {
			marry = $INVADER_CHAR$
		}
	}
}

# Make sure invader has troops
spawn_zanj_troops_effect = {
	spawn_zanj_army_effect = yes
}
spawn_zanj_army_effect = {
	spawn_army = {
		name = zanj_event_troops
		location = capital_province
		uses_supply = no
		inheritable = no
		
		levies = 50
		men_at_arms = {
			type = light_footmen
			stacks = 2
		}
		# siege
		men_at_arms = {
			type = onager
			stacks = 2
		}
	}
}