diff --git a/config.lua b/config.lua index e5c4305d..466bca3c 100644 --- a/config.lua +++ b/config.lua @@ -23,13 +23,9 @@ global.config = { -- the number of 'tiles' that are calculated per tick ['tiles_per_tick'] = 32, -- the entity modules to load (takes a list of requires), example included - ['entity_modules'] = { - --function() return require('map_gen.entities.fluffy_rainbows') end - }, + ['entity_modules'] = {}, -- the terrain modules to load (takes a list of requires), example included - ['terrain_modules'] = { - --function() return require('map_gen.terrain.tris_chunk_grid') end - }, + ['terrain_modules'] = {} }, -- redmew_surface allows a map preset to control world generation as well as map and difficulty settings -- the entire module can be toggled or just individual parts @@ -47,7 +43,7 @@ global.config = { -- allows syncing player colors from and to the server. Disable this if you want to enforce custom colors -- when enabled, /color will also be synced to the player settings player_colors = { - enabled = true, + enabled = true }, -- saves players' lives if they have a small-plane in their inventory, also adds the small-plane to the market and must therefor be loaded first train_saviour = { @@ -86,7 +82,6 @@ global.config = { -- enables score and tracking thereof score = { enabled = true, - -- the global score trackers to show global_to_show = { 'satellites-launched', @@ -395,6 +390,16 @@ global.config = { enabled = true, chunk_size = 3, -- size of chunk in tiles corpse_threshold = 3 -- number of corpses allowed on surface inside chunk + }, + turret_active_delay = { + enabled = true, + -- delay for turret type in ticks + turret_types = { + ['ammo-turret'] = 60 * 30, + ['electric-turret'] = 60 * 15, + ['fluid-turret'] = 60 * 20, + ['artillery-turret'] = 60 * 10 + } } } diff --git a/control.lua b/control.lua index 385a2510..2a207d52 100644 --- a/control.lua +++ b/control.lua @@ -100,6 +100,9 @@ end if config.biter_corpse_remover.enabled then require 'features.biter_corpse_remover' end +if config.turret_active_delay.enabled then + require 'features.turret_active_delay' +end -- GUIs -- The order determines the order they appear from left to right. diff --git a/features/turret_active_delay.lua b/features/turret_active_delay.lua new file mode 100644 index 00000000..534112bc --- /dev/null +++ b/features/turret_active_delay.lua @@ -0,0 +1,73 @@ +local Event = require 'utils.event' +local Task = require 'utils.task' +local Token = require 'utils.token' + +local config = require 'config' +turret_types = config.turret_active_delay.turret_types + +local tau = 2 * math.pi +local start_angle = -tau / 4 +local update_rate = 4 -- ticks between updates +local time_to_live = update_rate + 1 + +local draw_arc = rendering.draw_arc +local set_timeout_in_ticks = Task.set_timeout_in_ticks + +local entity_built_callback +entity_built_callback = + Token.register( + function(data) + local entity = data.entity + + if not entity.valid then + return + end + + local tick = data.tick + local now = game.tick + if now >= tick then + entity.active = true + return + end + + local fraction = ((now - tick) / data.delay) + 1 + + draw_arc( + { + color = {1 - fraction, fraction, 0}, + max_radius = 0.5, + min_radius = 0.4, + start_angle = start_angle, + angle = fraction * tau, + target = entity, + surface = entity.surface, + time_to_live = time_to_live + } + ) + + set_timeout_in_ticks(update_rate, entity_built_callback, data) + end +) + +local function entity_built(event) + local entity = event.created_entity + + if not entity.valid then + return + end + + local delay = turret_types[entity.type] + if not delay then + return + end + + entity.active = false + set_timeout_in_ticks( + update_rate, + entity_built_callback, + {entity = entity, tick = event.tick + delay, delay = delay} + ) +end + +Event.add(defines.events.on_built_entity, entity_built) +Event.add(defines.events.on_robot_built_entity, entity_built)