LUADOC - Farming Simulator 19

Doghouse

Parent
Placeable
Functions

canBuy

Description
Returns true if we can place a building
Definition
canBuy()
Return Values
bool
Code
66function Doghouse:canBuy()
67 local canBuy = AnimalHusbandry:superClass().canBuy(self)
68 return canBuy and not self:isDoghouseRegistered(), g_i18n:getText("warning_onlyOneOfThisItemAllowedPerFarm")
69end

delete

Description
Delete instance
Definition
delete()
Code
32function Doghouse:delete()
33 self:unregisterDoghouseToMission()
34
35 if self.isServer then
36 if self.dogBall ~= nil and not self.dogBall.isDeleted then -- Note: the dogBall might have been deleted by the server/client delete loop already
37 self.dogBall:delete()
38 self.dogBall = nil
39 end
40 if self.dog ~= nil and not self.dog.isDeleted then -- Note: the dogBall might have been deleted by the server/client delete loop already
41 self.dog:delete()
42 self.dog = nil
43 end
44 end
45
46 if self.triggerNode ~= nil then
47 removeTrigger(self.triggerNode)
48 end
49
50 unregisterObjectClassName(self)
51
52 Doghouse:superClass().delete(self)
53end

drawActivate

Description
Draw HUD icon
Definition
drawActivate()
Code
265function Doghouse:drawActivate()
266 g_currentMission:showFillDogBowlContext()
267end

drawDogName

Description
Definition
drawDogName()
Code
222function Doghouse:drawDogName()
223 -- @Todo: adust text width
224 setTextColor(0.843, 0.745, 0.705, 1.0)
225 setTextAlignment(RenderText.ALIGN_CENTER)
226 local x,y,z = getWorldTranslation(self.namePlateNode)
227 local rx,ry,rz = getWorldRotation(self.namePlateNode)
228 renderText3D(x,y,z, rx,ry,rz, 0.04, self.dog.name)
229 setTextAlignment(RenderText.ALIGN_LEFT)
230end

finalizePlacement

Description
Finalize placement
Definition
finalizePlacement()
Return Values
boolreturnstrue if placement successful
Code
74function Doghouse:finalizePlacement()
75 Doghouse:superClass().finalizePlacement(self)
76
77 -- dog specific information
78 local xmlFile = loadXMLFile("TempXML", self.configFileName)
79
80 if xmlFile == 0 then
81 return false
82 end
83
84 self.spawnNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.dogHouse.dog#node"))
85 if self.isServer then
86 local posX, posY, posZ = getWorldTranslation(self.spawnNode)
87 local xmlFilename = Utils.getFilename(getXMLString(xmlFile, "placeable.dogHouse.dog#xmlFilename"), self.baseDirectory)
88 self.dog = Dog:new(self.isServer, self.isClient)
89 self.dog:setOwnerFarmId(self:getOwnerFarmId(), true)
90 self.dog:load(self, xmlFilename, posX, posY, posZ)
91 self.dog:register()
92 end
93
94 self:registerDoghouseToMission()
95
96 self.namePlateNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.dogHouse.nameplate#node"))
97
98 self.ballSpawnNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.dogHouse.ball#node"))
99 if self.isServer then
100 local dogBallFilename = Utils.getFilename(getXMLString(xmlFile, "placeable.dogHouse.ball#filename"), self.baseDirectory)
101 local x, y, z = getWorldTranslation(self.ballSpawnNode)
102 local rx, ry, rz = getWorldRotation(self.ballSpawnNode)
103 self.dogBall = DogBall:new(self.isServer, self.isClient)
104 self.dogBall:setOwnerFarmId(self:getOwnerFarmId(), true)
105 self.dogBall:load(dogBallFilename, x, y, z, rx, ry, rz, self)
106 self.dogBall:register()
107 end
108
109
110 -- player interaction trigger
111 self.triggerNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.dogHouse.playerInteractionTrigger#node"))
112 if self.triggerNode ~= nil then
113 addTrigger(self.triggerNode, "playerInteractionTriggerCallback", self)
114 end
115
116 self.foodNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.dogHouse.bowl#foodNode"))
117 delete(xmlFile)
118 if self.foodNode ~= nil then
119 setVisibility(self.foodNode, false)
120 return true
121 end
122 return false
123end

getCanBePlacedAt

