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
WindTurbinePlaceable
DescriptionClass for placeable wind turbinesParent
PlaceableFunctions
- new
- delete
- deleteFinal
- readStream
- writeStream
- createNode
- load
- finalizePlacement
- initPose
- updateHeadRotation
- loadFromAttributesAndNodes
- getSaveAttributesAndNodes
- update
- hourChanged
new
DescriptionCreating placeable wind turbineDefinition
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 WindTurbinePlaceable:new(isServer, isClient, customMt) |
19 | local mt = customMt; |
20 | if mt == nil then |
21 | mt = WindTurbinePlaceable_mt; |
22 | end; |
23 | |
24 | local self = Placeable:new(isServer, isClient, mt); |
25 | |
26 | registerObjectClassName(self, "WindTurbinePlaceable"); |
27 | |
28 | self.rotationNode = 0; |
29 | self.headNode = 0; |
30 | self.incomePerHour = 0; |
31 | return self; |
32 | end; |
delete
DescriptionDeleting placeable wind turbineDefinition
delete()Code
36 | function WindTurbinePlaceable:delete() |
37 | unregisterObjectClassName(self); |
38 | g_currentMission.environment:removeHourChangeListener(self); |
39 | WindTurbinePlaceable:superClass().delete(self); |
40 | end; |
deleteFinal
DescriptionDeleting placeable wind turbineDefinition
deleteFinal()Code
44 | function WindTurbinePlaceable:deleteFinal() |
45 | WindTurbinePlaceable: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 WindTurbinePlaceable:readStream(streamId, connection) |
53 | if connection:getIsServer() then |
54 | self.headRotation=Utils.readCompressedAngle(streamId); |
55 | end; |
56 | WindTurbinePlaceable: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 WindTurbinePlaceable:writeStream(streamId, connection) |
64 | if not connection:getIsServer() then |
65 | Utils.writeCompressedAngle(streamId, self.headRotation); |
66 | end; |
67 | WindTurbinePlaceable:superClass().writeStream(self, streamId, connection); |
68 | end; |
createNode
DescriptionCreate nodeDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
boolean | success | success |
82 | function WindTurbinePlaceable:createNode(i3dFilename) |
83 | if not WindTurbinePlaceable: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 | if getNumOfChildren(self.headNode) < 1 then |
94 | delete(self.nodeId); |
95 | self.nodeId = 0; |
96 | return false; |
97 | end; |
98 | self.rotationNode = getChildAt(self.headNode, 0); |
99 | |
100 | return true; |
101 | end; |
load
DescriptionLoad wind turbineDefinition
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 |
114 | function WindTurbinePlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom) |
115 | if not WindTurbinePlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then |
116 | return false; |
117 | end; |
118 | |
119 | return true; |
120 | end; |
finalizePlacement
DescriptionCalled if placeable is placedDefinition
finalizePlacement()Code
124 | function WindTurbinePlaceable:finalizePlacement() |
125 | WindTurbinePlaceable:superClass().finalizePlacement(self); |
126 | g_currentMission.environment:addHourChangeListener(self); |
127 | 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 |
138 | function WindTurbinePlaceable:initPose(x,y,z, rx,ry,rz, initRandom) |
139 | WindTurbinePlaceable:superClass().initPose(self, x,y,z, rx,ry,rz, initRandom); |
140 | |
141 | if initRandom == nil or initRandom == true then |
142 | local rotVariation = 0.2; |
143 | self.headRotation = 0.7 + math.random() * 2*rotVariation - rotVariation; |
144 | end; |
145 | rotate(self.rotationNode, 0,0,math.random()*math.pi*2); |
146 | self:updateHeadRotation(); |
147 | end; |
updateHeadRotation
DescriptionUpdating head rotationDefinition
updateHeadRotation()Code
151 | function WindTurbinePlaceable:updateHeadRotation() |
152 | local dx,_,dz = worldDirectionToLocal(self.nodeId, math.sin(self.headRotation),0,math.cos(self.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 WindTurbinePlaceable:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
163 | local headRotation = getXMLFloat(xmlFile, key.."#headRotation"); |
164 | if headRotation == nil then |
165 | return false; |
166 | end; |
167 | |
168 | self.headRotation = headRotation; |
169 | |
170 | if not WindTurbinePlaceable: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 WindTurbinePlaceable:getSaveAttributesAndNodes(nodeIdent) |
183 | local attributes, nodes = WindTurbinePlaceable:superClass().getSaveAttributesAndNodes(self, nodeIdent); |
184 | attributes = attributes .. ' headRotation="'..self.headRotation..'"'; |
185 | return attributes, nodes; |
186 | end; |
update
DescriptionUpdateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
191 | function WindTurbinePlaceable:update(dt) |
192 | if self.rotationNode ~= 0 then |
193 | rotate(self.rotationNode, 0,0,-0.0025*dt); |
194 | end; |
195 | end; |
hourChanged
DescriptionCalled if hour changedDefinition
hourChanged()Code
199 | function WindTurbinePlaceable:hourChanged() |
200 | if self.isServer then |
201 | g_currentMission:addSharedMoney(self.incomePerHour, "propertyIncome"); |
202 | g_currentMission:addMoneyChange(self.incomePerHour, EconomyManager.MONEY_TYPE_PROPERTY_INCOME); |
203 | end |
204 | end |