# Dynamic Research Slots - Configuration
#
# This file contains all *default* configuration for the Dynamic Research Slots system:
# - Base RP weights per factory type
# - Base thresholds for research slots
# - Default Easy Slot settings
# - Game rule overrides that affect these values
#
# Submods can override this file (or the individual scripted effects) to change
# the behaviour of the system without touching the core logic.
#
# Recommended pattern for submods:
# - Create a new mod.
# - Copy this file, adjust values as needed.
# - Make sure your mod is loaded *after* "Dynamic Research Slots Reborn".
#

dr_apply_research_config = {
	# Step 1: apply all default values (base weights, arrays, Easy Slots).
	dr_reset_research_config_defaults = yes

	# Step 2: apply vanilla overrides that depend on game rules.
	dr_apply_research_factory_weight_rules = yes
	dr_apply_easy_slot_rule_overrides = yes
	dr_apply_easy_slot_cost_rules = yes

	# Step 3: allow submods to tweak/extend the config.
	# Note: Submods can also override this entire file for more extensive changes.
	dr_apply_research_config_submods = yes
}

# Rebuild effective RP thresholds for research slots based on
# base_research_for_slot[], easy_research_slots and easy_research_slot_coefficient.
dr_rebuild_research_thresholds = {
	for_each_loop = {
		array = base_research_for_slot

		# Start from the base threshold for this slot.
		set_variable = { research_for_slot^i = base_research_for_slot^i }

		# For Easy Slots, apply the reduced cost factor.
		if = {
			limit = {
				check_variable = {
					var = easy_research_slots
					value = i
					compare = greater_than_or_equals
				}
			}
			set_variable = { temp = base_research_for_slot^i }
			multiply_variable = { temp = easy_research_slot_coefficient }
			set_variable = { research_for_slot^i = var:temp }
		}
	}
}

dr_reset_research_config_defaults = {
	# Base RP weights per factory type
	set_variable = { research_power_per_civ = 3 }
	set_variable = { research_power_per_mil = 2 }
	set_variable = { research_power_per_nav = 2 }

	# RP per experimental facility (per building)
	set_variable = { rp_per_nuclear_facility = 30 }
	set_variable = { rp_per_naval_facility = 15 }
	set_variable = { rp_per_air_facility = 15 }
	set_variable = { rp_per_land_facility = 15 }
	# Reduction factor applied per additional facility of each type (0 = flat bonus)
	set_variable = { experimental_facility_rp_reduction_nuclear = 0.15 }
	set_variable = { experimental_facility_rp_reduction_naval = 0.15 }
	set_variable = { experimental_facility_rp_reduction_air = 0.15 }
	set_variable = { experimental_facility_rp_reduction_land = 0.15 }
	
	# RP per nuclear reactor (per building)
	set_variable = { rp_per_nuclear_reactor = 20 }
	set_variable = { rp_per_heavy_water_reactor = 35 }
	set_variable = { rp_per_commercial_reactor = 12 }
	# Reduction factor applied per additional reactor of each type (0 = flat bonus)
	set_variable = { experimental_facility_rp_reduction_nuclear_reactor = 0.15 }
	set_variable = { experimental_facility_rp_reduction_heavy_water_reactor = 0.15 }
	set_variable = { experimental_facility_rp_reduction_commercial_reactor = 0.15 }

	# Government support thresholds for war/peace RP modifiers
	set_variable = { government_support_threshold_very_low = 0.25 }
	set_variable = { government_support_threshold_low = 0.4 }
	set_variable = { government_support_threshold_medium = 0.55 }
	set_variable = { government_support_threshold_high = 0.7 }
	set_variable = { government_support_threshold_very_high = 0.85 }

	# War phase thresholds (days)
	set_variable = { war_phase_offensive_threshold_1 = 30 }
	set_variable = { war_phase_offensive_threshold_2 = 60 }
	set_variable = { war_phase_offensive_threshold_3 = 90 }
	set_variable = { war_phase_defensive_threshold_1 = 60 }
	set_variable = { war_phase_defensive_threshold_2 = 120 }
	set_variable = { war_phase_defensive_threshold_3 = 180 }

	# Base thresholds for research slots
	# Index 0 is a dummy entry for easier indexing.
	add_to_array = { base_research_for_slot = 0 }	# 0 (dummy)
	add_to_array = { base_research_for_slot = 0 }	# 1
	add_to_array = { base_research_for_slot = 0 }	# 2
	add_to_array = { base_research_for_slot = 50 }	# 3
	add_to_array = { base_research_for_slot = 200 }	# 4
	add_to_array = { base_research_for_slot = 400 }	# 5
	add_to_array = { base_research_for_slot = 700 }	# 6
	add_to_array = { base_research_for_slot = 1000 }	# 7
	add_to_array = { base_research_for_slot = 1500 }	# 8
	add_to_array = { base_research_for_slot = 2000 }	# 9
	add_to_array = { base_research_for_slot = 3000 }	# 10

	add_to_array = { research_for_slot = 0 }	# 0 (dummy)
	add_to_array = { research_for_slot = 0 }	# 1
	add_to_array = { research_for_slot = 0 }	# 2
	add_to_array = { research_for_slot = 50 }	# 3
	add_to_array = { research_for_slot = 200 }	# 4
	add_to_array = { research_for_slot = 400 }	# 5
	add_to_array = { research_for_slot = 700 }	# 6
	add_to_array = { research_for_slot = 1000 }	# 7
	add_to_array = { research_for_slot = 1500 }	# 8
	add_to_array = { research_for_slot = 2000 }	# 9
	add_to_array = { research_for_slot = 3000 }	# 10

	# Default Easy Slot setup
	set_variable = { easy_research_slots = 2 }
	set_variable = { easy_research_slot_coefficient = 0.6 }

	# AI update frequency (days between staggered updates for AI countries)
	set_variable = { dr_ai_update_frequency = 14 }
}

