LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

AIDriveStrategyStonePicker

Description
drive strategy to - stop when stone picker is full Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
Parent
AIDriveStrategy
Functions

getDriveData

Description
Definition
getDriveData()
Code
48function AIDriveStrategyStonePicker:getDriveData(dt, vX,vY,vZ)
49 local allowedToDrive = true
50 local maxSpeed = math.huge
51
52 for _, stonePicker in pairs(self.stonePickers) do
53 local spec = stonePicker.spec_stonePicker
54 local fillLevel = stonePicker:getFillUnitFillLevel(spec.fillUnitIndex)
55 local capacity = stonePicker:getFillUnitCapacity(spec.fillUnitIndex)
56
57 if stonePicker.getDischargeState ~= nil then
58 if stonePicker:getDischargeState() ~= Dischargeable.DISCHARGE_STATE_OFF then
59 allowedToDrive = false
60
61 local dischargeNode = stonePicker:getCurrentDischargeNode()
62 if dischargeNode ~= nil then
63 local targetObject, _ = stonePicker:getDischargeTargetObject(dischargeNode)
64 if targetObject == nil or fillLevel <= 0 then
65 stonePicker:setDischargeState(Dischargeable.DISCHARGE_STATE_OFF)
66 end
67 end
68 end
69 end
70
71 if stonePicker.getTipState ~= nil then
72 if stonePicker:getTipState() ~= Trailer.TIPSTATE_CLOSED then
73 allowedToDrive = false
74 end
75 end
76
77 if fillLevel >= capacity then
78 allowedToDrive = false
79 if VehicleDebug.state == VehicleDebug.DEBUG_AI then
80 self.vehicle:addAIDebugText(string.format("STONE PICKER -> full"))
81 end
82
83 if self.notificationFullTankShown ~= true then
84 g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_CRITICAL, string.format(g_i18n:getText("ai_messageErrorTankIsFull"), self.vehicle:getCurrentHelper().name) )
85 self.notificationFullTankShown = true
86 end
87
88 if stonePicker.getCurrentDischargeNode ~= nil then
89 local dischargeNode = stonePicker:getCurrentDischargeNode()
90 if dischargeNode ~= nil then
91 local targetObject, _ = stonePicker:getDischargeTargetObject(dischargeNode)
92 if targetObject ~= nil then
93 stonePicker:setDischargeState(Dischargeable.DISCHARGE_STATE_OBJECT)
94 end
95 end
96 end
97 else
98 self.notificationFullTankShown = false
99 end
100 end
101
102 if not allowedToDrive then
103 return 0, 1, true, 0, math.huge
104 else
105 return nil, nil, nil, maxSpeed, nil
106 end
107end

new

Description
Definition
new()
Code
12function AIDriveStrategyStonePicker.new(customMt)
13 if customMt == nil then
14 customMt = AIDriveStrategyStonePicker_mt
15 end
16
17 local self = AIDriveStrategy.new(customMt)
18
19 self.stonePickers = {}
20
21 self.notificationFullTankShown = false
22
23 return self
24end

setAIVehicle

Description
Definition
setAIVehicle()
Code
28function AIDriveStrategyStonePicker:setAIVehicle(vehicle)
29 AIDriveStrategyStonePicker:superClass().setAIVehicle(self, vehicle)
30
31 if SpecializationUtil.hasSpecialization(StonePicker, self.vehicle.specializations) then
32 table.insert(self.stonePickers, self.vehicle)
33 end
34 for _,implement in pairs(self.vehicle:getAttachedAIImplements()) do
35 if SpecializationUtil.hasSpecialization(StonePicker, implement.object.specializations) then
36 table.insert(self.stonePickers, implement.object)
37 end
38 end
39end

update

Description
Definition
update()
Code
43function AIDriveStrategyStonePicker:update(dt)
44end

updateDriving

Description
Definition
updateDriving()
Code
111function AIDriveStrategyStonePicker:updateDriving(dt)
112end