My specific use case is to make the AutoFill mod smarter, so it can figure out which ammo items go in which weapons (shotgun shells don't go in gun turrets) and which ones do the most damage.
Here's some code I wrote that would use this feature, if the data were exposed as it currently exists in the prototype lua files:
Code: Select all
updateAmmoArrays = function(tbl)
tbl["ammo-bullets"] = {}
local bul = tbl["ammo-bullets"]
if bul then
for name, item in pairs(game.item_prototypes) do
if item.type == "ammo" then
if item.ammo_type ~= nil then
if item.ammo_type.category == "bullet" then
bul[#bul + 1] = name
end
end
end
end
end
local ammoTotalDamage = function(name)
local item = game.item_prototypes[name]
local d_tot = 0
if item.ammo_type.action then
if item.ammo_type.action.action_delivery then
if item.ammo_type.action.action_delivery.target_effects then
for e in item.ammo_type.action.action_delivery.target_effects do
if e.type == "damage" then
d_tot = d_tot + e.damage.amount
end
end
end
end
end
return d_tot
end
local ammoHighToLow = function(a,b)
return ammoTotalDamage(a) > ammoTotalDamage(b)
end
table.sort(bul, ammoHighToLow)
end