COMMUNITY FORUM

Making the forage harvester to pickup straw

Forum Overview >> Farming Simulator 19

CategoryFarming Simulator 19
Created08.02.2021 10:15


Boris Klinko (Boris555) 08.02.2021 10:15
Hello,
I am trying to make the forage harvester to pickup straw. So far I have changed maps_fruitTypes.xml, I have added straw to pickup and forage harvester, but it doesn't work.

<fruitTypeCategories>
<fruitTypeCategory name="PICKUP" >GRASS DRYGRASS STRAW</fruitTypeCategory>

and

<fruitTypeConverters>
<fruitTypeConverter name="FORAGEHARVESTER">
<converter from="STRAW" to="STRAW" factor="1.0" windrowFactor="1.0" />

Is there some setting that I don't know about?

Bilbo Beutlin (BBeutlin) 08.02.2021 12:14
Doesn't work.
As the name says: a fruitTypeConverter can only convert "fruitType". And straw isn't it.

Boris Klinko (Boris555) 09.02.2021 09:17
Thank you for advice Bilbo, I assumed that straw is fruit. I have never looked carefully in the list because I believe that maps_fruitTypes.xml only adds new fruits or overwrites existing ones. How exactly does this work, are fruits listed in this file only ones accessible on the map?

I did some experiments, only solution that worked was when straw was converted to chaff, but that is not what I need. I only need to pickup straw without converting. Then I looked how grass works and I have added straw_windrow to fill types. But that solution doesn't work. What am I still missing?

Xml looks like this

<fruitType name="straw" title="straw" showOnPriceTable="false" shownOnMap="false" useForFieldJob="false">
<general startStateChannel="0" numStateChannels="4" />
<cultivation needsSeeding="false" allowsSeeding="false" useSeedingWidth="false" directionSnapAngle="0" alignsToSun="false"
seedUsagePerSqm="0.02" />
<harvest minHarvestingGrowthState="2" maxHarvestingGrowthState="3" cutState="1" allowsPartialGrowthState="false"
literPerSqm="4.37" />
<growth witheringNumGrowthStates="4" numGrowthStates="4" growthStateTime="26000000" resetsSpray="true"
groundTypeChangeGrowthState="-1" groundTypeChanged="NONE" growthRequiresLime="false" />
<windrow name="straw_windrow" litersPerSqm="4.37" />
<options lowSoilDensityRequired="false" increasesSoilDensity="false" consumesLime="false" startSprayState="1" />
<mapColors default="0.0823 0.1221 0.0292 1" colorBlind="1.0000 0.9473 0.0369 1"/>
</fruitType>


<fruitTypeCategory name="PICKUP" >GRASS DRYGRASS ALFALFA STRAW</fruitTypeCategory>

<fruitTypeConverter name="FORAGEHARVESTER">
<converter from="STRAW" to="STRAW_WINDROW" factor="1.0" windrowFactor="1.0" />


<fillType name="STRAW_WINDROW" title="$l10n_fillType_straw" showOnPriceTable="true" pricePerLiter="0.041" >
<image hud="$dataS2/menu/hud/fillTypes/hud_fill_straw.png" hudSmall="$dataS2/menu/hud/fillTypes/hud_fill_straw_sml.png" />
<physics massPerLiter="0.06" maxPhysicalSurfaceAngle="50" />
</fillType>

Boris Klinko (Boris555) 09.03.2021 09:38
I have found a working example here

https://www.modding-welt.com/mods/file/2262-claas-jaguar-800-pack/#versions

so what they did here is to configure this in map

<fruitTypeConverter name="FORAGEHARVESTERSTRAW">
<converter from="WHEAT" to="STRAW" factor="1.3" windrowFactor="1.0" />
<converter from="BARLEY" to="STRAW" factor="1.3" windrowFactor="1.0" />
<converter from="OAT" to="STRAW" factor="1.3" windrowFactor="1.0" />
<converter from="CANOLA" to="STRAW" factor="1.3" windrowFactor="1.0" />
<converter from="SOYBEAN" to="STRAW" factor="1.3" windrowFactor="1.0" />
</fruitTypeConverter>

and

<fillTypeCategory name="FORAGEHARVESTERSTRAW">STRAW</fillTypeCategory>



