1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-04 00:15:45 +02:00
ComfyFactorio/modules/trees_randomly_die.lua

117 lines
3.0 KiB
Lua
Raw Normal View History

2019-08-12 14:34:16 +02:00
-- trees get randomly hit by lightning strikes -- mewmew
2021-03-24 21:14:55 +02:00
local Event = require 'utils.event'
2020-05-16 12:37:05 +02:00
local Difficulty = require 'modules.difficulty_vote'
2019-08-12 14:34:16 +02:00
local math_random = math.random
2019-08-14 16:16:42 +02:00
local difficulties_votes = {
2020-05-16 12:37:05 +02:00
[1] = 128,
[2] = 64,
[3] = 32,
[4] = 16,
[5] = 8,
[6] = 4,
[7] = 2
2019-08-14 16:16:42 +02:00
}
2019-08-12 14:34:16 +02:00
local function create_particles(surface, name, position, amount)
2020-05-16 12:37:05 +02:00
local Diff = Difficulty.get()
local direction_mod = (-100 + math_random(0, 200)) * 0.0005
local direction_mod_2 = (-100 + math_random(0, 200)) * 0.0005
for i = 1, amount, 1 do
local m = math_random(12, 18)
local m2 = m * 0.005
surface.create_particle(
{
name = name,
position = position,
frame_speed = 1,
vertical_speed = 0.130,
height = 0,
movement = {
(m2 - (math_random(0, m) * 0.01)) + direction_mod,
(m2 - (math_random(0, m) * 0.01)) + direction_mod_2
}
}
)
end
surface.create_entity(
{
name = 'electric-beam',
2020-05-16 12:37:05 +02:00
position = {x = position.x, y = position.y},
source = {x = (position.x - 3) + math.random(0, 6), y = position.y - math.random(2, 4)},
target = {x = position.x, y = position.y},
duration = 30
2020-05-16 12:37:05 +02:00
}
)
surface.create_entity(
{
name = 'fire-flame',
position = {x = position.x, y = position.y}
}
)
local r = 8
if Diff.difficulty_vote_index then
r = difficulties_votes[Diff.difficulty_vote_index]
end
if math_random(1, r) == 1 then
surface.create_entity(
{
name = 'explosive-cannon-projectile',
position = position,
force = 'enemy',
source = position,
target = position,
max_range = 1,
speed = 1
}
)
end
2019-08-12 14:34:16 +02:00
end
local r = 128
2021-03-24 21:14:55 +02:00
local function get_random_area()
2020-05-16 12:37:05 +02:00
local p = game.players[math_random(1, #game.players)].position
if not p then
return
end
local area = {{p.x - r, p.y - r}, {p.x + r, p.y + r}}
return area
2019-08-12 14:34:16 +02:00
end
local function kill_random_tree(surface)
2020-05-16 12:37:05 +02:00
local trees = surface.find_entities_filtered({type = 'tree', area = get_random_area(surface)})
if not trees[1] then
return false
end
local tree = trees[math_random(1, #trees)]
create_particles(surface, 'wooden-particle', tree.position, 320)
tree.die()
return true
2019-08-12 14:34:16 +02:00
end
2020-05-16 12:37:05 +02:00
local function tick()
local Diff = Difficulty.get()
2021-03-24 21:14:55 +02:00
r = 48
2020-05-16 12:37:05 +02:00
if Diff.difficulty_vote_index then
r = difficulties_votes[Diff.difficulty_vote_index]
end
if math_random(1, r) ~= 1 then
return
end
local surface = game.players[1].surface
2021-03-24 21:14:55 +02:00
for _ = 1, 8, 1 do
2020-05-16 12:37:05 +02:00
if kill_random_tree(surface) then
return
end
end
2019-08-12 14:34:16 +02:00
end
2021-03-24 21:14:55 +02:00
Event.on_nth_tick(60, tick)