LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

LivestockTrailer

Description
Specialization for livestrock trailers with animals as cargo
Functions

addAnimals

Description
Definition
addAnimals()
Code
279function LivestockTrailer:addAnimals(subTypeIndex, numAnimals, age)
280 local cluster = g_currentMission.animalSystem:createClusterFromSubTypeIndex(subTypeIndex)
281 if cluster:getSupportsMerging() then
282 cluster.numAnimals = numAnimals
283 cluster.age = age
284 self:addCluster(cluster)
285 else
286 for i=1, numAnimals do
287 if i > 1 then
288 cluster = g_currentMission.animalSystem:createClusterFromSubTypeIndex(subTypeIndex)
289 end
290 cluster.numAnimals = 1
291 cluster.age = age
292 self:addCluster(cluster)
293 end
294 end
295end

addCluster

Description
Definition
addCluster()
Code
299function LivestockTrailer:addCluster(cluster)
300 local spec = self.spec_livestockTrailer
301
302 spec.clusterSystem:addPendingAddCluster(cluster)
303 spec.clusterSystem:updateNow()
304end

clearAnimals

Description
Definition
clearAnimals()
Code
433function LivestockTrailer:clearAnimals()
434 local spec = self.spec_livestockTrailer
435 if spec.animalTypeIndexToPlaces ~= nil then
436 for _, place in pairs(spec.animalTypeIndexToPlaces) do
437 for _, slot in ipairs(place.slots) do
438 if slot.sharedLoadRequestId ~= nil then
439 g_i3DManager:releaseSharedI3DFile(slot.sharedLoadRequestId)
440 slot.sharedLoadRequestId = nil
441 end
442 if slot.loadedMesh ~= nil then
443 delete(slot.loadedMesh)
444 slot.loadedMesh = nil
445 end
446 end
447 end
448 end
449end

dayChanged

Description
Definition
dayChanged()
Code
508function LivestockTrailer:dayChanged(superFunc)
509 superFunc(self)
510
511 local spec = self.spec_livestockTrailer
512 local clusters = spec.clusterSystem:getClusters()
513 for _, cluster in ipairs(clusters) do
514 cluster:onDayChanged()
515 end
516end

getAdditionalComponentMass

Description
Definition
getAdditionalComponentMass()
Code
473function LivestockTrailer:getAdditionalComponentMass(superFunc, component)
474 local additionalMass = superFunc(self, component)
475 local spec = self.spec_livestockTrailer
476
477 local clusters = spec.clusterSystem:getClusters()
478 for _, cluster in ipairs(clusters) do
479 local subTypeIndex = cluster:getSubTypeIndex()
480 local subType = g_currentMission.animalSystem:getSubTypeByIndex(subTypeIndex)
481 local fillTypeIndex = subType.fillTypeIndex
482 local fillType = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex)
483
484 additionalMass = additionalMass + (fillType.massPerLiter * cluster:getNumAnimals())
485 end
486
487 return additionalMass
488end

getAnimalUnloadPlaces

Description
Definition
getAnimalUnloadPlaces()
Code
573function LivestockTrailer:getAnimalUnloadPlaces()
574 local spec = self.spec_livestockTrailer
575 local places = {}
576
577 for _, spawnPlace in ipairs(spec.spawnPlaces) do
578 local node = spawnPlace.node
579 local x, y, z = getWorldTranslation(node)
580
581 local place = {}
582 place.startX, place.startY, place.startZ = x, y, z
583 place.rotX, place.rotY, place.rotZ = getWorldRotation(node)
584 place.dirX, place.dirY, place.dirZ = localDirectionToWorld(node, 1, 0, 0)
585 place.dirPerpX, place.dirPerpY, place.dirPerpZ = localDirectionToWorld(node, 0, 0, 1)
586 place.yOffset = 1
587 place.maxWidth = math.huge
588 place.maxLength = math.huge
589 place.maxHeight = math.huge
590 place.width = spawnPlace.width
591
592 table.insert(places, place)
593 end
594
595
596 return places
597end

getClusterById