Pickup configuration
<cutter fruitTypes="wheat barley oat rye soybean canola" fruitTypeConverter="forageHarvesterstraw" useWindrowed="true">


Chopper configuration
…. fillTypeCategories="forageHarvesterstraw"/>



I still haven't tried to reproduce this but I have question about game mechanics. What I really don't understand is how come the pickup is configured to convert fruits to straw, when he is actually working with straw? I see attribute useWindrowed="true" does that mean that the straw is actually windrowed form of fruit? Like what I see on ground as straw the game sees it as wheat in windrowed form, and when pickup interacts with that heap he is converting windrowed form of wheat to straw which is not a fruit but just a fill type. Does this mean that there are two kind's of straw in game, one is windrowed form of different fruits and the the other is fill type?

Bilbo Beutlin (BBeutlin) 09.03.2021 15:14
In earlier FS versions each grain windrow had its own straw type, like "wheat_windrow", "barley_windrow", etc.
Of course that made processing more complicate, so there was introduced the common windrow type "straw". This determines now the "fruitTypes.xml" <fruitType> <windrow name="straw" - so you don't need to convert anymore in tools or for terrainDetailHeight (heaps).

Boris Klinko (Boris555) 11.04.2021 10:06
Hello Bilbo,

I have managed to make this work on another map with example chopper. Now I am trying to make the BigX chopper from game to pickup straw. As it needs fill type configuration I have added it but I keep getting error. Any ideas why is there error? The fill type configuration is identical to example chopper and the example chopper is working without problem.

Here is my xml

<fillUnit>
<fillUnitConfigurations title="$l10n_configuration_Straw">
<fillUnitConfiguration name="$l10n_ui_no" price="0">
<fillUnits>
<fillUnit unit="$l10n_unit_literShort" showOnHud="false" fillTypeCategories="forageHarvester"/>
<fillUnit unit="$l10n_unit_literShort" showOnHud="false" showInShop="false" fillTypes="diesel" capacity="1290">
<dashboard displayType="NUMBER" valueType="fillLevelPct" numbers="numbersFuel" numberColor="0.1 0.1 0.1 1" precision="0" groups="MOTOR_ACTIVE"/>
<dashboard displayType="ANIMATION" valueType="fillLevel" animName="fuelDisplay" groups="MOTOR_ACTIVE"/>
</fillUnit>
<fillUnit unit="$l10n_unit_literShort" showOnHud="false" showInShop="false" fillTypes="def" capacity="200">
<dashboard displayType="NUMBER" valueType="fillLevelPct" numbers="numbersDef" numberColor="0.1 0.1 0.1 1" precision="0" groups="MOTOR_ACTIVE"/>
<dashboard displayType="ANIMATION" valueType="fillLevel" animName="defDisplay" groups="MOTOR_ACTIVE"/>
</fillUnit>
</fillUnits>
</fillUnitConfiguration>
<fillUnitConfiguration name="$l10n_ui_yes" price="0" >
<fillUnits>
<fillUnit unit="$l10n_unit_literShort" showOnHud="false" fillTypeCategories="forageHarvesterstraw"/>
<fillUnit unit="$l10n_unit_literShort" showOnHud="false" showInShop="false" fillTypes="diesel" capacity="1050">
<dashboard displayType="NUMBER" valueType="fillLevelPct" numbers="numbersFuel" numberColor="0.1 0.1 0.1 1" precision="0" groups="MOTOR_ACTIVE"/>
<dashboard displayType="ANIMATION" valueType="fillLevel" animName="fuelDisplay" groups="MOTOR_ACTIVE"/>
</fillUnit>
<fillUnit unit="$l10n_unit_literShort" showOnHud="false" showInShop="false" fillTypes="def" capacity="178">
<dashboard displayType="NUMBER" valueType="fillLevelPct" numbers="numbersDef" numberColor="0.1 0.1 0.1 1" precision="0" groups="MOTOR_ACTIVE"/>
<dashboard displayType="ANIMATION" valueType="fillLevel" animName="defDisplay" groups="MOTOR_ACTIVE"/>
</fillUnit>
</fillUnits>
</fillUnitConfiguration>
</fillUnitConfigurations>
</fillUnitConfigurations>
</fillUnit>

