Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
2 | |
3 | WindTurbinePlaceable = {}; |
4 | WindTurbinePlaceable_mt = Class(WindTurbinePlaceable, Placeable); |
5 | |
6 | InitStaticObjectClass(WindTurbinePlaceable, "WindTurbinePlaceable", ObjectIds.OBJECT_WIND_TURBINE_PLACEABLE); |
7 | |
8 | function WindTurbinePlaceable:new(isServer, isClient, customMt) |
9 | local mt = customMt; |
10 | if mt == nil then |
11 | mt = WindTurbinePlaceable_mt; |
12 | end; |
13 | |
14 | local self = Placeable:new(isServer, isClient, mt); |
15 | |
16 | registerObjectClassName(self, "WindTurbinePlaceable"); |
17 | |
18 | self.rotationNode = 0; |
19 | self.headNode = 0; |
20 | self.incomePerHour = 0; |
21 | return self; |
22 | end; |
23 | |
24 | function WindTurbinePlaceable:delete() |
25 | unregisterObjectClassName(self); |
26 | g_currentMission.environment:removeHourChangeListener(self); |
27 | WindTurbinePlaceable:superClass().delete(self); |
28 | end; |
29 | |
30 | function WindTurbinePlaceable:deleteFinal() |
31 | WindTurbinePlaceable:superClass().deleteFinal(self); |
32 | end; |
33 | |
34 | function WindTurbinePlaceable:readStream(streamId, connection) |
35 | if connection:getIsServer() then |
36 | self.headRotation=Utils.readCompressedAngle(streamId); |
37 | end; |
38 | WindTurbinePlaceable:superClass().readStream(self, streamId, connection); |
39 | end; |
40 | |
41 | function WindTurbinePlaceable:writeStream(streamId, connection) |
42 | if not connection:getIsServer() then |
43 | Utils.writeCompressedAngle(streamId, self.headRotation); |
44 | end; |
45 | WindTurbinePlaceable:superClass().writeStream(self, streamId, connection); |
46 | end; |
47 | |
48 | --[[function WindTurbinePlaceable:readUpdateStream(streamId, timestamp, connection) |
49 | WindTurbinePlaceable:superClass().readStream(self, streamId, timestamp, connection); |
50 | end; |
51 | |
52 | function WindTurbinePlaceable:writeUpdateStream(streamId, connection, dirtyMask) |
53 | WindTurbinePlaceable:superClass().writeUpdateStream(self, streamId, connection, dirtyMask); |
54 | end;]] |
55 | |
56 | function WindTurbinePlaceable:createNode(i3dFilename) |
57 | if not WindTurbinePlaceable:superClass().createNode(self, i3dFilename) then |
58 | return false; |
59 | end; |
60 | |
61 | if getNumOfChildren(self.nodeId) < 1 then |
62 | delete(self.nodeId); |
63 | self.nodeId = 0; |
64 | return false; |
65 | end; |
66 | self.headNode = getChildAt(self.nodeId, 0); |
67 | if getNumOfChildren(self.headNode) < 1 then |
68 | delete(self.nodeId); |
69 | self.nodeId = 0; |
70 | return false; |
71 | end; |
72 | self.rotationNode = getChildAt(self.headNode, 0); |
73 | |
74 | return true; |
75 | end; |
76 | |
77 | function WindTurbinePlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom) |
78 | if not WindTurbinePlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then |
79 | return false; |
80 | end; |
81 | |
82 | local xmlFile = loadXMLFile("TempXML", xmlFilename); |
83 | |
84 | local difficultyMultiplier = 2 ^ (3 - g_currentMission.missionStats.difficulty); --4 2 1 |
85 | self.incomePerHour = difficultyMultiplier * Utils.getNoNil(getXMLFloat(xmlFile, "placeable.incomePerHour"), 100); |
86 | |
87 | delete(xmlFile); |
88 | |
89 | return true; |
90 | end; |
91 | |
92 | function WindTurbinePlaceable:finalizePlacement() |
93 | WindTurbinePlaceable:superClass().finalizePlacement(self); |
94 | g_currentMission.environment:addHourChangeListener(self); |
95 | end |
96 | |
97 | function WindTurbinePlaceable:initPose(x,y,z, rx,ry,rz, initRandom) |
98 | WindTurbinePlaceable:superClass().initPose(self, x,y,z, rx,ry,rz, initRandom); |
99 | |
100 | if initRandom == nil or initRandom == true then |
101 | local rotVariation = 0.2; |
102 | self.headRotation = 0.7 + math.random() * 2*rotVariation - rotVariation; |
103 | end; |
104 | rotate(self.rotationNode, 0,0,math.random()*math.pi*2); |
105 | self:updateHeadRotation(); |
106 | end; |
107 | |
108 | function WindTurbinePlaceable:updateHeadRotation() |
109 | local dx,dy,dz = worldDirectionToLocal(self.nodeId, math.sin(self.headRotation),0,math.cos(self.headRotation)); |
110 | setDirection(self.headNode, dx,0,dz, 0,1,0); |
111 | end; |
112 | |
113 | function WindTurbinePlaceable:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
114 | local headRotation = getXMLFloat(xmlFile, key.."#headRotation"); |
115 | if headRotation == nil then |
116 | return false; |
117 | end; |
118 | |
119 | self.headRotation = headRotation; |
120 | |
121 | if not WindTurbinePlaceable:superClass().loadFromAttributesAndNodes(self, xmlFile, key, resetVehicles) then |
122 | return false; |
123 | end; |
124 | |
125 | return true; |
126 | end; |
127 | |
128 | function WindTurbinePlaceable:getSaveAttributesAndNodes(nodeIdent) |
129 | local attributes, nodes = WindTurbinePlaceable:superClass().getSaveAttributesAndNodes(self, nodeIdent); |
130 | attributes = attributes .. ' headRotation="'..self.headRotation..'"'; |
131 | return attributes, nodes; |
132 | end; |
133 | |
134 | function WindTurbinePlaceable:update(dt) |
135 | if self.rotationNode ~= 0 then |
136 | rotate(self.rotationNode, 0,0,-0.0025*dt); |
137 | end; |
138 | end; |
139 | |
140 | function WindTurbinePlaceable:hourChanged() |
141 | if self.isServer then |
142 | g_currentMission:addSharedMoney(self.incomePerHour, "other"); |
143 | g_currentMission:addMoneyChange(self.incomePerHour, FSBaseMission.MONEY_TYPE_HOUR_CHANGED); |
144 | end |
145 | end
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de