Muppet9010

Biter Attack Test Script

Oct 9th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. /c
  2. Settings = function()
  3. --[[
  4. 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?
  5. 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.
  6. 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?
  7. ]]
  8. _biterCount = 1000
  9. _biterMaxGroupSize = 100
  10. _biterSpawnTilesLeftOfPlayer = 150
  11. _biterWaveGroupsWide = 5
  12. end
  13.  
  14. TriggerBiterGroup = function()
  15. _surface = game.player.surface
  16. _maxBiterGroups = math.ceil(_biterCount / _biterMaxGroupSize)
  17. if _maxBiterGroups < _biterWaveGroupsWide then
  18. _biterWaveGroupsWide = _maxBiterGroups
  19. end
  20. _biterGroupSize = math.ceil(_biterCount / _maxBiterGroups)
  21. _biterGroupTileWidth = 20
  22. _biterGroupTileLength = math.sqrt(_biterMaxGroupSize)
  23. local groupStartPos = FindBiterGatherPoint()
  24. if _maxBiterGroups > 20 then
  25. game.print("too many attack groups will lag the game - stopped")
  26. return
  27. end
  28.  
  29. local waveWidthCount = 0
  30. local waveDepthCount = 0
  31. for i=1, _maxBiterGroups do
  32. local thisGroupStartPos = {
  33. x = groupStartPos.x - (waveDepthCount * 6 * _biterGroupTileLength),
  34. y = groupStartPos.y + (waveWidthCount * _biterGroupTileWidth)
  35. }
  36.  
  37. local biterGroup = CreateBiterGroup(thisGroupStartPos)
  38. SpawnBitersInGroup(biterGroup, thisGroupStartPos, _biterGroupSize)
  39. BiterGroupAttackMoveArea(biterGroup, FindMoveTarget(waveWidthCount, waveDepthCount), FindAttackAreaTarget(i))
  40. biterGroup.start_moving()
  41.  
  42. waveWidthCount = waveWidthCount + 1
  43. if waveWidthCount == _biterWaveGroupsWide then
  44. waveWidthCount = 0
  45. waveDepthCount = waveDepthCount + 1
  46. end
  47. end
  48. end
  49.  
  50. FindBiterGatherPoint = function()
  51. return {
  52. x = game.player.position.x - _biterSpawnTilesLeftOfPlayer,
  53. y = game.player.position.y - ((_biterWaveGroupsWide * _biterGroupTileWidth) / 2)
  54. }
  55. end
  56.  
  57. FindMoveTarget = function(groupWidthCount, groupDepthCount)
  58. return {
  59. x = game.player.position.x + (groupDepthCount),
  60. y = game.player.position.y - ((_biterWaveGroupsWide * _biterGroupTileWidth) / 2) + (groupWidthCount * _biterGroupTileWidth)
  61. }
  62. end
  63.  
  64. FindAttackAreaTarget = function(groupCount)
  65. return {
  66. x = game.player.position.x + groupCount,
  67. y = game.player.position.y
  68. }
  69. end
  70.  
  71. CreateBiterGroup = function(groupPosition)
  72. return _surface.create_unit_group{position = groupPosition, force = game.forces["enemy"]}
  73. end
  74.  
  75. SpawnBitersInGroup = function(unitGroup, spawnCenterPos, groupSize)
  76. local biterType = "small-biter"
  77. for i=1, groupSize do
  78. local spawnPos = _surface.find_non_colliding_position(biterType, spawnCenterPos, 0, 1)
  79. local biter = _surface.create_entity{
  80. name = biterType,
  81. position = spawnPos,
  82. force = game.forces["enemy"]
  83. }
  84. if not biter then
  85. game.print("creation of biter" .. i .. "failed")
  86. else
  87. unitGroup.add_member(biter)
  88. end
  89. end
  90. end
  91.  
  92. GetBiterGroupAttackAreaCommand = function(targetPos)
  93. return {
  94. type = defines.command.attack_area,
  95. destination = targetPos,
  96. radius = 10,
  97. distraction = defines.distraction.by_anything
  98. }
  99. end
  100.  
  101. GetBiterGroupMoveCommand = function(moveToPos)
  102. return {
  103. type = defines.command.go_to_location,
  104. destination = moveToPos,
  105. distraction = defines.distraction.by_anything
  106. }
  107. end
  108.  
  109. BiterGroupAttackMoveArea = function(unitGroup, moveToPos, targetPos)
  110. local command = {
  111. type = defines.command.compound,
  112. structure_type = defines.compound_command.return_last,
  113. commands = {
  114. GetBiterGroupMoveCommand(moveToPos),
  115. GetBiterGroupAttackAreaCommand(targetPos)
  116. }
  117. }
  118. unitGroup.set_command(command)
  119. end
  120.  
  121. Settings()
  122. TriggerBiterGroup()
Add Comment
Please, Sign In to add comment