LUADOC - Farming Simulator 22

AIParameterPositionAngle

Parent
AIParameterPosition
Functions

getAngle

Description
Definition
getAngle()
Code
85function AIParameterPositionAngle:getAngle()
86 return self.angle
87end

getDirection

Description
Definition
getDirection()
Code
91function AIParameterPositionAngle:getDirection()
92 if self.angle == nil then
93 return nil, nil
94 end
95
96 local xDir, zDir = MathUtil.getDirectionFromYRotation(self.angle)
97
98 return xDir, zDir
99end

getSnappingAngle

Description
Definition
getSnappingAngle()
Code
109function AIParameterPositionAngle:getSnappingAngle()
110 return self.snappingAngle
111end

getString

Description
Definition
getString()
Code
115function AIParameterPositionAngle:getString()
116 return string.format("< %.1f , %.1f | %d° >", self.x, self.z, math.deg(self.angle))
117end

loadFromXMLFile

Description
Definition
loadFromXMLFile()
Code
38function AIParameterPositionAngle:loadFromXMLFile(xmlFile, key)
39 AIParameterPositionAngle:superClass().loadFromXMLFile(self, xmlFile, key)
40
41 self.angle = xmlFile:getFloat(key .. "#angle", self.angle)
42end

new

Description
Definition
new()
Code
16function AIParameterPositionAngle.new(snappingAngle, customMt)
17 local self = AIParameterPosition.new(customMt or AIParameterPositionAngle_mt)
18
19 self.type = AIParameterType.POSITION_ANGLE
20
21 self.angle = nil
22 self.snappingAngle = math.abs(snappingAngle or math.rad(5))
23
24 return self
25end

readStream

Description
Definition
readStream()
Code
46function AIParameterPositionAngle:readStream(streamId, connection)
47 AIParameterPositionAngle:superClass().readStream(self, streamId, connection)
48
49 if streamReadBool(streamId) then
50 local angle = streamReadUIntN(streamId, 9)
51 self:setAngle(math.rad(angle))
52 end
53end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
29function AIParameterPositionAngle:saveToXMLFile(xmlFile, key, usedModNames)
30 AIParameterPositionAngle:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
31 if self.angle ~= nil then
32 xmlFile:setFloat(key .. "#angle", self.angle)
33 end
34end

setAngle

Description
Definition
setAngle()
Code
68function AIParameterPositionAngle:setAngle(angleRad)
69 angleRad = angleRad % (2*math.pi)
70
71 if angleRad < 0 then
72 angleRad = angleRad + 2*math.pi
73 end
74
75 if self.snappingAngle > 0 then
76 local numSteps = MathUtil.round(angleRad / self.snappingAngle, 0)
77 angleRad = numSteps * self.snappingAngle
78 end
79
80 self.angle = angleRad
81end

setSnappingAngle

Description
Definition
setSnappingAngle()
Code
103function AIParameterPositionAngle:setSnappingAngle(angle)
104 self.snappingAngle = math.abs(angle)
105end

validate

Description
Definition
validate()
Code
121function AIParameterPositionAngle:validate(fillTypeIndex, farmId)
122 local isValid, errorMessage = AIParameterPositionAngle:superClass().validate(self, fillTypeIndex, farmId)
123 if not isValid then
124 return false, errorMessage
125 end
126
127 if self.angle == nil then
128 return false, g_i18n:getText("ai_validationErrorNoAngle")
129 end
130
131 return true, nil
132end

writeStream

Description
Definition
writeStream()
Code
57function AIParameterPositionAngle:writeStream(streamId, connection)
58 AIParameterPositionAngle:superClass().writeStream(self, streamId, connection)
59
60 if streamWriteBool(streamId, self.angle ~= nil) then
61 local angle = math.deg(self.angle)
62 streamWriteUIntN(streamId, angle, 9)
63 end
64end