Example #1
0
        /// <summary>
        /// Creates an instance of BlockFaceEdge
        /// </summary>
        /// <param name="value">The value read from the original map format, it will construct the Block with the correct values.</param>
        public BlockFaceLid(ushort value) : base(value)
        {
            Boolean bit10 = BitHelper.CheckBit(value, 10);
            Boolean bit11 = BitHelper.CheckBit(value, 11);

            if (!bit10 && !bit11)
            {
                LightningLevel = 0;
                return;
            }
            if (bit10 && !bit11)
            {
                LightningLevel = 1;
                return;
            }
            if (!bit10 && bit11)
            {
                LightningLevel = 2;
                return;
            }
            if (bit10 && bit11)
            {
                LightningLevel = 3;
                return;
            }
        }
Example #2
0
        public void ParseSlope(byte type)
        {
            if (type == 0)
            {
                return;
            }

            int groundType = 0;

            groundType += (type & 1);
            groundType += (type & 2);
            GroundType  = (GroundType)groundType;

            if (type < 4)
            {
                return;
            }

            int slopeType = 0;

            for (int i = 2; i < 8; i++)
            {
                if (BitHelper.CheckBit(type, i))
                {
                    slopeType += (int)Math.Pow(2, i - 2);
                }
            }
            SlopeType = (SlopeType)slopeType;

            //make some corrections to the collision bits.
            switch (SlopeType)
            {
            case SlopeType.DiagonalFacingUpLeft:
            case SlopeType.DiagonalFacingDownLeft:
            case SlopeType.DiagonalSlopeFacingUpLeft:
            case SlopeType.DiagonalSlopeFacingDownLeft:
            case SlopeType.DiagonalFacingUpRight:
            case SlopeType.DiagonalFacingDownRight:
            case SlopeType.DiagonalSlopeFacingUpRight:
            case SlopeType.DiagonalSlopeFacingDownRight:
            case SlopeType.PartialBlockLeft:
            case SlopeType.PartialBlockRight:
            case SlopeType.PartialBlockTop:
            case SlopeType.PartialBlockBottom:
            case SlopeType.PartialBlockTopLeft:
            case SlopeType.PartialBlockTopRight:
            case SlopeType.PartialBlockBottomRight:
            case SlopeType.PartialBlockBottomLeft:
            case SlopeType.PartialCentreBlock:
                Top.Wall          = Top;
                Top.BulletWall    = Top;
                Bottom.Wall       = Bottom;
                Bottom.BulletWall = Bottom;
                Left.Wall         = Left;
                Left.BulletWall   = Left;
                Right.Wall        = Right;
                Right.BulletWall  = Right;
                break;
            }
        }
Example #3
0
        /// <summary>
        /// Creates an instance of BlockFace.
        /// </summary>
        /// <param name="value">The value read from the original map format, it will construct the Block with the correct values.</param>
        protected BlockFace(ushort value)
        {
            if (value == 0)
            {
                return;
            }

            //parse ushort value
            //Bits 0-9: Tile number
            uint tile = 0;

            for (var i = 0; i < 10; i++)
            {
                tile = tile + (value & (uint)Math.Pow(2, i));
            }
            TileNumber = tile;

            Flat = BitHelper.CheckBit(value, 12); //Bit 12
            Flip = BitHelper.CheckBit(value, 13); //Bit 13

            Boolean bit14 = BitHelper.CheckBit(value, 14);
            Boolean bit15 = BitHelper.CheckBit(value, 15);

            if (!bit14 && !bit15)
            {
                Rotation = RotationType.RotateNone;
                return;
            }
            if (bit14 && !bit15)
            {
                Rotation = RotationType.Rotate90;
                return;
            }
            if (!bit14 && bit15)
            {
                Rotation = RotationType.Rotate180;
                return;
            }
            if (bit14 && bit15)
            {
                Rotation = RotationType.Rotate270;
                return;
            }
        }
