-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.lua
212 lines (197 loc) · 8.06 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
---------------------------------------------------- Void Chests and Pipes ----------------------------------------------------
function ticker()
if global.ticks == 0 or global.ticks == nil then
global.ticks = 180
if global.chests ~= nil then
processchests()
end
if global.pipes ~= nil then
processpipes()
end
else
global.ticks = global.ticks - 1
end
end
script.on_load(function()
script.on_event(defines.events.on_tick, ticker)
end)
function builtEntity(event)
if event.created_entity.name == "void-chest" then
if global.chests == nil then
global.chests = {}
script.on_event(defines.events.on_tick, ticker)
end
table.insert(global.chests, event.created_entity)
end
if event.created_entity.name == "void-pipe" then
if global.pipes == nil then
global.pipes = {}
script.on_event(defines.events.on_tick, ticker)
end
table.insert(global.pipes, event.created_entity)
end
end
script.on_event(defines.events.on_built_entity, builtEntity)
script.on_event(defines.events.on_robot_built_entity, builtEntity)
function processchests()
for k,chest in pairs(global.chests) do
if chest.valid then
chest.get_inventory(1).clear()
else
table.remove(global.chests, k)
if #global.chests == 0 then
global.chests = nil
end
end
end
end
function processpipes()
for k,pipe in pairs(global.pipes) do
if pipe.valid then
pipe.fluidbox[1] = nil
else
table.remove(global.pipes, k)
if #global.pipes == 0 then
global.pipes = nil
end
end
end
end
-----------------------------------------------------------------------------------------------------------------------
function initPlayer(player)
if not settings.global["start_with_bots"].value then return end
if player.character == nil then return end
if global == nil then
global = {}
end
if global.donePlayers == nil then
global.donePlayers = {}
end
if global.donePlayers[player] ~= nil then return end
global.donePlayers[player] = true
if game.item_prototypes["yi_construction-robot"] then
player.insert{name = "yi_construction-robot", count = 100}
else
player.insert{name = "construction-robot", count = 100}
end
if game.item_prototypes["subspace-item-injector"] then
player.insert{name = "subspace-item-injector", count = 20}
player.insert{name = "subspace-item-extractor", count = 20}
end
player.insert{name = "landfill", count = 10000}
player.insert{name = "cm-waterfill", count = 10000}
local armorInventory = player.get_inventory(defines.inventory.character_armor)
armorInventory.insert("power-armor")
local armorGrid = armorInventory.find_item_stack("power-armor").grid
local equipment = {
"fusion-reactor-equipment",
"exoskeleton-equipment",
"energy-shield-mk2-equipment",
"personal-roboport-mk2-equipment",
"personal-roboport-mk2-equipment",
"battery-mk2-equipment",
"battery-mk2-equipment",
}
for _, v in pairs(equipment) do
armorGrid.put{name = v}
end
player.get_inventory(defines.inventory.character_guns).insert{name = "submachine-gun", count = 1}
player.get_inventory(defines.inventory.character_ammo).insert{name = "piercing-rounds-magazine", count = 200}
end
function onPlayerCreated(event)
local player = game.players[event.player_index]
initPlayer(player)
end
script.on_event({defines.events.on_player_created}, onPlayerCreated)
function onModInit()
if remote.interfaces["freeplay"] then
remote.call("freeplay", "set_disable_crashsite", true)
remote.call("freeplay", "set_skip_intro", true)
end
end
function cm_generate_standardized_ores()
if not settings.global["spawn_standardized_ore_patches"].value then return end
local surface = game.surfaces['nauvis']
local force = game.forces.neutral
local origin_spawn = force.get_spawn_position(surface)
local radius = 130
function sanitize_starting_area()
local oreList = {"coal","angels-ore1","angels-ore2","angels-ore3","angels-ore4","angels-ore5","angels-ore6","crude-oil","uranium-ore","iron-ore","copper-ore","stone","angels-fissure","angels-natural-gas"}
local area = {{-150,-150}, {150,150}}
for i, ore in pairs(oreList) do
for k, entity in pairs (surface.find_entities_filtered{area = area, name = ore}) do
entity.destroy()
end
end
end
sanitize_starting_area()
local cmxoreoffset = 32
local cmyoreoffset = 32
local cmoilx = 0
function cmgenstatingore(cmname, cmsizex, cmsizey)
if cmname == "crude-oil" or cmname == "angels-natural-gas" then
for y=1,cmsizey do
surface.create_entity({name=cmname, amount=settings.global["standardized_ore_oil_amount"].value, position={-radius+cmxoreoffset+1+cmoilx, -radius+cmyoreoffset}})
cmoilx=cmoilx+cmsizex
end
cmyoreoffset = cmsizey+cmyoreoffset+settings.global["standardized_ore_gap"].value
cmoilx = 0
else
for x=0,cmsizex do
for y=0,cmsizey do
surface.create_entity({name=cmname, amount=settings.global["standardized_ore_amount"].value, position={-radius+cmxoreoffset+x, -radius+cmyoreoffset+y}})
end
end
cmyoreoffset = cmsizey+cmyoreoffset+settings.global["standardized_ore_gap"].value
end
end
cmgenstatingore("coal", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
if game.item_prototypes["stone"] then
if game.item_prototypes["angels-ore1"] then
else
cmgenstatingore("stone", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
end
end
if game.item_prototypes["angels-ore1"] then
if settings.global["standardized_ore_double_iron"].value then
cmgenstatingore("angels-ore1", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value*2+2)
else
cmgenstatingore("angels-ore1", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
end
cmgenstatingore("angels-ore3", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
cmgenstatingore("angels-ore6", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
cmgenstatingore("angels-ore5", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
cmgenstatingore("crude-oil", settings.global["standardized_ore_oil_gap"].value, settings.global["standardized_ore_oil_count"].value)
if game.item_prototypes["catalyst-metal-blue"] then
cmgenstatingore("angels-natural-gas", settings.global["standardized_ore_oil_gap"].value, settings.global["standardized_ore_oil_count"].value)
end
elseif game.item_prototypes["y-res1"] then
if settings.global["standardized_ore_double_iron"].value then
cmgenstatingore("iron-ore", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value*2+2)
else
cmgenstatingore("iron-ore", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
end
cmgenstatingore("copper-ore", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
cmgenstatingore("y-res1", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
cmgenstatingore("y-res2", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
cmgenstatingore("crude-oil", settings.global["standardized_ore_oil_gap"].value, settings.global["standardized_ore_oil_count"].value)
else
if settings.global["standardized_ore_double_iron"].value then
cmgenstatingore("iron-ore", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value*2+2)
else
cmgenstatingore("iron-ore", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
end
cmgenstatingore("copper-ore", settings.global["standardized_ore_x"].value, settings.global["standardized_ore_y"].value)
cmgenstatingore("crude-oil", settings.global["standardized_ore_oil_gap"].value, settings.global["standardized_ore_oil_count"].value)
end
end
remote.add_interface("CMod",
{
gen = function()
cm_generate_standardized_ores()
end
})
script.on_init(function()
cm_generate_standardized_ores()
onModInit()
end)