Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- |
2 | -- ForageWagon |
3 | -- Class for all ForageWagons |
4 | -- |
5 | -- @author Stefan Geiger |
6 | -- @date 25/06/08 |
7 | -- |
8 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
9 | |
10 | ForageWagon = {}; |
11 | |
12 | source("dataS/scripts/vehicles/specializations/SetTurnedOnEvent.lua"); |
13 | source("dataS/scripts/vehicles/specializations/ForageWagonAreaEvent.lua"); |
14 | |
15 | function ForageWagon.initSpecialization() |
16 | WorkArea.registerAreaType("forageWagon"); |
17 | end; |
18 | |
19 | function ForageWagon.prerequisitesPresent(specializations) |
20 | return SpecializationUtil.hasSpecialization(Trailer, specializations) and SpecializationUtil.hasSpecialization(WorkArea, specializations) and SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations) and SpecializationUtil.hasSpecialization(Pickup, specializations); |
21 | end; |
22 | |
23 | function ForageWagon:preLoad(xmlFile) |
24 | self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, ForageWagon.loadWorkAreaFromXML); |
25 | self.loadSpeedRotatingPartFromXML = Utils.overwrittenFunction(self.loadSpeedRotatingPartFromXML, ForageWagon.loadSpeedRotatingPartFromXML); |
26 | end |
27 | |
28 | function ForageWagon:load(xmlFile) |
29 | |
30 | self.doCheckSpeedLimit = Utils.overwrittenFunction(self.doCheckSpeedLimit, ForageWagon.doCheckSpeedLimit); |
31 | self.getIsSpeedRotatingPartActive = Utils.overwrittenFunction(self.getIsSpeedRotatingPartActive, ForageWagon.getIsSpeedRotatingPartActive); |
32 | self.getTipScrollerSpeed = Utils.overwrittenFunction(self.getTipScrollerSpeed, ForageWagon.getTipScrollerSpeed); |
33 | |
34 | self.turnedOnTipScrollerSpeedFactor = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.turnedOnTipScrollerSpeedFactor#value"), 0.25); |
35 | |
36 | if self.isClient then |
37 | self.sampleForageWagon = Utils.loadSample(xmlFile, {}, "vehicle.forageWgnSound", nil, self.baseDirectory); |
38 | end; |
39 | |
40 | -- Backward compatibility: Convert non-windrow fill types to the correspoding windrow fill types |
41 | if Utils.getNoNil(getXMLBool(xmlFile, "vehicle.fillTypes#convertToWindrowFillType"), true) then |
42 | local fillTypesToAdd = {}; |
43 | for fillType, enabled in pairs(self.fillTypes) do |
44 | if fillType ~= Fillable.FILLTYPE_UNKNOWN and enabled then |
45 | local fruitType = FruitUtil.fillTypeToFruitType[fillType]; |
46 | if fruitType ~= nil and not FruitUtil.fillTypeIsWindrow[fillType] then |
47 | local windrowFillType = FruitUtil.fruitTypeToWindrowFillType[fruitType]; |
48 | if windrowFillType ~= nil and not self.fillTypes[windrowFillType] then |
49 | self.fillTypes[fillType] = nil; |
50 | table.insert(fillTypesToAdd, windrowFillType); |
51 | print("Warning: converted non-windrow fill type to windrow fill type in "..self.configFileName); |
52 | end |
53 | end |
54 | end |
55 | end |
56 | for _,fillType in pairs(fillTypesToAdd) do |
57 | self.fillTypes[fillType] = true; |
58 | end |
59 | end |
60 | |
61 | self.forageWagonTurnedOnRotationNodes = Utils.loadRotationNodes(xmlFile, {}, "vehicle.turnedOnRotationNodes.turnedOnRotationNode", "forageWagon", self.components); |
62 | |
63 | self.fillScale = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.fillScale#value"), 1); |
64 | self.isForageWagonSpeedLimitActive = false; |
65 | |
66 | self.lastForageWagonArea = 0; |
67 | |
68 | self.fillLevelIncreased = 0; |
69 | |
70 | self.forageWagonGroundFlag = self:getNextDirtyFlag(); |
71 | end; |
72 | |
73 | function ForageWagon:delete() |
74 | if self.isClient then |
75 | Utils.deleteSample(self.sampleForageWagon); |
76 | end; |
77 | end; |
78 | |
79 | function ForageWagon:readStream(streamId, connection) |
80 | end; |
81 | |
82 | function ForageWagon:writeStream(streamId, connection) |
83 | end; |
84 | |
85 | function ForageWagon:readUpdateStream(streamId, timestamp, connection) |
86 | end; |
87 | |
88 | function ForageWagon:writeUpdateStream(streamId, connection, dirtyMask) |
89 | end; |
90 | |
91 | function ForageWagon:mouseEvent(posX, posY, isDown, isUp, button) |
92 | end; |
93 | |
94 | function ForageWagon:keyEvent(unicode, sym, modifier, isDown) |
95 | end; |
96 | |
97 | function ForageWagon:update(dt) |
98 | if self.isClient then |
99 | Utils.updateRotationNodes(self, self.forageWagonTurnedOnRotationNodes, dt, self:getIsActive() and self.isTurnedOn ); |
100 | --Utils.updateScrollers(self.tipScrollers, dt*0.25, self:getIsActive() and self.isTurnedOn); |
101 | |
102 | if self:getIsActive() then |
103 | if self:getIsTurnedOn() then |
104 | if self.lastForageFillLevel ~= self:getFillLevel(self.currentFillType) then |
105 | self.lastForageFillLevel = self:getFillLevel(self.currentFillType); |
106 | self.lastForageFillTime = g_currentMission.time + 250; |
107 | end; |
108 | if self.lastForageFillTime > g_currentMission.time then |
109 | for i,fillVolume in pairs(self.fillVolumes) do |
110 | if fillVolume.scrollSpeedLoad[1] ~= 0 or fillVolume.scrollSpeedLoad[2] ~= 0 or fillVolume.scrollSpeedLoad[3] ~= 0 then |
111 | fillVolume.uvPosition[1] = fillVolume.uvPosition[1] + fillVolume.scrollSpeedLoad[1]*dt; |
112 | fillVolume.uvPosition[2] = fillVolume.uvPosition[2] + fillVolume.scrollSpeedLoad[2]*dt; |
113 | fillVolume.uvPosition[3] = fillVolume.uvPosition[3] + fillVolume.scrollSpeedLoad[3]*dt; |
114 | setShaderParameter(fillVolume.volume, "uvOffset", fillVolume.uvPosition[1], fillVolume.uvPosition[2], fillVolume.uvPosition[3], 0, false); |
115 | end; |
116 | end; |
117 | end; |
118 | end; |
119 | end; |
120 | end; |
121 | end; |
122 | |
123 | function ForageWagon:updateTick(dt) |
124 | self.isForageWagonSpeedLimitActive = false; |
125 | self.lastForageWagonArea = 0; |
126 | if self:getIsActive() then |
127 | if self:getIsTurnedOn() then |
128 | if self.fillLevel < self:getCapacity() then |
129 | if self:allowPickingUp() then |
130 | self.isForageWagonSpeedLimitActive = true; |
131 | if self.isServer then |
132 | local workAreasSend, _, _ = self:getTypedNetworkAreas(WorkArea.AREATYPE_FORAGEWAGON, false); |
133 | |
134 | if (table.getn(workAreasSend) > 0) then |
135 | local fruitTypeFix = false; |
136 | local fruitType = FruitUtil.FRUITTYPE_UNKNOWN; |
137 | if self.fillLevel > self:getCapacity()*self.fillTypeChangeThreshold and FruitUtil.fillTypeToFruitType[self.currentFillType] ~= nil and FruitUtil.fillTypeIsWindrow[self.currentFillType] then |
138 | fruitTypeFix = true; |
139 | fruitType = FruitUtil.fillTypeToFruitType[self.currentFillType]; |
140 | end |
141 | local area, usedFruitType = ForageWagonAreaEvent.runLocally(workAreasSend, self.fillTypes, fruitTypeFix, fruitType); |
142 | if area > 0 then |
143 | self.lastForageWagonArea = area; |
144 | |
145 | local pixelToSqm = g_currentMission:getFruitPixelsToSqm(); -- 4096px are mapped to 2048m |
146 | local literPerSqm = FruitUtil.getFillTypeLiterPerSqm(FruitUtil.fruitTypeToWindrowFillType[usedFruitType], 1); |
147 | local sqm = area*pixelToSqm; |
148 | |
149 | local deltaLevel = sqm*literPerSqm * self.fillScale; |
150 | |
151 | -- |
152 | local x,y,z = getWorldTranslation(self.fillVolumeLoadInfo.node); |
153 | local d1x,d1y,d1z = localDirectionToWorld(self.fillVolumeLoadInfo.node, self.fillVolumeLoadInfo.width,0,0); |
154 | local d2x,d2y,d2z = localDirectionToWorld(self.fillVolumeLoadInfo.node, 0,0,self.fillVolumeLoadInfo.length); |
155 | local fillSourceStruct = {x=x,y=y,z=z, d1x=d1x,d1y=d1y,d1z=d1z, d2x=d2x,d2y=d2y,d2z=d2z}; |
156 | self:setFillLevel(self.fillLevel+deltaLevel, FruitUtil.fruitTypeToWindrowFillType[usedFruitType], true, fillSourceStruct); |
157 | |
158 | g_server:broadcastEvent(ForageWagonAreaEvent:new(workAreasSend, usedFruitType)); |
159 | end; |
160 | end; |
161 | end; |
162 | end; |
163 | elseif self:getIsTurnedOn() then |
164 | self:setIsTurnedOn(false); |
165 | if self.setPickupState ~= nil then |
166 | self:setPickupState(false); |
167 | end; |
168 | end |
169 | |
170 | if self.isClient and self:getIsActiveForSound() and self:getIsTurnedOn() then |
171 | Utils.playSample(self.sampleForageWagon, 0, 0, nil); |
172 | end; |
173 | end; |
174 | if self.lastFillLevel == nil then |
175 | self.lastFillLevel = self.fillLevel; |
176 | end; |
177 | self.fillLevelIncreased = self.fillLevel > self.lastFillLevel; |
178 | self.lastFillLevel = self.fillLevel; |
179 | end; |
180 | end; |
181 | |
182 | function ForageWagon:draw() |
183 | end; |
184 | |
185 | function ForageWagon:onTurnedOff(noEventSend) |
186 | ForageWagon.onDeactivateSounds(self); |
187 | end; |
188 | |
189 | function ForageWagon:onDeactivateSounds() |
190 | if self.isClient then |
191 | Utils.stopSample(self.sampleForageWagon, true); |
192 | end; |
193 | end; |
194 | |
195 | function ForageWagon:doCheckSpeedLimit(superFunc) |
196 | local parent = true; |
197 | if superFunc ~= nil then |
198 | parent = superFunc(self); |
199 | end |
200 | |
201 | return parent and self.isForageWagonSpeedLimitActive; |
202 | end; |
203 | |
204 | function ForageWagon:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
205 | local retValue = true; |
206 | if superFunc ~= nil then |
207 | retValue = superFunc(self, workArea, xmlFile, key) |
208 | end |
209 | |
210 | if workArea.type == WorkArea.AREATYPE_DEFAULT then |
211 | workArea.type = WorkArea.AREATYPE_FORAGEWAGON; |
212 | end; |
213 | |
214 | return retValue; |
215 | end; |
216 | |
217 | function ForageWagon.getDefaultSpeedLimit() |
218 | return 20; |
219 | end; |
220 | |
221 | function ForageWagon:loadSpeedRotatingPartFromXML(superFunc, speedRotatingPart, xmlFile, key) |
222 | if superFunc ~= nil then |
223 | if not superFunc(self, speedRotatingPart, xmlFile, key) then |
224 | return false; |
225 | end |
226 | end |
227 | |
228 | speedRotatingPart.rotateOnlyIfFillLevelIncreased = Utils.getNoNil(getXMLBool(xmlFile, key .. "#rotateOnlyIfFillLevelIncreased"), false); |
229 | |
230 | return true; |
231 | end |
232 | |
233 | function ForageWagon:getIsSpeedRotatingPartActive(superFunc, speedRotatingPart) |
234 | if speedRotatingPart.rotateOnlyIfFillLevelIncreased ~= nil then |
235 | if speedRotatingPart.rotateOnlyIfFillLevelIncreased and not self.fillLevelIncreased then |
236 | return false; |
237 | end; |
238 | end; |
239 | |
240 | if superFunc ~= nil then |
241 | return superFunc(self, speedRotatingPart); |
242 | end |
243 | return true; |
244 | end; |
245 | |
246 | function ForageWagon:getTipScrollerSpeed(superFunc) |
247 | local value = 0; |
248 | if self:getIsTurnedOn() then |
249 | value = self.turnedOnTipScrollerSpeedFactor; |
250 | end; |
251 | return math.max(value, superFunc(self)); |
252 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de