diff --git a/README.md b/README.md index 1e996b3..80c4ea5 100644 --- a/README.md +++ b/README.md @@ -2,47 +2,56 @@ Autofill ===== 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 +https://forums.factorio.com/viewtopic.php?f=92&t=1612 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! +##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! +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. -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. +####More Information -*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. +* Fuel items are automaticly added and sorted from low to high anytime a mod is added, changed, or removed. +* 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. +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. -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! +####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. + +####Change Log + +1.4.1 - The NotEnoughTanks Release - More safety checks for when mods are removed, Added Tankwerks, MoCombat, Supertank, KSpower, Military5, IncindiaryMunitions, Artillery. +1.4.0 - The No Limits release - More Hotkeys, more mods supported by default, General improvements, Advanced Tanks. +1.3.18 - The Tap, tap, tap release -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. diff --git a/changelog.txt b/changelog.txt index 459ffa9..77e3678 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,9 @@ +1.4.1 - Even More Tanks +-More safety checks for when mods are removed +-Oooops fixed and some temporary logic. +-Added Tankwerks, MoCombat, Supertank, KSpower, Military5, IncindiaryMunitions, Artillery. +-TODO re-check defaults when loading new mods. + 1.4.0 -New Hotkey for turning fill limits on and off -default support for Advanced Tanks, GImprovements @@ -50,7 +56,7 @@ 1.3.10 -Added loader.extendItemArray. Use to add items to exiting arrays. -Added wildcard character * that can be used in set definitions. if entity name has * character(s) the name is convert to pattern. - * are changed to .+ and - are changed to %- + * are changed to .+ and - are changed to %- -Added AmmoBox turrets and ammoboxes -Added color coding locos -Added Yuoki's gun turrets diff --git a/control.lua b/control.lua index 48e3b3c..a9e7d38 100644 --- a/control.lua +++ b/control.lua @@ -16,7 +16,7 @@ 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.extendItemArray "settings/at-items" -- Advanced Tanks and Tankwerkz Mod loader.addItemArray "settings/at-newitems" loader.addSets "settings/at-sets" @@ -130,34 +130,38 @@ function autoFill(entity, player, fillset) local quickbar = player.get_inventory(defines.inventory.player_quickbar) local array, item, count, groupsize, slots, totalitemcount, color, inserted, removed - for i=1, #fillset do + for i=1, #fillset do --? Item prototype check here? array = fillset[i] 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 - if maininv.get_item_count(array[j]) + vehicleinv.get_item_count(array[j]) > count then - item = array[j] - count = maininv.get_item_count(array[j]) + vehicleinv.get_item_count(array[j]) - end - else - if maininv.get_item_count(array[j]) > count then - item = array[j] - count = maininv.get_item_count(array[j]) - end - end - end + if fillset.priority == order.itemcount then -- Pick item with highest count + for j = 1, #array do + if game.item_prototypes[array[j]] then + if vehicleinv then + if maininv.get_item_count(array[j]) + vehicleinv.get_item_count(array[j]) > count then + item = array[j] + count = maininv.get_item_count(array[j]) + vehicleinv.get_item_count(array[j]) + end + else + if maininv.get_item_count(array[j]) > count then + item = array[j] + count = maininv.get_item_count(array[j]) + end + end + end + end elseif fillset.priority == order.opposite then --Pick last available item for j = #array, 1, -1 do + if game.item_prototypes[array[j]] then if maininv.get_item_count(array[j]) > 0 or vehicleinv and vehicleinv.get_item_count(array[j]) > 0 then item = array[j] count = maininv.get_item_count(array[j]) count = not vehicleinv and count or count + vehicleinv.get_item_count(array[j]) break end + end end else --Pick first available item for j = 1, #array do @@ -199,11 +203,15 @@ function autoFill(entity, player, fillset) totalitemcount = 0 for j=1, #array do - totalitemcount = totalitemcount + maininv.get_item_count(array[j]) + if game.item_prototypes[array[j]] then + totalitemcount = totalitemcount + maininv.get_item_count(array[j]) + end end if vehicleinv then for j=1, #array do - totalitemcount = totalitemcount + vehicleinv.get_item_count(array[j]) + if game.item_prototypes[array[j]] then + totalitemcount = totalitemcount + vehicleinv.get_item_count(array[j]) + end end end count = math.max( 1, math.min( count, math.floor(totalitemcount / groupsize) ) ) @@ -310,13 +318,13 @@ end -function initMod(reset,keeppersonal) +function initMod(reset,update) if not global.defaultsets or not global.personalsets or not global.item_arrays or reset then global = {} -- Clears global loader.loadBackup() - if not keeppersonal or reset then + if not update or reset then global.personalsets = {} for k, player in pairs(game.players) do global.personalsets[player.name] = { active = true, uselimits=true } @@ -324,10 +332,14 @@ function initMod(reset,keeppersonal) end global.has_init = true - log("Autofill: INIT - Reset all to default") - else - loader.updateFuelArrays(global.item_arrays) - log("AutoFill: Updated fuel arrays") + log("Autofill: Initilized") + else + if update then + loader.loadBackup() + log("AutoFill: Defaults Updated") + else + loader.updateFuelArrays(global.item_arrays) + end end end diff --git a/info.json b/info.json index 6957834..f0a7a68 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "autofill", - "version": "1.4.0", + "version": "1.4.1", "factorio_version": "0.13", "title": "Autofill", "author": "rk84, Nexela", diff --git a/loader.lua b/loader.lua index cdeb2ba..5c8a5c4 100644 --- a/loader.lua +++ b/loader.lua @@ -18,13 +18,13 @@ loader = { end end end, - + extendItemArray = function(path) local tbl = require(path) for name, array in pairs(tbl) do - + if item_arrays_backup[name] and type(array) == "table" then - + if extension_items_backup[name] then extension_items_backup[name][#extension_items_backup[name]+1] = array else @@ -34,7 +34,7 @@ loader = { else backup_log[#backup_log + 1] = "Array '" .. name .. "' not found in '" .. path .. "'" end - + end end, @@ -61,7 +61,7 @@ loader = { end end end, - + getBackupLog = function() return backup_log end, @@ -78,21 +78,32 @@ loader = { for name, array in pairs(item_arrays) do for i=1, #array do if game.item_prototypes[array[i]] == nil then - backup_log[#backup_log + 1] = "Item array '" .. name .. "' removed" + backup_log[#backup_log + 1] = "Item array '" .. name .. ":" .. array[i] .. "' removed" item_arrays[name] = nil break end end end - + -- Remove extensions that has false itemnames and lacks of target array local array for name, modules in pairs(extension_items) do if item_arrays[name] then for j=#modules, 1, -1 do array = modules[j] + --Start temp fix for generic lists + if type(array) == "table" then + for num=#array, 1, -1 do + if game.item_prototypes[array[num]] == nil then + backup_log[#backup_log + 1] = "REMOVED " .. name .." : " .. array[num] + table.remove(array, num) + --log(serpent.block(array)) + end + end + end + --End temp fix for generic lists + for i=1, #array do - if type(array[i]) == "table" then if game.item_prototypes[array[i][1]] == nil then backup_log[#backup_log + 1] = "Extension for array '" .. name .. "' removed" @@ -101,12 +112,12 @@ loader = { end else if game.item_prototypes[array[i]] == nil then - backup_log[#backup_log + 1] = "Extension for array '" .. name .. "' removed" + backup_log[#backup_log + 1] = "Extension for array '" .. name .. ":" .. array[i] .. "' removed" table.remove(modules, j) break end end - + end end else -- lacks target array @@ -114,7 +125,7 @@ loader = { extension_items[name] = nil end end - + -- Add item extensions to item_arrays local tbl = table local array @@ -134,7 +145,7 @@ loader = { end end end - + --Pre-search wildcard entity names and add them to defaultsets for pattern, set in pairs(wildcardsets) do for name, _ in pairs(game.entity_prototypes) do @@ -143,11 +154,11 @@ loader = { end end end - + -- Remove sets with false entity names. Remove invalid items. Link array names to item_arrays for name, set in pairs(defaultsets) do if game.entity_prototypes[name] then - + for i=#set, 1, -1 do if type(set[i]) == "string" then if game.item_prototypes[set[i]] then @@ -168,7 +179,7 @@ loader = { end end end - + if #set == 0 then -- has no items or arrays backup_log[#backup_log + 1] = "Empty set '" .. name .. "'. Set removed" defaultsets[name] = nil @@ -178,25 +189,25 @@ loader = { defaultsets[name] = nil end end - + global.item_arrays = item_arrays global.defaultsets = defaultsets backup_log[#backup_log + 1] = game.tick .. " Backup loaded." end, - + updateFuelArrays = function(tbl) tbl["fuels-all"] = {} tbl["fuels-high"] = {} local all = tbl["fuels-all"] local high = tbl["fuels-high"] - + if all or high then local MINfuel_value = 8000000 -- Joules. local coal = game.item_prototypes.coal if coal and coal.fuel_value > 0 then MINfuel_value = coal.fuel_value end - + for name, item in pairs(game.item_prototypes) do if item.fuel_value > 0 then if all then @@ -218,4 +229,4 @@ loader = { table.sort(high, fuelHighToLow) backup_log[#backup_log + 1] = "Updating Fuel Arrays" end -} \ No newline at end of file +} diff --git a/settings/at-items.lua b/settings/at-items.lua index 0fd9fff..52161b3 100644 --- a/settings/at-items.lua +++ b/settings/at-items.lua @@ -5,7 +5,12 @@ --Advanced Tank Extend Arrays return { + --advanced Tanks ["ammo-shotgun"] = {"piercing-shotgun-shell-brick"}, ["ammo-bullets"] = {"ap-bullet-brick"}, - ["ammo-shells"] = {"cannon-shell-2"} + ["ammo-shells"] = {"cannon-shell-2"}, + + --Tankwerkz + ["ammo-shells"] = {"ap-cannon-shell", "hiex-cannon-shell"} + } diff --git a/settings/at-newitems.lua b/settings/at-newitems.lua index bddd175..bbd8749 100644 --- a/settings/at-newitems.lua +++ b/settings/at-newitems.lua @@ -4,10 +4,17 @@ --Advanced Tank New Item Arrays return { + --Advanced Tanks ["gi-ammo-flame"] = {"flame-thrower-ammo-tanker"}, ["gi-ammo-mine"] = {"minepack", "minepack-poison"}, ["gi-ammo-artillery"] = {"50mm-mortar", "50mm-mortar-poison"}, ["gi-ammo-wmd"] = {"tank-wmd-ammo"}, ["gi-ammo-rocket"] = {"rocketpack"}, - ["gi-ammo-auto45"] = {"45mm-auto"} + ["gi-ammo-auto45"] = {"45mm-auto"}, + + --Tankwerkz + ["tw-ammo-rocket"] = {"hydra-rocket"}, + ["tw-ammo-belt"] = {"heavy-mg-ammo"}, + ["tw-ammo-flame"] = {"tank-flame-thrower-ammo"}, + } diff --git a/settings/at-sets.lua b/settings/at-sets.lua index 617add7..e1e4227 100644 --- a/settings/at-sets.lua +++ b/settings/at-sets.lua @@ -1,9 +1,10 @@ -- -- Disclaimer: mp warranty void if edited. -- ---Advanced Tanks New Sets +--Advanced Tanks New Sets, Tankwerks New Sets return { + --Advanced Tank ["car-flamer"] = {priority=3, slots={1,1}, "fuels-all", "gi-ammo-flame"}, ["auto-tank-wlsk"] = {priority=3, slots={2,1,1}, "fuels-all", "gi-ammo-auto45", "ammo-shotgun"}, ["flame-tank-wlsk"] = {priority=3, slots={2,1,1}, "fuels-all", "ammo-shells", "gi-ammo-flame"}, @@ -15,5 +16,26 @@ ["mine-tank"] = {priority=3, slots={2,1,1}, "fuels-all", "gi-ammo-mine", "ammo-shotgun"}, ["super-tank"] = {priority=3, slots={4,1,1,1}, "fuels-all", "gi-ammo-auto45", "gi-ammo-artillery", "ammo-bullets"}, ["super-tank-alternate"] = {priority=3, slots={4,1,1,1}, "fuels-all", "ammo-shells", "gi-ammo-flame", "gi-ammo-mine"}, - ["super-tank-wmd"] = {priority=3, slots={4,1,1}, "fuels-all", "gi-ammo-wmd", "gi-ammo-auto45"} + ["super-tank-wmd"] = {priority=3, slots={4,1,1}, "fuels-all", "gi-ammo-wmd", "gi-ammo-auto45"}, + + --Tankwerkz + ["flame-tank"] = {priority=3, slots={2,1,1}, "fuels-all", "tw-ammo-flame", "ammo-bullets"}, --hmmmm We already have this, might have a problem......... + ["hydra-tank"] = {priority=3, slots={2,1,1}, "fuels-all", "tw-ammo-rocket", "ammo-bullets"}, + ["heavy-tank"] = {priority=3, slots={2,2,1}, "fuels-all", "ammo-shells", "tw-ammo-belt"}, + ["light-tank"] = {priority=3, slots={2,1}, "fuels-all", "ammo-bullets"}, + + +--[[ +tankw - flametanks - 2, 1, 1 fuel tankw-flamer, bullets +tankw - goliath - 2, 2, 1, - fuel, shells, heavygun +tankw - hydra - 2, 1, 1 fuel, tankrock, bullets +tankw -perseus light tank - 2, 1 fuel, bullets + +light-tank=Perseus light tank +hydra-tank=Hydra rocket tank +heavy-tank=Goliath heavy tank +flame-tank=Flame tank +]]-- + + } diff --git a/settings/generic-items.lua b/settings/generic-items.lua index 0ecb894..f9cb26e 100644 --- a/settings/generic-items.lua +++ b/settings/generic-items.lua @@ -1,11 +1,90 @@ -- -- Disclaimer: mp warranty void if edited. -- +--local newBullets = {} +--local newShells = {} +--local newShotgun = {} + +local tbl = { + bullets = { + "uranium-bullet-magazine", --Uranium Power + "basic-bullet-ammo-box", "piercing-bullet-ammo-box", --Ammobox + "nanobot-bullet-magazine", --GImprovments Mod + "super-piercing-bullet-magazine", --Supertank -- Not Working? + "incendiary-rounds-magazine", --IncendiaryMunitions -- Not working? + "incendiary-bullet-ammo-box", --IncendiaryMunitions, with ammobox + "explosive-bullet-magazine", --Mil5 + }, + shells = { + "artilleryshell", --Artillery + "super-explosive-cannon-shell", --Supertank + "uranium-small-nuke-shell", "uranium-cannon-shell", --Uranium Power + "high-explosive-cannon-shell", --Aircraft + }, + shotgun= { + "explosive-shotgun-shell", --Mi-5, Incendiary ammo + }, +} + +--log("START DATA") +--if game then log("GAME") end +--if data then log("DATA1") end +--if data and data.raw then log("DATA2") end +--if data and data.raw and data.raw.items then log("DATA3") end +--if game then log("GAME") end + +--[[ +for j, item in pairs(tbl["bullets"]) do + if data.raw["items"][item] then + newBullets[#newBullets + 1] = bullets + + log("added ".. i) + else + log("skipped ".. i) + end +end + +for j, item in pairs(tbl["shells"]) do + if data.raw["items"][item] then + newShells[#newShells + 1] = item + + log("added ".. i) + else + log("skipped ".. i) + end +end + +for j, item in pairs(tbl["shotgun"]) do + if data.raw["items"][item] then + newShotgun[#newNewShotgun + 1] = item + + log("added ".. i) + else + log("skipped ".. i) + end +end +--]] + + return { - ["ammo-bullets"] = {"uranium-bullet-magazine"}, --Uranium Power - ["ammo-bullets"] = {"basic-bullet-ammo-box", "piercing-bullet-ammo-box"}, --Ammobox - ["ammo-bullets"] = {"nanobot-bullet-magazine"}, --GImprovments Mod - ["ammo-shells"] = {"uranium-small-nuke-shell", "uranium-cannon-shell"}, --Uranium Power - ["ammo-shells"] = {"high-explosive-cannon-shell"} --Aircraft + ["ammo-bullets"] = tbl.bullets, + ["ammo-shells"] = tbl.shells, + ["ammo-shotgun"] = tbl.shotgun, + --[[ + ["ammo-bullets"] = {"uranium-bullet-magazine"}, --Uranium Power + ["ammo-bullets"+1] = {"basic-bullet-ammo-box", "piercing-bullet-ammo-box"}, --Ammobox + ["ammo-bullets"+1] = {"nanobot-bullet-magazine"}, --GImprovments Mod + ["ammo-bullets"+1] = {"super-piercing-bullet-magazine"}, --Supertank -- Not Working? + ["ammo-bullets"+1] = {"incendiary-rounds-magazine"}, --IncendiaryMunitions -- Not working? + ["ammo-bullets"+1] = {"incendiary-bullet-ammo-box"}, --IncendiaryMunitions, with ammobox + ["ammo-bullets"]+1 = {"explosive-bullet-magazine"}, --Mil5 + + ["ammo-shells"] = {"artilleryshell"}, --Artillery + ["ammo-shells"+1] = {"super-explosive-cannon-shell"}, --Supertank + ["ammo-shells"+1] = {"uranium-small-nuke-shell", "uranium-cannon-shell"}, --Uranium Power + ["ammo-shells"+1] = {"high-explosive-cannon-shell"}, --Aircraft + + ["ammo-shotgun"]= {"explosive-shotgun-shell"}, --Mi-5, Incendiary ammo +--]] } diff --git a/settings/generic-newitems.lua b/settings/generic-newitems.lua index 0ec1125..4db4724 100644 --- a/settings/generic-newitems.lua +++ b/settings/generic-newitems.lua @@ -3,5 +3,6 @@ -- return { -["combat-units"] = {"destroyer-unit-ammo", "defender-unit-ammo", "distractor-unit-ammo"} --Combat Units -} \ No newline at end of file +["combat-units"] = {"destroyer-unit-ammo", "defender-unit-ammo", "distractor-unit-ammo"}, --Combat Units +["mo-ammo-goliath"] = {"mega-cannon-shell"} --MoMods +} diff --git a/settings/generic-sets.lua b/settings/generic-sets.lua index 1c01279..926f216 100644 --- a/settings/generic-sets.lua +++ b/settings/generic-sets.lua @@ -8,7 +8,12 @@ return { ["farl"] = {group="locomotives", "fuels-high"}, --FARL ["shuttleTrain"] = {group="locomotives", "fuels-high"}, --ShuttleTrain ["ammobox-gun-turret-2"] = {group="turrets", limits= {10}, "ammo-bullets" }, --Ammobox - ["burner-ore-crusher"] = {group="burners", limits={10}, "fuels-high"}, - ["hvmg-turret"] = {priority=3, group="turrets", limits={10}, "ammo-bullets"}, - ["buggy"] = {priority=3, slots={1,1}, "fuels-all", "ammo-bullets"}, + ["burner-ore-crusher"] = {group="burners", limits={10}, "fuels-high"}, --Angels + ["hvmg-turret"] = {priority=3, group="turrets", limits={10}, "ammo-bullets"}, --Gimprovments + ["buggy"] = {priority=3, slots={1,1}, "fuels-all", "ammo-bullets"}, --Gimprovments + ["artillery"] = {priority=3, "ammo-shells"}, -- Artillery + ["burner-generator"] = {group="burners", slots={2}, limits={10}, "fuels-all"}, -- Kspower + ["mega-tank"] = {priority=3, slots={3,1,1}, "fuels-all", "mo-ammo-goliath", "ammo-bullets"}, --MoMods + ["supertank"] = {priority=3, slots={2,1,1}, "fuels-all", "ammo-shells" ,"ammo-bullets"}, --SuperTank + }