]> git.somenet.org - factorio/some-resourcespam.git/blob - control.lua
improved handling of cliffs.
[factorio/some-resourcespam.git] / control.lua
1 -- Iterate over every tile in the new chunk and spam with random resources, if empty and possible.\r
2 script.on_event(defines.events.on_chunk_generated, function (event)\r
3     -- prevent one big continuous patch\r
4     if (event.area.left_top.x/32)%10 == 5 or (event.area.left_top.y/32)%10 == 5 then\r
5         return\r
6     end\r
7 \r
8     -- dont spam uranium as it will halt normal miners :/\r
9     ores = {"stone", "iron-ore", "copper-ore", "coal"}\r
10     for x=event.area.left_top.x+0, event.area.right_bottom.x-1 do\r
11         for y=event.area.left_top.y+0, event.area.right_bottom.y-1 do\r
12             if  event.surface.get_tile(x, y).collides_with("ground-tile")\r
13                 and #event.surface.find_entities_filtered{area={{x,y}, {x+1, y+1}}, type="resource"} == 0\r
14                 and #event.surface.find_entities_filtered{area={{x-1, y-1}, {x+1, y+1}}, name="cliff"} == 0\r
15             then\r
16                 cnt = math.random(20, 50)\r
17                 ore = math.random(1, 4)\r
18                 event.surface.create_entity({name=ores[ore], amount=cnt, position={x, y}})\r
19             end\r
20         end\r
21     end\r
22 end)\r