Skip to content

Commit

Permalink
Add Gremlin Waves!
Browse files Browse the repository at this point in the history
  • Loading branch information
danhunsaker committed Mar 30, 2024
1 parent a34d1e9 commit 976e6ed
Show file tree
Hide file tree
Showing 11 changed files with 933 additions and 62 deletions.
6 changes: 6 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
- [Setup](./urgency/setup.md)
- [Usage](./urgency/usage.md)

# Gremlin Waves

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

# Book-Keeping

- [Contributors](./contributors.md)
6 changes: 3 additions & 3 deletions docs/evac/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Evac:setup({
lossThresholds = { 25, 25 },
maxExtractable = {
{
Generic = 12,
['Downed Pilot'] = 12,
Infantry = 12,
M249 = 12,
RPG = 12,
Expand All @@ -25,7 +25,7 @@ Evac:setup({
JTAC = 3,
},
{
Generic = 12,
['Downed Pilot'] = 12,
Infantry = 12,
M249 = 12,
RPG = 12,
Expand Down Expand Up @@ -65,7 +65,7 @@ Evac:setup({
- Default: `{ ["C-130"] = 90, ["CH-47D"] = 44, ["CH-43E"] = 55, ["Mi-8MT"] = 24, ["Mi-24P"] = 5, ["Mi-24V"] = 5, ["Mi-26"] = 70, ["SH60B"] = 5, ["UH-1H"] = 8, ["UH-60L"] = 11 }`

- `idStart`: The lowest ID number that Gremlin Evac will use to create units and groups
- Default: `500`
- Default: `50000`

- `loadUnloadPerIndividual`: The amount of time it takes to load/unload a single evacuee onto/from an aircraft, in seconds
- Default: `30`
Expand Down
4 changes: 2 additions & 2 deletions docs/evac/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Evac:setup({
lossThresholds = { 0, 25 },
maxExtractable = {
{
Generic = 12,
['Downed Pilot'] = 12,
Infantry = 12,
M249 = 12,
RPG = 12,
Expand All @@ -46,7 +46,7 @@ Evac:setup({
JTAC = 3,
},
{
Generic = 12,
['Downed Pilot'] = 12,
Infantry = 12,
M249 = 12,
RPG = 12,
Expand Down
4 changes: 2 additions & 2 deletions docs/urgency/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ Urgency:setup({
- countdown
- `reuse` whether to put this countdown back in the queue to be triggered again
- `startTrigger` table
- `type` one of `time`, `event`, or `menu`
- `type` one of `time`, `flag`, `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`
- `type` one of `time`, `flag`, `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)
Expand Down
4 changes: 4 additions & 0 deletions docs/waves.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable MD041 -->
## About

Gremlin Waves is a reinforcements script for your missions. Running low on RedFor, but not ready for the fun to end? Call in reinforcements with Gremlin Waves!
77 changes: 77 additions & 0 deletions docs/waves/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!-- markdownlint-disable MD041 -->
### Setup

#### Configuration

```lua,editable
Waves:setup({
adminPilotNames = {
'Steve Jobs',
'Linus Torvalds',
'Bill Gates',
},
waves = {
['Wave 2'] = {
trigger = {
type = 'time',
value = 12600, -- 3.5 hours
},
groups = {
['F-14B'] = {
category = Group.Category.AIRPLANE,
country = country.USA,
zone = 'Reinforcement Staging',
scatter = 15,
orders = {},
units = {
['F-14B'] = 3,
},
},
['Ground A'] = {
category = Group.Category.GROUND,
country = country.USA,
zone = 'Reinforcement Staging',
scatter = 5,
orders = {},
units = {
['Infantry'] = 4,
}
},
['Ground B'] = {
category = Group.Category.GROUND,
country = country.USA,
zone = 'Reinforcement Staging',
scatter = 5,
orders = {},
units = {
['RPG'] = 1,
['Infantry'] = 3,
['JTAC'] = 1,
}
},
},
},
},
})
```

- `adminPilotNames` table
- list of pilots who should see the menu
- `waves` table
- collection of reinforcement waves for this mission
- wave
- `trigger` table
- `type` one of `time`, `flag`, `event`, or `menu`
- `value` a time, event id / filter, or menu item text
- `groups` table
- list of groups to spawn
- group
- `category` a member of `Groups.Category` indicating the group's category
- `country` a `country` id
- `zone` where to spawn the group
- `scatter` how far apart, in meters, to scatter units at spawn
- `orders` table
- a list of [DCS AI tasks](https://www.digitalcombatsimulator.com/en/support/faq/1267/#3307680) for the group to perform
- `units` table
- key: the unit type to spawn
- value: how many to spawn in the group
4 changes: 4 additions & 0 deletions docs/waves/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable MD041 -->
### Usage

Gremlin Waves is really simple to use. Configure it once (see [the Setup page](./setup.md)), and it handles the rest!
115 changes: 60 additions & 55 deletions src/urgency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,6 @@ Urgency = {
},
}

Urgency._internal.handlers = {
eventTriggers = {
event = -1,
fn = function(_event)
Gremlin.log.trace(Urgency.Id, string.format('Checking Event Against Countdowns : %s', Gremlin.events.idToName[_event.id]))

for _name, _countdown in pairs(Urgency._state.countdowns.pending) do
if _countdown.startTrigger.type == 'event'
and (
_countdown.startTrigger.value.id == _event.id
or _countdown.startTrigger.value.id == -1
)
and _countdown.startTrigger.value.filter(_event)
then
Urgency._internal.startCountdown(_name)

Gremlin.log.trace(Urgency.Id, string.format('Started Countdown : %s', _name))
end
end

for _name, _countdown in pairs(Urgency._state.countdowns.active) do
if _countdown.endTrigger.type == 'event'
and (
_countdown.endTrigger.value.id == _event.id
or _countdown.endTrigger.value.id == -1
)
and _countdown.endTrigger.value.filter(_event)
then
Urgency._internal.endCountdown(_name)

Gremlin.log.trace(Urgency.Id, string.format('Ended Countdown : %s', _name))
end
end
end
},
}

Urgency._internal.menu = {
{
text = 'Reset Active Countdowns',
func = Urgency._internal.resetCountdowns,
args = {},
when = true,
},
{
text = 'Reset All Countdowns',
func = Urgency._internal.restoreCountdowns,
args = {},
when = true,
},
}

Urgency._internal.getAdminUnits = function()
Gremlin.log.trace(Urgency.Id, string.format('Scanning For Admin Units'))

Expand All @@ -81,9 +29,11 @@ Urgency._internal.getAdminUnits = function()
if _unit ~= nil and _unit.isExist ~= nil and _unit:isExist() and _unit.getPlayerName ~= nil then
local _pilot = _unit:getPlayerName()
if _pilot ~= nil and _pilot ~= '' then
Gremlin.log.trace(Urgency.Id, string.format('Found A Pilot : %s (in %s)', _pilot, _name))

for _, _adminName in pairs(Urgency.config.adminPilotNames) do
if _adminName == _pilot then
table.insert(_units, _name)
_units[_name] = _unit
break
end
end
Expand Down Expand Up @@ -152,9 +102,11 @@ Urgency._internal.doCountdowns = function()
local _now = timer.getTime()

for _name, _countdown in pairs(Urgency._state.countdowns.pending) do
if _countdown.startTrigger.type == 'time' and _countdown.startTrigger.value <= _now then
if (_countdown.startTrigger.type == 'time' and _countdown.startTrigger.value <= _now)
or (_countdown.startTrigger.type == 'flag' and trigger.misc.getUserFlag(_countdown.startTrigger.value) ~= 0)
then
Urgency._internal.startCountdown(_name)
Gremlin.log.trace(Urgency.Id, string.format('Timer-Based Countdown Started : %s', _name))
Gremlin.log.trace(Urgency.Id, string.format('%s-Based Countdown Started : %s', _countdown.startTrigger.type, _name))
end
end

Expand Down Expand Up @@ -250,6 +202,59 @@ Urgency._internal.restoreCountdowns = function()
Gremlin.log.trace(Urgency.Id, string.format('Restored Configured Countdowns'))
end

Urgency._internal.menu = {
{
text = 'Reset Active Countdowns',
func = Urgency._internal.resetCountdowns,
args = {},
when = true,
},
{
text = 'Reset All Countdowns',
func = Urgency._internal.restoreCountdowns,
args = {},
when = true,
},
}

Urgency._internal.handlers = {
eventTriggers = {
event = -1,
fn = function(_event)
Gremlin.log.trace(Urgency.Id,
string.format('Checking Event Against Countdowns : %s', Gremlin.events.idToName[_event.id]))

for _name, _countdown in pairs(Urgency._state.countdowns.pending) do
if _countdown.startTrigger.type == 'event'
and (
_countdown.startTrigger.value.id == _event.id
or _countdown.startTrigger.value.id == -1
)
and _countdown.startTrigger.value.filter(_event)
then
Urgency._internal.startCountdown(_name)

Gremlin.log.trace(Urgency.Id, string.format('Started Countdown : %s', _name))
end
end

for _name, _countdown in pairs(Urgency._state.countdowns.active) do
if _countdown.endTrigger.type == 'event'
and (
_countdown.endTrigger.value.id == _event.id
or _countdown.endTrigger.value.id == -1
)
and _countdown.endTrigger.value.filter(_event)
then
Urgency._internal.endCountdown(_name)

Gremlin.log.trace(Urgency.Id, string.format('Ended Countdown : %s', _name))
end
end
end
},
}

function Urgency:setup(config)
if config == nil then
config = {}
Expand Down
Loading

0 comments on commit 976e6ed

Please sign in to comment.