1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-16 10:19:27 +02:00
RedMew/map_gen/maps/quadrants/item_to_chest.lua
Simon 5a45ff1729
Quadrants balance update (#863)
* Fix for hydra worms destroying base

Also include a force disable of research for all quadrants to prevent a save mitigation bug from a factorio version to another.

* Fixed wrong worm tier

* Mapgen settings and market locale

Added mapgen settings based on feedback

Added [retailer] market_name to use in rendering the market name over the market. Key has been added in en, de and da with translations.

Indentation fix

* Fixed floating 'a'

* Fixed global variable

* Updated item to chest

Made it more clear what happens when you cross the border in a train

Also added a GPS coordinate for the spawned chest

* Bug fixes for chests spawn

* Gave buttons uid_name()

* Removed debug statements

* Fixed Item to chest

People think the previous behavior was a glitch so I've changed it to align with their expectations.

Also increased evolution factor from pollution a bit

* fixed game.player

* Added crafting_queue_size check

* Updated enemy settings

* Merged map_settings and mapgen_settings, added wall

* Merged map_settings and mapgen_settings

* Added three toggles to settings, disabled item to chest when traveling in trains

* Game.get_player_by_index converted to game.get_player

* Added charting and removed unused variable 'Game'

* Fixed for 0.17.35
https://forums.factorio.com/70188

* Fix for 0.17.35

* Added comments to force new CI build

* fixed missing player_inventory -> character_inventory
2019-05-03 00:40:45 +02:00

86 lines
2.6 KiB
Lua

local RS = require 'map_gen.shared.redmew_surface'
local Event = require 'utils.event'
local Public = {}
local function create_chest(player, position, radius, bounding_box)
local surface = RS.get_surface()
position = position ~= nil and position or player.position
local pos
if radius then
pos = surface.find_non_colliding_position('steel-chest', position, radius, 1)
elseif bounding_box then
pos = surface.find_non_colliding_position_in_box('steel-chest', bounding_box, 1)
end
if pos ~= nil then
local chest = surface.create_entity {name = 'steel-chest', position = pos, force = player.force}
chest.minable = false
return chest
end
return false
end
function Public.transfer_inventory(player_index, inventories, position, radius, bounding_box)
if inventories == nil or player_index == nil then
return 'You need to specify a player index and a table of define.inventory'
end
local player = game.get_player(player_index)
player.clean_cursor()
while player.crafting_queue_size ~= 0 do
player.cancel_crafting(player.crafting_queue[1])
end
local chest
for _, inventory in pairs(inventories) do
inventory = player.get_inventory(inventory)
for name, count in pairs(inventory.get_contents()) do
local ItemStack = {name = name, count = count}
inventory.remove(ItemStack)
while count > 0 do
if not chest or not chest.can_insert(ItemStack) then
chest = create_chest(player, position, radius, bounding_box)
if not chest then
return false
end
end
count = count - chest.insert(ItemStack)
ItemStack = {name = name, count = count}
end
end
end
if not chest then
return false
end
return chest.position
end
local function on_gui_closed(event)
local entity = event.entity
if entity == nil or not entity.valid then
return
end
if entity.name == 'steel-chest' and entity.minable == false and not entity.has_items_inside() then
entity.destroy()
end
end
local function ctrl_empty(event)
local entity = event.last_entity
if entity == nil or not entity.valid then
return
end
if entity.name == 'steel-chest' and not entity.minable then
event.entity = entity
on_gui_closed(event)
end
end
Event.add(defines.events.on_gui_closed, on_gui_closed)
Event.add(defines.events.on_selected_entity_changed, ctrl_empty)
Event.add(defines.events.on_pre_player_mined_item)
return Public