Advertisement
rafizzzz

Untitled

Feb 6th, 2021 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | None | 0 0
  1. function RemoveAliensInArea(surface, area)
  2.     for _, entity in pairs(surface.find_entities_filtered{area = area, force = "enemy"}) do
  3.         entity.destroy()
  4.     end
  5. end
  6.  
  7. function ReduceAliensInArea(surface, area, reductionFactor, evolution)
  8.     for _, entity in pairs(surface.find_entities_filtered{area = area, force = "enemy"}) do
  9.         if (math.random(0,reductionFactor) > 0) then
  10.             entity.destroy()
  11.         end
  12.     end
  13.     -- Downgrade all huge worms
  14.     if (evolution<0.75) then
  15.         for _, entity in pairs(surface.find_entities_filtered{area = area, name = "behemoth-worm-turret"}) do
  16.                 surface.create_entity({
  17.                     name="big-worm-turret",
  18.                     position=entity.position
  19.                 })
  20.                 entity.destroy()
  21.         end
  22.     end
  23.     -- Downgrade all big worms
  24.     if (evolution<0.5) then
  25.         for _, entity in pairs(surface.find_entities_filtered{area = area, name = "big-worm-turret"}) do
  26.                 surface.create_entity({
  27.                     name="medium-worm-turret",
  28.                     position=entity.position
  29.                 })
  30.                 entity.destroy()
  31.         end
  32.     end
  33.     -- Downgrade all medium worms
  34.     if (evolution<0.25) then
  35.         for _, entity in pairs(surface.find_entities_filtered{area = area, name = "medium-worm-turret"}) do
  36.                 surface.create_entity({
  37.                     name="small-worm-turret",
  38.                     position=entity.position
  39.                 })
  40.                 entity.destroy()
  41.         end
  42.     end
  43. end
  44.  
  45. local function removeAlienDecoratives(surface,area)
  46.     surface.destroy_decoratives( { area=area, name= {"shroom-decal","worms-decal","enemy-decal","enemy-decal-transparent"} } )
  47. end
  48.  
  49. local function scaleDownBiters(surface,area,evolution)
  50.     local reduction = 40
  51.     if (evolution>=0.1) then
  52.         reduction = 30
  53.     end
  54.     if (evolution>=0.2) then
  55.         reduction = 20
  56.     end
  57.     if (evolution>=0.35) then
  58.         reduction = 10
  59.     end
  60.     if (evolution>=0.5) then
  61.         reduction = 5
  62.     end
  63.     if (evolution>=0.65) then
  64.         reduction = 3
  65.     end
  66.     if (evolution>0.8) then
  67.         reduction = 1
  68.     end
  69.  
  70.     local dice_roll = math.random(0,reduction)
  71.     if ( dice_roll > 2) then
  72.         RemoveAliensInArea(surface,area)            -- kill all "enemy" objects in this chunk
  73.         removeAlienDecoratives(surface,event.area)
  74.     elseif (dice_roll > 0)then
  75.         ReduceAliensInArea(surface,area,2,evolution) --downgrade worms and kill some nests
  76.     else
  77.         ReduceAliensInArea(surface,area,0,evolution) --only downgrade worms
  78.     end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement