示例#1
0
        private bool ReadField(ObjectReader objectReader, Dictionary <TrackField, int> fieldValues, TrackField field)
        {
            string value = null;

            switch (field)
            {
            case TrackField.End:
                m_Script = Encoding.UTF8.GetBytes(_infoText);
                objectReader.Position--;
                return(false);

            case TrackField.Frames:
                fieldValues[field] = objectReader.ReadInt32();
                if (fieldValues[field] == 0)
                {
                    if (objectReader.ReadByte() != 255)
                    {
                        objectReader.BaseStream.Position--;
                    }
                }
                else if (!fieldValues.ContainsKey(TrackField.UnknownByte41))
                {
                    if (objectReader.ReadByte() != 32)
                    {
                        throw new InvalidDataException();
                    }

                    value = MxrAnimation.Read(objectReader, fieldValues[TrackField.Frames]);
                }
                break;

            case TrackField.Start:
                if (objectReader.ReadByte() != 1)
                {
                    throw new InvalidDataException();
                }
                return(true);

            case TrackField.UnknownByte41:
                fieldValues[field] = objectReader.ReadByte();
                break;

            case TrackField.UnknownByte48:
            case TrackField.UnknownByte49:
                string unknown48 = string.Empty;
                if (fieldValues.ContainsKey(TrackField.UnknownByte41))
                {
                    fieldValues.TryGetValue(TrackField.Type, out var resourceType);
                    while (true)
                    {
                        var objectType = (int)objectReader.ReadByte();
                        if (objectType == 255)
                        {
                            break;
                        }

                        if (objectType == 128)
                        {
                            objectType = objectReader.ReadInt32();
                        }

                        var objectCount = objectReader.ReadByte();
                        unknown48 += $"Unknown{objectType}[{objectCount}] = " + string.Join(", ",
                                                                                            Enumerable.Range(0, resourceType * objectCount).Select(e => objectReader.ReadSingle())) + Environment.NewLine;
                    }

                    value = unknown48.Length.ToString();
                    fieldValues[field] = unknown48.Length;
                }
                else
                {
                    fieldValues[field] = objectReader.ReadByte();
                }

                break;

            case TrackField.Name:
                value = MxrObjectReader.ReadString(objectReader);
                break;

            case TrackField.UnknownArray33:
            case TrackField.UnknownArray34:
            case TrackField.UnknownArray35:
            case TrackField.UnknownArray37:
            case TrackField.UnknownArray38:
            case TrackField.UnknownArray42:
                if (objectReader.ReadByte() != 0)
                {
                    throw new InvalidDataException();
                }
                var ints = Enumerable.Range(0, objectReader.ReadInt32())
                           .Select(i => (field == TrackField.UnknownArray34 || field == TrackField.UnknownArray35) ?
                                   objectReader.ReadInt32() : objectReader.ReadInt64())
                           .ToList();
                value = ints.Any() ? $"{ints.Count} {{\n    {string.Join(", ", ints)}\n}}" : "{ }";
                break;

            case TrackField.Type:
                fieldValues[field] = objectReader.ReadInt32();
                if (fieldValues.ContainsKey(TrackField.UnknownByte41))
                {
                    if (objectReader.ReadByte() != 255)
                    {
                        objectReader.BaseStream.Position--;
                    }
                }
                else
                {
                    if (objectReader.ReadByte() != (byte)TrackField.Index)
                    {
                        throw new InvalidDataException();
                    }

                    m_Name = ((MxrClassIDType)fieldValues[field]).ToString();
                    var objectIndex = objectReader.ReadInt32();

                    if (_objectsDic.TryGetValue(MxrSerializedFile.GetPathID(fieldValues[field], objectIndex), out var namedObject))
                    {
                        m_Name += $" {objectIndex} ({((NamedObject)namedObject).m_Name})";
                    }
                    else if (objectIndex != -1)
                    {
                        m_Name += $" {objectIndex}";
                    }

                    value = m_Name;
                }
                break;

            default:
                fieldValues[field] = objectReader.ReadInt32();
                break;
            }

            _infoText += $"{field} = {value ?? fieldValues[field].ToString()}\n";
            return(true);
        }
示例#2
0
    //Nexts goedzetten zodat ze goed op elkaar overlopen..
    public void SetNexts()
    {
        int highest_x = trackList.Aggregate((i1, i2) => i1.X > i2.X ? i1 : i2).X;
        int highest_y = trackList.Aggregate((i1, i2) => i1.Y > i2.Y ? i1 : i2).Y;

        for (int x_i = 0; x_i < highest_x; x_i++)
        {
            for (int y_i = 0; y_i <= highest_y; y_i++)
            {
                TrackField tempFieldStart = null;
                TrackField tempFieldNext  = null;
                if (y_i == 2)
                {
                    tempFieldStart = trackList.FirstOrDefault(f => f.X == x_i && f.Y == y_i);
                    tempFieldNext  = trackList.FirstOrDefault(f => f.X == x_i - 1 && f.Y == y_i);
                }
                else if (y_i == highest_y)
                {
                    tempFieldStart = trackList.FirstOrDefault(f => f.X == x_i && f.Y == y_i);
                    tempFieldNext  = trackList.FirstOrDefault(f => f.X == x_i - 1 && f.Y == y_i);
                }
                else
                {
                    tempFieldStart = trackList.FirstOrDefault(f => f.X == x_i && f.Y == y_i);
                    tempFieldNext  = trackList.FirstOrDefault(f => f.X == x_i + 1 && f.Y == y_i);
                }

                if (tempFieldNext != null && tempFieldStart != null)
                {
                    tempFieldStart.Next = tempFieldNext;
                }
            }
        }
        //de kolom omhoog
        trackList.First(v => v.X == 11 && v.Y == 2).Next = trackList.First(v => v.X == 10 && v.Y == 2);
        trackList.First(v => v.X == 11 && v.Y == 3).Next = trackList.First(v => v.X == 11 && v.Y == 2);
        trackList.First(v => v.X == 11 && v.Y == 4).Next = trackList.First(v => v.X == 11 && v.Y == 3);
        trackList.First(v => v.X == 11 && v.Y == 5).Next = trackList.First(v => v.X == 11 && v.Y == 4);

        //de bocht omlaag in de laatste rij/kolom
        trackList.First(v => v.X == 11 && v.Y == 8).Next = trackList.First(v => v.X == 11 && v.Y == 9);

        //koppel het schip aan het dek, schip is opgebouwd uit 3 vakken, middelste vak word de lading in geteld
        TrackField quayField = trackList.FirstOrDefault(v => v.X == 9 && v.Y == 2);

        if (quayField != null)
        {
            Quay quay = (Quay)quayField;     //kade gevonden, koppel het schip aan de kade
            quay.ship = trackList.FirstOrDefault(v => v.X == 9 && v.Y == 1);
        }


        //Bij een splitsing wordt er gekeken welke kant de wissel op staat voor de koppeling
        ChangeableTrack tempW = (RightChangeableTrack)trackList.First(v => v.X == 3 && v.Y == 5);

        if (tempW.IsUp)
        {
            trackList.First(v => v.X == 3 && v.Y == 4).Next = trackList.First(v => v.X == 3 && v.Y == 5);
        }
        else
        {
            trackList.First(v => v.X == 3 && v.Y == 6).Next = trackList.First(v => v.X == 3 && v.Y == 5);
        }
        tempW = (LeftChangeableTrack)trackList.First(v => v.X == 5 && v.Y == 5);
        if (tempW.IsUp)
        {
            trackList.First(v => v.X == 5 && v.Y == 5).Next = trackList.First(v => v.X == 5 && v.Y == 4);
            trackList.First(v => v.X == 5 && v.Y == 4).Next = trackList.First(v => v.X == 6 && v.Y == 4);
        }
        else
        {
            trackList.First(v => v.X == 5 && v.Y == 5).Next = trackList.First(v => v.X == 5 && v.Y == 6);
            trackList.First(v => v.X == 5 && v.Y == 6).Next = trackList.First(v => v.X == 6 && v.Y == 6);
        }
        tempW = (RightChangeableTrack)trackList.First(v => v.X == 6 && v.Y == 7);
        if (tempW.IsUp)
        {
            trackList.First(v => v.X == 6 && v.Y == 6).Next = trackList.First(v => v.X == 6 && v.Y == 7);
        }
        else
        {
            trackList.First(v => v.X == 6 && v.Y == 8).Next = trackList.First(v => v.X == 6 && v.Y == 7);
        }
        tempW = (LeftChangeableTrack)trackList.First(v => v.X == 8 && v.Y == 7);
        if (tempW.IsUp)
        {
            trackList.First(v => v.X == 8 && v.Y == 7).Next = trackList.First(v => v.X == 8 && v.Y == 6);
            trackList.First(v => v.X == 8 && v.Y == 6).Next = trackList.First(v => v.X == 9 && v.Y == 6);
        }
        else
        {
            trackList.First(v => v.X == 8 && v.Y == 7).Next = trackList.First(v => v.X == 8 && v.Y == 8);
            trackList.First(v => v.X == 8 && v.Y == 8).Next = trackList.First(v => v.X == 9 && v.Y == 8);
        }
        tempW = (RightChangeableTrack)trackList.First(v => v.X == 9 && v.Y == 5);
        if (tempW.IsUp)
        {
            trackList.First(v => v.X == 9 && v.Y == 4).Next = trackList.First(v => v.X == 9 && v.Y == 5);
        }
        else
        {
            trackList.First(v => v.X == 9 && v.Y == 6).Next = trackList.First(v => v.X == 9 && v.Y == 5);
        }
    }