-
Notifications
You must be signed in to change notification settings - Fork 29
/
control.lua
143 lines (119 loc) · 4.01 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
require "__pypostprocessing__.lib"
require "scripts.wiki.wiki"
require "scripts.wiki.text-pages"
require "scripts.wiki.spreadsheet-pages"
require "scripts.wiki.statistics-page"
require "scripts.tailings-pond"
require "scripts.beacons"
require "scripts.milestones"
py.on_event(py.events.on_init(), function()
for _, interface in pairs {"silo_script", "better-victory-screen"} do
if remote.interfaces[interface] and remote.interfaces[interface]["set_no_victory"] then
remote.call(interface, "set_no_victory", true)
end
end
if remote.interfaces["freeplay"] then
local created_items = remote.call("freeplay", "get_created_items")
created_items["burner-mining-drill"] = 10
remote.call("freeplay", "set_created_items", created_items)
local debris_items = remote.call("freeplay", "get_debris_items")
debris_items["iron-plate"] = 100
debris_items["copper-plate"] = 50
remote.call("freeplay", "set_debris_items", debris_items)
end
end)
py.on_event(defines.events.on_research_finished, function(event)
if storage.finished then return end
local tech = event.research
if tech.name == "pyrrhic" and game.tick ~= 0 then
local force = tech.force
for _, player in pairs(game.connected_players) do
if player.force == force then player.opened = nil end
end
storage.finished = true
if remote.interfaces["better-victory-screen"] and remote.interfaces["better-victory-screen"]["trigger_victory"] then
remote.call("better-victory-screen", "trigger_victory", force)
else
game.set_game_state {
game_finished = true,
player_won = true,
can_continue = true,
victorious_force = force
}
end
end
end)
py.on_event(py.events.on_built(), function(event)
Beacons.events.on_built(event)
Pond.events.on_built(event)
end)
py.on_event(py.events.on_destroyed(), Beacons.events.on_destroyed)
py.on_event(defines.events.on_entity_died, function(event)
Pond.events.on_entity_died(event)
Beacons.events.on_destroyed(event)
end)
py.on_event(defines.events.on_gui_opened, function(event)
Beacons.events.on_gui_opened(event)
end)
py.on_event({defines.events.on_gui_closed, defines.events.on_player_changed_surface}, function(event)
Wiki.events.on_gui_closed(event)
end)
py.on_event(defines.events.on_player_created, function(event)
Wiki.events.on_player_created(event)
local player = game.players[event.player_index]
if not player.valid then return end
local nauvis = game.surfaces["nauvis"]
if not nauvis then return end
local autoplace = nauvis.map_gen_settings.autoplace_controls
if not script.active_mods["PyBlock"] and autoplace.stone and autoplace.stone.richness <= 1 then
player.print {"messages.warning-no-preset", {"map-gen-preset-name.py-recommended"}}
end
if autoplace["enemy-base"] and autoplace["enemy-base"].size > 0 then
player.print {"messages.warning-biters"}
end
if script.active_mods.quality then
player.print {"messages.warning-quality"}
end
end)
py.register_on_nth_tick(153, "pond153", "pycp", Pond.events[153])
py.register_on_nth_tick(154, "pond154", "pycp", Pond.events[154])
-- grumble grumble filters apply for the whole mod
for _, event in pairs {defines.events.on_built_entity, defines.events.on_robot_built_entity, defines.events.script_raised_built, defines.events.script_raised_revive} do
script.set_event_filter(event, {
{
filter = "type",
type = "inserter",
},
{
filter = "type",
type = "storage-tank",
mode = "or"
},
{
filter = "name",
name = "tailings-pond",
mode = "or"
},
{
filter = "type",
type = "beacon",
mode = "or"
},
})
end
remote.add_interface("pycp", {
---@param func string
execute_on_nth_tick = function(func)
py.mod_nth_tick_funcs[func]()
end
})
-- this is also on_configuration_changed, for reasons
py.on_event(py.events.on_init(), function(changedata)
if not changedata then return end -- on_init, don't care
log(serpent.block(changedata))
local quality = (changedata.mod_changes or {}).quality
if quality and not quality.old_version then
game.print({"messages.warning-quality"})
end
end)
py.finalize_events()