From a10420c0d46ea4931b1fb91bfbbe05b0dacc686d Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 5 Jun 2019 23:14:57 +0200 Subject: [PATCH] Added mod settings + tweaked explosion --- changelog.txt | 7 ++++ control.lua | 74 +++++++++++++++++++---------------------- info.json | 2 +- locale/en/waterbomb.cfg | 16 +++++++-- settings.lua | 28 ++++++++++++++++ 5 files changed, 84 insertions(+), 43 deletions(-) create mode 100644 settings.lua diff --git a/changelog.txt b/changelog.txt index 5a1db01..8d7c110 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,10 @@ +--------------------------------------------------------------------------------------------------- +Version: 0.17.4 +Date: 2019-06-05 + + Changed: + - Added mod settings + tweaked explosion + --------------------------------------------------------------------------------------------------- Version: 0.17.3 Date: 2019-05-03 diff --git a/control.lua b/control.lua index 7357556..b27e0b3 100644 --- a/control.lua +++ b/control.lua @@ -1,9 +1,4 @@ -local explosionRadius = 2 -local displaceDirt = true -local throwRocksIntoWater = true -local throwRocks = true -local maximumRockThrowDistance = explosionRadius + 8 local bombs local replaceableTiles = { ["water"] = "grass-1", @@ -47,9 +42,12 @@ function tickBombs(event) table.remove(global.waterbombs, k) elseif e.energy > 49000000 then - local x, y, distX, distY, surface - x = e.position.x - y = e.position.y + local epos, x, y, distX, distY, surface + local explosionRadius = settings.global["Waterbomb-explosion-radius"].value + + epos = e.position + x = epos.x + y = epos.y surface = e.surface -- create explosions @@ -67,12 +65,6 @@ function tickBombs(event) -- big detonation e.surface.create_entity({name = "waterbomb-detonation", position = e.position, target = e, speed = 1}) - -- random stones - for a = 1, explosionRadius * 10 do - createRandomStone(e.position, surface) - createRandomStone(e.position, surface) - end - -- bomb explodes e.destroy() table.remove(global.waterbombs, k) @@ -80,6 +72,12 @@ function tickBombs(event) -- water is created createWater(x, y, explosionRadius, surface) throwDirt(x, y, explosionRadius, surface) + + -- random stones + for a = 1, (explosionRadius * 10) do + createRandomStone(epos, surface) + createRandomStone(epos, surface) + end end end @@ -118,19 +116,18 @@ end function throwDirt(x, y, size, surface) local dirtTiles = {} local tileName - local floor = math.floor local distX,distY - if displaceDirt == true then - x = floor(x) - y = floor(y) + if settings.global["Waterbomb-throw-dirt"].value == true then + x = math.floor(x) + y = math.floor(y) - for xx = x - (size + 1), x + (size + 1), 1 do - for yy = y - (size + 1), y + (size + 1), 1 do + for xx = x - size, x + (size + 1), 1 do + for yy = y - size, y + (size + 1), 1 do distX = math.abs(x - xx) distY = math.abs(y - yy) - if floor(math.sqrt((distX * distX) + (distY * distY))) >= 2 then + if math.floor(math.random(1, 4)) >= 4 then table.insert(dirtTiles, {name = "grass-1", position = {xx, yy}}) end end @@ -145,36 +142,33 @@ end function createRandomStone(position, surface) local x,y - local tileName - local floor = math.floor - local random = math.random + local maximumRockThrowDistance = settings.global["Waterbomb-explosion-radius"].value + 7 - if throwRocks == true then + if settings.global["Waterbomb-throw-stone"].value == true then x = position.x y = position.y - if random() > 0.5 then - x = x - floor(random(2, maximumRockThrowDistance)) + if math.random() > 0.5 then + x = x - math.floor(math.random(1, maximumRockThrowDistance)) else - x = x + floor(random(2, maximumRockThrowDistance)) + x = x + math.floor(math.random(1, maximumRockThrowDistance)) end - if random() < 0.5 then - y = y - floor(random(2, maximumRockThrowDistance)) + if math.random() < 0.5 then + y = y - math.floor(math.random(1, maximumRockThrowDistance)) else - y = y + floor(random(2, maximumRockThrowDistance)) + y = y + math.floor(math.random(1, maximumRockThrowDistance)) end - tileName = surface.get_tile(floor(x), floor(y)).name - - if replaceableTiles[tileName] then - if throwRocksIntoWater == true then - surface.set_tiles({{name=replaceableTiles[tileName], position={floor(x), floor(y)}}}) + if math.floor(math.random(1, 4)) >= 3 then + if settings.global["Waterbomb-throw-stone-into-water"].value == true then + surface.set_tiles({{name="grass-1", position={math.floor(x), math.floor(y)}}}) end - else - if floor(random(1, 4)) > 2 then - surface.create_entity({name = "stone", position = {x, y}}).amount = floor(random(13, 27)) - surface.create_entity({name = "explosion", position = {x, y}}) + + local tileName = surface.get_tile(math.floor(x), math.floor(y)).name + if not replaceableTiles[tileName] then + surface.create_entity({name="stone", position={x, y}}).amount = math.floor(math.random(13, 37)) + surface.create_entity({name="explosion", position={x, y}}) end end end diff --git a/info.json b/info.json index 3190c2e..c4128c2 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "Waterbomb", - "version": "0.17.3", + "version": "0.17.4", "title": "Waterbomb", "author": "someone1337", "homepage": "https://git.somenet.org/pub/jan/factorio_Waterbomb.git", diff --git a/locale/en/waterbomb.cfg b/locale/en/waterbomb.cfg index fb48cec..8e4ade1 100644 --- a/locale/en/waterbomb.cfg +++ b/locale/en/waterbomb.cfg @@ -1,11 +1,23 @@ [entity-name] -waterbomb=Shaped Compression Bomb +waterbomb=Shaped Compression Water Bomb [entity-description] waterbomb=Massive internal pressure buildup creates a huge explosion throwing land out of the way [item-name] -waterbomb=Shaped Compression Bomb +waterbomb=Shaped Compression Water Bomb [item-description] waterbomb=Massive internal pressure buildup creates a huge explosion throwing land out of the way + +[mod-setting-name] +Waterbomb-throw-dirt=Throw dirt +Waterbomb-throw-stone=Throw stone +Waterbomb-throw-stone-into-water=Throw stone into water +Waterbomb-explosion-radius=Explosion radius + +[mod-setting-description] +Waterbomb-throw-dirt=Throw dirt +Waterbomb-throw-stone=Throw stone +Waterbomb-throw-stone-into-water=Throw stone into water +Waterbomb-explosion-radius=Explosion radius diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..dc76d4d --- /dev/null +++ b/settings.lua @@ -0,0 +1,28 @@ +data:extend({ + { + type = "bool-setting", + name = "Waterbomb-throw-dirt", + setting_type = "runtime-global", + default_value = true, + }, + { + type = "bool-setting", + name = "Waterbomb-throw-stone", + setting_type = "runtime-global", + default_value = true, + }, + { + type = "bool-setting", + name = "Waterbomb-throw-stone-into-water", + setting_type = "runtime-global", + default_value = true, + }, + { + type = "int-setting", + name = "Waterbomb-explosion-radius", + setting_type = "runtime-global", + default_value = 2, + minimum_value = 2, + maximum_value = 16, + }, +}) -- 2.43.0