LUADOC - Farming Simulator 19

TipOccluder

Description
Specialization allowing vehicles to prevent tipping filltypes in specified areas (e.g. below wheels)
Functions

finalizeWheel

Description
Definition
finalizeWheel()
Code
105function TipOccluder:finalizeWheel(superFunc, wheel, parentWheel)
106 superFunc(self, wheel, parentWheel)
107
108 local spec = self.spec_tipOccluder
109 if wheel.tipOcclusionAreaGroupId ~= nil then
110 local vehicleRootNode = self.components[1].node
111 local doCreate = true
112 local area
113 for groupId, occluderArea in pairs(spec.createdTipOcclusionAreaGroupIds) do
114 if groupId == wheel.tipOcclusionAreaGroupId then
115 doCreate = false
116 area = occluderArea
117 break
118 end
119 end
120
121 -- the first wheel with the group id creates the area, the other just recalculate the area
122 if doCreate then
123 local start = createTransformGroup(string.format("tipOcclusionAreaGroupId%d", wheel.tipOcclusionAreaGroupId))
124 local width = createTransformGroup(string.format("tipOcclusionAreaGroupId%d", wheel.tipOcclusionAreaGroupId))
125 local height = createTransformGroup(string.format("tipOcclusionAreaGroupId%d", wheel.tipOcclusionAreaGroupId))
126 link(vehicleRootNode, start)
127 link(vehicleRootNode, width)
128 link(vehicleRootNode, height)
129
130 area = {start=start, width=width, height=height}
131 table.insert(spec.tipOcclusionAreas, area)
132 spec.createdTipOcclusionAreaGroupIds[wheel.tipOcclusionAreaGroupId] = area
133 end
134
135 if area ~= nil then
136 local xMax = -math.huge
137 local xMin = math.huge
138 local zMax = -math.huge
139 local zMin = math.huge
140
141 -- get other wheels with the same area group id
142 local usedWheels = self:getWheelsWithTipOcclisionAreaGroupId(self:getWheels(), wheel.tipOcclusionAreaGroupId)
143
144 -- also include myself into the calculation
145 table.insert(usedWheels, wheel)
146
147 for _,usedWheel in pairs(usedWheels) do
148 local x,_,z = localToLocal(usedWheel.driveNode, vehicleRootNode, usedWheel.wheelshapeWidth - 0.5 * usedWheel.width, 0, -usedWheel.radius)
149 xMax = math.max(x, xMax)
150 zMin = math.min(z, zMin)
151 x,_,z = localToLocal(usedWheel.driveNode, vehicleRootNode, -usedWheel.wheelshapeWidth + 0.5 * usedWheel.width, 0, usedWheel.radius)
152 xMin = math.min(x, xMin)
153 zMax = math.max(z, zMax)
154 end
155
156 setTranslation(area.start, xMax,0,zMin)
157 setTranslation(area.width, xMin,0,zMin)
158 setTranslation(area.height, xMax,0,zMax)
159 end
160 end
161end

getRequiresTipOcclusionArea

Description
Definition
getRequiresTipOcclusionArea()
Code
99function TipOccluder:getRequiresTipOcclusionArea()
100 return false
101end

getTipOcclusionAreas

Description
Definition
getTipOcclusionAreas()
Code
71function TipOccluder:getTipOcclusionAreas()
72 return self.spec_tipOccluder.tipOcclusionAreas
73end

getWheelsWithTipOcclisionAreaGroupId

Description
Definition
getWheelsWithTipOcclisionAreaGroupId()
Code
77function TipOccluder:getWheelsWithTipOcclisionAreaGroupId(wheels, groupId)
78 local returnWheels = {}
79 for _,wheel in pairs(wheels) do
80 if wheel.tipOcclusionAreaGroupId == groupId then
81 table.insert(returnWheels, wheel)
82 end
83 end
84 return returnWheels
85end

onLoad

Description
Definition
onLoad()
Code
43function TipOccluder:onLoad(savegame)
44 local spec = self.spec_tipOccluder
45
46 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.tipOcclusionAreas.tipOcclusionArea", "vehicle.tipOccluder.occlusionArea") --FS17 to FS19
47
48 -- load tip occlusion areas
49 spec.tipOcclusionAreas = {}
50 local i = 0
51 while true do
52 local key = string.format("vehicle.tipOccluder.occlusionArea(%d)", i)
53 if not hasXMLProperty(self.xmlFile, key) then
54 break
55 end
56 local entry = {}
57 entry.start = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, key .. "#start"), self.i3dMappings)
58 entry.width = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, key .. "#width"), self.i3dMappings)
59 entry.height = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, key .. "#height"), self.i3dMappings)
60 if entry.start ~= nil and entry.width ~= nil and entry.height ~= nil then
61 table.insert(spec.tipOcclusionAreas, entry)
62 end
63 i = i + 1
64 end
65
66 spec.createdTipOcclusionAreaGroupIds = {}
67end

onPostLoad

Description
Definition
onPostLoad()
Code
89function TipOccluder:onPostLoad()
90 if self:getRequiresTipOcclusionArea() then
91 if table.getn(self.spec_tipOccluder.tipOcclusionAreas) == 0 then
92 g_logManager:xmlDevWarning(self.configFileName, "No TipOcclusionArea defined")
93 end
94 end
95end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
16function TipOccluder.prerequisitesPresent(specializations)
17 return true
18end

registerEventListeners

Description
Definition
registerEventListeners()
Code
36function TipOccluder.registerEventListeners(vehicleType)
37 SpecializationUtil.registerEventListener(vehicleType, "onLoad", TipOccluder)
38 SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", TipOccluder)
39end

registerFunctions

Description
Definition
registerFunctions()
Code
22function TipOccluder.registerFunctions(vehicleType)
23 SpecializationUtil.registerFunction(vehicleType, "getTipOcclusionAreas", TipOccluder.getTipOcclusionAreas)
24 SpecializationUtil.registerFunction(vehicleType, "getWheelsWithTipOcclisionAreaGroupId", TipOccluder.getWheelsWithTipOcclisionAreaGroupId)
25 SpecializationUtil.registerFunction(vehicleType, "getRequiresTipOcclusionArea", TipOccluder.getRequiresTipOcclusionArea)
26end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
30function TipOccluder.registerOverwrittenFunctions(vehicleType)
31 SpecializationUtil.registerOverwrittenFunction(vehicleType, "finalizeWheel", TipOccluder.finalizeWheel)
32end