Description
Definition
getClusterById()
Code
322function LivestockTrailer:getClusterById(id)
323 local spec = self.spec_livestockTrailer
324 return spec.clusterSystem:getClusterById(id)
325end

getClusters

Description
Definition
getClusters()
Code
308function LivestockTrailer:getClusters()
309 local spec = self.spec_livestockTrailer
310 return spec.clusterSystem:getClusters()
311end

getClusterSystem

Description
Definition
getClusterSystem()
Code
329function LivestockTrailer:getClusterSystem()
330 local spec = self.spec_livestockTrailer
331 return spec.clusterSystem
332end

getCurrentAnimalType

Description
Definition
getCurrentAnimalType()
Code
245function LivestockTrailer:getCurrentAnimalType()
246 local spec = self.spec_livestockTrailer
247 local clusters = spec.clusterSystem:getClusters()
248 if #clusters == 0 then
249 return nil
250 end
251
252 local animalSystem = g_currentMission.animalSystem
253 local subTypeIndex = clusters[1]:getSubTypeIndex()
254 local subType = animalSystem:getSubTypeByIndex(subTypeIndex)
255 local animalType = animalSystem:getTypeByIndex(subType.typeIndex)
256 return animalType
257end

getLoadingTrigger

Description
Definition
getLoadingTrigger()
Code
267function LivestockTrailer:getLoadingTrigger()
268 return self.spec_livestockTrailer.loadingTrigger
269end

getMaxNumOfAnimals

Description
Definition
getMaxNumOfAnimals()
Code
353function LivestockTrailer:getMaxNumOfAnimals(animalType)
354 local spec = self.spec_livestockTrailer
355
356 local currentAnimalType = self:getCurrentAnimalType()
357 if animalType == nil and currentAnimalType == nil then
358 return 0
359 end
360
361 if currentAnimalType ~= nil and animalType ~= currentAnimalType then
362 return 0
363 end
364
365 animalType = animalType or currentAnimalType
366
367 if not self:getSupportsAnimalType(animalType.typeIndex) then
368 return 0
369 end
370
371 local place = spec.animalTypeIndexToPlaces[animalType.typeIndex]
372 return #place.slots
373end

getNumOfAnimals

Description
Definition
getNumOfAnimals()
Code
336function LivestockTrailer:getNumOfAnimals()
337 local spec = self.spec_livestockTrailer
338
339 local clusters = spec.clusterSystem:getClusters()
340 if #clusters == 0 then
341 return 0
342 end
343
344 local subTypeIndex = clusters[1]:getSubTypeIndex()
345 local subType = g_currentMission.animalSystem:getSubTypeByIndex(subTypeIndex)
346
347 local place = spec.animalTypeIndexToPlaces[subType.typeIndex]
348 return place.usedSlots or 0
349end

getNumOfFreeAnimalSlots

Description
Definition
getNumOfFreeAnimalSlots()
Code
377function LivestockTrailer:getNumOfFreeAnimalSlots(subTypeIndex)
378 local animalSystem = g_currentMission.animalSystem
379 local subType = animalSystem:getSubTypeByIndex(subTypeIndex)
380 local animalType = animalSystem:getTypeByIndex(subType.typeIndex)
381
382 local used = self:getNumOfAnimals()
383 local total = self:getMaxNumOfAnimals(animalType)
384 return total - used
385end

getRideablesInTrigger

Description
Definition
getRideablesInTrigger()
Code
315function LivestockTrailer:getRideablesInTrigger()
316 local spec = self.spec_livestockTrailer
317 return spec.rideablesInTrigger
318end

getSellPrice

Description
Definition
getSellPrice()
Code
492function LivestockTrailer:getSellPrice(superFunc)
493 local sellPrice = superFunc(self)
494
495 local spec = self.spec_livestockTrailer
496 local clusters = spec.clusterSystem:getClusters()
497 for _, cluster in ipairs(clusters) do
498 local sellPriceCluster = cluster:getSellPrice() * cluster:getNumAnimals()
499
500 sellPrice = sellPrice + (sellPriceCluster * 0.75)
501 end
502
503 return sellPrice
504end

getSpecValueNumberAnimals

