LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

FillTypeManager

Description
This class handles all fillTypes and fillTypeCategories
Parent
AbstractManager
Functions

addFillType

Description
Adds a new fillType
Definition
addFillType(string name, string title, boolean showOnPriceTable, float pricePerLiter, float massPerLiter, float maxPhysicalSurfaceAngle, string hudOverlayFilename, string hudOverlayFilenameSmall, string customEnv, table economicCurve)
Arguments
stringnamefillType index name
stringtitlefillType full name
booleanshowOnPriceTableshow on price table
floatpricePerLiterprice per liter
floatmassPerLitermass per liter
floatmaxPhysicalSurfaceAnglemax surface angle
stringhudOverlayFilenamehud icon
stringhudOverlayFilenameSmallhud icon small
stringcustomEnvcustom environment
tableeconomicCurveList of values with key being period and value being factor. Any missing periods are filled with 1.0.
Return Values
tablefillTypefillType object
Code
311function FillTypeManager:addFillType(name, title, showOnPriceTable, pricePerLiter, massPerLiter, maxPhysicalSurfaceAngle, hudOverlayFilename, baseDirectory, customEnv, fillPlaneColors, unitShort, palletFilename, economicCurve, diffuseMapFilename, normalMapFilename, specularMapFilename, distanceFilename, prioritizedEffectType, fillSmokeColor, fruitSmokeColor, achievementName, isBaseType)
312 if not ClassUtil.getIsValidIndexName(name) then
313 Logging.warning("'%s' is not a valid name for a fillType. Ignoring fillType!", tostring(name))
314 return nil
315 end
316
317 name = name:upper()
318
319 if isBaseType and self.nameToFillType[name] ~= nil then
320 Logging.warning("FillType '%s' already exists. Ignoring fillType!", name)
321 return nil
322 end
323
324 local fillType = self.nameToFillType[name]
325 if fillType == nil then
326 local maxNumFillTypes = 2^FillTypeManager.SEND_NUM_BITS-1
327 if #self.fillTypes >= maxNumFillTypes then
328 Logging.error("FillTypeManager.addFillType too many fill types. Only %d fill types are supported", maxNumFillTypes)
329 return
330 end
331
332 fillType = {}
333 fillType.name = name
334 fillType.index = #self.fillTypes + 1
335 fillType.title = g_i18n:convertText(title, customEnv)
336
337 if unitShort ~= nil then
338 unitShort = g_i18n:convertText(unitShort, customEnv)
339 end
340 fillType.unitShort = unitShort
341
342 self.nameToFillType[name] = fillType
343 self.nameToIndex[name] = fillType.index
344 self.indexToName[fillType.index] = name
345 self.indexToTitle[fillType.index] = fillType.title
346 self.indexToFillType[fillType.index] = fillType
347 table.insert(self.fillTypes, fillType)
348 end
349
350 fillType.achievementName = achievementName or fillType.achievementName
351 fillType.showOnPriceTable = Utils.getNoNil(showOnPriceTable, Utils.getNoNil(fillType.showOnPriceTable, false))
352 fillType.pricePerLiter = Utils.getNoNil(pricePerLiter, Utils.getNoNil(fillType.pricePerLiter, 0))
353 fillType.massPerLiter = Utils.getNoNil(massPerLiter, Utils.getNoNil(fillType.massPerLiter, 0.0001)) * FillTypeManager.MASS_SCALE
354 fillType.maxPhysicalSurfaceAngle = Utils.getNoNilRad(maxPhysicalSurfaceAngle, Utils.getNoNil(fillType.maxPhysicalSurfaceAngle, math.rad(30)))
355 fillType.hudOverlayFilename = hudOverlayFilename and Utils.getFilename(hudOverlayFilename, baseDirectory) or fillType.hudOverlayFilename
356
357 if diffuseMapFilename ~= nil then
358 fillType.diffuseMapFilename = Utils.getFilename(diffuseMapFilename, baseDirectory) or fillType.diffuseMapFilename
359 end
360 if normalMapFilename ~= nil then
361 fillType.normalMapFilename = Utils.getFilename(normalMapFilename, baseDirectory) or fillType.normalMapFilename
362 end
363 if specularMapFilename ~= nil then
364 fillType.specularMapFilename = Utils.getFilename(specularMapFilename, baseDirectory) or fillType.specularMapFilename
365 end
366 if distanceFilename ~= nil then
367 fillType.distanceFilename = Utils.getFilename(distanceFilename, baseDirectory) or fillType.distanceFilename
368 end
369
370 if fillType.index ~= FillType.UNKNOWN then
371 if fillType.hudOverlayFilename == nil or fillType.hudOverlayFilename == "" then
372 Logging.warning("FillType '%s' has no valid image assigned!", name)
373 end
374 end
375
376 if palletFilename ~= nil then
377 palletFilename = Utils.getFilename(palletFilename, baseDirectory) or fillType.palletFilename
378 if fileExists(palletFilename) then
379 fillType.palletFilename = palletFilename
380 else
381 Logging.error("Pallet xml '%s' in fillType '%s' does not exist", palletFilename, fillType.name)
382 end
383 end
384 fillType.previousHourPrice = fillType.pricePerLiter
385 fillType.startPricePerLiter = fillType.pricePerLiter
386 fillType.totalAmount = 0
387
388 fillType.fillPlaneColors = {}
389 if fillPlaneColors ~= nil then
390 fillType.fillPlaneColors[1] = fillPlaneColors[1] or fillType.fillPlaneColors[1]
391 fillType.fillPlaneColors[2] = fillPlaneColors[2] or fillType.fillPlaneColors[2]
392 fillType.fillPlaneColors[3] = fillPlaneColors[3] or fillType.fillPlaneColors[3]
393 else
394 fillType.fillPlaneColors[1] = fillType.fillPlaneColors[1] or 1.0
395 fillType.fillPlaneColors[2] = fillType.fillPlaneColors[2] or 1.0
396 fillType.fillPlaneColors[3] = fillType.fillPlaneColors[3] or 1.0
397 end
398
399 fillType.economy = fillType.economy or { factors = {}, history = {} }
400 for period = Environment.PERIOD.EARLY_SPRING, Environment.PERIOD.LATE_WINTER do
401 fillType.economy.factors[period] = economicCurve[period] or fillType.economy.factors[period] or 1.0
402 fillType.economy.history[period] = fillType.economy.factors[period] * fillType.pricePerLiter
403 end
404
405 fillType.prioritizedEffectType = prioritizedEffectType or fillType.prioritizedEffectType
406
407 if fillSmokeColor ~= nil and #fillSmokeColor == 4 then
408 fillType.fillSmokeColor = fillSmokeColor
409 end
410 if fruitSmokeColor ~= nil and #fruitSmokeColor == 4 then
411 fillType.fruitSmokeColor = fruitSmokeColor
412 end
413
414 return fillType
415end

