|
| 1 | +using LibRun8.Common; |
| 2 | + |
| 3 | +namespace LibRun8.Formats |
| 4 | +{ |
| 5 | + public class CarSpewerDatabase : FileFormat |
| 6 | + { |
| 7 | + public List<CarSpewer> Spewers { get; set; } = new List<CarSpewer>(); |
| 8 | + public static CarSpewerDatabase Read(string path) |
| 9 | + { |
| 10 | + CarSpewerDatabase carSpewerDatabase = new CarSpewerDatabase(); |
| 11 | + using (FileStream fileStream = new FileStream(path, FileMode.Open)) |
| 12 | + { |
| 13 | + using (BinaryReader reader = new BinaryReader(fileStream)) |
| 14 | + { |
| 15 | + reader.ReadInt32(); // reserved |
| 16 | + var numOfSpewers = reader.ReadInt32(); |
| 17 | + for (int i = 0; i < numOfSpewers; i++) |
| 18 | + { |
| 19 | + carSpewerDatabase.Spewers.Add(CarSpewer.Read(reader)); |
| 20 | + } |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + return carSpewerDatabase; |
| 25 | + } |
| 26 | + |
| 27 | + public override void Write() |
| 28 | + { |
| 29 | + throw new NotImplementedException(); |
| 30 | + } |
| 31 | + |
| 32 | + public class CarSpewer |
| 33 | + { |
| 34 | + public int Int0 { get; set; } // Doesn't appear to ever be used |
| 35 | + public int RoadNodeIndex { get; set; } |
| 36 | + public int MaxNumCars { get; set; } |
| 37 | + public double MinTimeBetwixtSpew { get; set; } |
| 38 | + public double MaxTimeBetwixtSpew { get; set; } |
| 39 | + public float MaxSpeed { get; set; } |
| 40 | + public List<CarSpewStartPoint> CarSpewStartPoints { get; set; } = new List<CarSpewStartPoint>(); |
| 41 | + |
| 42 | + public static CarSpewer Read(BinaryReader reader) |
| 43 | + { |
| 44 | + CarSpewer carSpewer = new CarSpewer(); |
| 45 | + |
| 46 | + var num = reader.ReadInt32(); |
| 47 | + carSpewer.Int0 = reader.ReadInt32(); |
| 48 | + carSpewer.RoadNodeIndex = reader.ReadInt32(); |
| 49 | + carSpewer.MaxNumCars = reader.ReadInt32(); |
| 50 | + carSpewer.MinTimeBetwixtSpew = reader.ReadDouble(); |
| 51 | + carSpewer.MaxTimeBetwixtSpew = reader.ReadDouble(); |
| 52 | + if (num == 2) |
| 53 | + { |
| 54 | + carSpewer.MaxSpeed = reader.ReadSingle(); |
| 55 | + } |
| 56 | + var numOfSpewStartPoints = reader.ReadInt32(); |
| 57 | + for (int i = 0; i < numOfSpewStartPoints; i++) |
| 58 | + { |
| 59 | + carSpewer.CarSpewStartPoints.Add(CarSpewStartPoint.Read(reader)); |
| 60 | + } |
| 61 | + |
| 62 | + return carSpewer; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + public class CarSpewStartPoint |
| 67 | + { |
| 68 | + public Vector3 PosXYZ { get; set; } |
| 69 | + public TileIndex TileXZ { get; set; } |
| 70 | + public float Heading { get; set; } = -999f; |
| 71 | + |
| 72 | + public static CarSpewStartPoint Read(BinaryReader reader) |
| 73 | + { |
| 74 | + CarSpewStartPoint carSpewStartPoint = new CarSpewStartPoint(); |
| 75 | + |
| 76 | + reader.ReadInt32(); |
| 77 | + carSpewStartPoint.PosXYZ = Vector3.Read(reader); |
| 78 | + carSpewStartPoint.TileXZ = TileIndex.Read(reader); |
| 79 | + carSpewStartPoint.Heading = reader.ReadSingle(); |
| 80 | + |
| 81 | + return carSpewStartPoint; |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments