-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.lua
227 lines (194 loc) · 7.21 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
217
218
219
220
221
222
223
224
225
226
227
local Event = require("__stdlib__/stdlib/event/event")
require("src/TaskImpl")
local Board = require("src/Board")
local BoardGenerator = require("src/BoardGenerator")
local BoardGui = require("src/BoardGui") --luacheck:ignore 211
local table = require("__stdlib__/stdlib/utils/table")
local StartingItems = require("src/StartingItems")
local StartingInventory = require("src/StartingInventory")
local string = require('__stdlib__/stdlib/utils/string')
local function set_research(force)
local techs_to_disable =
{
"physical-projectile-damage",
"stronger-explosives",
"refined-flammables",
"energy-weapons-damage",
"weapon-shooting-speed",
"laser-shooting-speed",
"follower-robot-count",
"mining-productivity"
}
force.research_all_technologies()
local tech = force.technologies
for k, name in pairs (techs_to_disable) do
for i = 1, 20 do
local full_name = name.."-"..i
if tech[full_name] then
tech[full_name].researched = false
end
end
end
force.reset_technology_effects()
end
local setup_spectator_force = function()
if game.forces.spectator then return end
local spectator_force = game.create_force("spectator")
local player_force = game.forces.player
spectator_force.set_friend("player", true)
spectator_force.set_cease_fire("player", true)
spectator_force.share_chart = true
player_force.set_cease_fire("spectator", false)
player_force.set_friend("spectator", true)
player_force.share_chart = true
end
local function create_start_settings()
local board_settings = {
mode = "default",
n_rows = 3,
tasks_per_line = {5},
n = 4
}
local preset = settings.global["bingo-start-preset"].value
if preset ~= "unset" then
if preset == "default" then
table.insert(board_settings.tasks_per_line, "gather")
end
if preset == "large" then
table.insert(board_settings.tasks_per_line, "gather")
table.insert(board_settings.tasks_per_line, "restriction")
board_settings.n = 5
end
if preset == "rows-only" then
board_settings.mode = "rows_only"
board_settings.n_rows = 3
end
if preset == "rows-only-large" then
board_settings.mode = "rows_only"
table.insert(board_settings.tasks_per_line, "gather")
table.insert(board_settings.tasks_per_line, "restriction")
board_settings.n = 6
board_settings.n_rows = 4
end
else
if settings.global["bingo-start-rows-only"].value == true then
board_settings.mode = "rows_only"
end
if settings.global["bingo-start-enable-gather-tasks"].value == true then
table.insert(board_settings.tasks_per_line, "gather")
end
if settings.global["bingo-start-enable-restriction-tasks"].value == true then
table.insert(board_settings.tasks_per_line, "restriction")
end
if settings.global["bingo-start-columns-count"].value then
board_settings.n = settings.global["bingo-start-columns-count"].value
end
if settings.global["bingo-start-rows-count"].value then
board_settings.n_rows = settings.global["bingo-start-rows-count"].value
end
end
for i = #board_settings.tasks_per_line, board_settings.n-1 do
table.insert(board_settings.tasks_per_line, 2)
end
return board_settings
end
-- TODO this is temporary. Come up with a better design.
-- Current design: Bingo starts on init, joining players are assigned to the board as active players.
local start_bingo = function()
local start_settings = create_start_settings()
local mode = start_settings.mode
local n_rows = start_settings.n_rows
local tasks_per_line = start_settings.tasks_per_line
local n = start_settings.n
--remote.call("freeplay", "set_disable_crashsite", true)
if not remote.interfaces["freeplay"] then error("The bingo mod only works in freeplay!") end
remote.call("freeplay", "set_skip_intro", true)
remote.call("freeplay", "set_disable_crashsite", true)
remote.call("freeplay", "set_created_items", {
["submachine-gun"] = 1,
["firearm-magazine"] = 40,
["shotgun"] = 1,
["shotgun-shell"] = 20,
["construction-robot"] = 10,
})
remote.call("freeplay", "set_respawn_items", {
["submachine-gun"] = 1,
["firearm-magazine"] = 40,
["shotgun"] = 1,
["shotgun-shell"] = 20,
["construction-robot"] = 10,
})
setup_spectator_force()
set_research(game.forces.player)
StartingItems.create_starting_chest(game.surfaces.nauvis, {x=0, y=0})
local generator_settings = {
seed = game.surfaces["nauvis"].map_gen_settings.seed,
tasks_per_line = tasks_per_line,
mode = mode,
n_rows = n_rows
}
local tasks = BoardGenerator.roll_board(generator_settings)
local players = {}
for _, p in pairs(game.players) do
if p.force.name == "player" and p.connected then
table.insert(players, p)
end
StartingInventory.give_respawn_equipment(p)
end
local bingo_settings = {
task_names = tasks,
n = n,
n_rows = n_rows,
mode = mode,
active_players = players,
}
local board = Board.create(bingo_settings)
global.bingo_board = board
end
Event.on_init(function()
start_bingo()
end)
Event.on_event(defines.events.on_runtime_mod_setting_changed, function(args)
if string.starts_with(args.setting, "bingo-start") and args.player_index then
game.players[args.player_index].print("A bingo mod setting was changed, this has no effect after the board has been started!")
end
end)
Event.on_event(defines.events.on_player_joined_game, function(args) --luacheck: ignore 212
local player = game.players[args.player_index]
if not global.bingo_board then
start_bingo()
end
Board.add_active_player(global.bingo_board, player)
StartingInventory.give_respawn_equipment(player)
end)
Event.on_event(defines.events.on_player_respawned, StartingInventory.on_player_respawned)
--[[
local set_spectator = function(player, followed_player)
if not game.forces.spectator then setup_spectator_force() end
global.is_spectator = global.is_spectator or {}
if global.is_spectator[player.index] then return end
player.force = "spectator"
if player.character then
player.character.destroy()
end
player.set_controller{type=defines.controllers.spectator}
player.spectator = true
player.color = {0,0,0,0}
Board.remove_player_from_all_boards(player, true)
player.tag = "[Spectator]"
-- TODO: set up following
global.is_spectator[player.index] = true
end
--]]
local spectate_help = "Switch to spectator mode. "
for _, s in pairs({"spectate", "spec"}) do
commands.add_command(s, spectate_help, function(args)
local player = game.players[args.player_index]
local name = args.parameter
local followed_player
if name and game.players[name] then
followed_player = game.players[name]
end
set_spectator(player, followed_player)
end)
end