addFillTypeCategory

Description
Adds a new fillType category
Definition
addFillTypeCategory(string name)
Arguments
stringnamefillType category index name
Return Values
tablefillTypeCategoryfillType category object
Code
696function FillTypeManager:addFillTypeCategory(name, isBaseType)
697 if not ClassUtil.getIsValidIndexName(name) then
698 print("Warning: '"..tostring(name).."' is not a valid name for a fillTypeCategory. Ignoring fillTypeCategory!")
699 return nil
700 end
701
702 name = name:upper()
703
704 if isBaseType and self.nameToCategoryIndex[name] ~= nil then
705 print("Warning: FillTypeCategory '"..tostring(name).."' already exists. Ignoring fillTypeCategory!")
706 return nil
707 end
708
709 local index = self.nameToCategoryIndex[name]
710 if index == nil then
711 local categoryFillTypes = {}
712 index = #self.categories + 1
713 table.insert(self.categories, name)
714 self.categoryNameToFillTypes[name] = categoryFillTypes
715 self.categoryIndexToFillTypes[index] = categoryFillTypes
716 self.nameToCategoryIndex[name] = index
717 end
718
719 return index
720end

addFillTypeConversion

Description
Add fill type to fill type conversion
Definition
addFillTypeConversion(integer converter, integer sourceFillTypeIndex, integer targetFillTypeIndex, float conversionFactor)
Arguments
integerconverterindex of converter
integersourceFillTypeIndexsource fill type index
integertargetFillTypeIndextarget fill type index
floatconversionFactorfactor of conversion
Code
869function FillTypeManager:addFillTypeConversion(converter, sourceFillTypeIndex, targetFillTypeIndex, conversionFactor)
870 if converter ~= nil and self.fillTypeConverters[converter] ~= nil and sourceFillTypeIndex ~= nil and targetFillTypeIndex ~= nil then
871 self.fillTypeConverters[converter][sourceFillTypeIndex] = {targetFillTypeIndex=targetFillTypeIndex, conversionFactor=conversionFactor}
872 end
873end

addFillTypeConverter

Description
Adds a new fill type converter
Definition
addFillTypeConverter(string name)
Arguments
stringnamename
Return Values
integerconverterIndexindex of converterIndex
Code
838function FillTypeManager:addFillTypeConverter(name, isBaseType)
839 if not ClassUtil.getIsValidIndexName(name) then
840 print("Warning: '"..tostring(name).."' is not a valid name for a fillTypeConverter. Ignoring fillTypeConverter!")
841 return nil
842 end
843
844 name = name:upper()
845
846 if isBaseType and self.nameToConverter[name] ~= nil then
847 print("Warning: FillTypeConverter '"..tostring(name).."' already exists. Ignoring FillTypeConverter!")
848 return nil
849 end
850
851 local index = self.converterNameToIndex[name]
852 if index == nil then
853 local converter = {}
854 table.insert(self.fillTypeConverters, converter)
855 self.converterNameToIndex[name] = #self.fillTypeConverters
856 self.nameToConverter[name] = converter
857 index = #self.fillTypeConverters
858 end
859
860 return index
861end

