Untitled diff

Creado El diff nunca expira
2 eliminaciones
293 líneas
19 adiciones
300 líneas


require "config"
require "config"


local freq = 16
local freq = 16
local freq2 = freq ^ 2
local freq2 = freq ^ 2
local totalgen = 0
local totalgen = 0
local chunksize = 32
local chunksize = 32
local original_tree_count = 0
local original_tree_count = 0
local last_status="-"
local last_status="-"
local debug_text1="-"
local debug_text1="-"
local debug_text2="-"
local debug_text2="-"
local tile_whitelist= {"grass","dirt","landfill"} -- this should find any tile that has grass or dirt in the name, so "grass", "grass-dry" and "dirt-dark" etc.
local tile_whitelist= {"grass","dirt","landfill"} -- this should find any tile that has grass or dirt in the name, so "grass", "grass-dry" and "dirt-dark" etc.


local tree_names = {
local tree_names = {
"tree-01",
"tree-01",
"tree-02",
"tree-02",
"tree-02-red",
"tree-02-red",
"tree-03",
"tree-03",
"tree-04",
"tree-04",
"tree-05",
"tree-05",
"tree-06",
"tree-06",
"tree-06-brown",
"tree-06-brown",
"tree-07",
"tree-07",
"tree-08",
"tree-08",
"tree-08-brown",
"tree-08-brown",
"tree-08-red",
"tree-08-red",
"tree-09",
"tree-09",
"tree-09-brown",
"tree-09-brown",
"tree-09-red"
"tree-09-red"
}
}


local function fmod(a,m)
local function fmod(a,m)
return a - math.floor(a / m) * m
return a - math.floor(a / m) * m
end
end


local function log(msg)
local function log(msg)
if enable_debug_window then
if enable_debug_window then
print("NaturalTree mod:" .. msg)
print("NaturalTree mod:" .. msg)
end
end
end
end


-- Pollution was too high to spawn a tree at thepos, so kill up to 3 surrounding trees
-- Pollution was too high to spawn a tree at thepos, so kill up to 3 surrounding trees
local function kill_surrounding_trees(thepos)
local function kill_surrounding_trees(thepos)
bounds={{thepos[1]-5, thepos[2]-5}, {thepos[1]+5, thepos[2]+5}}
bounds={{thepos[1]-5, thepos[2]-5}, {thepos[1]+5, thepos[2]+5}}
strees=game.surfaces[1].find_entities_filtered{area = bounds, type="tree", limit= 3}
strees=game.surfaces[1].find_entities_filtered{area = bounds, type="tree", limit= 3}
for i=1,#strees do
for i=1,#strees do
log("Killed tree due to pollution at "..strees[i].position.x..","..strees[i].position.y)
log("Killed tree due to pollution at "..strees[i].position.x..","..strees[i].position.y)
strees[i].destroy()
strees[i].destroy()
end
end
end
end


-- search area for specified entity names, return true if there are any.
-- search area for specified entity names, return true if there are any.
local function test_entity(surface,area,names)
local function test_entity(surface,area,names)
for i = 1,#names do
for i = 1,#names do
if 0 ~= surface.count_entities_filtered{area = area, type = names[i]} then
if 0 ~= surface.count_entities_filtered{area = area, type = names[i]} then
return false
return false
end
end
end
end
return true
return true
end
end


-- is the tile at newpos valid and a white-listed tile and pollution low enough (true)
-- is the tile at newpos valid and a white-listed tile and pollution low enough (true)
local function test_tile(surface,newpos)
local function test_tile(surface,newpos)
tile = surface.get_tile(newpos[1],newpos[2])
tile = surface.get_tile(newpos[1],newpos[2])
if not tile.valid then
if not tile.valid then
return false
return false
end
end
for i = 1,#tile_whitelist do
for i = 1,#tile_whitelist do
if string.find(tile.name, tile_whitelist[i]) then
if string.find(tile.name, tile_whitelist[i]) then
if surface.get_pollution({newpos[1],newpos[2]}) < pollution_threshold then
if surface.get_pollution({newpos[1],newpos[2]}) < pollution_threshold then
return true
return true
else
else
kill_surrounding_trees(newpos)
kill_surrounding_trees(newpos)
end
end
end
end
end
end
return false
return false
end
end


-- is parameter a equal to any of the b's
-- is parameter a equal to any of the b's
local function eqany(a,b)
local function eqany(a,b)
for i = 1,#b do
for i = 1,#b do
if a == b[i] then
if a == b[i] then
return true
return true
end
end
end
end
return false
return false
end
end


-----------------------------------------
-----------------------------------------
local shuffle_src = {}
local shuffle_src = {}
local shuffle = {}
local shuffled = false


local function shuffle_it()
for i = 1,freq do
for i = 1,freq do
for j = 1,freq do
for j = 1,freq do
shuffle_src[i * freq + j] = i * freq + j
shuffle_src[i * freq + j] = i * freq + j
end
end
end
end