-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspread.lua
More file actions
121 lines (116 loc) · 3.11 KB
/
spread.lua
File metadata and controls
121 lines (116 loc) · 3.11 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
local function AvailiblePlace()
for j = 1, 3 do
for i = 1, fieldLength do
if (i + j) % 2 == 1 and field[i][j] == "empty" then
return true
end
end
end
return false
end
local function PlaceSticks()
for j = 1, 3 do
for i = 1, fieldLength do
if farm.IsValidPlaceSticks(i, j) then
nav.MoveTo(i, j)
farm.PlaceSticks()
farm.PlaceSticks()
field[i][j] = "sticks"
end
end
end
end
local function PlaceNewCrop(slot, delta)
for j = 1, 3 do
for i = 1, fieldLength do
if (i + j) % 2 == 1 and field[i][j] == "empty" then
nav.MoveTo(i, j)
farm.PlaceSticks()
r.select(slot)
r.place(0)
plantCount = plantCount + 1
field[i][j] = delta
farm.CalculateAvgDelta()
return true
end
end
end
return false
end
local function CheckCrops()
misc.SetColor("care")
emptySpace = true
for j = 1, 3 do
for i = (j % 2 == 0 and fieldLength or 1),
(j % 2 == 0 and 1 or fieldLength),
(j % 2 == 0 and -1 or 1) do
if field[i][j] == "sticks" then
nav.MoveTo(i, j)
raw = s.analyze(0)
scan = farm.AnalyzeScan(raw)
if scan == "weed" then farm.RemoveWeed() end
if scan == "seedbag" then farm.AnotherSeedbag() end
if tonumber(scan) ~= nil then
if maxDelta > farm.CalculateDelta(raw) then
if raw["crop:size"] == maxStage then
r.swing(0)
farm.PlaceSticks()
farm.PlaceSticks()
slots = inv.SeedSlots()
for c = 1, #slots do
emptySpace = PlaceNewCrop(slots[c], farm.CalculateDelta(raw))
end
PlaceSticks()
end
else
r.swing(0)
farm.PlaceSticks()
farm.PlaceSticks()
slots = inv.SeedSlots()
for c = 1, #slots do
r.select(slots[c])
r.drop(0)
end
end
end
end
end
end
return emptySpace
end
local function Start()
misc.SetColor("scan")
skip = true
plantCount = 0
print("Spread mode")
for j = 1, 3 do
for i = (j % 2 == 0 and fieldLength or 1),
(j % 2 == 0 and 1 or fieldLength),
(j % 2 == 0 and -1 or 1) do
nav.MoveTo(i, j)
field[i][j] = farm.AnalyzeScan(s.analyze(0))
if field[i][j] == "weed" then farm.RemoveWeed() field[i][j] = "sticks" end
if field[i][j] == "seedbag" then farm.AnotherSeedbag() field[i][j] = "sticks" end
if farm.IsDelta(i, j) then
if j <= 3 and i <= 3 and (i + j) % 2 == 0 then
field[i][j] = "sticks"
else plantCount = plantCount + 1 end
end
end
end
farm.CalculateAvgDelta()
PlaceSticks()
if AvailiblePlace() then
while CheckCrops() do misc.Charge() end
end
slots = inv.SeedSlots()
for c = 1, #slots do
r.select(slots[c])
r.drop(0)
end
print("Spread complete")
end
spread = {
Start = Start
}
return spread