Sprache Deutsch Language English

Script Dokumentation LS 2015 - Tedder (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/Tedder.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1--
2-- Tedder
3-- Class for all Tedders
4-- Note: the rotor animation is not perfectly synchronized, thus do not attach any gameplay relevant stuff to the rotor animation
5--
6-- @author Stefan Geiger
7-- @date 11/05/08
8--
9-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
10
11Tedder = {};
12source("dataS/scripts/vehicles/specializations/SetTurnedOnEvent.lua");
13source("dataS/scripts/vehicles/specializations/TedderAreaEvent.lua");
14
15function Tedder.initSpecialization()
16 WorkArea.registerAreaType("tedder");
17 WorkArea.registerAreaType("tedderDrop");
18end;
19
20function Tedder.prerequisitesPresent(specializations)
21 return SpecializationUtil.hasSpecialization(WorkArea, specializations) and SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations);
22end;
23
24function Tedder:preLoad(xmlFile)
25 self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, Tedder.loadWorkAreaFromXML);
26end
27
28function Tedder:load(xmlFile)
29
30 self.getDirtMultiplier = Utils.overwrittenFunction(self.getDirtMultiplier, Tedder.getDirtMultiplier);
31 self.doCheckSpeedLimit = Utils.overwrittenFunction(self.doCheckSpeedLimit, Tedder.doCheckSpeedLimit);
32
33 self.tedderTurnedOnRotationNodes = Utils.loadRotationNodes(xmlFile, {}, "vehicle.turnedOnRotationNodes.turnedOnRotationNode", "tedder", self.components);
34
35 if hasXMLProperty(xmlFile, "vehicle.rotors") then
36 print("Warning: vehicle.rotors are not supported anymore, use vehicle.turnedOnRotationNodes.turnedOnRotationNode (type: tedder) instead");
37 end;
38
39 local numTedderDropAreas = table.getn(self:getTypedWorkAreas(WorkArea.AREATYPE_TEDDERDROP));
40 if numTedderDropAreas == 0 then
41 print("Warning: No drop work areas specified in '"..self.configFileName.."'");
42 else
43 if numTedderDropAreas ~= 1 and numTedderDropAreas ~= table.getn(self:getTypedWorkAreas(WorkArea.AREATYPE_TEDDER)) then
44 print("Warning: Number of work areas and drop work areas should be equal in '"..self.configFileName.."'");
45 end;
46 end;
47
48 self.grassParticleSystems = {};
49 local i=0;
50 while true do
51 local baseName = string.format("vehicle.grassParticleSystems.grassParticleSystem(%d)", i);
52
53 local particleSystem = {};
54 particleSystem.ps = {};
55 local ps = Utils.loadParticleSystem(xmlFile, particleSystem.ps, baseName, self.components, false, nil, self.baseDirectory)
56 if ps == nil then
57 break;
58 end;
59 particleSystem.disableTime = 0;
60 particleSystem.isEnabled = false;
61 table.insert(self.grassParticleSystems, particleSystem);
62 i = i+1;
63 end;
64
65 if self.isClient then
66 self.sampleTedder = Utils.loadSample(xmlFile, {}, "vehicle.tedderSound", nil, self.baseDirectory);
67 end;
68
69 self.isTedderSpeedLimitActive = false;
70
71 self.tedderParticleSystemFlag = self:getNextDirtyFlag();
72end;
73
74function Tedder:delete()
75
76 for k,v in pairs(self.grassParticleSystems) do
77 Utils.deleteParticleSystem(v.ps);
78 end;
79
80 if self.isClient then
81 Utils.deleteSample(self.sampleTedder);
82 end;
83end;
84
85function Tedder:readStream(streamId, connection)
86 for k,v in ipairs(self.grassParticleSystems) do
87 local enabled = streamReadBool(streamId);
88 Utils.setEmittingState(v.ps, enabled);
89 end;
90end;
91
92function Tedder:writeStream(streamId, connection)
93 for k,v in ipairs(self.grassParticleSystems) do
94 streamWriteBool(streamId, v.isEnabled);
95 end;
96end;
97
98function Tedder:readUpdateStream(streamId, timestamp, connection)
99 if connection:getIsServer() then
100 local hasUpdate = streamReadBool(streamId);
101 if hasUpdate then
102 for k,v in ipairs(self.grassParticleSystems) do
103 local enabled = streamReadBool(streamId);
104 Utils.setEmittingState(v.ps, enabled);
105 end;
106 end;
107 end;
108end;
109
110function Tedder:writeUpdateStream(streamId, connection, dirtyMask)
111 if not connection:getIsServer() then
112 if bitAND(dirtyMask, self.tedderParticleSystemFlag) ~= 0 then
113 streamWriteBool(streamId, true);
114 for k,v in ipairs(self.grassParticleSystems) do
115 streamWriteBool(streamId, v.isEnabled);
116 end;
117 else
118 streamWriteBool(streamId, false);
119 end;
120 end;
121end;
122
123function Tedder:mouseEvent(posX, posY, isDown, isUp, button)
124end;
125
126function Tedder:keyEvent(unicode, sym, modifier, isDown)
127end;
128
129function Tedder:update(dt)
130 if self.isClient then
131 Utils.updateRotationNodes(self, self.tedderTurnedOnRotationNodes, dt, self:getIsActive() and self:getIsTurnedOn());
132 end;
133end;
134
135function Tedder:updateTick(dt)
136 self.isTedderSpeedLimitActive = false;
137 self.isWorking = false;
138 if self:getIsActive() then
139 local hasGroundContact, typedWorkAreas = self:getIsTypedWorkAreaActive(WorkArea.AREATYPE_TEDDER);
140 self.hasGroundContact = hasGroundContact;
141
142 if self.hasGroundContact then
143 local foldAnimTime = self.foldAnimTime;
144 if self:getIsTurnedOn() then
145 self.isTedderSpeedLimitActive = true;
146 if self.isServer then
147 local workAreasSend = {};
148 local typedWorkAreasDrop = self:getTypedWorkAreas(WorkArea.AREATYPE_TEDDERDROP);
149 for k, workArea in pairs(typedWorkAreas) do
150 if self:getIsWorkAreaActive(workArea) then
151 local x,y,z = getWorldTranslation(workArea.start);
152 local x1,y1,z1 = getWorldTranslation(workArea.width);
153 local x2,y2,z2 = getWorldTranslation(workArea.height);
154
155 local dropArea = typedWorkAreasDrop[workArea.dropAreaIndex];
156 local dx,dy,dz = getWorldTranslation(dropArea.start);
157 local dx1,dy1,dz1 = getWorldTranslation(dropArea.width);
158 local dx2,dy2,dz2 = getWorldTranslation(dropArea.height);
159
160 table.insert(workAreasSend, {x,z, x1,z1, x2,z2, dx,dz, dx1,dz1, dx2,dz2, 0, k});
161 end;
162 end;
163 if (table.getn(workAreasSend) > 0) then
164 local workAreasSend, bitType = TedderAreaEvent.runLocally(workAreasSend, self.accumulatedWorkAreaValues);
165 if (table.getn(workAreasSend) > 0) then
166 self.isWorking = true;
167 if self:getLastSpeed(true) > 0.5 then
168 for i=1, table.getn(workAreasSend) do
169 local workArea = typedWorkAreas[workAreasSend[i][14]];
170 if workArea.grassParticleSystemIndex ~= nil then
171 local ps = self.grassParticleSystems[workArea.grassParticleSystemIndex+1];
172 if ps ~= nil then
173 ps.disableTime = g_currentMission.time + 300;
174 if not ps.isEnabled then
175 ps.isEnabled = true;
176 self:raiseDirtyFlags(self.tedderParticleSystemFlag);
177 if self.isClient then
178 Utils.setEmittingState(ps.ps, true);
179 end;
180 end;
181 end;
182 end;
183 end;
184 end;
185 g_server:broadcastEvent(TedderAreaEvent:new(workAreasSend, bitType));
186 end;
187 end;
188 end;
189 end;
190 end;
191 if self.isServer then
192 for k,v in pairs(self.grassParticleSystems) do
193 if g_currentMission.time > v.disableTime then
194 if v.isEnabled then
195 v.isEnabled = false;
196 self:raiseDirtyFlags(self.tedderParticleSystemFlag);
197 if self.isClient then
198 Utils.setEmittingState(v.ps, false);
199 end;
200 end;
201 end;
202 end;
203 end;
204
205 if self:getIsTurnedOn() then
206 if self.isClient and self:getIsActiveForSound() then
207 Utils.playSample(self.sampleTedder, 0, 0, nil);
208 end;
209 end;
210
211 end;
212end;
213
214function Tedder:draw()
215end;
216
217function Tedder:onDeactivate()
218 if self.isClient then
219 for k,v in pairs(self.grassParticleSystems) do
220 v.isEnabled = false;
221 Utils.setEmittingState(v.ps, false);
222 end;
223 end;
224end;
225
226function Tedder:onDeactivateSounds()
227 if self.isClient then
228 Utils.stopSample(self.sampleTedder, true);
229 end;
230end;
231
232function Tedder:onTurnedOff(noEventSend)
233 Tedder.onDeactivateSounds(self)
234end;
235
236function Tedder:getDirtMultiplier(superFunc)
237 local multiplier = 0;
238 if superFunc ~= nil then
239 multiplier = multiplier + superFunc(self);
240 end;
241
242 if self.isWorking then -- ToDo: sync self.isWorking for MP or dismiss ?
243 multiplier = multiplier + self.workMultiplier * self:getLastSpeed() / self.speedLimit;
244 end;
245
246 return multiplier;
247end;
248
249function Tedder:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key)
250 local retValue = true;
251 if superFunc ~= nil then
252 retValue = superFunc(self, workArea, xmlFile, key)
253 end
254
255 if workArea.type == WorkArea.AREATYPE_DEFAULT then
256 workArea.type = WorkArea.AREATYPE_TEDDER;
257 end;
258
259 if workArea.type == WorkArea.AREATYPE_TEDDER then
260 workArea.grassParticleSystemIndex = getXMLInt(xmlFile, key .. "#particleSystemIndex");
261 workArea.dropAreaIndex = Utils.getNoNil(getXMLInt(xmlFile, key .. "#dropAreaIndex"), 0) + 1;
262
263 if self.accumulatedWorkAreaValues == nil then
264 self.accumulatedWorkAreaValues = {};
265 end;
266 self.accumulatedWorkAreaValues[table.getn(self.accumulatedWorkAreaValues)+1] = 0;
267 end;
268
269 return retValue;
270end;
271
272function Tedder:doCheckSpeedLimit(superFunc)
273 local parent = true;
274 if superFunc ~= nil then
275 parent = superFunc(self);
276 end
277
278 return parent and self.isTedderSpeedLimitActive;
279end;
280
281function Tedder.getDefaultSpeedLimit()
282 return 15;
283end;
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