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

	# INVADER
	create_character = {
		template = sukaphaa_ahom_character_template
		dynasty = generate
		location = scope:invader_spawn_location
		save_scope_as = invader
	}
	scope:invader = {
		add_gold = 750
		add_prestige = 75
		add_piety = 50
		
		dynasty = {
			set_dynasty_name = hi_dynn_ahom

			add_dynasty_prestige_level = 1
			add_dynasty_prestige = 750

			$INVADER_DYNN$_add_dynasty_perks_effect = yes
		}
		house = {
			set_house_name = hi_dynn_ahom_house_su
		}
	}
}

ahom_add_dynasty_perks_effect = {}

ahom_maintenance_effect = {
	apply_invader_modifiers_effect = {
		INVADER_DYNN = $INVADER_DYNN$
	}
	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_ahom_family_effect = {
	# three spouses
	create_character = {
		template = hi_random_spouse_character_template
		dynasty = none
		employer = $INVADER_CHAR$
		save_scope_as = spouse_1
		after_creation = {
			disease_immunity_long_effect = yes
			marry = $INVADER_CHAR$
		}
	}
	create_character = {
		template = hi_random_spouse_character_template
		dynasty = none
		employer = $INVADER_CHAR$
		save_scope_as = spouse_2
		after_creation = {
			disease_immunity_long_effect = yes
			marry = $INVADER_CHAR$
		}
	}
	create_character = {
		template = hi_random_spouse_character_template
		dynasty = none
		employer = $INVADER_CHAR$
		save_scope_as = spouse_3
		after_creation = {
			disease_immunity_long_effect = yes
			marry = $INVADER_CHAR$
		}
	}
	# two sons
	create_character = {
		template = hi_random_child_character_template
		gender = male
		dynasty = inherit
		mother = scope:spouse_1
		father = $INVADER_CHAR$
		employer = $INVADER_CHAR$
		after_creation = {
			disease_immunity_long_effect = yes
			marry = $INVADER_CHAR$
		}
	}
	create_character = {
		template = hi_random_child_character_template
		gender = male
		dynasty = inherit
		mother = scope:spouse_2
		father = $INVADER_CHAR$
		employer = $INVADER_CHAR$
		after_creation = {
			disease_immunity_long_effect = yes
			marry = $INVADER_CHAR$
		}
	}
	# one daughter
	create_character = {
		template = hi_random_child_character_template
		gender = female
		dynasty = inherit
		mother = scope:spouse_3
		father = $INVADER_CHAR$
		employer = $INVADER_CHAR$
		after_creation = {
			disease_immunity_long_effect = yes
			marry = $INVADER_CHAR$
		}
	}
	
	$INVADER_CHAR$ = { trigger_event = game_rule.1001 }

	# government
	apply_invader_government_type_effect = { INVADER_CHAR = $INVADER_CHAR$ }

	# culture
	$INVADER_CHAR$.capital_county = { set_county_culture = $INVADER_CHAR$.culture }

	# faith
	$INVADER_CHAR$.capital_county = { set_county_faith = $INVADER_CHAR$.faith }

	# modifier
	$INVADER_CHAR$.capital_county = {
		add_county_modifier = {
			modifier = historicinvasions_county_tier_two_modifier
			years = 50
		}
	}
}

# Make sure invader has troops
spawn_ahom_troops_effect = {
	if = {
		limit = { has_character_flag = is_first_invader_flag }
		spawn_ahom_army_effect = yes
		spawn_ahom_army_effect = yes
	}
	spawn_ahom_army_effect = yes
	if = {
		limit = { game_start_date < 1000.1.1 }
		spawn_ahom_army_effect = yes
	}
}
spawn_ahom_army_effect = {
	spawn_army = {
		name = ahom_event_troops
		location = primary_title.title_capital_county.title_province
		war = scope:war
		war_keep_on_attacker_victory = no
		uses_supply = no
		inheritable = no
		
		levies = 250
		men_at_arms = {
			type = armored_footmen
			stacks = 3
		}
		men_at_arms = {
			type = pikemen_unit
			stacks = 7
		}
		men_at_arms = {
			type = bowmen
			stacks = 5
		}
		# siege
		men_at_arms = {
			type = trebuchet
			stacks = 5
		}
	}
}