﻿namespace = rajasa_invasion

### Spawn invader with the associated story...
rajasa_invasion.0001 = {
	scope = none
	hidden = yes

	trigger = {
		exists = title:e_rajasa # update compatibility - new titles in old saves return false
		any_county_in_region = {
			region = special_rajasa_conquest_region_start
			count > 0
			holder = { is_ai = yes }
		}
	}

	on_trigger_fail = {
		debug_log = "rajasa story has failed to trigger; trying again next year"
		debug_log_date = yes
	}

	immediate = {
		debug_log = "rajasa story owner has appeared"
		debug_log_date = yes
		
		spawn_rajasa_invader_effect = {
			INVADER_DYNN = rajasa
		}
		scope:invader = {
			create_story = story_rajasa_invasion
		}
	}
}

# Event for handling army spawning
rajasa_invasion.0100 = {
	hidden = yes
	immediate = {
		spawn_rajasa_troops_effect = yes
	}
}

# Event for declaring the very first war; values like current_ / max_military_strength aren't immediately filled with a value and return 0 instead
rajasa_invasion.0200 = {
	hidden = yes
	trigger = { is_ai = yes } # don't force a player into a war
	immediate = {
		war_target_evaluation_and_declaration_effect = {
			INVADER_DYNN = rajasa
			INVADER_CHAR = scope:story.story_owner
			INVADER_REGION = total
			INVADER_TARGET_TITLE_TIER = kingdom
			INVADER_RANGE = neighboring
			INVADER_LIEGE_RESTRICTIONS = ""
		}
	}
}

##################
# Notification Events
# 1000-1999
##################

### The invader has appeared! Would you like to play as them?
rajasa_invasion.1001 = { # only players see this
	type = character_event
	title = rajasa_invasion.1001.t
	desc = rajasa_invasion.1001.desc
	
	theme = hi_theme_steppe

	left_portrait = {
		character = scope:invader
		animation = personality_bold
	}

	trigger = { NOT = { has_game_rule = historicinvasion_notification_disabled } }
	
	option = { name = rajasa_invasion.1001.a }

	option = { # play as the newly spawned invader
		name = rajasa_invasion.1001.b
		trigger = { has_game_rule = historicinvasion_notification_enabled }
		add_internal_flag = dangerous
		scope:invader = {
			set_variable = {
				name = historicinvasions_previous_ruler_var
				value = root
				months = 1
			}
		}
		set_player_character = scope:invader
	}
}