LUADOC - Farming Simulator 17

Printable Version

SolarCollectorPlaceable

Description
Class for placeable solar collectors
Parent
Placeable
Functions

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
18function SolarCollectorPlaceable:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = SolarCollectorPlaceable_mt;
22 end;
23
24 local self = Placeable:new(isServer, isClient, mt);
25
26 registerObjectClassName(self, "SolarCollectorPlaceable");
27
28 self.headNode = 0;
29 self.incomePerHour = 0;
30 self.headRotationRandom = 0;
31 return self;
32end;

delete

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

deleteFinal

Description
Deleting placeable solar collector final
Definition
deleteFinal()
Code
44function SolarCollectorPlaceable:deleteFinal()
45 SolarCollectorPlaceable:superClass().deleteFinal(self);
46end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
52function SolarCollectorPlaceable:readStream(streamId, connection)
53 if connection:getIsServer() then
54 self.headRotationRandom=Utils.readCompressedAngle(streamId);
55 end;
56 SolarCollectorPlaceable:superClass().readStream(self, streamId, connection);
57end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
63function SolarCollectorPlaceable:writeStream(streamId, connection)
64 if not connection:getIsServer() then
65 Utils.writeCompressedAngle(streamId, self.headRotationRandom);
66 end;
67 SolarCollectorPlaceable:superClass().writeStream(self, streamId, connection);
68end;

createNode

Description
Create node
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Return Values
booleansuccesssuccess
Code
82function SolarCollectorPlaceable:createNode(i3dFilename)
83 if not SolarCollectorPlaceable:superClass().createNode(self, i3dFilename) then
84 return false;
85 end;
86
87 if getNumOfChildren(self.nodeId) < 1 then
88 delete(self.nodeId);
89 self.nodeId = 0;
90 return false;
91 end;
92 self.headNode = getChildAt(self.nodeId, 0);
93
94 return true;
95end;

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
108function SolarCollectorPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
109 if not SolarCollectorPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
110 return false;
111 end;
112
113 return true;
114end;

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
118function SolarCollectorPlaceable:finalizePlacement()
119 SolarCollectorPlaceable:superClass().finalizePlacement(self);
120 g_currentMission.environment:addHourChangeListener(self);
121end

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
132function SolarCollectorPlaceable:initPose(x,y,z, rx,ry,rz, initRandom)
133 SolarCollectorPlaceable:superClass().initPose(self, x,y,z, rx,ry,rz, initRandom);
134
135 local rotVariation = 0.1;
136 self.headRotationRandom = math.rad(75-90) + math.random() * 2*rotVariation - rotVariation; -- 75-90 = rotate to light (75 y rot) x axis
137
138 self:updateHeadRotation();
139end;

updateHeadRotation

Description
Updates the rotation of the head
Definition
updateHeadRotation()
Code
143function SolarCollectorPlaceable:updateHeadRotation()
144
145 local headRotation = math.rad(75-90);
146 if g_currentMission.environment.sunLightId ~= nil then
147 local dx,_,dz = localDirectionToWorld(g_currentMission.environment.sunLightId, 0,0,1);
148 headRotation = math.atan2(dx, dz);
149 end
150 headRotation = headRotation + self.headRotationRandom;
151
152 local dx,_,dz = worldDirectionToLocal(self.nodeId, math.sin(headRotation),0,math.cos(headRotation));
153 setDirection(self.headNode, dx,0,dz, 0,1,0);
154end;

loadFromAttributesAndNodes

Description
Loading from attributes and nodes
Definition
loadFromAttributesAndNodes(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
162function SolarCollectorPlaceable:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
163 local headRotationRandom = getXMLFloat(xmlFile, key.."#headRotationRandom");
164 if headRotationRandom == nil then
165 return false;
166 end;
167
168 self.headRotationRandom = headRotationRandom;
169
170 if not SolarCollectorPlaceable:superClass().loadFromAttributesAndNodes(self, xmlFile, key, resetVehicles) then
171 return false;
172 end;
173
174 return true;
175end;

getSaveAttributesAndNodes

Description
Get save attributes and nodes
Definition
getSaveAttributesAndNodes(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
182function SolarCollectorPlaceable:getSaveAttributesAndNodes(nodeIdent)
183 local attributes, nodes = SolarCollectorPlaceable:superClass().getSaveAttributesAndNodes(self, nodeIdent);
184 attributes = attributes .. ' headRotationRandom="'..self.headRotationRandom..'"';
185 return attributes, nodes;
186end;

hourChanged

Description
Called if hour changed
Definition
hourChanged()
Code
193function SolarCollectorPlaceable:hourChanged()
194 if self.isServer then
195 g_currentMission:addSharedMoney(self.incomePerHour, "propertyIncome");
196 g_currentMission:addMoneyChange(self.incomePerHour, EconomyManager.MONEY_TYPE_PROPERTY_INCOME);
197 end
198 self:updateHeadRotation();
199end