LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

FieldUtil

Description
Util for field jobs
Functions

getFruitArea

Description
Returns amount of fruit to work is in given area
Definition
getFruitArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, table terrainDetailRequiredValueRanges, table terrainDetailProhibitValueRanges, integer requiredfruittype, integer requiredMinGrowthState, integer requiredMaxGrowthState, integer prohibitedFruitType, integer prohibitedMinGrowthState, integer prohibitedMaxGrowthState, boolean useWindrowed)
Arguments
floatstartWorldXstart world x
floatstartWorldZstart world z
floatwidthWorldXwidth world x
floatwidthWorldZwidth world z
floatheightWorldXheight world x
floatheightWorldZheight world z
tableterrainDetailRequiredValueRangesterrain detail required value ranges
tableterrainDetailProhibitValueRangesterrain detail prohibit value ranges
integerrequiredfruittyperequired fruit type
integerrequiredMinGrowthStaterequired min growth state
integerrequiredMaxGrowthStaterequired max growth state
integerprohibitedFruitTypeprohibited fruit type
integerprohibitedMinGrowthStateprohibited min growth state
integerprohibitedMaxGrowthStateprohibited max growth state
booleanuseWindroweduse windrow
Return Values
floatareaarea found
floattotalAreatotal area checked
Code
379function FieldUtil.getFruitArea(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, terrainDetailRequiredValueRanges, terrainDetailProhibitValueRanges, requiredFruitType, requiredMinGrowthState, requiredMaxGrowthState, prohibitedFruitType, prohibitedMinGrowthState, prohibitedMaxGrowthState, useWindrowed)
380 local query = g_currentMission.fieldCropsQuery
381
382 local groundTypeMapId, groundTypeFirstChannel, groundTypeNumChannels = g_currentMission.fieldGroundSystem:getDensityMapData(FieldDensityMap.GROUND_TYPE)
383
384 if requiredFruitType ~= FruitType.UNKNOWN then
385 local fruitTypeDesc = g_fruitTypeManager:getFruitTypeByIndex(requiredFruitType)
386 if fruitTypeDesc ~= nil and fruitTypeDesc.terrainDataPlaneId ~= nil then
387 if useWindrowed then
388 return 0, 1
389 end
390
391 query:addRequiredCropType(fruitTypeDesc.terrainDataPlaneId, requiredMinGrowthState, requiredMaxGrowthState, fruitTypeDesc.startStateChannel, fruitTypeDesc.numStateChannels, 0, 0)--groundTypeMapId, groundTypeFirstChannel, groundTypeNumChannels) -- needs engine fix so we can use different mapId
392 end
393 end
394
395 if prohibitedFruitType ~= FruitType.UNKNOWN then
396 local fruitTypeDesc = g_fruitTypeManager:getFruitTypeByIndex(prohibitedFruitType)
397 if fruitTypeDesc ~= nil and fruitTypeDesc.terrainDataPlaneId ~= nil then
398 query:addProhibitedCropType(fruitTypeDesc.terrainDataPlaneId, prohibitedMinGrowthState, prohibitedMaxGrowthState, fruitTypeDesc.startStateChannel, fruitTypeDesc.numStateChannels, groundTypeFirstChannel, groundTypeNumChannels)
399 end
400 end
401
402 for _,valueRange in pairs(terrainDetailRequiredValueRanges) do
403 query:addRequiredGroundValue(valueRange[1], valueRange[2], valueRange[3], valueRange[4])
404 end
405 for _,valueRange in pairs(terrainDetailProhibitValueRanges) do
406 query:addProhibitedGroundValue(valueRange[1], valueRange[2], valueRange[3], valueRange[4])
407 end
408
409 local x,z, widthX,widthZ, heightX,heightZ = MathUtil.getXZWidthAndHeight(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ)
410 return query:getParallelogram(x,z, widthX,widthZ, heightX,heightZ, true)
411end