Skip to content

Commit

Permalink
1.4.1 - Some logic fixes, some ooopsie fixes, more tanks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nexela committed Jul 27, 2016
1 parent 11ff74a commit 8f69386
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 88 deletions.
65 changes: 37 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 7 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
60 changes: 36 additions & 24 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) ) )
Expand Down Expand Up @@ -310,24 +318,28 @@ 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 }
end
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

Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "autofill",
"version": "1.4.0",
"version": "1.4.1",
"factorio_version": "0.13",
"title": "Autofill",
"author": "rk84, Nexela",
Expand Down
51 changes: 31 additions & 20 deletions loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +34,7 @@ loader = {
else
backup_log[#backup_log + 1] = "Array '" .. name .. "' not found in '" .. path .. "'"
end

end
end,

Expand All @@ -61,7 +61,7 @@ loader = {
end
end
end,

getBackupLog = function()
return backup_log
end,
Expand All @@ -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"
Expand All @@ -101,20 +112,20 @@ 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
backup_log[#backup_log + 1] = "Extension for array '" .. name .. "' removed"
extension_items[name] = nil
end
end

-- Add item extensions to item_arrays
local tbl = table
local array
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -218,4 +229,4 @@ loader = {
table.sort(high, fuelHighToLow)
backup_log[#backup_log + 1] = "Updating Fuel Arrays"
end
}
}
Loading

0 comments on commit 8f69386

Please sign in to comment.