Example #4
0
        public BlockFaceLid(ushort value) : base(value)
        {
            var bit10 = BitHelper.CheckBit(value, 10);
            var bit11 = BitHelper.CheckBit(value, 11);

            if (!bit10 && !bit11)
            {
                LightningLevel = 0;
            }
            if (bit10 && !bit11)
            {
                LightningLevel = 1;
            }
            if (!bit10 && bit11)
            {
                LightningLevel = 2;
            }
            if (bit10 && bit11)
            {
                LightningLevel = 3;
            }
        }
Example #5
0
        public static Block Build(BlockStructure blockStructure, Vector3 position)
        {
            var slopeType = 0;

            for (var i = 2; i < 8; i++)
            {
                if (BitHelper.CheckBit(blockStructure.SlopeType, i))
                {
                    slopeType += (int)Math.Pow(2, i - 2);
                }
            }

            foreach (var block in _blocks)
            {
                if (block.IsSlopeOf((SlopeType)slopeType))
                {
                    return(block.DeepCopy(blockStructure, position));
                }
            }

            //return new CubeBlock(blockStructure, position);    //Hack until all the different _blocks are implemented.
            throw new NotSupportedException("Slope Type " + slopeType + " not implemented!"); // <- Must be this.
        }
Example #6
0
 public BlockFaceEdge(ushort value) : base(value)
 {
     Wall       = BitHelper.CheckBit(value, 10);
     BulletWall = BitHelper.CheckBit(value, 11);
 }
Example #7
0
        private static SerializableDictionary <int, CarInfo> ReadCars(BinaryReader reader, int chunkSize, IDictionary <int, List <int> > carSprites)
        {
            System.Diagnostics.Debug.WriteLine("Reading car infos...");
            var carInfoDict   = new SerializableDictionary <int, CarInfo>();
            var position      = 0;
            var currentSprite = 0;
            var modelList     = new List <int>();

            while (position < chunkSize)
            {
                var carInfo = new CarInfo {
                    Model = reader.ReadByte(), SpriteId = currentSprite
                };
                modelList.Add(carInfo.Model);
                var useNewSprite = reader.ReadByte();
                if (useNewSprite > 0)
                {
                    currentSprite++;
                    carSprites.Add(carInfo.SpriteId, modelList);
                    modelList = new List <int>();
                }
                carInfo.Width  = reader.ReadByte();
                carInfo.Height = reader.ReadByte();
                var numRemaps = reader.ReadByte();
                carInfo.Passengers        = reader.ReadByte();
                carInfo.Wreck             = reader.ReadByte();
                carInfo.Rating            = reader.ReadByte();
                carInfo.FrontWheelOffset  = reader.ReadSByte();
                carInfo.RearWheelOffset   = reader.ReadSByte();
                carInfo.FrontWindowOffset = reader.ReadSByte();
                carInfo.RearWindowOffset  = reader.ReadSByte();
                var infoFlag = reader.ReadByte();
                carInfo.InfoFlags = (CarInfoFlags)infoFlag;
                var infoFlag2        = reader.ReadByte();
                var infoFlags2Value0 = BitHelper.CheckBit(infoFlag2, 0);
                var infoFlags2Value1 = BitHelper.CheckBit(infoFlag2, 1);
                if (infoFlags2Value0)
                {
                    carInfo.InfoFlags += 0x100;
                }
                if (infoFlags2Value1)
                {
                    carInfo.InfoFlags += 0x200;
                }
                for (var i = 0; i < numRemaps; i++)
                {
                    carInfo.RemapList.Add(reader.ReadByte());
                }
                var numDoors = reader.ReadByte();
                for (var i = 0; i < numDoors; i++)
                {
                    var door = new DoorInfo {
                        X = reader.ReadSByte(), Y = reader.ReadSByte()
                    };
                    carInfo.Doors.Add(door);
                }
                if (!carInfoDict.Keys.Contains(carInfo.Model))
                {
                    carInfoDict.Add(carInfo.Model, carInfo);
                }
                position = position + 15 + numRemaps + numDoors * 2;
            }
            return(carInfoDict);
        }