addFillTypeToCategory

Description
Add fillType to category
Definition
addFillTypeToCategory(Integer fillTypeIndex, Integer categoryIndex)
Arguments
IntegerfillTypeIndexindex of fillType
IntegercategoryIndexindex of category
Return Values
tablesuccesstrue if added else false
Code
727function FillTypeManager:addFillTypeToCategory(fillTypeIndex, categoryIndex)
728 if categoryIndex ~= nil and fillTypeIndex ~= nil then
729 if self.categoryIndexToFillTypes[categoryIndex] ~= nil then
730 -- category -> fillType
731 self.categoryIndexToFillTypes[categoryIndex][fillTypeIndex] = true
732
733 -- fillType -> categories
734 if self.fillTypeIndexToCategories[fillTypeIndex] == nil then
735 self.fillTypeIndexToCategories[fillTypeIndex] = {}
736 end
737 self.fillTypeIndexToCategories[fillTypeIndex][categoryIndex] = true
738
739 return true
740 end
741 end
742 return false
743end

assignDensityMapHeightTextureArrays

Description
Assignes density map height type array textures to given node id
Definition
assignDensityMapHeightTextureArrays(integer nodeId)
Arguments
integernodeIdnode id
Code
539function FillTypeManager:assignDensityMapHeightTextureArrays(nodeId)
540 if self.densityMapHeightDiffuseMap ~= nil and self.densityMapHeightNormalMap ~= nil and self.densityMapHeightSpecularMap ~= nil then
541 local material = getMaterial(nodeId, 0)
542 material = setMaterialDiffuseMap(material, self.densityMapHeightDiffuseMap, false)
543 material = setMaterialNormalMap(material, self.densityMapHeightNormalMap, false)
544 material = setMaterialGlossMap(material, self.densityMapHeightSpecularMap, false)
545 setMaterial(nodeId, material, 0)
546 end
547end

assignFillTypeTextureArrays

Description
Assignes fill type array textures to given node id
Definition
assignFillTypeTextureArrays(integer nodeId, bool diffuse, bool normal, bool specular)
Arguments
integernodeIdnode id
booldiffuseapply diffuse map (default is true)
boolnormalapply normal map (default is true)
boolspecularapply specular map (default is true)
Code
468function FillTypeManager:assignFillTypeTextureArrays(nodeId, diffuse, normal, specular)
469 local material = getMaterial(nodeId, 0)
470
471 if self.fillTypeTextureDiffuseMap ~= nil and self.fillTypeTextureDiffuseMap ~= 0 and diffuse ~= false then
472 material = setMaterialDiffuseMap(material, self.fillTypeTextureDiffuseMap, false)
473 end
474
475 if self.fillTypeTextureNormalMap ~= nil and self.fillTypeTextureNormalMap ~= 0 and normal ~= false then
476 material = setMaterialNormalMap(material, self.fillTypeTextureNormalMap, false)
477 end
478
479 if self.fillTypeTextureSpecularMap ~= nil and self.fillTypeTextureSpecularMap ~= 0 and specular ~= false then
480 material = setMaterialGlossMap(material, self.fillTypeTextureSpecularMap, false)
481 end
482
483 setMaterial(nodeId, material, 0)
484end

constructDensityMapHeightTextureArrays

Description
Constructs density map height type array textures to given node id
Definition
constructDensityMapHeightTextureArrays(table heightTypes)
Arguments
tableheightTypestable of density height map types
Code
489function FillTypeManager:constructDensityMapHeightTextureArrays(heightTypes)
490 self:deleteDensityMapHeightTextureArrays()
491
492 local diffuseMapConstr = TextureArrayConstructor.new()
493 local normalMapConstr = TextureArrayConstructor.new()
494 local specularMapConstr = TextureArrayConstructor.new()
495
496 for i=1, #heightTypes do
497 local heightType = heightTypes[i]
498
499 local fillType = self.fillTypes[heightType.fillTypeIndex]
500 if fillType ~= nil then
501 if fillType.diffuseMapFilename ~= nil and fillType.normalMapFilename ~= nil and fillType.specularMapFilename ~= nil then
502 diffuseMapConstr:addLayerFilename(fillType.diffuseMapFilename)
503 normalMapConstr:addLayerFilename(fillType.normalMapFilename)
504 specularMapConstr:addLayerFilename(fillType.specularMapFilename)
505 else
506 Logging.error("Failed to create density height map texture array. Fill type '%s' does not have textures defined!", heightType.fillTypeName)
507 return false
508 end
509 end
510 end
511
512 self.densityMapHeightDiffuseMap = diffuseMapConstr:finalize(true, true, true)
513 self.densityMapHeightNormalMap = normalMapConstr:finalize(true, false, true)
514 self.densityMapHeightSpecularMap = specularMapConstr:finalize(true, false, true)
515end

