###################################
# Scripted Values - Grand Archive #
###################################

##################
# Gravity Snares #
##################

gravity_snare_cooldown_for_fleet = {
	complex_trigger_modifier = {
		trigger = timed_flag_days_left
		parameters = {
			flag = gravity_snare_is_in_cooldown
		}
		mode = add
	}
}

# This = fleet
calc_gravity_snare_cooldown = {
	base = 1
	add = $SCOPE|this$.modifier:gravity_snare_cooldown_mult 			# FLEET scope
	add = $SCOPE|this$.controller.modifier:gravity_snare_cooldown_mult	# COUNTRY scope
	mult = @gravity_snare_cooldown_per_fleet_in_days
	min = 1
}

num_gravity_snare_upgrade_unlocked = {
	base = 0
	modifier = {
		add = 1
		from = {
			has_technology = tech_gravity_snare_capacity_1
		}
	}
	modifier = {
		add = 1
		from = {
			has_technology = tech_gravity_snare_capacity_2
		}
	}
	modifier = {
		add = 1
		from = {
			has_technology = tech_gravity_snare_capacity_3
		}
	}
	modifier = {
		add = 1
		from = {
			has_technology = tech_containment_vessel
		}
	}
}

vivarium_repopulation_cost = {
	base = 0
	modifier = {
		add = 500
		has_dna = { ship_category = space_amoeba }
	}
	modifier = {
		add = 500
		has_dna = { ship_category = tiyanki }
	}
	modifier = {
		add = 500
		has_dna = { ship_category = crystalline_entity }
	}
	modifier = {
		add = 500
		has_dna = { ship_category = voidworm }
	}
	modifier = {
		add = 500
		has_dna = { ship_category = cutholoid }
	}
}
grand_archive_size_effect_pop_factor = {
	base = 0
	add = owner.trigger:empire_size
	subtract = 100
	min = 0
}

grand_archive_size_effect = {
	base = 0.005
	multiply = value:grand_archive_size_effect_pop_factor
	add = 1
}

cutholoid_spawn_scale = {
	base = 0
	modifier = {
		add = $VARIABLE$
		is_variable_set = $VARIABLE$
	}
	mult = trigger:cutholoids_scaling
}

#############
# Voidworms #
#############

voidworms_tiny_spawn_chance = {
	add = 90000
}

voidworms_small_spawn_chance = {
	add = 90000
	modifier = {
		factor = 0
		galaxy_size = tiny
	}
}

voidworms_medium_spawn_chance = {
	add = 90000
	modifier = {
		factor = 0
		OR = {
			galaxy_size = tiny
			galaxy_size = small
		}
	}
}

voidworms_large_spawn_chance = {
	base = 0
	modifier = {
		add = 90000
		OR = {
			galaxy_size = large
			galaxy_size = huge
		}
	}
}

voidworms_huge_spawn_chance = {
	base = 0
	modifier = {
		add = 90000
		galaxy_size = huge
	}
}

voidworm_ships_owned = {
	base = 0
	complex_trigger_modifier = {
		trigger = count_owned_ship
		parameters = {
			limit = {
				is_ship_category = voidworm
				is_ship_size = voidworms_titan
			}
		}
		mode = add
	}
	mult = 3
	complex_trigger_modifier = {
		trigger = count_owned_ship
		parameters = {
			limit = {
				is_ship_category = voidworm
				NOT = { is_ship_size = voidworms_titan }
			}
		}
		mode = add
	}
}

voidworm_ships_owned_in_system = {
	base = 0
	complex_trigger_modifier = {
		trigger = count_ship_in_system
		parameters = {
			limit = {
				owner = {
					is_voidworms_country_type = yes
				}
				is_ship_category = voidworm
				is_ship_size = voidworms_titan
			}
		}
		mode = add
	}
	mult = 3
	complex_trigger_modifier = {
		trigger = count_ship_in_system
		parameters = {
			limit = {
				owner = {
					is_voidworms_country_type = yes
				}
				is_ship_category = voidworm
				NOT = { is_ship_size = voidworms_titan }
			}
		}
		mode = add
	}
}

