LUADOC - Farming Simulator 19

SolarCollectorPlaceable

Description
Class for placeable solar collectors
Parent
Placeable
Functions

createNode

Description
Create node
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Return Values
booleansuccesssuccess
Code
74function SolarCollectorPlaceable:createNode(i3dFilename)
75 if not SolarCollectorPlaceable:superClass().createNode(self, i3dFilename) then
76 return false;
77 end;
78
79 if getNumOfChildren(self.nodeId) < 1 then
80 delete(self.nodeId);
81 self.nodeId = 0;
82 return false;
83 end;
84 self.headNode = getChildAt(self.nodeId, 0);
85
86 return true;
87end

delete

Description
Deleting solar collector
Definition
delete()
Code
34function SolarCollectorPlaceable:delete()
35 unregisterObjectClassName(self);
36 g_currentMission.environment:removeHourChangeListener(self);
37 SolarCollectorPlaceable:superClass().delete(self);
38end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
110function SolarCollectorPlaceable:finalizePlacement()
111 SolarCollectorPlaceable:superClass().finalizePlacement(self);
112 g_currentMission.environment:addHourChangeListener(self);
113end

hourChanged

Description
Called if hour changed
Definition
hourChanged()
Code
180function SolarCollectorPlaceable:hourChanged()
181 if self.isServer then
182 g_currentMission:addMoney(self.incomePerHour, self:getOwnerFarmId(), MoneyType.PROPERTY_INCOME, true)
183 end
184 self:updateHeadRotation();
185end

initPose

Description
Initialize pose
Definition
initPose(float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
floatxx world position
floatyy world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Code
124function SolarCollectorPlaceable:initPose(x,y,z, rx,ry,rz, initRandom)
125 SolarCollectorPlaceable:superClass().initPose(self, x,y,z, rx,ry,rz, initRandom);
126
127 local rotVariation = 0.1;
128 self.headRotationRandom = math.rad(75-90) + math.random() * 2*rotVariation - rotVariation; -- 75-90 = rotate to light (75 y rot) x axis
129
130 self:updateHeadRotation();
131end

load

Description
Load solar collector
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
100function SolarCollectorPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
101 if not SolarCollectorPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
102 return false;
103 end;
104
105 return true;
106end

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
154function SolarCollectorPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
155 local headRotationRandom = getXMLFloat(xmlFile, key.."#headRotationRandom");
156 if headRotationRandom == nil then
157 return false;
158 end;
159
160 self.headRotationRandom = headRotationRandom;
161
162 if not SolarCollectorPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
163 return false;
164 end;
165
166 return true;
167end

new

Description
Creating placeable solar collector
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
16function SolarCollectorPlaceable:new(isServer, isClient, customMt)
17 local mt = customMt;
18 if mt == nil then
19 mt = SolarCollectorPlaceable_mt;
20 end;
21
22 local self = Placeable:new(isServer, isClient, mt);
23
24 registerObjectClassName(self, "SolarCollectorPlaceable");
25
26 self.headNode = 0;
27 self.incomePerHour = 0;
28 self.headRotationRandom = 0;
29 return self;
30end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
44function SolarCollectorPlaceable:readStream(streamId, connection)
45 if connection:getIsServer() then
46 self.headRotationRandom=NetworkUtil.readCompressedAngle(streamId);
47 end;
48 SolarCollectorPlaceable:superClass().readStream(self, streamId, connection);
49end

updateHeadRotation

Description
Updates the rotation of the head
Definition
updateHeadRotation()
Code
135function SolarCollectorPlaceable:updateHeadRotation()
136
137 local headRotation = math.rad(75-90);
138 if g_currentMission.environment.sunLightId ~= nil then
139 local dx,_,dz = localDirectionToWorld(g_currentMission.environment.sunLightId, 0,0,1);
140 headRotation = math.atan2(dx, dz);
141 end
142 headRotation = headRotation + self.headRotationRandom;
143
144 local dx,_,dz = worldDirectionToLocal(self.nodeId, math.sin(headRotation),0,math.cos(headRotation));
145 setDirection(self.headNode, dx,0,dz, 0,1,0);
146end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
55function SolarCollectorPlaceable:writeStream(streamId, connection)
56 if not connection:getIsServer() then
57 NetworkUtil.writeCompressedAngle(streamId, self.headRotationRandom);
58 end;
59 SolarCollectorPlaceable:superClass().writeStream(self, streamId, connection);
60end