Description
Definition
getSpecValueNumberAnimals()
Code
649function LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, specName)
650 if storeItem.specs[specName] == nil then
651 return nil
652 end
653 return string.format("%d %s", storeItem.specs[specName], g_i18n:getText("unit_pieces"))
654end

getSpecValueNumberAnimalsCow

Description
Definition
getSpecValueNumberAnimalsCow()
Code
658function LivestockTrailer.getSpecValueNumberAnimalsCow(storeItem, realItem)
659 return LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, "numAnimalsCow")
660end

getSpecValueNumberAnimalsHorse

Description
Definition
getSpecValueNumberAnimalsHorse()
Code
676function LivestockTrailer.getSpecValueNumberAnimalsHorse(storeItem, realItem)
677 return LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, "numAnimalsHorse")
678end

getSpecValueNumberAnimalsPig

Description
Definition
getSpecValueNumberAnimalsPig()
Code
664function LivestockTrailer.getSpecValueNumberAnimalsPig(storeItem, realItem)
665 return LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, "numAnimalsPig")
666end

getSpecValueNumberAnimalsSheep

Description
Definition
getSpecValueNumberAnimalsSheep()
Code
670function LivestockTrailer.getSpecValueNumberAnimalsSheep(storeItem, realItem)
671 return LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, "numAnimalsSheep")
672end

getSupportsAnimalSubType

Description
Definition
getSupportsAnimalSubType()
Code
235function LivestockTrailer:getSupportsAnimalSubType(subTypeIndex)
236 local animalSystem = g_currentMission.animalSystem
237 local subType = animalSystem:getSubTypeByIndex(subTypeIndex)
238 local animalType = animalSystem:getTypeByIndex(subType.typeIndex)
239
240 return self:getSupportsAnimalType(animalType.typeIndex)
241end

getSupportsAnimalType

Description
Definition
getSupportsAnimalType()
Code
229function LivestockTrailer:getSupportsAnimalType(animalTypeIndex)
230 return self.spec_livestockTrailer.animalTypeIndexToPlaces[animalTypeIndex] ~= nil
231end

initSpecialization

Description
Definition
initSpecialization()
Code
15function LivestockTrailer.initSpecialization()
16 g_storeManager:addSpecType("numAnimalsCow", "shopListAttributeIconCow", LivestockTrailer.loadSpecValueNumberAnimalsCow, LivestockTrailer.getSpecValueNumberAnimalsCow, "vehicle")
17 g_storeManager:addSpecType("numAnimalsPig", "shopListAttributeIconPig", LivestockTrailer.loadSpecValueNumberAnimalsPig, LivestockTrailer.getSpecValueNumberAnimalsPig, "vehicle")
18 g_storeManager:addSpecType("numAnimalsSheep", "shopListAttributeIconSheep", LivestockTrailer.loadSpecValueNumberAnimalsSheep, LivestockTrailer.getSpecValueNumberAnimalsSheep, "vehicle")
19 g_storeManager:addSpecType("numAnimalsHorse", "shopListAttributeIconHorse", LivestockTrailer.loadSpecValueNumberAnimalsHorse, LivestockTrailer.getSpecValueNumberAnimalsHorse, "vehicle")
20
21 local schema = Vehicle.xmlSchema
22 schema:setXMLSpecializationType("LivestockTrailer")
23
24 schema:register(XMLValueType.STRING, "vehicle.livestockTrailer.animal(?)#type", "Animal type name")
25 schema:register(XMLValueType.NODE_INDEX, "vehicle.livestockTrailer.animal(?)#node", "Animal node")
26 schema:register(XMLValueType.INT, "vehicle.livestockTrailer.animal(?)#numSlots", "Number of slots")
27 schema:register(XMLValueType.NODE_INDEX, "vehicle.livestockTrailer.loadTrigger#node", "Load trigger node")
28 schema:register(XMLValueType.NODE_INDEX, "vehicle.livestockTrailer.spawnPlaces.spawnPlace(?)#node", "Unload spawn places")
29 schema:register(XMLValueType.FLOAT, "vehicle.livestockTrailer.spawnPlaces.spawnPlace(?)#width", "Unloading width", 15)
30
31 schema:setXMLSpecializationType()
32
33 local savegameSchema = Vehicle.xmlSchemaSavegame
34 savegameSchema:register(XMLValueType.STRING, "vehicles.vehicle(?).livestockTrailer#animalType", "Animal type name")
35 AnimalClusterSystem.registerSavegameXMLPaths(savegameSchema, "vehicles.vehicle(?).livestockTrailer")
36end

