diff --git a/DevHelper.lua b/DevHelper.lua index bd09bfc17..9ef8fd15e 100644 --- a/DevHelper.lua +++ b/DevHelper.lua @@ -87,6 +87,7 @@ function DevHelper:update() self.data.isField, self.fieldArea, self.totalFieldArea = courseplay:isField(self.data.x, self.data.z, 3, 3) self.data.landId = PathfinderUtil.getFieldIdAtWorldPosition(self.data.x, self.data.z) + self.data.owned = PathfinderUtil.isWorldPositionOwned(self.data.x, self.data.z) self.data.fieldAreaPercent = 100 * self.fieldArea / self.totalFieldArea self.data.collidingShapes = '' @@ -149,8 +150,6 @@ end -- Left-Ctrl + , (<) = mark current field as field for pathfinding -- Left-Alt + Space = save current vehicle position -- Left-Ctrl + Space = restore current vehicle position --- Left-Alt + / = look for bales --- Left-Ctrl + / = find path to next bale function DevHelper:keyEvent(unicode, sym, modifier, isDown) if not CpManager.isDeveloper then return end if bitAND(modifier, Input.MOD_LALT) ~= 0 and isDown and sym == Input.KEY_comma then @@ -186,10 +185,6 @@ function DevHelper:keyEvent(unicode, sym, modifier, isDown) elseif bitAND(modifier, Input.MOD_LCTRL) ~= 0 and isDown and sym == Input.KEY_space then -- restore vehicle position DevHelper.restoreVehiclePosition(g_currentMission.controlledVehicle) - elseif bitAND(modifier, Input.MOD_LALT) ~= 0 and isDown and sym == Input.KEY_slash then - self:initBales() - elseif bitAND(modifier, Input.MOD_LCTRL) ~= 0 and isDown and sym == Input.KEY_slash then - self:findPathToNextBale() end end @@ -284,61 +279,6 @@ function DevHelper:showFillNodes() end end -function DevHelper:findBales(fieldId) - self:debug('Finding bales on field %d...', fieldId or 0) - local bales = {} - for _, object in pairs(g_currentMission.nodeToObject) do - if object:isa(Bale) then - local bale = BaleToCollect(object) - if not fieldId or fieldId == 0 or bale:getFieldId() == fieldId then - bales[object.id] = bale - end - end - end - return bales -end - -function DevHelper:initBales() - local allBales = self:findBales() - local closestBale, d = self:findClosestBale(allBales, self.node) - self:debug('Closest bale is at %.1f m, on field %d', d, closestBale:getFieldId()) - self.bales = self:findBales(closestBale:getFieldId()) -end - ----@return BaleToCollect, number closest bale and its distance -function DevHelper:findClosestBale(bales, node) - local closestBale, minDistance = nil, math.huge - for _, bale in pairs(bales) do - local _, _, _, d = bale:getPositionFromNodeInfo(node) - if d < minDistance then - closestBale = bale - minDistance = d - end - end - return closestBale, minDistance -end - -function DevHelper:findPathToNextBale() - if not self.bales then return end - local baleId - for id, bale in pairs(self.bales) do - -- first figure out the direction at the goal, as the pathfinder needs that. - -- for now, just use the direction from our location towards the bale - local xb, zb, yRot, d = bale:getPositionFromNodeInfo(self.node) - - self.start = State3D(self.data.x, -self.data.z, courseGenerator.fromCpAngleDeg(self.data.yRotDeg)) - self.goal = State3D(xb, -zb, courseGenerator.fromCpAngle(yRot)) - local offset = Vector(0, 3.5) - self.goal:add(offset:rotate(self.goal.t)) - - self:startPathfinding() - baleId = id - break - end - -- remove bale from list - if baleId then self.bales[baleId] = nil end -end - function DevHelper:showVehicleSize() local vehicle = g_currentMission.controlledVehicle if not vehicle then return end diff --git a/course-generator/PathfinderUtil.lua b/course-generator/PathfinderUtil.lua index f18eb4a2c..3e7889069 100644 --- a/course-generator/PathfinderUtil.lua +++ b/course-generator/PathfinderUtil.lua @@ -190,6 +190,12 @@ function PathfinderUtil.getFieldIdAtWorldPosition(posX, posZ) return 0 end +--- Is the land at this position owned by me? +function PathfinderUtil.isWorldPositionOwned(posX, posZ) + local farmland = g_farmlandManager:getFarmlandAtWorldPosition(posX, posZ) + return farmland and farmland.isOwned +end + --- Pathfinder context ---@class PathfinderUtil.Context PathfinderUtil.Context = CpObject() @@ -485,7 +491,7 @@ function PathfinderConstraints:getNodePenalty(node) local offField = area / totalArea < minRequiredAreaRatio if self.fieldNum ~= 0 and not offField then -- if there's a preferred field and we are on a field - if self.fieldNum ~= PathfinderUtil.getFieldIdAtWorldPosition(node.x, -node.y) then + if not PathfinderUtil.isWorldPositionOwned(node.x, -node.y) then -- the field we are on is not ours, more penalty! offField = true offFieldPenalty = self.offFieldPenalty * 1.2 diff --git a/modDesc.xml b/modDesc.xml index 60adc2a54..8f930fc97 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -1,6 +1,6 @@ - 6.03.00044 + 6.03.00045 <!-- en=English de=German fr=French es=Spanish ru=Russian pl=Polish it=Italian br=Brazilian-Portuguese cs=Chinese(Simplified) ct=Chinese(Traditional) cz=Czech nl=Netherlands hu=Hungary jp=Japanese kr=Korean pt=Portuguese ro=Romanian tr=Turkish --> <en>CoursePlay SIX</en>