mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-10 00:43:27 +02:00
commit
e180e89166
@ -192,7 +192,7 @@ function Public.reset_map()
|
||||
Collapse.set_speed(8)
|
||||
Collapse.set_amount(1)
|
||||
Collapse.set_max_line_size(level_depth)
|
||||
Collapse.set_surface(surface)
|
||||
Collapse.set_surface_index(surface.index)
|
||||
Collapse.set_position({0, 130})
|
||||
Collapse.set_direction('north')
|
||||
|
||||
|
@ -82,7 +82,7 @@ local collapse_kill = {
|
||||
['flamethrower-turret'] = true,
|
||||
['gun-turret'] = true,
|
||||
['artillery-turret'] = true,
|
||||
['landmine'] = true,
|
||||
['land-mine'] = true,
|
||||
['locomotive'] = true,
|
||||
['cargo-wagon'] = true,
|
||||
['character'] = true,
|
||||
@ -253,7 +253,7 @@ function Public.reset_map()
|
||||
Collapse.set_amount(1)
|
||||
-- Collapse.set_max_line_size(zone_settings.zone_width)
|
||||
Collapse.set_max_line_size(540)
|
||||
Collapse.set_surface(surface)
|
||||
Collapse.set_surface_index(surface.index)
|
||||
Collapse.set_position({0, 130})
|
||||
Collapse.set_direction('north')
|
||||
Collapse.start_now(false)
|
||||
|
@ -136,9 +136,10 @@ local function init(mountain_race)
|
||||
Collapse.set_speed(8)
|
||||
Collapse.set_amount(0)
|
||||
Collapse.set_max_line_size(mountain_race.border_width + mountain_race.playfield_height * 2)
|
||||
Collapse.set_surface(surface)
|
||||
Collapse.set_surface_index(surface.index)
|
||||
Collapse.set_position({0, 0})
|
||||
Collapse.set_direction('east')
|
||||
Collapse.start_now(true)
|
||||
|
||||
game.reset_time_played()
|
||||
|
||||
|
@ -1,60 +1,97 @@
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Public = {}
|
||||
|
||||
local math_floor = math.floor
|
||||
local table_shuffle_table = table.shuffle_table
|
||||
|
||||
local collapse = {
|
||||
local this = {
|
||||
debug = false
|
||||
}
|
||||
Global.register(
|
||||
collapse,
|
||||
this,
|
||||
function(tbl)
|
||||
collapse = tbl
|
||||
this = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local directions = {
|
||||
['north'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.width
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
local surface_index = this.surface_index
|
||||
if not surface_index then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = game.get_surface(surface_index)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
local width = surface.map_gen_settings.width
|
||||
if width > this.max_line_size then
|
||||
width = this.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {0, -1}
|
||||
collapse.area = {{position.x - a, position.y - 1}, {position.x + a, position.y}}
|
||||
this.vector = {0, -1}
|
||||
this.area = {{position.x - a, position.y - 1}, {position.x + a, position.y}}
|
||||
end,
|
||||
['south'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.width
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
local surface_index = this.surface_index
|
||||
if not surface_index then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = game.get_surface(surface_index)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
local width = surface.map_gen_settings.width
|
||||
if width > this.max_line_size then
|
||||
width = this.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {0, 1}
|
||||
collapse.area = {{position.x - a, position.y}, {position.x + a, position.y + 1}}
|
||||
this.vector = {0, 1}
|
||||
this.area = {{position.x - a, position.y}, {position.x + a, position.y + 1}}
|
||||
end,
|
||||
['west'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.height
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
local surface_index = this.surface_index
|
||||
if not surface_index then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = game.get_surface(surface_index)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
local width = surface.map_gen_settings.height
|
||||
if width > this.max_line_size then
|
||||
width = this.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {-1, 0}
|
||||
collapse.area = {{position.x - 1, position.y - a}, {position.x, position.y + a}}
|
||||
this.vector = {-1, 0}
|
||||
this.area = {{position.x - 1, position.y - a}, {position.x, position.y + a}}
|
||||
end,
|
||||
['east'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.height
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
local surface_index = this.surface_index
|
||||
if not surface_index then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = game.get_surface(surface_index)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
local width = surface.map_gen_settings.height
|
||||
if width > this.max_line_size then
|
||||
width = this.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {1, 0}
|
||||
collapse.area = {{position.x, position.y - a}, {position.x + 1, position.y + a}}
|
||||
this.vector = {1, 0}
|
||||
this.area = {{position.x, position.y - a}, {position.x + 1, position.y + a}}
|
||||
end
|
||||
}
|
||||
|
||||
local function print_debug(a)
|
||||
if not collapse.debug then
|
||||
if not this.debug then
|
||||
return
|
||||
end
|
||||
print('Collapse error #' .. a)
|
||||
@ -64,52 +101,60 @@ local function set_collapse_tiles(surface)
|
||||
if not surface or surface.valid then
|
||||
print_debug(45)
|
||||
end
|
||||
game.forces.player.chart(surface, collapse.area)
|
||||
collapse.tiles = surface.find_tiles_filtered({area = collapse.area})
|
||||
if not collapse.tiles then
|
||||
game.forces.player.chart(surface, this.area)
|
||||
this.tiles = surface.find_tiles_filtered({area = this.area})
|
||||
if not this.tiles then
|
||||
return
|
||||
end
|
||||
collapse.size_of_tiles = #collapse.tiles
|
||||
if collapse.size_of_tiles > 0 then
|
||||
table_shuffle_table(collapse.tiles)
|
||||
this.size_of_tiles = #this.tiles
|
||||
if this.size_of_tiles > 0 then
|
||||
table_shuffle_table(this.tiles)
|
||||
end
|
||||
collapse.position = {x = collapse.position.x + collapse.vector[1], y = collapse.position.y + collapse.vector[2]}
|
||||
local v = collapse.vector
|
||||
local area = collapse.area
|
||||
collapse.area = {{area[1][1] + v[1], area[1][2] + v[2]}, {area[2][1] + v[1], area[2][2] + v[2]}}
|
||||
game.forces.player.chart(surface, collapse.area)
|
||||
this.position = {x = this.position.x + this.vector[1], y = this.position.y + this.vector[2]}
|
||||
local v = this.vector
|
||||
local area = this.area
|
||||
this.area = {{area[1][1] + v[1], area[1][2] + v[2]}, {area[2][1] + v[1], area[2][2] + v[2]}}
|
||||
game.forces.player.chart(surface, this.area)
|
||||
end
|
||||
|
||||
local function progress()
|
||||
local surface = collapse.surface
|
||||
|
||||
if not collapse.start_now then
|
||||
collapse.tiles = nil
|
||||
local surface_index = this.surface_index
|
||||
if not surface_index then
|
||||
return
|
||||
end
|
||||
|
||||
local tiles = collapse.tiles
|
||||
local surface = game.get_surface(surface_index)
|
||||
if not surface.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if not this.start_now then
|
||||
this.tiles = nil
|
||||
return
|
||||
end
|
||||
|
||||
local tiles = this.tiles
|
||||
if not tiles then
|
||||
set_collapse_tiles(surface)
|
||||
tiles = collapse.tiles
|
||||
tiles = this.tiles
|
||||
end
|
||||
if not tiles then
|
||||
return
|
||||
end
|
||||
|
||||
for _ = 1, collapse.amount, 1 do
|
||||
local tile = tiles[collapse.size_of_tiles]
|
||||
for _ = 1, this.amount, 1 do
|
||||
local tile = tiles[this.size_of_tiles]
|
||||
if not tile then
|
||||
collapse.tiles = nil
|
||||
this.tiles = nil
|
||||
return
|
||||
end
|
||||
collapse.size_of_tiles = collapse.size_of_tiles - 1
|
||||
this.size_of_tiles = this.size_of_tiles - 1
|
||||
if not tile.valid then
|
||||
return
|
||||
end
|
||||
if collapse.specific_entities.enabled then
|
||||
if this.specific_entities.enabled then
|
||||
local position = {tile.position.x + 0.5, tile.position.y + 0.5}
|
||||
local entities = collapse.specific_entities.entities
|
||||
local entities = this.specific_entities.entities
|
||||
for _, e in pairs(surface.find_entities_filtered({area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}})) do
|
||||
if entities[e.name] and e.valid and e.health then
|
||||
e.die()
|
||||
@ -118,7 +163,7 @@ local function progress()
|
||||
end
|
||||
end
|
||||
end
|
||||
if collapse.kill then
|
||||
if this.kill then
|
||||
local position = {tile.position.x + 0.5, tile.position.y + 0.5}
|
||||
for _, e in pairs(surface.find_entities_filtered({area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}})) do
|
||||
if e.valid and e.health then
|
||||
@ -130,20 +175,19 @@ local function progress()
|
||||
end
|
||||
end
|
||||
|
||||
function Public.set_surface(surface)
|
||||
if not surface then
|
||||
function Public.set_surface_index(surface_index)
|
||||
if not surface_index then
|
||||
print_debug(1)
|
||||
return
|
||||
end
|
||||
|
||||
local surface = game.get_surface(surface_index)
|
||||
if not surface.valid then
|
||||
print_debug(2)
|
||||
return
|
||||
end
|
||||
if not game.surfaces[surface.index] then
|
||||
print_debug(3)
|
||||
return
|
||||
end
|
||||
collapse.surface = surface
|
||||
|
||||
this.surface_index = surface_index
|
||||
end
|
||||
|
||||
function Public.set_direction(direction)
|
||||
@ -151,7 +195,7 @@ function Public.set_direction(direction)
|
||||
print_debug(11)
|
||||
return
|
||||
end
|
||||
directions[direction](collapse.position)
|
||||
directions[direction](this.position)
|
||||
end
|
||||
|
||||
function Public.set_speed(speed)
|
||||
@ -163,7 +207,7 @@ function Public.set_speed(speed)
|
||||
if speed < 1 then
|
||||
speed = 1
|
||||
end
|
||||
collapse.speed = speed
|
||||
this.speed = speed
|
||||
end
|
||||
|
||||
function Public.set_amount(amount)
|
||||
@ -175,7 +219,7 @@ function Public.set_amount(amount)
|
||||
if amount < 0 then
|
||||
amount = 0
|
||||
end
|
||||
collapse.amount = amount
|
||||
this.amount = amount
|
||||
end
|
||||
|
||||
function Public.set_position(position)
|
||||
@ -205,28 +249,28 @@ function Public.set_position(position)
|
||||
if position.y then
|
||||
y = position.y
|
||||
end
|
||||
collapse.position = {x = x, y = y}
|
||||
this.position = {x = x, y = y}
|
||||
end
|
||||
|
||||
function Public.get_position()
|
||||
return collapse.position
|
||||
return this.position
|
||||
end
|
||||
|
||||
function Public.get_amount()
|
||||
return collapse.amount
|
||||
return this.amount
|
||||
end
|
||||
|
||||
function Public.get_speed()
|
||||
return collapse.speed
|
||||
return this.speed
|
||||
end
|
||||
|
||||
function Public.start_now(status)
|
||||
if status == true then
|
||||
collapse.start_now = true
|
||||
this.start_now = true
|
||||
elseif status == false then
|
||||
collapse.start_now = false
|
||||
this.start_now = false
|
||||
end
|
||||
return collapse.start_now
|
||||
return this.start_now
|
||||
end
|
||||
|
||||
function Public.set_max_line_size(size)
|
||||
@ -239,44 +283,45 @@ function Public.set_max_line_size(size)
|
||||
print_debug(21)
|
||||
return
|
||||
end
|
||||
collapse.max_line_size = size
|
||||
this.max_line_size = size
|
||||
end
|
||||
|
||||
function Public.set_kill_entities(a)
|
||||
collapse.kill = a
|
||||
this.kill = a
|
||||
end
|
||||
|
||||
function Public.set_kill_specific_entities(tbl)
|
||||
if tbl then
|
||||
collapse.specific_entities = tbl
|
||||
this.specific_entities = tbl
|
||||
else
|
||||
collapse.specific_entities = {
|
||||
this.specific_entities = {
|
||||
enabled = false
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
Public.set_surface(game.surfaces.nauvis)
|
||||
Public.set_surface_index(game.surfaces.nauvis.index)
|
||||
Public.set_position({0, 32})
|
||||
Public.set_max_line_size(256)
|
||||
Public.set_direction('north')
|
||||
Public.set_kill_entities(true)
|
||||
Public.set_kill_specific_entities()
|
||||
collapse.tiles = nil
|
||||
collapse.speed = 1
|
||||
collapse.amount = 8
|
||||
collapse.start_now = true
|
||||
this.tiles = nil
|
||||
this.speed = 1
|
||||
this.amount = 8
|
||||
this.start_now = false
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
if game.tick % collapse.speed ~= 0 then
|
||||
local tick = game.tick
|
||||
if tick % this.speed ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
progress()
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user