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 | BaleUtil = {}; |
4 | |
5 | BaleUtil.BALETYPE_UNKNOWN = 0; |
6 | BaleUtil.NUM_BALETYPES = 0; |
7 | |
8 | BaleUtil.baleIndexToDesc = {}; |
9 | BaleUtil.roundBales = {}; |
10 | BaleUtil.squareBales = {}; |
11 | BaleUtil.defaultRoundBale = nil; |
12 | BaleUtil.defaultSquareBale = nil; |
13 | BaleUtil.sendNumBits = 6; |
14 | |
15 | function BaleUtil.registerBaleType(filename, fillTypeName, width, height, length, diameter, isRoundbale) |
16 | local key = BaleUtil.getBaleKey(fillTypeName, width, height, length, diameter, isRoundbale); |
17 | |
18 | if BaleUtil[key] ~= nil then |
19 | print("Overriding bale ("..key..") '"..BaleUtil[key].filename.."'"); |
20 | end; |
21 | |
22 | if BaleUtil.NUM_BALETYPES >= 64 then |
23 | print("Error BaleUtil.registerBaleType: Too many bale types. Only 64 bale types are supported"); |
24 | return; |
25 | end; |
26 | |
27 | BaleUtil.NUM_BALETYPES = BaleUtil.NUM_BALETYPES+1; |
28 | BaleUtil[key] = BaleUtil.NUM_BALETYPES; |
29 | |
30 | local desc = {fillTypeName=fillTypeName, index = BaleUtil.NUM_BALETYPES}; |
31 | desc.width = Utils.getNoNil(tonumber(width), 1.2); |
32 | desc.height = Utils.getNoNil(tonumber(height), 0.9); |
33 | desc.length = Utils.getNoNil(tonumber(length), 2.4); |
34 | desc.diameter = Utils.getNoNil(tonumber(diameter), 1.8); |
35 | desc.isRoundbale = isRoundbale; |
36 | desc.filename = filename; |
37 | |
38 | BaleUtil.baleIndexToDesc[BaleUtil.NUM_BALETYPES] = desc; |
39 | |
40 | if isRoundbale then |
41 | BaleUtil.roundBales[key] = desc; |
42 | if BaleUtil.defaultRoundBale == nil then |
43 | BaleUtil.defaultRoundBale = desc; |
44 | end; |
45 | else |
46 | BaleUtil.squareBales[key] = desc; |
47 | if BaleUtil.defaultSquareBale == nil then |
48 | BaleUtil.defaultSquareBale = desc; |
49 | end; |
50 | end; |
51 | |
52 | return BaleUtil[key]; |
53 | end |
54 | |
55 | -- always takes the largest fitting baletype |
56 | function BaleUtil.getBale(fillType, width, height, length, diameter, isRoundbale) |
57 | local fillTypeName = "wheat_windrow"; |
58 | if FruitUtil.fillTypeToFruitType[fillType] ~= nil and FruitUtil.fruitIndexToDesc[FruitUtil.fillTypeToFruitType[fillType]].windrowName ~= nil then |
59 | fillTypeName = FruitUtil.fruitIndexToDesc[FruitUtil.fillTypeToFruitType[fillType]].windrowName; |
60 | end; |
61 | |
62 | local key = BaleUtil.getBaleKey(fillTypeName, width, height, length, diameter, isRoundbale); |
63 | if BaleUtil[key] ~= nil then |
64 | return BaleUtil.baleIndexToDesc[BaleUtil[key]]; |
65 | end; |
66 | |
67 | local baleType = nil; |
68 | if isRoundbale then |
69 | for _, bt in pairs(BaleUtil.roundBales) do |
70 | if bt.width <= width and bt.diameter <= diameter then |
71 | if baleType ~= nil then |
72 | if fillTypeName == nil or bt.fillTypeName == fillTypeName then |
73 | -- take the better fitting bale |
74 | if bt.width >= baleType.width and bt.diameter >= baleType.diameter then |
75 | baleType = bt; |
76 | end; |
77 | end; |
78 | else |
79 | baleType = bt; |
80 | end; |
81 | end; |
82 | end; |
83 | |
84 | if baleType == nil then |
85 | baleType = BaleUtil.defaultRoundBale; |
86 | end; |
87 | else |
88 | for _, bt in pairs(BaleUtil.squareBales) do |
89 | if bt.width <= width and bt.height <= height and bt.length <= length then |
90 | if baleType ~= nil then |
91 | if fillTypeName == nil or bt.fillTypeName == fillTypeName then |
92 | -- take the better fitting bale (prio to width) |
93 | if bt.width >= baleType.width and (bt.length >= baleType.length or bt.height >= baleType.height) then |
94 | baleType = bt; |
95 | end; |
96 | end; |
97 | else |
98 | baleType = bt; |
99 | end; |
100 | end; |
101 | end; |
102 | |
103 | if baleType == nil then |
104 | baleType = BaleUtil.defaultSquareBale; |
105 | end; |
106 | end; |
107 | |
108 | return baleType; |
109 | end |
110 | |
111 | function BaleUtil.getBaleKey(fillTypeName, width, height, length, diameter, isRoundbale) |
112 | local key = "BALETYPE_"..string.upper(fillTypeName).."_"..(width*100).."_"; |
113 | if isRoundbale then |
114 | key = key .. (diameter*100); |
115 | else |
116 | key = key ..(height*100).."_"..(length*100); |
117 | end; |
118 | |
119 | return key; |
120 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de