straightdrive = {}; function straightdrive.prerequisitesPresent(specializations) return true; end function straightdrive:load() end function straightdrive:draw() if self.isAITractorActivated then self.fahren = false else if self.KompassX and self.KompassZ then g_currentMission:addHelpButtonText(g_i18n:getText("Drive on"), InputBinding.Driveon); if InputBinding.hasEvent(InputBinding.Driveon) then if self.fahren then self.fahren = false straightdrive:raiseimplement(self) self.motor:setSpeedLevel(0, false); self.motor.maxRpmOverride = nil; WheelsUtil.updateWheelsPhysics(self, 0, self.lastSpeed, 0, false, self.requiredDriveMode); else self.aiTractorDirectionX = self.KompassX;self.aiTractorDirectionZ = self.KompassZ;self.fahren = true straightdrive:lowerimplement(self) end end if self.fahren then local x,y,z = getWorldTranslation(self.rootNode); local dirX, dirZ = self.aiTractorDirectionX, self.aiTractorDirectionZ; local targetX, targetZ = self.aiTractorTargetX, self.aiTractorTargetZ; local dx, dz = x-targetX, z-targetZ; local dot = dx*dirX + dz*dirZ; local projTargetX = targetX +dirX; local projTargetZ = targetZ +dirZ; newTargetX = projTargetX+self.aiTractorDirectionX*dot; newTargetY = y; newTargetZ = projTargetZ+self.aiTractorDirectionZ*dot; local lx, lz = AIVehicleUtil.getDriveDirection(self.rootNode, newTargetX, newTargetY, newTargetZ); AIVehicleUtil.driveInDirection(self, dt, 25, 0.5, 0.5, 20, true, true, lx, lz, 1, 0.9); end end local x,y,z = localDirectionToWorld(self.rootNode, 0, 0, 1); local length = Utils.vector2Length(x,z); local dX = x/length local dZ = z/length local x,y,z = getWorldTranslation(self.rootNode); self.aiTractorTargetX = x; self.aiTractorTargetZ = z; local TEntfernung = math.sqrt(dX * dX + dZ * dZ) local TRichtung = math.deg(math.atan2(dX,dZ)) if TRichtung < 0 then TRichtung = 360 - (TRichtung * -1) end if not self.Beforeturn then self.Beforeturn = true ;end if self.fahren then g_currentMission:addHelpButtonText(g_i18n:getText("Turn Right"), InputBinding.Turnright); g_currentMission:addHelpButtonText(g_i18n:getText("Turn Left"), InputBinding.Turnleft); if InputBinding.hasEvent(InputBinding.Turnleft) then TRichtung = TRichtung + 90;self.turn = true;self.dreht = true if TRichtung > 360 then TRichtung = TRichtung - 360 end self.Beforeturn = TRichtung end if InputBinding.hasEvent(InputBinding.Turnright) then TRichtung = TRichtung - 90;self.turn = true;self.dreht = true if TRichtung < 0 then TRichtung = TRichtung + 360 end self.Beforeturn = TRichtung end end renderText(0.85,0.77,0.03,string.format("Richtung: %f ",360 - math.floor(TRichtung + 0.5) )); self.KompassX = TEntfernung * math.sin(math.rad( math.floor(TRichtung + 0.5)) ) self.KompassZ = TEntfernung * math.cos(math.rad( math.floor(TRichtung + 0.5)) ) if self.turn and self.dreht then self.aiTractorDirectionX = self.KompassX;self.aiTractorDirectionZ = self.KompassZ; straightdrive:raiseimplement(self) self.dreht = false self.wait = true end if not self.wait then if self.turn then if math.floor(self.Beforeturn + 0.5) == math.floor(TRichtung + 0.5) then self.turn = false straightdrive:lowerimplement(self) end end end self.wait = false end end function straightdrive:update() end function straightdrive:delete() end; function straightdrive:mouseEvent(posX, posY, isDown, isUp, button) end function straightdrive:keyEvent(unicode, sym, modifier, isDown) end; function straightdrive:raiseimplement(self) for k,implement in pairs(self.attachedImplements) do if implement.object.needsLowering and implement.object.aiNeedsLowering then local jointDesc = self.attacherJoints[implement.jointDescIndex]; jointDesc.moveDown = false; end; for k,implement in pairs(self.attachedImplements) do implement.object:aiRaise(); end; end; end function straightdrive:lowerimplement(self) AITractor.updateToolsInfo(self); for k,implement in pairs(self.attachedImplements) do if implement.object.needsLowering and implement.object.aiNeedsLowering then local jointDesc = self.attacherJoints[implement.jointDescIndex]; jointDesc.moveDown = true; end; implement.object:aiTurnOn(); AITractor.addToolTrigger(self, implement.object); end; end