-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVehicleScheduleCapacity.TaskTransfers.cs
95 lines (85 loc) · 3.18 KB
/
VehicleScheduleCapacity.TaskTransfers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System.Collections.Generic;
using VoxelTycoon;
namespace ScheduleStopwatch
{
public partial class VehicleScheduleCapacity
{
public enum TransferDirection { both, loading, unloading };
public struct TransferData
{
public int load, unload;
public bool estimated; //time data for calculation monthly tranfers is estimated
public int Total
{
get
{
return load - unload;
}
}
public int Get(TransferDirection direction)
{
switch (direction)
{
case TransferDirection.loading:
return load;
case TransferDirection.unloading:
return unload;
case TransferDirection.both:
return Total;
}
return 0;
}
}
public class TaskTransfers
{
//transfer per Item ( >0 = loading, <0 = unloading)
private readonly Dictionary<Item, TransferData> _transfers = new Dictionary<Item, TransferData>();
public TaskTransfers() { }
public TaskTransfers(TaskTransfers taskTransfers, float? multiplier = null, bool estimated = false)
{
Add(taskTransfers._transfers, multiplier, estimated);
}
public IReadOnlyDictionary<Item, TransferData> Transfers
{
get
{
return _transfers;
}
}
public void Add(Item item, int count, bool estimated = false)
{
if (count > 0)
{
Add(item, count, 0, estimated);
} else
{
Add(item, 0, -count, estimated);
}
}
public void Add(Item item, int load, int unload, bool estimated = false)
{
if (!_transfers.TryGetValue(item, out TransferData data))
{
data = default;
}
data.load += load;
data.unload += unload;
data.estimated |= estimated;
_transfers[item] = data;
}
public void Add(TaskTransfers transfers, float? multiplier = null, bool estimated = false)
{
Add(transfers._transfers, multiplier, estimated);
}
public void Add(IReadOnlyDictionary<Item, TransferData> transfers, float? multiplier=null, bool estimated = false)
{
foreach (KeyValuePair<Item, TransferData> transfer in transfers)
{
int load = multiplier != null ? (transfer.Value.load * multiplier.Value).RoundToInt() : transfer.Value.load;
int unload = multiplier != null ? (transfer.Value.unload * multiplier.Value).RoundToInt() : transfer.Value.unload;
this.Add(transfer.Key, load, unload, transfer.Value.estimated | estimated);
}
}
}
}
}