Sprache Deutsch Language English

Script Dokumentation LS 2015 - RecievingHopper (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/RecievingHopper.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-- RecievingHopper
3-- Class for all RecievingHopper
4--
5-- @author Manuel Leithner
6-- @date 16/04/14
7--
8-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
9
10RecievingHopper = {};
11
12function RecievingHopper.prerequisitesPresent(specializations)
13 return SpecializationUtil.hasSpecialization(Fillable, specializations);
14end;
15
16function RecievingHopper:load(xmlFile)
17 self.setFillLevel = Utils.appendedFunction(self.setFillLevel, RecievingHopper.setFillLevel);
18 self.onBoxTriggerCallback = RecievingHopper.onBoxTriggerCallback;
19 self.createBox = RecievingHopper.createBox;
20
21 local triggerId = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.tipTrigger#index"));
22 if triggerId ~= nil and triggerId ~= 0 then
23 self.tipTrigger = RecievingTipTrigger:new(self.isServer, self.isClient);
24 self.tipTrigger:load(triggerId, self);
25 end;
26
27 self.boxTriggerNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.boxTrigger#index"));
28 if self.boxTriggerNode ~= nil and self.isServer then
29 self.boxTrigger = addTrigger(self.boxTriggerNode, "onBoxTriggerCallback", self);
30 end;
31 self.isBoxFilling = false;
32 self.boxes = {};
33 local i=0;
34 while true do
35 local baseName = string.format("vehicle.boxTrigger.box(%d)", i);
36 if not hasXMLProperty(xmlFile, baseName) then
37 break;
38 end;
39
40 local fruitType = getXMLString(xmlFile, baseName.."#fruitType");
41 local filename = getXMLString(xmlFile, baseName.."#filename");
42 local fillType = Fillable.fillTypeNameToInt[fruitType];
43 if fillType ~= nil then
44 self.boxes[fillType] = filename;
45 else
46 print("Warning: invalid fruitType '"..fruitType.."'");
47 end;
48 i = i + 1;
49 end;
50
51 if self.isClient then
52 self.fillBoxScrollerNodes = Utils.loadScrollers(self.components, xmlFile, "vehicle.fillBoxScrollerNodes.fillBoxScrollerNode", {}, false);
53
54 -- fill particle systems
55 self.fillBoxParticleSystems = {};
56 local i = 0;
57 while true do
58 local key = string.format("vehicle.fillBoxParticleSystems.fillBoxParticleSystem(%d)", i);
59 local t = getXMLString(xmlFile, key .. "#type");
60 if t == nil then
61 break;
62 end;
63 local desc = FruitUtil.fruitTypes[t];
64 if desc ~= nil then
65 local currentPS = {};
66 Utils.loadParticleSystem(xmlFile, currentPS, key, self.components, false, nil, self.baseDirectory);
67 self.fillBoxParticleSystems[desc.index] = currentPS;
68 end;
69 i = i + 1;
70 end;
71 self.currentBoxFillParticleSystem = nil;
72 end;
73
74 self.litersPerMs = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.boxTrigger#litersPerMinute"), 2000) / 60 / 1000;
75 self.objectsInBoxPlace = 0;
76 self.timeUntilNextBox = 2000;
77 self.nextBoxWaitTime = 2000;
78 self.currentBox = nil;
79end;
80
81function RecievingHopper:delete()
82 if self.tipTrigger ~= nil then
83 self.tipTrigger:delete();
84 end
85
86 if self.isServer then
87 if self.boxTrigger ~= nil then
88 removeTrigger(self.boxTrigger);
89 end;
90 end;
91
92 if self.isClient then
93 for _,v in pairs(self.fillBoxParticleSystems) do
94 Utils.deleteParticleSystem(v);
95 end;
96 end;
97end;
98
99function RecievingHopper:readStream(streamId, connection)
100 if connection:getIsServer() then
101 self.isBoxFilling = streamReadBool(streamId);
102 end;
103end;
104
105function RecievingHopper:writeStream(streamId, connection)
106 if not connection:getIsServer() then
107 streamWriteBool(streamId, self.isBoxFilling);
108 end;
109end;
110
111function RecievingHopper:readUpdateStream(streamId, timestamp, connection)
112 if connection:getIsServer() then
113 self.isBoxFilling = streamReadBool(streamId);
114 end;
115end;
116
117function RecievingHopper:writeUpdateStream(streamId, connection, dirtyMask)
118 if not connection:getIsServer() then
119 streamWriteBool(streamId, self.isBoxFilling)
120 end;
121end;
122
123function RecievingHopper:mouseEvent(posX, posY, isDown, isUp, button)
124end;
125
126function RecievingHopper:keyEvent(unicode, sym, modifier, isDown)
127end;
128
129function RecievingHopper:update(dt)
130end;
131
132function RecievingHopper:updateTick(dt)
133 if self.isServer then
134 self.isBoxFilling = false;
135 if self.fillLevel > 0 then
136 if self.currentBox ~= nil then
137 if self.currentBox:getFillLevel() < self.currentBox:getCapacity() then
138 local delta = math.min(math.min(self.litersPerMs * dt, self.fillLevel), self.currentBox:getCapacity()-self.currentBox:getFillLevel());
139 self.currentBox:setFillLevel(self.currentBox:getFillLevel() + delta);
140 self:setFillLevel(self.fillLevel - delta, self.currentFillType);
141 self.isBoxFilling = true;
142 end;
143 else
144 if self.objectsInBoxPlace == 0 then
145 self.timeUntilNextBox = self.timeUntilNextBox - dt;
146 if self.timeUntilNextBox < 0 then
147 self:createBox();
148 self.timeUntilNextBox = self.nextBoxWaitTime;
149 end;
150 else
151 self.timeUntilNextBox = self.nextBoxWaitTime;
152 end;
153 end;
154 end;
155 end;
156
157 if self.isClient then
158 Utils.updateScrollers(self.fillBoxScrollerNodes, dt, self.isBoxFilling, self.isBoxFilling);
159 if self.currentBoxFillParticleSystem ~= nil then
160 Utils.setEmittingState(self.currentBoxFillParticleSystem, self.isBoxFilling);
161 end;
162 end;
163end;
164
165function RecievingHopper:draw()
166end;
167
168function RecievingHopper:onDetach()
169end;
170
171function RecievingHopper:setFillLevel(fillLevel)
172 if fillLevel > 0 and self.currentFillType then
173 if self.isClient then
174 local ps = self.currentBoxFillParticleSystem;
175 self.currentBoxFillParticleSystem = self.fillBoxParticleSystems[self.currentFillType];
176 if ps ~= nil and ps ~= self.currentBoxFillParticleSystem then
177 Utils.setEmittingState(ps, false);
178 end;
179 end;
180 end;
181end;
182
183function RecievingHopper:createBox()
184 if self.isServer then
185 local i3dFilename = Utils.getFilename(self.boxes[self.currentFillType], self.baseDirectory);
186 local x,y,z = getWorldTranslation(self.boxTriggerNode);
187 local rx,ry,rz = getWorldRotation(self.boxTriggerNode);
188 self.currentBox = FillablePallet:new(self.isServer, self.isClient);
189 self.currentBox:load(i3dFilename, x,y,z, rx,ry,rz);
190 end;
191end;
192
193function RecievingHopper:onBoxTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId)
194 if onEnter then
195 local object = g_currentMission:getNodeObject(otherShapeId);
196 if object ~= nil then
197 self.objectsInBoxPlace = self.objectsInBoxPlace + 1;
198 if self.currentBox == nil and object:isa(FillablePallet) and object:getFillType() == self.currentFillType and object:getFillLevel() < object:getCapacity() then
199 self.currentBox = object;
200 end;
201 end;
202 elseif onLeave then
203 local object = g_currentMission:getNodeObject(otherShapeId);
204 if object ~= nil then
205 self.objectsInBoxPlace = math.max(0, self.objectsInBoxPlace - 1);
206 end;
207 if object == self.currentBox then
208 self.currentBox = nil;
209 end;
210 end;
211end;
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