Sprache Deutsch Language English

Script Dokumentation LS 2015 - FuelTrailer (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/FuelTrailer.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-- FuelTrailer
3--
4-- @author Stefan Geiger
5-- @date 08/10/10
6--
7-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
8
9FuelTrailer = {};
10
11function FuelTrailer.prerequisitesPresent(specializations)
12 return not SpecializationUtil.hasSpecialization(Motorized, specializations) and SpecializationUtil.hasSpecialization(Fillable, specializations);
13end;
14
15function FuelTrailer:load(xmlFile)
16
17 self.setIsFuelFilling = SpecializationUtil.callSpecializationsFunction("setIsFuelFilling");
18 self.addFuelFillTrigger = FuelTrailer.addFuelFillTrigger;
19 self.removeFuelFillTrigger = FuelTrailer.removeFuelFillTrigger;
20
21 self.fuelTrailerFillActivatable = FuelTrailerFillActivatable:new(self);
22
23 self.fuelFillTriggers = {};
24 self.isFuelFilling = false;
25
26 self.fuelFillLitersPerSecond = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.fuelFillLitersPerSecond"), 50);
27
28 local gasStationTriggerNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.gasStationTrigger#index"));
29
30 if gasStationTriggerNode ~= nil then
31 self.gasStationTrigger = GasStation:new(gasStationTriggerNode, self);
32 end;
33
34 if self.isClient then
35 self.sampleRefuel = Utils.loadSample(xmlFile, {}, "vehicle.refuelSound", "$data/maps/sounds/refuel.wav", self.baseDirectory, self.components[1].node);
36 end;
37end;
38
39function FuelTrailer:delete()
40 for _, trigger in pairs(self.fuelFillTriggers) do
41 trigger:onVehicleDeleted(self);
42 end
43 g_currentMission:removeActivatableObject(self.fuelTrailerFillActivatable);
44 if self.gasStationTrigger ~= nil then
45 self.gasStationTrigger:delete();
46 self.gasStationTrigger = nil;
47 end;
48 if self.isClient then
49 Utils.deleteSample(self.sampleRefuel);
50 end;
51end;
52
53function FuelTrailer:mouseEvent(posX, posY, isDown, isUp, button)
54end;
55
56function FuelTrailer:keyEvent(unicode, sym, modifier, isDown)
57end;
58
59function FuelTrailer:readStream(streamId, connection)
60 local isFuelFilling = streamReadBool(streamId);
61 self:setIsFuelFilling(isFuelFilling, true);
62end;
63
64function FuelTrailer:writeStream(streamId, connection)
65 streamWriteBool(streamId, self.isFuelFilling);
66end;
67
68function FuelTrailer:readUpdateStream(streamId, timestamp, connection)
69end;
70
71function FuelTrailer:writeUpdateStream(streamId, connection, dirtyMask)
72end;
73
74function FuelTrailer:update(dt)
75end;
76
77function FuelTrailer:updateTick(dt)
78
79 if self.isServer and self.isFuelFilling then
80 local delta = 0;
81 if self.fuelFillTrigger ~= nil then
82 delta = self.fuelFillLitersPerSecond*dt*0.001;
83 delta = self.fuelFillTrigger:fillFuel(self, delta);
84 end
85
86 if delta <= 0 then
87 self:setIsFuelFilling(false);
88 end
89 end
90end;
91
92function FuelTrailer:draw()
93 if self.isClient then
94 if self.fillLevel <= 0 and self:getCapacity() ~= 0 then
95 g_currentMission:addExtraPrintText(g_i18n:getText("FirstFillTheTool"));
96 end;
97 end
98end;
99
100function FuelTrailer:setIsFuelFilling(isFilling, noEventSend)
101 if isFilling ~= self.isFuelFilling then
102 if noEventSend == nil or noEventSend == false then
103 if g_server ~= nil then
104 g_server:broadcastEvent(SteerableToggleRefuelEvent:new(self, isFilling), nil, nil, self);
105 else
106 g_client:getServerConnection():sendEvent(SteerableToggleRefuelEvent:new(self, isFilling));
107 end;
108 end;
109 self.isFuelFilling = isFilling;
110 if isFilling then
111 -- find the first trigger which is activable
112 self.fuelFillTrigger = nil;
113 for i=1, table.getn(self.fuelFillTriggers) do
114 local trigger = self.fuelFillTriggers[i];
115 if trigger:getIsActivatable(self) then
116 self.fuelFillTrigger = trigger;
117 break;
118 end;
119 end;
120 end
121 if self.isClient and self.sampleRefuel ~= nil then
122 if isFilling then
123 Utils.play3DSample(self.sampleRefuel);
124 else
125 Utils.stop3DSample(self.sampleRefuel);
126 end;
127 end;
128 end
129end
130
131function FuelTrailer:addFuelFillTrigger(trigger)
132 if table.getn(self.fuelFillTriggers) == 0 then
133 g_currentMission:addActivatableObject(self.fuelTrailerFillActivatable);
134 end;
135 table.insert(self.fuelFillTriggers, trigger);
136end;
137
138function FuelTrailer:removeFuelFillTrigger(trigger)
139 for i=1, table.getn(self.fuelFillTriggers) do
140 if self.fuelFillTriggers[i] == trigger then
141 table.remove(self.fuelFillTriggers, i);
142 break;
143 end;
144 end;
145 if table.getn(self.fuelFillTriggers) == 0 or trigger == self.fuelFillTrigger then
146 if self.isServer then
147 self:setIsFuelFilling(false);
148 end;
149 if table.getn(self.fuelFillTriggers) == 0 then
150 g_currentMission:removeActivatableObject(self.fuelTrailerFillActivatable);
151 end
152 end;
153end;
154
155FuelTrailerFillActivatable = {}
156local FuelTrailerFillActivatable_mt = Class(FuelTrailerFillActivatable);
157
158function FuelTrailerFillActivatable:new(trailer)
159 local self = {};
160 setmetatable(self, FuelTrailerFillActivatable_mt);
161
162 self.trailer = trailer;
163 self.activateText = "unknown";
164
165 return self;
166end;
167
168
169function FuelTrailerFillActivatable:getIsActivatable()
170 if self.trailer:getIsActiveForInput() and self.trailer:getFillLevel(Fillable.FILLTYPE_FUEL) < self.trailer:getCapacity() and self.trailer:allowFillType(Fillable.FILLTYPE_FUEL, false) then
171 -- find the first trigger which is activable
172 for i=1, table.getn(self.trailer.fuelFillTriggers) do
173 local trigger = self.trailer.fuelFillTriggers[i];
174 if trigger:getIsActivatable(self.trailer) then
175 self:updateActivateText();
176 return true;
177 end
178 end
179 end
180 return false;
181end;
182
183function FuelTrailerFillActivatable:onActivateObject()
184 self.trailer:setIsFuelFilling(not self.trailer.isFuelFilling);
185 self:updateActivateText();
186 g_currentMission:addActivatableObject(self);
187end;
188
189function FuelTrailerFillActivatable:drawActivate()
190 g_currentMission:enableHudIcon("refuel", 5);
191end;
192
193function FuelTrailerFillActivatable:updateActivateText()
194 if self.trailer.isFuelFilling then
195 self.activateText = string.format(g_i18n:getText("stop_refill_OBJECT"), self.trailer.typeDesc);
196 else
197 self.activateText = string.format(g_i18n:getText("refill_OBJECT"), self.trailer.typeDesc);
198 end;
199end;
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