Skip to content

Commit

Permalink
Update to 1.4.0
Browse files Browse the repository at this point in the history
More default sets, hotkey to toggle limits.
  • Loading branch information
Nexela committed Jul 26, 2016
1 parent 39093bf commit 11ff74a
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 57 deletions.
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
Autofill
========
=====

Factorio mod for automatic insertion of items to built entities.
The Autofill mod by rk84 updated for .13 by Jakimfett and more default sets added by Nexela
https://forums.factorio.com/viewtopic.php?f=92&t=1612&hilit=autofill

Autofill Automaticly fills fuel (like coal) and ammo from your main inventory to entities when you create them. Including Trains, Planes, and Automobiles. Oh and Turrets, boilers, burner inserters, burner assemblers, overpower nuclear weapon launchers just to name a few more!

#Now with HOTKEY support!
Hover over an entity in the field and CTRL-F to fill it based on your ruleset!
Toggle filling limits on or off with CTRL-SHIFT-F for those times when you want to Fill something without limits!



Fuel items are automaticly added and sorted from low to high anytime a mod is added, changed, or removed.

Current Mods with a set enabled by default
*Yuoki Industries - All Turrets, Boilers, Ammos
*Bob's Mods - All Turrets, Tanks including Artillery ammo, Ammos
*Uranium Power - Ammo's and shells
*Shuttle Train
*Advanced Tanks
*Combat Robots
*General Improvments
*Farl
And many others.

*car, dielsel-locomotive and tank are loaded with fuel with highest fuelvalue. (+ tank includes ammos too)
*Burners group: Burner mining drills, Stone furnaces, Steel furnaces, Burner inserters and Boilers work same as vehicles, but all fuel is divided to all "burners" that are in quickbar and hand.
*Turrets group: Gun turrets are loaded with ammos (First in array first in use). Ammo is divided to all turrets in quickbar and hand.

If a mod you like doesn't work out of the box let me know and I will see about adding it or walk your through how to add it to your personal set using the command line interface for adding new items from other mods to your autofill set.

Example for making your own set:
remote.call("af", "insertset", "", "car", {{"coal","raw-wood"}, "basic-bullet-magazine"}) -- Creates personal setting for car.
remote.call("af", "insertset", "", "car", 0) -- insert nothing to car. (ignores default setting)
remote.call("af", "insertset", "", "car", nil) -- reset to default setting
---
##TODO
*Super Awesome GUI for making sets a lot easier
*Better Error Checking
*Fuel blacklists so we are not burning our wooden power poles!


---
1.4.0 - More Hotkeys, more mods supported by default, General improvements, Advanced Tanks.
1.3.18 - Hotkeys!, Added some more of Bob's Stuff, Temporary fix for mods being removed causing crash.
1.3.17 - Added Bulldozer and Combat Drones. Might have to do /c remote.call("af", "resetMod") if adding to an existing save.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.4.0
-New Hotkey for turning fill limits on and off
-default support for Advanced Tanks, GImprovements
-personalsets are kept upon updating however they are not verified when other mods are added or removed. You will have to do /c remote.call("af","resetUser") if a mod change causes an item to be removed. I was gonna fix this but I forgot.........

1.3.18
-Temporary work around to mod changes causing crash if the item no longer exists.
-Hotkey support, hover over an entity and CTRL-F to autofill
Expand Down
97 changes: 60 additions & 37 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ loader.extendItemArray "settings/yuoki-ind-items" -- YI Bullets
loader.addSets "settings/yuoki-ind-sets" -- YI Item Sets
loader.addSets "settings/aircraft-sets"
loader.addSets "settings/5dim-sets"
loader.extendItemArray "settings/at-items" -- Advanced Tanks Mod
loader.addItemArray "settings/at-newitems"
loader.addSets "settings/at-sets"


--flying text colors
local RED = {r = 0.9}
local GREEN = {g = 0.7}
local YELLOW = {r = 0.8, g = 0.8}

