Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
2 | |
3 | TrailerTipAreaEvent = {}; |
4 | TrailerTipAreaEvent_mt = Class(TrailerTipAreaEvent, Event); |
5 | |
6 | InitStaticEventClass(TrailerTipAreaEvent, "TrailerTipAreaEvent", EventIds.EVENT_TRAILER_TIP_AREA); |
7 | |
8 | function TrailerTipAreaEvent:emptyNew() |
9 | local self = Event:new(TrailerTipAreaEvent_mt); |
10 | return self; |
11 | end; |
12 | |
13 | function TrailerTipAreaEvent:new(area, bitType, fillType) |
14 | local self = TrailerTipAreaEvent:emptyNew() |
15 | self.area = area; |
16 | self.bitType = bitType; |
17 | self.fillType = fillType; |
18 | assert(self.bitType >= 0 and self.bitType <= 3); |
19 | return self; |
20 | end; |
21 | |
22 | function TrailerTipAreaEvent:readStream(streamId, connection) |
23 | |
24 | local fillType = streamReadUIntN(streamId, Fillable.sendNumBits); |
25 | local groundValueId = g_currentMission.groundValueIds[fillType]; |
26 | local amountPerPixel = streamReadUIntN(streamId, groundValueId.numChannels); |
27 | |
28 | local refX = streamReadFloat32(streamId); |
29 | local refY = streamReadFloat32(streamId); |
30 | local values = Utils.readCompressed2DVectors(streamId, refX, refY, 2, 0.01, true); |
31 | |
32 | local x = values[1].x; |
33 | local z = values[1].y; |
34 | local x1 = values[2].x; |
35 | local z1 = values[2].y; |
36 | local x2 = values[3].x; |
37 | local z2 = values[3].y; |
38 | |
39 | Utils.addGroundValueAreaPerPixel(groundValueId.id, groundValueId.firstChannel, groundValueId.numChannels, x, z, x1, z1, x2, z2, amountPerPixel) |
40 | end; |
41 | |
42 | function TrailerTipAreaEvent:writeStream(streamId, connection) |
43 | |
44 | streamWriteUIntN(streamId, self.fillType, Fillable.sendNumBits); |
45 | local groundValueId = g_currentMission.groundValueIds[self.fillType]; |
46 | streamWriteUIntN(streamId, self.area[8], groundValueId.numChannels); |
47 | |
48 | local d = self.area; |
49 | local refX, refY = d[1], d[2]; |
50 | streamWriteFloat32(streamId, d[1]); |
51 | streamWriteFloat32(streamId, d[2]); |
52 | local values = { {x=d[3], y=d[4]}, {x=d[5], y=d[6]} }; |
53 | |
54 | Utils.writeCompressed2DVectors(streamId, refX, refY, values, 0.01, self.bitType); |
55 | end; |
56 | |
57 | function TrailerTipAreaEvent:run(connection) |
58 | print("Error: Do not run TrailerTipAreaEvent locally"); |
59 | end; |
60 | |
61 | function TrailerTipAreaEvent.runLocally(area, fillType, valueAccumulation) |
62 | |
63 | local groundValueId = g_currentMission.groundValueIds[fillType]; |
64 | if groundValueId == nil then |
65 | return nil; |
66 | end; |
67 | local numAreas = table.getn(area); |
68 | |
69 | local refX, refY= area[1],area[2]; |
70 | local values = { {x=area[3], y=area[4]}, {x=area[5], y=area[6]} }; |
71 | |
72 | local values, bitType = Utils.simWriteCompressed2DVectors(refX, refY, values, 0.01, true); |
73 | |
74 | local retArea = nil; |
75 | local x = values[1].x; |
76 | local z = values[1].y; |
77 | local x1 = values[2].x; |
78 | local z1 = values[2].y; |
79 | local x2 = values[3].x; |
80 | local z2 = values[3].y; |
81 | local fillLevel = area[7]; |
82 | |
83 | local amount = fillLevel / groundValueId.groundAmountToFillLevel + valueAccumulation; |
84 | |
85 | local addedAmount, _, amountPerPixel, roundingError = Utils.addGroundValueArea(groundValueId.id, groundValueId.firstChannel, groundValueId.numChannels, x, z, x1, z1, x2, z2, amount); |
86 | |
87 | if addedAmount > 0 and amountPerPixel > 0 then |
88 | area[8] = math.min(amountPerPixel, groundValueId.maxValue); |
89 | retArea = area; |
90 | end; |
91 | return retArea, bitType, roundingError; |
92 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de