-
Notifications
You must be signed in to change notification settings - Fork 0
/
stocksfuncs.lua
169 lines (144 loc) · 3.78 KB
/
stocksfuncs.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
-- a script for monitoring stockpiles, this is a holder for functions
utils = require('utils')
args = {...}
-------------------
-- FUNCTIONS
----------------------
---------------------------
function get_type(item)
return string.match(tostring(item._type),"<type: item_(.+)st>"):lower()
end
---------------------------
function get_all_items()
--print('start function')
local utils = require('utils')
piles = {}
shops = {}
for k, v in ipairs(df.global.world.buildings.all) do
local str = utils.getBuildingName(v)
if string.find(str, "Stockpile") then
table.insert(piles, v)
else
--if its not a stockpile, its a building.
--should i call buildings by name or fuckit.
table.insert(shops, v)
end
end
--now we have all buildings and stockpiles.
for i, pile in ipairs(piles) do
--print(utils.getBuildingName(pile))
end
--lets see whats inside
allstored = {}
for i, pile in ipairs(piles) do
--inside the stockpiles..
local contents = dfhack.buildings.getStockpileContents(pile)
for j, item in ipairs(contents) do
--if item is a bin, look in the bin
--print(item)
local itemname = get_type(item)
if itemname == "bin" or itemname == "barrel" then
local bincon = dfhack.items.getContainedItems(item)
for k, v in ipairs(bincon) do
table.insert(allstored, v)
end
else
table.insert(allstored, item)
end
end
end
--for i, item in ipairs(allstored) do
-- print(item)
--end
--print('hit')
return allstored
end
------for counting bars and ores
function count_each(list)
types = {}
--table.insert(temp, list[0])
--print(temp)
for i, item in ipairs(list) do
g = dfhack.matinfo.decode(item).material.state_name.Solid
--print(g)
a = check_list(g, types)
if a == false then
table.insert(types, item)
end
end
for i, item in ipairs(types) do
g = dfhack.matinfo.decode(item).material.state_name.Solid
--print(g)
end
counts = run_numbers(types, list)
return counts
end
function check_list(item, types)
isin = false
for i, j in ipairs(types) do
--print(item)
h = dfhack.matinfo.decode(j).material.state_name.Solid
if g == h then
--print('found')
isin = true
end
end
return isin
end
function run_numbers(types, list)
counts = {}
for i, j in ipairs(types) do
num = 0;
mw = 0;
g = dfhack.matinfo.decode(j).material.state_name.Solid
--print(g..' check against')
for k, v in ipairs(list) do
h = dfhack.matinfo.decode(v).material.state_name.Solid
-- print(h)
if g == h then
num = num + 1;
--print('found match')
end
if v.getQuality(v) >= 5 then
mw = mw + 1;
end
end
str = g..' '..num..' | '..mw..'*';
--print(str)
table.insert(counts, str)
--print(g..' done')
end
for i, j in ipairs(counts) do
--print(j)
end
return counts
end
function get_ores()
--local b = dfhack.script_environment('stocksfuncs').get_all_items()
ores = {}
for i, item in ipairs(b) do
c = dfhack.script_environment('stocksfuncs').get_type(item)
if c == "boulder" then
mat = dfhack.matinfo.decode(item)
p = df.global.world.raws.inorganics[mat.index].metal_ore.mat_index
count = 0
ore = false
for x,y in ipairs(p) do
count = count + 1
end
if count > 0 then
ore = true
end
if ore == true then
table.insert(ores, item)
d = item
g = dfhack.matinfo.decode(item).material.state_name.Solid
end
end
end
--all ores retrieved, now sort and display
c = dfhack.script_environment('stocksfuncs').count_each(ores)
--print(c)
end
--------------------------------------
--end of bars and ores functions.