constructFillTypeDistanceTextureArray

Description
Constructs fill types texture distance array
Definition
constructFillTypeDistanceTextureArray(integer terrainDetailHeightId, integer typeFirstChannel, integer typeFirstChannel)
Arguments
integerterrainDetailHeightIdid of terrain detail height node
integertypeFirstChannelfirst type channel
integertypeFirstChannelnum type channels
Code
573function FillTypeManager:constructFillTypeDistanceTextureArray(terrainDetailHeightId, typeFirstChannel, typeNumChannels, heightTypes)
574 local distanceConstr = TerrainDetailDistanceConstructor.new(typeFirstChannel, typeNumChannels)
575
576 for i=1, #heightTypes do
577 local heightType = heightTypes[i]
578
579 local fillType = self.fillTypes[heightType.fillTypeIndex]
580 if fillType ~= nil then
581 if fillType.distanceFilename ~= nil and fillType.distanceFilename:len() > 0 then
582 distanceConstr:addTexture(i - 1, fillType.distanceFilename, 3)
583 else
584 Logging.error("Failed to create density height map distance texture array. Fill type '%s' does not have distance texture defined!", heightType.fillTypeName)
585 return false
586 end
587 end
588 end
589
590 distanceConstr:finalize(terrainDetailHeightId)
591end

constructFillTypeTextureArrays

Description
Constructs fill types texture array
Definition
constructFillTypeTextureArrays()
Code
419function FillTypeManager:constructFillTypeTextureArrays()
420 self:deleteFillTypeTextureArrays()
421
422 local diffuseMapConstr = TextureArrayConstructor.new()
423 local normalMapConstr = TextureArrayConstructor.new()
424 local specularMapConstr = TextureArrayConstructor.new()
425
426 self.fillTypeTextureArraySize = 0
427 for i=1, #self.fillTypes do
428 local fillType = self.fillTypes[i]
429
430 if fillType.diffuseMapFilename ~= nil and fillType.normalMapFilename ~= nil and fillType.specularMapFilename ~= nil then
431 diffuseMapConstr:addLayerFilename(fillType.diffuseMapFilename)
432 normalMapConstr:addLayerFilename(fillType.normalMapFilename)
433 specularMapConstr:addLayerFilename(fillType.specularMapFilename)
434 self.fillTypeTextureArraySize = self.fillTypeTextureArraySize + 1
435
436 fillType.textureArrayIndex = self.fillTypeTextureArraySize
437 end
438 end
439
440 self.fillTypeTextureDiffuseMap = diffuseMapConstr:finalize(true, true, true)
441 self.fillTypeTextureNormalMap = normalMapConstr:finalize(true, false, true)
442 self.fillTypeTextureSpecularMap = specularMapConstr:finalize(true, false, true)
443end

deleteDensityMapHeightTextureArrays

Description
Delete density map height texture arrays
Definition
deleteDensityMapHeightTextureArrays()
Code
519function FillTypeManager:deleteDensityMapHeightTextureArrays()
520 if self.densityMapHeightDiffuseMap ~= nil then
521 delete(self.densityMapHeightDiffuseMap)
522 self.densityMapHeightDiffuseMap = nil
523 end
524
525 if self.densityMapHeightNormalMap ~= nil then
526 delete(self.densityMapHeightNormalMap)
527 self.densityMapHeightNormalMap = nil
528 end
529
530 if self.densityMapHeightSpecularMap ~= nil then
531 delete(self.densityMapHeightSpecularMap)
532 self.densityMapHeightSpecularMap = nil
533 end
534end

deleteFillTypeTextureArrays

Description
Removes fill types texture array
Definition
deleteFillTypeTextureArrays()
Code
551function FillTypeManager:deleteFillTypeTextureArrays()
552 if self.fillTypeTextureDiffuseMap ~= nil then
553 delete(self.fillTypeTextureDiffuseMap)
554 self.fillTypeTextureDiffuseMap = nil
555 end
556
557 if self.fillTypeTextureNormalMap ~= nil then
558 delete(self.fillTypeTextureNormalMap)
559 self.fillTypeTextureNormalMap = nil
560 end
561
562 if self.fillTypeTextureSpecularMap ~= nil then
563 delete(self.fillTypeTextureSpecularMap)
564 self.fillTypeTextureSpecularMap = nil
565 end
566end

getConverterDataByName