loadSpecValueNumberAnimals

Description
Definition
loadSpecValueNumberAnimals()
Code
601function LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, animalTypeName)
602 local maxNumAnimals = nil
603 local i = 0
604 local root = xmlFile:getRootName()
605 while true do
606 local key = string.format("%s.livestockTrailer.animal(%d)", root, i)
607 if not xmlFile:hasProperty(key) then
608 break
609 end
610
611 local typeName = xmlFile:getValue(key.."#type")
612 if typeName ~= nil and string.lower(typeName) == string.lower(animalTypeName) then
613 maxNumAnimals = xmlFile:getValue(key.."#numSlots", 0)
614 break
615 end
616
617 i = i + 1
618 end
619
620 return maxNumAnimals
621end

loadSpecValueNumberAnimalsCow

Description
Definition
loadSpecValueNumberAnimalsCow()
Code
625function LivestockTrailer.loadSpecValueNumberAnimalsCow(xmlFile, customEnvironment, baseDir)
626 return LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, "cow")
627end

loadSpecValueNumberAnimalsHorse

Description
Definition
loadSpecValueNumberAnimalsHorse()
Code
643function LivestockTrailer.loadSpecValueNumberAnimalsHorse(xmlFile, customEnvironment, baseDir)
644 return LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, "horse")
645end

loadSpecValueNumberAnimalsPig

Description
Definition
loadSpecValueNumberAnimalsPig()
Code
631function LivestockTrailer.loadSpecValueNumberAnimalsPig(xmlFile, customEnvironment, baseDir)
632 return LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, "pig")
633end

loadSpecValueNumberAnimalsSheep

Description
Definition
loadSpecValueNumberAnimalsSheep()
Code
637function LivestockTrailer.loadSpecValueNumberAnimalsSheep(xmlFile, customEnvironment, baseDir)
638 return LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, "sheep")
639end

onAnimalLoaded

Description
Definition
onAnimalLoaded()
Code
453function LivestockTrailer:onAnimalLoaded(i3dNode, failedReason, args)
454 if i3dNode ~= 0 then
455 local slot = args.slot
456 local visual = args.visual
457
458 link(slot.linkNode, i3dNode)
459
460 slot.loadedMesh = i3dNode
461 slot.meshLoadingInProgress = false
462
463 local variations = visual.visualAnimal.variations[1]
464 local tileU = variations.tileUIndex / variations.numTilesU
465 local tileV = variations.tileVIndex / variations.numTilesV
466 I3DUtil.setShaderParameterRec(i3dNode, "atlasInvSizeAndOffsetUV", nil, nil, tileU, tileV, false)
467 I3DUtil.setShaderParameterRec(i3dNode, "RDT", nil, 0, nil, nil, false)
468 end
469end

onAnimalLoadTriggerCallback

Description
Definition
onAnimalLoadTriggerCallback()
Code
532function LivestockTrailer:onAnimalLoadTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
533 if onEnter or onLeave then
534 local spec = self.spec_livestockTrailer
535 local vehicle = g_currentMission.nodeToObject[otherId]
536
537 if vehicle ~= nil and vehicle.spec_rideable ~= nil then
538 local cluster = vehicle:getCluster()
539 if cluster ~= nil then
540 local subTypeIndex = cluster:getSubTypeIndex()
541 if self:getSupportsAnimalSubType(subTypeIndex) then
542 if onEnter then
543 table.addElement(spec.rideablesInTrigger, vehicle)
544 vehicle:addDeleteListener(self, "onAnimalRideableDeleted")
545 else
546 table.removeElement(spec.rideablesInTrigger, vehicle)
547 vehicle:removeDeleteListener(self, "onAnimalRideableDeleted")
548 end
549
550 if spec.animalScreenController ~= nil then
551 spec.animalScreenController:onAnimalsChanged(self, nil)
552 end
553 end
554 end
555 end
556 end
557end

