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