Sprache Deutsch Language English

Script Dokumentation LS 2015 - Cultivator (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/Cultivator.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-- Cultivator
3-- Class for all cultivators
4--
5-- @author Stefan Geiger
6-- @date 16/01/14
7--
8-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
9
10Cultivator = {};
11source("dataS/scripts/vehicles/specializations/CultivatorAreaEvent.lua");
12
13function Cultivator.initSpecialization()
14 WorkArea.registerAreaType("cultivator");
15end;
16
17function Cultivator.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(WorkArea, specializations);
19end;
20
21function Cultivator:preLoad(xmlFile)
22 self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, Cultivator.loadWorkAreaFromXML);
23end
24
25function Cultivator:load(xmlFile)
26
27 self.getDoGroundManipulation = Utils.overwrittenFunction(self.getDoGroundManipulation, Cultivator.getDoGroundManipulation);
28 self.doCheckSpeedLimit = Utils.overwrittenFunction(self.doCheckSpeedLimit, Cultivator.doCheckSpeedLimit);
29 self.getDirtMultiplier = Utils.overwrittenFunction(self.getDirtMultiplier, Cultivator.getDirtMultiplier);
30 self.getIsReadyToSpray = Utils.overwrittenFunction(self.getIsReadyToSpray, Cultivator.getIsReadyToSpray);
31
32 if hasXMLProperty(xmlFile, "vehicle.drum#index") then
33 print("Warning: vehicle.drum is no longer used, use vehicle.speedRotatingParts.speedRotatingPart\n");
34 end;
35
36 if next(self.groundReferenceNodes) == nil then
37 print("Warning: No ground reference nodes in "..self.configFileName);
38 end;
39
40 if self.isClient then
41 self.sampleCultivator = Utils.loadSample(xmlFile, {}, "vehicle.cultivatorSound", nil, self.baseDirectory);
42 end;
43
44 self.cultivatorDirectionNode = Utils.getNoNil(Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.cultivatorDirectionNode#index")), self.components[1].node);
45
46 self.onlyActiveWhenLowered = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.onlyActiveWhenLowered#value"), true);
47
48 self.aiTerrainDetailChannel1 = g_currentMission.ploughChannel;
49 self.aiTerrainDetailChannel2 = g_currentMission.sowingChannel;
50 self.aiTerrainDetailChannel3 = g_currentMission.sowingWidthChannel;
51
52 self.startActivationTimeout = 2000;
53 self.startActivationTime = 0;
54
55 self.cultivatorHasGroundContact = false;
56 self.doGroundManipulation = false;
57 self.cultivatorLimitToField = false;
58 self.cultivatorForceLimitToField = true;
59 self.lastCultivatorArea = 0;
60
61 self.isCultivatorSpeedLimitActive = false;
62
63 self.showFieldNotOwnedWarning = false;
64
65 self.cultivatorGroundContactFlag = self:getNextDirtyFlag();
66end;
67
68function Cultivator:delete()
69 if self.isClient then
70 Utils.deleteSample(self.sampleCultivator);
71 end;
72end;
73
74function Cultivator:readUpdateStream(streamId, timestamp, connection)
75 if connection:getIsServer() then
76 self.cultivatorHasGroundContact = streamReadBool(streamId);
77 self.showFieldNotOwnedWarning = streamReadBool(streamId);
78 end;
79end;
80
81function Cultivator:writeUpdateStream(streamId, connection, dirtyMask)
82 if not connection:getIsServer() then
83 streamWriteBool(streamId, self.cultivatorHasGroundContact);
84 streamWriteBool(streamId, self.showFieldNotOwnedWarning);
85 end;
86end;
87
88function Cultivator:mouseEvent(posX, posY, isDown, isUp, button)
89end;
90
91function Cultivator:keyEvent(unicode, sym, modifier, isDown)
92end;
93
94function Cultivator:update(dt)
95end;
96
97function Cultivator:updateTick(dt)
98 self.isCultivatorSpeedLimitActive = false;
99 if self:getIsActive() then
100 self.lastCultivatorArea = 0;
101 local showFieldNotOwnedWarning = false;
102
103 if self.isServer then
104 local hasGroundContact = self:getIsTypedWorkAreaActive(WorkArea.AREATYPE_CULTIVATOR);
105 if self.cultivatorHasGroundContact ~= hasGroundContact then
106 self:raiseDirtyFlags(self.cultivatorGroundContactFlag);
107 self.cultivatorHasGroundContact = hasGroundContact;
108 end;
109 end;
110 local hasGroundContact = self.cultivatorHasGroundContact;
111
112 self.doGroundManipulation = (hasGroundContact and (not self.onlyActiveWhenLowered or self:isLowered(false)) and self.startActivationTime <= g_currentMission.time);
113
114 local foldAnimTime = self.foldAnimTime;
115 if self.doGroundManipulation then
116 self.isCultivatorSpeedLimitActive = true;
117 if self.isServer then
118 local workAreasSend, showWarning, _ = self:getTypedNetworkAreas(WorkArea.AREATYPE_CULTIVATOR, true);
119 showFieldNotOwnedWarning = showWarning;
120
121 if table.getn(workAreasSend) > 0 then
122 local limitToField = self.cultivatorLimitToField or self.cultivatorForceLimitToField;
123 local limitGrassDestructionToField = self.cultivatorLimitToField or self.cultivatorForceLimitToField;
124 if not g_currentMission:getHasPermission("createFields", self:getOwner()) then
125 limitToField = true;
126 limitGrassDestructionToField = true;
127 end;
128
129 local dx,dy,dz = localDirectionToWorld(self.cultivatorDirectionNode, 0, 0, 1);
130 local angle = Utils.convertToDensityMapAngle(Utils.getYRotationFromDirection(dx, dz), g_currentMission.terrainDetailAngleMaxValue);
131
132 local realArea = CultivatorAreaEvent.runLocally(workAreasSend, limitToField, limitGrassDestructionToField, angle);
133 g_server:broadcastEvent(CultivatorAreaEvent:new(workAreasSend, limitToField, limitGrassDestructionToField, angle));
134
135 self.lastCultivatorArea = Utils.areaToHa(realArea, g_currentMission:getFruitPixelsToSqm()); -- 4096px are mapped to 2048m
136 g_currentMission.missionStats:updateStats("hectaresWorked", self.lastCultivatorArea);
137 end;
138 end;
139 g_currentMission.missionStats:updateStats("workingDuration", dt/(1000*60));
140 end
141
142 if self.isClient then
143 if self.doGroundManipulation and self:getLastSpeed() > 3 then
144 if self:getIsActiveForSound() then
145 Utils.playSample(self.sampleCultivator, 0, 0, nil);
146 end;
147 else
148 Utils.stopSample(self.sampleCultivator);
149 end;
150 end;
151
152 if self.isServer then
153 if showFieldNotOwnedWarning ~= self.showFieldNotOwnedWarning then
154 self.showFieldNotOwnedWarning = showFieldNotOwnedWarning;
155 self:raiseDirtyFlags(self.cultivatorGroundContactFlag);
156 end
157 end
158 end;
159
160end;
161
162function Cultivator:draw()
163 if self.showFieldNotOwnedWarning then
164 g_currentMission:showBlinkingWarning(g_i18n:getText("You_dont_own_this_field"));
165 end;
166end;
167
168function Cultivator:onAttach(attacherVehicle)
169 Cultivator.onActivate(self);
170 self.startActivationTime = g_currentMission.time + self.startActivationTimeout;
171end;
172
173function Cultivator:onDetach()
174 self.cultivatorLimitToField = false;
175end;
176
177function Cultivator:onEnter(isControlling)
178 if isControlling then
179 Cultivator.onActivate(self);
180 end;
181end;
182
183function Cultivator:onActivate()
184end;
185
186function Cultivator:onDeactivate()
187 self.showFieldNotOwnedWarning = false;
188end;
189
190function Cultivator:onDeactivateSounds()
191 if self.isClient then
192 Utils.stopSample(self.sampleCultivator, true);
193 end;
194end;
195
196function Cultivator:aiTurnOn()
197 self.cultivatorLimitToField = true;
198end;
199
200function Cultivator:aiTurnOff()
201 self.cultivatorLimitToField = false;
202end;
203
204function Cultivator:doCheckSpeedLimit(superFunc)
205 local parent = true;
206 if superFunc ~= nil then
207 parent = superFunc(self);
208 end
209
210 return parent and self.isCultivatorSpeedLimitActive;
211end;
212
213function Cultivator:getDoGroundManipulation(superFunc)
214 if not self.doGroundManipulation then
215 return false;
216 end;
217
218 if superFunc ~= nil then
219 return superFunc(self, speedRotatingPart);
220 end
221 return true;
222end;
223
224function Cultivator:getIsReadyToSpray(superFunc)
225 local isReadyToSpray = true;
226 if superFunc ~= nil then
227 isReadyToSpray = isReadyToSpray and superFunc(self);
228 end;
229
230 isReadyToSpray = isReadyToSpray and self.doGroundManipulation;
231
232 return isReadyToSpray;
233end;
234
235function Cultivator:getDirtMultiplier(superFunc)
236 local multiplier = 0;
237 if superFunc ~= nil then
238 multiplier = multiplier + superFunc(self);
239 end;
240
241 if self.doGroundManipulation then
242 multiplier = multiplier + self.workMultiplier * self:getLastSpeed() / self.speedLimit;
243 end;
244
245 return multiplier;
246end;
247
248function Cultivator:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key)
249 local retValue = true;
250 if superFunc ~= nil then
251 retValue = superFunc(self, workArea, xmlFile, key)
252 end
253
254 if workArea.type == WorkArea.AREATYPE_DEFAULT then
255 workArea.type = WorkArea.AREATYPE_CULTIVATOR;
256 end;
257
258 return retValue;
259end;
260
261function Cultivator.getDefaultSpeedLimit()
262 return 15;
263end;
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