Description
Returns converter data by given name
Definition
getConverterDataByName(string converterName)
Arguments
stringconverterNamename of converter
Return Values
tableconverterDataconverter data
Code
879function FillTypeManager:getConverterDataByName(converterName)
880 return self.nameToConverter[converterName and converterName:upper()]
881end

getFillTypeByIndex

Description
Gets a fillType by index
Definition
getFillTypeByIndex(integer index)
Arguments
integerindexthe fillType index
Return Values
tablefillTypethe fillType object
Code
633function FillTypeManager:getFillTypeByIndex(index)
634 return self.fillTypes[index]
635end

getFillTypeByName

Description
Gets a fillType by index name
Definition
getFillTypeByName(string name)
Arguments
stringnamethe fillType index name
Return Values
tablefillTypethe fillType object
Code
678function FillTypeManager:getFillTypeByName(name)
679 if ClassUtil.getIsValidIndexName(name) then
680 return self.nameToFillType[name:upper()]
681 end
682 return nil
683end

getFillTypeIndexByName

Description
Gets a fillType index by name
Definition
getFillTypeIndexByName(string name)
Arguments
stringnamethe fillType index name
Return Values
integerfillTypeIndexthe fillType index
Code
670function FillTypeManager:getFillTypeIndexByName(name)
671 return self.nameToIndex[name and name:upper()]
672end

getFillTypeNameByIndex

Description
Gets a fillTypeName by index
Definition
getFillTypeNameByIndex(integer index)
Arguments
integerindexthe fillType index
Return Values
stringfillTypeNamethe fillType name
Code
641function FillTypeManager:getFillTypeNameByIndex(index)
642 return self.indexToName[index]
643end

getFillTypeNamesByIndices

Description
Gets an array of fillType names from an array of fillType indices
Definition
getFillTypeNamesByIndices(table indices)
Arguments
tableindicesarray of fillType indices
Return Values
tablearrayof fillType names
Code
657function FillTypeManager:getFillTypeNamesByIndices(indices)
658 local names = {}
659 for fillTypeIndex in pairs(indices) do
660 table.insert(names, self.indexToName[fillTypeIndex])
661 end
662 return names
663end

getFillTypes

Description
Gets a list of fillTypes
Definition
getFillTypes()
Return Values
tablefillTypeslist of fillTypes
Code
688function FillTypeManager:getFillTypes()
689 return self.fillTypes
690end

getFillTypesByCategoryNames

Description
Gets a list of fillTypes of the given category names
Definition
getFillTypesByCategoryNames(string name, string warning)
Arguments
stringnamefillType category index names
stringwarninga warning text shown if a category is not found
Return Values
tablefillTypeslist of fillTypes
Code
750function FillTypeManager:getFillTypesByCategoryNames(names, warning, fillTypes)
751 fillTypes = fillTypes or {}
752 local alreadyAdded = {}
753 local categories = string.split(names, " ")
754 for _, categoryName in pairs(categories) do
755 categoryName = categoryName:upper()
756 local categoryFillTypes = self.categoryNameToFillTypes[categoryName]
757 if categoryFillTypes ~= nil then
758 for fillType, _ in pairs(categoryFillTypes) do
759 if alreadyAdded[fillType] == nil then
760 table.insert(fillTypes, fillType)
761 alreadyAdded[fillType] = true
762 end
763 end
764 else
765 if warning ~= nil then
766 print(string.format(warning, categoryName))
767 end
768 end
769 end
770 return fillTypes
771end

getFillTypesByNames

Description
Gets list of fillTypes from string with fill type names
Definition
getFillTypesByNames(string fillTypes, string warning)
Arguments
stringfillTypesfill types
stringwarningwarning if fill type not found
Return Values
tablefillTypesfill types
Code
792function FillTypeManager:getFillTypesByNames(names, warning, fillTypes)
793 fillTypes = fillTypes or {}
794 local alreadyAdded = {}
795 local fillTypeNames = string.split(names, " ")
796 for _, name in pairs(fillTypeNames) do
797 name = name:upper()
798 local fillTypeIndex = self.nameToIndex[name]
799 if fillTypeIndex ~= nil then
800 if fillTypeIndex ~= FillType.UNKNOWN then
801 if alreadyAdded[fillTypeIndex] == nil then
802 table.insert(fillTypes, fillTypeIndex)
803 alreadyAdded[fillTypeIndex] = true
804 end
805 end
806 else
807 if warning ~= nil then
808 print(string.format(warning, name))
809 end
810 end
811 end
812
813 return fillTypes
814end

getFillTypesFromXML

