Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /c
- Settings = function()
- --[[
- Advised to use max group size of 200 or less to avoid them getting in each others way too much. when biter group is attacked each biter targets a random targets, so they get in each others way breaking pack formation. could reduce collision box size to 40% like Rampent?
- More than 10 groups total in a wave will tend to loose formation and partially form in to a mass single group column, rather than hold the shape. built in AI UPS protection.
- If you want more than 10 groups at a time call the command after each wave has cleared the spawn area or from a different side?
- ]]
- _biterCount = 1000
- _biterMaxGroupSize = 100
- _biterSpawnTilesLeftOfPlayer = 150
- _biterWaveGroupsWide = 5
- end
- TriggerBiterGroup = function()
- _surface = game.player.surface
- _maxBiterGroups = math.ceil(_biterCount / _biterMaxGroupSize)
- if _maxBiterGroups < _biterWaveGroupsWide then
- _biterWaveGroupsWide = _maxBiterGroups
- end
- _biterGroupSize = math.ceil(_biterCount / _maxBiterGroups)
- _biterGroupTileWidth = 20
- _biterGroupTileLength = math.sqrt(_biterMaxGroupSize)
- local groupStartPos = FindBiterGatherPoint()
- if _maxBiterGroups > 20 then
- game.print("too many attack groups will lag the game - stopped")
- return
- end
- local waveWidthCount = 0
- local waveDepthCount = 0
- for i=1, _maxBiterGroups do
- local thisGroupStartPos = {
- x = groupStartPos.x - (waveDepthCount * 6 * _biterGroupTileLength),
- y = groupStartPos.y + (waveWidthCount * _biterGroupTileWidth)
- }
- local biterGroup = CreateBiterGroup(thisGroupStartPos)
- SpawnBitersInGroup(biterGroup, thisGroupStartPos, _biterGroupSize)
- BiterGroupAttackMoveArea(biterGroup, FindMoveTarget(waveWidthCount, waveDepthCount), FindAttackAreaTarget(i))
- biterGroup.start_moving()
- waveWidthCount = waveWidthCount + 1
- if waveWidthCount == _biterWaveGroupsWide then
- waveWidthCount = 0
- waveDepthCount = waveDepthCount + 1
- end
- end
- end
- FindBiterGatherPoint = function()
- return {
- x = game.player.position.x - _biterSpawnTilesLeftOfPlayer,
- y = game.player.position.y - ((_biterWaveGroupsWide * _biterGroupTileWidth) / 2)
- }
- end
- FindMoveTarget = function(groupWidthCount, groupDepthCount)
- return {
- x = game.player.position.x + (groupDepthCount),
- y = game.player.position.y - ((_biterWaveGroupsWide * _biterGroupTileWidth) / 2) + (groupWidthCount * _biterGroupTileWidth)
- }
- end
- FindAttackAreaTarget = function(groupCount)
- return {
- x = game.player.position.x + groupCount,
- y = game.player.position.y
- }
- end
- CreateBiterGroup = function(groupPosition)
- return _surface.create_unit_group{position = groupPosition, force = game.forces["enemy"]}
- end
- SpawnBitersInGroup = function(unitGroup, spawnCenterPos, groupSize)
- local biterType = "small-biter"
- for i=1, groupSize do
- local spawnPos = _surface.find_non_colliding_position(biterType, spawnCenterPos, 0, 1)
- local biter = _surface.create_entity{
- name = biterType,
- position = spawnPos,
- force = game.forces["enemy"]
- }
- if not biter then
- game.print("creation of biter" .. i .. "failed")
- else
- unitGroup.add_member(biter)
- end
- end
- end
- GetBiterGroupAttackAreaCommand = function(targetPos)
- return {
- type = defines.command.attack_area,
- destination = targetPos,
- radius = 10,
- distraction = defines.distraction.by_anything
- }
- end
- GetBiterGroupMoveCommand = function(moveToPos)
- return {
- type = defines.command.go_to_location,
- destination = moveToPos,
- distraction = defines.distraction.by_anything
- }
- end
- BiterGroupAttackMoveArea = function(unitGroup, moveToPos, targetPos)
- local command = {
- type = defines.command.compound,
- structure_type = defines.compound_command.return_last,
- commands = {
- GetBiterGroupMoveCommand(moveToPos),
- GetBiterGroupAttackAreaCommand(targetPos)
- }
- }
- unitGroup.set_command(command)
- end
- Settings()
- TriggerBiterGroup()
Add Comment
Please, Sign In to add comment