Skip to main content
Skip to main content

SemiTrailerFront

SemiTrailerFront

Description

Specialization for detachable front part of separable semi trailers

Functions

isDetachAllowed

Description

Returns true if detach is allowed

Definition

isDetachAllowed()

Arguments

anysuperFunc

Return Values

anydetachAlloweddetach is allowed

Code

function SemiTrailerFront:isDetachAllowed(superFunc)
local canBeDatached, warning = superFunc( self )
if not canBeDatached then
return false , warning
end

local spec = self.spec_semiTrailerFront
return spec.attachedSemiTrailerBack ~ = nil , nil
end

onLoad

Description

Called on loading

Definition

onLoad(table savegame)

Arguments

tablesavegamesavegame

Code

function SemiTrailerFront:onLoad(savegame)
local spec = self.spec_semiTrailerFront
spec.inputAttacherCurFade = 1
spec.inputAttacherFadeDir = 1
spec.inputAttacherFadeDuration = 1000

spec.joint = self.spec_attachable.inputAttacherJoints[ 1 ]
spec.joint.lowerRotLimitScaleBackup = { spec.joint.lowerRotLimitScale[ 1 ], spec.joint.lowerRotLimitScale[ 2 ], spec.joint.lowerRotLimitScale[ 3 ] }

spec.attachedSemiTrailerBack = nil
spec.inputAttacherImplement = nil
spec.doSemiTrailerLockCheck = true
end

onPostAttach

Description

Called after vehicle was attached

Definition

onPostAttach(table attacherVehicle, integer inputJointDescIndex, integer jointDescIndex)

Arguments

tableattacherVehicleattacher vehicle
integerinputJointDescIndexindex of input attacher joint
integerjointDescIndexindex of attacher joint it was attached to

Code

function SemiTrailerFront:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex)
local spec = self.spec_semiTrailerFront
spec.inputAttacherImplement = attacherVehicle:getImplementByObject( self )
end

onPostAttachImplement

Description

Called on attaching a implement

Definition

onPostAttachImplement(table implement, , , )

Arguments

tableimplementimplement to attach
anyinputJointDescIndex
anyjointDescIndex
anyloadFromSavegame

Code

function SemiTrailerFront:onPostAttachImplement(attachable, inputJointDescIndex, jointDescIndex, loadFromSavegame)
local spec = self.spec_semiTrailerFront
spec.attachedSemiTrailerBack = attachable
spec.inputAttacherFadeDir = 1000
end

onPreDetach

Description

Called if vehicle gets detached

Definition

onPreDetach(table attacherVehicle, table implement)

Arguments

tableattacherVehicleattacher vehicle
tableimplementimplement

Code

function SemiTrailerFront:onPreDetach(attacherVehicle, implement)
local spec = self.spec_semiTrailerFront
spec.inputAttacherImplement = nil
end

onPreDetachImplement

Description

Called on detaching a implement

Definition

onPreDetachImplement(integer implementIndex)

Arguments

integerimplementIndexindex of implement to detach

Code

function SemiTrailerFront:onPreDetachImplement(implement)
local spec = self.spec_semiTrailerFront
spec.attachedSemiTrailerBack = nil
spec.inputAttacherFadeDir = - 1
end

onUpdate

Description

Called on update

Definition

onUpdate(float dt, boolean isActiveForInput, boolean isSelected, )

Arguments

floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
anyisSelected

Code

function SemiTrailerFront:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
local spec = self.spec_semiTrailerFront

if spec.doSemiTrailerLockCheck then
spec.doSemiTrailerLockCheck = false
if spec.attachedSemiTrailerBack = = nil then
spec.inputAttacherFadeDir = - 1
end
end

if self.isServer and spec.inputAttacherImplement ~ = nil and((spec.inputAttacherCurFade > 0 and spec.inputAttacherFadeDir < 0 ) or(spec.inputAttacherCurFade < 1 and spec.inputAttacherFadeDir > 0 )) then
spec.inputAttacherCurFade = math.clamp(spec.inputAttacherCurFade + (spec.inputAttacherFadeDir * dt) / spec.inputAttacherFadeDuration, 0 , 1 )

local lowerRotLimitScale = spec.joint.lowerRotLimitScale
local lowerRotLimitScaleBackup = spec.joint.lowerRotLimitScaleBackup
lowerRotLimitScale[ 1 ] = lowerRotLimitScaleBackup[ 1 ] * spec.inputAttacherCurFade
lowerRotLimitScale[ 2 ] = lowerRotLimitScaleBackup[ 2 ] * spec.inputAttacherCurFade
lowerRotLimitScale[ 3 ] = lowerRotLimitScaleBackup[ 3 ] * spec.inputAttacherCurFade

local attacherVehicle = self:getAttacherVehicle()
if attacherVehicle ~ = nil then
local attacherJoints = attacherVehicle:getAttacherJoints()
local jointDesc = attacherJoints[spec.inputAttacherImplement.jointDescIndex]
local lowerRotLimit = spec.inputAttacherImplement.lowerRotLimit
if lowerRotLimit ~ = nil then
local x = lowerRotLimit[ 1 ] * lowerRotLimitScale[ 1 ]
local y = lowerRotLimit[ 2 ] * lowerRotLimitScale[ 2 ]
local z = lowerRotLimit[ 3 ] * lowerRotLimitScale[ 3 ]

setJointRotationLimit(jointDesc.jointIndex, 0 , true , - x, x)
setJointRotationLimit(jointDesc.jointIndex, 1 , true , - y, y)
setJointRotationLimit(jointDesc.jointIndex, 2 , true , - z, z)
end
end
end
end

prerequisitesPresent

Description

Checks if all prerequisite specializations are loaded

Definition

prerequisitesPresent(table specializations)

Arguments

tablespecializationsspecializations

Return Values

tablehasPrerequisitetrue if all prerequisite specializations are loaded

Code

function SemiTrailerFront.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization( AttacherJoints , specializations)
end

registerEventListeners

Description

Definition

registerEventListeners()

Arguments

anyvehicleType

Code

function SemiTrailerFront.registerEventListeners(vehicleType)
SpecializationUtil.registerEventListener(vehicleType, "onLoad" , SemiTrailerFront )
SpecializationUtil.registerEventListener(vehicleType, "onUpdate" , SemiTrailerFront )
SpecializationUtil.registerEventListener(vehicleType, "onPostAttachImplement" , SemiTrailerFront )
SpecializationUtil.registerEventListener(vehicleType, "onPreDetachImplement" , SemiTrailerFront )
SpecializationUtil.registerEventListener(vehicleType, "onPreDetach" , SemiTrailerFront )
SpecializationUtil.registerEventListener(vehicleType, "onPostAttach" , SemiTrailerFront )
end

registerOverwrittenFunctions

Description

Definition

registerOverwrittenFunctions()

Arguments

anyvehicleType

Code

function SemiTrailerFront.registerOverwrittenFunctions(vehicleType)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "isDetachAllowed" , SemiTrailerFront.isDetachAllowed)
end