1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-12 02:28:02 +02:00

Logistics slots save/reset during force toggle event

This commit is contained in:
TWLTriston 2017-11-20 11:17:21 -05:00
parent 06ec743530
commit fff3395cad

View File

@ -329,53 +329,73 @@ end
global.old_force = {}
global.force_toggle_init = true
local function forcetoggle(cmd)
if not game.player or not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
if not game.player or not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
if global.force_toggle_init then
game.forces.enemy.research_all_technologies() --avoids losing logstics slot configuration
global.force_toggle_init = false
end
if global.force_toggle_init then
game.forces.enemy.research_all_technologies() --avoids losing logstics slot configuration
global.force_toggle_init = false
end
if game.player.force.name == "enemy" then
local old_force = global.old_force[game.player.name]
if not old_force then
game.player.force = "player"
game.player.print("Your are now on the player force.")
else
if game.forces[old_force] then
game.player.force = old_force
-- save the logistics slots
local slots = {}
local slot_counts = game.player.character.request_slot_count
if game.player.character.request_slot_count > 0 then
for i = 1, slot_counts do
slot = game.player.character.get_request_slot(i)
if slot ~= nil then
table.insert(slots, slot)
end
end
end
if game.player.force.name == "enemy" then
local old_force = global.old_force[game.player.name]
if not old_force then
game.player.force = "player"
game.player.print("You're are now on the player force.")
else
game.player.force = "player"
if game.forces[old_force] then
game.player.force = old_force
else
game.player.force = "player"
end
end
end
else
else
--Put roboports into inventory
inv = game.player.get_inventory(defines.inventory.player_armor)
if inv[1].valid_for_read
inv = game.player.get_inventory(defines.inventory.player_armor)
if inv[1].valid_for_read
then
local name = inv[1].name
if name:match("power") or name:match("modular") then
local equips = inv[1].grid.equipment
for _,equip in pairs(equips) do
if equip.name == "personal-roboport-equipment"
or equip.name == "personal-roboport-mk2-equipment"
or equip.name == "personal-laser-defense-equipment" then
if game.player.insert{name = equip.name} == 0 then
game.player.surface.spill_item_stack(game.player.position, {name = equip.name})
local name = inv[1].name
if name:match("power") or name:match("modular") then
local equips = inv[1].grid.equipment
for _,equip in pairs(equips) do
if equip.name == "personal-roboport-equipment"
or equip.name == "personal-roboport-mk2-equipment"
or equip.name == "personal-laser-defense-equipment" then
if game.player.insert{name = equip.name} == 0 then
game.player.surface.spill_item_stack(game.player.position, {name = equip.name})
end
inv[1].grid.take(equip)
end
end
inv[1].grid.take(equip)
end
end
end
end
end
global.old_force[game.player.name] = game.player.force.name
game.player.force = "enemy"
end
game.player.print("You are now on the " .. game.player.force.name .. " force.")
global.old_force[game.player.name] = game.player.force.name
game.player.force = "enemy"
end
game.player.print("You are now on the " .. game.player.force.name .. " force.")
-- Attempt to rebuild the request slots
slot_counts = game.player.character.request_slot_count
if game.player.character.request_slot_count > 0 then
for _,slot in ipairs(slots) do
game.player.character.set_request_slot(slot, _)
end
end
end
local function get_group()