mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 12:16:37 +09:00
Fixed Paths Huge Size
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
-- made by cooldude
|
||||
-- idea from Mylon - Dirt Path
|
||||
|
||||
local clean_time = 18000 -- time in ticks
|
||||
local paths = {
|
||||
-- ['tile name'] = {health,convert to}
|
||||
-- health is in hundrads of steps
|
||||
@@ -26,7 +27,6 @@ local paths = {
|
||||
['dirt-3']={10,'dirt-4'},
|
||||
['dirt-4']={5,'dirt-5'},
|
||||
['dirt-5']={5,'dirt-6'},
|
||||
['dirt-6']={1000,'dirt-6'},
|
||||
['grass-4']={10,'dirt-4'}
|
||||
}
|
||||
for tile,value in pairs(paths) do
|
||||
@@ -43,19 +43,33 @@ local function global_key(surface,pos)
|
||||
return global.paths[key]
|
||||
end
|
||||
|
||||
local function remove_key(surface,pos)
|
||||
local key = 'S'..surface.name..'X'..math.floor(pos.x)..'Y'..math.floor(pos.y)
|
||||
if not global.paths then global.paths = {} end
|
||||
global.paths[key] = nil
|
||||
end
|
||||
|
||||
local function clean_global()
|
||||
if not global.paths then return end
|
||||
for key,tile in pairs(global.paths) do
|
||||
if tile[3] < game.tick-clean_time then global.paths[key] = nil end
|
||||
end
|
||||
end
|
||||
|
||||
local function down_grade(surface,pos)
|
||||
local tile = surface.get_tile(pos).name
|
||||
local new_tile = paths[tile][2]
|
||||
if new_tile == 'world-gen' then new_tile = global_key(surface,pos)[1] or 'grass-1' end
|
||||
surface.set_tiles{{name=new_tile,position=pos}}
|
||||
global_key(surface,pos)[2]=paths[new_tile][1]
|
||||
if not paths[new_tile] then remove_key(surface,pos) return end
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_player_built_tile, function(event)
|
||||
local surface = game.surfaces[event.surface_index]
|
||||
local old_tiles = event.tiles
|
||||
for _,old_tile in pairs(old_tiles) do
|
||||
if not paths[old_tile.old_tile.name] or not paths[surface.get_tile(old_tile.position).name] then return end
|
||||
if not paths[old_tile.old_tile.name] or not paths[surface.get_tile(old_tile.position).name] then remove_key(surface,pos) return end
|
||||
if old_tile.old_tile.name ~= 'refined-concrete' and old_tile.old_tile.name ~= 'refined-hazard-concrete-right'
|
||||
and old_tile.old_tile.name ~= 'refined-hazard-concrete-left' and old_tile.old_tile.name ~= 'concrete'
|
||||
and old_tile.old_tile.name ~= 'hazard-concrete-right' and old_tile.old_tile.name ~= 'hazard-concrete-left'
|
||||
@@ -64,24 +78,33 @@ Event.register(defines.events.on_player_built_tile, function(event)
|
||||
end
|
||||
global_key(surface,old_tile.position)[2]=paths[surface.get_tile(old_tile.position).name][1]
|
||||
end
|
||||
global_key(surface,pos)[3] = event.tick
|
||||
end)
|
||||
|
||||
Event.register(defines.events.on_player_mined_tile, function(event)
|
||||
local surface = game.surfaces[event.surface_index]
|
||||
local old_tiles = event.tiles
|
||||
for _,old_tile in pairs(old_tiles) do
|
||||
if not paths[old_tile.old_tile.name] or not paths[surface.get_tile(old_tile.position).name] then return end
|
||||
if not paths[surface.get_tile(old_tile.position).name] then remove_key(surface,pos) return end
|
||||
global_key(surface,old_tile.position)[2]=paths[surface.get_tile(old_tile.position).name][1]
|
||||
end
|
||||
global_key(surface,pos)[3] = event.tick
|
||||
end)
|
||||
|
||||
Event.register(defines.events.on_player_changed_position, function(event)
|
||||
local player = Game.get_player(event)
|
||||
local surface = player.surface
|
||||
local pos = player.position
|
||||
if not paths[surface.get_tile(pos).name] then return end
|
||||
if not paths[surface.get_tile(pos).name] then remove_key(surface,pos) return end
|
||||
global_key(surface,pos)[2] = global_key(surface,pos)[2]-1
|
||||
if global_key(surface,pos)[2] <= 0 then
|
||||
down_grade(surface,pos)
|
||||
end
|
||||
global_key(surface,pos)[3] = event.tick
|
||||
end)
|
||||
|
||||
Event.register(defines.events.on_tick, function(event)
|
||||
if (game.tick%clean_time) == 0 then
|
||||
clean_global()
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user