bigSowingMachine = {}; function bigSowingMachine.prerequisitesPresent(specializations) return true; end; function bigSowingMachine:load(xmlFile) self.work = false self.brake = SpecializationUtil.callSpecializationsFunction("brake"); self.releaseBrake = SpecializationUtil.callSpecializationsFunction("releaseBrake"); self.groundReferenceNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.groundReferenceNode#index")); self.saveGroundReferenceNode = self.groundReferenceNode; self.hasGroundContact = false; self.speedViolationMaxTime = 2500; self.speedViolationTimer = self.speedViolationMaxTime; self.groundParticleSystems = {}; local psName = "vehicle.groundParticleSystem"; Utils.loadParticleSystem(xmlFile, self.groundParticleSystems, psName, self.components, false, nil, self.baseDirectory) self.groundParticleSystemActive = false; self.isTurnedOn = false; self.dungOffToTurn = false; self.terrainDetailChannel1 = g_currentMission.cultivatorChannel; self.terrainDetailChannel2 = g_currentMission.ploughChannel; self.terrainDetailChannel3 = g_currentMission.sowingChannel; local sowingSound = getXMLString(xmlFile, "vehicle.sowingSound#file"); if sowingSound ~= nil and sowingSound ~= "" then sowingSound = Utils.getFilename(sowingSound, self.baseDirectory); self.sowingSound = createSample("sowingSound"); loadSample(self.sowingSound, sowingSound, false); self.sowingSoundPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.sowingSound#pitchOffset"), 0); self.sowingSoundVolume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.sowingSound#volume"), 1.0); self.sowingSoundEnabled = false; end; self.drumDummy = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.drumDummy#index")); self.drumBar = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.drumBar#index")); self.currentSeed = 0; self.dungOn = false; self.workMode = false; self.literPerQmDung = (Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.dungLiterPerQm"), 0.3)/10); self.seedTrailer = {}; self.dungTrailer = {}; self.saveAILM = self.aiLeftMarker; self.isAirseeder = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.isAirseeder#value"), false); self.haAHour = 0; self.roundArea = 0; self.dungTrailerIsAttached = false; self.seedTrailerIsAttached = false; self.dungFillLevel = 0; self.seedFillLevel = 0; self.currentDungType = 0; self.noDungInGame = true; self.noTill = false; if FruitUtil.fruitIndexToDesc[FruitUtil.FRUITTYPE_PESTICIDE] ~= nil then self.noDungInGame = false; end; self.attacherJoint1 = nil; local attacherJoint = {}; attacherJoint.node = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.attacherJoint#index")); if attacherJoint.node ~= nil then attacherJoint.rotLimitScale = {1, 1, 1}; attacherJoint.transLimitScale = {1, 1, 1}; attacherJoint.rootNode = Utils.getNoNil(Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.attacherJoint#rootNode")), self.components[1].node); local jointTypeStr = getXMLString(xmlFile, "vehicle.attacherJoint#jointType") local jointType; if jointTypeStr ~= nil then jointType = Vehicle.jointTypeNameToInt[jointTypeStr]; end; attacherJoint.jointType = jointType; self.attacherJoint1 = attacherJoint; end; self.attacherJoint2 = nil; local attacherJoint2 = {}; attacherJoint2.node = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.attacherJoint2#index")); if attacherJoint2.node ~= nil then attacherJoint2.rotLimitScale = {1, 1, 1}; attacherJoint2.transLimitScale = {1, 1, 1}; attacherJoint2.rootNode = Utils.getNoNil(Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.attacherJoint2#rootNode")), self.components[1].node); local jointTypeStr2 = getXMLString(xmlFile, "vehicle.attacherJoint2#jointType") local jointType2; if jointTypeStr2 ~= nil then jointType2 = Vehicle.jointTypeNameToInt[jointTypeStr2]; end; attacherJoint2.jointType = jointType2; self.attacherJoint2 = attacherJoint2; end; self.attacherJoint = self.attacherJoint1; self.connectCollisions = SpecializationUtil.callSpecializationsFunction("connectCollisions"); self.anim = SpecializationUtil.callSpecializationsFunction("anim"); self.Go = {}; self.Done = {}; self.charId = {}; self.clipIndex = {}; self.CheckDone = {}; self.moveColli = {}; self.animationParts = {}; self.collisionArm = {}; self.startpoint = {}; self.loopCheck = {}; self.Speed = {}; local count = getXMLInt(xmlFile, "vehicle.animParts#count"); local part = self.animationParts; if count ~= nil then for i=1, count do part[i] = {}; local partname = string.format("vehicle.animParts.part".."%d", i); local nameR = getXMLString(xmlFile, partname.."#name"); self.charId[nameR] = Utils.indexToObject(self.components, getXMLString(xmlFile, partname.."#rootNode")); self.clipIndex[nameR] = getXMLString(xmlFile, partname.."#animationClip"); self.CheckDone[nameR] = false; self.moveColli[nameR] = getXMLString(xmlFile, partname.."#moveColli"); self.startpoint[nameR] = Utils.getNoNil(getXMLFloat(xmlFile, partname.."#startpoint"),0.0); self.Speed[nameR] = Utils.getNoNil(getXMLFloat(xmlFile, partname.."#speed"),0.0); if self.moveColli[nameR] ~= nil then self.Collision = {}; self.Collision.collision = Utils.indexToObject(self.components, getXMLString(xmlFile, partname.."#collision")); self.Collision.collisionAttacher = Utils.indexToObject(self.components, getXMLString(xmlFile, partname.."#collsionAttacher")); self.Collision.armAttacher = Utils.indexToObject(self.components, getXMLString(xmlFile, partname.. "#armAttacher")); self.Collision.index = 0; self.collisionArm[nameR] = self.Collision; self:connectCollisions(nameR); end; local charId = getAnimCharacterSet(self.charId[nameR]); local clipIndex = getAnimClipIndex(charId, self.clipIndex[nameR]); assignAnimTrackClip(charId , 0, clipIndex); setAnimTrackTime(charId, 0, self.startpoint[nameR]); enableAnimTrack(charId, 0); disableAnimTrack(charId, 0); self.loopCheck[nameR] = false; self.Speed[nameR] = 1.0; end; end; self.seedPanelPath = Utils.getFilename("seedPanel.png", self.baseDirectory); self.HudWidth = 0.22; --0.310; self.HudHeight = 0.16; --0.214; self.HudPosX = 0.775; --0.001; self.HudPosY = 0.7385; --0.001; self.seedPanelOverlay = Overlay:new("seedPanel", self.seedPanelPath, self.HudPosX, self.HudPosY, self.HudWidth, self.HudHeight); end; function bigSowingMachine:delete() Utils.deleteParticleSystem(self.groundParticleSystems); if self.sowingSound ~= nil then delete(self.sowingSound); end; end; function bigSowingMachine:mouseEvent(posX, posY, isDown, isUp, button) end; function bigSowingMachine:keyEvent(unicode, sym, modifier, isDown) end; function bigSowingMachine:update(dt) if self:getIsActiveForInput() then if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA) then self.isTurnedOn = not self.isTurnedOn; end; if InputBinding.hasEvent(InputBinding.DUNG_ON) then self.dungOn = not self.dungOn; end; if InputBinding.hasEvent(InputBinding.SEEDMODE) then self.noTill = not self.noTill; end; if InputBinding.hasEvent(InputBinding.REBUILD) and not self.isTurnedOn then if table.getn(self.dungTrailer) ~= 0 then table.insert(self.seedTrailer[1].dungTrailer, self.dungTrailer[1]); end; self:detachImplementByObject(self.seedTrailer[1]); if not self.workMode then local lastTrailer = table.getn(self.dungTrailer); table.remove(self.dungTrailer, lastTrailer); end; if self.attacherVehicle ~= nil then self.attacherVehicle:playDetachSound(); self.attacherVehicle:detachImplementByObject(self); end; self.workMode = not self.workMode; end; end; if self.workMode then self.groundReferenceNode = self.saveGroundReferenceNode; self.attacherJoint = self.attacherJoint2; setVisibility(self.drumDummy, false); setVisibility(self.drumBar, true); setJointRotationLimit(self.componentJoints[10].jointIndex, 2, true, Utils.degToRad(-0), Utils.degToRad(0)); setJointRotationLimit(self.componentJoints[5].jointIndex, 2, true, Utils.degToRad(-2), Utils.degToRad(2)); self.Go.transport = true; self.Done.transport = true; self.aiLeftMarker = self.saveAILM; self.wheels[1].steeringAxleScale = -0.75; self.wheels[2].steeringAxleScale = -0.95; self.wheels[3].steeringAxleScale = -0.75; self.wheels[4].steeringAxleScale = -0.95; else self.groundReferenceNode = nil; self:setFoldDirection(1); self.attacherJoint = self.attacherJoint1; setJointRotationLimit(self.componentJoints[10].jointIndex, 2, true, Utils.degToRad(-10), Utils.degToRad(10)); setJointRotationLimit(self.componentJoints[5].jointIndex, 2, true, Utils.degToRad(-8), Utils.degToRad(8)); setVisibility(self.drumDummy, true); setVisibility(self.drumBar, false); self.Go.transport = false; self.Done.transport = true; self.aiLeftMarker = nil; self.wheels[1].steeringAxleScale = 0; self.wheels[2].steeringAxleScale = 0; self.wheels[3].steeringAxleScale = 0; self.wheels[4].steeringAxleScale = 0; end; self:anim("transport", false); if self:getIsActive() then local hasGroundContact = self.hasGroundContact; if self.groundReferenceNode ~= nil then local x,y,z = getWorldTranslation(self.groundReferenceNode); local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 0, z); if terrainHeight >= y then hasGroundContact = true; end; end; if table.getn(self.seedTrailer) > 0 then for i=1, table.getn(self.seedTrailer) do if self.seedTrailer[i].isSeedTankTrailer then self.seedTrailerIsAttached = true; else self.seedTrailerIsAttached = false; end; end; else self.seedTrailerIsAttached = false; end; if table.getn(self.dungTrailer) > 0 then for i=1, table.getn(self.dungTrailer) do if self.dungTrailer[i].isDungTankTrailer then self.dungTrailerIsAttached = true; else self.dungTrailerIsAttached = false; end; end; else self.dungTrailerIsAttached = false; end; if self.seedTrailerIsAttached then for i=1, table.getn(self.seedTrailer) do self.currentSeed = self.seedTrailer[i].currentFillType; self.seedFillLevel = self.seedTrailer[i].fillLevel; end; else self.currentSeed = FruitUtil.FRUITTYPE_UNKNOWN; self.seedFillLevel = 0; end; if self.dungTrailerIsAttached then if not self.noDungInGame then for i=1, table.getn(self.dungTrailer) do self.dungFillLevel = self.dungTrailer[i].fillLevel; self.currentDungType = self.dungTrailer[i].currentFillType; end; else self.dungFillLevel = self.dungTrailer[1].capacity; end; else self.dungFillLevel = 0; self.currentDungType = FruitUtil.FRUITTYPE_UNKNOWN; end; if self.isTurnedOn and (self.seedFillLevel > 0) then if self.noTill then self.aiTerrainDetailChannel1 = self.terrainDetailChannel1; self.aiTerrainDetailChannel2 = self.terrainDetailChannel3; else self.aiTerrainDetailChannel1 = self.terrainDetailChannel1; self.aiTerrainDetailChannel2 = self.terrainDetailChannel2; end; else self.noTill = false; self.aiTerrainDetailChannel1 = self.terrainDetailChannel1; self.aiTerrainDetailChannel2 = self.terrainDetailChannel3; end; if self.movingDirection > 0 and hasGroundContact then if self.isTurnedOn then if self.seedFillLevel > 0 then if self.currentSeed ~= 0 then if self.foldAnimTime > 0.85 then local x,y,z = getWorldTranslation(self.cuttingAreas[1].start); local x1,y1,z1 = getWorldTranslation(self.cuttingAreas[1].width); local x2,y2,z2 = getWorldTranslation(self.cuttingAreas[1].height); Utils.updateCultivatorArea(x, z, x1, z1, x2, z2); end; local x,y,z = getWorldTranslation(self.cuttingAreas[2].start); local x1,y1,z1 = getWorldTranslation(self.cuttingAreas[2].width); local x2,y2,z2 = getWorldTranslation(self.cuttingAreas[2].height); local area = Utils.updateSowingArea(self.currentSeed, x, z, x1, z1, x2, z2); local pixelToQm = 2048 / 8192 * 2048 / 8192; -- 8192px are mapped to 2048m local qm = area*pixelToQm; local ha = qm/10000; local fruitDesc = FruitUtil.fruitIndexToDesc[self.currentSeed]; local usageSeed = fruitDesc.seedUsagePerQm*qm for i=1, table.getn(self.seedTrailer) do local newSeedFillLevel = self.seedTrailer[i].fillLevel-usageSeed; self.seedTrailer[i]:setFillLevel(newSeedFillLevel, self.currentSeed); end; g_currentMission.missionStats.seedUsageTotal = g_currentMission.missionStats.seedUsageTotal + usageSeed; g_currentMission.missionStats.seedUsageSession = g_currentMission.missionStats.seedUsageSession + usageSeed; g_currentMission.missionStats.hectaresSeededTotal = g_currentMission.missionStats.hectaresSeededTotal + ha; g_currentMission.missionStats.hectaresSeededSession = g_currentMission.missionStats.hectaresSeededSession + ha; g_currentMission.missionStats.seedingDurationTotal = g_currentMission.missionStats.seedingDurationTotal + dt/(1000*60); g_currentMission.missionStats.seedingDurationSession = g_currentMission.missionStats.seedingDurationSession + dt/(1000*60); end; else local x,y,z = getWorldTranslation(self.cuttingAreas[1].start); local x1,y1,z1 = getWorldTranslation(self.cuttingAreas[1].width); local x2,y2,z2 = getWorldTranslation(self.cuttingAreas[1].height); Utils.updateCultivatorArea(x, z, x1, z1, x2, z2); if self.attacherVehicle.isAITractorActivated then self.attacherVehicle:stopAITractor(); end; end; if self.dungOn then if self.dungFillLevel > 0 then local x,y,z = getWorldTranslation(self.cuttingAreas[2].start); local x1,y1,z1 = getWorldTranslation(self.cuttingAreas[2].width); local x2,y2,z2 = getWorldTranslation(self.cuttingAreas[2].height); Utils.updateSprayArea(x, z, x1, z1, x2, z2); local difficultyMultiplier = math.max(3 * (3 - g_currentMission.missionStats.difficulty), 1); local usageDung = self.literPerQmDung * difficultyMultiplier; local money = 0.05 * usageDung; if not self.noDungInGame then for i=1, table.getn(self.dungTrailer) do local newDungFillLevel = self.dungTrailer[i].fillLevel-usageDung; self.dungTrailer[i]:setFillLevel(newDungFillLevel, self.currentDungType); end; else g_currentMission.missionStats.money = g_currentMission.missionStats.money - money; end; else if self.attacherVehicle.isAITractorActivated then self.attacherVehicle:stopAITractor(); end; end; end; if self.sowingSound ~= nil and not self.sowingSoundEnabled then if self.lastSpeed*3600 > 3 and self:getIsActiveForSound() then playSample(self.sowingSound, 0, self.sowingSoundVolume, 0); setSamplePitch(self.sowingSound, self.sowingSoundPitchOffset); self.sowingSoundEnabled = true; end; end; else local x,y,z = getWorldTranslation(self.cuttingAreas[1].start); local x1,y1,z1 = getWorldTranslation(self.cuttingAreas[1].width); local x2,y2,z2 = getWorldTranslation(self.cuttingAreas[1].height); Utils.updateCultivatorArea(x, z, x1, z1, x2, z2); end; if self:doCheckSpeedLimit() and self.lastSpeed*3600 > 12 then self.speedViolationTimer = self.speedViolationTimer - dt; if self.speedViolationTimer < 0 then if self.attacherVehicle ~= nil then self.attacherVehicle:detachImplementByObject(self); end; end; else self.speedViolationTimer = self.speedViolationMaxTime; end; if not self.groundParticleSystemActive then self.groundParticleSystemActive = true; Utils.setEmittingState(self.groundParticleSystems, true); end; local mh = (self.lastSpeed*self.speedDisplayScale*3600)*1000; local area = (39.4/10000)*mh; self.haAHour = area; else self.haAHour = 0; if self.groundParticleSystemActive then self.groundParticleSystemActive = false; Utils.setEmittingState(self.groundParticleSystems, false); end; self.speedViolationTimer = self.speedViolationMaxTime; bigSowingMachine.onDeactivateSounds(self); end; if self.haAHour > 0.05 then if self.haAHour > self.roundArea then self.roundArea = self.roundArea+(dt*0.002); elseif self.haAHour < self.roundArea then self.roundArea = self.roundArea-(dt*0.002); end; else self.roundArea = 0; end; end; if self.sowingSoundEnabled then if self.lastSpeed*3600 < 3 then bigSowingMachine.onDeactivateSounds(self); end; end; if self.attacherVehicle ~= nil then if not self.attacherVehicle.isKinkSteering then if self.attacherVehicle.isAITractorActivated and self.attacherVehicle.turnStage ~= 0 then if self.attacherVehicle.rotatedTime >= 0.255 then self.attacherVehicle.rotatedTime = 0.255; elseif self.attacherVehicle.rotatedTime <= -0.255 then self.attacherVehicle.rotatedTime = -0.255; else self.attacherVehicle.rotatedTime = self.attacherVehicle.rotatedTime; end; end; else if self.attacherVehicle.isAITractorActivated and self.attacherVehicle.turnStage ~= 0 then if self.attacherVehicle.turnStage == 5 then setTranslation(self.aiBackMarker, 0, 0, 8); if self.attacherVehicle.rotatedTime >= 0.11 then self.attacherVehicle.rotatedTime = 0.11; elseif self.attacherVehicle.rotatedTime <= -0.11 then self.attacherVehicle.rotatedTime = -0.11; else self.attacherVehicle.rotatedTime = self.attacherVehicle.rotatedTime; end; else setTranslation(self.aiBackMarker, 0, 0, -2.2); if self.attacherVehicle.rotatedTime >= 0.52 then self.attacherVehicle.rotatedTime = 0.52; elseif self.attacherVehicle.rotatedTime <= -0.52 then self.attacherVehicle.rotatedTime = -0.52; else self.attacherVehicle.rotatedTime = self.attacherVehicle.rotatedTime; end; end; end; end; end; for i=1, table.getn(self.componentJoints), 1 do local joint = self.componentJoints[i]; setJointFrame(joint.jointIndex, 0,joint.jointNode); end; for i=1, table.getn(self.attachedImplements) do if not self.attachedImplements[i].isDungTankTrailer then self:detachImplementByObject(self.attachedImplements[1]); end; if not self.attachedImplements[i].isSeedTankTrailer then self:detachImplementByObject(self.attachedImplements[1]); end; end; end; function bigSowingMachine:draw() if self.currentSeed ~= 0 then g_currentMission.fruitOverlays[self.currentSeed]:render(); end; if self.attacherVehicle ~= nil then if self.workMode then if g_currentMission.showHelpText then self.seedPanelOverlay:render(); renderText(self.HudPosX+0.112, self.HudPosY+0.00355, 0.03, string.format("%.1f", math.abs(self.roundArea))); if self.dungFillLevel < 120 and self.dungTrailerIsAttached then setTextColor(1.0, 0, 0, 1.0); else setTextColor(1.0, 1.0, 1.0, 1.0); end; renderText(self.HudPosX+0.1085, self.HudPosY+0.0698, 0.034, string.format("%d l", self.dungFillLevel)); setTextColor(1.0, 1.0, 1.0, 1.0); if self.seedFillLevel < 1000 and self.seedTrailerIsAttached then setTextColor(1.0, 0, 0, 1.0); else setTextColor(1.0, 1.0, 1.0, 1.0); end; renderText(self.HudPosX+0.1085, self.HudPosY+0.032, 0.034, string.format("%d kg", self.seedFillLevel)); setTextColor(1.0, 1.0, 1.0, 1.0); end; if self.isTurnedOn then g_currentMission:addHelpButtonText(string.format(g_i18n:getText("AirseederOff"), self.typeDesc), InputBinding.IMPLEMENT_EXTRA); if self.dungTrailerIsAttached and self.dungFillLevel ~= 0 then if self.dungOn then g_currentMission:addHelpButtonText(string.format(g_i18n:getText("dung_Active"), self.typeDesc), InputBinding.DUNG_ON); else g_currentMission:addHelpButtonText(string.format(g_i18n:getText("dung_Deactive"), self.typeDesc), InputBinding.DUNG_ON); end; end; if self.noTill then g_currentMission:addHelpButtonText(g_i18n:getText("noTillActive"), InputBinding.SEEDMODE); else g_currentMission:addHelpButtonText(g_i18n:getText("noTillDeactive"), InputBinding.SEEDMODE); end; else g_currentMission:addHelpButtonText(string.format(g_i18n:getText("rebuild"), self.typeDesc), InputBinding.REBUILD); g_currentMission:addHelpButtonText(string.format(g_i18n:getText("AirseederOn"), self.typeDesc), InputBinding.IMPLEMENT_EXTRA); end; else g_currentMission:addHelpButtonText(string.format(g_i18n:getText("rebuild"), self.typeDesc), InputBinding.REBUILD); end; if math.abs(self.speedViolationTimer - self.speedViolationMaxTime) > 3 then g_currentMission:addWarning(g_i18n:getText("Dont_drive_to_fast") .. "\n" .. string.format(g_i18n:getText("Cruise_control_levelN"), "1", InputBinding.getButtonKeyName(InputBinding.SPEED_LEVEL1)), 0.07+0.022, 0.019+0.029); end; end; end; function bigSowingMachine:getSaveAttributesAndNodes(nodeIdent) if self.workMode then transportMode = "false"; else transportMode = "true"; end; local attributes = 'transport="'..transportMode..'"'; return attributes, nil; end; function bigSowingMachine:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) local transportMode = getXMLString(xmlFile, key.."#transport"); if transportMode == "false" and not resetVehicles then self.workMode = true; self.attacherJoint = self.attacherJoint2; end; return BaseMission.VEHICLE_LOAD_OK; end; function bigSowingMachine:onAttach() bigSowingMachine.onActivate(self); end; function bigSowingMachine:onDetach() if self.deactivateOnDetach then bigSowingMachine.onDeactivate(self); else bigSowingMachine.onDeactivateSounds(self); end; setVisibility(self.brakeLight, false); end; function bigSowingMachine:attachImplement(object, jointIndex) local attachableTrailer = g_currentMission.attachableInMountRange; if attachableTrailer.isDungTankTrailer then table.insert(self.dungTrailer, attachableTrailer); end; if attachableTrailer.isSeedTankTrailer then table.insert(self.seedTrailer, attachableTrailer); end; if table.getn(self.seedTrailer[1].dungTrailer) ~= 0 then table.insert(self.dungTrailer, self.seedTrailer[1].dungTrailer[1]); table.remove(self.seedTrailer[1].dungTrailer, 1); end; end; function bigSowingMachine:detachImplement(implementIndex) local numSeedTrailer = table.getn(self.seedTrailer); local numDungTrailer = table.getn(self.dungTrailer); if numSeedTrailer > 0 then table.remove(self.seedTrailer, numSeedTrailer); end; if numDungTrailer > 0 then table.remove(self.dungTrailer, numDungTrailer); end; end; function bigSowingMachine:onEnter() bigSowingMachine.onActivate(self); end; function bigSowingMachine:onLeave() if self.deactivateOnLeave then bigSowingMachine.onDeactivate(self); end; end; function bigSowingMachine:onActivate() end; function bigSowingMachine:onDeactivate() self.speedViolationTimer = self.speedViolationMaxTime; if self.groundParticleSystemActive then self.groundParticleSystemActive = false; Utils.setEmittingState(self.groundParticleSystems, false); end; bigSowingMachine.onDeactivateSounds(self); end; function bigSowingMachine:onDeactivateSounds() if self.sowingSoundEnabled then stopSample(self.sowingSound); self.sowingSoundEnabled = false; end; end; function bigSowingMachine:aiTurnOn() if self.dungOffToTurn then self.dungOn = true; end; self:setFoldDirection(1); end; function bigSowingMachine:aiTurnOff() self:setFoldDirection(-1); self.dungOn = false; end; function bigSowingMachine:aiLower() self:setFoldDirection(1); if self.dungOffToTurn then self.dungOn = true; end; end; function bigSowingMachine:aiRaise() self:setFoldDirection(-1); if self.dungOn then if self.foldAnimTime < 0.15 then self.dungOn = false; self.dungOffToTurn = true; end; end; end; function bigSowingMachine:anim(varName, loopCheck) if self.moveColli[varName] ~= nil then local Collision = self.collisionArm[varName]; setJointFrame(Collision.index, 0, Collision.armAttacher); end; local loopCheck = self.loopCheck[varName]; local speed = Utils.getNoNil(self.Speed[varName],1); local offset = 10; local charId = getAnimCharacterSet(self.charId[varName]); local clipIndex = getAnimClipIndex(charId, self.clipIndex[varName]); if self.Done[varName] ~= false then if self.Go[varName] == true then assignAnimTrackClip(charId , 0, clipIndex); setAnimTrackLoopState(charId, 0, loopCheck); setAnimTrackSpeedScale(charId, 0, speed); enableAnimTrack(charId, 0); if getAnimTrackTime(charId, 0) >= getAnimClipDuration(charId, clipIndex) and loopCheck == false then self.Done[varName] = false; self.CheckDone[varName] = self.Go[varName]; end; if getAnimTrackTime(charId, 0) >= getAnimClipDuration(charId, clipIndex) and loopCheck then local setTime = getAnimClipDuration(charId, clipIndex) - getAnimClipDuration(charId, clipIndex); setAnimTrackTime(charId, 0, setTime); end; elseif self.Go[varName] == false then if loopCheck == true then self.Done[varName] = false; else assignAnimTrackClip(charId , 0, clipIndex); setAnimTrackLoopState(charId, 0, loopCheck); setAnimTrackSpeedScale(charId, 0, -speed); enableAnimTrack(charId, 0); if getAnimTrackTime(charId, 0) <= 0 then self.Done[varName] = false; self.CheckDone[varName] = self.Go[varName]; end; end; elseif self.Go[varName] ~= nil then assignAnimTrackClip(charId , 0, clipIndex); setAnimTrackLoopState(charId, 0, loopCheck); if self.Go[varName] < 0.0 then self.Go[varName] = 0.0; elseif self.Go[varName] > getAnimClipDuration(charId, clipIndex) then self.Go[varName] = getAnimClipDuration(charId, clipIndex); end; if getAnimTrackTime(charId, 0) >= self.Go[varName] then setAnimTrackSpeedScale(charId, 0, -speed); else setAnimTrackSpeedScale(charId, 0, speed); end; enableAnimTrack(charId, 0); if getAnimTrackTime(charId, 0) <= self.Go[varName] + offset and getAnimTrackTime(charId, 0) >= self.Go[varName] - offset then self.Done[varName] = false; self.CheckDone[varName] = self.Go[varName]; end; end; end; if self.Done[varName] == false then disableAnimTrack(charId, 0); end; end; function bigSowingMachine:connectCollisions(varName) local Collision = self.collisionArm[varName]; local constr = JointConstructor:new(); constr:setActors(self.rootNode, Collision.collision); constr:setJointTransforms(Collision.armAttacher, Collision.collisionAttacher); for i=1, 3 do constr:setRotationLimit(i-1, 0, 0, 0); constr:setTranslationLimit(i-1, true, 0, 0); end; Collision.index = constr:finalize(); end; function bigSowingMachine:brake() for k,implement in pairs(self.attachedImplements) do if implement.object.brake then implement.object:brake(); end; end; end; function bigSowingMachine:releaseBrake() for k,implement in pairs(self.attachedImplements) do if implement.object.releaseBrake then implement.object:releaseBrake(); end; end; end;