forked from xyqyear/auto-crossbreeding
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtasks.lua
More file actions
215 lines (202 loc) · 7.12 KB
/
Copy pathtasks.lua
File metadata and controls
215 lines (202 loc) · 7.12 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
local gps = require("gps")
local action = require("action")
local database = require("database")
local scanner = require("scanner")
local posUtil = require("posUtil")
local config = require("config")
local lowestTier
local lowestTierSlot
local lowestStat
local lowestStatSlot
local nearestReplacableDistance
local nearestReplacableSlot
local fillGaps
local function updateLowest()
lowestStat = 64
lowestStatSlot = 0
local farm = database.getFarm()
local workingCropName = database.getFarm()[1].name
for slot=1, config.farmArea, 2 do
local crop = farm[slot]
if crop ~= nil then
local stat = crop.gr+crop.ga-crop.re
if stat < lowestStat then
lowestStat = stat
lowestStatSlot = slot
end
end
end
nearestReplacableSlot = 0
nearestReplacableDistance = config.farmArea * 2
for slot=1, config.farmArea, 2 do
local crop = farm[slot]
if crop ~= nil and crop.name ~= workingCropName then
local pos = posUtil.farmToGlobal(slot)
if (pos[1] + pos[2]) < nearestReplacableDistance then
nearestReplacableDistance = pos[1] + pos[2]
nearestReplacableSlot = slot
end
end
end
end
--[[
This came from autoCrossBred, needs to be renamed or something lated
local function findSuitableFarmSlot(crop)
-- if the return value > 0, then it's a valid crop slot
-- if the return value == 0, then it's not a valid crop slot
-- the caller may consider not to replace any crop.
if crop.tier > lowestTier then
return lowestTierSlot
elseif crop.tier == lowestTier then
if crop.gr+crop.ga-crop.re > lowestStat then
return lowestStatSlot
end
end
return 0
end
]]
local function findSuitableFarmSlot(crop)
if nearestReplacableSlot ~= 0 then
return nearestReplacableSlot
elseif crop.gr+crop.ga-crop.re > lowestStat then
return lowestStatSlot
else
return 0
end
end
local function breedOnce(nonstop)
-- return true if all stats are maxed out
-- 52 = 21(max gr) + 31(max ga) - 0 (min re)
if lowestStat == 52 then
if nonstop == false then
return true
end
end
for slot=2, config.farmSize^2, 2 do
gps.go(posUtil.farmToGlobal(slot))
local crop = scanner.scan()
if crop.name == "air" then
action.placeCropStick(2)
elseif (not config.assumeNoBareStick) and crop.name == "crop" then
action.placeCropStick()
elseif crop.isCrop then
if crop.name == "weed" or crop.gr > 21 or crop.re > 0 or
(crop.name == "venomilia" and crop.gr > 7) then
action.deweed()
action.placeCropStick()
elseif crop.name == database.getFarm()[1].name then
local suitableSlot = findSuitableFarmSlot(crop)
if suitableSlot == 0 then
action.deweed()
action.placeCropStick()
else
action.transplant(posUtil.farmToGlobal(slot), posUtil.farmToGlobal(suitableSlot))
action.placeCropStick(2)
database.updateFarm(suitableSlot, crop)
updateLowest()
end
elseif config.keepNewCropWhileMinMaxing and (not database.existInStorage(crop)) then
action.transplant(posUtil.farmToGlobal(slot), posUtil.storageToGlobal(database.nextStorageSlot()))
action.placeCropStick(2)
database.addToStorage(crop)
else
action.deweed()
action.placeCropStick()
end
end
if action.needCharge() then
action.charge()
end
end
return false
end
local function spreadOnce()
for slot=2, config.farmSize^2, 2 do
gps.go(posUtil.farmToGlobal(slot))
local crop = scanner.scan()
if crop.name == "air" then
action.placeCropStick(2)
elseif (not config.assumeNoBareStick) and crop.name == "crop" then
action.placeCropStick()
elseif crop.isCrop then
if crop.name == "weed" or crop.gr > 23 or
(crop.name == "venomilia" and crop.gr > 7) then
action.deweed()
action.placeCropStick()
elseif crop.name == database.getFarm()[1].name and
(not config.bestStatWhileSpreading or (crop.gr >= 21 and crop.ga == 31 and crop.re == 0)) then
local nextMultifarmPos = database.nextMultifarmPos()
if nextMultifarmPos then
action.transplantToMultifarm(posUtil.farmToGlobal(slot), nextMultifarmPos)
action.placeCropStick(2)
database.updateMultifarm(nextMultifarmPos)
else
return true
end
else
action.deweed()
action.placeCropStick()
end
end
if action.needCharge() then
action.charge()
end
end
return false
end
local function fillGaps(ignorestats, ignorecrops)
-- return true if all the gaps have been filled
-- print("fillGaps called\n")
local fillResult = 0
for slot=2, config.farmSize^2, 2 do
gps.go(posUtil.farmToGlobal(slot))
local crop = scanner.scan()
-- print("crop="..slot..", name=`"..crop.name.."`\n")
if crop.name == "air" then
action.placeCropStick(2)
fillResult = fillResult + 1
-- print("Crop = air\n")
elseif (not config.assumeNoBareStick) and crop.name == "crop" then
action.placeCropStick()
fillResult = fillResult + 1
-- print("Crop = empty\n")
elseif crop.isCrop then
if crop.name == "weed" or
(crop.name == "venomilia" and crop.gr > 7) then
action.deweed()
action.placeCropStick()
fillResult = fillResult + 1
-- print("Crop = weed\n")
elseif (not ignorestats and ( crop.ga ~= 31 or crop.re ~= 0 or crop.gr ~= 21 )) or
(ignorestats and (crop.gr > 21 )) then
action.decrop()
action.placeCropStick()
action.placeCropStick()
fillResult = fillResult + 1
-- print("Crop = wrong stats\n")
elseif ((crop.name == database.getFarm()[1].name) or ignorecrops) then
database.addToFilled(slot)
local ignoreMe = true
-- print("Crop = matched\n")
else
action.deweed()
action.placeCropStick()
fillResult = fillResult + 1
-- print("Crop = unknown\n")
end
end
if action.needCharge() then
action.charge()
end
end
-- print("fillResult=")
-- print(fillResult)
-- print("\n")
return fillResult
end
return {
spreadOnce = spreadOnce,
breedOnce = breedOnce,
updateLowest = updateLowest,
fillGaps = fillGaps
}