Sprache Deutsch Language English

Script Dokumentation LS 2015 - BalerAreaEvent (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/BalerAreaEvent.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
3BalerAreaEvent = {};
4BalerAreaEvent_mt = Class(BalerAreaEvent, Event);
5
6InitStaticEventClass(BalerAreaEvent, "BalerAreaEvent", EventIds.EVENT_BALER_AREA);
7
8function BalerAreaEvent:emptyNew()
9 local self = Event:new(BalerAreaEvent_mt);
10 return self;
11end
12
13function BalerAreaEvent:new(workAreas, usedFillType)
14 local self = BalerAreaEvent:emptyNew()
15 self.workAreas = workAreas;
16 self.usedFillType = usedFillType;
17 assert(table.getn(self.workAreas) > 0 and table.getn(self.workAreas) <= 16);
18 return self;
19end
20
21function BalerAreaEvent:readStream(streamId, connection)
22 local numAreas = streamReadUIntN(streamId, 4)+1;
23 local usedFillType = streamReadUIntN(streamId, Fillable.sendNumBits);
24
25 local params = g_currentMission.areaCompressionParams;
26 local paramsRelative = g_currentMission.areaRelativeCompressionParams;
27 for i=1, numAreas do
28 local x = Utils.readCompressedWorldPosition(streamId, params);
29 local z = Utils.readCompressedWorldPosition(streamId, params);
30 local x1 = x + Utils.readCompressedWorldPosition(streamId, paramsRelative);
31 local z1 = z + Utils.readCompressedWorldPosition(streamId, paramsRelative);
32 local x2 = x + Utils.readCompressedWorldPosition(streamId, paramsRelative);
33 local z2 = z + Utils.readCompressedWorldPosition(streamId, paramsRelative);
34
35 local fruitType = FruitUtil.fillTypeToFruitType[usedFillType];
36
37 Utils.updateFruitWindrowArea(fruitType, x, z, x1, z1, x2, z2, 0);
38
39 -- 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)
40 if fruitType == FruitUtil.FRUITTYPE_DRYGRASS then
41 Utils.switchFruitTypeArea(FruitUtil.FRUITTYPE_GRASS, FruitUtil.FRUITTYPE_DRYGRASS, x, z, x1, z1, x2, z2, 2);
42 end
43 end
44end
45
46function BalerAreaEvent:writeStream(streamId, connection)
47 local numAreas = table.getn(self.workAreas);
48 streamWriteUIntN(streamId, numAreas-1, 4);
49 streamWriteUIntN(streamId, self.usedFillType, Fillable.sendNumBits);
50
51 local params = g_currentMission.areaCompressionParams;
52 local paramsRelative = g_currentMission.areaRelativeCompressionParams;
53 for i=1, numAreas do
54 local d = self.workAreas[i];
55 Utils.writeCompressedWorldPosition(streamId, d[1], params);
56 Utils.writeCompressedWorldPosition(streamId, d[2], params);
57 Utils.writeCompressedWorldPosition(streamId, d[3] - d[1], paramsRelative);
58 Utils.writeCompressedWorldPosition(streamId, d[4] - d[2], paramsRelative);
59 Utils.writeCompressedWorldPosition(streamId, d[5] - d[1], paramsRelative);
60 Utils.writeCompressedWorldPosition(streamId, d[6] - d[2], paramsRelative);
61 end
62end
63
64function BalerAreaEvent:run(connection)
65 --print("Error: do not run BalerAreaEvent locally");
66end
67
68function BalerAreaEvent.runLocally(workAreas, balerPickupFillTypes)
69 local totalArea =0;
70 local usedFillType = Fillable.FILLTYPE_UNKNOWN;
71
72 local numAreas = table.getn(workAreas);
73
74 local params = g_currentMission.areaCompressionParams;
75 local paramsRelative = g_currentMission.areaRelativeCompressionParams;
76 for i=1, numAreas do
77 local d = workAreas[i];
78 local x = Utils.simWriteCompressedWorldPosition(d[1], params);
79 local z = Utils.simWriteCompressedWorldPosition(d[2], params);
80 local x1 = x + Utils.simWriteCompressedWorldPosition(d[3] - d[1], paramsRelative);
81 local z1 = z + Utils.simWriteCompressedWorldPosition(d[4] - d[2], paramsRelative);
82 local x2 = x + Utils.simWriteCompressedWorldPosition(d[5] - d[1], paramsRelative);
83 local z2 = z + Utils.simWriteCompressedWorldPosition(d[6] - d[2], paramsRelative);
84
85 if usedFillType ~= Fillable.FILLTYPE_UNKNOWN then
86 local fruitType = FruitUtil.fillTypeToFruitType[usedFillType];
87 local area = Utils.updateFruitWindrowArea(fruitType, x, z, x1, z1, x2, z2, 0);
88 if area > 0 then
89 -- now that we removed the windrow, maybe there is some hidden drygrass to grow (set it to growth state 1 if there is some)
90 if fruitType == FruitUtil.FRUITTYPE_DRYGRASS then
91 Utils.switchFruitTypeArea(FruitUtil.FRUITTYPE_GRASS, FruitUtil.FRUITTYPE_DRYGRASS, x, z, x1, z1, x2, z2, 2);
92 end;
93 totalArea = totalArea+area;
94 end
95 else
96 for _, fillType in pairs(balerPickupFillTypes) do
97 local fruitType = FruitUtil.fillTypeToFruitType[fillType];
98
99 local area = Utils.updateFruitWindrowArea(fruitType, x, z, x1, z1, x2, z2, 0);
100 if area > 0 then
101 -- now that we removed the windrow, maybe there is some hidden drygrass to grow (set it to growth state 1 if there is some)
102 if fruitType == FruitUtil.FRUITTYPE_DRYGRASS then
103 Utils.switchFruitTypeArea(FruitUtil.FRUITTYPE_GRASS, FruitUtil.FRUITTYPE_DRYGRASS, x, z, x1, z1, x2, z2, 2);
104 end;
105
106 totalArea = totalArea+area;
107 usedFillType = fillType;
108 break;
109 end
110 end
111 end
112 end
113 return totalArea, usedFillType;
114end
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