onAnimalRideableDeleted

Description
Definition
onAnimalRideableDeleted()
Code
561function LivestockTrailer:onAnimalRideableDeleted(rideable)
562 local spec = self.spec_livestockTrailer
563
564 table.removeElement(spec.rideablesInTrigger, rideable)
565
566 if spec.animalScreenController ~= nil then
567 spec.animalScreenController:onAnimalsChanged(self, nil)
568 end
569end

onDelete

Description
Definition
onDelete()
Code
184function LivestockTrailer:onDelete()
185 self:clearAnimals()
186 g_messageCenter:unsubscribe(AnimalClusterUpdateEvent, self)
187
188 if g_currentMission ~= nil then
189 g_currentMission.husbandrySystem:removeLivestockTrailer(self)
190 end
191
192 local spec = self.spec_livestockTrailer
193 if spec.triggerNode ~= nil then
194 removeTrigger(spec.triggerNode)
195 end
196
197 if spec.activatable ~= nil then
198 g_currentMission.activatableObjectsSystem:removeActivatable(spec.activatable)
199 end
200
201 if spec.loadingTrigger ~= nil then
202 spec.loadingTrigger:setLoadingTrailer(nil)
203 end
204end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
93function LivestockTrailer:onLoad(savegame)
94 local spec = self.spec_livestockTrailer
95
96 spec.animalPlaces = {}
97 spec.animalTypeIndexToPlaces = {}
98 local i = 0
99 while true do
100 local key = string.format("vehicle.livestockTrailer.animal(%d)", i)
101 if not self.xmlFile:hasProperty(key) then
102 break
103 end
104
105 local place = {}
106 place.numUsed = 0
107
108 local animalTypeStr = self.xmlFile:getValue(key .. "#type")
109 local animalTypeIndex = g_currentMission.animalSystem:getTypeIndexByName(animalTypeStr)
110 if animalTypeIndex == nil then
111 Logging.xmlWarning(self.xmlFile, "Animal type '%s' could not be found!", animalTypeStr)
112 break
113 end
114 place.animalTypeIndex = animalTypeIndex
115
116 place.slots = {}
117 local parent = self.xmlFile:getValue(key .. "#node", nil, self.components, self.i3dMappings)
118 local numSlots = math.abs(self.xmlFile:getValue(key.."#numSlots", 0))
119 if numSlots > getNumOfChildren(parent) then
120 Logging.xmlWarning(self.xmlFile, "numSlots is greater than available children for '%s'", key)
121 numSlots = getNumOfChildren(parent)
122 end
123 for j=0, numSlots-1 do
124 local slotNode = getChildAt(parent, j)
125 table.insert(place.slots, {linkNode=slotNode, loadedMesh=nil, place=place})
126 end
127
128 table.insert(spec.animalPlaces, place)
129 spec.animalTypeIndexToPlaces[place.animalTypeIndex] = place
130
131 i = i + 1
132 end
133
134 local trigger = self.xmlFile:getValue("vehicle.livestockTrailer.loadTrigger#node", nil, self.components, self.i3dMappings)
135 if trigger ~= nil then
136 addTrigger(trigger, "onAnimalLoadTriggerCallback", self)
137 spec.triggerNode = trigger
138 end
139 spec.rideablesInTrigger = {}
140
141 spec.spawnPlaces = {}
142 self.xmlFile:iterate("vehicle.livestockTrailer.spawnPlaces.spawnPlace", function(_, key)
143 local node = self.xmlFile:getValue(key .. "#node", nil, self.components, self.i3dMappings)
144 local width = self.xmlFile:getValue(key.."#width", 5)
145
146 if node ~= nil then
147 table.insert(spec.spawnPlaces, {node=node, width=width})
148 end
149 end)
150
151 if #spec.spawnPlaces > 0 or spec.triggerNode ~= nil then
152 spec.activatable = LivestockTrailerActivatable.new(self)
153 if g_currentMission ~= nil then
154 g_currentMission.activatableObjectsSystem:addActivatable(spec.activatable)
155 end
156 end
157
158 spec.clusterSystem = AnimalClusterSystem.new(self.isServer, self)
159 g_messageCenter:subscribe(AnimalClusterUpdateEvent, self.updatedClusters, self)
160
161 spec.loadingTrigger = nil
162 spec.animalScreenController = nil
163
164 if g_currentMission ~= nil then
165 g_currentMission.husbandrySystem:addLivestockTrailer(self)
166 end
167end

onLoadFinished

Description
Definition
onLoadFinished()
Code
171function LivestockTrailer:onLoadFinished(savegame)
172 if savegame ~= nil and not savegame.resetVehicles then
173 local spec = self.spec_livestockTrailer
174 local xmlFile = savegame.xmlFile
175 local key = savegame.key
176
177 spec.clusterSystem:loadFromXMLFile(xmlFile, key .. ".livestockTrailer")
178 spec.clusterSystem:updateNow()
179 end
180end

onReadStream

Description
Definition
onReadStream()
Code
215function LivestockTrailer:onReadStream(streamId, connection)
216 local spec = self.spec_livestockTrailer
217 spec.clusterSystem:readStream(streamId, connection)
218end

onWriteStream

Description
Definition
onWriteStream()
Code
222function LivestockTrailer:onWriteStream(streamId, connection)
223 local spec = self.spec_livestockTrailer
224 spec.clusterSystem:writeStream(streamId, connection)
225end

periodChanged

Description
Definition
periodChanged()
Code
520function LivestockTrailer:periodChanged(superFunc)
521 superFunc(self)
522
523 local spec = self.spec_livestockTrailer
524 local clusters = spec.clusterSystem:getClusters()
525 for _, cluster in ipairs(clusters) do
526 cluster:onPeriodChanged()
527 end
528end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
40function LivestockTrailer.prerequisitesPresent(specializations)
41 return true
42end

registerEventListeners

Description
Definition
registerEventListeners()
Code
82function LivestockTrailer.registerEventListeners(vehicleType)
83 SpecializationUtil.registerEventListener(vehicleType, "onLoad", LivestockTrailer)
84 SpecializationUtil.registerEventListener(vehicleType, "onLoadFinished", LivestockTrailer)
85 SpecializationUtil.registerEventListener(vehicleType, "onDelete", LivestockTrailer)
86 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", LivestockTrailer)
87 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", LivestockTrailer)
88end

registerFunctions

Description
Definition
registerFunctions()
Code
46function LivestockTrailer.registerFunctions(vehicleType)
47 SpecializationUtil.registerFunction(vehicleType, "getCurrentAnimalType", LivestockTrailer.getCurrentAnimalType)
48 SpecializationUtil.registerFunction(vehicleType, "getSupportsAnimalType", LivestockTrailer.getSupportsAnimalType)
49 SpecializationUtil.registerFunction(vehicleType, "getSupportsAnimalSubType", LivestockTrailer.getSupportsAnimalSubType)
50 SpecializationUtil.registerFunction(vehicleType, "setLoadingTrigger", LivestockTrailer.setLoadingTrigger)
51 SpecializationUtil.registerFunction(vehicleType, "getLoadingTrigger", LivestockTrailer.getLoadingTrigger)
52 SpecializationUtil.registerFunction(vehicleType, "updateAnimals", LivestockTrailer.updateAnimals)
53 SpecializationUtil.registerFunction(vehicleType, "updatedClusters", LivestockTrailer.updatedClusters)
54 SpecializationUtil.registerFunction(vehicleType, "clearAnimals", LivestockTrailer.clearAnimals)
55 SpecializationUtil.registerFunction(vehicleType, "addAnimals", LivestockTrailer.addAnimals)
56 SpecializationUtil.registerFunction(vehicleType, "addCluster", LivestockTrailer.addCluster)
57 SpecializationUtil.registerFunction(vehicleType, "getClusters", LivestockTrailer.getClusters)
58 SpecializationUtil.registerFunction(vehicleType, "getRideablesInTrigger", LivestockTrailer.getRideablesInTrigger)
59 SpecializationUtil.registerFunction(vehicleType, "getClusterById", LivestockTrailer.getClusterById)
60 SpecializationUtil.registerFunction(vehicleType, "getClusterSystem", LivestockTrailer.getClusterSystem)
61 SpecializationUtil.registerFunction(vehicleType, "getNumOfAnimals", LivestockTrailer.getNumOfAnimals)
62 SpecializationUtil.registerFunction(vehicleType, "getMaxNumOfAnimals", LivestockTrailer.getMaxNumOfAnimals)
63 SpecializationUtil.registerFunction(vehicleType, "getNumOfFreeAnimalSlots", LivestockTrailer.getNumOfFreeAnimalSlots)
64 SpecializationUtil.registerFunction(vehicleType, "onAnimalLoaded", LivestockTrailer.onAnimalLoaded)
65 SpecializationUtil.registerFunction(vehicleType, "onAnimalLoadTriggerCallback", LivestockTrailer.onAnimalLoadTriggerCallback)
66 SpecializationUtil.registerFunction(vehicleType, "getAnimalUnloadPlaces", LivestockTrailer.getAnimalUnloadPlaces)
67 SpecializationUtil.registerFunction(vehicleType, "setAnimalScreenController", LivestockTrailer.setAnimalScreenController)
68 SpecializationUtil.registerFunction(vehicleType, "onAnimalRideableDeleted", LivestockTrailer.onAnimalRideableDeleted)
69end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
73function LivestockTrailer.registerOverwrittenFunctions(vehicleType)
74 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAdditionalComponentMass", LivestockTrailer.getAdditionalComponentMass)
75 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getSellPrice", LivestockTrailer.getSellPrice)
76 SpecializationUtil.registerOverwrittenFunction(vehicleType, "dayChanged", LivestockTrailer.dayChanged)
77 SpecializationUtil.registerOverwrittenFunction(vehicleType, "periodChanged", LivestockTrailer.periodChanged)
78end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
208function LivestockTrailer:saveToXMLFile(xmlFile, key, usedModNames)
209 local spec = self.spec_livestockTrailer
210 spec.clusterSystem:saveToXMLFile(xmlFile, key, usedModNames)
211end

setAnimalScreenController

Description
Definition
setAnimalScreenController()
Code
273function LivestockTrailer:setAnimalScreenController(controller)
274 self.spec_livestockTrailer.animalScreenController = controller
275end

setLoadingTrigger

Description
Definition
setLoadingTrigger()
Code
261function LivestockTrailer:setLoadingTrigger(trigger)
262 self.spec_livestockTrailer.loadingTrigger = trigger
263end

updateAnimals

Description
Definition
updateAnimals()
Code
398function LivestockTrailer:updateAnimals()
399 local spec = self.spec_livestockTrailer
400
401 self:clearAnimals()
402
403 local slotIndex = 1
404 local clusters = spec.clusterSystem:getClusters()
405 local animalType = self:getCurrentAnimalType()
406 if animalType ~= nil then
407 local place = spec.animalTypeIndexToPlaces[animalType.typeIndex]
408 place.usedSlots = 0
409 for _, cluster in ipairs(clusters) do
410 for i = 1, cluster:getNumAnimals() do
411 local slot = place.slots[slotIndex]
412 slot.meshLoadingInProgress = true
413
414 local visual = g_currentMission.animalSystem:getVisualByAge(cluster:getSubTypeIndex(), cluster:getAge())
415 local filename = visual.visualAnimal.filenamePosed
416 slot.filename = filename
417 local arguments = {
418 slot = slot,
419 visual = visual
420 }
421 local sharedLoadRequestId = g_i3DManager:loadSharedI3DFileAsync(filename, false, false, self.onAnimalLoaded, self, arguments)
422 slot.sharedLoadRequestId = sharedLoadRequestId
423
424 slotIndex = slotIndex + 1
425 place.usedSlots = place.usedSlots + 1
426 end
427 end
428 end
429end

updatedClusters

Description
Definition
updatedClusters()
Code
389function LivestockTrailer:updatedClusters(trailer)
390 if trailer == self then
391 self:updateAnimals()
392 self:setMassDirty()
393 end
394end