-
Notifications
You must be signed in to change notification settings - Fork 2
/
FreightSystemInterface.cs
152 lines (131 loc) · 4.52 KB
/
FreightSystemInterface.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System.Collections.Generic;
using FortressCraft.Community.Utilities;
using System;
public interface FreightSystemInterface
{
/// <summary>
/// List of all items that the interface has available to provide to the freight system
/// </summary>
List<FreightListing> FreightOfferings
{
get;
}
/// <summary>
/// List of all items that the interface wants delivered to it by the freight system
/// </summary>
List<FreightListing> FreightRequests
{
get;
}
/// <summary>
/// Checked each tick by the connected freight station. If true the station will query
/// the master freight registry for the freight data associated with the stations network.
/// This request is costly, avoid making frequent requests! The registry fully updates
/// every 3 seconds so requests more frequent than this are unnecessary. Cache locally!
/// </summary>
bool FreightDataRequest
{
get;
}
/// <summary>
/// Queried freight network data is passed to the interface here
/// </summary>
/// <param name="data">Current freight status for the connected station's network.</param>
void FreightNetworkData(List<FreightData> data);
/// <summary>
/// The freight system calls this when it has an item to offer to the interface
/// </summary>
/// <param name="item">The item being offered to the interface</param>
/// <returns>True if the item is accepted</returns>
bool ReceiveFreight(ItemBase item);
/// <summary>
/// The freight system calls this when requesting an item from the interface
/// </summary>
/// <param name="item">The item the freight system wants the interface to provide</param>
/// <returns>True if the interface successfully provides the item</returns>
bool ProvideFreight(ItemBase item);
}
/// <summary>
/// Class representing a freight item and offered/requested quantity
/// </summary>
public class FreightListing
{
public ItemBase Item { get; }
public int Quantity { get; set; }
public FreightListing(ItemBase item, int quantity)
{
Item = item;
Quantity = quantity;
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
Type type = obj.GetType();
if (type == typeof(FreightListing))
return Item.Compare((obj as FreightListing).Item);
else if (type == typeof(ItemBase))
return Item.Compare(obj as ItemBase);
else
return false;
}
public static bool operator ==(FreightListing a, FreightListing b)
{
if ((object)a != null && (object)b != null)
return a.Item.Compare(b.Item);
if ((object)a == null && (object)b == null)
return true;
return false;
}
public static bool operator !=(FreightListing a, FreightListing b)
{
if ((object)a != null && (object)b != null)
return !(a.Item.Compare(b.Item));
if (((object)a != null && (object)b == null) || ((object)a == null && (object)b != null))
return true;
return false;
}
public static explicit operator ItemBase(FreightListing freight)
{
return freight.Item;
}
public override int GetHashCode()
{
return Item.GetHashCode();
}
}
/// <summary>
/// Class containing basic freight system status information
/// </summary>
public class FreightData
{
/// <summary>
/// The Freight Item traded on the network
/// </summary>
public ItemBase FreightItem { get; }
/// <summary>
/// Total quantity of this freight item among all mass storage with networked stations
/// Hoppers do not contribute to network inventory.
/// </summary>
public int Inventory { get; }
/// <summary>
/// The sum of all demand across the network for this item
/// </summary>
public int Deficit { get; }
/// <summary>
/// The sum of all excess offered available for delivery to requesting stations
/// </summary>
public int Surplus { get; }
/// <summary>
/// Current stock of this item in transit in the freight system
/// </summary>
public int Stock { get; }
public FreightData(ItemBase item, int inv, int def, int sur, int stock)
{
FreightItem = item;
Inventory = inv;
Deficit = def;
Surplus = sur;
Stock = stock;
}
}