Esempio n. 1
0
        public static Car Load(string path)
        {
            DocumentParser file = new DocumentParser(path);
            Car            car  = new Car();

            string version = file.ReadLine();

            if (!version.StartsWith("VERSION"))
            {
                Logger.LogToFile(Logger.LogLevel.Error, "Not a valid Carmageddon 2 car .txt file");
                return(null);
            }

            car.Version = version.Replace("VERSION ", "").ToInt();

            if (file.PeekLine() == "GIRL")
            {
                car.FemaleDriver = true;
                file.ReadLine();
            }

            car.Name           = file.ReadLine();
            car.SoftnessFactor = file.ReadSingle();

            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 extraLevelsOfDetail = file.ReadInt();

            for (int j = 0; j < extraLevelsOfDetail; j++)
            {
                car.ExtraLevelsOfDetail.Add(file.ReadInt());
            }

            car.WAM = file.ReadLine();

            car.ReflectiveScreenMaterial = file.ReadLine();
            car.TransparencyOfWindscreen = file.ReadSingle();

            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();

            int _ = file.ReadLine().Replace("START OF MECHANICS STUFF version ", "", StringComparison.InvariantCultureIgnoreCase).ToInt();

            car.MinimumTurningCircle      = file.ReadSingle();
            car.BrakeMultiplier           = file.ReadSingle();
            car.BrakingStrengthMultiplier = file.ReadSingle();
            car.NumberOfGears             = file.ReadSingle();
            car.TopGearRedlineSpeed       = file.ReadSingle();
            car.TopGearAcceleration       = file.ReadSingle();

            car.RootPartType       = file.ReadEnum <PartType>();
            car.RootPartIdentifier = file.ReadLine();
            car.RootPartActor      = file.ReadLine();

            car.SubPartType = file.ReadEnum <PartType>();

            car.CentreOfMass = file.ReadVector3();
            car.Mass         = file.ReadSingle();
            car.AngularMomentumProportions    = file.ReadVector3();
            car.DownforceToWeightBalanceSpeed = file.ReadSingle();

            int numberOfWheels = file.ReadInt();

            for (int j = 0; j < numberOfWheels; j++)
            {
                Wheel wheel = new Wheel
                {
                    Type           = file.ReadEnum <Wheel.WheelType>(),
                    Identifier     = file.ReadLine(),
                    Actor          = file.ReadLine(),
                    Position       = file.ReadVector3(),
                    SteerableFlags = file.ReadInt(),
                    DrivenFlags    = file.ReadInt(),
                    SuspensionGive = file.ReadSingle(),
                    DampingFactor  = file.ReadSingle(),
                    SlipFrictionReductionFraction = file.ReadSingle(),
                    FrictionAngles = file.ReadVector2(),
                    TractionFractionalMultiplier = file.ReadSingle(),
                    RollingResistance            = file.ReadSingle()
                };

                car.Wheels.Add(wheel);
            }

            int boundingShapes = file.ReadInt();

            for (int j = 0; j < boundingShapes; j++)
            {
                BoundingShape shape = new BoundingShape
                {
                    Type = file.ReadEnum <BoundingShape.BoundingShapeType>()
                };

                int shapePoints = file.ReadInt();

                for (int k = 0; k < shapePoints; k++)
                {
                    shape.Points.Add(file.ReadVector3());
                }

                car.BoundingShapes.Add(shape);
            }

            int subParts = file.ReadInt();

            for (int j = 0; j < subParts; j++)
            {
                throw new NotImplementedException("subparts?!");
            }

            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());
            }

            for (int i = 0; i < 12; i++)
            {
                car.FirePoints.Add(file.ReadInt());
            }

            while (file.PeekLine() != "END")
            {
                string keyWord = file.ReadLine();

                switch (keyWord)
                {
                case "CAMERA_POSITIONS":
                    car.Keywords.Add(new CameraPosition
                    {
                        BumperPosition  = file.ReadVector3(),
                        CockpitPosition = file.ReadVector3()
                    });
                    break;

                case "CAMERA_TURN_OFF_MATERIALS":
                {
                    CameraTurnOffMaterials ctom = new CameraTurnOffMaterials();

                    int materialCount = file.ReadInt();

                    for (int i = 0; i < materialCount; i++)
                    {
                        CameraTurnOffMaterialEntry ctomEntry = new CameraTurnOffMaterialEntry
                        {
                            MaterialName = file.ReadLine()
                        };

                        int entryCount = file.ReadInt();

                        for (int j = 0; j < entryCount; j++)
                        {
                            ctomEntry.Materials.Add(file.ReadLine());
                        }

                        ctom.Entries.Add(ctomEntry);
                    }

                    car.Keywords.Add(ctom);
                }
                break;

                default:
                    throw new NotImplementedException($"{keyWord} not supported!");
                }
            }

            return(car);
        }
Esempio n. 2
0
        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);
        }