Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- AbstractManager
- AdditionalFieldBuyInfo
- BaleManager
- ConnectionHoseManager
- CropSensorLinkageData
- ExtendedWeedControl
- FillTypeManager
- FruitTypeManager
- ManureSensorLinkageData
- ProductionChainManager
- SplitTypeManager
- SprayTypeManager
- TensionBeltManager
- Timer
- ToolTypeManager
- TreePlantManager
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
FruitTypeManager
DescriptionThis class handles all fruitTypes and fruitTypeCategoriesParent
AbstractManagerFunctions
- addFruitType
- addFruitTypeCategory
- addFruitTypeConversion
- addFruitTypeConverter
- addFruitTypeToCategory
- getConverterDataByName
- getCutHeightByFruitTypeIndex
- getFillTypeByFruitTypeIndex
- getFillTypeIndexByFruitTypeIndex
- getFillTypeLiterPerSqm
- getFillTypesByFruitTypeCategoryName
- getFillTypesByFruitTypeNames
- getFruitTypeByFillTypeIndex
- getFruitTypeByIndex
- getFruitTypeByName
- getFruitTypeIndexByFillTypeIndex
- getFruitTypeNameByIndex
- getFruitTypes
- getFruitTypesByCategoryNames
- getFruitTypesByNames
- getWindrowFillTypeIndexByFruitTypeIndex
- initDataStructures
- isFillTypeWindrow
- loadDefaultTypes
- loadFruitTypeCropCare
- loadFruitTypeCultivation
- loadFruitTypeDestruction
- loadFruitTypeGrowth
- loadFruitTypeHarvest
- loadFruitTypeMapColors
- loadFruitTypeOptions
- loadFruitTypePreparing
- loadFruitTypes
- loadFruitTypeWindrow
- loadMapData
- new
addFruitType
DescriptionAdds a new fruitTypeDefinition
addFruitType(string name, boolean shownOnMap, boolean useForFieldJob)Arguments
string | name | fruit index name |
boolean | shownOnMap | show on map |
boolean | useForFieldJob | use for field job |
table | fruitType | fruitType type object |
296 | function FruitTypeManager:addFruitType(name, shownOnMap, useForFieldJob, missionMultiplier, isBaseType) |
297 | if not ClassUtil.getIsValidIndexName(name) then |
298 | print("Warning: '"..tostring(name).."' is not a valid name for a fruitType. Ignoring fruitType!") |
299 | return nil |
300 | end |
301 | |
302 | local upperName = name:upper() |
303 | |
304 | local fillType = g_fillTypeManager:getFillTypeByName(upperName) |
305 | if fillType == nil then |
306 | print("Warning: Missing fillType '"..tostring(name).."' for fruitType definition. Ignoring fruitType!") |
307 | return nil |
308 | end |
309 | |
310 | if isBaseType and self.nameToFruitType[upperName] ~= nil then |
311 | print("Warning: FillType '"..tostring(name).."' already exists. Ignoring fillType!") |
312 | return nil |
313 | end |
314 | |
315 | local fruitType = self.nameToFruitType[upperName] |
316 | if fruitType == nil then |
317 | fruitType = {} |
318 | fruitType.layerName = name |
319 | fruitType.name = upperName |
320 | fruitType.index = #self.fruitTypes + 1 |
321 | fruitType.fillType = fillType |
322 | |
323 | fruitType.defaultMapColor = {1, 1, 1, 1} |
324 | fruitType.colorBlindMapColor = {1, 1, 1, 1} |
325 | end |
326 | |
327 | fruitType.shownOnMap = Utils.getNoNil(shownOnMap, Utils.getNoNil(fruitType.shownOnMap, true)) |
328 | fruitType.useForFieldJob = Utils.getNoNil(useForFieldJob, Utils.getNoNil(fruitType.useForFieldJob, true)) |
329 | fruitType.missionMultiplier = Utils.getNoNil(missionMultiplier, Utils.getNoNil(fruitType.missionMultiplier, 1.0)) |
330 | |
331 | return fruitType |
332 | end |
addFruitTypeCategory
DescriptionAdds a new fruitType categoryDefinition
addFruitTypeCategory(string name)Arguments
string | name | fruit category index name |
table | fruitTypeCategory | fruitType category object |
724 | function FruitTypeManager:addFruitTypeCategory(name, isBaseType) |
725 | if not ClassUtil.getIsValidIndexName(name) then |
726 | print("Warning: '"..tostring(name).."' is not a valid name for a fruitTypeCategory. Ignoring fruitTypeCategory!") |
727 | return nil |
728 | end |
729 | |
730 | name = name:upper() |
731 | |
732 | if isBaseType and self.categories[name] ~= nil then |
733 | print("Warning: FruitTypeCategory '"..tostring(name).."' already exists. Ignoring fruitTypeCategory!") |
734 | return nil |
735 | end |
736 | |
737 | local index = self.categories[name] |
738 | |
739 | if index == nil then |
740 | self.numCategories = self.numCategories + 1 |
741 | self.categories[name] = self.numCategories |
742 | self.indexToCategory[self.numCategories] = name |
743 | self.categoryToFruitTypes[self.numCategories] = {} |
744 | index = self.numCategories |
745 | end |
746 | |
747 | return index |
748 | end |
addFruitTypeConversion
DescriptionAdd fruit type to fill type conversionDefinition
addFruitTypeConversion(integer converter, integer fruitTypeIndex, integer fillTypeIndex, float conversionFactor, float windrowConversionFactor)Arguments
integer | converter | index of converter |
integer | fruitTypeIndex | fruit type index |
integer | fillTypeIndex | fill type index |
float | conversionFactor | factor of conversion |
float | windrowConversionFactor | factor of windrow conversion |
950 | function FruitTypeManager:addFruitTypeConversion(converter, fruitTypeIndex, fillTypeIndex, conversionFactor, windrowConversionFactor) |
951 | if converter ~= nil and self.fruitTypeConverters[converter] ~= nil and fruitTypeIndex ~= nil and fillTypeIndex ~= nil then |
952 | self.fruitTypeConverters[converter][fruitTypeIndex] = {fillTypeIndex=fillTypeIndex, conversionFactor=conversionFactor, windrowConversionFactor=windrowConversionFactor} |
953 | end |
954 | end |
addFruitTypeConverter
DescriptionAdds a new fruit type converterDefinition
addFruitTypeConverter(string name)Arguments
string | name | name |
integer | converterIndex | index of converterIndex |
918 | function FruitTypeManager:addFruitTypeConverter(name, isBaseType) |
919 | if not ClassUtil.getIsValidIndexName(name) then |
920 | print("Warning: '"..tostring(name).."' is not a valid name for a fruitTypeConverter. Ignoring fruitTypeConverter!") |
921 | return nil |
922 | end |
923 | |
924 | name = name:upper() |
925 | |
926 | if isBaseType and self.converterNameToIndex[name] ~= nil then |
927 | print("Warning: FruitTypeConverter '"..tostring(name).."' already exists. Ignoring fruitTypeConverter!") |
928 | return nil |
929 | end |
930 | |
931 | local index = self.converterNameToIndex[name] |
932 | if index == nil then |
933 | local converter = {} |
934 | table.insert(self.fruitTypeConverters, converter) |
935 | self.converterNameToIndex[name] = #self.fruitTypeConverters |
936 | self.nameToConverter[name] = converter |
937 | index = #self.fruitTypeConverters |
938 | end |
939 | |
940 | return index |
941 | end |
addFruitTypeToCategory
DescriptionAdd fruitType to categoryDefinition
addFruitTypeToCategory(Integer fruitTypeIndex, Integer categoryIndex)Arguments
Integer | fruitTypeIndex | index of fruit type |
Integer | categoryIndex | index of category |
table | success | true if added else false |
755 | function FruitTypeManager:addFruitTypeToCategory(fruitTypeIndex, categoryIndex) |
756 | if categoryIndex ~= nil and fruitTypeIndex ~= nil then |
757 | table.insert(self.categoryToFruitTypes[categoryIndex], fruitTypeIndex) |
758 | return true |
759 | end |
760 | return false |
761 | end |
getConverterDataByName
DescriptionReturns converter data by given nameDefinition
getConverterDataByName(string converterName)Arguments
string | converterName | name of converter |
table | converterData | converter data |
960 | function FruitTypeManager:getConverterDataByName(converterName) |
961 | return self.nameToConverter[converterName and converterName:upper()] |
962 | end |
getCutHeightByFruitTypeIndex
DescriptionDefinitiongetCutHeightByFruitTypeIndex()Code
711 | function FruitTypeManager:getCutHeightByFruitTypeIndex(index, isForageCutter) |
712 | local fruitType = self.indexToFruitType[index] |
713 | if isForageCutter then |
714 | return (fruitType and (fruitType.forageCutHeight or fruitType.cutHeight)) or 0.15 |
715 | end |
716 | |
717 | return (fruitType and fruitType.cutHeight) or 0.15 |
718 | end |
getFillTypeByFruitTypeIndex
DescriptionDefinitiongetFillTypeByFruitTypeIndex()Code
705 | function FruitTypeManager:getFillTypeByFruitTypeIndex(index) |
706 | return self.fruitTypeIndexToFillType[index] |
707 | end |
getFillTypeIndexByFruitTypeIndex
DescriptionDefinitiongetFillTypeIndexByFruitTypeIndex()Code
695 | function FruitTypeManager:getFillTypeIndexByFruitTypeIndex(index) |
696 | local fillType = self.fruitTypeIndexToFillType[index] |
697 | if fillType ~= nil then |
698 | return fillType.index |
699 | end |
700 | return nil |
701 | end |
getFillTypeLiterPerSqm
DescriptionGet fill type liter per sqmDefinition
getFillTypeLiterPerSqm(integer fillType, float defaultValue)Arguments
integer | fillType | fill type |
float | defaultValue | default value if fill type not found |
float | literPerSqm | liter per sqm |
902 | function FruitTypeManager:getFillTypeLiterPerSqm(fillType, defaultValue) |
903 | local fruitType = self.fruitTypes[self:getFruitTypeIndexByFillTypeIndex(fillType)] |
904 | if fruitType ~= nil then |
905 | if fruitType.hasWindrow then |
906 | return fruitType.windrowLiterPerSqm |
907 | else |
908 | return fruitType.literPerSqm |
909 | end |
910 | end |
911 | return defaultValue |
912 | end |
getFillTypesByFruitTypeCategoryName
DescriptionGets a list of fillTypes from string with fruit type category namesDefinition
getFillTypesByFruitTypeCategoryName(string fruitTypeCategories, string warning)Arguments
string | fruitTypeCategories | fruit type categories |
string | warning | warning if category not found |
table | fillTypes | fill types |
855 | function FruitTypeManager:getFillTypesByFruitTypeCategoryName(fruitTypeCategories, warning) |
856 | local fillTypes = {} |
857 | local alreadyAdded = {} |
858 | local categories = string.split(fruitTypeCategories, " ") |
859 | for _, categoryName in pairs(categories) do |
860 | categoryName = categoryName:upper() |
861 | local category = self.categories[categoryName] |
862 | if category ~= nil then |
863 | for _, fruitTypeIndex in ipairs(self.categoryToFruitTypes[category]) do |
864 | local fillType = self:getFillTypeByFruitTypeIndex(fruitTypeIndex) |
865 | if fillType ~= nil then |
866 | if alreadyAdded[fillType.index] == nil then |
867 | table.insert(fillTypes, fillType.index) |
868 | alreadyAdded[fillType.index] = true |
869 | end |
870 | end |
871 | end |
872 | else |
873 | if warning ~= nil then |
874 | print(string.format(warning, categoryName)) |
875 | end |
876 | end |
877 | end |
878 | return fillTypes |
879 | end |
getFillTypesByFruitTypeNames
DescriptionGets a list if fillType from string with fruit type namesDefinition
getFillTypesByFruitTypeNames(string names, string warning)Arguments
string | names | fruit type names |
string | warning | warning if fill type not found |
table | fillTypes | fill types |
825 | function FruitTypeManager:getFillTypesByFruitTypeNames(names, warning) |
826 | local fillTypes = {} |
827 | local alreadyAdded = {} |
828 | local fruitTypeNames = string.split(names, " ") |
829 | for _, name in pairs(fruitTypeNames) do |
830 | local fillType = nil |
831 | local fruitType = self:getFruitTypeByName(name) |
832 | if fruitType ~= nil then |
833 | fillType = self:getFillTypeByFruitTypeIndex(fruitType.index) |
834 | end |
835 | if fillType ~= nil then |
836 | if alreadyAdded[fillType.index] == nil then |
837 | table.insert(fillTypes, fillType.index) |
838 | alreadyAdded[fillType.index] = true |
839 | end |
840 | else |
841 | if warning ~= nil then |
842 | print(string.format(warning, name)) |
843 | end |
844 | end |
845 | end |
846 | |
847 | return fillTypes |
848 | end |
getFruitTypeByFillTypeIndex
DescriptionDefinitiongetFruitTypeByFillTypeIndex()Code
689 | function FruitTypeManager:getFruitTypeByFillTypeIndex(index) |
690 | return self.fruitTypes[self.fillTypeIndexToFruitTypeIndex[index]] |
691 | end |
getFruitTypeByIndex
DescriptionGets a fruitType by indexDefinition
getFruitTypeByIndex(integer index)Arguments
integer | index | the fruit index |
table | fruit | the fruit object |
653 | function FruitTypeManager:getFruitTypeByIndex(index) |
654 | return self.indexToFruitType[index] |
655 | end |
getFruitTypeByName
DescriptionGets a fruitType by index nameDefinition
getFruitTypeByName(string name)Arguments
string | name | the fruit index name |
table | fruit | the fruit object |
670 | function FruitTypeManager:getFruitTypeByName(name) |
671 | return self.nameToFruitType[name and name:upper()] |
672 | end |
getFruitTypeIndexByFillTypeIndex
DescriptionDefinitiongetFruitTypeIndexByFillTypeIndex()Code
683 | function FruitTypeManager:getFruitTypeIndexByFillTypeIndex(index) |
684 | return self.fillTypeIndexToFruitTypeIndex[index] |
685 | end |
getFruitTypeNameByIndex
DescriptionDefinitiongetFruitTypeNameByIndex()Code
659 | function FruitTypeManager:getFruitTypeNameByIndex(index) |
660 | if self.indexToFruitType[index] ~= nil then |
661 | return self.indexToFruitType[index].name |
662 | end |
663 | return nil |
664 | end |
getFruitTypes
DescriptionGets a list of fruitTypesDefinition
getFruitTypes()Return Values
table | fruitTypes | a list of fruitTypes |
677 | function FruitTypeManager:getFruitTypes() |
678 | return self.fruitTypes |
679 | end |
getFruitTypesByCategoryNames
DescriptionGets a list of fruitTypes of the given category namesDefinition
getFruitTypesByCategoryNames(string name, string warning)Arguments
string | name | fruitType category index names |
string | warning | a warning text shown if a category is not found |
table | fruitTypes | list of fruitTypes |
769 | function FruitTypeManager:getFruitTypesByCategoryNames(names, warning) |
770 | local fruitTypes = {} |
771 | local alreadyAdded = {} |
772 | local categories = string.split(names, " ") |
773 | for _, categoryName in pairs(categories) do |
774 | categoryName = categoryName:upper() |
775 | local categoryIndex = self.categories[categoryName] |
776 | local categoryFruitTypes = self.categoryToFruitTypes[categoryIndex] |
777 | if categoryFruitTypes ~= nil then |
778 | for _, fruitType in ipairs(categoryFruitTypes) do |
779 | if alreadyAdded[fruitType] == nil then |
780 | table.insert(fruitTypes, fruitType) |
781 | alreadyAdded[fruitType] = true |
782 | end |
783 | end |
784 | else |
785 | if warning ~= nil then |
786 | print(string.format(warning, categoryName)) |
787 | end |
788 | end |
789 | end |
790 | return fruitTypes |
791 | end |
getFruitTypesByNames
DescriptionGets list of fruitTypes from string with fruit type namesDefinition
getFruitTypesByNames(string fruitTypes, string warning)Arguments
string | fruitTypes | fruit types |
string | warning | warning if fruit type not found |
table | fruitTypes | fruit types |
798 | function FruitTypeManager:getFruitTypesByNames(names, warning) |
799 | local fruitTypes = {} |
800 | local alreadyAdded = {} |
801 | local fruitTypeNames = string.split(names, " ") |
802 | for _, name in pairs(fruitTypeNames) do |
803 | name = name:upper() |
804 | local fruitTypeIndex = self.nameToIndex[name] |
805 | if fruitTypeIndex ~= nil then |
806 | if alreadyAdded[fruitTypeIndex] == nil then |
807 | table.insert(fruitTypes, fruitTypeIndex) |
808 | alreadyAdded[fruitTypeIndex] = true |
809 | end |
810 | else |
811 | if warning ~= nil then |
812 | print(string.format(warning, name)) |
813 | end |
814 | end |
815 | end |
816 | |
817 | return fruitTypes |
818 | end |
getWindrowFillTypeIndexByFruitTypeIndex
DescriptionDefinitiongetWindrowFillTypeIndexByFruitTypeIndex()Code
892 | function FruitTypeManager:getWindrowFillTypeIndexByFruitTypeIndex(index) |
893 | return self.fruitTypeIndexToWindrowFillTypeIndex[index] |
894 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
126 | function FruitTypeManager:initDataStructures() |
127 | self.fruitTypes = {} |
128 | self.indexToFruitType = {} |
129 | self.nameToIndex = {} |
130 | self.nameToFruitType = {} |
131 | self.fruitTypeIndexToFillType = {} |
132 | self.fillTypeIndexToFruitTypeIndex = {} |
133 | |
134 | self.fruitTypeConverters = {} |
135 | self.converterNameToIndex = {} |
136 | self.nameToConverter = {} |
137 | |
138 | self.windrowFillTypes = {} |
139 | self.fruitTypeIndexToWindrowFillTypeIndex = {} |
140 | |
141 | self.numCategories = 0 |
142 | self.categories = {} |
143 | self.indexToCategory = {} |
144 | self.categoryToFruitTypes = {} |
145 | |
146 | FruitType = self.nameToIndex |
147 | FruitType.UNKNOWN = 0 |
148 | FruitTypeCategory = self.categories |
149 | FruitTypeConverter = self.converterNameToIndex |
150 | end |
isFillTypeWindrow
DescriptionDefinitionisFillTypeWindrow()Code
883 | function FruitTypeManager:isFillTypeWindrow(index) |
884 | if index ~= nil then |
885 | return self.windrowFillTypes[index] == true |
886 | end |
887 | return false |
888 | end |
loadDefaultTypes
DescriptionDefinitionloadDefaultTypes()Code
154 | function FruitTypeManager:loadDefaultTypes() |
155 | local xmlFile = loadXMLFile("fuitTypes", "data/maps/maps_fruitTypes.xml") |
156 | self:loadFruitTypes(xmlFile, nil, true) |
157 | delete(xmlFile) |
158 | end |
loadFruitTypeCropCare
DescriptionLoads fruitType cropcare dataDefinition
loadFruitTypeCropCare(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
561 | function FruitTypeManager:loadFruitTypeCropCare(fruitType, xmlFile, key) |
562 | if fruitType ~= nil then |
563 | fruitType.maxWeederState = getXMLInt(xmlFile, key..".cropCare#maxWeederState") or fruitType.maxWeederState or 2 |
564 | fruitType.maxWeederHoeState = getXMLInt(xmlFile, key..".cropCare#maxWeederHoeState") or fruitType.maxWeederHoeState or fruitType.maxWeederState |
565 | |
566 | return true |
567 | end |
568 | |
569 | return false |
570 | end |
loadFruitTypeCultivation
DescriptionLoads fruitType cultivation dataDefinition
loadFruitTypeCultivation(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
498 | function FruitTypeManager:loadFruitTypeCultivation(fruitType, xmlFile, key) |
499 | if fruitType ~= nil then |
500 | fruitType.needsSeeding = Utils.getNoNil(getXMLBool(xmlFile, key..".cultivation#needsSeeding"), Utils.getNoNil(fruitType.needsSeeding, true)) |
501 | fruitType.allowsSeeding = Utils.getNoNil(getXMLBool(xmlFile, key..".cultivation#allowsSeeding"), Utils.getNoNil(fruitType.allowsSeeding, true)) |
502 | fruitType.directionSnapAngle = Utils.getNoNilRad(getXMLFloat(xmlFile, key..".cultivation#directionSnapAngle"), Utils.getNoNil(fruitType.directionSnapAngle, 0)) |
503 | fruitType.alignsToSun = Utils.getNoNil(getXMLBool(xmlFile, key..".cultivation#alignsToSun"), Utils.getNoNil(fruitType.alignsToSun, false)) |
504 | fruitType.seedUsagePerSqm = Utils.getNoNil(getXMLFloat(xmlFile, key..".cultivation#seedUsagePerSqm"), Utils.getNoNil(fruitType.seedUsagePerSqm, 0.1)) |
505 | fruitType.plantsWeed = Utils.getNoNil(getXMLBool(xmlFile, key..".cultivation#plantsWeed"), Utils.getNoNil(fruitType.plantsWeed, true)) |
506 | fruitType.needsRolling = Utils.getNoNil(getXMLBool(xmlFile, key..".cultivation#needsRolling"), Utils.getNoNil(fruitType.needsRolling, true)) |
507 | |
508 | local cultivationStates |
509 | local i = 0 |
510 | while true do |
511 | local cultivationKey = string.format("%s.cultivation.state(%d)", key, i) |
512 | if not hasXMLProperty(xmlFile, cultivationKey) then |
513 | break |
514 | end |
515 | |
516 | local state = getXMLInt(xmlFile, cultivationKey .. "#state") |
517 | |
518 | if state ~= nil then |
519 | if cultivationStates == nil then |
520 | cultivationStates = {} |
521 | end |
522 | |
523 | table.insert(cultivationStates, state) |
524 | end |
525 | |
526 | i = i + 1 |
527 | end |
528 | |
529 | fruitType.cultivationStates = cultivationStates |
530 | |
531 | |
532 | return true |
533 | end |
534 | |
535 | return false |
536 | end |
loadFruitTypeDestruction
DescriptionLoad fruit type map overlay color data.Definition
loadFruitTypeDestruction(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
614 | function FruitTypeManager:loadFruitTypeDestruction(fruitType, xmlFile, key) |
615 | if fruitType ~= nil then |
616 | fruitType.destruction = fruitType.destruction or {} |
617 | if hasXMLProperty(xmlFile, key..".destruction") then |
618 | local destruction = fruitType.destruction |
619 | |
620 | destruction.onlyOnField = Utils.getNoNil(getXMLBool(xmlFile, key..".destruction#onlyOnField"), Utils.getNoNil(destruction.onlyOnField, true)) |
621 | destruction.filterStart = getXMLInt(xmlFile, key..".destruction#filterStart", destruction.filterStart) |
622 | destruction.filterEnd = getXMLInt(xmlFile, key..".destruction#filterEnd", destruction.filterEnd) |
623 | destruction.state = getXMLInt(xmlFile, key..".destruction#state") or destruction.state or fruitType.cutState |
624 | |
625 | destruction.canBeDestroyed = Utils.getNoNil(getXMLBool(xmlFile, key..".destruction#canBeDestroyed"), Utils.getNoNil(destruction.canBeDestroyed, true)) |
626 | end |
627 | |
628 | fruitType.mulcher = fruitType.mulcher or {} |
629 | fruitType.mulcher.state = Utils.getNoNil(getXMLInt(xmlFile, key..".mulcher#state"), fruitType.mulcher.state or (2^fruitType.numStateChannels-1)) |
630 | |
631 | fruitType.mulcher.hasChopperGroundLayer = Utils.getNoNil(getXMLBool(xmlFile, key..".mulcher#hasChopperGroundLayer"), Utils.getNoNil(fruitType.mulcher.hasChopperGroundLayer, true)) |
632 | local chopperTypeName = getXMLString(xmlFile, key..".harvest#chopperTypeName") or "CHOPPER_STRAW" |
633 | if chopperTypeName ~= nil then |
634 | fruitType.mulcher.chopperTypeIndex = g_currentMission.fieldGroundSystem:getChopperTypeIndexByName(chopperTypeName) |
635 | end |
636 | |
637 | local defaultColorString = getXMLString(xmlFile, key .. ".mapColors#default") or "1 1 1 1" -- default white |
638 | local defaultColorBlindString = getXMLString(xmlFile, key .. ".mapColors#colorBlind") or "1 1 1 1" |
639 | |
640 | fruitType.defaultMapColor = GuiUtils.getColorArray(defaultColorString) or fruitType.defaultMapColor |
641 | fruitType.colorBlindMapColor = GuiUtils.getColorArray(defaultColorBlindString) or fruitType.colorBlindMapColor |
642 | |
643 | return true |
644 | end |
645 | |
646 | return false |
647 | end |
loadFruitTypeGrowth
DescriptionLoads fruitType growth dataDefinition
loadFruitTypeGrowth(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
380 | function FruitTypeManager:loadFruitTypeGrowth(fruitType, xmlFile, key) |
381 | if fruitType ~= nil then |
382 | fruitType.isGrowing = Utils.getNoNil(getXMLBool(xmlFile, key..".growth#isGrowing"), Utils.getNoNil(fruitType.isGrowing, true)) |
383 | if fruitType.isGrowing then |
384 | fruitType.numGrowthStates = Utils.getNoNil(getXMLInt(xmlFile, key..".growth#numGrowthStates"), Utils.getNoNil(fruitType.numGrowthStates, 0)) |
385 | -- fruitType.growthStateTime = Utils.getNoNil(getXMLInt(xmlFile, key..".growth#growthStateTime"), Utils.getNoNil(fruitType.growthStateTime, 0)) |
386 | fruitType.resetsSpray = Utils.getNoNil(getXMLBool(xmlFile, key..".growth#resetsSpray"), Utils.getNoNil(fruitType.resetsSpray, true)) |
387 | fruitType.growthRequiresLime = Utils.getNoNil(getXMLInt(xmlFile, key..".growth#requiresLime"), Utils.getNoNil(fruitType.growthRequiresLime, true)) |
388 | |
389 | fruitType.witheredState = getXMLInt(xmlFile, key..".growth#witheredState") or fruitType.witheredState |
390 | |
391 | fruitType.groundTypeChangeGrowthState = Utils.getNoNil(getXMLInt(xmlFile, key..".growthGroundTypeChange#state"), Utils.getNoNil(fruitType.groundTypeChangeGrowthState, -1)) |
392 | local groundTypeStr = getXMLString(xmlFile, key..".growthGroundTypeChange#groundType") |
393 | if groundTypeStr ~= nil then |
394 | local groundType = FieldGroundType.getByName(groundTypeStr) |
395 | if groundType == nil then |
396 | Logging.warning("Invalid groundTypeChanged name '%s'. Ignoring growth data!", groundTypeStr) |
397 | return false |
398 | end |
399 | fruitType.groundTypeChangeType = groundType |
400 | end |
401 | |
402 | fruitType.groundTypeChangeMaskTypes = {} |
403 | local groundTypeChangeMaskString = getXMLString(xmlFile, key..".growthGroundTypeChange#groundTypeMask") |
404 | if groundTypeChangeMaskString ~= nil then |
405 | local groundTypeChangeMaskList = groundTypeChangeMaskString:split(" ") |
406 | for _, v in ipairs(groundTypeChangeMaskList) do |
407 | local groundType = FieldGroundType.getByName(v) |
408 | if groundType ~= nil then |
409 | table.insert(fruitType.groundTypeChangeMaskTypes, groundType) |
410 | else |
411 | Logging.warning("Invalid groundTypeChangeMask name '%s'. Ignoring growth data!", v) |
412 | return false |
413 | end |
414 | end |
415 | end |
416 | |
417 | fruitType.regrows = Utils.getNoNil(getXMLBool(xmlFile, key .. ".growth#regrows"), Utils.getNoNil(fruitType.regrows, false)) |
418 | if fruitType.regrows then |
419 | fruitType.firstRegrowthState = Utils.getNoNil(getXMLInt(xmlFile, key .. ".growth#firstRegrowthState"), Utils.getNoNil(fruitType.firstRegrowthState, 1)) |
420 | end |
421 | end |
422 | |
423 | return true |
424 | end |
425 | |
426 | return false |
427 | end |
loadFruitTypeHarvest
DescriptionLoads fruitType harvest dataDefinition
loadFruitTypeHarvest(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
434 | function FruitTypeManager:loadFruitTypeHarvest(fruitType, xmlFile, key) |
435 | if fruitType ~= nil then |
436 | fruitType.minHarvestingGrowthState = Utils.getNoNil(getXMLInt(xmlFile, key..".harvest#minHarvestingGrowthState"), Utils.getNoNil(fruitType.minHarvestingGrowthState, 0)) |
437 | fruitType.maxHarvestingGrowthState = Utils.getNoNil(getXMLInt(xmlFile, key..".harvest#maxHarvestingGrowthState"), Utils.getNoNil(fruitType.maxHarvestingGrowthState, 0)) |
438 | fruitType.minForageGrowthState = Utils.getNoNil(getXMLInt(xmlFile, key..".harvest#minForageGrowthState"), Utils.getNoNil(fruitType.minForageGrowthState, fruitType.minHarvestingGrowthState)) |
439 | fruitType.cutState = Utils.getNoNil(getXMLInt(xmlFile, key..".harvest#cutState"), Utils.getNoNil(fruitType.cutState, 0)) |
440 | fruitType.allowsPartialGrowthState = Utils.getNoNil(getXMLBool(xmlFile, key..".harvest#allowsPartialGrowthState"), Utils.getNoNil(fruitType.allowsPartialGrowthState, false)) |
441 | fruitType.literPerSqm = Utils.getNoNil(getXMLFloat(xmlFile, key..".harvest#literPerSqm"), Utils.getNoNil(fruitType.literPerSqm, 0)) |
442 | fruitType.cutHeight = Utils.getNoNil(getXMLFloat(xmlFile, key..".harvest#cutHeight"), fruitType.cutHeight) |
443 | fruitType.forageCutHeight = Utils.getNoNil(getXMLFloat(xmlFile, key..".harvest#forageCutHeight"), fruitType.forageCutHeight or fruitType.cutHeight) |
444 | fruitType.beeYieldBonusPercentage = getXMLFloat(xmlFile, key..".harvest#beeYieldBonusPercentage") or 0 |
445 | local harvestGroundTypeChange = getXMLString(xmlFile, key..".harvestGroundTypeChange#groundType") |
446 | if harvestGroundTypeChange ~= nil then |
447 | local groundType = FieldGroundType.getByName(harvestGroundTypeChange) |
448 | if groundType ~= nil then |
449 | fruitType.harvestGroundTypeChange = groundType |
450 | end |
451 | end |
452 | |
453 | local chopperTypeName = getXMLString(xmlFile, key..".harvest#chopperTypeName") or nil |
454 | if chopperTypeName ~= nil then |
455 | fruitType.chopperTypeIndex = g_currentMission.fieldGroundSystem:getChopperTypeIndexByName(chopperTypeName) |
456 | if fruitType.chopperTypeIndex == nil then |
457 | Logging.warning("Invalid chopperTypeName name '%s' for '%s'.", chopperTypeName, key..".harvest") |
458 | end |
459 | end |
460 | |
461 | local transitions |
462 | local i = 0 |
463 | while true do |
464 | local transitionKey = string.format("%s.harvest.transition(%d)", key, i) |
465 | if not hasXMLProperty(xmlFile, transitionKey) then |
466 | break |
467 | end |
468 | |
469 | local srcState = getXMLInt(xmlFile, transitionKey .. "#srcState") |
470 | local targetState = getXMLInt(xmlFile, transitionKey .. "#targetState") |
471 | |
472 | if srcState ~= nil and targetState ~= nil then |
473 | if transitions == nil then |
474 | transitions = {} |
475 | end |
476 | |
477 | transitions[srcState] = targetState |
478 | end |
479 | |
480 | i = i + 1 |
481 | end |
482 | |
483 | fruitType.harvestTransitions = transitions |
484 | |
485 | fruitType.harvestWeedState = Utils.getNoNil(getXMLInt(xmlFile, key..".harvest#weedState"), Utils.getNoNil(fruitType.harvestWeedState, nil)) |
486 | |
487 | return true |
488 | end |
489 | |
490 | return false |
491 | end |
loadFruitTypeMapColors
DescriptionLoad fruit type map overlay color data.Definition
loadFruitTypeMapColors(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
595 | function FruitTypeManager:loadFruitTypeMapColors(fruitType, xmlFile, key) |
596 | if fruitType ~= nil then |
597 | local defaultColorString = getXMLString(xmlFile, key .. ".mapColors#default") or "1 1 1 1" -- default white |
598 | local defaultColorBlindString = getXMLString(xmlFile, key .. ".mapColors#colorBlind") or "1 1 1 1" |
599 | |
600 | fruitType.defaultMapColor = GuiUtils.getColorArray(defaultColorString) or fruitType.defaultMapColor |
601 | fruitType.colorBlindMapColor = GuiUtils.getColorArray(defaultColorBlindString) or fruitType.colorBlindMapColor |
602 | |
603 | return true |
604 | end |
605 | |
606 | return false |
607 | end |
loadFruitTypeOptions
DescriptionLoads fruitType option dataDefinition
loadFruitTypeOptions(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
577 | function FruitTypeManager:loadFruitTypeOptions(fruitType, xmlFile, key) |
578 | if fruitType ~= nil then |
579 | fruitType.increasesSoilDensity = Utils.getNoNil(getXMLBool(xmlFile, key..".options#increasesSoilDensity"), Utils.getNoNil(fruitType.increasesSoilDensity, false)) |
580 | fruitType.lowSoilDensityRequired = Utils.getNoNil(getXMLBool(xmlFile, key..".options#lowSoilDensityRequired"), Utils.getNoNil(fruitType.lowSoilDensityRequired, true)) |
581 | fruitType.consumesLime = Utils.getNoNil(getXMLBool(xmlFile, key..".options#consumesLime"), Utils.getNoNil(fruitType.consumesLime, true)) |
582 | fruitType.startSprayState = math.max(Utils.getNoNil(getXMLInt(xmlFile, key..".options#startSprayState"), Utils.getNoNil(fruitType.startSprayState, 0)), 0) |
583 | |
584 | return true |
585 | end |
586 | |
587 | return false |
588 | end |
loadFruitTypePreparing
DescriptionLoads fruitType preparing dataDefinition
loadFruitTypePreparing(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
543 | function FruitTypeManager:loadFruitTypePreparing(fruitType, xmlFile, key) |
544 | if fruitType ~= nil then |
545 | fruitType.preparingOutputName = Utils.getNoNil(getXMLString(xmlFile, key..".preparing#outputName"), fruitType.preparingOutputName) |
546 | fruitType.minPreparingGrowthState = Utils.getNoNil(getXMLInt(xmlFile, key..".preparing#minGrowthState"), Utils.getNoNil(fruitType.minPreparingGrowthState, -1)) |
547 | fruitType.maxPreparingGrowthState = Utils.getNoNil(getXMLInt(xmlFile, key..".preparing#maxGrowthState"), Utils.getNoNil(fruitType.maxPreparingGrowthState, -1)) |
548 | fruitType.preparedGrowthState = Utils.getNoNil(getXMLInt(xmlFile, key..".preparing#preparedGrowthState"), Utils.getNoNil(fruitType.preparedGrowthState, -1)) |
549 | |
550 | return true |
551 | end |
552 | |
553 | return false |
554 | end |
loadFruitTypes
DescriptionLoads fruitTypesDefinition
loadFruitTypes(table self, integer xmlFile)Arguments
table | self | target |
integer | xmlFile | xml file handle |
boolean | success | success |
175 | function FruitTypeManager:loadFruitTypes(xmlFile, missionInfo, isBaseType) |
176 | |
177 | local i = 0 |
178 | while true do |
179 | local key = string.format("map.fruitTypes.fruitType(%d)", i) |
180 | if not hasXMLProperty(xmlFile, key) then |
181 | break |
182 | end |
183 | |
184 | local name = getXMLString(xmlFile, key.."#name") |
185 | local shownOnMap = getXMLBool(xmlFile, key.."#shownOnMap") |
186 | local useForFieldJob = getXMLBool(xmlFile, key.."#useForFieldJob") |
187 | local missionMultiplier = getXMLFloat(xmlFile, key.."#missionMultiplier") |
188 | |
189 | local fruitType = self:addFruitType(name, shownOnMap, useForFieldJob, missionMultiplier, isBaseType) |
190 | if fruitType ~= nil then |
191 | local success = true |
192 | success = success and self:loadFruitTypeGeneral(fruitType, xmlFile, key) |
193 | success = success and self:loadFruitTypeWindrow(fruitType, xmlFile, key) |
194 | success = success and self:loadFruitTypeGrowth(fruitType, xmlFile, key) |
195 | success = success and self:loadFruitTypeHarvest(fruitType, xmlFile, key) |
196 | success = success and self:loadFruitTypeCultivation(fruitType, xmlFile, key) |
197 | success = success and self:loadFruitTypePreparing(fruitType, xmlFile, key) |
198 | success = success and self:loadFruitTypeCropCare(fruitType, xmlFile, key) |
199 | success = success and self:loadFruitTypeOptions(fruitType, xmlFile, key) |
200 | success = success and self:loadFruitTypeMapColors(fruitType, xmlFile, key) |
201 | success = success and self:loadFruitTypeDestruction(fruitType, xmlFile, key) |
202 | |
203 | if success and self.indexToFruitType[fruitType.index] == nil then |
204 | local maxNumFruitTypes = 2^FruitTypeManager.SEND_NUM_BITS-1 |
205 | if #self.fruitTypes >= maxNumFruitTypes then |
206 | Logging.error("FruitTypeManager.loadFruitTypes too many fruit types. Only %d fruit types are supported", maxNumFruitTypes) |
207 | return |
208 | end |
209 | |
210 | table.insert(self.fruitTypes, fruitType) |
211 | self.nameToFruitType[fruitType.name] = fruitType |
212 | self.nameToIndex[fruitType.name] = fruitType.index |
213 | self.indexToFruitType[fruitType.index] = fruitType |
214 | |
215 | self.fillTypeIndexToFruitTypeIndex[fruitType.fillType.index] = fruitType.index |
216 | self.fruitTypeIndexToFillType[fruitType.index] = fruitType.fillType |
217 | end |
218 | end |
219 | |
220 | i = i + 1 |
221 | end |
222 | |
223 | i = 0 |
224 | while true do |
225 | local key = string.format("map.fruitTypeCategories.fruitTypeCategory(%d)", i) |
226 | if not hasXMLProperty(xmlFile, key) then |
227 | break |
228 | end |
229 | |
230 | local name = getXMLString(xmlFile, key.."#name") |
231 | local fruitTypesStr = getXMLString(xmlFile, key) |
232 | |
233 | local fruitTypeCategoryIndex = self:addFruitTypeCategory(name, isBaseType) |
234 | if fruitTypeCategoryIndex ~= nil then |
235 | local fruitTypeNames = string.split(fruitTypesStr, " ") |
236 | for _, fruitTypeName in ipairs(fruitTypeNames) do |
237 | local fruitType = self:getFruitTypeByName(fruitTypeName) |
238 | if fruitType ~= nil then |
239 | if not self:addFruitTypeToCategory(fruitType.index, fruitTypeCategoryIndex) then |
240 | print("Warning: Could not add fruitType '"..tostring(fruitTypeName).."' to fruitTypeCategory '"..tostring(name).."'!") |
241 | end |
242 | else |
243 | print("Warning: FruitType '"..tostring(fruitTypeName).."' referenced in fruitTypeCategory '"..tostring(name).."' is not defined!") |
244 | end |
245 | end |
246 | end |
247 | |
248 | i = i + 1 |
249 | end |
250 | |
251 | i = 0 |
252 | while true do |
253 | local key = string.format("map.fruitTypeConverters.fruitTypeConverter(%d)", i) |
254 | if not hasXMLProperty(xmlFile, key) then |
255 | break |
256 | end |
257 | |
258 | local name = getXMLString(xmlFile, key.."#name") |
259 | local converter = self:addFruitTypeConverter(name, isBaseType) |
260 | if converter ~= nil then |
261 | local j = 0 |
262 | while true do |
263 | local converterKey = string.format("%s.converter(%d)", key, j) |
264 | if not hasXMLProperty(xmlFile, converterKey) then |
265 | break |
266 | end |
267 | |
268 | local from = getXMLString(xmlFile, converterKey.."#from") |
269 | local to = getXMLString(xmlFile, converterKey.."#to") |
270 | local factor = getXMLFloat(xmlFile, converterKey.."#factor") |
271 | local windrowFactor = getXMLFloat(xmlFile, converterKey.."#windrowFactor") |
272 | |
273 | local fruitType = self:getFruitTypeByName(from) |
274 | local fillType = g_fillTypeManager:getFillTypeByName(to) |
275 | |
276 | if fruitType ~= nil and fillType ~= nil and factor ~= nil then |
277 | self:addFruitTypeConversion(converter, fruitType.index, fillType.index, factor, windrowFactor) |
278 | end |
279 | |
280 | j = j + 1 |
281 | end |
282 | end |
283 | |
284 | i = i + 1 |
285 | end |
286 | |
287 | return true |
288 | end |
loadFruitTypeWindrow
DescriptionLoads fruitType windrow dataDefinition
loadFruitTypeWindrow(table fruitType, integer xmlFile, string key)Arguments
table | fruitType | fruit type object |
integer | xmlFile | xml file handle |
string | key | xml key |
348 | function FruitTypeManager:loadFruitTypeWindrow(fruitType, xmlFile, key) |
349 | if fruitType ~= nil then |
350 | local windrowName = getXMLString(xmlFile, key..".windrow#name") |
351 | local windrowLitersPerSqm = getXMLFloat(xmlFile, key..".windrow#litersPerSqm") |
352 | |
353 | if windrowName == nil or windrowLitersPerSqm == nil then |
354 | return true |
355 | end |
356 | |
357 | local windrowFillType = g_fillTypeManager:getFillTypeByName(windrowName) |
358 | if windrowFillType == nil then |
359 | print("Warning: Mission fillType '"..tostring(windrowName).."' for windrow definition. Ignoring windrow!") |
360 | return false |
361 | end |
362 | |
363 | fruitType.hasWindrow = true |
364 | fruitType.windrowName = windrowFillType.name |
365 | fruitType.windrowLiterPerSqm = windrowLitersPerSqm |
366 | |
367 | self.windrowFillTypes[windrowFillType.index] = true |
368 | self.fruitTypeIndexToWindrowFillTypeIndex[fruitType.index] = windrowFillType.index |
369 | self.fillTypeIndexToFruitTypeIndex[windrowFillType.index] = fruitType.index |
370 | end |
371 | |
372 | return true |
373 | end |
loadMapData
DescriptionLoad data on map loadDefinition
loadMapData()Return Values
boolean | true | if loading was successful else false |
163 | function FruitTypeManager:loadMapData(xmlFile, missionInfo, baseDirectory) |
164 | FruitTypeManager:superClass().loadMapData(self) |
165 | |
166 | self:loadDefaultTypes() |
167 | return XMLUtil.loadDataFromMapXML(xmlFile, "fruitTypes", baseDirectory, self, self.loadFruitTypes, missionInfo) |
168 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
119 | function FruitTypeManager.new(customMt) |
120 | local self = AbstractManager.new(customMt or FruitTypeManager_mt) |
121 | return self |
122 | end |