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