workaround for ore generation
This commit is contained in:
parent
22076c0522
commit
16cecece72
6 changed files with 89 additions and 2 deletions
|
|
@ -3,8 +3,10 @@ Version: 2.0.0
|
||||||
Date: 2024-12-06
|
Date: 2024-12-06
|
||||||
Features:
|
Features:
|
||||||
- Works with Factorio 2.0 vanilla and Space Age
|
- Works with Factorio 2.0 vanilla and Space Age
|
||||||
Currently does not work when adding to a ongoing game:
|
Currently uses a workaround to generate ore patches on new chunks when added to an existing
|
||||||
https://forums.factorio.com/viewtopic.php?f=7&t=124996
|
game due to an issue, https://forums.factorio.com/viewtopic.php?t=124996
|
||||||
|
And thank's to Eradicator's script to make natural looking ore patches for the workaround,
|
||||||
|
https://forums.factorio.com/viewtopic.php?t=72723
|
||||||
- Compatibility with other mods is not confirmed, but many will still work
|
- Compatibility with other mods is not confirmed, but many will still work
|
||||||
- Titanium production on Vulcanus and Gleba, recycling on Fulgora.
|
- Titanium production on Vulcanus and Gleba, recycling on Fulgora.
|
||||||
These production chains may need further balancing or updates.
|
These production chains may need further balancing or updates.
|
||||||
|
|
|
||||||
|
|
@ -95,5 +95,77 @@ function util.warptorio2_expansion_helper()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- A workaround for generating ores until this bug is fixed:
|
||||||
|
-- https://forums.factorio.com/viewtopic.php?f=7&t=124996&p=655013#p655013
|
||||||
|
function util.ore_workaround(event)
|
||||||
|
for i, ore in pairs(util.me.ores_for_workaround) do
|
||||||
|
if event.surface.map_gen_settings.autoplace_controls["titanium-ore"] then return end
|
||||||
|
if event.surface.name ~= "nauvis" then return end
|
||||||
|
if math.random() < settings.global[util.me.name.."-ore-workaround-probability"].value then
|
||||||
|
util.generate_ore(event, ore.name, ore.amount, ore.tiles)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The majority of this function was written by Eradicator, see https://forums.factorio.com/viewtopic.php?t=72723
|
||||||
|
function util.generate_ore(event, name, amount, tiles)
|
||||||
|
local biases = {[0] = {[0] = 1}}
|
||||||
|
local t = 1
|
||||||
|
|
||||||
|
repeat
|
||||||
|
t = t + util.grow(biases,t,tiles)
|
||||||
|
until t >= tiles
|
||||||
|
|
||||||
|
local pos = {x=event.position.x*32, y=event.position.y*32}
|
||||||
|
local multiplier = math.max(math.abs(event.position.x), math.abs(event.position.y))
|
||||||
|
if multiplier < 10 then return end -- don't generate too close to start
|
||||||
|
local total_bias = 0
|
||||||
|
for x,_ in pairs(biases) do for y,bias in pairs(_) do
|
||||||
|
total_bias = total_bias + bias
|
||||||
|
end end
|
||||||
|
|
||||||
|
for x,_ in pairs(biases) do for y,bias in pairs(_) do
|
||||||
|
local entity = {
|
||||||
|
name = name,
|
||||||
|
amount = amount * (bias/total_bias) * multiplier,
|
||||||
|
force = 'neutral',
|
||||||
|
position = {pos.x+x,pos.y+y},
|
||||||
|
}
|
||||||
|
if event.surface.can_place_entity(entity) then
|
||||||
|
event.surface.create_entity(entity)
|
||||||
|
end
|
||||||
|
end end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The majority of this function was written by Eradicator, see https://forums.factorio.com/viewtopic.php?t=72723
|
||||||
|
function util.grow(grid,t,tiles)
|
||||||
|
local w_max = 256
|
||||||
|
local h_max = 256
|
||||||
|
local abs = math.abs
|
||||||
|
local old = {}
|
||||||
|
local new_count = 0
|
||||||
|
for x,_ in pairs(grid) do for y,__ in pairs(_) do
|
||||||
|
table.insert(old,{x,y})
|
||||||
|
end end
|
||||||
|
for _,pos in pairs(old) do
|
||||||
|
local x,y = pos[1],pos[2]
|
||||||
|
local bias = grid[x][y]
|
||||||
|
for dx=-1,1,1 do for dy=-1,1,1 do
|
||||||
|
local a,b = x+dx, y+dy
|
||||||
|
if (math.random() > 0.9) and (abs(a) < w_max) and (abs(b) < h_max) then
|
||||||
|
grid[a] = grid[a] or {}
|
||||||
|
if not grid[a][b] then
|
||||||
|
grid[a][b] = 1 - (t/tiles)
|
||||||
|
new_count = new_count + 1
|
||||||
|
if (new_count+t) == tiles then return new_count end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end end
|
||||||
|
end
|
||||||
|
return new_count
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return util
|
return util
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
local util = require("control-util")
|
local util = require("control-util")
|
||||||
|
|
||||||
script.on_init(util.check_fluid_mining)
|
script.on_init(util.check_fluid_mining)
|
||||||
|
|
||||||
|
script.on_event(defines.events.on_chunk_generated, util.ore_workaround)
|
||||||
|
|
|
||||||
|
|
@ -53,11 +53,13 @@ titanium-in-foundry=Smelt titanium in an oxygen-free environment
|
||||||
bztitanium-recipe-bypass=Bypass recipes
|
bztitanium-recipe-bypass=Bypass recipes
|
||||||
bztitanium-mining-fluid=Titanium mining fluid
|
bztitanium-mining-fluid=Titanium mining fluid
|
||||||
bztitanium-mining-fluid-amount=Titanium mining fluid amount
|
bztitanium-mining-fluid-amount=Titanium mining fluid amount
|
||||||
|
bztitanium-ore-workaround-probability=Ore generation workaround probability
|
||||||
|
|
||||||
[mod-setting-description]
|
[mod-setting-description]
|
||||||
bztitanium-recipe-bypass=Skip modifying these recipes (comma-separated list).
|
bztitanium-recipe-bypass=Skip modifying these recipes (comma-separated list).
|
||||||
bztitanium-mining-fluid=Choose which fluid to use when mining Titanium.\n[color=orange]Lubricant is recommended![/color]
|
bztitanium-mining-fluid=Choose which fluid to use when mining Titanium.\n[color=orange]Lubricant is recommended![/color]
|
||||||
bztitanium-mining-fluid-amount=Amount of fluid used to mine. Default 3.
|
bztitanium-mining-fluid-amount=Amount of fluid used to mine. Default 3.
|
||||||
|
bztitanium-ore-workaround-probability=When using workaround, probability of generating ore on a given chunk. (Only used when mod is added to existing game, if bug in forum post 124996 is not fixed)
|
||||||
[string-mod-setting]
|
[string-mod-setting]
|
||||||
bztitanium-mining-fluid-lubricant=Lubricant
|
bztitanium-mining-fluid-lubricant=Lubricant
|
||||||
bztitanium-mining-fluid-sulfuric-acid=Sulfuric Acid
|
bztitanium-mining-fluid-sulfuric-acid=Sulfuric Acid
|
||||||
|
|
|
||||||
1
me.lua
1
me.lua
|
|
@ -3,6 +3,7 @@ local me = {}
|
||||||
me.name = "bztitanium"
|
me.name = "bztitanium"
|
||||||
me.titanium_plate = ""
|
me.titanium_plate = ""
|
||||||
me.titanium_processing = ""
|
me.titanium_processing = ""
|
||||||
|
me.ores_for_workaround = {{name="titanium-ore", amount=100000, tiles=300}}
|
||||||
|
|
||||||
if mods and mods["FactorioExtended-Plus-Core"] then
|
if mods and mods["FactorioExtended-Plus-Core"] then
|
||||||
me.titanium_plate = "titanium-alloy"
|
me.titanium_plate = "titanium-alloy"
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,12 @@ data:extend({
|
||||||
minimum_value = 1,
|
minimum_value = 1,
|
||||||
maximum_value = 1000,
|
maximum_value = 1000,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type = "double-setting",
|
||||||
|
name = "bztitanium-ore-workaround-probability",
|
||||||
|
setting_type = "runtime-global",
|
||||||
|
default_value = .01,
|
||||||
|
minimum_value = .00001,
|
||||||
|
maximum_value = .1,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue