Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- AIConveyorBelt
- AIDrivable
- AIFieldWorker
- AIImplement
- AIJobVehicle
- AIVehicle
- AIVehicleObstacle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- AutoLoader
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BigBag
- BunkerSiloCompacter
- BunkerSiloInteractor
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- CropSensor
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- ExtendedAIVehicle
- ExtendedCombine
- ExtendedMotorized
- ExtendedMower
- ExtendedSowingMachine
- ExtendedSprayer
- ExtendedWearable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- HeadlandAnimation
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- InlineWrapper
- JigglingParts
- Leveler
- LicensePlates
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- ManureSensor
- MixerWagon
- Motorized
- Mountable
- Mower
- Mulcher
- MultipleItemPurchase
- Pallet
- Pickup
- Pipe
- PlaceableAI
- PlaceableAnimatedObjects
- PlaceableBeehive
- PlaceableBeehivePalletSpa...
- PlaceableBunkerSilo
- PlaceableBuyingStation
- PlaceableCartridgePlayer
- PlaceableChargingStation
- PlaceableClearAreas
- PlaceableColorable
- PlaceableDeletedNodes
- PlaceableDoghouse
- PlaceableDynamicallyLoade...
- PlaceableFarmhouse
- PlaceableFence
- PlaceableFoliageAreas
- PlaceableGreenhouse
- PlaceableHighPressureWash...
- PlaceableHotspots
- PlaceableHusbandry
- PlaceableHusbandryAnimals
- PlaceableHusbandryFeeding...
- PlaceableHusbandryFence
- PlaceableHusbandryFood
- PlaceableHusbandryLiquidM...
- PlaceableHusbandryMilk
- PlaceableHusbandryPallets
- PlaceableHusbandryStraw
- PlaceableHusbandryWater
- PlaceableIncomePerHour
- PlaceableIndoorAreas
- PlaceableInfoTrigger
- PlaceableLeveling
- PlaceableLights
- PlaceableManureHeap
- PlaceablePlacement
- PlaceableProductionPoint
- PlaceableSellingStation
- PlaceableSilo
- PlaceableSiloExtension
- PlaceableSolarPanels
- PlaceableTipOcclusionArea...
- PlaceableTrainSystem
- PlaceableTriggerMarkers
- PlaceableVine
- PlaceableWardrobe
- PlaceableWeatherStation
- PlaceableWeighingStation
- PlaceableWindTurbine
- PlaceableWorkshop
- Plow
- PlowPacker
- PowerConsumer
- PowerTakeOffs
- PrecisionFarmingStatistic
- PushHandTool
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- RTKStation
- SaltSpreader
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SoilSampler
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StonePicker
- StrawBlower
- StumpCutter
- SupportVehicle
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TestAreas
- TipOccluder
- Trailer
- TreePlanter
- TreeSaplingPallet
- TreeSaw
- TurnOnVehicle
- VariableWorkWidth
- VehicleSettings
- VineCutter
- VineDetector
- VinePrepruner
- Washable
- WaterTrailer
- Wearable
- Weeder
- WeedSpotSpray
- Wheels
- WindBending
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
LivestockTrailer
DescriptionSpecialization for livestrock trailers with animals as cargoFunctions
- addAnimals
- addCluster
- clearAnimals
- dayChanged
- getAdditionalComponentMass
- getAnimalUnloadPlaces
- getClusterById
- getClusters
- getClusterSystem
- getCurrentAnimalType
- getLoadingTrigger
- getMaxNumOfAnimals
- getNumOfAnimals
- getNumOfFreeAnimalSlots
- getRideablesInTrigger
- getSellPrice
- getSpecValueNumberAnimals
- getSpecValueNumberAnimalsCow
- getSpecValueNumberAnimalsHorse
- getSpecValueNumberAnimalsPig
- getSpecValueNumberAnimalsSheep
- getSupportsAnimalSubType
- getSupportsAnimalType
- initSpecialization
- loadSpecValueNumberAnimals
- loadSpecValueNumberAnimalsCow
- loadSpecValueNumberAnimalsHorse
- loadSpecValueNumberAnimalsPig
- loadSpecValueNumberAnimalsSheep
- onAnimalLoaded
- onAnimalLoadTriggerCallback
- onAnimalRideableDeleted
- onDelete
- onLoad
- onLoadFinished
- onReadStream
- onWriteStream
- periodChanged
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- saveToXMLFile
- setAnimalScreenController
- setLoadingTrigger
- updateAnimals
- updatedClusters
addAnimals
DescriptionDefinitionaddAnimals()Code
279 | function 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 |
295 | end |
addCluster
DescriptionDefinitionaddCluster()Code
299 | function LivestockTrailer:addCluster(cluster) |
300 | local spec = self.spec_livestockTrailer |
301 | |
302 | spec.clusterSystem:addPendingAddCluster(cluster) |
303 | spec.clusterSystem:updateNow() |
304 | end |
clearAnimals
DescriptionDefinitionclearAnimals()Code
433 | function 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 |
449 | end |
dayChanged
DescriptionDefinitiondayChanged()Code
508 | function 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 |
516 | end |
getAdditionalComponentMass
DescriptionDefinitiongetAdditionalComponentMass()Code
473 | function 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 |
488 | end |
getAnimalUnloadPlaces
DescriptionDefinitiongetAnimalUnloadPlaces()Code
573 | function 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 |
597 | end |
getClusterById
DescriptionDefinitiongetClusterById()Code
322 | function LivestockTrailer:getClusterById(id) |
323 | local spec = self.spec_livestockTrailer |
324 | return spec.clusterSystem:getClusterById(id) |
325 | end |
getClusters
DescriptionDefinitiongetClusters()Code
308 | function LivestockTrailer:getClusters() |
309 | local spec = self.spec_livestockTrailer |
310 | return spec.clusterSystem:getClusters() |
311 | end |
getClusterSystem
DescriptionDefinitiongetClusterSystem()Code
329 | function LivestockTrailer:getClusterSystem() |
330 | local spec = self.spec_livestockTrailer |
331 | return spec.clusterSystem |
332 | end |
getCurrentAnimalType
DescriptionDefinitiongetCurrentAnimalType()Code
245 | function 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 |
257 | end |
getLoadingTrigger
DescriptionDefinitiongetLoadingTrigger()Code
267 | function LivestockTrailer:getLoadingTrigger() |
268 | return self.spec_livestockTrailer.loadingTrigger |
269 | end |
getMaxNumOfAnimals
DescriptionDefinitiongetMaxNumOfAnimals()Code
353 | function 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 |
373 | end |
getNumOfAnimals
DescriptionDefinitiongetNumOfAnimals()Code
336 | function 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 |
349 | end |
getNumOfFreeAnimalSlots
DescriptionDefinitiongetNumOfFreeAnimalSlots()Code
377 | function 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 |
385 | end |
getRideablesInTrigger
DescriptionDefinitiongetRideablesInTrigger()Code
315 | function LivestockTrailer:getRideablesInTrigger() |
316 | local spec = self.spec_livestockTrailer |
317 | return spec.rideablesInTrigger |
318 | end |
getSellPrice
DescriptionDefinitiongetSellPrice()Code
492 | function 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 |
504 | end |
getSpecValueNumberAnimals
DescriptionDefinitiongetSpecValueNumberAnimals()Code
649 | function 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")) |
654 | end |
getSpecValueNumberAnimalsCow
DescriptionDefinitiongetSpecValueNumberAnimalsCow()Code
658 | function LivestockTrailer.getSpecValueNumberAnimalsCow(storeItem, realItem) |
659 | return LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, "numAnimalsCow") |
660 | end |
getSpecValueNumberAnimalsHorse
DescriptionDefinitiongetSpecValueNumberAnimalsHorse()Code
676 | function LivestockTrailer.getSpecValueNumberAnimalsHorse(storeItem, realItem) |
677 | return LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, "numAnimalsHorse") |
678 | end |
getSpecValueNumberAnimalsPig
DescriptionDefinitiongetSpecValueNumberAnimalsPig()Code
664 | function LivestockTrailer.getSpecValueNumberAnimalsPig(storeItem, realItem) |
665 | return LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, "numAnimalsPig") |
666 | end |
getSpecValueNumberAnimalsSheep
DescriptionDefinitiongetSpecValueNumberAnimalsSheep()Code
670 | function LivestockTrailer.getSpecValueNumberAnimalsSheep(storeItem, realItem) |
671 | return LivestockTrailer.getSpecValueNumberAnimals(storeItem, realItem, "numAnimalsSheep") |
672 | end |
getSupportsAnimalSubType
DescriptionDefinitiongetSupportsAnimalSubType()Code
235 | function 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) |
241 | end |
getSupportsAnimalType
DescriptionDefinitiongetSupportsAnimalType()Code
229 | function LivestockTrailer:getSupportsAnimalType(animalTypeIndex) |
230 | return self.spec_livestockTrailer.animalTypeIndexToPlaces[animalTypeIndex] ~= nil |
231 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
15 | function 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") |
36 | end |
loadSpecValueNumberAnimals
DescriptionDefinitionloadSpecValueNumberAnimals()Code
601 | function 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 |
621 | end |
loadSpecValueNumberAnimalsCow
DescriptionDefinitionloadSpecValueNumberAnimalsCow()Code
625 | function LivestockTrailer.loadSpecValueNumberAnimalsCow(xmlFile, customEnvironment, baseDir) |
626 | return LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, "cow") |
627 | end |
loadSpecValueNumberAnimalsHorse
DescriptionDefinitionloadSpecValueNumberAnimalsHorse()Code
643 | function LivestockTrailer.loadSpecValueNumberAnimalsHorse(xmlFile, customEnvironment, baseDir) |
644 | return LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, "horse") |
645 | end |
loadSpecValueNumberAnimalsPig
DescriptionDefinitionloadSpecValueNumberAnimalsPig()Code
631 | function LivestockTrailer.loadSpecValueNumberAnimalsPig(xmlFile, customEnvironment, baseDir) |
632 | return LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, "pig") |
633 | end |
loadSpecValueNumberAnimalsSheep
DescriptionDefinitionloadSpecValueNumberAnimalsSheep()Code
637 | function LivestockTrailer.loadSpecValueNumberAnimalsSheep(xmlFile, customEnvironment, baseDir) |
638 | return LivestockTrailer.loadSpecValueNumberAnimals(xmlFile, customEnvironment, baseDir, "sheep") |
639 | end |
onAnimalLoaded
DescriptionDefinitiononAnimalLoaded()Code
453 | function 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 |
469 | end |
onAnimalLoadTriggerCallback
DescriptionDefinitiononAnimalLoadTriggerCallback()Code
532 | function 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 |
557 | end |
onAnimalRideableDeleted
DescriptionDefinitiononAnimalRideableDeleted()Code
561 | function 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 |
569 | end |
onDelete
DescriptionDefinitiononDelete()Code
184 | function 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 |
204 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
93 | function 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 |
167 | end |
onLoadFinished
DescriptionDefinitiononLoadFinished()Code
171 | function 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 |
180 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
215 | function LivestockTrailer:onReadStream(streamId, connection) |
216 | local spec = self.spec_livestockTrailer |
217 | spec.clusterSystem:readStream(streamId, connection) |
218 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
222 | function LivestockTrailer:onWriteStream(streamId, connection) |
223 | local spec = self.spec_livestockTrailer |
224 | spec.clusterSystem:writeStream(streamId, connection) |
225 | end |
periodChanged
DescriptionDefinitionperiodChanged()Code
520 | function 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 |
528 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
40 | function LivestockTrailer.prerequisitesPresent(specializations) |
41 | return true |
42 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
82 | function 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) |
88 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
46 | function 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) |
69 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
73 | function 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) |
78 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
208 | function LivestockTrailer:saveToXMLFile(xmlFile, key, usedModNames) |
209 | local spec = self.spec_livestockTrailer |
210 | spec.clusterSystem:saveToXMLFile(xmlFile, key, usedModNames) |
211 | end |
setAnimalScreenController
DescriptionDefinitionsetAnimalScreenController()Code
273 | function LivestockTrailer:setAnimalScreenController(controller) |
274 | self.spec_livestockTrailer.animalScreenController = controller |
275 | end |
setLoadingTrigger
DescriptionDefinitionsetLoadingTrigger()Code
261 | function LivestockTrailer:setLoadingTrigger(trigger) |
262 | self.spec_livestockTrailer.loadingTrigger = trigger |
263 | end |
updateAnimals
DescriptionDefinitionupdateAnimals()Code
398 | function 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 |
429 | end |
updatedClusters
DescriptionDefinitionupdatedClusters()Code
389 | function LivestockTrailer:updatedClusters(trailer) |
390 | if trailer == self then |
391 | self:updateAnimals() |
392 | self:setMassDirty() |
393 | end |
394 | end |