3 local replaceableTiles = {
5 ["deepwater"] = "grass-1",
6 ["water-green"] = "grass-1",
7 ["deepwater-green"] = "grass-1"
11 script.on_configuration_changed(function(data)
12 if waterbombs ~= nil then
13 script.on_event(defines.events.on_tick, tickBombs)
18 script.on_load(function(event)
19 if waterbombs ~= nil then
20 script.on_event(defines.events.on_tick, tickBombs)
25 script.on_event(defines.events.on_built_entity, function(event)
26 if event.entity.name == "waterbomb" then
28 for _, surface in pairs(game.surfaces) do
29 for _, entity in pairs(surface.find_entities_filtered{name="waterbomb"}) do
30 table.insert(waterbombs, entity)
33 script.on_event(defines.events.on_tick, tickBombs)
38 function tickBombs(event)
39 if event.tick % 20 == 0 then
40 for k,e in pairs(waterbombs) do
42 table.remove(waterbombs, k)
44 elseif e.energy > 49000000 then
45 local epos, x, y, distX, distY, surface
46 local explosionRadius = settings.global["Waterbomb-explosion-radius"].value
54 for xx = x - explosionRadius, x + explosionRadius, 2 do
55 for yy = y - explosionRadius, y + explosionRadius, 2 do
56 distX = math.abs(x - xx)
57 distY = math.abs(y - yy)
59 if math.floor(math.sqrt((distX * distX) + (distY * distY))) <= explosionRadius then
60 e.surface.create_entity({name = "medium-explosion", position = {x = xx, y = yy}})
66 e.surface.create_entity({name = "waterbomb-detonation", position = e.position, target = e, speed = 1})
70 table.remove(waterbombs, k)
73 createWater(x, y, explosionRadius, surface)
74 throwDirt(x, y, explosionRadius, surface)
77 for a = 1, (explosionRadius * 10) do
78 createRandomStone(epos, surface)
79 createRandomStone(epos, surface)
84 -- nothing more to be exploded. Stop ticking.
85 if #waterbombs == 0 then
87 script.on_event(defines.events.on_tick, nil)
92 function createWater(x, y, size, surface)
93 -- Setting tiles to water where player characters are standing deletes the character and sets them to god mode. We dont want that.
94 local players = surface.find_entities_filtered({area = {{x - size - 1, y - size - 1}, {x + size + 1, y + size + 1}}, type="character"})
103 for wx = x - size, x + size, 1 do
104 for wy = y - size, y + size, 1 do
105 table.insert(waterTiles, {name="water", position={wx, wy}})
108 surface.set_tiles(waterTiles)
111 table.insert(waterTiles, {name="deepwater", position={x, y}})
112 surface.set_tiles(waterTiles)
116 function throwDirt(x, y, size, surface)
121 if settings.global["Waterbomb-throw-dirt"].value == true then
125 for xx = x - size, x + (size + 1), 1 do
126 for yy = y - size, y + (size + 1), 1 do
127 distX = math.abs(x - xx)
128 distY = math.abs(y - yy)
130 if math.floor(math.random(1, 4)) >= 4 then
131 table.insert(dirtTiles, {name = "grass-1", position = {xx, yy}})
136 if #dirtTiles ~= 0 then
137 surface.set_tiles(dirtTiles)
143 function createRandomStone(position, surface)
145 local maximumRockThrowDistance = settings.global["Waterbomb-explosion-radius"].value + 7
147 if settings.global["Waterbomb-throw-stone"].value == true then
151 if math.random() > 0.5 then
152 x = x - math.floor(math.random(1, maximumRockThrowDistance))
154 x = x + math.floor(math.random(1, maximumRockThrowDistance))
157 if math.random() < 0.5 then
158 y = y - math.floor(math.random(1, maximumRockThrowDistance))
160 y = y + math.floor(math.random(1, maximumRockThrowDistance))
163 if math.floor(math.random(1, 4)) >= 3 then
164 if settings.global["Waterbomb-throw-stone-into-water"].value == true then
165 surface.set_tiles({{name="grass-1", position={math.floor(x), math.floor(y)}}})
168 local tileName = surface.get_tile(math.floor(x), math.floor(y)).name
169 if not replaceableTiles[tileName] then
170 surface.create_entity({name="stone", position={x, y}}).amount = math.floor(math.random(13, 37))
171 surface.create_entity({name="explosion", position={x, y}})