Skip to content

Commit

Permalink
Add Gremlin Urgency
Browse files Browse the repository at this point in the history
  • Loading branch information
danhunsaker committed Mar 28, 2024
1 parent 0542dfd commit a34d1e9
Show file tree
Hide file tree
Showing 10 changed files with 715 additions and 17 deletions.
6 changes: 6 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
- [Units](./evac/functions/units.md)
- [Zones](./evac/functions/zones.md)

# Gremlin Urgency

- [About](./urgency.md)
- [Setup](./urgency/setup.md)
- [Usage](./urgency/usage.md)

# Book-Keeping

- [Contributors](./contributors.md)
4 changes: 4 additions & 0 deletions docs/urgency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable MD041 -->
## About

Gremlin Urgency is a great way to add ... well, urgency to your missions. Timed events made easy - whether that be mission duration or anything else.
98 changes: 98 additions & 0 deletions docs/urgency/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!-- markdownlint-disable MD041 -->
### Setup

#### Configuration

```lua,editable
Urgency:setup({
adminPilotNames = {
'Steve Jobs',
'Linus Torvalds',
'Bill Gates',
},
countdowns = {
missionDuration = {
reuse = false,
startTrigger = {
type = 'time',
value = 0, -- mission start (or, well, as close as we can manage)
},
startFlag = 'MissionRunning',
endTrigger = {
type = 'time',
value = 25200, -- 7 hours
},
endFlag = 'MissionTimeout',
messages = {
[0] = { to = 'blue', text = 'Mission is a go! We only get seven hours to complete our objectives!', duration = 15 },
[-1800] = { to = 'blue', text = '30 minutes left in mission! Are we gonna make it?', duration = 15 },
[-900] = { to = 'blue', text = '15 minutes left in mission! Are we gonna make it?', duration = 15 },
[-600] = { to = 'blue', text = '10 minutes left in mission! Are we gonna make it?', duration = 15 },
[-300] = { to = 'blue', text = '5 minutes left in mission! Are we gonna make it?', duration = 15 },
[-60] = { to = 'blue', text = '1 minute left in mission! Are we gonna make it?', duration = 15 },
[-30] = { to = 'blue', text = '30 seconds left in mission...', duration = 5 },
[-15] = { to = 'blue', text = '15 seconds left in mission...', duration = 5 },
[-10] = { to = 'blue', text = '10 seconds left in mission...', duration = 1 },
[-9] = { to = 'blue', text = '9 seconds left in mission...', duration = 1 },
[-8] = { to = 'blue', text = '8 seconds left in mission...', duration = 1 },
[-7] = { to = 'blue', text = '7 seconds left in mission...', duration = 1 },
[-6] = { to = 'blue', text = '6 seconds left in mission...', duration = 1 },
[-5] = { to = 'blue', text = '5 seconds left in mission...', duration = 1 },
[-4] = { to = 'blue', text = '4 seconds left in mission...', duration = 1 },
[-3] = { to = 'blue', text = '3 seconds left in mission...', duration = 1 },
[-2] = { to = 'blue', text = '2 seconds left in mission...', duration = 1 },
[-1] = { to = 'blue', text = '1 seconds left in mission...', duration = 1 },
[25200] = { to = 'all', text = "Time's up! Ending mission...", duration = 15 },
},
},
easterEgg1 = {
reuse = true,
startTrigger = {
type = 'event',
value = {
id = world.event.S_EVENT_TRIGGER_ZONE,
filter = function(_event)
local _unit = _event.initiator
local _zone = _event.target
if _zone == 'egg1' then
return true
end
return false
end,
},
},
startFlag = 'Egg1Found',
endTrigger = {
type = 'time',
value = 3600, -- 1 hour
},
endFlag = 'Egg1Expired',
messages = {
[0] = { to = 'all', text = 'An Easter Egg Was Discovered!', duration = 15 },
[3600] = { to = 'all', text = 'An Easter Egg Has Vanished!', duration = 15 },
},
},
},
})
```

- `adminPilotNames` table
- A list of pilots who should get the admin menu

