Guest User

Untitled

a guest
May 22nd, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.98 KB | None | 0 0
  1. --control.lua
  2.  
  3. VERSION = "1.2.0"
  4. PREFIX = "more-biters-"
  5.  
  6. deathExplosions = {}
  7. deathExplosions[PREFIX .. "small-explosive-biter"] = {radius = 1, damage = 50}
  8. deathExplosions[PREFIX .. "medium-explosive-biter"] = {radius = 2, damage = 100}
  9. deathExplosions[PREFIX .. "big-explosive-biter"] = {radius = 3, damage = 200}
  10. deathExplosions[PREFIX .. "behemoth-explosive-biter"] = {radius = 4, damage = 300}
  11. deathExplosions[PREFIX .. "small-atomic-biter"] = {radius = 2, damage = 100}
  12. deathExplosions[PREFIX .. "medium-atomic-biter"] = {radius = 3, damage = 200}
  13. deathExplosions[PREFIX .. "big-atomic-biter"] = {radius = 4, damage = 400}
  14. deathExplosions[PREFIX .. "behemoth-atomic-biter"] = {radius = 5, damage = 600}
  15.  
  16. local sizes = {"small", "medium", "big", "behemoth"}
  17.  
  18. function isExplosiveBiter(entity)
  19. return deathExplosions[entity.name] ~= nil
  20. end
  21.  
  22. function isTitanBiter(entity)
  23. return entity.name == PREFIX .. "behemoth-titan-biter"
  24. end
  25.  
  26. function isLeechSpitter(entity)
  27. return string.match(entity.name, "leech%-spitter")
  28. end
  29.  
  30. function isTunnelerBiter(entity)
  31. return string.match(entity.name, "tunneler%-biter") or string.match(entity.name, "atomic%-biter")
  32. end
  33.  
  34. function isTree(entity)
  35. return string.match(entity.name, "tree")
  36. end
  37.  
  38. function isSeismic(entity)
  39. return entity.name == PREFIX .. "seismic"
  40. end
  41.  
  42. function noSeismic(pos)
  43. for ent, _ in pairs(global[PREFIX .. "seismic"]) do
  44. if (ent.valid) then
  45. local distance = (ent.position.x - pos.x) ^ 2 + (ent.position.y - pos.y) ^ 2
  46. if (distance <= 900) then -- 30^2 since seismic range is 30
  47. for _, player in pairs(game.players) do
  48. player.print("blocked tunnel")
  49. end
  50. return false
  51. end
  52. end
  53. end
  54. return true
  55. end
  56.  
  57. function spawnDeathExplosion(entity)
  58. local radius = deathExplosions[entity.name].radius
  59. local damage = deathExplosions[entity.name].damage
  60. local ents =
  61. entity.surface.find_entities(
  62. {
  63. {entity.position.x - radius, entity.position.y - radius},
  64. {entity.position.x + radius, entity.position.y + radius}
  65. }
  66. )
  67. for _, ent in pairs(ents) do
  68. if (ent and ent.valid and ent.destructible and ent.health ~= nil and ent.health > 0) then
  69. ent.damage(damage, entity.force, "explosion")
  70. end
  71. end
  72. end
  73.  
  74. function maybeTunnel(entity)
  75. if ((game.tick + shiftTick) % 100 == 0 and noSeismic(entity.position)) then -- chance of tunneling on damage
  76. shiftTick = shiftTick + 1
  77. local tunnelPos = getTunnelPos(entity)
  78. local surface = entity.surface
  79. local goodPos = surface.find_non_colliding_position(entity.name, tunnelPos, 15, 1)
  80. if (goodPos ~= nil and noSeismic(goodPos)) then -- can't be seismic turrets at the destination either
  81. global[PREFIX .. "tunnels"][(game.tick - game.tick % 60) + 3 * 60] = {
  82. -- round to 3 seconds later
  83. goodPos,
  84. {
  85. name = entity.name,
  86. health = entity.health,
  87. orientation = entity.orientation,
  88. surface = entity.surface
  89. }
  90. }
  91. entity.surface.create_entity({name = PREFIX .. "tunnel", position = entity.position})
  92. entity.destroy()
  93. end
  94. end
  95. end
  96.  
  97. function nameToSize(name)
  98. if (string.match(name, "small")) then
  99. return "small"
  100. elseif (string.match(name, "medium")) then
  101. return "medium"
  102. elseif (string.match(name, "big")) then
  103. return "big"
  104. elseif (string.match(name, "behemoth")) then
  105. return "behemoth"
  106. end
  107. end
  108.  
  109. function clearLeechDrains()
  110. for _, struct in pairs(global[PREFIX .. "leech-drains"]) do
  111. struct[2].destroy()
  112. struct = nil
  113. end
  114. end
  115.  
  116.  
  117. function moveLeechDrain(entity)
  118. --for _, struct in pairs(global[PREFIX .. "leech-drains"]) do
  119. -- if (struct[1] == entity) then
  120. -- struct[2].destroy()
  121. -- struct = nil
  122. -- end
  123. -- end
  124. if ((game.tick + shiftTick2) % 20 == 0 ) then
  125. shiftTick2 = shiftTick2 + 1
  126. local size = nameToSize(entity.name)
  127. local newDrain =
  128. entity.surface.create_entity(
  129. {
  130. name = PREFIX .. size .. "-leech-drain",
  131. position = getTunnelPos(entity) --entity.position
  132. }
  133. )
  134. if (newDrain ~= nil) then
  135. table.insert(
  136. global[PREFIX .. "leech-drains"],
  137. {
  138. entity,
  139. newDrain
  140. }
  141. )
  142. end
  143.  
  144. end
  145. end
  146.  
  147. mimicCounter = 1
  148. function maybeSpawnMimic(tree)
  149. mimicCounter = mimicCounter + 1
  150. if (mimicCounter % 80 ~= 0) then
  151. return
  152. end
  153. local evo = game.forces["enemy"].evolution_factor
  154. local size = nil
  155. if (evo > 0.9) then
  156. size = "behemoth"
  157. elseif (evo > 0.5) then
  158. size = "big"
  159. elseif (evo > 0.2) then
  160. size = "medium"
  161. else
  162. size = "small"
  163. end
  164. tree.surface.create_entity(
  165. {
  166. name = PREFIX .. size .. "-mimic-biter",
  167. position = tree.position
  168. }
  169. )
  170. end
  171.  
  172. function getTunnelPos(entity)
  173. local radius = 20 + (game.tick % 15) -- 10 to 25
  174. local tunnelPos = {
  175. x = entity.position.x,
  176. y = entity.position.y
  177. }
  178. local rad = 2 * math.pi * entity.orientation
  179. tunnelPos.x = tunnelPos.x + math.sin(rad) * radius
  180. tunnelPos.y = tunnelPos.y - math.cos(rad) * radius
  181. return tunnelPos
  182. end
  183.  
  184. function onDie(event)
  185. local entity = event.entity
  186.  
  187. if (isExplosiveBiter(entity) and (not settings.global[PREFIX .. "-disable-explosive"])) then
  188. spawnDeathExplosion(entity)
  189. elseif (isLeechSpitter(entity)) then
  190. clearLeechDrains(entity)
  191. elseif (isSeismic(entity)) then
  192. global[PREFIX .. "seismic"][entity] = nil
  193. end
  194. end
  195. script.on_event(defines.events.on_entity_died, onDie)
  196.  
  197. function onTick(event)
  198. if (event.tick % 60 * 4 == 0) then
  199. if (not settings.global[PREFIX .. "-disable-tunnel"]) then
  200. for _, surface in pairs(game.surfaces) do
  201. for tick, tunnel in pairs(global[PREFIX .. "tunnels"]) do
  202. if (tick == game.tick) then
  203. local pos = tunnel[1]
  204. local oldEnt = tunnel[2]
  205.  
  206. if (oldEnt.surface.valid) then
  207. local newEnt = oldEnt.surface.create_entity({name = oldEnt.name, position = pos})
  208. if (newEnt ~= nil) then
  209. newEnt.surface.create_entity({name = PREFIX .. "tunnel", position = newEnt.position})
  210. newEnt.health = oldEnt.health
  211. newEnt.orientation = oldEnt.orientation
  212. global[PREFIX .. "tunnels"][tick] = nil
  213. end
  214. end
  215. end
  216. end
  217. end
  218. end
  219. end
  220. end
  221.  
  222. script.on_event(defines.events.on_tick, onTick)
  223.  
  224. function onMined(event)
  225. local entity = event.entity
  226.  
  227. if (isSeismic(entity)) then
  228. global[PREFIX .. "seismic"][entity] = nil
  229. end
  230.  
  231. if (isTree(entity)) then
  232. maybeSpawnMimic(entity)
  233. end
  234. end
  235. script.on_event(defines.events.on_player_mined_entity, onMined)
  236.  
  237. shiftTick = 0
  238. shiftTick2 = 0
  239.  
  240. function onDamaged(event)
  241. local entity = event.entity
  242.  
  243. if (not (entity and entity.valid)) then
  244. return
  245. end
  246.  
  247. if (isLeechSpitter(entity) and (not settings.global[PREFIX .. "-disable-leech"])) then
  248. moveLeechDrain(entity)
  249.  
  250. end
  251.  
  252. if (isTunnelerBiter(entity)) then
  253. maybeTunnel(entity)
  254. end
  255. end
  256. script.on_event(defines.events.on_entity_damaged, onDamaged)
  257.  
  258. function onBuilt(event)
  259. local entity = event.created_entity
  260.  
  261. if (not (entity and entity.valid)) then
  262. return
  263. end
  264. if (isSeismic(entity)) then
  265. global[PREFIX .. "seismic"][entity] = true
  266. end
  267. end
  268. script.on_event(defines.events.on_built_entity, onBuilt)
  269.  
  270. function onAmmo(event)
  271. local player = game.players[event.player_index]
  272.  
  273. if (not (player and player.valid)) then
  274. return
  275. end
  276.  
  277. if player.get_item_count("atomic-bomb") > 0 then
  278. global[PREFIX .. "atomic-biters-enbaled"] = true
  279. end
  280. end
  281. script.on_event(defines.events.on_player_ammo_inventory_changed, onAmmo)
  282.  
  283. script.on_init(
  284. function()
  285. game.forces["enemy"].friendly_fire = false
  286. global[PREFIX .. "tunnels"] = {}
  287. global[PREFIX .. "seismic"] = {}
  288. global[PREFIX .. "leech-drains"] = {}
  289. global[PREFIX .. "atomic-biters-enbaled"] = false
  290. end
  291. )
Advertisement
Add Comment
Please, Sign In to add comment