-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.lua
More file actions
40 lines (35 loc) · 1.49 KB
/
Copy pathcontrol.lua
File metadata and controls
40 lines (35 loc) · 1.49 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
-- Maps an ore to its coresponding mod setting
local resource_setting_map = {
["coal"] = "refill-coal" ,
["iron-ore"] = "refill-iron" ,
["copper-ore"] = "refill-copper" ,
["stone"] = "refill-stone" ,
["uranium-ore"] = "refill-uranium" ,
["calcite"] = "refill-calcite" ,
["tungsten-ore"] = "refill-tungsten",
["scrap"] = "refill-scrap" ,
["lithium-brine"] = "refill-lithium"
}
local function is_setting_enabled(setting_name)
local mod_setting = settings.global[setting_name]
return mod_setting and mod_setting.value
end
-- Called each time an ore patch runs out
local function refill_ore(event)
-- Checks which ore ran out and if the corresponding setting is enabled
local setting = resource_setting_map[event.entity.name]
-- Falls back to the modded ores setting for unknown ores, or when this
-- ore's own setting isn't registered (e.g. a space age ore added to a
-- base game by another mod)
if setting == nil or settings.global[setting] == nil then
setting = "refill-modded-ores"
end
if not is_setting_enabled(setting) then
return
end
-- Increases the amount that ores are refilled to to prevent tiny ore patches from firing too many events
storage.refill_amount = storage.refill_amount and storage.refill_amount + 1 or 1
-- Refills the ore
event.entity.amount = storage.refill_amount
end
script.on_event(defines.events.on_resource_depleted, refill_ore);