This is error

2021-04-11 09:46 Error: H:/Games/FS19 mods/BlankMap/bigx_straw/bigX1180.xml. fillUnit.
2021-04-11 09:46 Error (H:/Games/FS19 mods/BlankMap/bigx_straw/bigX1180.xml): No storeData found. StoreItem will be ignored!

Bilbo Beutlin (BBeutlin) 11.04.2021 10:56
You have the closing tag </fillUnitConfigurations> twice. Expected is </fillUnit>.
Due to this XML error the complete tag <fillUnit> is invalid.

I'd recommand using Notepad++ plugin "XML Tools" for xml validation.

Boris Klinko (Boris555) 12.04.2021 10:46
Hello Bilbo,

yes I have XML Tools installed, but despite that I managed to make error. Thank you for reply.

Anyway, I got this working by editing xml as in example, Now I would like to try and make a mod that will make this possible on any map with any forage harvester and pickup.

As first step I would like to add fillTypeCategory, for example I am using Lizard biofuel mod. That mod is using global company to add fill types to map. I have tried to the same but I got this error.

2021-04-12 10:08 Warning: 'H:/Games/FS19 mods/BlankMap/bigx_straw/bigX1180.xml' has invalid fillTypeCategory 'FORAGEHARVESTERSTRAW'.

I have global company mod loading, my fillTypes.xml in mod folder is

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<map>
<fillTypeCategories>
<fillTypeCategory name="FORAGEHARVESTERSTRAW">STRAW</fillTypeCategory>
</fillTypeCategories>
</map>

And I have copied GC_checker.lua and added it to the mod.desc

<extraSourceFiles>
<sourceFile filename="GC_Checker.lua" />
</extraSourceFiles>

Beside using global company, is there another way to add this via script? I have found function g_fillTypeManager:addFillType but when I tried g_fillTypeManager: fillTypeCategory I found nothing.

Bilbo Beutlin (BBeutlin) 13.04.2021 10:50
Unluckily the fillTypeManager functions are not documented completely. Neither here on GDN nor in Giants Debugger.

But by investigating its function table, you'll find a function FillTypeManager:addFillTypeCategory(). However I don't know proper parameters. I'd guess something like addFillTypeCategory(name, fillTypes).

Boris Klinko (Boris555) 13.04.2021 14:07
How can I see function table of a class?

You were correct, I have tried print(tostring(g_fillTypeManager:addFillTypeCategory("FORAGEHARVESTERSTRAW",{"Straw"}))) and got 21 in response, so I believe it is working correctly.

Now I need to find how to execute this correctly. I have attached script to combine.onLoad but script executes after the mod chopper I am using for testing. I have also tried check is fill type category was added correctly by executing getFillTypeCategories (I quess it exists) but got error on that.

So question is how do I ensure my script is loaded before any chopper is loaded, and how can I see list of FillTypeCategories?

Here is my code:

function StrawChopper:onLoad(savegame)
print("in function")
print(tostring(g_fillTypeManager:addFillTypeCategory("FORAGEHARVESTERSTRAW",{"Straw"})))
for index, value in ipairs(g_fillTypeManager:getFillTypeCategories()) do
print(tostring(index), tostring(value))
end
end;

Combine.onLoad = Utils.appendedFunction(Combine.onLoad, StrawChopper.onLoad);

and log:

Warning: 'H:/Games/FS19 mods/BlankMap/FS19_ClaasJaguar800_Straw_Edition/xml/jaguar800.xml' has invalid fillTypeCategory 'FORAGEHARVESTERSTRAW'.
2021-04-13 13:52 data/particleSystems/shared/exhaust.i3d (0.44 ms)
2021-04-13 13:52 data/shared/assets/lights/lizard/rearPlateNumberLight_01.i3d (0.71 ms)
2021-04-13 13:52 data/shared/assets/beaconLights/lizard/beaconLight06.i3d (0.73 ms)
2021-04-13 13:52 in function
2021-04-13 13:52 21
2021-04-13 13:52 Error: Running LUA method 'loadSharedI3DFileFinished'.
2021-04-13 13:52 H:/Games/FS19 mods/BlankMap/script_forageHarvester_straw/strawChopper.lua:20: attempt to call method 'getFillTypeCategories' (a nil value)

