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 | RemoveGroundValueAreaEvent = {}; |
4 | RemoveGroundValueAreaEvent_mt = Class(RemoveGroundValueAreaEvent, Event); |
5 | |
6 | InitStaticEventClass(RemoveGroundValueAreaEvent, "RemoveGroundValueAreaEvent", EventIds.EVENT_REMOVE_GROUND_VALUE_AREA); |
7 | |
8 | function RemoveGroundValueAreaEvent:emptyNew() |
9 | local self = Event:new(RemoveGroundValueAreaEvent_mt); |
10 | return self; |
11 | end; |
12 | |
13 | function RemoveGroundValueAreaEvent:new(areas, fillType, bitType) |
14 | local self = RemoveGroundValueAreaEvent:emptyNew() |
15 | self.areas = areas; |
16 | self.bitType = bitType; |
17 | self.fillType = fillType; |
18 | assert(self.bitType >= 0 and self.bitType <= 3); |
19 | assert(table.getn(self.areas) > 0 and table.getn(self.areas) < 16); |
20 | return self; |
21 | end; |
22 | |
23 | function RemoveGroundValueAreaEvent:readStream(streamId, connection) |
24 | local numAreas = streamReadUIntN(streamId, 4); |
25 | local fillType = streamReadUIntN(streamId, Fillable.sendNumBits); |
26 | local groundValueId = g_currentMission.groundValueIds[fillType]; |
27 | local valueToLeave = {}; |
28 | for i=1,numAreas do |
29 | valueToLeave[i] = streamReadUIntN(streamId, groundValueId.numChannels); |
30 | end; |
31 | |
32 | local refX = streamReadFloat32(streamId); |
33 | local refY = streamReadFloat32(streamId); |
34 | local values = Utils.readCompressed2DVectors(streamId, refX, refY, numAreas*3-1, 0.01, true); |
35 | |
36 | local groundValueId = g_currentMission.groundValueIds[fillType]; |
37 | if groundValueId ~= nil then |
38 | for i=1,numAreas do |
39 | local vi = i-1; |
40 | local x = values[vi*3+1].x; |
41 | local z = values[vi*3+1].y; |
42 | local x1 = values[vi*3+2].x; |
43 | local z1 = values[vi*3+2].y; |
44 | local x2 = values[vi*3+3].x; |
45 | local z2 = values[vi*3+3].y; |
46 | |
47 | Utils.removeGroundValueArea(groundValueId.id, groundValueId.firstChannel, groundValueId.numChannels, x, z, x1, z1, x2, z2, valueToLeave[i]); |
48 | end; |
49 | end; |
50 | end; |
51 | |
52 | |
53 | function RemoveGroundValueAreaEvent:writeStream(streamId, connection) |
54 | |
55 | local numAreas = table.getn(self.areas); |
56 | streamWriteUIntN(streamId, numAreas, 4); |
57 | streamWriteUIntN(streamId, self.fillType, Fillable.sendNumBits); |
58 | |
59 | local groundValueId = g_currentMission.groundValueIds[self.fillType]; |
60 | |
61 | local refX, refY; |
62 | local values = {}; |
63 | for i=1, numAreas do |
64 | local d = self.areas[i]; |
65 | if i==1 then |
66 | refX = d[1]; |
67 | refY = d[2]; |
68 | streamWriteFloat32(streamId, d[1]); |
69 | streamWriteFloat32(streamId, d[2]); |
70 | else |
71 | table.insert(values, {x=d[1], y=d[2]}); |
72 | end; |
73 | table.insert(values, {x=d[3], y=d[4]}); |
74 | table.insert(values, {x=d[5], y=d[6]}); |
75 | |
76 | streamWriteUIntN(streamId, math.floor(groundValueId.maxValue * d[7]), groundValueId.numChannels); -- valueToLeave |
77 | end; |
78 | assert(table.getn(values) == numAreas*3 - 1); |
79 | Utils.writeCompressed2DVectors(streamId, refX, refY, values, 0.01, self.bitType); |
80 | end; |
81 | |
82 | function RemoveGroundValueAreaEvent:run(connection) |
83 | print("Error: Do not run RemoveGroundValueAreaEvent locally"); |
84 | end; |
85 | |
86 | function RemoveGroundValueAreaEvent.runLocally(areas, fillType) |
87 | |
88 | local numAreas = table.getn(areas); |
89 | |
90 | local refX, refY; |
91 | local values = {}; |
92 | for i=1, numAreas do |
93 | local d = areas[i]; |
94 | if i==1 then |
95 | refX = d[1]; |
96 | refY = d[2]; |
97 | else |
98 | table.insert(values, {x=d[1], y=d[2]}); |
99 | end; |
100 | table.insert(values, {x=d[3], y=d[4]}); |
101 | table.insert(values, {x=d[5], y=d[6]}); |
102 | end; |
103 | assert(table.getn(values) == numAreas*3 - 1); |
104 | |
105 | local values, bitType = Utils.simWriteCompressed2DVectors(refX, refY, values, 0.01, true); |
106 | local totalValueRemoved = 0; |
107 | |
108 | local retAreas = {}; |
109 | local groundValueId = g_currentMission.groundValueIds[fillType]; |
110 | if groundValueId ~= nil then |
111 | for i=1, numAreas do |
112 | local vi = i-1; |
113 | local x = values[vi*3+1].x; |
114 | local z = values[vi*3+1].y; |
115 | local x1 = values[vi*3+2].x; |
116 | local z1 = values[vi*3+2].y; |
117 | local x2 = values[vi*3+3].x; |
118 | local z2 = values[vi*3+3].y; |
119 | local valueToLeave = math.floor(groundValueId.maxValue * areas[i][7]); |
120 | |
121 | local valueRemoved, numPixels = Utils.removeGroundValueArea(groundValueId.id, groundValueId.firstChannel, groundValueId.numChannels, x, z, x1, z1, x2, z2, valueToLeave); |
122 | |
123 | if valueRemoved > 0 then |
124 | totalValueRemoved = totalValueRemoved + valueRemoved; |
125 | table.insert(retAreas, areas[i]); |
126 | end; |
127 | end; |
128 | end; |
129 | return retAreas, bitType, totalValueRemoved; |
130 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de