1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-17 21:08:08 +02:00

turret active delay

This commit is contained in:
grilledham 2019-06-19 14:28:40 +01:00
parent ff25cffa80
commit c7f63dcc4f
3 changed files with 89 additions and 8 deletions

View File

@ -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
}
}
}

View File

@ -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.

View File

@ -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)