Skip to content

Commit

Permalink
Refactor to start supporting improved spawn distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
danhunsaker committed May 6, 2024
1 parent e58c8b0 commit 2befcbe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/evac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,7 @@ Evac._internal.utils = {
local _angle = math.atan2(_point.z, _point.x)

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

_unitsOut[_i] = {
type = typeTranslation[_side][_unit.type],
Expand Down
19 changes: 18 additions & 1 deletion src/gremlin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,24 @@ Gremlin = {
end

return tbl1
end
end,
spawnPoints = function(_angle, _scatterRadius, _counter)
local _xOffset, _yOffset

if _counter < 1 then
_counter = 0
end

if type(_scatterRadius) == 'table' then
_xOffset = math.cos(_angle) * math.random(_scatterRadius.min, _scatterRadius.max) * _counter
_yOffset = math.sin(_angle) * math.random(_scatterRadius.min, _scatterRadius.max) * _counter
else
_xOffset = math.cos(_angle) * math.random(_scatterRadius) * _counter
_yOffset = math.sin(_angle) * math.random(_scatterRadius) * _counter
end

return _xOffset, _yOffset
end,
},

-- Internal State
Expand Down
3 changes: 1 addition & 2 deletions src/waves.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ Waves._internal.spawnWave = function(_name, _wave)
local _units = {}
for _unitType, _unitCount in pairs(_groupData.units) do
for i = 1, _unitCount do
local _xOffset = math.cos(_angle) * math.random(_groupData.scatter.min, _groupData.scatter.max) * #_units
local _yOffset = math.sin(_angle) * math.random(_groupData.scatter.min, _groupData.scatter.max) * #_units
local _xOffset, _yOffset = Gremlin.utils.spawnPoints(_angle, _groupData.scatter, #_units)

table.insert(_units, {
type = _unitType,
Expand Down

0 comments on commit 2befcbe

Please sign in to comment.