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