mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-05-13 21:56:29 +02:00
more changes to planet prison
This commit is contained in:
parent
f1adda1f60
commit
43beed887a
@ -2,7 +2,6 @@ local Global = require('utils.global')
|
||||
local Event = require('utils.event')
|
||||
local Server = require('utils.server')
|
||||
local MapFuntions = require('tools.map_functions')
|
||||
local TimersFunctions = require('planet_prison.mod.timers')
|
||||
local CommonFunctions = require('planet_prison.mod.common')
|
||||
local LayersFunctions = require('planet_prison.mod.layers')
|
||||
local AIFunctions = require('planet_prison.mod.ai')
|
||||
@ -104,8 +103,7 @@ local set_noise_hostile_hook =
|
||||
|
||||
local set_neutral_to_entity =
|
||||
Token.register(
|
||||
function(data)
|
||||
local entity = data.entity
|
||||
function(entity)
|
||||
entity.force = 'neutral'
|
||||
end
|
||||
)
|
||||
@ -155,7 +153,12 @@ local industrial_zone_layers = {
|
||||
type = 'LuaEntity',
|
||||
name = 'scrap',
|
||||
objects = {
|
||||
'crash-site-spaceship-wreck-medium-1'
|
||||
'crash-site-spaceship-wreck-small-1',
|
||||
'crash-site-spaceship-wreck-small-2',
|
||||
'crash-site-spaceship-wreck-small-3',
|
||||
'crash-site-spaceship-wreck-small-4',
|
||||
'crash-site-spaceship-wreck-small-5',
|
||||
'crash-site-spaceship-wreck-small-6'
|
||||
},
|
||||
elevation = 0.5,
|
||||
resolution = 0.1,
|
||||
@ -268,7 +271,6 @@ local function init_game()
|
||||
LayersFunctions.init()
|
||||
Blueprints.init()
|
||||
AIFunctions.init()
|
||||
TimersFunctions.init()
|
||||
ClaimsFunctions.init(MapConfig.claim_markers, MapConfig.claim_max_distance)
|
||||
|
||||
local map = pick_map()
|
||||
@ -296,16 +298,23 @@ local function init_game()
|
||||
LayersFunctions.set_collision_mask({'water-tile'})
|
||||
|
||||
for _, layer in pairs(preset) do
|
||||
local token = Token.register(layer.hook)
|
||||
LayersFunctions.add_noise_layer(layer.type, layer.name, layer.objects, layer.elevation, layer.resolution)
|
||||
if layer.hook ~= nil then
|
||||
LayersFunctions.add_noise_layer_hook(layer.name, token)
|
||||
if layer.hook and type(layer.hook) == 'number' then
|
||||
LayersFunctions.add_noise_layer_hook(layer.name, layer.hook)
|
||||
else
|
||||
local token = Token.register(layer.hook)
|
||||
LayersFunctions.add_noise_layer_hook(layer.name, token)
|
||||
end
|
||||
end
|
||||
|
||||
local token2 = Token.register(layer.deps)
|
||||
|
||||
if layer.deps ~= nil then
|
||||
LayersFunctions.add_noise_layer_dependency(layer.name, token2)
|
||||
if layer.deps and type(layer.deps) == 'number' then
|
||||
LayersFunctions.add_noise_layer_dependency(layer.name, layer.deps)
|
||||
else
|
||||
local token = Token.register(layer.deps)
|
||||
LayersFunctions.add_noise_layer_dependency(layer.name, token)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -917,10 +926,6 @@ local function on_tick()
|
||||
if (game.tick + 1) % 100 == 0 then
|
||||
AfkFunctions.on_inactive_players(90, kill_player)
|
||||
end
|
||||
|
||||
if (game.tick + 1) % 60 == 0 then
|
||||
TimersFunctions.do_job()
|
||||
end
|
||||
end
|
||||
|
||||
local function make_ore_patch(e)
|
||||
@ -946,9 +951,20 @@ local function on_chunk_generated(e)
|
||||
LayersFunctions.push_chunk(e.position)
|
||||
end
|
||||
|
||||
local valid_ents = {
|
||||
['crash-site-spaceship-wreck-small-1'] = true,
|
||||
['crash-site-spaceship-wreck-small-2'] = true,
|
||||
['crash-site-spaceship-wreck-small-3'] = true,
|
||||
['crash-site-spaceship-wreck-small-4'] = true,
|
||||
['crash-site-spaceship-wreck-small-5'] = true,
|
||||
['crash-site-spaceship-wreck-small-6'] = true
|
||||
}
|
||||
|
||||
local function mined_wreckage(e)
|
||||
if e.entity.name ~= 'crash-site-spaceship-wreck-medium-1' then
|
||||
return
|
||||
if e and e.valid then
|
||||
if not valid_ents[e.name] then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local candidates = {}
|
||||
|
@ -46,9 +46,12 @@ public.set_blueprint_hook = function(name, hook)
|
||||
return
|
||||
end
|
||||
|
||||
local token = Token.register(hook)
|
||||
|
||||
this._bps[name].hook = token
|
||||
if hook and type(hook) ~= 'number' then
|
||||
local token = Token.register(hook)
|
||||
this._bps[name].hook = token
|
||||
else
|
||||
this._bps[name].hook = hook
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
|
@ -115,25 +115,8 @@ end
|
||||
|
||||
local function _do_job_entity(surf, layer)
|
||||
local hook = layer.hook
|
||||
if not hook then
|
||||
return
|
||||
end
|
||||
local func = Token.get(hook)
|
||||
if not func then
|
||||
return
|
||||
end
|
||||
func = Token.get(func)
|
||||
if not func then
|
||||
return
|
||||
end
|
||||
local deps = layer.deps
|
||||
if not deps then
|
||||
return
|
||||
end
|
||||
local func2 = Token.get(deps)
|
||||
if not func2 then
|
||||
return
|
||||
end
|
||||
|
||||
for _, object in pairs(layer.cache) do
|
||||
if object.name == 'character' or object.name == 'gun-turret' then
|
||||
if not surf.can_place_entity(object) then
|
||||
@ -147,7 +130,13 @@ local function _do_job_entity(surf, layer)
|
||||
end
|
||||
|
||||
if hook then
|
||||
func(ent, func2)
|
||||
local funcDeps = Token.get(deps)
|
||||
local func = Token.get(hook)
|
||||
if deps == nil then
|
||||
func(ent, deps)
|
||||
else
|
||||
func(ent, funcDeps)
|
||||
end
|
||||
end
|
||||
|
||||
::continue::
|
||||
|
@ -1,108 +0,0 @@
|
||||
local public = {}
|
||||
local Global = require 'utils.global'
|
||||
local Token = require 'utils.token'
|
||||
|
||||
local this = {}
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(tbl)
|
||||
this = tbl
|
||||
end
|
||||
)
|
||||
|
||||
public.init = function()
|
||||
this.timers = {}
|
||||
end
|
||||
|
||||
--[[
|
||||
set_timer - Sets a timer.
|
||||
@param left - Time left on the timer in ticks.
|
||||
@param hook - Action executed after timer is elapsed.
|
||||
--]]
|
||||
public.set_timer = function(left, hook)
|
||||
local id = game.tick
|
||||
local token = Token.register(hook)
|
||||
local token2 = Token.register(left)
|
||||
local entry = {
|
||||
left = token2,
|
||||
hook_finish = token,
|
||||
hook_update = nil,
|
||||
deps = nil,
|
||||
running = false,
|
||||
last_update = 0
|
||||
}
|
||||
|
||||
this.timers[id] = entry
|
||||
return id
|
||||
end
|
||||
|
||||
--[[
|
||||
set_timer_on_update - Adds a hook that is executed everytime a
|
||||
timers is updated.
|
||||
@param id - Id of the timer.
|
||||
@param hook - Hook that will be executed per update.
|
||||
--]]
|
||||
public.set_timer_on_update = function(id, hook)
|
||||
local token = Token.register(hook)
|
||||
this.timers[id].hook_update = token
|
||||
end
|
||||
|
||||
--[[
|
||||
set_timer_dependency - Adds dependency into user callback.
|
||||
@param id - Id of the timer,
|
||||
@param deps - Dependency of timer to add.
|
||||
--]]
|
||||
public.set_timer_dependency = function(id, deps)
|
||||
local token = Token.register(deps)
|
||||
this.timers[id].deps = token
|
||||
end
|
||||
|
||||
--[[
|
||||
set_timer_start - Sets the timer to run.
|
||||
@param id - Id of a timer.
|
||||
--]]
|
||||
public.set_timer_start = function(id)
|
||||
this.timers[id].running = true
|
||||
this.timers[id].last_update = game.tick
|
||||
end
|
||||
|
||||
--[[
|
||||
kill_timer - Effectivly kills the timer.
|
||||
@param id - Timer id.
|
||||
--]]
|
||||
public.kill_timer = function(id)
|
||||
this.timers[id] = nil
|
||||
end
|
||||
|
||||
--[[
|
||||
do_job - Execute timer logic within a tick.
|
||||
--]]
|
||||
public.do_job = function()
|
||||
for id, entry in pairs(this.timers) do
|
||||
if entry.running == false then
|
||||
goto continue
|
||||
end
|
||||
|
||||
entry.left = entry.left - (game.tick - entry.last_update)
|
||||
if entry.left > 0 then
|
||||
entry.last_update = game.tick
|
||||
|
||||
if entry.hook_update ~= nil then
|
||||
if not entry.hook_update(entry.left, entry.deps) then
|
||||
goto premature_finish
|
||||
end
|
||||
end
|
||||
|
||||
goto continue
|
||||
end
|
||||
|
||||
::premature_finish::
|
||||
entry.hook_finish(entry.deps)
|
||||
this.timers[id] = nil
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
return public
|
Loading…
x
Reference in New Issue
Block a user