- `countdowns` table
- A list of countdowns to register at mission start
- countdown
- `reuse` whether to put this countdown back in the queue to be triggered again
- `startTrigger` table
- `type` one of `time`, `event`, or `menu`
- `value` the time, event id and handler, or menu text to trigger on
- `startFlag` the flag to set true when the countdown starts
- `endTrigger` table
- `type` one of `time`, `event`, or `menu`
- `value` the time, event id and handler, or menu text to trigger on
- `endFlag` the flag to set true when the countdown ends
- `messages` a list of messages to display, keyed by the countdown's seconds since start (or seconds until end, if negative)
- `text` the message to display
- `duration` how long the message should be visible (in seconds)
4 changes: 4 additions & 0 deletions docs/urgency/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable MD041 -->
### Usage

Gremlin Urgency is really simple to use. Configure it once (see [the Setup page](./setup.md)), and it handles the rest!
16 changes: 12 additions & 4 deletions src/evac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ Evac.groups = {
local _spawnZone = trigger.misc.getZone(_zone)

if _spawnZone == nil then
trigger.action.outText("GREMLIN EVAC ERROR: Can't find zone called " .. _zone, 10)
Gremlin.log.error(Evac.Id, "Can't find zone called " .. _zone)
return
end

Expand Down Expand Up @@ -1198,6 +1198,13 @@ Evac._internal.zones = {

-- Menu
Evac._internal.menu = {
updateF10 = function()
Gremlin.log.trace(Evac.Id, string.format('Updating Menu'))

timer.scheduleFunction(Evac._internal.menu.updateF10, nil, timer.getTime() + 5)

Gremlin.menu.updateF10(Evac.Id, Evac._internal.menu.commands, Evac._internal.utils.extractionUnitsToMenuUnits())
end,
commands = {{
text = 'Scan For Evacuation Beacons',
func = Evac.units.findEvacuees,
Expand Down Expand Up @@ -1376,10 +1383,11 @@ Evac._internal.utils = {
local _unitsOut = {}
---@diagnostic disable-next-line: deprecated
local _angle = math.atan2(_point.z, _point.x)
local _xOffset = math.cos(_angle) * math.random(_scatterRadius)
local _yOffset = math.sin(_angle) * math.random(_scatterRadius)

for _i, _unit in pairs(_units) do
local _xOffset = math.cos(_angle) * math.random(_scatterRadius)
local _yOffset = math.sin(_angle) * math.random(_scatterRadius)

_unitsOut[_i] = {
type = _unit.type,
unitId = _unit.unitId,
Expand Down Expand Up @@ -1874,7 +1882,7 @@ function Evac:setup(config)
timer.scheduleFunction(Evac._internal.doSpawns, nil, timer.getTime() + 5)
timer.scheduleFunction(Evac._internal.beacons.killDead, nil, timer.getTime() + 5)
timer.scheduleFunction(Evac._internal.smoke.refresh, nil, timer.getTime() + 5)
timer.scheduleFunction(Gremlin.menu.updateF10, { Evac.Id, Evac._internal.menu.commands, Evac._internal.utils.extractionUnitsToMenuUnits }, timer.getTime() + 5)
timer.scheduleFunction(Evac._internal.menu.updateF10, nil, timer.getTime() + 5)
end, nil, timer.getTime() + 1)

for _name, _def in pairs(Evac._internal.handlers) do
Expand Down
9 changes: 2 additions & 7 deletions src/gremlin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,12 @@ Gremlin = {
end
},
menu = {
updateF10 = function(args)
local toolId, commands, getForUnits = table.unpack(args)
local forUnits = getForUnits()

updateF10 = function(toolId, commands, forUnits)
Gremlin.log.trace(Gremlin.Id, string.format('Updating F10 Menu For %i Units', Gremlin.utils.countTableEntries(forUnits)))

timer.scheduleFunction(Gremlin.menu.updateF10, args, timer.getTime() + 10)

for _unitName, _extractor in pairs(forUnits) do
local _unit = _extractor or Unit.getByName(_unitName)
if _unit ~= nil and _unit:isExist() then
if _unit ~= nil and _unit.isExist ~= nil and _unit:isExist() then
local _groupId = _unit:getGroup():getID()
local _groupName = _unit:getGroup():getName()

Expand Down
Loading

0 comments on commit a34d1e9

Please sign in to comment.