Sprache Deutsch Language English

Script Dokumentation LS 2015 - WindTurbinePlaceable (Patch 1.3)

Script Dokumentation Übersicht

scripts/placeables/WindTurbinePlaceable.lua

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
3WindTurbinePlaceable = {};
4WindTurbinePlaceable_mt = Class(WindTurbinePlaceable, Placeable);
5
6InitStaticObjectClass(WindTurbinePlaceable, "WindTurbinePlaceable", ObjectIds.OBJECT_WIND_TURBINE_PLACEABLE);
7
8function 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;
22end;
23
24function WindTurbinePlaceable:delete()
25 unregisterObjectClassName(self);
26 g_currentMission.environment:removeHourChangeListener(self);
27 WindTurbinePlaceable:superClass().delete(self);
28end;
29
30function WindTurbinePlaceable:deleteFinal()
31 WindTurbinePlaceable:superClass().deleteFinal(self);
32end;
33
34function WindTurbinePlaceable:readStream(streamId, connection)
35 if connection:getIsServer() then
36 self.headRotation=Utils.readCompressedAngle(streamId);
37 end;
38 WindTurbinePlaceable:superClass().readStream(self, streamId, connection);
39end;
40
41function 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);
46end;
47
48--[[function WindTurbinePlaceable:readUpdateStream(streamId, timestamp, connection)
49 WindTurbinePlaceable:superClass().readStream(self, streamId, timestamp, connection);
50end;
51
52function WindTurbinePlaceable:writeUpdateStream(streamId, connection, dirtyMask)
53 WindTurbinePlaceable:superClass().writeUpdateStream(self, streamId, connection, dirtyMask);
54end;]]
55
56function 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;
75end;
76
77function 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;
90end;
91
92function WindTurbinePlaceable:finalizePlacement()
93 WindTurbinePlaceable:superClass().finalizePlacement(self);
94 g_currentMission.environment:addHourChangeListener(self);
95end
96
97function 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();
106end;
107
108function 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);
111end;
112
113function 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;
126end;
127
128function WindTurbinePlaceable:getSaveAttributesAndNodes(nodeIdent)
129 local attributes, nodes = WindTurbinePlaceable:superClass().getSaveAttributesAndNodes(self, nodeIdent);
130 attributes = attributes .. ' headRotation="'..self.headRotation..'"';
131 return attributes, nodes;
132end;
133
134function WindTurbinePlaceable:update(dt)
135 if self.rotationNode ~= 0 then
136 rotate(self.rotationNode, 0,0,-0.0025*dt);
137 end;
138end;
139
140function 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
145end
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
Script Dokumentation Übersicht