Description
Definition
getFillTypesFromXML()
Code
818function FillTypeManager:getFillTypesFromXML(xmlFile, categoryKey, namesKey, requiresFillTypes)
819 local fillTypes = {}
820 local fillTypeCategories = xmlFile:getValue(categoryKey)
821 local fillTypeNames = xmlFile:getValue(namesKey)
822 if fillTypeCategories ~= nil and fillTypeNames == nil then
823 fillTypes = g_fillTypeManager:getFillTypesByCategoryNames(fillTypeCategories, "Warning: '"..xmlFile:getFilename().. "' has invalid fillTypeCategory '%s'.")
824 elseif fillTypeCategories == nil and fillTypeNames ~= nil then
825 fillTypes = g_fillTypeManager:getFillTypesByNames(fillTypeNames, "Warning: '"..xmlFile:getFilename().. "' has invalid fillType '%s'.")
826 elseif fillTypeCategories ~= nil and fillTypeNames ~= nil then
827 Logging.xmlWarning(xmlFile, "fillTypeCategories and fillTypeNames are both set, only one of the two allowed")
828 elseif requiresFillTypes ~= nil and requiresFillTypes then
829 Logging.xmlWarning(xmlFile, "either the '%s' or '%s' attribute has to be set", categoryKey, namesKey)
830 end
831 return fillTypes
832end

getFillTypeTextureArrays

Description
Returns fill types texture array
Definition
getFillTypeTextureArrays()
Return Values
integerfillTypeTextureDiffuseMapid of diffuse map
integerfillTypeTextureNormalMapid of normal map
integerfillTypeTextureSpecularMapid of specular map
integerfillTypeTextureArraySizesize of array
Code
451function FillTypeManager:getFillTypeTextureArrays()
452 return self.fillTypeTextureDiffuseMap, self.fillTypeTextureNormalMap, self.fillTypeTextureSpecularMap, self.fillTypeTextureArraySize
453end

getFillTypeTextureArraySize

Description
Returns fill types texture array
Definition
getFillTypeTextureArraySize()
Return Values
integerfillTypeTextureArraySizesize of array
Code
458function FillTypeManager:getFillTypeTextureArraySize()
459 return self.fillTypeTextureArraySize
460end

getFillTypeTitleByIndex

Description
Gets a fillType title by index
Definition
getFillTypeTitleByIndex(integer index)
Arguments
integerindexthe fillType index
Return Values
stringfillTypeTitlethe localized fillType title
Code
649function FillTypeManager:getFillTypeTitleByIndex(index)
650 return self.indexToTitle[index]
651end

getIsFillTypeInCategory

Description
Gets if filltype is part of a category
Definition
getIsFillTypeInCategory(string fillTypeIndex, string warning)
Arguments
stringfillTypeIndexfillType index
stringwarningwarning if fill type not found
Return Values
booleantrueif fillType is part of category
Code
778function FillTypeManager:getIsFillTypeInCategory(fillTypeIndex, categoryName)
779 local catgegoy = self.nameToCategoryIndex[categoryName]
780 if catgegoy ~= nil and self.fillTypeIndexToCategories[fillTypeIndex] then
781 return self.fillTypeIndexToCategories[fillTypeIndex][catgegoy] ~= nil
782 end
783 return false
784end

getPrioritizedEffectTypeByFillTypeIndex

Description
Returns the prioritized effect type by given fill type index
Definition
getPrioritizedEffectTypeByFillTypeIndex(integer index)
Arguments
integerindexthe fillType index
Return Values
stringclassname of effect type
Code
606function FillTypeManager:getPrioritizedEffectTypeByFillTypeIndex(index)
607 local fillType = self.fillTypes[index]
608 return fillType and fillType.prioritizedEffectType
609end

getSampleByFillType

Description
Returns sound sample of fill type
Definition
getSampleByFillType(int fillType)
Arguments
intfillTypefill type index
Return Values
tablesamplesample
Code
887function FillTypeManager:getSampleByFillType(fillType)
888 return self.fillTypeToSample[fillType]
889end

getSmokeColorByFillTypeIndex

Description
Returns the smoke color by fill type index
Definition
getSmokeColorByFillTypeIndex(integer index, bool fruitColor)
Arguments
integerindexthe fillType index
boolfruitColoruse fruit color of defined
Return Values
tablecolorsmoke color
Code
616function FillTypeManager:getSmokeColorByFillTypeIndex(index, fruitColor)
617 local fillType = self.fillTypes[index]
618 if fillType ~= nil then
619 if not fruitColor then
620 return fillType.fillSmokeColor
621 else
622 return fillType.fruitSmokeColor or fillType.fillSmokeColor
623 end
624 end
625
626 return nil
627end

getTextureArrayIndexByFillTypeIndex

