LUADOC - Farming Simulator 17

Printable Version

HeatingPlantPlaceable

Description
Class for placeable heating plants
Parent
Placeable
Functions

new

Description
Creating placeable high pressure washer
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
18function HeatingPlantPlaceable:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = HeatingPlantPlaceable_mt;
22 end;
23
24 local self = Placeable:new(isServer, isClient, mt);
25
26 registerObjectClassName(self, "HeatingPlantPlaceable");
27
28 self.heatingPlantDirtyFlag = self:getNextDirtyFlag();
29
30 return self;
31end;

delete

Description
Deleting heating plant
Definition
delete()
Code
35function HeatingPlantPlaceable:delete()
36 if self.tipTrigger ~= nil then
37 self.tipTrigger:removeUpdateEventListener(self)
38 if self.tipTrigger.isRegistered then
39 self.tipTrigger:unregister()
40 end
41 self.tipTrigger:delete()
42 end
43
44 if self.exhaustEffect ~= nil then
45 Utils.releaseSharedI3DFile(self.exhaustEffect.filename, self.baseDirectory, true);
46 end
47
48 unregisterObjectClassName(self);
49 HeatingPlantPlaceable:superClass().delete(self);
50end;

load

Description
Load heating plant
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
63function HeatingPlantPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
64 if not HeatingPlantPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
65 return false;
66 end;
67
68 local xmlFile = loadXMLFile("TempXML", xmlFilename);
69
70 self.tipTrigger = TipTrigger:new(self.isServer, self.isClient)
71 if self.tipTrigger:load(Utils.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.heatingPlant#tipTrigger"))) then
72 self.tipTrigger:register(true)
73 self.tipTrigger:addUpdateEventListener(self)
74 else
75 self.tipTrigger:delete()
76 self.tipTrigger = nil
77 end
78
79 if self.isClient then
80 self.heatingPlantRotationNodes = Utils.loadRotationNodes(xmlFile, {}, "placeable.turnedOnRotationNodes.turnedOnRotationNode", "heatingPlant", self.nodeId);
81
82 local filename = getXMLString(xmlFile, "placeable.exhaust#filename");
83 local node = Utils.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.exhaust#index"));
84 if filename ~= nil then
85 local i3dNode = Utils.loadSharedI3DFile(filename, self.baseDirectory, false, false, false);
86 if i3dNode ~= 0 then
87 self.exhaustEffect = {}
88 self.exhaustEffect.node = getChildAt(i3dNode, 0);
89 self.exhaustEffect.filename = filename
90 link(Utils.getNoNil(node, self.nodeId), self.exhaustEffect.node);
91 setVisibility(self.exhaustEffect.node, false);
92 setShaderParameter(self.exhaustEffect.node, "param", 0, 0, 0, 0.4, false);
93 delete(i3dNode);
94 end
95 end
96 end
97
98 self.workingTimeDuration = 120*1000
99 self.workingTime = 0
100
101 delete(xmlFile);
102
103 return true;
104end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
110function HeatingPlantPlaceable:readStream(streamId, connection)
111 HeatingPlantPlaceable:superClass().readStream(self, streamId, connection);
112 if connection:getIsServer() then
113 local tipTriggerId = readNetworkNodeObjectId(streamId);
114 self.tipTrigger:readStream(streamId, connection);
115 g_client:finishRegisterObject(self.tipTrigger, tipTriggerId);
116 end
117end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
123function HeatingPlantPlaceable:writeStream(streamId, connection)
124 HeatingPlantPlaceable:superClass().writeStream(self, streamId, connection);
125 if not connection:getIsServer() then
126 writeNetworkNodeObjectId(streamId, self.tipTrigger.id);
127 self.tipTrigger:writeStream(streamId, connection);
128 g_server:registerObjectInStream(connection, self.tipTrigger);
129 end
130end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
137function HeatingPlantPlaceable:readUpdateStream(streamId, timestamp, connection)
138 HeatingPlantPlaceable:superClass().readUpdateStream(self, streamId, timestamp, connection);
139 if connection:getIsServer() then
140 local workingTimeBiggerZero = streamReadBool(streamId)
141 if workingTimeBiggerZero then
142 self.workingTime = self.workingTimeDuration
143 if self.exhaustEffect ~= nil then
144 setVisibility(self.exhaustEffect.node, true);
145 end
146 end
147 end;
148end;

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
155function HeatingPlantPlaceable:writeUpdateStream(streamId, connection, dirtyMask)
156 HeatingPlantPlaceable:superClass().writeUpdateStream(self, streamId, connection, dirtyMask);
157 if not connection:getIsServer() then
158 streamWriteBool(streamId, self.workingTime > 0)
159 end;
160end;

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
165function HeatingPlantPlaceable:collectPickObjects(node)
166 if self.tipTrigger == nil or self.tipTrigger.shovelTarget == nil or self.tipTrigger.shovelTarget.nodeId ~= node then
167 HeatingPlantPlaceable:superClass().collectPickObjects(self, node)
168 end
169end;

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
174function HeatingPlantPlaceable:update(dt)
175 HeatingPlantPlaceable:superClass().update(self, dt);
176
177 if self.isClient then
178 if self.workingTime > 0 then
179 self.workingTime = self.workingTime - dt
180 if self.workingTime <= 0 then
181 if self.exhaustEffect ~= nil then
182 setVisibility(self.exhaustEffect.node, false);
183 end
184 end
185 end
186
187 Utils.updateRotationNodes(self, self.heatingPlantRotationNodes, dt, self.workingTime > 0);
188 end
189end

updateTick

Description
Update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
194function HeatingPlantPlaceable:updateTick(dt)
195 HeatingPlantPlaceable:superClass().updateTick(self, dt);
196end

onUpdateEvent

Description
Called if someone filled in something
Definition
onUpdateEvent(table trigger, float fillDelta, integer fillType, table trailer, table tipTriggerTarget)
Arguments
tabletriggertrigger
floatfillDeltadelta filled in
integerfillTypefill type filled in
tabletrailerobject of trailer
tabletipTriggerTargettip trigger target
Code
205function HeatingPlantPlaceable:onUpdateEvent(trigger, fillDelta, fillType, trailer, tipTriggerTarget)
206 if self.exhaustEffect ~= nil then
207 setVisibility(self.exhaustEffect.node, true);
208 end
209 if self.isServer then
210 self:raiseDirtyFlags(self.heatingPlantDirtyFlag);
211 end
212 self.workingTime = self.workingTimeDuration
213end