Sprache Deutsch Language English

Script Dokumentation LS 2015 - ForageWagonAreaEvent (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/ForageWagonAreaEvent.lua

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
3ForageWagonAreaEvent = {};
4ForageWagonAreaEvent_mt = Class(ForageWagonAreaEvent, Event);
5
6InitStaticEventClass(ForageWagonAreaEvent, "ForageWagonAreaEvent", EventIds.EVENT_FORAGE_WAGON_AREA);
7
8function ForageWagonAreaEvent:emptyNew()
9 local self = Event:new(ForageWagonAreaEvent_mt);
10 return self;
11end;
12
13function ForageWagonAreaEvent:new(workAreas, fruitType)
14 local self = ForageWagonAreaEvent:emptyNew()
15 self.workAreas = workAreas;
16 self.fruitType = fruitType;
17 return self;
18end;
19
20function ForageWagonAreaEvent:readStream(streamId, connection)
21 local fruitType = streamReadUIntN(streamId, FruitUtil.sendNumBits);
22 local numAreas = streamReadUIntN(streamId, 4);
23
24 local fruitDesc = FruitUtil.fruitIndexToDesc[fruitType]
25
26 local refX = streamReadFloat32(streamId);
27 local refY = streamReadFloat32(streamId);
28 local values = Utils.readCompressed2DVectors(streamId, refX, refY, numAreas*3-1, 0.01, true);
29 for i=1,numAreas do
30 local vi = i-1;
31 local x = values[vi*3+1].x;
32 local z = values[vi*3+1].y;
33 local x1 = values[vi*3+2].x;
34 local z1 = values[vi*3+2].y;
35 local x2 = values[vi*3+3].x;
36 local z2 = values[vi*3+3].y;
37
38 Utils.updateFruitWindrowArea(fruitType, x, z, x1, z1, x2, z2, 0);
39 if fruitDesc ~= nil then
40 for fruitTypeSrc,_ in pairs(fruitDesc.forageWagonConversionSources) do
41 Utils.updateFruitWindrowArea(fruitTypeSrc, x, z, x1, z1, x2, z2, 0);
42 end
43 end
44
45 -- now that we removed the cut long and windrow, maybe there is some hidden drygrass to grow (set it to growth state 1 if there is some)
46 if fruitType == FruitUtil.FRUITTYPE_DRYGRASS then
47 Utils.switchFruitTypeArea(FruitUtil.FRUITTYPE_GRASS, FruitUtil.FRUITTYPE_DRYGRASS, x, z, x1, z1, x2, z2, 2);
48 end
49 end;
50end;
51
52function ForageWagonAreaEvent:writeStream(streamId, connection)
53 streamWriteUIntN(streamId, self.fruitType, FruitUtil.sendNumBits);
54 local numAreas = table.getn(self.workAreas);
55 streamWriteUIntN(streamId, numAreas, 4);
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);
73end;
74
75function ForageWagonAreaEvent:run(connection)
76 print("Error: Do not run ForageWagonAreaEvent locally");
77end;
78
79function ForageWagonAreaEvent.runLocally(workAreas, fillTypes, fruitTypeFix, fruitType)
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 totalArea = 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
110 local area = 0
111 if fruitTypeFix then
112 area = Utils.updateFruitWindrowArea(fruitType, x, z, x1, z1, x2, z2, 0);
113 local fruitDesc = FruitUtil.fruitIndexToDesc[fruitType]
114 if fruitDesc ~= nil then
115 for fruitTypeSrc,_ in pairs(fruitDesc.forageWagonConversionSources) do
116 area = area + Utils.updateFruitWindrowArea(fruitTypeSrc, x, z, x1, z1, x2, z2, 0);
117 end
118 end
119 else
120 for fillType, enabled in pairs(fillTypes) do
121 -- Note: we count both grass and dry grass as grass (ignore dry grass in the loop, and pickup dry grass when cutting normal grass)
122 -- and we do the same with barley and wheat windrows
123 -- This is generalized with the forageWagonConversionTarget and forageWagonConversionSources attributes of the fruitTypeDesc
124 fruitType = FruitUtil.fillTypeToFruitType[fillType];
125 local fruitDesc;
126 if fruitType ~= nil then
127 fruitDesc = FruitUtil.fruitIndexToDesc[fruitType];
128 end
129 if enabled and fruitDesc ~= nil and FruitUtil.fillTypeIsWindrow[fillType] and fruitDesc.forageWagonConversionTarget == nil then
130 area = Utils.updateFruitWindrowArea(fruitType, x, z, x1, z1, x2, z2, 0);
131 for fruitTypeSrc,_ in pairs(fruitDesc.forageWagonConversionSources) do
132 area = area + Utils.updateFruitWindrowArea(fruitTypeSrc, x, z, x1, z1, x2, z2, 0);
133 end
134 if area > 0 then
135 fruitTypeFix = true;
136 break;
137 end
138 end
139 end
140 end
141 if area > 0 then
142 -- now that we removed the windrow, maybe there is some hidden drygrass to grow (set it to growth state 1 if there is some)
143 if fruitType == FruitUtil.FRUITTYPE_GRASS then
144 Utils.switchFruitTypeArea(FruitUtil.FRUITTYPE_GRASS, FruitUtil.FRUITTYPE_DRYGRASS, x, z, x1, z1, x2, z2, 2);
145 end
146 totalArea = totalArea + area;
147 end
148 end;
149 return totalArea, fruitType;
150end;
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
Script Dokumentation Übersicht