namespace = inspiration_system

##################################################
# Inspiration Generation
# Checks how many inspirations currently exist and, if there are not enough, generates new ones for pool characters.
# by Sean Hughes
# 0005
##################################################

inspiration_system.0005 = {
	scope = none
	hidden = yes

	trigger = {
		has_ep1_dlc_trigger = yes

		num_world_inspired_characters_value < ideal_total_world_inspirations
	}

	immediate = {
		set_local_variable = {
			name = try_create_inspiration_attempts
			value = max_new_inspirations_per_year_value
		}

		while = {
			limit = {			
				AND = {
					local_var:try_create_inspiration_attempts > 0
					num_world_inspired_characters_value < ideal_total_world_inspirations
				}
			}
			grant_new_inspiration_in_world_effect = yes
			change_local_variable = {
				name = try_create_inspiration_attempts
				subtract = 1
			}
		}	
	}
}

##################################################
# Inspired Character Maintenance
# Every Royal Court owner occasionally checks guests who have an Inspiration and, if unsponsored, moves them to a different Royal Court
# by Sean Hughes
# 1001-1101
##################################################

inspiration_system.1001 = {
	hidden = yes

	trigger = {
		has_ep1_dlc_trigger = yes
	}

	immediate = {
		every_pool_guest = {
			limit = {
				exists = inspiration
				NOR = {
					# Inspiration is not currently being sponsored
					inspiration = { exists = inspiration_sponsor }
					# Has not arrived at our court in the last X months (defined in 00_ep1_script_values.txt )
					has_character_flag = inspired_character_recent_arrival
				}
			}
			if = {
				limit = {
					inspiration = {
						days_since_creation > 3650
					}
				}
				# Destroy our inspiration, since nobody seems interested in sponsoring it.
				trigger_event = inspiration_system.1101
			}
			else = {
				# Look for a new royal court to visit.
				inspired_character_seek_out_new_royal_court_effect = yes
			}
		}
	}
}

# After going an extended period of time without being recruited or having their Inspiration sponsored, characters lose it in order to make room for new Inspired characters in the pool.
inspiration_system.1101  = {
	hidden = yes

	immediate = {
		destroy_inspiration = inspiration
		move_to_pool = yes

		# Unrealized potential is tough on people.
		random_list = {
			25 = {
				add_trait = depressed_1
				add_stress = minor_stress_gain
			}
			25 = {
				trigger = { can_be_drunkard = yes }
				add_trait = drunkard
				add_stress = minor_stress_gain
			}
			25 = {
				trigger = { can_be_hashishiyah = yes }
				add_trait = hashishiyah
				add_stress = minor_stress_gain
			}
			50 = {
				add_stress = major_stress_gain
			}
		}
	}
}

inspiration_system.1200 = { # Courtier becomes Adventurer
	type = character_event
	hidden = yes
	
	trigger = {
		scope:antiquarian_from_task ?= {
			has_court_position = antiquarian_court_position
		}
		scope:adventure_target ?= {
			is_physically_able_adult = yes
			NOR = {
				exists = inspiration
				has_court_position = antiquarian_court_position
			}
			adventure_inspiration_average_skill_value >= medium_inspiration_skill
			host ?= root
		}
	}

	immediate = {
		send_interface_toast = {
			type = msg_court_inspiration
			left_icon = scope:adventure_target
			right_icon = scope:antiquarian_from_task
			title = antiquarian_inspired_adventurer_message
			desc = antiquarian_inspired_adventurer_effect
			scope:adventure_target = {
				create_inspiration = adventure_inspiration
			}
		}
	}
}
