Director
The game's hand on the group: a tension meter, a difficulty number and a shared blackboard.
Exposed as VluxyAI.Director. Make one per game (or per group), raise it from the events
that matter, and give every enemy director:Sense() so its brain can read the numbers.
local director = VluxyAI.Director.new({ Fall = 0.05 })
director.Blackboard.Alarm = nil
-- each enemy
:AddSense(director:Sense())
-- the game
agent.Events:Connect(function(name)
if name == "Kill" then director:Raise(1) end
end)
-- a state
agent:SetSpeed(director:Scale(BASE_SPEED, 0.5)) -- up to 50% faster at full tension
if agent.Blackboard.DirectorTension > 0.8 then return "Retreat" end
Tension is a number in [0, 1] that drains by Fall per second; difficulty is any number
the game chooses. Blackboard is a plain table shared by reference: an enemy writes the
alarm position into it, the others read it on their next tick.
Functions
new
Types
interface DirectorOptions {Fall: number?--
Tension drained per second. Default 0.05, so a full meter empties in twenty seconds of quiet.
Difficulty: number?--
The starting difficulty. Default 1.
Tension: number?--
The starting tension. Default 0.
}Errors
| Type | Description |
|---|---|
| "unknown option" |
GetTension
Director.GetTension(self: Director) → number--
Tension in [0, 1], drained for the time since it was last touched.
Raise
Director.Raise(amount: number--
Added to the tension, clamped to 1. A kill might be 1, a near miss 0.3.
) → ()Lower
SetTension
GetDifficulty
SetDifficulty
Director.SetDifficulty(value: number--
Any number the game means by difficulty; 1 is normal.
) → ()Scale
Director.Scale(base: number,--
A speed, a memory, a cooldown.
byTension: number?,--
How much a full meter changes it: 0.5 means base * 1.5 at full tension. Default 0.
byDifficulty: number?--
How much each unit of difficulty above 1 changes it. Default 0.
) → number--
base * (1 + byTension * tension) * (1 + byDifficulty * (difficulty - 1)).
The one line a state needs to scale itself by the game's mood.
Sense
Director.Sense(options: DirectorSenseOptions?) → Sense--
Writes DirectorTension, DirectorDifficulty and DirectorShared (the shared blackboard, by reference) each tick.
Types
interface DirectorSenseOptions {Prefix: string?--
Prepended to the three keys. Default "Director", so the keys are DirectorTension, DirectorDifficulty and DirectorShared.
}One instance serves every agent in the group. Add it before the senses and states that read from it.
Destroy
Clears the shared blackboard. The senses handed out keep working; they read live values.