LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

AIDriveStrategyConveyor

Description
Class for a drive strategy for driving forward and backward Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
Parent
AIDriveStrategy
Functions

getDriveData

Description
Definition
getDriveData()
Code
55function AIDriveStrategyConveyor:getDriveData(dt, vX, vY, vZ)
56 local _, y, z = localToLocal(self.vehicle.wheels[self.vehicle.aiConveyorBelt.backWheelIndex].repr, self.vehicle.components[1].node, 0, 0, 0)
57 local worldCX, worldCY, worldCZ = localToWorld(self.vehicle.components[1].node, 0, y, z)
58 local distanceMoved = MathUtil.vector2Length(worldCX-self.lastPos[1], worldCZ-self.lastPos[3])
59
60 self.distanceMoved = self.distanceMoved + distanceMoved
61 self.lastPos = {worldCX, worldCY, worldCZ}
62
63 if self.distanceMoved >= self.distanceToMove then
64 if self.fistTimeChange then
65 self.distanceToMove = self.distanceToMove * 2
66 self.fistTimeChange = false
67 end
68
69 self.distanceMoved = 0
70 if self.currentTarget == 1 then
71 self.currentTarget = 2
72 else
73 self.currentTarget = 1
74 end
75 end
76
77 local speedFactor = MathUtil.clamp(math.sin(self.distanceMoved/self.distanceToMove*3.14), 0.1, 0.5)*2
78
79 local dir = true
80 if self.currentTarget == 2 then
81 dir = not dir
82 end
83 return self.worldTarget[self.currentTarget][1], self.worldTarget[self.currentTarget][3], dir, self.vehicle.aiConveyorBelt.speed*speedFactor, 100
84end

new

Description
Definition
new()
Code
11function AIDriveStrategyConveyor:new(customMt)
12 if customMt == nil then
13 customMt = AIDriveStrategyConveyor_mt
14 end
15
16 local self = AIDriveStrategy:new(customMt)
17
18 return self
19end

setAIVehicle

Description
Definition
setAIVehicle()
Code
23function AIDriveStrategyConveyor:setAIVehicle(vehicle)
24 AIDriveStrategyConveyor:superClass().setAIVehicle(self, vehicle)
25
26 local _, y, z = localToLocal(self.vehicle.wheels[self.vehicle.aiConveyorBelt.backWheelIndex].repr, self.vehicle.components[1].node, 0, 0, 0)
27 local x1, y1, z1 = localToWorld(self.vehicle.components[1].node, 0, y, z)
28 local x2, y2, z2 = getWorldTranslation(self.vehicle.wheels[self.vehicle.aiConveyorBelt.centerWheelIndex].repr)
29
30 local length = MathUtil.vector3Length(x1-x2, y1-y2, z1-z2)
31 local width = length * math.sin(math.rad(self.vehicle.aiConveyorBelt.currentAngle/2))
32 local length2 = math.sqrt(math.pow(length, 2)-math.pow(width, 2))
33
34 self.distanceToMove = math.rad(self.vehicle.aiConveyorBelt.currentAngle)*length/2
35
36 self.currentTarget = 1
37
38 self.worldTarget = {}
39 self.worldTarget[1] = {localToWorld(self.vehicle.wheels[self.vehicle.aiConveyorBelt.centerWheelIndex].repr, width, 0, -length2)}
40 self.worldTarget[2] = {localToWorld(self.vehicle.wheels[self.vehicle.aiConveyorBelt.centerWheelIndex].repr, -width, 0, -length2)}
41
42 self.lastPos = {x1, y1, z1}
43
44 self.distanceMoved = 0
45 self.fistTimeChange = true
46end

update

Description
Definition
update()
Code
50function AIDriveStrategyConveyor:update(dt)
51end