Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- AIConveyorBelt
- AIDrivable
- AIFieldWorker
- AIImplement
- AIJobVehicle
- AIVehicle
- AIVehicleObstacle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- AutoLoader
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BigBag
- BunkerSiloCompacter
- BunkerSiloInteractor
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- CropSensor
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- ExtendedAIVehicle
- ExtendedCombine
- ExtendedMotorized
- ExtendedMower
- ExtendedSowingMachine
- ExtendedSprayer
- ExtendedWearable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- HeadlandAnimation
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- InlineWrapper
- JigglingParts
- Leveler
- LicensePlates
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- ManureSensor
- MixerWagon
- Motorized
- Mountable
- Mower
- Mulcher
- MultipleItemPurchase
- Pallet
- Pickup
- Pipe
- PlaceableAI
- PlaceableAnimatedObjects
- PlaceableBeehive
- PlaceableBeehivePalletSpa...
- PlaceableBunkerSilo
- PlaceableBuyingStation
- PlaceableCartridgePlayer
- PlaceableChargingStation
- PlaceableClearAreas
- PlaceableColorable
- PlaceableDeletedNodes
- PlaceableDoghouse
- PlaceableDynamicallyLoade...
- PlaceableFarmhouse
- PlaceableFence
- PlaceableFoliageAreas
- PlaceableGreenhouse
- PlaceableHighPressureWash...
- PlaceableHotspots
- PlaceableHusbandry
- PlaceableHusbandryAnimals
- PlaceableHusbandryFeeding...
- PlaceableHusbandryFence
- PlaceableHusbandryFood
- PlaceableHusbandryLiquidM...
- PlaceableHusbandryMilk
- PlaceableHusbandryPallets
- PlaceableHusbandryStraw
- PlaceableHusbandryWater
- PlaceableIncomePerHour
- PlaceableIndoorAreas
- PlaceableInfoTrigger
- PlaceableLeveling
- PlaceableLights
- PlaceableManureHeap
- PlaceablePlacement
- PlaceableProductionPoint
- PlaceableSellingStation
- PlaceableSilo
- PlaceableSiloExtension
- PlaceableSolarPanels
- PlaceableTipOcclusionArea...
- PlaceableTrainSystem
- PlaceableTriggerMarkers
- PlaceableVine
- PlaceableWardrobe
- PlaceableWeatherStation
- PlaceableWeighingStation
- PlaceableWindTurbine
- PlaceableWorkshop
- Plow
- PlowPacker
- PowerConsumer
- PowerTakeOffs
- PrecisionFarmingStatistic
- PushHandTool
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- RTKStation
- SaltSpreader
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SoilSampler
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StonePicker
- StrawBlower
- StumpCutter
- SupportVehicle
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TestAreas
- TipOccluder
- Trailer
- TreePlanter
- TreeSaplingPallet
- TreeSaw
- TurnOnVehicle
- VariableWorkWidth
- VehicleSettings
- VineCutter
- VineDetector
- VinePrepruner
- Washable
- WaterTrailer
- Wearable
- Weeder
- WeedSpotSpray
- Wheels
- WindBending
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- 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
MultipleItemPurchase
DescriptionClass for a root vehicle that loads bales or vehicles and is removed afterwardsFunctions
- addToPhysics
- getFillUnitCapacity
- getTotalMass
- initSpecialization
- loadItemAtPosition
- onDelete
- onFinishLoadingVehicle
- onLoad
- onPreLoadFinished
- onUpdate
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- removeFromPhysics
- setVisibility
addToPhysics
DescriptionDefinitionaddToPhysics()Code
288 | function MultipleItemPurchase:addToPhysics(superFunc) |
289 | end |
getFillUnitCapacity
DescriptionDefinitiongetFillUnitCapacity()Code
255 | function MultipleItemPurchase:getFillUnitCapacity(superFunc, fillUnitIndex) |
256 | if self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
257 | local fillLevel = 0 |
258 | local spec = self.spec_multipleItemPurchase |
259 | for _, bale in ipairs(spec.loadedBales) do |
260 | fillLevel = fillLevel + bale:getFillLevel() |
261 | end |
262 | |
263 | for _, vehicle in ipairs(spec.loadedVehicles) do |
264 | if vehicle.getFillUnitCapacity ~= nil then |
265 | fillLevel = fillLevel + vehicle:getFillUnitCapacity(1) |
266 | end |
267 | end |
268 | |
269 | return fillLevel |
270 | end |
271 | |
272 | return 0 |
273 | end |
getTotalMass
DescriptionDefinitiongetTotalMass()Code
235 | function MultipleItemPurchase:getTotalMass(superFunc, onlyGivenVehicle) |
236 | if self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
237 | local mass = 0 |
238 | local spec = self.spec_multipleItemPurchase |
239 | for _, bale in ipairs(spec.loadedBales) do |
240 | mass = mass + bale:getMass() |
241 | end |
242 | |
243 | for _, vehicle in ipairs(spec.loadedVehicles) do |
244 | mass = mass + vehicle:getTotalMass() |
245 | end |
246 | |
247 | return mass |
248 | end |
249 | |
250 | return 0 |
251 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
15 | function MultipleItemPurchase.initSpecialization() |
16 | g_configurationManager:addConfigurationType("multipleItemPurchaseAmount", g_i18n:getText("configuration_buyableBaleAmount"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION) |
17 | |
18 | local schema = Vehicle.xmlSchema |
19 | schema:setXMLSpecializationType("MultipleItemPurchase") |
20 | |
21 | schema:register(XMLValueType.STRING, "vehicle.multipleItemPurchase#filename", "Item filename") |
22 | schema:register(XMLValueType.BOOL, "vehicle.multipleItemPurchase#isVehicle", "Is Loading a vehicle (false=Bale)", false) |
23 | schema:register(XMLValueType.STRING, "vehicle.multipleItemPurchase#fillType", "Bale fill type", "STRAW") |
24 | schema:register(XMLValueType.BOOL, "vehicle.multipleItemPurchase#baleIsWrapped", "Bale is wrapped", false) |
25 | |
26 | schema:register(XMLValueType.VECTOR_TRANS, "vehicle.multipleItemPurchase.offsets.offset(?)#offset", "Offset") |
27 | schema:register(XMLValueType.FLOAT, "vehicle.multipleItemPurchase.offsets.offset(?)#amount", "Amount of items to activate offset") |
28 | |
29 | schema:register(XMLValueType.VECTOR_TRANS, "vehicle.multipleItemPurchase.itemPositions.itemPosition(?)#position", "Bale position") |
30 | schema:register(XMLValueType.VECTOR_ROT, "vehicle.multipleItemPurchase.itemPositions.itemPosition(?)#rotation", "Bale rotation") |
31 | |
32 | schema:setXMLSpecializationType(XMLManager.XML_SPECIALIZATION_NONE) |
33 | end |
loadItemAtPosition
DescriptionDefinitionloadItemAtPosition()Code
143 | function MultipleItemPurchase:loadItemAtPosition(position) |
144 | local spec = self.spec_multipleItemPurchase |
145 | |
146 | if self.isServer or self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
147 | local x, y, z = localToWorld(self.components[1].node, unpack(position.position)) |
148 | local rx, ry, rz = localRotationToWorld(self.components[1].node, unpack(position.rotation)) |
149 | |
150 | if not spec.isVehicle then |
151 | local baleObject = Bale.new(self.isServer, self.isClient) |
152 | if baleObject:loadFromConfigXML(spec.itemFilename, x, y, z, rx, ry, rz) then |
153 | baleObject:setFillType(spec.baleFillTypeIndex, true) |
154 | baleObject:setOwnerFarmId(self:getActiveFarm(), true) |
155 | if self.propertyState ~= Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
156 | baleObject:register() |
157 | end |
158 | |
159 | if spec.baleIsWrapped then |
160 | baleObject:setWrappingState(1) |
161 | |
162 | if self.configurations["baseColor"] ~= nil then |
163 | local color = ConfigurationUtil.getColorByConfigId(self, "baseColor", self.configurations["baseColor"]) |
164 | baleObject:setColor(unpack(color)) |
165 | end |
166 | end |
167 | |
168 | setPairCollision(self.components[1].node, baleObject.nodeId, false) |
169 | |
170 | table.insert(spec.loadedBales, baleObject) |
171 | end |
172 | else |
173 | local location = { |
174 | x = x, |
175 | y = y, |
176 | z = z, |
177 | xRot = rx, |
178 | yRot = ry, |
179 | zRot = rz |
180 | } |
181 | |
182 | self.subLoadingTasksFinished = false |
183 | self.numPendingSubLoadingTasks = self.numPendingSubLoadingTasks + 1 |
184 | |
185 | local registerVehicle = self.propertyState ~= Vehicle.PROPERTY_STATE_SHOP_CONFIG |
186 | local forceServer = self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG |
187 | VehicleLoadingUtil.loadVehicle(spec.itemFilename, location, true, 0, self.propertyState, self:getActiveFarm(), nil, nil, self.onFinishLoadingVehicle, self, nil, registerVehicle, forceServer) |
188 | end |
189 | end |
190 | end |
onDelete
DescriptionDefinitiononDelete()Code
210 | function MultipleItemPurchase:onDelete() |
211 | if self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG or g_iconGenerator ~= nil or g_currentMission.debugVehiclesToBeLoaded ~= nil then |
212 | local spec = self.spec_multipleItemPurchase |
213 | if spec.loadedBales ~= nil then |
214 | for _, bale in ipairs(spec.loadedBales) do |
215 | bale:delete() |
216 | end |
217 | |
218 | for _, vehicle in ipairs(spec.loadedVehicles) do |
219 | vehicle:delete() |
220 | end |
221 | end |
222 | end |
223 | end |
onFinishLoadingVehicle
DescriptionDefinitiononFinishLoadingVehicle()Code
194 | function MultipleItemPurchase:onFinishLoadingVehicle(vehicle, vehicleLoadState) |
195 | local spec = self.spec_multipleItemPurchase |
196 | if vehicleLoadState == VehicleLoadingUtil.VEHICLE_LOAD_OK then |
197 | table.insert(spec.loadedVehicles, vehicle) |
198 | end |
199 | |
200 | self.numPendingSubLoadingTasks = self.numPendingSubLoadingTasks - 1 |
201 | self.subLoadingTasksFinished = self.numPendingSubLoadingTasks == 0 |
202 | if not self.isDeleted and not self.isDeleting then |
203 | if self.syncVehicleLoadingFinished then |
204 | self:tryFinishLoading() |
205 | end |
206 | end |
207 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
70 | function MultipleItemPurchase:onLoad(savegame) |
71 | local spec = self.spec_multipleItemPurchase |
72 | |
73 | spec.loadedBales = {} |
74 | spec.loadedVehicles = {} |
75 | |
76 | spec.itemFilename = Utils.getFilename(self.xmlFile:getValue("vehicle.multipleItemPurchase#filename"), self.baseDirectory) |
77 | spec.isVehicle = self.xmlFile:getValue("vehicle.multipleItemPurchase#isVehicle", false) |
78 | |
79 | local fillTypeName = self.xmlFile:getValue("vehicle.multipleItemPurchase#fillType", "STRAW") |
80 | spec.baleFillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeName) |
81 | spec.baleIsWrapped = self.xmlFile:getValue("vehicle.multipleItemPurchase#baleIsWrapped", false) |
82 | |
83 | local positionOffset = {0, 0, 0} |
84 | local i = 0 |
85 | while true do |
86 | local baseKey = string.format("vehicle.multipleItemPurchase.offsets.offset(%d)", i) |
87 | if not self.xmlFile:hasProperty(baseKey) then |
88 | break |
89 | end |
90 | |
91 | local offset = self.xmlFile:getValue(baseKey.."#offset", nil, true) |
92 | local amount = self.xmlFile:getValue(baseKey.."#amount") |
93 | |
94 | if amount <= self.configurations["multipleItemPurchaseAmount"] then |
95 | positionOffset = offset |
96 | end |
97 | |
98 | i = i + 1 |
99 | end |
100 | |
101 | spec.positions = {} |
102 | i = 0 |
103 | while true do |
104 | local baseKey = string.format("vehicle.multipleItemPurchase.itemPositions.itemPosition(%d)", i) |
105 | if not self.xmlFile:hasProperty(baseKey) then |
106 | break |
107 | end |
108 | |
109 | local position = self.xmlFile:getValue(baseKey.."#position", nil, true) |
110 | local rotation = self.xmlFile:getValue(baseKey.."#rotation", nil, true) |
111 | if position ~= nil and rotation ~= nil then |
112 | if positionOffset ~= nil then |
113 | for j=1, 3 do |
114 | position[j] = position[j] + positionOffset[j] |
115 | end |
116 | end |
117 | |
118 | table.insert(spec.positions, {position=position, rotation=rotation}) |
119 | end |
120 | |
121 | i = i + 1 |
122 | end |
123 | |
124 | if not self.isServer then |
125 | SpecializationUtil.removeEventListener(self, "onUpdate", MultipleItemPurchase) |
126 | end |
127 | end |
onPreLoadFinished
DescriptionCalled after loadingDefinition
onPreLoadFinished(table savegame)Arguments
table | savegame | savegame |
132 | function MultipleItemPurchase:onPreLoadFinished(savegame) |
133 | local spec = self.spec_multipleItemPurchase |
134 | for j, position in ipairs(spec.positions) do |
135 | if j <= self.configurations["multipleItemPurchaseAmount"] then |
136 | self:loadItemAtPosition(position) |
137 | end |
138 | end |
139 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
227 | function MultipleItemPurchase:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
228 | if self.propertyState ~= Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
229 | g_currentMission:removeVehicle(self) |
230 | end |
231 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
37 | function MultipleItemPurchase.prerequisitesPresent(specializations) |
38 | return SpecializationUtil.hasSpecialization(FillUnit, specializations) |
39 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
60 | function MultipleItemPurchase.registerEventListeners(vehicleType) |
61 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", MultipleItemPurchase) |
62 | SpecializationUtil.registerEventListener(vehicleType, "onPreLoadFinished", MultipleItemPurchase) |
63 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", MultipleItemPurchase) |
64 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", MultipleItemPurchase) |
65 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
43 | function MultipleItemPurchase.registerFunctions(vehicleType) |
44 | SpecializationUtil.registerFunction(vehicleType, "loadItemAtPosition", MultipleItemPurchase.loadItemAtPosition) |
45 | SpecializationUtil.registerFunction(vehicleType, "onFinishLoadingVehicle", MultipleItemPurchase.onFinishLoadingVehicle) |
46 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
50 | function MultipleItemPurchase.registerOverwrittenFunctions(vehicleType) |
51 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getTotalMass", MultipleItemPurchase.getTotalMass) |
52 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getFillUnitCapacity", MultipleItemPurchase.getFillUnitCapacity) |
53 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "setVisibility", MultipleItemPurchase.setVisibility) |
54 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "addToPhysics", MultipleItemPurchase.addToPhysics) |
55 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "removeFromPhysics", MultipleItemPurchase.removeFromPhysics) |
56 | end |
removeFromPhysics
DescriptionDefinitionremoveFromPhysics()Code
293 | function MultipleItemPurchase:removeFromPhysics(superFunc) |
294 | local spec = self.spec_multipleItemPurchase |
295 | for _, bale in ipairs(spec.loadedBales) do |
296 | bale:removeFromPhysics() |
297 | end |
298 | for _, vehicle in ipairs(spec.loadedVehicles) do |
299 | vehicle:removeFromPhysics() |
300 | end |
301 | |
302 | superFunc(self) |
303 | end |
setVisibility
DescriptionDefinitionsetVisibility()Code
277 | function MultipleItemPurchase:setVisibility(superFunc, state) |
278 | local spec = self.spec_multipleItemPurchase |
279 | for _, vehicle in ipairs(spec.loadedVehicles) do |
280 | vehicle:setVisibility(state) |
281 | end |
282 | |
283 | superFunc(self, state) |
284 | end |