Description
Returns texture array by fill type index (returns nil if not in texture array)
Definition
getTextureArrayIndexByFillTypeIndex(integer index)
Arguments
integerindexthe fillType index
Return Values
integertextureArrayIndexindex in texture array
Code
597function FillTypeManager:getTextureArrayIndexByFillTypeIndex(index)
598 local fillType = self.fillTypes[index]
599 return fillType and fillType.textureArrayIndex
600end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
87function FillTypeManager:initDataStructures()
88 self.fillTypes = {}
89 self.nameToFillType = {}
90 self.indexToFillType = {}
91 self.nameToIndex = {}
92 self.indexToName = {}
93 self.indexToTitle = {}
94
95 self.fillTypeConverters = {}
96 self.converterNameToIndex = {}
97 self.nameToConverter = {}
98
99 self.categories = {}
100 self.nameToCategoryIndex = {}
101 self.categoryIndexToFillTypes = {}
102 self.categoryNameToFillTypes = {}
103 self.fillTypeIndexToCategories = {}
104
105 self.fillTypeSamples = {}
106 self.fillTypeToSample = {}
107
108 self.fillTypeTextureDiffuseMap = nil
109 self.fillTypeTextureNormalMap = nil
110 self.fillTypeTextureSpecularMap = nil
111
112 self.modsToLoad = {}
113
114 FillType = self.nameToIndex
115 FillTypeCategory = self.categories
116end

loadDefaultTypes

Description
Definition
loadDefaultTypes()
Code
120function FillTypeManager:loadDefaultTypes()
121 local xmlFile = loadXMLFile("fillTypes", "data/maps/maps_fillTypes.xml")
122 self:loadFillTypes(xmlFile, nil, true, nil)
123 delete(xmlFile)
124end

loadFillTypes

Description
Loads fillTypes
Definition
loadFillTypes(table self, table xmlFile, string baseDirectory, boolean isBaseType, string customEnv)
Arguments
tableselftarget
tablexmlFilexml file handle
stringbaseDirectoryFor sourcing textures and sounds
booleanisBaseTypeIs basegame type
stringcustomEnvCustom environment
Return Values
booleansuccesssuccess
Code
174function FillTypeManager:loadFillTypes(xmlFile, baseDirectory, isBaseType, customEnv)
175 if type(xmlFile) ~= "table" then
176 xmlFile = XMLFile.wrap(xmlFile, FillTypeManager.xmlSchema)
177 end
178
179 if isBaseType then
180 self:addFillType("UNKNOWN", "Unknown", false, 0, 0, 0, "", baseDirectory, nil, nil, nil, nil, {}, nil, nil, nil, nil, nil, nil, nil, nil, isBaseType)
181 end
182
183 xmlFile:iterate("map.fillTypes.fillType", function(_, key)
184 local name = xmlFile:getValue(key.."#name")
185 local title = xmlFile:getValue(key.."#title")
186 local achievementName = xmlFile:getValue(key.."#achievementName")
187 local showOnPriceTable = xmlFile:getValue(key.."#showOnPriceTable")
188 local fillPlaneColors = xmlFile:getValue(key.."#fillPlaneColors", "1.0 1.0 1.0", true)
189 local unitShort = xmlFile:getValue(key.."#unitShort", "")
190
191 local kgPerLiter = xmlFile:getValue(key..".physics#massPerLiter")
192 local massPerLiter = kgPerLiter and kgPerLiter / 1000
193 local maxPhysicalSurfaceAngle = xmlFile:getValue(key..".physics#maxPhysicalSurfaceAngle")
194
195 local hudFilename = xmlFile:getValue(key..".image#hud")
196
197 local palletFilename = xmlFile:getValue(key..".pallet#filename")
198
199 local pricePerLiter = xmlFile:getValue(key..".economy#pricePerLiter")
200 local economicCurve = {}
201
202 xmlFile:iterate(key .. ".economy.factors.factor", function(_, factorKey)
203 local period = xmlFile:getValue(factorKey .. "#period")
204 local factor = xmlFile:getValue(factorKey .. "#value")
205
206 if period ~= nil and factor ~= nil then
207 economicCurve[period] = factor
208 end
209 end)
210
211 local diffuseMapFilename = xmlFile:getValue(key .. ".textures#diffuse")
212 local normalMapFilename = xmlFile:getValue(key .. ".textures#normal")
213 local specularMapFilename = xmlFile:getValue(key .. ".textures#specular")
214 local distanceFilename = xmlFile:getValue(key .. ".textures#distance")
215
216 local prioritizedEffectType = xmlFile:getValue(key..".effects#prioritizedEffectType") or "ShaderPlaneEffect"
217 local fillSmokeColor = xmlFile:getValue(key..".effects#fillSmokeColor", nil, true)
218 local fruitSmokeColor = xmlFile:getValue(key..".effects#fruitSmokeColor", nil, true)
219
220 self:addFillType(name, title, showOnPriceTable, pricePerLiter, massPerLiter, maxPhysicalSurfaceAngle, hudFilename, baseDirectory, customEnv, fillPlaneColors, unitShort, palletFilename, economicCurve, diffuseMapFilename, normalMapFilename, specularMapFilename, distanceFilename, prioritizedEffectType, fillSmokeColor, fruitSmokeColor, achievementName, isBaseType or false)
221 end)
222
223 xmlFile:iterate("map.fillTypeCategories.fillTypeCategory", function(_, key)
224 local name = xmlFile:getValue(key.."#name")
225 local fillTypesStr = xmlFile:getValue(key) or ""
226 local fillTypeCategoryIndex = self:addFillTypeCategory(name, isBaseType)
227 if fillTypeCategoryIndex ~= nil then
228 local fillTypeNames = fillTypesStr:split(" ")
229 for _, fillTypeName in ipairs(fillTypeNames) do
230 local fillType = self:getFillTypeByName(fillTypeName)
231 if fillType ~= nil then
232 if not self:addFillTypeToCategory(fillType.index, fillTypeCategoryIndex) then
233 Logging.warning("Could not add fillType '"..tostring(fillTypeName).."' to fillTypeCategory '"..tostring(name).."'!")
234 end
235 else
236 Logging.warning("Unknown FillType '"..tostring(fillTypeName).."' in fillTypeCategory '"..tostring(name).."'!")
237 end
238 end
239 end
240 end)
241
242 xmlFile:iterate("map.fillTypeConverters.fillTypeConverter", function(_, key)
243 local name = xmlFile:getValue(key.."#name")
244 local converter = self:addFillTypeConverter(name, isBaseType)
245 if converter ~= nil then
246 xmlFile:iterate(key .. ".converter", function(_, converterKey)
247 local from = xmlFile:getValue(converterKey.."#from")
248 local to = xmlFile:getValue(converterKey.."#to")
249 local factor = xmlFile:getValue(converterKey.."#factor")
250
251 local sourceFillType = g_fillTypeManager:getFillTypeByName(from)
252 local targetFillType = g_fillTypeManager:getFillTypeByName(to)
253
254 if sourceFillType ~= nil and targetFillType ~= nil and factor ~= nil then
255 self:addFillTypeConversion(converter, sourceFillType.index, targetFillType.index, factor)
256 end
257 end)
258 end
259 end)
260
261 xmlFile:iterate("map.fillTypeSounds.fillTypeSound", function(_, key)
262 local sample = g_soundManager:loadSampleFromXML(xmlFile, key, "sound", baseDirectory, getRootNode(), 0, AudioGroup.VEHICLE, nil, nil)
263 if sample ~= nil then
264 local entry = {}
265 entry.sample = sample
266
267 entry.fillTypes = {}
268 local fillTypesStr = xmlFile:getValue(key.."#fillTypes") or ""
269 if fillTypesStr ~= nil then
270 local fillTypeNames = fillTypesStr:split(" ")
271
272 for _, fillTypeName in ipairs(fillTypeNames) do
273 local fillType = self:getFillTypeIndexByName(fillTypeName)
274 if fillType ~= nil then
275 table.insert(entry.fillTypes, fillType)
276 self.fillTypeToSample[fillType] = sample
277 else
278 Logging.warning("Unable to load fill type '%s' for fillTypeSound '%s'", fillTypeName, key)
279 end
280 end
281 end
282
283 if xmlFile:getValue(key.."#isDefault") then
284 for fillType, _ in ipairs(self.fillTypes) do
285 if self.fillTypeToSample[fillType] == nil then
286 self.fillTypeToSample[fillType] = sample
287 end
288 end
289 end
290
291 table.insert(self.fillTypeSamples, entry)
292 end
293 end)
294
295 return true
296end

