This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 528
/
BunkerSiloLoaderAIDriver.lua
119 lines (94 loc) · 4 KB
/
BunkerSiloLoaderAIDriver.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
--[[
This file is part of Courseplay (https://github.com/Courseplay/courseplay)
Copyright (C) 2021 Courseplay Dev team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]
---@class BunkerSiloLoaderAIDriver : BunkerSiloAIDriver
BunkerSiloLoaderAIDriver = CpObject(BunkerSiloAIDriver)
function BunkerSiloLoaderAIDriver:init(vehicle)
BunkerSiloAIDriver.init(self,vehicle)
self.shovel = AIDriverUtil.getImplementWithSpecialization(self.vehicle,Shovel) or self.vehicle
self.shovelSpec = self.shovel.spec_shovel
self.dischargeObject = AIDriverUtil.getImplementWithSpecialization(self.vehicle,Dischargeable) or self.vehicle
self.dischargeSpec = self.dischargeObject.spec_dischargeable
self.currentDischargeNode = self.dischargeObject:getCurrentDischargeNode()
self.mode = courseplay.MODE_SHOVEL_FILL_AND_EMPTY
end
function BunkerSiloLoaderAIDriver:setHudContent()
BunkerSiloAIDriver.setHudContent(self)
courseplay.hud:setBunkerSiloLoaderAIDriverContent(self.vehicle)
end
function BunkerSiloLoaderAIDriver:start(startingPoint)
self:changeSiloState(self.states.CHECK_SILO)
--- Remember the old giants setup
self.canStartDischargeAutomatically = self.currentDischargeNode.canStartDischargeAutomatically
self.oldCanDischargeToGround = self.currentDischargeNode.canDischargeToGround
self.currentDischargeNode.canStartDischargeAutomatically = true
self.currentDischargeNode.canDischargeToGround = false
BunkerSiloAIDriver.start(self,startingPoint)
end
function BunkerSiloLoaderAIDriver:stop(msg)
--- Reset the old giants setup
self.currentDischargeNode.canStartDischargeAutomatically = self.canStartDischargeAutomatically
self.currentDischargeNode.canDischargeToGround = self.oldCanDischargeToGround
self.canStartDischargeAutomatically = nil
self.oldCanDischargeToGround = nil
BunkerSiloAIDriver.stop(self,msg)
end
function BunkerSiloLoaderAIDriver:getTargetNode()
return self.shovelSpec.shovelNodes[1].node
end
function BunkerSiloLoaderAIDriver:isDriveDirectionReverse()
return false
end
function BunkerSiloAIDriver:isEmptySiloAllowed()
return false
end
function BunkerSiloLoaderAIDriver:beforeDriveIntoSilo()
self.vehicle:raiseAIEvent("onAIStart", "onAIImplementStart")
self.vehicle:aiImplementStartLine()
self.vehicle:requestActionEventUpdate()
BunkerSiloAIDriver.beforeDriveIntoSilo(self)
end
function BunkerSiloLoaderAIDriver:beforeDriveOutOfSilo()
self.vehicle:raiseAIEvent("onAIEnd", "onAIImplementEnd")
self.vehicle:aiImplementEndLine()
self.vehicle:requestActionEventUpdate()
BunkerSiloAIDriver.beforeDriveOutOfSilo(self)
end
function BunkerSiloLoaderAIDriver:driveIntoSilo(dt)
if not self:getIsMovingAllowed() then
self:hold()
end
BunkerSiloAIDriver.driveIntoSilo(self,dt)
end
function BunkerSiloLoaderAIDriver:isHeapSearchAllowed()
return true
end
--- Can the driver continue driving into the silo/heap ?
function BunkerSiloLoaderAIDriver:getIsMovingAllowed()
local isUnloading = self.dischargeSpec.currentDischargeState ~= Dischargeable.DISCHARGE_STATE_OFF
if not isUnloading then
self:setInfoText("WAITING_FOR_UNLOADERS")
end
return self.shovelSpec.loadingFillType == FillType.UNKNOWN and (isUnloading or self.shovel:getFillUnitFillLevel(1) < 0.02)
end
--- Let the driver reverse a bit to have more room for driving into the silo.
function BunkerSiloLoaderAIDriver:isStartDistanceToSiloNeeded()
return true
end
--- Overwritten to disable this.
function BunkerSiloLoaderAIDriver:isStuck()
end
function BunkerSiloLoaderAIDriver:getBunkerSiloSpeed()
return 2
end