Bilbo Beutlin (BBeutlin) 13.04.2021 14:40
To examine tables simply use the 'DebugUtil.printTableRecursively()', see LUADOC/Debug.

Timing order of certain actions/functions is sometimes tricky. You'll need to test and 'print()' out elaborately.

If you need your mod executed before or after loading other mods, name it accordingly. The mods get loaded in alphabetical order. So name your mod eg. "AAA_myMod" or "ZZZ_myMod" to get it loaded first or finally.

Boris Klinko (Boris555) 13.04.2021 18:55
I have moved execution of script to FillUnit.OnLoad and now it is loaded before chopper is. However it still doesn't work, this is the code

function StrawChopper:onLoad(savegame)
print(tostring(g_fillTypeManager:addFillTypeCategory("FORAGEHARVESTERSTRAW",{g_fillTypeManager:getFillTypeByIndex(31)})))
DebugUtil.printTableRecursively(g_fillTypeManager:getFillTypesByCategoryNames("FORAGEHARVESTER","Warning"), "FORAGEHARVESTER ", 0, 3)
DebugUtil.printTableRecursively(g_fillTypeManager:getFillTypesByCategoryNames("FORAGEHARVESTERSTRAW","Warning"), "FORAGEHARVESTERSTRAW ", 0, 3)
end;

FillUnit.onLoad = Utils.prependedFunction(FillUnit.onLoad, StrawChopper.onLoad);

It executes few times during loading, first time that print returns 21 and on other times returns nil. 21 is index of chaff fill type, 31 is index of straw fill type.
first debug returns as expected

FORAGEHARVESTER 1 :: 28
FORAGEHARVESTER 2 :: 21
FORAGEHARVESTER 3 :: 30
FORAGEHARVESTER 4 :: 23

but second debug returns nothing. Also on secon execution and on later ones this warrning appears

Warning: FillTypeCategory 'FORAGEHARVESTERSTRAW' already exists. Ignoring fillTypeCategory!

So I believe g_fillTypeManager:addFillTypeCategory is adding this category, but somehow it is empty. Have I used the function correctly?

Bilbo Beutlin (BBeutlin) 13.04.2021 20:45
Like I said before, I don't know exactly. But I'd assume the parameters are the same as in fillTypes.xml:
addFillTypeCategory( (string) name, (string) fillTypes ), like eg.
addFillTypeCategory( "GRAIN", "wheat barley oat rye" )

Boris Klinko (Boris555) 15.04.2021 12:07
I managed to to add fill type category. Now I need to add fruit type converter. For that I would like to read xml file in order to keep the code clean.
I have tried:

local xmlFile = loadXMLFile("TempXML", "fruit_categories.xml")

this is my fruit_categories.xml, it is in same folder as my script:

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<fruitTypeConverter name="FORAGEHARVESTERSTRAW">
<converter from="WHEAT" to="STRAW" factor="1.3" windrowFactor="1.0" />
<converter from="BARLEY" to="STRAW" factor="1.3" windrowFactor="1.0" />
<converter from="OAT" to="STRAW" factor="1.3" windrowFactor="1.0" />
<converter from="CANOLA" to="STRAW" factor="1.3" windrowFactor="1.0" />
<converter from="SOYBEAN" to="STRAW" factor="1.3" windrowFactor="1.0" />
</fruitTypeConverter>

I am getting this error

Error: Failed to open xml file 'fruit_categories.xml'.

Bilbo Beutlin (BBeutlin) 15.04.2021 12:33
You must specify the path to your file, since in functions the current active directory may be elsewhere.
Best is you do that just at begin of your mod in the basic code:
myMod = {}
myMod.homeDir = g_currentModDirectory -- points to root dir of your mod/map
Then you can access later the file with
local fruitCatFile = Utils.getFilename("path/fruit_categories.xml", myMod.homeDir)

Boris Klinko (Boris555) 17.04.2021 13:18
Your solution is working. Xml file is read and g_fruitTypeManager.nameToConverter.FORAGEHARVESTERSTRAW table is created and filled with data from xml. However this table looks differently then when it is loaded normally from maps_fruitTypes.xml, and i believe that is the reason why the script isn't working. Is the difference really the reason and what is fill type unknown?

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is g_fruitTypeManager.nameToConverter.FORAGEHARVESTERSTRAW table when it is normaly loaded from maps_fruitTypes.xml