local order = {
local order = {
default = 1,
opposite = 2,
itemcount = 3
Expand All @@ -34,7 +37,7 @@ local order = {
--

script.on_configuration_changed(function()
initMod(true) --TODO needs to be changed to only update sets
initMod(false,true) --TODO needs to be changed to only update sets
end)

script.on_init(function()
Expand All @@ -43,10 +46,11 @@ end)

script.on_event(defines.events.on_built_entity, function(event)
local player = game.players[event.player_index]
if global.personalsets[player.name].uselimits == nil then global.personalsets[player.name].uselimits=true end
local global = global
if global.personalsets[player.name] and global.personalsets[player.name].active then
local fillset = global.personalsets[player.name][event.created_entity.name] or global.defaultsets[event.created_entity.name]
if fillset ~= 0 and fillset ~= nil then
if fillset ~= 0 and fillset ~= nil then
autoFill(event.created_entity, player, fillset)
end
end
Expand All @@ -55,7 +59,7 @@ end)
script.on_event(defines.events.on_player_created, function(event)
local username = game.players[event.player_index].name
if global.personalsets[username] == nil then
global.personalsets[username] = { active = true }
global.personalsets[username] = { active = true, uselimits=true }
end
--log("AutoFill: user ".. username .. " Created")
end)
Expand All @@ -66,12 +70,26 @@ script.on_event("autofill-entity", function(event)
local global = global
if global.personalsets[player.name] and global.personalsets[player.name].active and selection then
local fillset = global.personalsets[player.name][selection.name] or global.defaultsets[selection.name]
if fillset ~= 0 and fillset ~= nil then
if fillset ~= 0 and fillset ~= nil then
autoFill(selection, player, fillset)
end
end
end)

script.on_event("autofill-toggle-limits", function(event)
local player = game.players[event.player_index]
local afplayer = global.personalsets[player.name]
if afplayer then
afplayer.uselimits = not afplayer.uselimits
if afplayer.uselimits then
player.print({"autofill.toggle-limits-on"})
elseif not afplayer.uselimits then
player.print({"autofill.toggle-limits-off"})
end
global.personalsets[player.name].uselimits=afplayer.uselimits
end
end)

--
--Funtions
--
Expand Down Expand Up @@ -117,7 +135,7 @@ function autoFill(entity, player, fillset)
item = false
count = 0
color = RED

if fillset.priority == order.itemcount then -- Pick item with highest count
for j = 1, #array do
if vehicleinv then
Expand Down Expand Up @@ -163,11 +181,11 @@ function autoFill(entity, player, fillset)
-- Divide stack between group (only items in quickbar are part of group)
if fillset.group then
if player.cursor_stack.valid_for_read then
groupsize = player.cursor_stack.count + 1
groupsize = player.cursor_stack.count + 1
else
groupsize = 1
end

for k,v in pairs(global.personalsets[player.name]) do
if type(v) == "table" and v.group == fillset.group then
groupsize = groupsize + quickbar.get_item_count(k)
Expand All @@ -178,7 +196,7 @@ function autoFill(entity, player, fillset)
groupsize = groupsize + quickbar.get_item_count(k)
end
end

totalitemcount = 0
for j=1, #array do
totalitemcount = totalitemcount + maininv.get_item_count(array[j])
Expand All @@ -190,21 +208,24 @@ function autoFill(entity, player, fillset)
end
count = math.max( 1, math.min( count, math.floor(totalitemcount / groupsize) ) )
end

-- Limit insertion if has limit value
if fillset.limits and fillset.limits[i] then
local uselimits = global.personalsets[player.name].uselimits
if uselimits == nil then uselimits = true end
--log("limits in autofill script" .. tostring(uselimits))
if uselimits and fillset.limits and fillset.limits[i] then
if count > fillset.limits[i] then
count = fillset.limits[i]
end
end

-- Determine insertable stack count if has slot count
if fillset.slots and fillset.slots[i] then
if fillset.slots and fillset.slots[i] then --TODO Also see if slots are full for use in hotkey filling, also check if we have a better type of ammo/fuel, ALSO check if inv full
slots = fillset.slots[i]
else
slots = 1
end

if count < game.item_prototypes[item].stack_size * slots then
color = YELLOW
else
Expand Down Expand Up @@ -234,7 +255,7 @@ function autoFill(entity, player, fillset)
text({"autofill.insertion", inserted, game.item_prototypes[item].localised_name }, textpos, color)
textpos.y = textpos.y + 1
end
end
end
end -- if not item or count < 1 then
end -- for i=1, #fillset do
end
Expand Down Expand Up @@ -289,17 +310,19 @@ end



function initMod(reset)
function initMod(reset,keeppersonal)
if not global.defaultsets or not global.personalsets or not global.item_arrays or reset then
global = {} -- Clears global

loader.loadBackup()

global.personalsets = {}
for k, player in pairs(game.players) do
global.personalsets[player.name] = { active = true }
if not keeppersonal or reset then
global.personalsets = {}
for k, player in pairs(game.players) do
global.personalsets[player.name] = { active = true, uselimits=true }
end
end

global.has_init = true
log("Autofill: INIT - Reset all to default")
else
Expand All @@ -312,7 +335,7 @@ function isValidEntity(name)
if game.entity_prototypes[name] then
return true
end

globalPrint( {"autofill.invalid-entityname", tostring(name)} )
return false
end
Expand All @@ -323,9 +346,9 @@ function isValidSet(set)
return true
elseif type(set) == "table" then
for i = 1, #set do

if type(set[i]) == "string" then

if global.item_arrays[set[i]] then -- replace name with array
set[i] = global.item_arrays[set[i]]
else
Expand All @@ -336,23 +359,23 @@ function isValidSet(set)
return false
end
end

elseif type(set[i]) == "table" then

for j = 1, #set[i] do
if game.item_prototypes[set[i][j]] == nil then
globalPrint( {"autofill.invalid-itemname", tostring(set[i][j])} )
return false
end
end

else
globalPrint( {"autofill.invalid-form"} )
return false
end

end -- for i = 1, #set do

return true
end
globalPrint( {"autofill.invalid-parameter"} )
Expand All @@ -366,11 +389,11 @@ function isValidUser(name)
return players[i].name
end
end

if game.player then -- for single player game
return game.player.name
end

globalPrint( {"autofill.invalid-username", tostring(name)} )
return false
end
Expand Down Expand Up @@ -405,13 +428,13 @@ remote.add_interface(MOD.IF,
global.personalsets[username][entityname] = set
end
end,

addToDefaultSets = function(entityname, set)
if isValidEntity(entityname) and isValidSet(set) then
global.defaultsets[entityname] = set
end
end,

getDefaultSets = function()
local sets = table.deepcopy(global.defaultsets)
for entity_name, set in pairs(sets) do
Expand All @@ -426,7 +449,7 @@ remote.add_interface(MOD.IF,
end
return sets
end,

setDefaultSets = function(sets)
for entity_name, set in pairs(sets) do
if not isValidSet(set) then
Expand All @@ -435,17 +458,17 @@ remote.add_interface(MOD.IF,
end
global.defaultsets = sets
end,

getBackupLog = function()
local tbl = loader.getBackupLog()
local block = table.concat(tbl, "\n")
log(block)
end,

getItemArray = function(name)
return global.item_arrays[name]
end,

setItemArray = function(name, new_array)
if global.item_arrays[name] == nil then
global.item_arrays[name] = new_array
Expand All @@ -457,7 +480,7 @@ remote.add_interface(MOD.IF,
end
end
end,

logGlobal = function(key)
key = key or "global"
if _G[key] then
Expand All @@ -470,7 +493,7 @@ remote.add_interface(MOD.IF,
resetMod = function()
initMod(true)
end,

resetUser = function(setname, username)
username = isValidUser(username)
if username then
Expand All @@ -492,4 +515,4 @@ remote.add_interface(MOD.IF,
end
end
end
})
})
9 changes: 8 additions & 1 deletion data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@ data:extend({
name = "autofill-entity",
key_sequence = "CONTROL + F",
consuming = "all"
},
{
type = "custom-input",
name = "autofill-toggle-limits",
key_sequence = "CONTROL + SHIFT + F",
consuming = "script-only"
}
})

})
8 changes: 4 additions & 4 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "autofill",
"version": "1.3.18",
"version": "1.4.0",
"factorio_version": "0.13",
"title": "Autofill",
"author": "rk84",
"author": "rk84, Nexela",
"contact": "www.factorioforums.com",
"homepage": "https://forums.factorio.com/viewtopic.php?f=92&t=1612",
"description": "Autofill inserts items (ammo,fuel,etc) inside entities when placing them in the world.",
"dependencies": ["base >= 0.13.0"],
"dependencies": ["base >= 0.13.9"],
"license": "MIT"
}
}
Loading

0 comments on commit 11ff74a

Please sign in to comment.