-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStockReporter.cs
229 lines (212 loc) · 6.59 KB
/
StockReporter.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using System;
using UnityEngine;
using DV.Logic.Job;
// TODO: Learn the what and *why* of C# fields vs properties
namespace DVPathTracer
{
public class StockReporter
{
public TrainCar Target { get; private set; }
public string TargetID { get; private set; }
public string TargetType { get; private set; }
private string prevValues = "";
/**
* Rolling stock reporter, reports on the given train car (inc. locos, caboose)
*/
public StockReporter(TrainCar car)
{
Target = car;
TargetID = car.ID;
TargetType = GetCarType(car);
}
// C = 'Car' (includes locos)
// Cg = 'Cargo' loaded in car (if applicable)
public const string Headings = "CID,CType,CPosX,CPosY,CPosZ,CRotA,CSpd,C%,CgType,CgCat,Cg%";
public string Values
{
get
{
string newValues = $"{TargetID},{TargetType},{Position.x},{Position.y - BaseReporter.seaLevel},{Position.z},{Rotation},{SpeedUnits(Speed)},{CarHealth}";
if (Target.LoadedCargo == CargoType.None)
{
if (CargoTypes.Military1CarContainers.Contains(CargoTypes.CarTypeToContainerType[Target.carType]))
{
// Military 1 licence allows LH jobs of military cars - it's more interesting to class as MIL1 despite being empty
newValues += ",None,MIL1,N/A";
}
else
{
// Loco, caboose, or otherwise unloaded car
newValues += ",None,N/A,N/A";
}
}
else
{
newValues += $",{Cargo},{CargoCategory},{CargoHealth}";
}
if (Main.verboseTracing || newValues != prevValues)
{
prevValues = newValues;
return newValues;
}
return "";
}
}
public string Removed
{
get
{
return $"{TargetID},{TargetType},Removed,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A";
}
}
/**
* In-game speed - metres per second
*/
public float Speed
{
get
{
return Target.GetForwardSpeed();
}
}
/**
* Position in 3d space, no adjustments
*/
public Vector3 Position
{
get
{
return Target.transform.position - WorldMover.currentMove;
}
}
/**
* Rotation from map-North, in degrees
*/
public float Rotation
{
get
{
Transform locoTransform = Target.transform;
Vector3 planeRotation = Vector3.ProjectOnPlane(locoTransform.forward, Vector3.up);
float rotationAngle = Mathf.Atan2(planeRotation.x, planeRotation.z) * Mathf.Rad2Deg;
return rotationAngle >= 0 ? rotationAngle : 360 + rotationAngle;
}
}
/**
* Car health, %
*/
public float CarHealth
{
get
{
return Target.CarDamage.EffectiveHealthPercentage100Notation;
}
}
/**
* Cargo health, %
*/
public float CargoHealth
{
get
{
return Target.CargoDamage.EffectiveHealthPercentage100Notation;
}
}
/**
* In-game name of the cargo
*/
public string Cargo
{
get
{
return CargoTypes.GetCargoName(Target.LoadedCargo);
}
}
/**
* DVPT-specific human-readable category of loaded cargo for use in animator
* Assumes there is loaded cargo to categorise
*/
public string CargoCategory
{
get
{
// Mil>Haz if more than one apply
if (CargoTypes.Military3Cargo.Contains(Target.LoadedCargo))
{
return "MIL3";
}
if (CargoTypes.Military2Cargo.Contains(Target.LoadedCargo))
{
return "MIL2";
}
if (CargoTypes.Hazmat3Cargo.Contains(Target.LoadedCargo))
{
return "HZMT3";
}
if (CargoTypes.Hazmat2Cargo.Contains(Target.LoadedCargo))
{
return "HZMT2";
}
if (CargoTypes.Hazmat1Cargo.Contains(Target.LoadedCargo))
{
return "HZMT1";
}
return "Inert";
}
}
/**
* Returns the given speed in m/s converted to mph or kph as appropriate
*/
public static float SpeedUnits(float speed)
{
if (Main.settings.mph)
{
return speed * (float) 2.23694;
}
return speed * (float) 3.6;
}
/**
* Returns a reader-friendly descriptor of the type of car
*/
private string GetCarType(TrainCar car)
{
string type = "";
if (Main.cclEnabled)
{
try
{
type = CCLInterface.CustomCarIndentifier(car.carType);
}
catch //(Exception e)
{
//Main.Log(e.ToString());
// It's either an error or just not CCL stock
// TODO: this better
}
}
if (type == "")
{
switch (car.carType)
{
case TrainCarType.LocoShunter:
type = "DE2";
break;
case TrainCarType.LocoSteamHeavy:
type = "SH282";
break;
case TrainCarType.LocoDiesel:
type = "DE6";
break;
case TrainCarType.CabooseRed:
type = "Caboose";
break;
case TrainCarType.NotSet:
default:
type = car.carType.ToString();
break;
}
}
return type;
}
}
}