Unlocks
Reference for `gameplay_missions_unlocks`, which evaluates start/visible conditions, manages unlock dependencies between missions, and computes mission ordering depth.
Reference for gameplay_missions_unlocks, which evaluates start/visible conditions, manages unlock dependencies between missions, and computes mission ordering depth.
Module Exports (M)
Unlock Evaluation
| Function | Signature | Description |
|---|---|---|
updateUnlockStatus | (missions?) | Evaluates startable/visible conditions for all missions |
conditionMet | (condition) → {met, condition, nested, label, hidden} | Recursively evaluates a condition tree |
Unlock Comparison
| Function | Signature | Description |
|---|---|---|
getSimpleUnlockedStatus | () → table | Snapshots current unlock state of all missions |
getUnlockDiff | (before, after) → table | Compares two snapshots to find changes |
getMissionBasedUnlockDiff | (mission, diff) → table | Gets unlock status of missions directly downstream |
Dependency Analysis
| Function | Signature | Description |
|---|---|---|
setUnlockForwardBackward | (missions) | Builds forward/backward dependency links and depth ordering |
getMissionsForCondition | (cond, list) | Recursively extracts referenced mission IDs from conditions |
getBranchLevelForCondition | (cond, list) | Recursively extracts branch level requirements |
Sorting
| Function | Signature | Description |
|---|---|---|
depthIdSort | (a, b) → bool | Sort comparator: depth first, then ID |
depthIdSortUsingIds | (aId, bId) → bool | Same but takes IDs instead of mission objects |
M.conditionMet | (condition) | - |
M.depthIdSort | (a,b) | - |
M.depthIdSortUsingIds | (aId,bId) | - |
M.getBranchLevelForCondition | (cond, list) | - |
M.getMissionBasedUnlockDiff | (mission, diff) | - |
M.getMissionsForCondition | (cond, list) | - |
M.getSimpleUnlockedStatus | () | - |
M.getUnlockDiff | (before, after) | - |
M.onExtensionLoaded | () | - |
M.setUnlockForwardBackward | (missions) | - |
M.startConditionMet | value | - |
M.updateUnlockStatus | (missions) | - |
Condition System
Conditions are loaded from /gameplay/missions/unlocks/conditions/*.lua files on extension load. Each condition type provides:
{
info = "Description",
editorFunction = "editorFnName", -- optional
getLabel = function(condition) → string/table end,
conditionMet = function(condition) → bool, nested? end,
hidden = bool -- optional, hides condition from UI
}Unlock Evaluation Flow
local function updateUnlockStatus(missions)
-- Pass 1: Evaluate startCondition for each mission
for _, mission in ipairs(missions) do
mission.unlocks.startable = conditionMet(mission.startCondition).met
-- Career+freeroam missions: always startable outside career
end
-- Pass 2: Evaluate visibleCondition
for _, mission in ipairs(missions) do
if visibleCondition.type == 'automatic' then
-- Visible if any backward-linked mission is startable
-- (or if no backward links exist)
else
mission.unlocks.visible = conditionMet(mission.visibleCondition).met
end
end
endDependency & Depth Ordering
setUnlockForwardBackward(missions):
- Extract dependencies - Parse
startConditionfor mission references (missionPassed/missionCompleted) - Double-link - Build forward links (which missions does this unlock?)
- Extract branch levels - Parse conditions for
branchLevelandleaguerequirements - Propagate branch data - Forward-propagate max branch level and branch tags
- Compute depth - BFS from root missions (no backward links), depth = distance from root
- Shift by branch level - Offset depth by accumulated branch level thresholds
This produces mission.unlocks.depth used for UI ordering.
Unlock Diff Structure
{
list = { {missionId, change = {{key, old, new}, ...}}, ... },
byId = { [missionId] = change },
missionsList = { {name, id}, ... } -- newly startable missions
}Key Behaviors
- Career missions with
showInCareerandshowInFreeroamboth true are always startable/visible outside career 'automatic'visible condition: visible if any predecessor is startable (or no predecessors)- Condition types loaded dynamically from condition files (see
careerConditions,genericConditions,missionConditions,vehicleConditions) - Depth ordering ensures missions with higher branch level requirements appear later in UI
See Also
- missions/locationsDetector - Nearby Mission Location Detection - Related reference
- missions/missionManager - Mission Lifecycle Manager - Related reference
- missions/missionScreen - Mission UI Screen & Starting Options - Related reference
- Gameplay Systems Guide - Guide
Mission Start Trigger
Reference for `gameplay_missions_startTrigger`, which parses mission start triggers into location data and clusters nearby missions for the POI/marker system.
Base Mission
Reference for the base mission type, the simplest mission class providing minimal lifecycle hooks. Returned by `gameplay_missions_missions.baseMission()`.