--From printTable with xml (works)
FORAGEHARVESTERSTRAW :: table: 0x022528187528
2021-04-17 11:26 1 :: table: 0x022526e9cb58
2021-04-17 11:26 conversionFactor :: 1.2999999523163
2021-04-17 11:26 fillTypeIndex :: 31
2021-04-17 11:26 windrowConversionFactor :: 1
2021-04-17 11:26 2 :: table: 0x022521742618
2021-04-17 11:26 conversionFactor :: 1.2999999523163
2021-04-17 11:26 fillTypeIndex :: 31
2021-04-17 11:26 windrowConversionFactor :: 1
2021-04-17 11:26 3 :: table: 0x02252a162af0
2021-04-17 11:26 conversionFactor :: 1.2999999523163
2021-04-17 11:26 fillTypeIndex :: 31
2021-04-17 11:26 windrowConversionFactor :: 1
2021-04-17 11:26 5 :: table: 0x022521923f00
2021-04-17 11:26 conversionFactor :: 1.2999999523163
2021-04-17 11:26 fillTypeIndex :: 31
2021-04-17 11:26 windrowConversionFactor :: 1
2021-04-17 11:26 7 :: table: 0x022529fb4398
2021-04-17 11:26 conversionFactor :: 1.2999999523163
2021-04-17 11:26 fillTypeIndex :: 31
2021-04-17 11:26 windrowConversionFactor :: 1
-------------------------------------------------------------------------------------------------------------------------------------
This is when script loads xml from mod folder

