# Pathfinders' Ledger
# All effects: scope = country.

# Fires milestone event $EVENT$ once, when the ledger reaches $N$ systems.
apb_ledger_check_milestone = {
	if = {
		limit = {
			NOT = { has_country_flag = apb_ledger_milestone_$N$ }
			check_variable = {
				which = apb_ledger_systems
				value >= $N$
			}
		}
		set_country_flag = apb_ledger_milestone_$N$
		country_event = { id = $EVENT$ }
	}
}

# Reward: a renowned scientist of level $SKILL$.
apb_ledger_reward_scientist = {
	custom_tooltip = apb_ledger_reward_scientist_$SKILL$_tt
	hidden_effect = {
		create_leader = {
			class = scientist
			species = owner_main_species
			name = random
			skill = $SKILL$
			tier = leader_tier_renowned
		}
	}
}

# Reward: a random research option with $PROGRESS$ progress. If none can be
# offered, $RVALUE$ months of that research income instead (at least $RMIN$).
apb_ledger_reward_tech = {
	custom_tooltip = apb_ledger_reward_tech_tt
	hidden_effect = {
		random_list = {
			10 = {
				add_random_research_option = {
					add_progress = $PROGRESS$
					area = physics
					ignore_prereqs = no
					fail_effects = {
						add_monthly_resource_mult = {
							resource = physics_research
							value = $RVALUE$
							min = $RMIN$
							max = 1000000
						}
					}
				}
			}
			10 = {
				add_random_research_option = {
					add_progress = $PROGRESS$
					area = society
					ignore_prereqs = no
					fail_effects = {
						add_monthly_resource_mult = {
							resource = society_research
							value = $RVALUE$
							min = $RMIN$
							max = 1000000
						}
					}
				}
			}
			10 = {
				add_random_research_option = {
					add_progress = $PROGRESS$
					area = engineering
					ignore_prereqs = no
					fail_effects = {
						add_monthly_resource_mult = {
							resource = engineering_research
							value = $RVALUE$
							min = $RMIN$
							max = 1000000
						}
					}
				}
			}
		}
	}
}

# Reward: one more permanent stack of Wayfinder's Charts.
# The stack count lives in apb_ledger_wayfinding_stacks; the modifier is rebuilt from it.
apb_ledger_reward_wayfinding = {
	custom_tooltip = apb_ledger_reward_wayfinding_tt
	hidden_effect = {
		if = {
			limit = { NOT = { is_variable_set = apb_ledger_wayfinding_stacks } }
			set_variable = { which = apb_ledger_wayfinding_stacks value = 0 }
		}
		change_variable = { which = apb_ledger_wayfinding_stacks value = 1 }
		if = {
			limit = { has_modifier = apb_ledger_wayfinding }
			remove_modifier = apb_ledger_wayfinding
		}
		add_modifier = {
			modifier = apb_ledger_wayfinding
			multiplier = apb_ledger_wayfinding_stacks
		}
	}
}

# Reward: $MONTHS$ months of unity income (at least $MIN$).
apb_ledger_reward_unity = {
	add_monthly_resource_mult = {
		resource = unity
		value = $MONTHS$
		min = $MIN$
		max = 1000000
	}
}