dr_apply_research_factory_weight_rules = {
	# Optional override via factory weights game rule
	if = {
		limit = { has_game_rule = { rule = DR_FACTORY_WEIGHTS_RULE option = DR_FACTORY_WEIGHTS_INDUSTRY } }
		set_variable = { research_power_per_civ = 4 }
		set_variable = { research_power_per_mil = 2 }
		set_variable = { research_power_per_nav = 1 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_FACTORY_WEIGHTS_RULE option = DR_FACTORY_WEIGHTS_MILITARY } }
		set_variable = { research_power_per_civ = 2 }
		set_variable = { research_power_per_mil = 4 }
		set_variable = { research_power_per_nav = 2 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_FACTORY_WEIGHTS_RULE option = DR_FACTORY_WEIGHTS_NAVAL } }
		set_variable = { research_power_per_civ = 2 }
		set_variable = { research_power_per_mil = 2 }
		set_variable = { research_power_per_nav = 4 }
	}
}

dr_apply_easy_slot_rule_overrides = {
	# Additional Easy Slots via game rule
	if = {
		limit = { has_game_rule = { rule = DR_EASY_SLOTS_RULE option = DR_EASY_SLOTS_PLUS_1 } }
		add_to_variable = { easy_research_slots = 1 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_SLOTS_RULE option = DR_EASY_SLOTS_PLUS_2 } }
		add_to_variable = { easy_research_slots = 2 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_SLOTS_RULE option = DR_EASY_SLOTS_PLUS_3 } }
		add_to_variable = { easy_research_slots = 3 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_SLOTS_RULE option = DR_EASY_SLOTS_PLUS_4 } }
		add_to_variable = { easy_research_slots = 4 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_SLOTS_RULE option = DR_EASY_SLOTS_PLUS_5 } }
		add_to_variable = { easy_research_slots = 5 }
	}

	# Optional: minor nations get an additional Easy Slot (controlled via game rule)
	if = {
		limit = {
			is_major = no
			has_game_rule = {
				rule = DR_MINOR_EASY_SLOTS_RULE
				option = DR_MINOR_EASY_SLOTS_ON
			}
		}
		add_to_variable = { easy_research_slots = 1 }
	}
}

dr_apply_easy_slot_cost_rules = {
	# Cost factor of Easy Slots via game rule (default 60%)
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_10 } }
		set_variable = { easy_research_slot_coefficient = 0.1 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_20 } }
		set_variable = { easy_research_slot_coefficient = 0.2 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_30 } }
		set_variable = { easy_research_slot_coefficient = 0.3 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_40 } }
		set_variable = { easy_research_slot_coefficient = 0.4 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_50 } }
		set_variable = { easy_research_slot_coefficient = 0.5 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_60 } }
		set_variable = { easy_research_slot_coefficient = 0.6 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_70 } }
		set_variable = { easy_research_slot_coefficient = 0.7 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_80 } }
		set_variable = { easy_research_slot_coefficient = 0.8 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_90 } }
		set_variable = { easy_research_slot_coefficient = 0.9 }
	}
	if = {
		limit = { has_game_rule = { rule = DR_EASY_COST_RULE option = DR_EASY_COST_100 } }
		set_variable = { easy_research_slot_coefficient = 1.0 }
	}
}

dr_apply_research_config_submods = {
	# Intentionally left blank. Submods can override this scripted effect to
	# adjust or extend the configuration after the base logic has executed.
	#
	# For extensive changes, submods can also override this entire file:
	# - Copy 00_dr_dynamic_research_config.txt to your submod
	# - Adjust values as needed
	# - Make sure your submod loads after "Dynamic Research Slots Reborn"
}
