Skip to content

Commit 71a2329

Browse files
committed
start adding cargo offset editing for trainstation
1 parent 53ebfa8 commit 71a2329

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

Dat/Objects/TrainStationObject.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@ public enum TrainStationObjectFlags : uint8_t
1212
None = 0,
1313
Recolourable = 1 << 0,
1414
NoGlass = 1 << 1,
15-
};
15+
}
16+
17+
[TypeConverter(typeof(ExpandableObjectConverter))]
18+
[LocoStructSize(0x06)]
19+
public record CargoOffset(
20+
[property: LocoStructOffset(0x00)] Pos3 A,
21+
[property: LocoStructOffset(0x06)] Pos3 B
22+
) : ILocoStruct
23+
{
24+
public CargoOffset() : this(new Pos3(), new Pos3())
25+
{ }
26+
27+
public bool Validate() => true;
28+
}
1629

1730
[TypeConverter(typeof(ExpandableObjectConverter))]
1831
[LocoStructSize(0xAE)]
@@ -30,9 +43,9 @@ public record TrainStationObject(
3043
[property: LocoStructOffset(0x0C)] TrainStationObjectFlags Flags,
3144
[property: LocoStructOffset(0x0D)] uint8_t var_0D,
3245
[property: LocoStructOffset(0x0E), LocoStructVariableLoad, Browsable(false)] image_id Image,
33-
[property: LocoStructOffset(0x12), LocoArrayLength(TrainStationObject.MaxImageOffsets)] uint32_t[] ImageOffsets,
46+
[property: LocoStructOffset(0x12), LocoArrayLength(TrainStationObject.MaxImageOffsets), Browsable(false)] uint32_t[] ImageOffsets,
3447
[property: LocoStructOffset(0x22)] uint8_t CompatibleTrackObjectCount,
35-
[property: LocoStructOffset(0x23), LocoArrayLength(TrainStationObject.MaxNumCompatible)] object_id[] _Compatible,
48+
[property: LocoStructOffset(0x23), LocoArrayLength(TrainStationObject.MaxNumCompatible), Browsable(false)] object_id[] _Compatible, // only used for runtime loco, this isn't part of object 'definition'
3649
[property: LocoStructOffset(0x2A)] uint16_t DesignedYear,
3750
[property: LocoStructOffset(0x2C)] uint16_t ObsoleteYear,
3851
[property: LocoStructOffset(0x2E), LocoStructVariableLoad, LocoArrayLength(TrainStationObject.CargoOffsetBytesSize), Browsable(false)] uint8_t[] _CargoOffsetBytes,
@@ -45,10 +58,14 @@ public record TrainStationObject(
4558
public const int MaxNumCompatible = 7;
4659
public const int ManualPowerLength = 16;
4760
public const int CargoOffsetBytesSize = 16;
61+
public const int MaxStationCargoDensity = 15;
62+
4863
public uint8_t[][][] CargoOffsetBytes { get; set; }
4964

5065
public uint8_t[][] ManualPower { get; set; }
5166

67+
public CargoOffset[] CargoOffsets { get; init; } = Enumerable.Repeat(new CargoOffset(), 15).ToArray();
68+
5269
public ReadOnlySpan<byte> Load(ReadOnlySpan<byte> remainingData)
5370
{
5471
// compatible
@@ -104,7 +121,7 @@ public ReadOnlySpan<byte> Save()
104121
{
105122
using (var ms = new MemoryStream())
106123
{
107-
// compatible
124+
// compatible track objects
108125
foreach (var co in CompatibleTrackObjects)
109126
{
110127
ms.Write(co.Write());

Dat/Types/Typedefs.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
global using char_t = System.Byte;
2+
global using coord_t = System.Int16;
23
global using image_id = System.UInt32;
34
global using int16_t = System.Int16;
45
global using int32_t = System.Int32;
@@ -21,8 +22,19 @@ namespace OpenLoco.Dat.Types
2122
[TypeConverter(typeof(ExpandableObjectConverter))]
2223
[LocoStructSize(0x04)]
2324
public record Pos2(
24-
[property: LocoStructOffset(0x00)] int16_t X,
25-
[property: LocoStructOffset(0x02)] int16_t Y
25+
[property: LocoStructOffset(0x00)] coord_t X = 0,
26+
[property: LocoStructOffset(0x02)] coord_t Y = 0
27+
) : ILocoStruct
28+
{
29+
public bool Validate() => true;
30+
}
31+
32+
[TypeConverter(typeof(ExpandableObjectConverter))]
33+
[LocoStructSize(0x06)]
34+
public record Pos3(
35+
[property: LocoStructOffset(0x00)] coord_t X = 0,
36+
[property: LocoStructOffset(0x02)] coord_t Y = 0,
37+
[property: LocoStructOffset(0x04)] coord_t Z = 0
2638
) : ILocoStruct
2739
{
2840
public bool Validate() => true;

0 commit comments

Comments
 (0)