-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.lua
58 lines (47 loc) · 1.67 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require "defines"
require "util"
local inChainReaction = false
function onDeath(event)
local entity = event.entity
if inChainReaction then
return
end
if entity.name == 'stone-rock' then
local maxRadius = 0
local maxCount = 200
-- Check research
for i, player in pairs(game.players) do
if player.force.technologies['exploding-rocks-4'].researched then
maxRadius = 150
maxCount = 1000
elseif player.force.technologies['exploding-rocks-3'].researched then
maxRadius = 80
maxCount = 50
elseif player.force.technologies['exploding-rocks-2'].researched then
maxRadius = 40
maxCount = 30
elseif player.force.technologies['exploding-rocks-1'].researched then
maxRadius = 20
maxCount = 10
end
break
end
if maxRadius = 0 then
return
end
inChainReaction = true
local area
local otherRocks
local radius = maxRadius
repeat
area = {{entity.position.x - radius, entity.position.y - radius}, {entity.position.x + radius, entity.position.y + radius}}
otherRocks = game.get_surface(1).find_entities_filtered({area = area, name='stone-rock'})
radius = radius - 5
until #otherRocks <= maxCount or radius < 5
for k, v in ipairs(otherRocks) do
v.die()
end
inChainReaction = false
end
end
script.on_event(defines.events.on_entity_died, onDeath)