mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
Recommended Diggy bot mining update for Factorio .18.27 (#1064)
* Recommended Diggy bot mining update for Factorio .18.27 * Resolve conflicts in this PR with diggy_hole.lua in PR 1061 * Include recent updates made to diggy_hole.lua in PR 1061 * Mining delay and particle tweaks
This commit is contained in:
parent
3e08ea6b6c
commit
dbdd241c86
@ -56,8 +56,10 @@ local Config = {
|
|||||||
-- core feature
|
-- core feature
|
||||||
diggy_hole = {
|
diggy_hole = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
-- initial damage per tick it damages a rock to mine, can be enhanced by robot_damage_per_mining_prod_level
|
-- delay in ticks between robot mining rock and rock being marked again for deconstruction
|
||||||
robot_initial_mining_damage = 4,
|
robot_mining_delay = 6,
|
||||||
|
-- This value is multiplied with robot_mining_delay to determine mining damage applied. Can be enhanced by robot_damage_per_mining_prod_level
|
||||||
|
robot_per_tick_damage = 4,
|
||||||
-- damage added per level of mining productivity level research
|
-- damage added per level of mining productivity level research
|
||||||
robot_damage_per_mining_prod_level = 1,
|
robot_damage_per_mining_prod_level = 1,
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@ local ScoreTracker = require 'utils.score_tracker'
|
|||||||
local Command = require 'utils.command'
|
local Command = require 'utils.command'
|
||||||
local CreateParticles = require 'features.create_particles'
|
local CreateParticles = require 'features.create_particles'
|
||||||
local Ranks = require 'resources.ranks'
|
local Ranks = require 'resources.ranks'
|
||||||
|
local Token = require 'utils.token'
|
||||||
|
local Task = require 'utils.task'
|
||||||
|
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||||
local random = math.random
|
local random = math.random
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
@ -19,6 +22,7 @@ local destroy_rock = CreateParticles.destroy_rock
|
|||||||
local mine_rock = CreateParticles.mine_rock
|
local mine_rock = CreateParticles.mine_rock
|
||||||
local raise_event = script.raise_event
|
local raise_event = script.raise_event
|
||||||
local mine_size_name = 'mine-size'
|
local mine_size_name = 'mine-size'
|
||||||
|
local ceil = math.ceil
|
||||||
|
|
||||||
-- this
|
-- this
|
||||||
local DiggyHole = {}
|
local DiggyHole = {}
|
||||||
@ -32,8 +36,27 @@ local robot_mining = {
|
|||||||
damage = 0,
|
damage = 0,
|
||||||
active_modifier = 0,
|
active_modifier = 0,
|
||||||
research_modifier = 0,
|
research_modifier = 0,
|
||||||
|
delay = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Used in conjunction with set_timeout_in_ticks(robot_mining_delay... to control bot mining frequency
|
||||||
|
-- Robot_mining.damage is equal to robot_mining_delay * robot_per_tick_damage
|
||||||
|
-- So for example if robot_mining delay is doubled, robot_mining.damage gets doubled to compensate.
|
||||||
|
local metered_bot_mining = Token.register(function(params)
|
||||||
|
local entity = params.entity
|
||||||
|
local force = params.force
|
||||||
|
local health_update = params.health_update
|
||||||
|
if entity.valid then
|
||||||
|
local health = entity.health
|
||||||
|
--If health of entity didn't change during delay apply bot mining damage and re-order order_deconstruction
|
||||||
|
--If rock was damaged during the delay the bot gets scared off and stops mining this particular rock.
|
||||||
|
if health_update == health - robot_mining.damage then
|
||||||
|
entity.health = health_update
|
||||||
|
entity.order_deconstruction(force)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
Global.register({
|
Global.register({
|
||||||
full_inventory_mining_cache = full_inventory_mining_cache,
|
full_inventory_mining_cache = full_inventory_mining_cache,
|
||||||
bot_mining_damage = robot_mining,
|
bot_mining_damage = robot_mining,
|
||||||
@ -156,7 +179,8 @@ function DiggyHole.register(cfg)
|
|||||||
global_to_show[#global_to_show + 1] = mine_size_name
|
global_to_show[#global_to_show + 1] = mine_size_name
|
||||||
|
|
||||||
config = cfg
|
config = cfg
|
||||||
robot_mining.damage = cfg.robot_initial_mining_damage
|
robot_mining.delay = cfg.robot_mining_delay
|
||||||
|
robot_mining.damage = cfg.robot_per_tick_damage * robot_mining.delay
|
||||||
|
|
||||||
Event.add(defines.events.on_entity_died, function (event)
|
Event.add(defines.events.on_entity_died, function (event)
|
||||||
local entity = event.entity
|
local entity = event.entity
|
||||||
@ -207,7 +231,7 @@ function DiggyHole.register(cfg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local health = entity.health
|
local health = entity.health
|
||||||
health = health - robot_mining.damage
|
local health_update = health - robot_mining.damage
|
||||||
event.buffer.clear()
|
event.buffer.clear()
|
||||||
|
|
||||||
local graphics_variation = entity.graphics_variation
|
local graphics_variation = entity.graphics_variation
|
||||||
@ -215,18 +239,21 @@ function DiggyHole.register(cfg)
|
|||||||
local create_particle = entity.surface.create_particle
|
local create_particle = entity.surface.create_particle
|
||||||
local position = entity.position
|
local position = entity.position
|
||||||
local force = event.robot.force
|
local force = event.robot.force
|
||||||
|
local delay = robot_mining.delay
|
||||||
|
|
||||||
if health < 1 then
|
if health_update < 1 then
|
||||||
entity.die(force)
|
entity.die(force)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
entity.destroy()
|
entity.destroy()
|
||||||
|
|
||||||
local rock = create_entity({name = name, position = position})
|
local rock = create_entity({name = name, position = position})
|
||||||
mine_rock(create_particle, 1, position)
|
mine_rock(create_particle, ceil(delay / 2), position)
|
||||||
rock.graphics_variation = graphics_variation
|
rock.graphics_variation = graphics_variation
|
||||||
rock.order_deconstruction(force)
|
|
||||||
rock.health = health
|
rock.health = health
|
||||||
|
--Mark replaced rock for de-construction and apply health_update after delay. Health verified and
|
||||||
|
--update applied after delay to help prevent more rapid damage if someone were to spam deconstruction blueprints
|
||||||
|
set_timeout_in_ticks(delay, metered_bot_mining, {entity = rock, force = force, health_update = health_update})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Event.add(defines.events.on_player_mined_entity, function (event)
|
Event.add(defines.events.on_player_mined_entity, function (event)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user