voidworm_nest_owned = {
	base = 0
	complex_trigger_modifier = {
		trigger = count_owned_fleet
		parameters = {
			limit = {
				num_ships > 0
				is_ship_size = voidworm_nest
			}
		}
		mode = add
	}
}

voidworm_nest_spawn_minimum = {
	base = 0
	modifier = {
		add = 16
		galaxy_size = tiny
	}
	modifier = {
		add = 32
		galaxy_size = small
	}
	modifier = {
		add = 48
		galaxy_size = medium
	}
	modifier = {
		add = 64
		galaxy_size = large
	}
	modifier = {
		add = 80
		galaxy_size = huge
	}
	mult = trigger:voidworms_scaling
	round = yes
}

voidworm_maximum_population = {
	base = 0
	add = value:voidworm_nest_owned
	mult = 20
	mult = trigger:voidworms_scaling
	round = yes
}

voidworm_crisis_maximum_population = {
	base = 0
	add = value:voidworm_maximum_population
	mult = 2
}

voidworm_systems_in_galaxy = {
	base = 0
	complex_trigger_modifier = {
		trigger = count_system
		parameters = {
			limit = {
				has_star_flag = voidworms_system
			}
		}
		mode = add
	}
}

voidworm_system_month_respawn_time = {
	base = 9
	divide = value:voidworm_systems_in_galaxy
	mult = 12
	ceiling = yes
}

calc_voidworms_surplus = {
	base = 0
	add = value:voidworm_ships_owned
	subtract = value:voidworm_nest_spawn_minimum
	min = 0
	mult = 0.5
}
voidworm_crisis_start_chance = {
	base = 0
	add = trigger:voidworms_scaling
	add = value:calc_voidworms_surplus
	max = 50
}

voidworms_growth_mult = {
	base = 1
	modifier = {
		factor = @voidworms_crisis_growth_mult
		exists = owner
		owner = { is_country_type = voidworms_crisis }
	}
}

voidworm_plague_progress_per_voidworm_killed = {
	base = 2
	mult = value:ship_size_naval_cap_scaling|SHIP_SCOPE|$SCOPE$|
}

#############
# Specimens #
#############

available_rewards_per_category = {
	base = 0
	modifier = {
		add = 1
		check_variable = {
			which = $VALUE$
			value >= @curator_reward_first_threshold
		}
	}
	modifier = {
		add = 1
		check_variable = {
			which = $VALUE$
			value >= @curator_reward_second_threshold
		}
	}
	modifier = {
		add = 1
		check_variable = {
			which = $VALUE$
			value >= @collection_max_exhibit_count
		}
	}
}

curators_contact_relative_to_specimen = {
	base = 0
	add = value:available_rewards_per_category|VALUE|xeno_specimen_count|
	add = value:available_rewards_per_category|VALUE|wonder_specimen_count|
	add = value:available_rewards_per_category|VALUE|historical_specimen_count|
}

xeno_geology_specimens_modifiers_mult = {
	base = 1
	add = modifier:xeno_geology_specimens_produces_mult
	add = modifier:specimens_produces_mult
}

aesthetic_wonder_specimens_modifiers_mult = {
	base = 1
	add = modifier:aesthetic_wonder_specimens_produces_mult
	add = modifier:specimens_produces_mult
}

historical_item_specimens_modifiers_mult = {
	base = 1
	add = modifier:historical_item_specimens_produces_mult
	add = modifier:specimens_produces_mult
}

#############
# Artifacts #
#############
scaled_artifact_cost = {
	base = 0
	modifier = {
		add = $INCREASE_VARIABLE$
		is_variable_set = $INCREASE_VARIABLE$
	}
	mult = $INCREASE$
	add = $BASE$
}

##########
# Relics #
##########

modularium_multiplier = {
	base = 1
	modifier = {
		add = 1
		is_variable_set = $VARIABLE$
	}
	modifier = {
		pow = $VARIABLE$
		is_variable_set = $VARIABLE$
	}
	round = yes
}

