-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunfrozen.lua
More file actions
100 lines (89 loc) · 2.93 KB
/
unfrozen.lua
File metadata and controls
100 lines (89 loc) · 2.93 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/sc
local prefix = 'unfrozen_'
if storage[prefix] then
error('already running')
end
storage[prefix] = true
local Event = require 'utils.event'
local on_ai_command_completed = 'function(event)
if not event.was_distracted then
return
end
local group = storage.ai_target_destroyed_map[event.unit_number]
if not group or type(group) ~= "userdata" or group.object_name ~= "LuaCommandable" then
return
end
local cmd = group.command
if not cmd or cmd.type ~= defines.command.compound then
return
end
local sacrificial_cmd = {
type = defines.command.wander,
ticks_to_wait = 1,
}
table.insert(cmd.commands, 1, sacrificial_cmd)
group.set_command(cmd)
end'
Event.add_removable_function(
defines.events.on_ai_command_completed,
on_ai_command_completed,
prefix..'on_ai_command_completed'
)
local on_unit_group_finished_gathering = 'function(event)
local _, id, _ = script.register_on_object_destroyed(event.group)
local scenario_will_ignore_this = event.group
storage.ai_target_destroyed_map[id] = scenario_will_ignore_this
end'
Event.add_removable_function(
defines.events.on_unit_group_finished_gathering,
on_unit_group_finished_gathering,
prefix..'on_unit_group_finished_gathering'
)
game.player.print("[color=green]Unfrozen has been installed.[/color]")
local biters = {
"small-biter",
"medium-biter",
"big-biter",
"behemoth-biter",
"small-spitter",
"medium-spitter",
"big-spitter",
"behemoth-spitter",
}
local surface = game.get_surface(storage.bb_surface_name)
local biters = surface.find_entities_filtered{
name = biters,
type = 'unit',
force = {'north_biters', 'north_biters_boss','south_biters', 'south_biters_boss' }
}
for _, biter in pairs(biters) do
local group = biter.commandable.parent_group
if group and not group.command then
local force = (group.force == 'north_biters' or group.force == 'north_biters_boss') and 'north' or 'south'
local silo = storage.rocket_silo[force]
if silo then
local bug_workaround = {
type = defines.command.wander,
radius = 32,
ticks_to_wait = 1,
}
local smooth_path_finding_lag = {
type = defines.command.wander,
radius = 32,
ticks_to_wait = math.random(1, 5 * 60),
}
local attack_silo = {
type = defines.command.attack,
target = silo,
distraction = defines.distraction.by_damage,
}
local chain = { bug_workaround, smooth_path_finding_lag, bug_workaround, attack_silo }
group.set_command{
type = defines.command.compound,
structure_type = defines.compound_command.return_last,
commands = chain,
}
group.start_moving()
end
end
end