loadMapData

Description
Load data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
129function FillTypeManager:loadMapData(xmlFile, missionInfo, baseDirectory)
130 FillTypeManager:superClass().loadMapData(self)
131
132 self:loadDefaultTypes()
133
134 if XMLUtil.loadDataFromMapXML(xmlFile, "fillTypes", baseDirectory, self, self.loadFillTypes, baseDirectory, false, missionInfo.customEnvironment) then
135 -- Load additional fill types from mods
136 for _, data in ipairs(self.modsToLoad) do
137 local fillTypesXmlFile = XMLFile.load("fillTypes", data[1], FillTypeManager.xmlSchema)
138 g_fillTypeManager:loadFillTypes(fillTypesXmlFile, data[2], false, data[3])
139 fillTypesXmlFile:delete()
140 end
141
142 self:constructFillTypeTextureArrays()
143 return true
144 end
145
146 return false
147end

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
80function FillTypeManager.new(customMt)
81 local self = AbstractManager.new(customMt or FillTypeManager_mt)
82 return self
83end

unloadMapData

Description
Definition
unloadMapData()
Code
155function FillTypeManager:unloadMapData()
156 for _, sample in pairs(self.fillTypeSamples) do
157 g_soundManager:deleteSample(sample.sample)
158 end
159
160 self:deleteFillTypeTextureArrays()
161 self:deleteDensityMapHeightTextureArrays()
162
163 FillTypeManager:superClass().unloadMapData(self)
164end