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 | PloughAreaEvent = {}; |
4 | PloughAreaEvent_mt = Class(PloughAreaEvent, Event); |
5 | |
6 | InitStaticEventClass(PloughAreaEvent, "PloughAreaEvent", EventIds.EVENT_PLOUGH_AREA); |
7 | |
8 | function PloughAreaEvent:emptyNew() |
9 | local self = Event:new(PloughAreaEvent_mt); |
10 | return self; |
11 | end; |
12 | |
13 | function PloughAreaEvent:new(workAreas, limitToField, limitGrassDestructionToField, angle) |
14 | local self = PloughAreaEvent:emptyNew() |
15 | assert(table.getn(workAreas) > 0); |
16 | self.workAreas = workAreas; |
17 | self.limitToField = limitToField; |
18 | self.limitGrassDestructionToField = Utils.getNoNil(limitGrassDestructionToField, limitToField); |
19 | self.angle = angle; |
20 | return self; |
21 | end; |
22 | |
23 | function PloughAreaEvent:readStream(streamId, connection) |
24 | local limitToField = streamReadBool(streamId); |
25 | local limitGrassDestructionToField = streamReadBool(streamId); |
26 | local angle = nil; |
27 | if streamReadBool(streamId) then |
28 | angle = streamReadUIntN(streamId, g_currentMission.terrainDetailAngleNumChannels); |
29 | end |
30 | local numAreas = streamReadUIntN(streamId, 4); |
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 | for i=1,numAreas do |
36 | local vi = i-1; |
37 | local x = values[vi*3+1].x; |
38 | local z = values[vi*3+1].y; |
39 | local x1 = values[vi*3+2].x; |
40 | local z1 = values[vi*3+2].y; |
41 | local x2 = values[vi*3+3].x; |
42 | local z2 = values[vi*3+3].y; |
43 | Utils.updatePloughArea(x, z, x1, z1, x2, z2, not limitToField, not limitGrassDestructionToField, angle); |
44 | end; |
45 | end; |
46 | |
47 | function PloughAreaEvent:writeStream(streamId, connection) |
48 | local numAreas = table.getn(self.workAreas); |
49 | streamWriteBool(streamId, self.limitToField); |
50 | streamWriteBool(streamId, self.limitGrassDestructionToField); |
51 | if streamWriteBool(streamId, self.angle ~= nil) then |
52 | streamWriteUIntN(streamId, self.angle, g_currentMission.terrainDetailAngleNumChannels); |
53 | end |
54 | streamWriteUIntN(streamId, numAreas, 4); |
55 | |
56 | local refX, refY; |
57 | local values = {}; |
58 | for i=1, numAreas do |
59 | local d = self.workAreas[i]; |
60 | if i==1 then |
61 | refX = d[1]; |
62 | refY = d[2]; |
63 | streamWriteFloat32(streamId, d[1]); |
64 | streamWriteFloat32(streamId, d[2]); |
65 | else |
66 | table.insert(values, {x=d[1], y=d[2]}); |
67 | end; |
68 | table.insert(values, {x=d[3], y=d[4]}); |
69 | table.insert(values, {x=d[5], y=d[6]}); |
70 | end; |
71 | assert(table.getn(values) == numAreas*3 - 1); |
72 | Utils.writeCompressed2DVectors(streamId, refX, refY, values, 0.01); |
73 | end; |
74 | |
75 | function PloughAreaEvent:run(connection) |
76 | print("Error: Do not run PloughAreaEvent locally"); |
77 | end; |
78 | |
79 | function PloughAreaEvent.runLocally(workAreas, limitToField, limitGrassDestructionToField, angle) |
80 | |
81 | local numAreas = table.getn(workAreas); |
82 | |
83 | local refX, refY; |
84 | local values = {}; |
85 | for i=1, numAreas do |
86 | local d = workAreas[i]; |
87 | if i==1 then |
88 | refX = d[1]; |
89 | refY = d[2]; |
90 | else |
91 | table.insert(values, {x=d[1], y=d[2]}); |
92 | end; |
93 | table.insert(values, {x=d[3], y=d[4]}); |
94 | table.insert(values, {x=d[5], y=d[6]}); |
95 | end; |
96 | assert(table.getn(values) == numAreas*3 - 1); |
97 | |
98 | local values = Utils.simWriteCompressed2DVectors(refX, refY, values, 0.01, true); |
99 | |
100 | local areaSum = 0; |
101 | for i=1, numAreas do |
102 | local vi = i-1; |
103 | local x = values[vi*3+1].x; |
104 | local z = values[vi*3+1].y; |
105 | local x1 = values[vi*3+2].x; |
106 | local z1 = values[vi*3+2].y; |
107 | local x2 = values[vi*3+3].x; |
108 | local z2 = values[vi*3+3].y; |
109 | areaSum = areaSum + Utils.updatePloughArea(x, z, x1, z1, x2, z2, not limitToField, not limitGrassDestructionToField, angle); -- TODO: this does not return the effectively worked area |
110 | end; |
111 | |
112 | return areaSum; |
113 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de