--From printTable with my script (doesn't work)
FORAGEHARVESTERSTRAW :: table: 0x02617c3e53d8
2021-04-17 11:19 2 :: table: 0x02617c3e5590
2021-04-17 11:19 conversionFactor :: 1.3
2021-04-17 11:19 fillTypeIndex :: 31
2021-04-17 11:19 windrowConversionFactor :: 1
2021-04-17 11:19 3 :: table: 0x02617c3e57a0
2021-04-17 11:19 conversionFactor :: 1.3
2021-04-17 11:19 fillTypeIndex :: 31
2021-04-17 11:19 windrowConversionFactor :: 1
2021-04-17 11:19 4 :: table: 0x02617c3e59b8
2021-04-17 11:19 conversionFactor :: 1.3
2021-04-17 11:19 fillTypeIndex :: 31
2021-04-17 11:19 windrowConversionFactor :: 1
2021-04-17 11:19 5 :: table: 0x02617c3e5ba8
2021-04-17 11:19 conversionFactor :: 1.3
2021-04-17 11:19 fillTypeIndex :: 31
2021-04-17 11:19 windrowConversionFactor :: 1
2021-04-17 11:19 7 :: table: 0x02617c3e5db0
2021-04-17 11:19 conversionFactor :: 1.3
2021-04-17 11:19 fillTypeIndex :: 31
2021-04-17 11:19 windrowConversionFactor :: 1

----------------------------------------------------------------------------------------------------------------------------------
g_fillTypeManager. indexToName are indetical in both cases

2021-04-17 12:20 -- g_fillTypeManager (START) -- with my script (doesn't work)
2021-04-17 12:20 indexToName :: table: 0x021dd42eba10
2021-04-17 12:20 1 :: UNKNOWN
2021-04-17 12:20 2 :: WHEAT
2021-04-17 12:20 3 :: BARLEY
2021-04-17 12:20 4 :: OAT
2021-04-17 12:20 5 :: CANOLA
2021-04-17 12:20 6 :: SUNFLOWER
2021-04-17 12:20 7 :: SOYBEAN
2021-04-17 12:20 8 :: MAIZE
2021-04-17 12:20 9 :: POTATO


021-04-17 12:32 -- g_fillTypeManager.indexToName (START) -- with xml (works)
2021-04-17 12:32 1 :: UNKNOWN
2021-04-17 12:32 2 :: WHEAT
2021-04-17 12:32 3 :: BARLEY
2021-04-17 12:32 4 :: OAT
2021-04-17 12:32 5 :: CANOLA
2021-04-17 12:32 6 :: SUNFLOWER
2021-04-17 12:32 7 :: SOYBEAN
2021-04-17 12:32 8 :: MAIZE
2021-04-17 12:32 9 :: POTATO

------------------------------------------------------------------------------------
the code

function StrawChopper:onLoad(savegame)
-- add FORAGEHARVESTERSTRAW category to fill types
if g_fillTypeManager:getFillTypeIndexByName("STRAW") then
local strawFillIndex = g_fillTypeManager:getFillTypeIndexByName("STRAW")
if g_fillTypeManager.nameToCategoryIndex["FORAGEHARVESTERSTRAW"] == nil then
local fillTypeCategoryIndex = g_fillTypeManager:addFillTypeCategory("FORAGEHARVESTERSTRAW")
g_fillTypeManager.categoryNameToFillTypes["FORAGEHARVESTERSTRAW"][strawFillIndex]=true
end
end

--add fruit type category
local fruitCatFile = Utils.getFilename("fruit_categories.xml", StrawChopper.homeDir)
local xmlFile = loadXMLFile("TempXML", fruitCatFile)

if not g_fruitTypeManager.nameToConverter["FORAGEHARVESTERSTRAW"] then
g_fruitTypeManager.nameToConverter["FORAGEHARVESTERSTRAW"] = {}

local key = "fruitTypeConverter";
if hasXMLProperty(xmlFile, key) then
local i = 0;
while true do
local settingKey = string.format("%s.converter(%d)", key, i);
if not hasXMLProperty(xmlFile, settingKey) then
break;
end;

local from = g_fillTypeManager:getFillTypeIndexByName(getXMLString(xmlFile, settingKey .. "#from"));
local to = g_fillTypeManager:getFillTypeIndexByName(getXMLString(xmlFile, settingKey .. "#to"));
if not g_fruitTypeManager.nameToConverter["FORAGEHARVESTERSTRAW"][from] then
g_fruitTypeManager.nameToConverter["FORAGEHARVESTERSTRAW"][from]= {}
end
g_fruitTypeManager.nameToConverter["FORAGEHARVESTERSTRAW"][from]["conversionFactor"] = 1.3;
g_fruitTypeManager.nameToConverter["FORAGEHARVESTERSTRAW"][from]["fillTypeIndex"] = to;
g_fruitTypeManager.nameToConverter["FORAGEHARVESTERSTRAW"][from]["windrowConversionFactor"] = 1;

i = i + 1;
end;
end;
end;
end;

FillUnit.onLoad = Utils.prependedFunction(FillUnit.onLoad, StrawChopper.onLoad);

Bilbo Beutlin (BBeutlin) 17.04.2021 14:58
The fillType "UNKNOWN" is a placeholder, often used for undefined/empty fillUnits.

Since your table dumps are different to default setup, the method is probably also different as you're assuming.
Unluckily the setup of converters is not documented in LUADOCs or Giants Debugger lua sources.
If you don't want to experiment furtheron with trial and error, consider to ask a Giants developer.

I didn't examine your code in detail, but what I noticed on 1st overview:
- where the default table begins with index 1, your one begins with 2
- for checking on 'nil' you're often using "if not ..", that's not proper code. Where 'nil' is undefined, 'not ..' expects a boolean. That doesn't give an error, since 'nil' gives also 'false'. But may lead to unexpected results, eg. if the tested value indeed is boolean 'false' instead undefined 'nil'. I know, this is often used, but bad coding. *g*

Boris Klinko (Boris555) 21.04.2021 11:18
Thanks Bilbo,
problem is solved by inserting unknown fill type in .xml and I have corrected code according to your suggestion.

Now I am moving on, I need to add new shop configuration to chopper and pickup. I have seen some similar mods and I think I can repeat that, but I can't find link between chopper and his fruit type categories. I was reading the documentation and noticed that when chopper is loading its xml in function Combine:onLoad he isn't loading fruit type categories, that is loaded in function FillUnit:loadFillUnitFromXML. How does combine/chopper knows which fruit type category to use?

Bilbo Beutlin (BBeutlin) 21.04.2021 13:03
You have looked at the wrong place. *g*
The converters are loaded by the processing tool like cutter, mower.


Note: Log in to post. Create a new account here.