mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-11 13:39:14 +02:00
final inventory handling fixes
This commit is contained in:
parent
7d5ab6e450
commit
9e2537a468
@ -178,22 +178,39 @@ function Public_chrono.process_jump(choice)
|
||||
end
|
||||
end
|
||||
|
||||
function Public_chrono.get_wagons()
|
||||
local inventories = {
|
||||
one = global.locomotive_cargo[1].get_inventory(defines.inventory.cargo_wagon),
|
||||
two = global.locomotive_cargo[2].get_inventory(defines.inventory.cargo_wagon),
|
||||
three = global.locomotive_cargo[3].get_inventory(defines.inventory.cargo_wagon)
|
||||
}
|
||||
inventories.one.sort_and_merge()
|
||||
--inventories.two.sort_and_merge()
|
||||
function Public_chrono.get_wagons(start)
|
||||
local wagons = {}
|
||||
wagons[1] = {inventory = inventories.one.get_contents(), bar = inventories.one.get_bar(), filters = {}}
|
||||
wagons[2] = {inventory = inventories.two.get_contents(), bar = inventories.two.get_bar(), filters = {}}
|
||||
wagons[3] = {inventory = inventories.three.get_contents(), bar = inventories.three.get_bar(), filters = {}}
|
||||
for i = 1, 40, 1 do
|
||||
wagons[1].filters[i] = inventories.one.get_filter(i)
|
||||
wagons[2].filters[i] = inventories.two.get_filter(i)
|
||||
wagons[3].filters[i] = inventories.three.get_filter(i)
|
||||
wagons[1] = {inventory = {}, bar = 0, filters = {}}
|
||||
wagons[2] = {inventory = {}, bar = 0, filters = {}}
|
||||
wagons[3] = {inventory = {}, bar = 0, filters = {}}
|
||||
if start then
|
||||
wagons[1].inventory[1] = {name = "raw-fish", count = 100}
|
||||
for i = 2, 3, 1 do
|
||||
wagons[i].inventory[1] = {name = 'firearm-magazine', count = 16}
|
||||
wagons[i].inventory[2] = {name = 'iron-plate', count = 16}
|
||||
wagons[i].inventory[3] = {name = 'wood', count = 16}
|
||||
wagons[i].inventory[4] = {name = 'burner-mining-drill', count = 8}
|
||||
end
|
||||
else
|
||||
local inventories = {
|
||||
one = global.locomotive_cargo[1].get_inventory(defines.inventory.cargo_wagon),
|
||||
two = global.locomotive_cargo[2].get_inventory(defines.inventory.cargo_wagon),
|
||||
three = global.locomotive_cargo[3].get_inventory(defines.inventory.cargo_wagon)
|
||||
}
|
||||
inventories.one.sort_and_merge()
|
||||
--inventories.two.sort_and_merge()
|
||||
|
||||
wagons[1].bar = inventories.one.get_bar()
|
||||
wagons[2].bar = inventories.two.get_bar()
|
||||
wagons[3].bar = inventories.three.get_bar()
|
||||
for i = 1, 40, 1 do
|
||||
wagons[1].filters[i] = inventories.one.get_filter(i)
|
||||
wagons[1].inventory[i] = inventories.one[i]
|
||||
wagons[2].filters[i] = inventories.two.get_filter(i)
|
||||
wagons[2].inventory[i] = inventories.two[i]
|
||||
wagons[3].filters[i] = inventories.three.get_filter(i)
|
||||
wagons[3].inventory[i] = inventories.three[i]
|
||||
end
|
||||
end
|
||||
return wagons
|
||||
end
|
||||
|
@ -19,12 +19,12 @@ function Public.locomotive_spawn(surface, position, wagons)
|
||||
for i = 1, 3, 1 do
|
||||
global.locomotive_cargo[i] = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + math_floor((i - 1) * 6.5)}, force = "player"})
|
||||
local inv = global.locomotive_cargo[i].get_inventory(defines.inventory.cargo_wagon)
|
||||
for item, count in pairs(wagons[i].inventory) do
|
||||
inv.insert({name = item, count = count})
|
||||
if wagons[i].bar > 0 then inv.set_bar(wagons[i].bar) end
|
||||
for ii = 1, 40, 1 do
|
||||
inv.set_filter(ii, wagons[i].filters[ii])
|
||||
end
|
||||
if wagons[i].bar > 0 then inv.set_bar(wagons[i].bar) end
|
||||
for ii = 1, 40, 1 do
|
||||
inv.set_filter(ii, wagons[i].filters[ii])
|
||||
if wagons[i].inventory[ii] then
|
||||
inv.insert(wagons[i].inventory[ii])
|
||||
end
|
||||
end
|
||||
global.locomotive_cargo[i].minable = false
|
||||
end
|
||||
|
@ -38,7 +38,6 @@ global.comfylatron = nil
|
||||
global.lab_cells = {}
|
||||
|
||||
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 32, ['grenade'] = 4, ['raw-fish'] = 4, ['rail'] = 16, ['wood'] = 16}
|
||||
local starting_cargo = {['firearm-magazine'] = 16, ['iron-plate'] = 16, ['wood'] = 16, ['burner-mining-drill'] = 8}
|
||||
|
||||
local function generate_overworld(surface, optplanet)
|
||||
Planets.determine_planet(optplanet)
|
||||
@ -156,15 +155,7 @@ local function reset_map()
|
||||
Chrono.restart_settings()
|
||||
|
||||
game.forces.player.set_spawn_position({12, 10}, surface)
|
||||
local wagons = {}
|
||||
wagons[1] = {inventory = {["raw-fish"] = 100}, bar = 0, filters = {}}
|
||||
wagons[2] = {inventory = starting_cargo, bar = 0, filters = {}}
|
||||
wagons[3] = {inventory = starting_cargo, bar = 0, filters = {}}
|
||||
for i = 1, 40, 1 do
|
||||
wagons[2].filters[i] = nil
|
||||
wagons[3].filters[i] = nil
|
||||
end
|
||||
Locomotive.locomotive_spawn(surface, {x = 16, y = 10}, wagons)
|
||||
Locomotive.locomotive_spawn(surface, {x = 16, y = 10}, Chrono.get_wagons(true))
|
||||
render_train_hp()
|
||||
game.reset_time_played()
|
||||
Locomotive.create_wagon_room()
|
||||
@ -260,7 +251,7 @@ local function chronojump(choice)
|
||||
|
||||
game.forces.player.set_spawn_position({12, 10}, surface)
|
||||
|
||||
Locomotive.locomotive_spawn(surface, {x = 16, y = 10}, Chrono.get_wagons())
|
||||
Locomotive.locomotive_spawn(surface, {x = 16, y = 10}, Chrono.get_wagons(false))
|
||||
render_train_hp()
|
||||
game.delete_surface(oldsurface)
|
||||
Chrono.post_jump()
|
||||
|
@ -7,8 +7,6 @@ local math_min = math.min
|
||||
|
||||
function Public_tick.check_chronoprogress()
|
||||
local objective = global.objective
|
||||
local map_gen_settings = Public_tick.get_map_gen_settings()
|
||||
--game.print(objective.chronotimer)
|
||||
if objective.planet[1].name.id == 19 then
|
||||
if objective.passivetimer == 10 then
|
||||
game.print({"chronosphere.message_danger1"}, {r=0.98, g=0.66, b=0.22})
|
||||
@ -49,7 +47,6 @@ function Public_tick.charge_chronosphere()
|
||||
acus[i].energy = acus[i].energy - 3000000
|
||||
objective.chronotimer = objective.chronotimer + 1
|
||||
game.surfaces[global.active_surface_index].pollute(global.locomotive.position, (10 + 2 * objective.chronojumps) * (4 / (objective.filterupgradetier / 2 + 1)) * global.difficulty_vote_value)
|
||||
--log("energy charged from acu")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -85,22 +82,13 @@ function Public_tick.move_items()
|
||||
local input_inventory = input[i].get_inventory(defines.inventory.chest)
|
||||
local output_inventory = output[i].get_inventory(defines.inventory.chest)
|
||||
input_inventory.sort_and_merge()
|
||||
local items = input_inventory.get_contents()
|
||||
|
||||
for item, count in pairs(items) do
|
||||
if item == "modular-armor" or item == "power-armor" or item == "power-armor-mk2" then
|
||||
--log("can't move armors")
|
||||
else
|
||||
local inserted = output_inventory.insert({name = item, count = count})
|
||||
if inserted > 0 then
|
||||
local removed = input_inventory.remove({name = item, count = inserted})
|
||||
end
|
||||
end
|
||||
output_inventory.sort_and_merge()
|
||||
for ii = 1, #input_inventory, 1 do
|
||||
if input_inventory[ii].valid_for_read then
|
||||
local count = output_inventory.insert(input_inventory[ii])
|
||||
input_inventory[ii].count = input_inventory[ii].count - count
|
||||
end
|
||||
end
|
||||
-- local items = {}
|
||||
-- for ii = 1, #input_inventory, 1 do
|
||||
-- items[#items + 1] = input_inventory[ii]
|
||||
-- end
|
||||
end
|
||||
end
|
||||
|
||||
@ -110,25 +98,19 @@ function Public_tick.output_items()
|
||||
if not global.locomotive_cargo[2] then return end
|
||||
if not global.locomotive_cargo[3] then return end
|
||||
if global.objective.outupgradetier ~= 1 then return end
|
||||
local wagon = {
|
||||
[1] = global.locomotive_cargo[2].get_inventory(defines.inventory.cargo_wagon),
|
||||
[2] = global.locomotive_cargo[3].get_inventory(defines.inventory.cargo_wagon)
|
||||
}
|
||||
for i = 1, 4, 1 do
|
||||
if not global.outchests[i].valid then return end
|
||||
local inv = global.outchests[i].get_inventory(defines.inventory.chest)
|
||||
inv.sort_and_merge()
|
||||
local items = inv.get_contents()
|
||||
for item, count in pairs(items) do
|
||||
if item == "modular-armor" or item == "power-armor" or item == "power-armor-mk2" then
|
||||
--log("can't move armors")
|
||||
else
|
||||
local inserted = nil
|
||||
if i <= 2 then
|
||||
inserted = global.locomotive_cargo[2].get_inventory(defines.inventory.cargo_wagon).insert({name = item, count = count, grid = item.grid})
|
||||
else
|
||||
inserted = global.locomotive_cargo[3].get_inventory(defines.inventory.cargo_wagon).insert({name = item, count = count, grid = item.grid})
|
||||
end
|
||||
if inserted > 0 then
|
||||
local removed = inv.remove({name = item, count = inserted})
|
||||
end
|
||||
end
|
||||
for ii = 1, #inv, 1 do
|
||||
if inv[ii].valid_for_read then
|
||||
local count = wagon[math_ceil(i/2)].insert(inv[ii])
|
||||
inv[ii].count = inv[ii].count - count
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -254,7 +236,6 @@ function Public_tick.offline_players()
|
||||
end
|
||||
players[i] = nil
|
||||
else
|
||||
--game.print("keeping player in list")
|
||||
later[#later + 1] = players[i]
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user