Script v1.4.4.0
- Handtools
- Events
- Objects
- Placeables
- AnimatedObjectPlaceable
- BeehivePlaceable
- GreenhousePlaceable
- HayLoftPlaceable
- HeatingPlantPlaceable
- HighPressureWasherPlaceab...
- Placeable
- SolarCollectorPlaceable
- WindTurbinePlaceable
- Triggers
- Utils
- Vehicles
- Specializations
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
SolarCollectorPlaceable
DescriptionClass for placeable solar collectorsParent
PlaceableFunctions
- new
- delete
- deleteFinal
- readStream
- writeStream
- createNode
- load
- finalizePlacement
- initPose
- updateHeadRotation
- loadFromAttributesAndNodes
- getSaveAttributesAndNodes
- hourChanged
new
DescriptionCreating placeable solar collectorDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | custom metatable |
table | instance | Instance of object |
18 | function 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; |
32 | end; |
delete
DescriptionDeleting solar collectorDefinition
delete()Code
36 | function SolarCollectorPlaceable:delete() |
37 | unregisterObjectClassName(self); |
38 | g_currentMission.environment:removeHourChangeListener(self); |
39 | SolarCollectorPlaceable:superClass().delete(self); |
40 | end; |
deleteFinal
DescriptionDeleting placeable solar collector finalDefinition
deleteFinal()Code
44 | function SolarCollectorPlaceable:deleteFinal() |
45 | SolarCollectorPlaceable:superClass().deleteFinal(self); |
46 | end; |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
52 | function SolarCollectorPlaceable:readStream(streamId, connection) |
53 | if connection:getIsServer() then |
54 | self.headRotationRandom=Utils.readCompressedAngle(streamId); |
55 | end; |
56 | SolarCollectorPlaceable:superClass().readStream(self, streamId, connection); |
57 | end; |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
63 | function 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); |
68 | end; |
createNode
DescriptionCreate nodeDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
boolean | success | success |
82 | function 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; |
95 | end; |
load
DescriptionLoad solar collectorDefinition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)Arguments
string | xmlFilename | xml file name |
float | x | x world position |
float | y | z world position |
float | z | z world position |
float | rx | rx world rotation |
float | ry | ry world rotation |
float | rz | rz world rotation |
boolean | initRandom | initialize random |
boolean | success | success |
108 | function 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; |
114 | end; |
finalizePlacement
DescriptionCalled if placeable is placedDefinition
finalizePlacement()Code
118 | function SolarCollectorPlaceable:finalizePlacement() |
119 | SolarCollectorPlaceable:superClass().finalizePlacement(self); |
120 | g_currentMission.environment:addHourChangeListener(self); |
121 | end |
initPose
DescriptionInitialize poseDefinition
initPose(float x, float y, float z, float rx, float ry, float rz, boolean initRandom)Arguments
float | x | x world position |
float | y | y world position |
float | z | z world position |
float | rx | rx world rotation |
float | ry | ry world rotation |
float | rz | rz world rotation |
boolean | initRandom | initialize random |
132 | function 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(); |
139 | end; |
updateHeadRotation
DescriptionUpdates the rotation of the headDefinition
updateHeadRotation()Code
143 | function 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); |
154 | end; |
loadFromAttributesAndNodes
DescriptionLoading from attributes and nodesDefinition
loadFromAttributesAndNodes(integer xmlFile, string key, boolean resetVehicles)Arguments
integer | xmlFile | id of xml object |
string | key | key |
boolean | resetVehicles | reset vehicles |
boolean | success | success |
162 | function 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; |
175 | end; |
getSaveAttributesAndNodes
DescriptionGet save attributes and nodesDefinition
getSaveAttributesAndNodes(string nodeIdent)Arguments
string | nodeIdent | node ident |
string | attributes | attributes |
string | nodes | nodes |
182 | function SolarCollectorPlaceable:getSaveAttributesAndNodes(nodeIdent) |
183 | local attributes, nodes = SolarCollectorPlaceable:superClass().getSaveAttributesAndNodes(self, nodeIdent); |
184 | attributes = attributes .. ' headRotationRandom="'..self.headRotationRandom..'"'; |
185 | return attributes, nodes; |
186 | end; |
hourChanged
DescriptionCalled if hour changedDefinition
hourChanged()Code
193 | function 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(); |
199 | end |