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
WindTurbinePlaceable
DescriptionClass for placeable wind turbinesParent
PlaceableFunctions
- delete
- finalizePlacement
- hourChanged
- initPose
- load
- loadFromXMLFile
- new
- readStream
- update
- updateHeadRotation
- writeStream
delete
DescriptionDeleting placeable wind turbineDefinition
delete()Code
30 | function WindTurbinePlaceable:delete() |
31 | unregisterObjectClassName(self) |
32 | g_currentMission.environment:removeHourChangeListener(self) |
33 | WindTurbinePlaceable:superClass().delete(self) |
34 | end |
finalizePlacement
DescriptionCalled if placeable is placedDefinition
finalizePlacement()Code
91 | function WindTurbinePlaceable:finalizePlacement() |
92 | WindTurbinePlaceable:superClass().finalizePlacement(self) |
93 | g_currentMission.environment:addHourChangeListener(self) |
94 | end |
hourChanged
DescriptionCalled if hour changedDefinition
hourChanged()Code
167 | function WindTurbinePlaceable:hourChanged() |
168 | if self.isServer then |
169 | g_currentMission:addMoney(self.incomePerHour, self:getOwnerFarmId(), MoneyType.PROPERTY_INCOME, true) |
170 | end |
171 | 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 |
105 | function WindTurbinePlaceable:initPose(x,y,z, rx,ry,rz, initRandom) |
106 | WindTurbinePlaceable:superClass().initPose(self, x,y,z, rx,ry,rz, initRandom) |
107 | |
108 | if self.headNode ~= nil and self.headNode ~= 0 then |
109 | if initRandom == nil or initRandom == true then |
110 | local rotVariation = 0.2 |
111 | self.headRotation = 0.7 + math.random() * 2*rotVariation - rotVariation |
112 | end |
113 | |
114 | rotate(self.rotationNode, 0,0,math.random()*math.pi*2) |
115 | |
116 | self:updateHeadRotation() |
117 | end |
118 | 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 |
71 | function WindTurbinePlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom) |
72 | if not WindTurbinePlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then |
73 | return false |
74 | end |
75 | |
76 | local xmlFile = loadXMLFile("TempXML", xmlFilename) |
77 | |
78 | self.headNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.windTurbine#headNode")) |
79 | self.rotationNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.windTurbine#rotationNode")) |
80 | |
81 | -- Now that the nodes are loaded, pose again |
82 | self:initPose(x,y,z, rx,ry,rz, initRandom) |
83 | |
84 | delete(xmlFile) |
85 | |
86 | return true |
87 | 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 |
133 | function WindTurbinePlaceable:loadFromXMLFile(xmlFile, key, resetVehicles) |
134 | local headRotation = getXMLFloat(xmlFile, key.."#headRotation") |
135 | if headRotation == nil then |
136 | return false |
137 | end |
138 | |
139 | self.headRotation = headRotation |
140 | |
141 | if not WindTurbinePlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then |
142 | return false |
143 | end |
144 | |
145 | return true |
146 | end |
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 |
16 | function WindTurbinePlaceable:new(isServer, isClient, customMt) |
17 | local self = Placeable:new(isServer, isClient, customMt or WindTurbinePlaceable_mt) |
18 | |
19 | registerObjectClassName(self, "WindTurbinePlaceable") |
20 | |
21 | self.rotationNode = 0 |
22 | self.headNode = 0 |
23 | self.incomePerHour = 0 |
24 | |
25 | return self |
26 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
40 | function WindTurbinePlaceable:readStream(streamId, connection) |
41 | if connection:getIsServer() then |
42 | self.headRotation = NetworkUtil.readCompressedAngle(streamId) |
43 | end |
44 | |
45 | WindTurbinePlaceable:superClass().readStream(self, streamId, connection) |
46 | end |
update
DescriptionUpdateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
157 | function WindTurbinePlaceable:update(dt) |
158 | if self.rotationNode ~= 0 then |
159 | rotate(self.rotationNode, 0,0,-0.0025*dt) |
160 | |
161 | self:raiseActive() |
162 | end |
163 | end |
updateHeadRotation
DescriptionUpdating head rotationDefinition
updateHeadRotation()Code
122 | function WindTurbinePlaceable:updateHeadRotation() |
123 | local dx,_,dz = worldDirectionToLocal(self.nodeId, math.sin(self.headRotation),0,math.cos(self.headRotation)) |
124 | setDirection(self.headNode, dx,0,dz, 0,1,0) |
125 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
52 | function WindTurbinePlaceable:writeStream(streamId, connection) |
53 | if not connection:getIsServer() then |
54 | NetworkUtil.writeCompressedAngle(streamId, self.headRotation) |
55 | end |
56 | |
57 | WindTurbinePlaceable:superClass().writeStream(self, streamId, connection) |
58 | end |