Sprache Deutsch Language English

Script Dokumentation LS 2015 - FruitPreparer (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/FruitPreparer.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-- FruitPreparer
3-- This is the specialization for tool that prepare the fruits for harvesting. E.g. potato haulm toppers and sugar beet defoliators
4--
5-- @author Stefan Geiger
6-- @date 10/07/12
7--
8-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
9
10source("dataS/scripts/vehicles/specializations/SetTurnedOnEvent.lua");
11source("dataS/scripts/vehicles/specializations/FruitPreparerAreaEvent.lua");
12
13FruitPreparer = {};
14
15function FruitPreparer.initSpecialization()
16 WorkArea.registerAreaType("fruitPreparer");
17end;
18
19function FruitPreparer.prerequisitesPresent(specializations)
20 return SpecializationUtil.hasSpecialization(WorkArea, specializations) and SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations);
21end;
22
23function FruitPreparer:preLoad(xmlFile)
24 self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, FruitPreparer.loadWorkAreaFromXML);
25end
26
27function FruitPreparer:load(xmlFile)
28
29 self.getDoGroundManipulation = Utils.overwrittenFunction(self.getDoGroundManipulation, FruitPreparer.getDoGroundManipulation);
30 self.doCheckSpeedLimit = Utils.overwrittenFunction(self.doCheckSpeedLimit, FruitPreparer.doCheckSpeedLimit);
31 self.getIsTurnedOnAllowed = Utils.overwrittenFunction(self.getIsTurnedOnAllowed, FruitPreparer.getIsTurnedOnAllowed);
32
33 if self.isClient then
34 self.sampleFruitPreparer = Utils.loadSample(xmlFile, {}, "vehicle.fruitPreparerSound", nil, self.baseDirectory);
35 end;
36
37 self.fruitPreparerGroundReferenceThreshold = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.fruitPreparerGroundReferenceNode#threshold"), 0.2);
38 self.fruitPreparerGroundReferenceNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.fruitPreparerGroundReferenceNode#index"));
39
40 self.fruitPreparerFruitType = FruitUtil.FRUITTYPE_UNKNOWN;
41 local fruitType = getXMLString(xmlFile, "vehicle.fruitPreparer#fruitType");
42 if fruitType ~= nil then
43 local desc = FruitUtil.fruitTypes[fruitType];
44 if desc ~= nil then
45 self.fruitPreparerFruitType = desc.index;
46 self.aiRequiredFruitType = desc.index;
47 self.aiRequiredMinGrowthState = desc.minPreparingGrowthState;
48 self.aiRequiredMaxGrowthState = desc.maxPreparingGrowthState;
49 end
50 end
51
52 self.fruitPreparerTurnedOnRotationNodes = Utils.loadRotationNodes(xmlFile, {}, "vehicle.turnedOnRotationNodes.turnedOnRotationNode", "fruitPreparer", self.components);
53
54 self.turnOnAnimation = getXMLString(xmlFile, "vehicle.turnOnAnimation#name");
55 self.turnOnAnimationSpeed = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.turnOnAnimation#speed"), 1);
56
57 self.fruitPreparerOnlyActiveWhenLowered = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.fruitPreparerOnlyActiveWhenLowered#value"), true);
58 self.isPreparerSpeedLimitActive = false;
59 self.areFruitPreparerParticlesActive = false;
60end
61
62function FruitPreparer:delete()
63 if self.isClient then
64 Utils.deleteSample(self.sampleFruitPreparer);
65 end;
66end
67
68function FruitPreparer:mouseEvent(posX, posY, isDown, isUp, button)
69end
70
71function FruitPreparer:keyEvent(unicode, sym, modifier, isDown)
72end
73
74function FruitPreparer:update(dt)
75 if self.isClient then
76 Utils.updateRotationNodes(self, self.fruitPreparerTurnedOnRotationNodes, dt, self:getIsActive() and self:getIsTurnedOn() );
77 end;
78end
79
80function FruitPreparer:updateTick(dt)
81 self.isPreparerSpeedLimitActive = false;
82 self.areFruitPreparerParticlesActive = false;
83 if self.isActive then
84 if (self.isThreshing or self:getIsTurnedOn()) and self.fruitPreparerFruitType ~= FruitUtil.FRUITTYPE_UNKNOWN then
85 local isTypedWorkAreaActive, typedWorkAreas = self:getIsTypedWorkAreaActive(WorkArea.AREATYPE_FRUITPREPARER);
86 local fruitPreparerDoGroundManipulation = (not self.fruitPreparerOnlyActiveWhenLowered or self:isLowered(true));
87 if fruitPreparerDoGroundManipulation then
88 fruitPreparerDoGroundManipulation = isTypedWorkAreaActive;
89 end;
90 if fruitPreparerDoGroundManipulation then
91 self.isPreparerSpeedLimitActive = true;
92 if self.isServer then
93 local numAreasSend = 0;
94 local areasSend = self.fruitPreparerAreasSend;
95 for _,area in pairs(typedWorkAreas) do
96 if self:getIsWorkAreaActive(area) then
97 numAreasSend = numAreasSend + 1;
98 areasSend[numAreasSend].x,_,areasSend[numAreasSend].z = getWorldTranslation(area.start);
99 areasSend[numAreasSend].x1,_,areasSend[numAreasSend].z1 = getWorldTranslation(area.width);
100 areasSend[numAreasSend].x2,_,areasSend[numAreasSend].z2 = getWorldTranslation(area.height);
101 areasSend[numAreasSend].hasSeparateDropArea = (area.dropStart ~= nil);
102 if areasSend[numAreasSend].hasSeparateDropArea then
103 areasSend[numAreasSend].dx,_,areasSend[numAreasSend].dz = getWorldTranslation(area.dropStart);
104 areasSend[numAreasSend].dx1,_,areasSend[numAreasSend].dz1 = getWorldTranslation(area.dropWidth);
105 areasSend[numAreasSend].dx2,_,areasSend[numAreasSend].dz2 = getWorldTranslation(area.dropHeight);
106 end
107 end
108 end
109 if numAreasSend > 0 then
110 numAreasSend = FruitPreparerAreaEvent.runLocally(areasSend, numAreasSend, self.fruitPreparerFruitType);
111 if numAreasSend > 0 then
112 self.areFruitPreparerParticlesActive = true;
113 g_server:broadcastEvent(FruitPreparerAreaEvent:new(areasSend, numAreasSend, self.fruitPreparerFruitType));
114 end
115 end
116 end
117 end
118 if self.isClient and self:getIsActiveForSound() then
119 Utils.playSample(self.sampleFruitPreparer, 0, 0, nil);
120 end
121 end
122 end
123end
124
125function FruitPreparer:draw()
126end
127
128function FruitPreparer:onDeactivateSounds()
129 if self.isClient then
130 Utils.stopSample(self.sampleFruitPreparer, true);
131 end;
132end
133
134function FruitPreparer:getIsTurnedOnAllowed(superFunc, isTurnedOn)
135 if isTurnedOn and self.isThreshing ~= nil then
136 return false;
137 end;
138
139 if superFunc ~= nil then
140 return superFunc(self, isTurnedOn);
141 end
142
143 return true;
144end;
145
146function FruitPreparer:onTurnedOn(noEventSend)
147 if self.turnOnAnimation ~= nil and self.playAnimation ~= nil then
148 self:playAnimation(self.turnOnAnimation, self.turnOnAnimationSpeed, nil, true);
149 end;
150end;
151
152function FruitPreparer:onTurnedOff(noEventSend)
153 if self.turnOnAnimation ~= nil and self.playAnimation ~= nil then
154 self:playAnimation(self.turnOnAnimation, -self.turnOnAnimationSpeed, nil, true);
155 end;
156
157 FruitPreparer.onDeactivateSounds(self);
158end;
159
160function FruitPreparer:aiTurnOn()
161 self:setIsTurnedOn(true, true);
162end;
163
164function FruitPreparer:aiLower()
165 self:setIsTurnedOn(true, true);
166end;
167
168function FruitPreparer:aiRaise()
169 self:setIsTurnedOn(false, true);
170end;
171
172function FruitPreparer:doCheckSpeedLimit(superFunc)
173 local parent = true;
174 if superFunc ~= nil then
175 parent = superFunc(self);
176 end
177
178 return parent and self.isPreparerSpeedLimitActive;
179end;
180
181function FruitPreparer:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key)
182 local retValue = true;
183 if superFunc ~= nil then
184 retValue = superFunc(self, workArea, xmlFile, key)
185 end
186
187 if workArea.type == WorkArea.AREATYPE_FRUITPREPARER then
188 local dropStart = Utils.indexToObject(self.components, getXMLString(xmlFile, key .. "#dropStartIndex"));
189 local dropWidth = Utils.indexToObject(self.components, getXMLString(xmlFile, key .. "#dropWidthIndex"));
190 local dropHeight = Utils.indexToObject(self.components, getXMLString(xmlFile, key .. "#dropHeightIndex"));
191
192 if dropStart ~= nil and dropWidth ~= nil and dropHeight ~= nil then
193 workArea.dropStart = dropStart;
194 workArea.dropWidth = dropWidth;
195 workArea.dropHeight = dropHeight;
196 end
197
198 if self.fruitPreparerAreasSend == nil then
199 self.fruitPreparerAreasSend = {};
200 end;
201 table.insert(self.fruitPreparerAreasSend, {});
202 end;
203
204 return retValue;
205end;
206
207function FruitPreparer:getDoGroundManipulation(superFunc)
208 if not self.areFruitPreparerParticlesActive then
209 return false;
210 end;
211
212 if superFunc ~= nil then
213 return superFunc(self, speedRotatingPart);
214 end
215 return true;
216end;
217
218function FruitPreparer.getDefaultSpeedLimit()
219 return 15;
220end;
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