Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 23 additions & 1 deletion src/gremlin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,29 @@ Gremlin = {
end

return tbl1
end
end,
--- Calculate the positions of units to spawn.
--
-- @function Gremlin.utlis.spawnPoints
-- @tparam number _angle
-- @tparam number|table _scatterRadius
-- @tparam number _counter
-- @treturn number, number
spawnPoints = function(_angle, _scatterRadius)
local _xOffset, _yOffset

if type(_scatterRadius) == 'table' then
local _realRadius = math.min(math.max(_scatterRadius.max * math.sqrt(math.random()), _scatterRadius.min), _scatterRadius.max)
_xOffset = math.cos(_angle) * _realRadius
_yOffset = math.sin(_angle) * _realRadius
else
local _realRadius = _scatterRadius * math.sqrt(math.random())
_xOffset = math.cos(_angle) * _realRadius
_yOffset = math.sin(_angle) * _realRadius
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)

table.insert(_units, {
type = _unitType,
Expand Down
20 changes: 20 additions & 0 deletions test/gremlin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -653,5 +653,25 @@ TestGremlinUtils = {
-- SIDE EFFECTS
-- N/A?
end,
testSpawnPointsNumber = function()
-- INIT
-- N/A?

-- TEST
lu.assertAlmostEquals({ Gremlin.utils.spawnPoints(0.25 * math.pi, 50) }, { 0, 0 }, 50)

-- SIDE EFFECTS
-- N/A?
end,
testSpawnPointsTable = function()
-- INIT
-- N/A?

-- TEST
lu.assertAlmostEquals({ Gremlin.utils.spawnPoints(0.25 * math.pi, { min = 25, max = 50 }) }, { 0, 0 }, 50)

-- SIDE EFFECTS
-- N/A?
end,
tearDown = tearDown,
}