mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-04 09:42:30 +02:00
Made hail_hydra available to all redmew scenarios
This commit is contained in:
parent
dfb49c74b9
commit
fb9e1dba6e
25
config.lua
25
config.lua
@ -156,6 +156,31 @@ global.config = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- spawns more units when one dies
|
||||
hail_hydra = {
|
||||
enabled = false,
|
||||
|
||||
-- any non-rounded number will turn into a chance to spawn an additional alien
|
||||
-- example: 2.5 would spawn 2 for sure and 50% chance to spawn one additionally
|
||||
hydras = {
|
||||
-- spitters
|
||||
['small-spitter'] = {['small-worm-turret'] = 0.2},
|
||||
['medium-spitter'] = {['medium-worm-turret'] = 0.2},
|
||||
['big-spitter'] = {['big-worm-turret'] = 0.2},
|
||||
['behemoth-spitter'] = {['big-worm-turret'] = 0.4},
|
||||
|
||||
-- biters
|
||||
['medium-biter'] = {['small-biter'] = 1.2},
|
||||
['big-biter'] = {['medium-biter'] = 1.2},
|
||||
['behemoth-biter'] = {['big-biter'] = 1.2},
|
||||
|
||||
-- worms
|
||||
['small-worm-turret'] = {['small-biter'] = 2.5},
|
||||
['medium-worm-turret'] = {['small-biter'] = 2.5, ['medium-biter'] = 0.6},
|
||||
['big-worm-turret'] = {['small-biter'] = 3.8, ['medium-biter'] = 1.3, ['big-biter'] = 1.1},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return global.config
|
||||
|
@ -43,6 +43,10 @@ if global.config.performance.enabled then
|
||||
require 'features.performance'
|
||||
end
|
||||
|
||||
if global.config.hail_hydra.enabled then
|
||||
require 'features.hail_hydra'
|
||||
end
|
||||
|
||||
-- GUIs the order determines the order they appear from left to right.
|
||||
-- These can be safely disabled if you want less GUI items.
|
||||
-- Some map presets will add GUI modules themselves.
|
||||
|
81
features/hail_hydra.lua
Normal file
81
features/hail_hydra.lua
Normal file
@ -0,0 +1,81 @@
|
||||
-- Cut off a limb, and two more shall take its place!
|
||||
local Event = require 'utils.event'
|
||||
local CreateParticles = require 'features.create_particles'
|
||||
local random = math.random
|
||||
local floor = math.floor
|
||||
local ceil = math.ceil
|
||||
local compound = defines.command.compound
|
||||
local logical_or = defines.compound_command.logical_or
|
||||
local attack = defines.command.attack
|
||||
local attack_area = defines.command.attack_area
|
||||
|
||||
local HailHydra = {}
|
||||
|
||||
local function create_attack_command(position, target)
|
||||
local command = {type = attack_area, destination = position, radius = 10}
|
||||
if target then
|
||||
command = {type = compound, structure_type = logical_or, commands = {
|
||||
{type = attack, target = target},
|
||||
command,
|
||||
}}
|
||||
end
|
||||
|
||||
return command
|
||||
end
|
||||
|
||||
local config = global.config.hail_hydra
|
||||
local hydras = config.hydras
|
||||
|
||||
Event.add(defines.events.on_entity_died, function (event)
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
|
||||
local hydra = hydras[name]
|
||||
if not hydra then
|
||||
return
|
||||
end
|
||||
|
||||
local position = entity.position
|
||||
local force = entity.force
|
||||
local evolution_factor = force.evolution_factor
|
||||
local cause = event.cause
|
||||
|
||||
local surface = entity.surface
|
||||
local create_entity = surface.create_entity
|
||||
local find_non_colliding_position = surface.find_non_colliding_position
|
||||
|
||||
local command = create_attack_command(position, cause)
|
||||
|
||||
for hydra_spawn, amount in pairs(hydra) do
|
||||
amount = amount + evolution_factor
|
||||
local extra_chance = amount % 1
|
||||
if extra_chance > 0 then
|
||||
if random() <= extra_chance then
|
||||
amount = ceil(amount)
|
||||
else
|
||||
amount = floor(amount)
|
||||
end
|
||||
end
|
||||
local particle_count
|
||||
|
||||
if amount > 4 then
|
||||
particle_count = 60
|
||||
else
|
||||
particle_count = amount * 15
|
||||
end
|
||||
|
||||
CreateParticles.blood_explosion(create_entity, particle_count, position)
|
||||
|
||||
for _ = amount, 1, -1 do
|
||||
position = find_non_colliding_position(hydra_spawn, position, 2, 0.4) or position
|
||||
local spawned = create_entity({name = hydra_spawn, force = force, position = position})
|
||||
if spawned and spawned.type == 'unit' then
|
||||
spawned.set_command(command)
|
||||
elseif spawned and cause then
|
||||
spawned.shooting_target = cause
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return HailHydra
|
@ -46,22 +46,6 @@ end)
|
||||
|
||||
local rocks_to_find = Template.diggy_rocks
|
||||
|
||||
local function create_attack_command(position, target)
|
||||
local command = {type = defines.command.attack_area, destination = position, radius = 10}
|
||||
if target then
|
||||
command = {
|
||||
type = defines.command.compound,
|
||||
structure_type = defines.compound_command.logical_or,
|
||||
commands = {
|
||||
{type = defines.command.attack, target = target},
|
||||
command,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
return command
|
||||
end
|
||||
|
||||
---Triggers mining at the collision_box of the alien, to free it
|
||||
local do_alien_mining = Token.register(function(params)
|
||||
local surface = params.surface
|
||||
@ -170,57 +154,8 @@ function AlienSpawner.register(config)
|
||||
local hail_hydra = config.hail_hydra
|
||||
|
||||
if size(hail_hydra) > 0 then
|
||||
Event.add(defines.events.on_entity_died, function (event)
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
|
||||
local hydras = hail_hydra[name]
|
||||
if not hydras then
|
||||
return
|
||||
end
|
||||
|
||||
local position = entity.position
|
||||
local force = entity.force
|
||||
local evolution_factor = force.evolution_factor
|
||||
local cause = event.cause
|
||||
|
||||
local surface = entity.surface
|
||||
local create_entity = surface.create_entity
|
||||
local find_non_colliding_position = surface.find_non_colliding_position
|
||||
|
||||
local command = create_attack_command(position, cause)
|
||||
|
||||
for hydra_spawn, amount in pairs(hydras) do
|
||||
amount = amount + evolution_factor
|
||||
local extra_chance = amount % 1
|
||||
if extra_chance > 0 then
|
||||
if random() <= extra_chance then
|
||||
amount = ceil(amount)
|
||||
else
|
||||
amount = floor(amount)
|
||||
end
|
||||
end
|
||||
local particle_count
|
||||
|
||||
if amount > 4 then
|
||||
particle_count = 60
|
||||
else
|
||||
particle_count = amount * 15
|
||||
end
|
||||
|
||||
CreateParticles.blood_explosion(create_entity, particle_count, position)
|
||||
|
||||
for _ = amount, 1, -1 do
|
||||
position = find_non_colliding_position(hydra_spawn, position, 2, 0.4) or position
|
||||
local spawned = create_entity({name = hydra_spawn, force = force, position = position})
|
||||
if spawned and spawned.type == 'unit' then
|
||||
spawned.set_command(command)
|
||||
elseif spawned and cause then
|
||||
spawned.shooting_target = cause
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
global.config.hail_hydra.enabled = true
|
||||
global.config.hail_hydra.hydras = hail_hydra
|
||||
end
|
||||
|
||||
Event.add(Template.events.on_void_removed, function (event)
|
||||
|
Loading…
Reference in New Issue
Block a user