1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2026-06-20 16:32:28 +02:00
This commit is contained in:
Gerkiz
2020-10-22 13:32:18 +02:00
parent 30fdb4b8ad
commit c2a33b08e0
5 changed files with 133 additions and 91 deletions
+45 -40
View File
@@ -267,23 +267,28 @@ commands.add_command(
for k, v in pairs(game.connected_players) do
v.cheat_mode = true
v.insert {name = 'power-armor-mk2', count = 1}
if v.character ~= nil then
if v.get_inventory(defines.inventory.character_armor) then
v.get_inventory(defines.inventory.character_armor).clear()
end
v.insert {name = 'power-armor-mk2', count = 1}
local p_armor = v.get_inventory(5)[1].grid
p_armor.put({name = 'fusion-reactor-equipment'})
p_armor.put({name = 'fusion-reactor-equipment'})
p_armor.put({name = 'fusion-reactor-equipment'})
p_armor.put({name = 'exoskeleton-equipment'})
p_armor.put({name = 'exoskeleton-equipment'})
p_armor.put({name = 'exoskeleton-equipment'})
p_armor.put({name = 'energy-shield-mk2-equipment'})
p_armor.put({name = 'energy-shield-mk2-equipment'})
p_armor.put({name = 'energy-shield-mk2-equipment'})
p_armor.put({name = 'energy-shield-mk2-equipment'})
p_armor.put({name = 'personal-roboport-mk2-equipment'})
p_armor.put({name = 'night-vision-equipment'})
p_armor.put({name = 'battery-mk2-equipment'})
p_armor.put({name = 'battery-mk2-equipment'})
if p_armor and p_armor.valid then
p_armor.put({name = 'fusion-reactor-equipment'})
p_armor.put({name = 'fusion-reactor-equipment'})
p_armor.put({name = 'fusion-reactor-equipment'})
p_armor.put({name = 'exoskeleton-equipment'})
p_armor.put({name = 'exoskeleton-equipment'})
p_armor.put({name = 'exoskeleton-equipment'})
p_armor.put({name = 'energy-shield-mk2-equipment'})
p_armor.put({name = 'energy-shield-mk2-equipment'})
p_armor.put({name = 'energy-shield-mk2-equipment'})
p_armor.put({name = 'energy-shield-mk2-equipment'})
p_armor.put({name = 'personal-roboport-mk2-equipment'})
p_armor.put({name = 'night-vision-equipment'})
p_armor.put({name = 'battery-mk2-equipment'})
p_armor.put({name = 'battery-mk2-equipment'})
end
local item = game.item_prototypes
local i = 0
for _k, _v in pairs(item) do
@@ -319,33 +324,33 @@ commands.add_command(
end
end
local forces = {}
for _, force in pairs(game.forces) do
if force.index == 1 or force.index > 3 then
table.insert(forces, force)
end
end
local forces = {}
for _, force in pairs(game.forces) do
if force.index == 1 or force.index > 3 then
table.insert(forces, force)
end
end
local is_charted
local count = 0
local is_charted
local count = 0
for _, surface in pairs(game.surfaces) do
for chunk in surface.get_chunks() do
is_charted = false
for _, force in pairs(forces) do
if force.is_chunk_charted(surface, {chunk.x, chunk.y}) then
is_charted = true
break
end
end
if not is_charted then
surface.delete_chunk({chunk.x, chunk.y})
count = count + 1
end
end
end
local message = player.name .. " deleted " .. count .. " uncharted chunks!"
game.print(message, Color.warning)
for chunk in surface.get_chunks() do
is_charted = false
for _, force in pairs(forces) do
if force.is_chunk_charted(surface, {chunk.x, chunk.y}) then
is_charted = true
break
end
end
if not is_charted then
surface.delete_chunk({chunk.x, chunk.y})
count = count + 1
end
end
end
local message = player.name .. ' deleted ' .. count .. ' uncharted chunks!'
game.print(message, Color.warning)
Server.to_discord_bold(table.concat {message})
end
)
+1 -1
View File
@@ -377,7 +377,7 @@ function Public.reset_map()
wave_defense_table.spawn_position = {x = 0, y = 100}
WD.alert_boss_wave(true)
WD.clear_corpses(false)
WD.remove_entities(false)
WD.remove_entities(true)
WD.enable_threat_log(true)
WD.check_collapse_position(true)
+18 -2
View File
@@ -47,6 +47,21 @@ local function debug_print(msg)
print('WaveDefense: ' .. msg)
end
local function is_closer(pos1, pos2, pos)
return ((pos1.x - pos.x) ^ 2 + (pos1.y - pos.y) ^ 2) < ((pos2.x - pos.x) ^ 2 + (pos2.y - pos.y) ^ 2)
end
local function shuffle_distance(tbl, position)
local size = #tbl
for i = size, 1, -1 do
local rand = math_random(size)
if is_closer(tbl[i].position, tbl[rand].position, position) and i > rand then
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
end
return tbl
end
local function remove_trees(entity)
local surface = entity.surface
local radius = 10
@@ -478,9 +493,10 @@ local function get_commmands(group)
position = old_position,
radius = step_length / 2,
type = {'simple-entity', 'tree'},
limit = 1
limit = 50
}
if obstacles then
shuffle_distance(obstacles, old_position)
for i = 1, #obstacles, 1 do
if obstacles[i].valid then
commands[#commands + 1] = {
@@ -539,7 +555,7 @@ local function command_unit_group(group)
group.set_command(
{
type = defines.command.compound,
structure_type = defines.compound_command.logical_and,
structure_type = defines.compound_command.return_last,
commands = get_commmands(group)
}
)
+68 -47
View File
@@ -1,69 +1,90 @@
local WD = require "modules.wave_defense.table"
local WD = require 'modules.wave_defense.table'
local Public = {}
local side_target_types = {
["accumulator"] = true,
["assembling-machine"] = true,
["boiler"] = true,
["furnace"] = true,
["generator"] = true,
["lab"] = true,
["lamp"] = true,
["mining-drill"] = true,
["power-switch"] = true,
["radar"] = true,
["reactor"] = true,
["roboport"] = true,
["rocket-silo"] = true,
["solar-panel"] = true,
['accumulator'] = true,
['assembling-machine'] = true,
['boiler'] = true,
['furnace'] = true,
['generator'] = true,
['lab'] = true,
['lamp'] = true,
['mining-drill'] = true,
['power-switch'] = true,
['radar'] = true,
['reactor'] = true,
['roboport'] = true,
['rocket-silo'] = true,
['solar-panel'] = true
}
local function get_random_target(wave_defense_table)
local r = math.random(1, wave_defense_table.side_target_count)
if not wave_defense_table.side_targets[r] then
table.remove(wave_defense_table.side_targets, r)
wave_defense_table.side_target_count = wave_defense_table.side_target_count - 1
return
end
if not wave_defense_table.side_targets[r].valid then
table.remove(wave_defense_table.side_targets, r)
wave_defense_table.side_target_count = wave_defense_table.side_target_count - 1
return
end
return wave_defense_table.side_targets[r]
local r = math.random(1, wave_defense_table.side_target_count)
if not wave_defense_table.side_targets[r] then
table.remove(wave_defense_table.side_targets, r)
wave_defense_table.side_target_count = wave_defense_table.side_target_count - 1
return
end
if not wave_defense_table.side_targets[r].valid then
table.remove(wave_defense_table.side_targets, r)
wave_defense_table.side_target_count = wave_defense_table.side_target_count - 1
return
end
return wave_defense_table.side_targets[r]
end
function Public.get_side_target()
local wave_defense_table = WD.get_table()
for _ = 1, 512, 1 do
if wave_defense_table.side_target_count == 0 then return end
local target = get_random_target(wave_defense_table)
if target then return target end
end
local wave_defense_table = WD.get_table()
for _ = 1, 512, 1 do
if wave_defense_table.side_target_count == 0 then
return
end
local target = get_random_target(wave_defense_table)
if target then
return target
end
end
end
local function add_entity(entity)
local wave_defense_table = WD.get_table()
local wave_defense_table = WD.get_table()
--skip entities that are on another surface
if entity.surface.index ~= wave_defense_table.surface_index then return end
--skip entities that are on another surface
if entity.surface.index ~= wave_defense_table.surface_index then
return
end
if wave_defense_table.side_target_count >= 512 then
return
end
--add entity to the side target list
table.insert(wave_defense_table.side_targets, entity)
wave_defense_table.side_target_count = wave_defense_table.side_target_count + 1
--add entity to the side target list
table.insert(wave_defense_table.side_targets, entity)
wave_defense_table.side_target_count = wave_defense_table.side_target_count + 1
end
local function on_built_entity(event)
if not event.created_entity then return end
if not event.created_entity.valid then return end
if not side_target_types[event.created_entity.type] then return end
add_entity(event.created_entity)
if not event.created_entity then
return
end
if not event.created_entity.valid then
return
end
if not side_target_types[event.created_entity.type] then
return
end
add_entity(event.created_entity)
end
local function on_robot_built_entity(event)
if not event.created_entity then return end
if not event.created_entity.valid then return end
if not side_target_types[event.created_entity.type] then return end
add_entity(event.created_entity)
if not event.created_entity then
return
end
if not event.created_entity.valid then
return
end
if not side_target_types[event.created_entity.type] then
return
end
add_entity(event.created_entity)
end
local event = require 'utils.event'
+1 -1
View File
@@ -54,7 +54,7 @@ function Public.reset_wave_defense()
this.worm_raffle = {}
this.clear_corpses = false
this.alert_boss_wave = false
this.remove_entities = true
this.remove_entities = false
this.enable_threat_log = true
this.check_collapse_position = true
end