Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- AnimalHusbandry
- BeehivePlaceable
- BgaPlaceable
- BunkerSiloPlaceable
- BuyingStationPlaceable
- Doghouse
- FarmhousePlaceable
- GreenhousePlaceable
- HeatingPlantPlaceable
- HusbandryModuleWater
- Placeable
- SellingStationPlaceable
- SiloExtensionPlaceable
- SiloPlaceable
- SolarCollectorPlaceable
- WindTurbinePlaceable
- WoodSellStationPlaceable
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
SolarCollectorPlaceable
DescriptionClass for placeable solar collectorsParent
PlaceableFunctions
- createNode
- delete
- finalizePlacement
- hourChanged
- initPose
- load
- loadFromXMLFile
- new
- readStream
- updateHeadRotation
- writeStream
createNode
DescriptionCreate nodeDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
boolean | success | success |
74 | function 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; |
87 | end |
delete
DescriptionDeleting solar collectorDefinition
delete()Code
34 | function SolarCollectorPlaceable:delete() |
35 | unregisterObjectClassName(self); |
36 | g_currentMission.environment:removeHourChangeListener(self); |
37 | SolarCollectorPlaceable:superClass().delete(self); |
38 | end |
finalizePlacement
DescriptionCalled if placeable is placedDefinition
finalizePlacement()Code
110 | function SolarCollectorPlaceable:finalizePlacement() |
111 | SolarCollectorPlaceable:superClass().finalizePlacement(self); |
112 | g_currentMission.environment:addHourChangeListener(self); |
113 | end |
hourChanged
DescriptionCalled if hour changedDefinition
hourChanged()Code
180 | function SolarCollectorPlaceable:hourChanged() |
181 | if self.isServer then |
182 | g_currentMission:addMoney(self.incomePerHour, self:getOwnerFarmId(), MoneyType.PROPERTY_INCOME, true) |
183 | end |
184 | self:updateHeadRotation(); |
185 | 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 |
124 | function 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(); |
131 | 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 |
100 | function 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; |
106 | end |
loadFromXMLFile
DescriptionLoading from attributes and nodesDefinition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)Arguments
integer | xmlFile | id of xml object |
string | key | key |
boolean | resetVehicles | reset vehicles |
boolean | success | success |
154 | function 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; |
167 | end |
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 |
16 | function 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; |
30 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
44 | function SolarCollectorPlaceable:readStream(streamId, connection) |
45 | if connection:getIsServer() then |
46 | self.headRotationRandom=NetworkUtil.readCompressedAngle(streamId); |
47 | end; |
48 | SolarCollectorPlaceable:superClass().readStream(self, streamId, connection); |
49 | end |
updateHeadRotation
DescriptionUpdates the rotation of the headDefinition
updateHeadRotation()Code
135 | function 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); |
146 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
55 | function 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); |
60 | end |