forked from Crimso777/Factorio-Access
-
Notifications
You must be signed in to change notification settings - Fork 9
/
data-updates.lua
159 lines (134 loc) · 5.6 KB
/
data-updates.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
local Consts = require("scripts.consts")
local DataToRuntimeMap = require("scripts.data-to-runtime-map")
for name, proto in pairs(data.raw.container) do
proto.open_sound = proto.open_sound or { filename = "__base__/sound/metallic-chest-open.ogg", volume = 0.43 }
proto.close_sound = proto.close_sound or { filename = "__base__/sound/metallic-chest-close.ogg", volume = 0.43 }
end
---Apply universal belt immunity
data.raw.character.character.has_belt_immunity = true
---Make the character unlikely to be selected by the mouse pointer when overlapping with entities
data.raw.character.character.selection_priority = 2
for _, item in pairs(vanilla_tip_and_tricks_item_table) do
remove_tip_and_tricks_item(item)
end
-- Modifications to Kruise Kontrol inputs (no longer needed)
-- We will handle Kruise Kontrol driving through the remote API. It binds
-- everything to the mouse, which we don't use. The exception is enter, which
-- cancels. We also cancel on enter, but double-cancel doesn't do anything.
-- This file used to modify those inputs, but we don't need to since things
-- already work. If we do need to revisit that, note that we will need to move
-- KK inputs to a dummy key, or alternatively try setting [alt]_key_sequence to
-- the empty string. Other solutions (e.g. removal, setting them to disabled)
-- break KK because Factorio will not let KK register events.
--Modifications to Pavement Driving Assist Continued inputs
data:extend({
{
type = "custom-input",
name = "toggle_drive_assistant",
key_sequence = "L",
consuming = "game-only",
},
{
type = "custom-input",
name = "toggle_cruise_control",
key_sequence = "O",
consuming = "game-only",
},
{
type = "custom-input",
name = "set_cruise_control_limit",
key_sequence = "CONTROL + O",
consuming = "game-only",
},
{
type = "custom-input",
name = "confirm_set_cruise_control_limit",
key_sequence = "",
linked_game_control = "confirm-gui",
},
})
--Modify base prototypes to remove their default descriptions
for name, pack in pairs(data.raw.tool) do
if pack.localised_description and pack.localised_description[1] == "item-description.science-pack" then
pack.localised_description = nil
end
end
for name, mod in pairs(data.raw.module) do
if
mod.localised_description and mod.localised_description[1] == "item-description.effectivity-module"
or mod.localised_description and mod.localised_description[1] == "item-description.productivity-module"
or mod.localised_description and mod.localised_description[1] == "item-description.speed-module"
then
mod.localised_description = nil
end
end
---Make selected vanilla objects not collide with players
local function remove_player_collision(ent_p)
local new_mask = {}
for _, layer in pairs(ent_p.collision_mask or { "object-layer", "floor-layer", "water-tile" }) do
if layer ~= "player-layer" then table.insert(new_mask, layer) end
end
ent_p.collision_mask = new_mask
end
for _, ent_type in pairs({ "pipe", "pipe-to-ground", "constant-combinator", "inserter" }) do
for _, ent_p in pairs(data.raw[ent_type]) do
remove_player_collision(ent_p)
end
end
--TODO:should probably just filter electric poles by their collision_box size...
remove_player_collision(data.raw["electric-pole"]["small-electric-pole"])
remove_player_collision(data.raw["electric-pole"]["medium-electric-pole"])
--[[
We will now inject a trigger on entity creation, which will send control.lua an
event on the creation of any map-placed entity. This is slow, and it should
also be possible to tone it back in future if that ever becomes problematic. The
purpose is being able to scan efficiently, rather than trying to scan surfaces
every time we get a request. See scripts.scanner.entrypoint.
A trigger is either a single trigger or an array of triggers. To be compatible
with other mods, we convert these to arrays, then tack ours on at the end.
]]
local function augment_with_trigger(proto)
-- our trigger.
---@type data.Trigger
local nt = {
type = "direct",
action_delivery = {
type = "instant",
source_effects = {
type = "script",
effect_id = Consts.NEW_ENTITY_SUBSCRIBER_TRIGGER_ID,
},
},
}
if not proto.created_effect then
proto.created_effect = {}
elseif not proto.created_effect[1] then
-- This is how we ask lua if something is an array.
proto.created_effect = { proto.created_effect }
end
table.insert(proto.created_effect, nt)
end
for ty, children in pairs(data.raw) do
if not defines.prototypes.entity[ty] then goto continue end
for _name, proto in pairs(children) do
augment_with_trigger(proto)
end
::continue::
end
--[[
See https://forums.factorio.com/viewtopic.php?f=28&t=114820
We need resource_patch_search_radius to write the scanner algorithm, though
hopefully in future we can just ask the engine. The problem of today is that we
don't have it at runtime. We therefore make a dummy item, and smuggle it
across in the localised_description. The format is:
prototype-name=5
other-prototype-name=10
So on. Parsed back out in scripts.scanner.resource-patches.lua.
If nil we just don't write anything after the =.
]]
local resource_search_radiuses = {}
for name, proto in pairs(data.raw["resource"]) do
if proto.type == "resource" then resource_search_radiuses[name] = proto.resource_patch_search_radius or 3 end
end
local DataToRuntimeMap = require("scripts.data-to-runtime-map")
DataToRuntimeMap.build(Consts.RESOURCE_SEARCH_RADIUSES_MAP_NAME, resource_search_radiuses)