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 | |
10 | source("dataS/scripts/vehicles/specializations/SetTurnedOnEvent.lua"); |
11 | source("dataS/scripts/vehicles/specializations/FruitPreparerAreaEvent.lua"); |
12 | |
13 | FruitPreparer = {}; |
14 | |
15 | function FruitPreparer.initSpecialization() |
16 | WorkArea.registerAreaType("fruitPreparer"); |
17 | end; |
18 | |
19 | function FruitPreparer.prerequisitesPresent(specializations) |
20 | return SpecializationUtil.hasSpecialization(WorkArea, specializations) and SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations); |
21 | end; |
22 | |
23 | function FruitPreparer:preLoad(xmlFile) |
24 | self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, FruitPreparer.loadWorkAreaFromXML); |
25 | end |
26 | |
27 | function 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; |
60 | end |
61 | |
62 | function FruitPreparer:delete() |
63 | if self.isClient then |
64 | Utils.deleteSample(self.sampleFruitPreparer); |
65 | end; |
66 | end |
67 | |
68 | function FruitPreparer:mouseEvent(posX, posY, isDown, isUp, button) |
69 | end |
70 | |
71 | function FruitPreparer:keyEvent(unicode, sym, modifier, isDown) |
72 | end |
73 | |
74 | function FruitPreparer:update(dt) |
75 | if self.isClient then |
76 | Utils.updateRotationNodes(self, self.fruitPreparerTurnedOnRotationNodes, dt, self:getIsActive() and self:getIsTurnedOn() ); |
77 | end; |
78 | end |
79 | |
80 | function 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 |
123 | end |
124 | |
125 | function FruitPreparer:draw() |
126 | end |
127 | |
128 | function FruitPreparer:onDeactivateSounds() |
129 | if self.isClient then |
130 | Utils.stopSample(self.sampleFruitPreparer, true); |
131 | end; |
132 | end |
133 | |
134 | function 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; |
144 | end; |
145 | |
146 | function FruitPreparer:onTurnedOn(noEventSend) |
147 | if self.turnOnAnimation ~= nil and self.playAnimation ~= nil then |
148 | self:playAnimation(self.turnOnAnimation, self.turnOnAnimationSpeed, nil, true); |
149 | end; |
150 | end; |
151 | |
152 | function 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); |
158 | end; |
159 | |
160 | function FruitPreparer:aiTurnOn() |
161 | self:setIsTurnedOn(true, true); |
162 | end; |
163 | |
164 | function FruitPreparer:aiLower() |
165 | self:setIsTurnedOn(true, true); |
166 | end; |
167 | |
168 | function FruitPreparer:aiRaise() |
169 | self:setIsTurnedOn(false, true); |
170 | end; |
171 | |
172 | function 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; |
179 | end; |
180 | |
181 | function 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; |
205 | end; |
206 | |
207 | function 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; |
216 | end; |
217 | |
218 | function FruitPreparer.getDefaultSpeedLimit() |
219 | return 15; |
220 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de