Description
Returns true if we can place a building
Definition
getCanBePlacedAt()
Return Values
bool
Code
58function Doghouse:getCanBePlacedAt(x, y, z, distance, farmId)
59 local canBePlaced = Doghouse:superClass().getCanBePlacedAt(self, x, y, z, distance, farmId)
60 return canBePlaced and not self:isDoghouseRegistered()
61end

getIsActivatable

Description
Checks if doghouse can be activated and bowl is empty
Definition
getIsActivatable()
Return Values
boolreturntrue if doghouse can be activated to fill bowl
Code
259function Doghouse:getIsActivatable()
260 return self.isActivatable
261end

isDoghouseRegistered

Description
Returns true if a doghouse is registered
Definition
isDoghouseRegistered()
Return Values
bool
Code
285function Doghouse:isDoghouseRegistered()
286 local dogHouse = g_currentMission:getDoghouse(self:getOwnerFarmId())
287 return dogHouse ~= nil
288end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
183function Doghouse:loadFromXMLFile(xmlFile, key, resetVehicles)
184 if not Doghouse:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
185 return false
186 end
187
188 return self.dog:loadFromXMLFile(xmlFile, key..".dog", resetVehicles)
189end

new

Description
Creating instance and initializing member variables
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom meta table
Return Values
tableinstanceInstance of object
Code
15function Doghouse:new(isServer, isClient, customMt)
16 local self = Placeable:new(isServer, isClient, customMt or Doghouse_mt)
17
18 registerObjectClassName(self, "Doghouse")
19
20 -- trigger
21 self.triggerNode = nil
22 self.isActivatable = false
23 self.activateText = g_i18n:getText("action_doghouseFillbowl")
24
25 self.dirtyFlag = self:getNextDirtyFlag()
26
27 return self
28end

onActivateObject

Description
Callback on bowl activated
Definition
onActivateObject()
Code
252function Doghouse:onActivateObject()
253 self:raiseActive()
254end

playerInteractionTriggerCallback

Description
Callback when interaction trigger is activated
Definition
playerInteractionTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
239function Doghouse:playerInteractionTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
240 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode and g_currentMission.player.farmId == self:getOwnerFarmId() then
241 if onEnter then
242 self.isActivatable = true
243 elseif onLeave then
244 self.isActivatable = false
245 end
246 end
247 --self:raiseActive()
248end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
129function Doghouse:readStream(streamId, connection)
130 Doghouse:superClass().readStream(self, streamId, connection)
131 if connection:getIsServer() then
132 self.dog = NetworkUtil.readNodeObject(streamId)
133 if self.dog ~= nil then
134 self.dog.spawner = self
135 end
136 setVisibility(self.foodNode, streamReadBool(streamId))
137 end
138end

readUpdateStream

Description
Read update network stream
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdnetwork stream identification
integertimestamp
tableconnectionconnection information
Code
158function Doghouse:readUpdateStream(streamId, timestamp, connection)
159 Doghouse:superClass().readUpdateStream(self, streamId, timestamp, connection)
160 if connection:getIsServer() then
161 setVisibility(self.foodNode, streamReadBool(streamId))
162 end
163end

registerDoghouseToMission

Description
Registers the doghouse to the mission game.
Definition
registerDoghouseToMission()
Return Values
booltrueif registration went well
Code
293function Doghouse:registerDoghouseToMission()
294 if not self:isDoghouseRegistered() then
295 g_currentMission.doghouses[self] = self
296 return true
297 end
298 return false
299end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
196function Doghouse:saveToXMLFile(xmlFile, key, usedModNames)
197 Doghouse:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
198
199 self.dog:saveToXMLFile(xmlFile, key..".dog", usedModNames)
200end

unregisterDoghouseToMission

Description
Registers the doghouse to the mission game.
Definition
unregisterDoghouseToMission()
Return Values
booltrueif registration went well
Code
304function Doghouse:unregisterDoghouseToMission()
305 g_currentMission.doghouses[self] = nil
306 return true
307end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
144function Doghouse:writeStream(streamId, connection)
145 Doghouse:superClass().writeStream(self, streamId, connection)
146 if not connection:getIsServer() then
147 NetworkUtil.writeNodeObject(streamId, self.dog)
148 streamWriteBool(streamId, getVisibility(self.foodNode))
149 end
150end

writeUpdateStream

Description
Write update network stream
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
integerdirtyMask
Code
170function Doghouse:writeUpdateStream(streamId, connection, dirtyMask)
171 Doghouse:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
172 if not connection:getIsServer() then
173 streamWriteBool(streamId, getVisibility(self.foodNode))
174 end
175end