-- -- HorschSW3500S -- Specialization for HorschSW3500S -- -- @author Felix "Outlaw" Sorge -- @date 13/08/09 -- @web www.ls-modsource.de - www.ls-mods.de -- -- Copyright (C) Outlaw, All Rights Reserved. -- HorschSW3500S = {}; function HorschSW3500S.prerequisitesPresent(specializations) return SpecializationUtil.hasSpecialization(Trailer, specializations); end; function HorschSW3500S:load(xmlFile) self.horschImplementInRange = SpecializationUtil.callSpecializationsFunction("horschImplementInRange"); self.horschAttacher = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.horschAttacher#index")); self.horschImplement = {}; self.aiTerrainDetailChannel1 = g_currentMission.cultivatorChannel; self.aiTerrainDetailChannel2 = g_currentMission.ploughChannel; self.safeMode = true self.ParticleSystem = {}; local i = 0; while true do local namei = string.format("vehicle.ParticleSystem.ParticleSystem(%d)", i); local nodei = Utils.indexToObject(self.components, getXMLString(xmlFile, namei .. "#index")); if nodei == nil then break; end; Utils.loadParticleSystem(xmlFile, self.ParticleSystem, namei, nodei, false, nil, self.baseDirectory) i = i +1; end; local pneuSound = getXMLString(xmlFile, "vehicle.pneuSound#file"); if pneuSound ~= nil and pneuSound ~= "" then pneuSound = Utils.getFilename(pneuSound, self.baseDirectory); self.pneuSound = createSample("pneuSound"); self.pneuSoundEnabled = false; loadSample(self.pneuSound, pneuSound, false); self.pneuSoundPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.pneuSound#pitchOffset"), 1); self.pneuSoundVolume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.pneuSound#volume"), 1); end; local workSound = getXMLString(xmlFile, "vehicle.workSound#file"); if workSound ~= nil and workSound ~= "" then workSound = Utils.getFilename(workSound, self.baseDirectory); self.workSound = createSample("workSound"); self.workSoundEnabled = false; loadSample(self.workSound, workSound, false); self.workSoundPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.workSound#pitchOffset"), 1); self.workSoundVolume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.workSound#volume"), 1); end; self.AIon = false; self.saveAILM = self.aiLeftMarker; self.aiLeftMarker = nil; self.attacherBackup = nil; self.TurnRadiusBackup = 0; self.Go.pillar = not self.Go.pillar; self.Done.pillar = true; return self; end; function HorschSW3500S:update(dt) if self:getIsActive() then if self.attacherVehicle.isAITractorActivated ~= nil then self.AIon = self.attacherVehicle.isAITractorActivated; end; if self.attacherVehicle.isAITractorActivated ~= nil then self.aiLeftMarker = self.saveAILM; AITractor.updateToolsInfo(self.attacherVehicle) end; if self.AIon then self.attacherVehicle.steeringAxleAngle = 0; end; if self.attacherBackup == nil and self.attacherVehicle ~= nil then self.attacherBackup = self.attacherVehicle; end; if self.attacherVehicle.isAITractorActivated then self.attacherVehicle.turnStage3Timeout = 0; self.stop = false; self.offsound =true; if self.fillLevel == 0 then AITractor.stopAITractor(self.attacherVehicle); self.stop = true; end; if self.attacherVehicle.turnStage == 0 then self.Go.Work = false; self.Done.Work = true; -- self.activarAreas= true ; self.offsound =true; -- self.levelCheck =true; else self.Go.Work = true; self.Done.Work = true; -- self.activarAreas= false; -- self.levelCheck =false; if self:getIsActiveForInput() then if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA2) then self.safeMode = not self.safeMode end; end; else if self.fillLevel == self.capacity and self.stop then AITractor.startAITractor(self.attacherVehicle); self.stop = false; self.Go.Work = false; self.Done.Work = true; -- self.activarAreas= true ; -- self.levelCheck =true; end; if self.attacherVehicle.isAITractorActivated ~= nil then self.attacherVehicle.turnStage3Timeout = 65000; end; end; if InputBinding.hasEvent(InputBinding.HorschSW3500S_on) and self:getIsActiveForInput() and self.horschImplement.attached and self.CheckDone.trsp and self.Go.trsp and not self.Done.trsp then self.turnOn = not self.turnOn; end; if InputBinding.hasEvent(InputBinding.HorschSW3500S_tank) and self:getIsActiveForInput() and self.horschImplement.attached then self.Go.tank = not self.Go.tank; self.Done.tank = true; end; if InputBinding.hasEvent(InputBinding.HorschSW3500S_emptytank) and self:getIsActiveForInput() and self.fillLevel ~= 0 then self.fillLevel = 0; self:setFillLevel(self.fillLevel, FruitUtil.FRUITTYPE_UNKNOWN); end; if InputBinding.hasEvent(InputBinding.HorschSW3500S_trsp) and self:getIsActiveForInput() and self.horschImplement.attached and not self.Go.down and not self.CheckDone.down and not self.Done.down and not self.turnOn then self.Speed.trsp = 1.0; self.Go.trsp = not self.Go.trsp; self.Done.trsp = true; end; if InputBinding.hasEvent(InputBinding.HorschSW3500S_lower) and self:getIsActiveForInput() then self.Speed.down = 1.0; self.Go.down = not self.Go.down; self.Done.down = true; end; if InputBinding.hasEvent(InputBinding.HorschSW3500S_attach) and self:getIsActiveForInput() and not self.blockDetach and (self.inRange or self.horschImplement.attached) and self.Go.down and not self.Done.down and self.CheckDone.down then self.horschImplement.attach = not self.horschImplement.attach; end; if not self.attacherVehicleJoint then for i=1, table.getn(self.attacherVehicle.attachedImplements) do if self.attacherVehicle.attachedImplements[i].object == self then local index = self.attacherVehicle.attachedImplements[i].jointDescIndex; self.attacherVehicleJoint = self.attacherVehicle.attacherJoints[index]; break; end; end; end; if self.turnOn then if not self.pneuSoundEnabled and self:getIsActiveForSound() then playSample(self.pneuSound, 0, self.pneuSoundVolume, 0); setSamplePitch(self.pneuSound, self.pneuSoundPitchOffset); self.pneuSoundEnabled = true; end; else if self.pneuSoundEnabled then stopSample(self.pneuSound); self.pneuSoundEnabled = false; end; end; if self.horschImplement.attached then self.fillTypes = self.horschImplement.Object.fillTypes; if self.Go.tank and not self.Done.tank and self.CheckDone.tank then self.allowFillFromAir = true; elseif not self.Go.tank then self.allowFillFromAir = false; end; else self.allowFillFromAir = false; end; if not self.Go.down then self.attacherVehicleJoint.moveDown = false; else self.attacherVehicleJoint.moveDown = true; end; if self.horschImplement.attached then setJointFrame(self.horschImplement.ObjectIndex,0,self.horschAttacher); end; if not self.inRage and self.horschImplement.attached and not self.horschImplement.attach then setMass(self.horschImplement.node, self.horschImplement.oldmass); removeJoint(self.horschImplement.ObjectIndex); self.horschImplement.Object:onDetach(self); self.horschImplement.Object = nil; self.horschImplement.ObjectIndex = 0; self.horschImplement.rootNode = false; self.horschImplement.attached = false; self.horschImplement.attach = false; self.horschImplement.name = false; end; if self.Go.down and not self.Done.down and self.CheckDone.down and self.CheckDone.trsp and self.Go.trsp and not self.Done.trsp then for v,cuttingArea in pairs(self.cuttingAreas) do local x,y,z = getWorldTranslation(cuttingArea.start); local x1,y1,z1 = getWorldTranslation(cuttingArea.width); local x2,y2,z2 = getWorldTranslation(cuttingArea.height); if self.safeMode then cultivator.updateSafeArea(x, z, x1, z1, x2, z2) else Utils.updatecultivatorArea(x, z, x1, z1, x2, z2); end; end; end; if self.movingDirection ~= 0 then if not self.workSoundEnabled and self:getIsActiveForSound() and self.Go.down and not self.Done.down and self.CheckDone.down and self.CheckDone.trsp and self.Go.trsp and not self.Done.trsp then playSample(self.workSound, 0, self.workSoundVolume, 0); setSamplePitch(self.workSound, self.workSoundPitchOffset); Utils.setEmittingState(self.ParticleSystem, true); self.workSoundEnabled = true; end; end; if self.movingDirection == 0 or not self.CheckDone.down then if self.workSoundEnabled then stopSample(self.workSound); self.workSoundEnabled = false; end; Utils.setEmittingState(self.ParticleSystem, false); end; if not self.horschImplement.attached then self:horschImplementInRange(); end; else if self.pneuSoundEnabled then stopSample(self.pneuSound); self.pneuSoundEnabled = false; end; if self.workSoundEnabled then stopSample(self.workSound); self.workSoundEnabled = false; end; end; if self.Done.down then local joint = self.componentJoints[3]; setJointFrame(joint.jointIndex, 0,joint.jointNode); end; if self.Go.down ~= nil and self.Done.down ~= false then self:anim("down", false); end; if self.Go.tank ~= nil and self.Done.tank ~= false then self:anim("tank", false); end; if self.Go.pillar ~= nil and self.Done.pillar ~= false then self:anim("pillar", false); end; if self.Go.trsp ~= nil and self.Done.trsp ~= false then self:anim("trsp", false); end; if self.attacherVehicle then for k, implement in pairs(self.attacherVehicle.attachedImplements) do if implement.object == self then local index = implement.jointDescIndex; self.attacherVehicleJoint = self.attacherVehicle.attacherJoints[index]; setJointRotationLimit(self.attacherVehicleJoint.jointIndex, 2, true, Utils.degToRad(-20), Utils.degToRad(20)); end; end; end; end; function HorschSW3500S:draw() self:addSubSettings("Horsch","Horsch SW 3500S ",InputBinding.HorschSW3500S_subHud, "textures/logo.png", 0.238,0.67,0.2,0.2,0.853); -- hudText, subText, key,keyText, logo, logoX, logoY, logoW, logoH, logoYHigher if self.inRange and not self.blockDetach and not self.CheckDone.trsp and not self.horschImplement.attached and not self.Go.down then self:addSubText(g_i18n:getText("HorschSW3500S_1"), false) end; if self.Go.trsp and self.horschImplement.attached and not self.Go.down and not self.CheckDone.down and not self.Done.down and not self.turnOn then self:addSubText(g_i18n:getText("HorschSW3500S_3"), InputBinding.HorschSW3500S_trsp); elseif not self.Go.trsp and self.horschImplement.attached and not self.Go.down and not self.CheckDone.down and not self.Done.down and not self.turnOn then self:addSubText(g_i18n:getText("HorschSW3500S_2"), InputBinding.HorschSW3500S_trsp); end; if self.inRange and not self.blockDetach and self.Go.down and not self.Done.down and self.CheckDone.down then self:addSubText(self.horschImplement.name.. " " ..g_i18n:getText("Attach"), InputBinding.HorschSW3500S_attach); elseif self.horschImplement.attached and not self.blockDetach and self.Go.down and not self.Done.down and self.CheckDone.down then self:addSubText(self.horschImplement.name.. " abkuppeln", InputBinding.HorschSW3500S_attach); end; if self.Go.down then self:addSubText(g_i18n:getText("HorschSW3500S_5"), InputBinding.HorschSW3500S_lower); else self:addSubText(g_i18n:getText("HorschSW3500S_4"), InputBinding.HorschSW3500S_lower); end; if self.Go.tank and self.horschImplement.attached then self:addSubText(g_i18n:getText("HorschSW3500S_7"), InputBinding.HorschSW3500S_tank); elseif self.horschImplement.attached then self:addSubText(g_i18n:getText("HorschSW3500S_6"), InputBinding.HorschSW3500S_tank); end; if self.fillLevel ~= 0 then self:addSubText(g_i18n:getText("HorschSW3500S_10"), InputBinding.HorschSW3500S_emptytank); end; if self.turnOn and self.horschImplement.attached and self.CheckDone.trsp and self.Go.trsp and not self.Done.trsp then self:addSubText(g_i18n:getText("HorschSW3500S_9"), InputBinding.HorschSW3500S_on); elseif self.horschImplement.attached and self.CheckDone.trsp and self.Go.trsp and not self.Done.trsp then self:addSubText(g_i18n:getText("HorschSW3500S_8"), InputBinding.HorschSW3500S_on); end; if self.safeMode then g_currentMission:addHelpButtonText("switch to normal Mode", InputBinding.IMPLEMENT_EXTRA2); else g_currentMission:addHelpButtonText("switch to safe Mode", InputBinding.IMPLEMENT_EXTRA2); end; end; function HorschSW3500S:delete() if self.horschImplement.rootNode then setMass(self.horschImplement.node, self.horschImplement.oldmass); removeJoint(self.horschImplement.ObjectIndex); self.horschImplement.Object:onDetach(self); self.horschImplement.Object = nil; self.horschImplement.ObjectIndex = 0; self.horschImplement.rootNode = false; self.horschImplement.attached = false; self.horschImplement.attach = false; self.horschImplement.name = false; end; if self.pneuSoundEnabled then stopSample(self.pneuSound); self.pneuSoundEnabled = false; end; if self.workSoundEnabled then stopSample(self.workSound); self.workSoundEnabled = false; end; Utils.setEmittingState(self.ParticleSystem, false); end; function HorschSW3500S:horschImplementInRange() self.inRange = false; local nearestDistance = 2.0; local nearestDistanceClose = 10.0; local px, py, pz = getWorldTranslation(self.horschAttacher); for i=1, table.getn(g_currentMission.attachables) do if g_currentMission.attachables[i].horschAttacher then local vx, vy, vz = getWorldTranslation(g_currentMission.attachables[i].rootNode); local distance = Utils.vector3Length(px-vx, py-vy, pz-vz); local attachable = g_currentMission.attachables[i]; if (distance < nearestDistance and not self.horschImplement.rootNode) or (distance < nearestDistanceClose and not self.horschImplement.rootNode and self.linkNow) then self.horschImplement.name = attachable.name; self.inRange = true; if (self.horschImplement.attach and not self.horschImplement.rootNode) or (distance < nearestDistanceClose and not self.horschImplement.rootNode and self.linkNow) then self.horschImplement.Object = attachable; self.horschImplement.Object:onAttach(self); local constr = JointConstructor:new(); constr:setActors(self.rootNode, attachable.rootNode); constr:setJointTransforms(self.horschAttacher, attachable.horschAttacher); constr:setRotationLimit(0, Utils.degToRad(0), Utils.degToRad(0)); constr:setRotationLimit(1, Utils.degToRad(0), Utils.degToRad(0));--0 constr:setRotationLimit(2, Utils.degToRad(0), Utils.degToRad(0)); self.horschImplement.ObjectIndex = constr:finalize(); self.horschImplement.oldMass = getMass(attachable.rootNode); setMass(attachable.rootNode, 0.2); self.inRange = false; self.linkNow = false; self.horschImplement.attached = true; self.horschImplement.rootNode = attachable.rootNode; self.horschImplement.attach = true; end; nearestDistance = distance; end; end; end; end; function HorschSW3500S:onAttach() self.Go.pillar = false; self.Done.pillar = true; self.Speed.down = 1.0; self.Go.down = false; self.Done.down = true; self.TurnRadiusBackup = self.attacherVehicle.aiTractorTurnRadius; self.attacherVehicle.aiTractorTurnRadius = 0; end; function HorschSW3500S:onDetach() if self.horschImplement.rootNode then self.horschImplement.Object.turnOn = false; end; self.attacherBackup.aiTractorTurnRadius = self.TurnRadiusBackup; self.attacherVehicle = self.attacherBackup; self.attacherVehicle = nil; self.attacherBackup = nil; self.Go.pillar = true; self.Done.pillar = true; self.Speed.down = 1.0; self.Go.down = true; self.Done.down = true; if self.pneuSoundEnabled then stopSample(self.pneuSound); self.pneuSoundEnabled = false; end; if self.workSoundEnabled then stopSample(self.workSound); self.workSoundEnabled = false; end; Utils.setEmittingState(self.ParticleSystem, false); end; function Utils.destroyCompleteArea(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ) local meadowId = g_currentMission.meadowId; local cuttedMeadowId = g_currentMission.cuttedMeadowId; Utils.updateDensity(meadowId, startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, 0, 0); Utils.updateDensity(cuttedMeadowId, startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, 0, 0); end; function HorschSW3500S:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) self.Go.down = not self.Go.down; self.Done.down = true; self.Speed.down = 10.0; if not resetVehicles then self.linkNow = Utils.getNoNil(getXMLBool(xmlFile, key.."#link"),false); self.linkName = Utils.getNoNil(getXMLString(xmlFile, key.."#linkName"),false); local trsp = getXMLBool(xmlFile, key.."#trsp"); if trsp then self.Go.trsp = not self.Go.trsp; self.Done.trsp = true; self.Speed.trsp = 10.0; end; end; return BaseMission.VEHICLE_LOAD_OK; end; function HorschSW3500S:getSaveAttributesAndNodes(nodeIdent) local attributes = 'link="'..tostring(self.horschImplement.attached)..'" trsp="'..tostring(self.CheckDone.trsp)..'" linkName="'..tostring(self.horschImplement.name)..'"'; return attributes, nil; end; function HorschSW3500S:aiLower() self.Speed.down = 1.0; self.Go.down = not self.Go.down; self.Done.down = true; end; function HorschSW3500S:aiRaise() self.Speed.down = 1.0; self.Go.down = not self.Go.down; self.Done.down = true; end; function HorschSW3500S:mouseEvent(posX, posY, isDown, isUp, button) end; function HorschSW3500S:keyEvent(unicode, sym, modifier, isDown) end;