celestial_resonator_value = {
	base = 0
	complex_trigger_modifier = {
		trigger = count_exhibit
		parameters = {
			limit = {
				is_exhibit_active = yes
			}
		}
		mode = add
	}
}

everchanging_stone_modifier_mult = {
	base = 0
	complex_trigger_modifier = {
		trigger = count_exhibit
		parameters = {
			limit = {
				is_exhibit_active = yes
				is_specimen_category = xeno_geology
			}
		}
		mode = add
	}
}

############################
# Primal Calling modifiers #
############################
titanic_life_spawn_chance = {
	base = 25
	modifier = {
		factor = 2
		has_planet_modifier = "pm_high_gravity"
	}
	modifier = {
		add = 5
		has_planet_modifier = "pm_lush"
	}
	modifier = {
		factor = 0.2
		has_planet_modifier = "pm_low_gravity"
	}
	modifier = {
		factor = 0
		has_planet_modifier = "pm_titanic_life"
	}
	modifier = {
		factor = 0
		has_planet_modifier = "pm_dangerous_wildlife"
	}
	modifier = {
		factor = 0
		num_modifiers > 1
	}
}

distance_to_system_star = {
	base = 0
	complex_trigger_modifier = {
		trigger = distance
		mode = add
		parameters = {
			source = prev.star
			same_solar_system = yes
		}
	}
}

####################
# Treasure Hunters #
####################
systems_available_for_sabotage = {
	base = 1
	complex_trigger_modifier = {
		trigger = is_difficulty
		trigger_scope = this
		mode = add
	}
	modifier = {
		mult = 100
		is_difficulty = 6 # Grand Admiral has unlimited number of vulnerable colonies
	}
}

# Modifiers
# Whole successes granted before the remainder is rolled, so a chance above 100% is not wasted.
deposit_increase_on_survey_guaranteed_count = {
	base = 0
	add = modifier:deposit_increase_on_survey_chance_mult
	floor = yes
}

deposit_increase_on_survey_chance = {
	base = 0
	add = modifier:deposit_increase_on_survey_chance_mult
	mult = 100
	round = yes
	modulo = 100
}

enemy_ship_size_energy_add = {
	base = 0
	add = value:ship_size_naval_cap_scaling|SHIP_SCOPE|$SHIP_SCOPE$|
	mult = modifier:enemy_ship_destroyed_energy_add
	min = modifier:enemy_ship_destroyed_energy_add
}

calc_treasure_trove_progress = {
	base = 0
	add = $VALUE$
	mult = value:scripted_modifier_mult|MODIFIER|treasure_trove_reward_mult|
	min = 0
}

get_ruler_level = {
	base = 0
	complex_trigger_modifier = {
		trigger = has_base_skill
		trigger_scope = ruler
		mode = add
	}
	min = 1
}

get_vivarium_capacity_mult = {
	base = 1
	add = modifier:country_vivarium_max_capacity_mult
	min = 0
}

get_vivarium_capacity = {
	base = 0
	add = modifier:country_vivarium_max_capacity_add
	mult = value:get_vivarium_capacity_mult
	floor = yes
	max = @max_vivarium_capacity
}

get_vivarium_slots_left = {
	base = 0
	add = value:get_vivarium_capacity
	subtract = trigger:num_vivarium_slots
	min = 0
}

##########
# Civics #
##########

curator_purchase_cost = {
	base = 1
	modifier = {
		add = @galactic_curators_curator_enclave_purchase_cost
		is_galactic_curators_empire = yes
	}
	mult = $COST$
}

#############
# Mutations #
#############

component_dynamic_cost = {
	base = 0
	add = $COST$
	complex_trigger_modifier = {
		trigger = ship_size_cost_resource_percent
		potential = {
			is_scope_valid = yes
			OR = {
				is_scope_type = ship
				is_scope_type = ship_growth_stage
			}
		}
		parameters = {
			resource = $RESOURCE$
		}
		mode = mult
	}
	mult = $SCALING$
	floor = yes
}
