public static Crush Load(DocumentParser file) { Crush crush = new Crush { SoftnessFactor = file.ReadSingle(), FoldFactor = file.ReadVector2(), WibbleFactor = file.ReadSingle(), LimitDeviant = file.ReadSingle(), SplitChance = file.ReadSingle(), MinYFoldDown = file.ReadSingle() }; int pointCount = file.ReadInt(); for (int i = 0; i < pointCount; i++) { crush.Points.Add(CrushPoint.Load(file)); } return(crush); }
public static Car Load(string path, bool suppressFolderCheck) { DocumentParser file = new DocumentParser(path); Car car = new Car { Name = file.ReadLine() }; if (!suppressFolderCheck) { if (string.Compare(Path.GetFileName(path).ToUpper(), car.Name) != 0) { Logger.LogToFile(Logger.LogLevel.Error, "Not a valid Carmageddon car .txt file, expected {0} but found {1}", Path.GetFileName(path).ToUpper(), car.Name); return(null); } } if (file.ReadLine() != "START OF DRIVABLE STUFF") { Logger.LogToFile(Logger.LogLevel.Error, "Expected \"{0}\", didn't get it. Are you sure this is a Car.TXT file?", "START OF DRIVABLE STUFF"); return(null); } car.DriversHeadOffset = file.ReadVector3(); car.DriversHeadTurnAngles = file.ReadVector2(); car.MirrorCamera = file.ReadVector4(); car.PratcamBorders = file.ReadStrings(); if (file.ReadLine() != "END OF DRIVABLE STUFF") { Logger.LogToFile(Logger.LogLevel.Error, "Expected \"{0}\", didn't get it. Are you sure this is a Car.TXT file?", "END OF DRIVABLE STUFF"); return(null); } car.EngineNoises = file.ReadInts(); car.Stealworthy = file.ReadLine().ToLower() == "stealworthy"; car.ImpactTop = ImpactSpec.Load("top", file); car.ImpactBottom = ImpactSpec.Load("bottom", file); car.ImpactLeft = ImpactSpec.Load("left", file); car.ImpactRight = ImpactSpec.Load("right", file); car.ImpactFront = ImpactSpec.Load("front", file); car.ImpactBack = ImpactSpec.Load("rear", file); car.GridImages = file.ReadStrings(); int pixCount = file.ReadInt(); for (int i = 0; i < pixCount; i++) { car.PixelmapsLoMem.Add(file.ReadLine()); } pixCount = file.ReadInt(); for (int i = 0; i < pixCount; i++) { car.PixelmapsLoRes.Add(file.ReadLine()); } pixCount = file.ReadInt(); for (int i = 0; i < pixCount; i++) { car.PixelmapsHiRes.Add(file.ReadLine()); } int shadeCount = file.ReadInt(); for (int j = 0; j < shadeCount; j++) { car.ShadeTables.Add(file.ReadLine()); } int matCount = file.ReadInt(); for (int i = 0; i < matCount; i++) { car.MaterialsLoMem.Add(file.ReadLine()); } matCount = file.ReadInt(); for (int i = 0; i < matCount; i++) { car.MaterialsLoRes.Add(file.ReadLine()); } matCount = file.ReadInt(); for (int i = 0; i < matCount; i++) { car.MaterialsHiRes.Add(file.ReadLine()); } int modelCount = file.ReadInt(); for (int j = 0; j < modelCount; j++) { car.Models.Add(file.ReadLine()); } int actorCount = file.ReadInt(); for (int j = 0; j < actorCount; j++) { string[] s = file.ReadStrings(); car.ActorLODs.Add(s[0].ToInt()); car.Actors.Add(s[1]); } car.ReflectiveScreenMaterial = file.ReadLine(); int steerableWheelsCount = file.ReadInt(); for (int j = 0; j < steerableWheelsCount; j++) { car.SteerableWheels.Add(file.ReadInt()); } car.LeftFrontSuspension = file.ReadInts(); car.RightFrontSuspension = file.ReadInts(); car.LeftRearSuspension = file.ReadInts(); car.RightRearSuspension = file.ReadInts(); car.DrivenWheels = file.ReadInts(); car.NonDrivenWheels = file.ReadInts(); car.DrivenWheelDiameter = file.ReadSingle(); car.NonDrivenWheelDiameter = file.ReadSingle(); if (file.ReadLine() != "START OF FUNK") { Logger.LogToFile(Logger.LogLevel.Error, "Expected \"{0}\", didn't get it. Are you sure this is a Car.TXT file?", "START OF FUNK"); return(null); } while (file.PeekLine() != "END OF FUNK") { car.Funks.Add(Funk.Load(file)); if (file.PeekLine() == "NEXT FUNK") { file.ReadLine(); } } file.ReadLine(); if (file.ReadLine() != "START OF GROOVE") { Logger.LogToFile(Logger.LogLevel.Error, "Expected \"{0}\", didn't get it. Are you sure this is a Car.TXT file?", "START OF GROOVE"); return(null); } while (file.PeekLine() != "END OF GROOVE") { car.Grooves.Add(Groove.Load(file)); if (file.PeekLine() == "NEXT GROOVE") { file.ReadLine(); } } file.ReadLine(); for (int i = 0; i < car.Actors.Count; i++) { car.Crushes.Add(Crush.Load(file)); } car.MechanicsVersion = file.ReadLine().Replace("START OF MECHANICS STUFF version ", "", StringComparison.InvariantCultureIgnoreCase).ToInt(); car.LRWheelPos = file.ReadVector3(); car.RRWheelPos = file.ReadVector3(); car.LFWheelPos = file.ReadVector3(); car.RFWheelPos = file.ReadVector3(); car.CentreOfMass = file.ReadVector3(); switch (car.MechanicsVersion) { case 2: int boundingBoxCount = file.ReadInt(); for (int i = 0; i < boundingBoxCount; i++) { car.BoundingBoxes.Add(new BoundingBox { Min = file.ReadVector3(), Max = file.ReadVector3() }); } break; case 3: case 4: car.BoundingBoxes.Add(new BoundingBox { Min = file.ReadVector3(), Max = file.ReadVector3() }); int additionalPointsCount = file.ReadInt(); for (int i = 0; i < additionalPointsCount; i++) { car.AdditionalPoints.Add(file.ReadVector3()); } break; } car.MinimumTurningCircle = file.ReadSingle(); car.SuspensionGive = file.ReadVector2(); car.RideHeight = file.ReadSingle(); car.DampingFactor = file.ReadSingle(); car.Mass = file.ReadSingle(); car.SlipFrictionReductionFraction = file.ReadSingle(); if (car.MechanicsVersion == 4) { car.FrictionAngle = file.ReadVector3(); } else { car.FrictionAngle = (Vector3)file.ReadVector2(); } car.AngularMomentumProportions = file.ReadVector3(); car.TractionFractionalMultiplier = file.ReadSingle(); car.DownforceToWeightBalanceSpeed = file.ReadSingle(); car.BrakeMultiplier = file.ReadSingle(); car.BrakingStrengthMultiplier = file.ReadSingle(); car.RollingResistance = file.ReadVector2(); car.NumberOfGears = file.ReadInt(); car.TopGearRedlineSpeed = file.ReadInt(); car.TopGearAcceleration = file.ReadSingle(); if (file.ReadLine() != "END OF MECHANICS STUFF") { Logger.LogToFile(Logger.LogLevel.Error, "Expected \"{0}\", didn't get it. Are you sure this is a Car.TXT file?", "END OF MECHANICS STUFF"); return(null); } int shrapnelCount = file.ReadInt(); for (int i = 0; i < shrapnelCount; i++) { car.Shrapnel.Add(file.ReadLine()); } if (!file.EOF) { for (int i = 0; i < 12; i++) { car.FirePoints.Add(file.ReadInt()); } } if (!file.EOF) { Console.WriteLine("Still data to parse in {0}", path); } return(car); }