LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

AIDriveStrategyBaler

Description
drive strategy to - automatic bale dropping while ai is active Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
Parent
AIDriveStrategy
Functions

getDriveData

Description
Definition
getDriveData()
Code
49function AIDriveStrategyBaler:getDriveData(dt, vX,vY,vZ)
50 local allowedToDrive = true
51 local maxSpeed = math.huge
52
53 for _, baler in pairs(self.balers) do
54 local spec = baler.spec_baler
55
56 if not spec.nonStopBaling then
57 local fillLevel = baler:getFillUnitFillLevel(spec.fillUnitIndex)
58 local capacity = baler:getFillUnitCapacity(spec.fillUnitIndex)
59
60 local freeFillLevel = capacity - fillLevel
61 if freeFillLevel < self.slowDownFillLevel then
62 -- we want to drive at least 2 km/h to avoid baler stops too early
63 maxSpeed = 2 + (freeFillLevel / self.slowDownFillLevel) * self.slowDownStartSpeed
64
65 if VehicleDebug.state == VehicleDebug.DEBUG_AI then
66 self.vehicle:addAIDebugText(string.format("BALER -> Slow down because nearly full: %.2f", maxSpeed))
67 end
68 end
69
70 if fillLevel == capacity or spec.unloadingState ~= Baler.UNLOADING_CLOSED then
71 allowedToDrive = false
72 end
73 else
74 if spec.platformDropInProgress then
75 maxSpeed = spec.platformAIDropSpeed
76
77 if VehicleDebug.state == VehicleDebug.DEBUG_AI then
78 self.vehicle:addAIDebugText(string.format("BALER -> Platform dropping active, reducing speed to %.1f km/h", spec.platformAIDropSpeed))
79 end
80 end
81 end
82 end
83
84 if not allowedToDrive then
85 return 0, 1, true, 0, math.huge
86 else
87 return nil, nil, nil, maxSpeed, nil
88 end
89end

new

Description
Definition
new()
Code
12function AIDriveStrategyBaler.new(customMt)
13 if customMt == nil then
14 customMt = AIDriveStrategyBaler_mt
15 end
16
17 local self = AIDriveStrategy.new(customMt)
18
19 self.balers = {}
20
21 self.slowDownFillLevel = 200
22 self.slowDownStartSpeed = 20
23
24 return self
25end

setAIVehicle

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

update

Description
Definition
update()
Code
44function AIDriveStrategyBaler:update(dt)
45end

updateDriving

Description
Definition
updateDriving()
Code
93function AIDriveStrategyBaler:updateDriving(dt)
94end