-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.lua
216 lines (184 loc) · 9.65 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
local calculate_flammabilities = require("lua/calc_flammability")
local flammability_manager = require("lua/flammability_manager")
local on_belt_fire = require("lua/belt_fire")
local on_container_fire = require("lua/container_fire")
local on_tank_fire = require("lua/fluid_tank_fire")
local init_ground_item_fire_events = require("lua/ground_item_fire")
local gui = require("lua/gui")
local function load_flammables()
flammability_manager.add_root_element("water")
flammability_manager.add_root_element("stone")
flammability_manager.add_root_element("iron-ore")
flammability_manager.add_root_element("copper-ore")
flammability_manager.add_root_element("uranium-ore")
flammability_manager.add_flammable_item("wood", false, 30, 2, false, nil, 0, true)
flammability_manager.add_flammable_item("coal", false, 15, 7, false, nil, 0, true)
flammability_manager.add_flammable_item("solid-fuel", false, 10, 10, false, nil, 0)
flammability_manager.add_flammable_item("rocket-fuel", true, 10, 15, false, "maticzplars-rocket-fuel-explosion", 1)
flammability_manager.add_flammable_item("flamethrower-ammo", true, 10, 16, false, "maticzplars-rocket-fuel-explosion", 0.5)
flammability_manager.add_flammable_item("grenade", false, 15, 2, false, "grenade-explosion", 3)
flammability_manager.add_flammable_item("cluster-grenade", false, 15, 2, false, "grenade-explosion", 3)
flammability_manager.add_flammable_item("firearm-magazine", false, 5, 2, false, "maticzplars-damage-explosion", 0.2)
flammability_manager.add_flammable_item("piercing-rounds-magazine", false, 5, 3, false, "maticzplars-damage-explosion", 0.3)
flammability_manager.add_flammable_item("uranium-rounds-magazine", false, 5, 4, false, "maticzplars-damage-explosion", 0.4)
flammability_manager.add_flammable_item("rocket", false, 10, 10, false, "maticzplars-damage-explosion", 0.4)
flammability_manager.add_flammable_item("explosive-rocket", false, 10, 7, false, "maticzplars-damage-explosion", 0.7)
flammability_manager.add_flammable_item("cannon-shell", false, 10, 7, false, "maticzplars-damage-explosion", 0.6)
flammability_manager.add_flammable_item("explosive-cannon-shell", false, 10, 7, false, "maticzplars-damage-explosion", 1)
flammability_manager.add_flammable_item("uranium-cannon-shell", false, 10, 7, false, "maticzplars-damage-explosion", 1)
flammability_manager.add_flammable_item("explosive-uranium-cannon-shell", false, 10, 7, false, "maticzplars-damage-explosion", 1.4)
flammability_manager.add_flammable_item("shotgun-shell", false, 5, 2, false, "maticzplars-damage-explosion", 0.2)
flammability_manager.add_flammable_item("piercing-shotgun-shell", false, 5, 3, false, "maticzplars-damage-explosion", 0.3)
flammability_manager.add_flammable_item("explosives", false, 5, 20, false, "maticzplars-dynamite-explosion", 3)
flammability_manager.add_flammable_fluid("crude-oil", true, 20, 6, false, "maticzplars-rocket-fuel-explosion", 0.5, true)
flammability_manager.add_flammable_fluid("light-oil", true, 10, 10, false, "maticzplars-rocket-fuel-explosion", 0.6)
flammability_manager.add_flammable_fluid("heavy-oil", true, 10, 10, false, "maticzplars-rocket-fuel-explosion", 0.6)
flammability_manager.add_flammable_fluid("petroleum-gas", true, 5, 10, false, "maticzplars-rocket-fuel-explosion", 0.7)
---@type FlammabilityEdit
local dont_burn = { strength = 0 }
---@type FlammabilityEdit
local dont_burn_children = { dont_affect_products = true }
flammability_manager.make_edit("plastic-bar", dont_burn_children)
flammability_manager.make_edit("lubricant", dont_burn)
flammability_manager.make_edit("sulfuric-acid", dont_burn)
flammability_manager.make_edit("steel", dont_burn)
flammability_manager.make_edit("barrel", dont_burn)
flammability_manager.make_edit("rocket-part", dont_burn)
flammability_manager.make_edit("sulfur", { explosion_radius = 0 })
-- Space Age
flammability_manager.make_edit("superconductor", dont_burn)
flammability_manager.make_edit("tungsten-carbide", dont_burn)
flammability_manager.make_edit("carbon-fiber", dont_burn_children)
flammability_manager.make_edit("fluoroketone-cold", dont_burn)
flammability_manager.make_edit("electrolyte", dont_burn)
for name, _ in pairs(prototypes.get_item_filtered({{filter = "subgroup", subgroup = "science-pack" }})) do
flammability_manager.make_edit(name, dont_burn)
end
calculate_flammabilities()
end
function init_storage()
storage.flammable = storage.flammable or {}
storage.fluids = storage.fluids or {}
storage.edits = storage.edits or {}
storage.graph = storage.graph or {}
storage.last_tick = storage.last_tick or 0
storage.invocations = storage.invocations or 0
end
script.on_init(function ()
init_storage()
load_flammables()
end)
script.on_configuration_changed(function ()
init_storage()
load_flammables()
end)
script.on_event(defines.events.on_player_joined_game, gui.add_mod_button)
script.on_event(defines.events.on_player_promoted, gui.add_mod_button)
script.on_event(defines.events.on_player_demoted, gui.add_mod_button)
script.on_event(defines.events.on_entity_damaged,
--- @param event EventData.on_entity_damaged
function (event)
if event.tick > storage.last_tick then
storage.invocations = storage.invocations + 1
if storage.invocations > 15 then
storage.last_tick = event.tick
storage.invocations = 0
end
if event.entity.get_inventory(defines.inventory.chest) or
event.entity.get_inventory(defines.inventory.cargo_wagon) or
event.entity.get_inventory(defines.inventory.car_trunk) then
on_container_fire(event)
elseif event.entity.type == "fluid-wagon" or event.entity.type == "storage-tank" then
on_tank_fire(event)
else
on_belt_fire(event)
end
end
end,
{
{filter = "damage-type", type = "fire"},
--- @diagnostic disable-next-line missing-fields
{filter = "transport-belt-connectable", mode="and"},
{filter = "damage-type", type = "fire"},
{filter = "type", type="container", mode="and"},
{filter = "damage-type", type = "fire"},
{filter = "type", type="logistic-container", mode="and"},
{filter = "damage-type", type = "fire"},
{filter = "type", type="cargo-wagon", mode="and"},
{filter = "damage-type", type = "fire"},
{filter = "type", type="fluid-wagon", mode="and"},
{filter = "damage-type", type = "fire"},
{filter = "type", type="storage-tank", mode="and"},
}
)
script.on_event(
defines.events.on_entity_died,
--- @param event EventData.on_entity_died
function (event)
if math.random(0, 100) < settings.global["maticzplars-pole-fire"].value then
local has_power = false
for _, v in pairs(event.entity.electric_network_statistics.output_counts) do
if v > 0.0 then
has_power = true
end
end
if has_power then
--- @diagnostic disable-next-line missing-fields
event.entity.surface.create_entity({
name="fire-flame",
position=event.entity.position,
initial_ground_flame_count=5
})
end
end
end,
{
{filter = "type", type = "electric-pole"},
}
)
remote.add_interface("maticzplars-flammables", {
---@param name string
---@param fire_strength int
---@param fire_spread_cooldown int
---@param make_fireball boolean
---@param explosion_radius double
---@param explosion_prototype string?
---@param raw_resource boolean? Should be true if the item cannot be crafted from simpler items. This is used to prevent flammability calculations from using recipies for recyclers, crushers or anything else that might go from a more complex item to a less complex one.
add_item = function (name, fire_strength, fire_spread_cooldown, make_fireball, explosion_radius, explosion_prototype, raw_resource)
flammability_manager.add_flammable_item(
name,
make_fireball,
fire_spread_cooldown,
fire_strength,
false,
explosion_prototype or "maticzplars-rocket-fuel-explosion",
explosion_radius,
raw_resource or false
)
end,
---@param name string
---@param fire_strength int
---@param fire_spread_cooldown int
---@param make_fireball boolean
---@param explosion_radius double
---@param explosion_prototype string?
---@param raw_resource boolean?
add_fluid = function (name, fire_strength, fire_spread_cooldown, make_fireball, explosion_radius, explosion_prototype, raw_resource)
flammability_manager.add_flammable_fluid(
name,
make_fireball,
fire_spread_cooldown,
fire_strength,
false,
explosion_prototype or "maticzplars-rocket-fuel-explosion",
explosion_radius,
raw_resource or false
)
end,
-- TODO: check this ignore param if needed and stuff
---@param ignore string?
recalculate_flammables = function (ignore)
calculate_flammabilities()
end
})
init_ground_item_fire_events()