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
AIConveyorBelt
DescriptionSpecialization for extending conveyor belts with AI functionalityFunctions
- actionEventChangeAngle
- getAINeedsTrafficCollisionBox
- getCanBeSelected
- getCanStartAIVehicle
- getCanStartFieldWork
- getDirectionAndSpeedToTargetAngle
- getHasStartableAIJob
- getStartableAIJob
- initSpecialization
- onAIFieldWorkerStart
- onLoad
- onPostLoad
- onReadStream
- onRegisterActionEvents
- onUpdate
- onUpdateTick
- onWriteStream
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- saveToXMLFile
- setAIConveyorBeltAngle
actionEventChangeAngle
DescriptionDefinitionactionEventChangeAngle()Code
287 | function AIConveyorBelt.actionEventChangeAngle(self, actionName, inputValue, callbackState, isAnalog) |
288 | local spec = self.spec_aiConveyorBelt |
289 | local newAngle = spec.currentAngle + spec.stepSize |
290 | if newAngle > spec.maxAngle then |
291 | newAngle = spec.minAngle |
292 | end |
293 | |
294 | self:setAIConveyorBeltAngle(newAngle) |
295 | end |
getAINeedsTrafficCollisionBox
DescriptionDefinitiongetAINeedsTrafficCollisionBox()Code
254 | function AIConveyorBelt:getAINeedsTrafficCollisionBox(superFunc) |
255 | return false |
256 | end |
getCanBeSelected
DescriptionDefinitiongetCanBeSelected()Code
248 | function AIConveyorBelt:getCanBeSelected(superFunc) |
249 | return true |
250 | end |
getCanStartAIVehicle
DescriptionDefinitiongetCanStartAIVehicle()Code
208 | function AIConveyorBelt:getCanStartAIVehicle(superFunc) |
209 | if not superFunc(self) then |
210 | return false |
211 | end |
212 | |
213 | return self.spec_aiConveyorBelt.isAllowed |
214 | end |
getCanStartFieldWork
DescriptionDefinitiongetCanStartFieldWork()Code
218 | function AIConveyorBelt:getCanStartFieldWork() |
219 | return self:getCanStartAIVehicle() |
220 | end |
getDirectionAndSpeedToTargetAngle
DescriptionDefinitiongetDirectionAndSpeedToTargetAngle()Code
182 | function AIConveyorBelt:getDirectionAndSpeedToTargetAngle(direction, minAngle, maxAngle) |
183 | local dx, _, dz = localDirectionToWorld(self.components[1].node, 0, 0, 1) |
184 | local yRot = MathUtil.getYRotationFromDirection(dx, dz) |
185 | |
186 | local angleDifference |
187 | if direction > 0 then |
188 | if yRot > maxAngle then |
189 | return -1, 0 |
190 | end |
191 | angleDifference = maxAngle - yRot |
192 | elseif direction < 0 then |
193 | if yRot < minAngle then |
194 | return 1, 0 |
195 | end |
196 | angleDifference = yRot - minAngle |
197 | else |
198 | angleDifference = 0 |
199 | end |
200 | |
201 | local speed = MathUtil.clamp(math.deg(angleDifference) / 2.5, 0.1, 1) * direction |
202 | |
203 | return direction, speed |
204 | end |
getHasStartableAIJob
DescriptionDefinitiongetHasStartableAIJob()Code
242 | function AIConveyorBelt:getHasStartableAIJob(superFunc) |
243 | return true |
244 | end |
getStartableAIJob
DescriptionDefinitiongetStartableAIJob()Code
224 | function AIConveyorBelt:getStartableAIJob(superFunc) |
225 | |
226 | if self:getCanStartFieldWork() then |
227 | local spec = self.spec_aiConveyorBelt |
228 | local conveyorJob = spec.conveyorJob |
229 | conveyorJob:applyCurrentState(self, g_currentMission, g_currentMission.player.farmId, false) |
230 | conveyorJob:setValues() |
231 | local success = conveyorJob:validate(false) |
232 | if success then |
233 | return conveyorJob |
234 | end |
235 | end |
236 | |
237 | return nil |
238 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
25 | function AIConveyorBelt.initSpecialization() |
26 | local schema = Vehicle.xmlSchema |
27 | schema:setXMLSpecializationType("AIConveyorBelt") |
28 | |
29 | schema:register(XMLValueType.FLOAT, "vehicle.ai.conveyorBelt#minAngle", "Min angle", 5) |
30 | schema:register(XMLValueType.FLOAT, "vehicle.ai.conveyorBelt#maxAngle", "Max angle", 45) |
31 | schema:register(XMLValueType.FLOAT, "vehicle.ai.conveyorBelt#stepSize", "Step size", 5) |
32 | schema:register(XMLValueType.FLOAT, "vehicle.ai.conveyorBelt#speed", "Speed", 1) |
33 | schema:register(XMLValueType.INT, "vehicle.ai.conveyorBelt#direction", "Direction", -1) |
34 | |
35 | schema:setXMLSpecializationType() |
36 | |
37 | local schemaSavegame = Vehicle.xmlSchemaSavegame |
38 | schemaSavegame:register(XMLValueType.FLOAT, "vehicles.vehicle(?).aiConveyorBelt#currentAngle", "Current angle", 45) |
39 | end |
onAIFieldWorkerStart
DescriptionDefinitiononAIFieldWorkerStart()Code
260 | function AIConveyorBelt:onAIFieldWorkerStart() |
261 | local spec = self.spec_aiConveyorBelt |
262 | |
263 | local dx, _, dz = localDirectionToWorld(self.components[1].node, 0, 0, 1) |
264 | local yRot = MathUtil.getYRotationFromDirection(dx, dz) |
265 | |
266 | spec.minTargetWorldYRot = yRot - math.rad(spec.currentAngle) / 2 |
267 | spec.maxTargetWorldYRot = yRot + math.rad(spec.currentAngle) / 2 |
268 | spec.currentDirection = 1 |
269 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
75 | function AIConveyorBelt:onLoad(savegame) |
76 | local spec = self.spec_aiConveyorBelt |
77 | |
78 | spec.isAllowed = self.xmlFile:hasProperty("vehicle.ai.conveyorBelt") |
79 | |
80 | spec.minAngle = self.xmlFile:getValue("vehicle.ai.conveyorBelt#minAngle", 5) |
81 | spec.maxAngle = self.xmlFile:getValue("vehicle.ai.conveyorBelt#maxAngle", 45) |
82 | spec.stepSize = self.xmlFile:getValue("vehicle.ai.conveyorBelt#stepSize", 5) |
83 | spec.currentAngle = spec.maxAngle |
84 | |
85 | spec.minTargetWorldYRot = 0 |
86 | spec.maxTargetWorldYRot = 0 |
87 | spec.currentDirection = 0 |
88 | spec.currentSpeed = 0 |
89 | |
90 | spec.conveyorJob = g_currentMission.aiJobTypeManager:createJob(AIJobType.CONVEYOR) |
91 | |
92 | spec.speed = self.xmlFile:getValue("vehicle.ai.conveyorBelt#speed", 1) |
93 | spec.direction = self.xmlFile:getValue("vehicle.ai.conveyorBelt#direction", -1) |
94 | |
95 | if not self.isServer then |
96 | SpecializationUtil.removeEventListener(self, "onUpdate", AIConveyorBelt) |
97 | end |
98 | if not self.isClient then |
99 | SpecializationUtil.removeEventListener(self, "onUpdateTick", AIConveyorBelt) |
100 | end |
101 | end |
onPostLoad
DescriptionDefinitiononPostLoad()Code
105 | function AIConveyorBelt:onPostLoad(savegame) |
106 | local spec = self.spec_aiConveyorBelt |
107 | if savegame ~= nil and not savegame.resetVehicles then |
108 | spec.currentAngle = savegame.xmlFile:getValue(savegame.key..".aiConveyorBelt#currentAngle", spec.currentAngle) |
109 | end |
110 | end |
onReadStream
DescriptionCalled on client side on joinDefinition
onReadStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
123 | function AIConveyorBelt:onReadStream(streamId, connection) |
124 | self:setAIConveyorBeltAngle(streamReadInt8(streamId), true) |
125 | end |
onRegisterActionEvents
DescriptionDefinitiononRegisterActionEvents()Code
273 | function AIConveyorBelt:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
274 | if self.isClient then |
275 | local spec = self.spec_aiConveyorBelt |
276 | self:clearActionEventsTable(spec.actionEvents) |
277 | |
278 | if isActiveForInputIgnoreSelection and spec.isAllowed then |
279 | local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA3, self, AIConveyorBelt.actionEventChangeAngle, false, true, false, true, nil) |
280 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL) |
281 | end |
282 | end |
283 | end |
onUpdate
DescriptionCalled on updateDefinition
onUpdate(float dt, boolean isActiveForInput, boolean isSelected)Arguments
float | dt | time since last call in ms |
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
140 | function AIConveyorBelt:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
141 | if self:getIsAIActive() then |
142 | local spec = self.spec_aiConveyorBelt |
143 | spec.currentDirection, spec.currentSpeed = self:getDirectionAndSpeedToTargetAngle(spec.currentDirection, spec.minTargetWorldYRot, spec.maxTargetWorldYRot) |
144 | |
145 | self:getMotor():setSpeedLimit(math.abs(spec.currentSpeed * spec.speed)) |
146 | WheelsUtil.updateWheelsPhysics(self, dt, spec.currentSpeed * spec.speed * spec.direction, spec.currentDirection * spec.direction, false, true) |
147 | end |
148 | end |
onUpdateTick
DescriptionCalled on updateTickDefinition
onUpdateTick(float dt, boolean isActiveForInput, boolean isSelected)Arguments
float | dt | time since last call in ms |
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
155 | function AIConveyorBelt:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
156 | local spec = self.spec_aiConveyorBelt |
157 | local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA3] |
158 | if actionEvent ~= nil then |
159 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, isActiveForInputIgnoreSelection) |
160 | if isActiveForInputIgnoreSelection then |
161 | g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format(g_i18n:getText("action_conveyorBeltChangeAngle"), string.format("%.0f", spec.currentAngle))) |
162 | end |
163 | end |
164 | end |
onWriteStream
DescriptionCalled on server side on joinDefinition
onWriteStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
131 | function AIConveyorBelt:onWriteStream(streamId, connection) |
132 | streamWriteInt8(streamId, self.spec_aiConveyorBelt.currentAngle) |
133 | end |
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
19 | function AIConveyorBelt.prerequisitesPresent(specializations) |
20 | return SpecializationUtil.hasSpecialization(AIFieldWorker, specializations) and SpecializationUtil.hasSpecialization(Motorized, specializations) |
21 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
61 | function AIConveyorBelt.registerEventListeners(vehicleType) |
62 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", AIConveyorBelt) |
63 | SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", AIConveyorBelt) |
64 | SpecializationUtil.registerEventListener(vehicleType, "onReadStream", AIConveyorBelt) |
65 | SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", AIConveyorBelt) |
66 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", AIConveyorBelt) |
67 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", AIConveyorBelt) |
68 | SpecializationUtil.registerEventListener(vehicleType, "onAIFieldWorkerStart", AIConveyorBelt) |
69 | SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", AIConveyorBelt) |
70 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
43 | function AIConveyorBelt.registerFunctions(vehicleType) |
44 | SpecializationUtil.registerFunction(vehicleType, "setAIConveyorBeltAngle", AIConveyorBelt.setAIConveyorBeltAngle) |
45 | SpecializationUtil.registerFunction(vehicleType, "getDirectionAndSpeedToTargetAngle", AIConveyorBelt.getDirectionAndSpeedToTargetAngle) |
46 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
50 | function AIConveyorBelt.registerOverwrittenFunctions(vehicleType) |
51 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getStartableAIJob", AIConveyorBelt.getStartableAIJob) |
52 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getHasStartableAIJob", AIConveyorBelt.getHasStartableAIJob) |
53 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanStartFieldWork", AIConveyorBelt.getCanStartFieldWork) |
54 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanStartAIVehicle", AIConveyorBelt.getCanStartAIVehicle) |
55 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", AIConveyorBelt.getCanBeSelected) |
56 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAINeedsTrafficCollisionBox", AIConveyorBelt.getAINeedsTrafficCollisionBox) |
57 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
114 | function AIConveyorBelt:saveToXMLFile(xmlFile, key, usedModNames) |
115 | local spec = self.spec_aiConveyorBelt |
116 | xmlFile:setValue(key.."#currentAngle", spec.currentAngle) |
117 | end |
setAIConveyorBeltAngle
DescriptionDefinitionsetAIConveyorBeltAngle()Code
168 | function AIConveyorBelt:setAIConveyorBeltAngle(angle, noEventSend) |
169 | if noEventSend == nil or noEventSend == false then |
170 | if g_server ~= nil then |
171 | g_server:broadcastEvent(AIConveyorBeltSetAngleEvent.new(self, angle), nil, nil, self) |
172 | else |
173 | g_client:getServerConnection():sendEvent(AIConveyorBeltSetAngleEvent.new(self, angle)) |
174 | end |
175 | end |
176 | |
177 | self.spec_aiConveyorBelt.currentAngle = angle |
178 | end |