Exemplo n.º 1
0
        public override void SetSubject(Chunk xiChunk)
        {
            if (!(xiChunk is SteeringImageChunk))
              {
            mChunk = null;
              }
              else
              {
            mChunk = (SteeringImageChunk)xiChunk;
              }

              if (mLastSubject == mChunk)
              {
            return;
              }

              if (mChunk == null)
              {
            mMainForm.SteeringEditPictureBox.Image = null;
              }
              else
              {
            byte lType = mChunk.GetPixelType(mX, mY);
            mMainForm.SteeringTypeLabel.Text = GetSteeringDirectionName(lType);
            SetUpDropDown(lType);

            RefreshView();
              }

              mLastSubject = xiChunk;
        }
Exemplo n.º 2
0
        ///========================================================================
        /// Method : AddSteeringImage
        ///
        /// <summary>
        ///     Add a new Steering Image, returning the size of the added image in bytes
        /// </summary>
        /// <param name="xiSteeringImage"></param>
        /// <returns></returns>
        ///========================================================================
        public int AddSteeringImage(SteeringImageChunk xiSteeringImage)
        {
            Chunk[] lNewSteeringArray = new Chunk[SteeringImages.mChildren.Length + 1];
            Array.Copy(SteeringImages.mChildren, lNewSteeringArray, SteeringImages.mChildren.Length);
            lNewSteeringArray[SteeringImages.mChildren.Length] = xiSteeringImage;
            SteeringImages.mChildren = lNewSteeringArray;

            return(xiSteeringImage.Data.Length);
        }
Exemplo n.º 3
0
        private void FindUnusedSteeringImages()
        {
            //=======================================================================
            // Get a list of all steering images to start with.
            //=======================================================================
            for (int i = 0; i < SteeringImages.mChildren.Length; i++)
            {
                if (!(SteeringImages.mChildren[i] is SteeringImageChunk))
                {
                    continue;
                }

                SteeringImageChunk lSteeringImage = (SteeringImageChunk)SteeringImages.mChildren[i];
                mUnusedSteeringImages[i] = lSteeringImage;
            }

            //=======================================================================
            // Now remove all used steering images.
            //=======================================================================
            foreach (FlatChunk lFlat in Flats)
            {
                if (lFlat.TexMetaData == null)
                {
                    continue;
                }

                for (int x = 0; x < lFlat.Width; x++)
                {
                    for (int y = 0; y < lFlat.Height; y++)
                    {
                        int lSteeringId = lFlat.TexMetaData[x][y][(byte)eTexMetaDataEntries.Steering];

                        if (mUnusedSteeringImages.ContainsKey(lSteeringId))
                        {
                            mUnusedSteeringImages.Remove(lSteeringId);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Deserialise(Stream inStr, BinaryReader bin)
        {
            //header
            HeaderString1 = StreamUtils.ReadASCIINullTermString(inStr);
            HeaderString2 = StreamUtils.ReadASCIINullTermString(inStr);
            HeaderShort1  = bin.ReadInt16();
            HeaderShort2  = bin.ReadInt16();
            HeaderByte    = bin.ReadByte();
            int lSheetCount = bin.ReadInt16();

            Flats = new FlatChunk[lSheetCount];
            for (int i = 0; i < lSheetCount; i++)
            {
                Flats[i] = new FlatChunk(bin);
            }

            //key waypoints
            KeyWaypoints = new KeyWaypointsChunk(bin);

            //now the first set of images. I don't really know
            //what these do. They might be referred to by TexMetaData[7]
            short steeringImgCount = bin.ReadInt16();

            SteeringImageChunk[] steeringImages = new SteeringImageChunk[steeringImgCount];
            for (int i = 0; i < steeringImgCount; i++)
            {
                steeringImages[i] = new SteeringImageChunk(i, inStr);
            }
            this.SteeringImages = new GroupingChunk("SteeringImages", steeringImages);

            //now some camera positions:
            short cameraPositionCount = bin.ReadInt16();

            CameraPosChunk[] cameraPositions = new CameraPosChunk[cameraPositionCount];
            for (int i = 0; i < cameraPositionCount; i++)
            {
                cameraPositions[i] = new CameraPosChunk(i, bin);
            }
            this.CameraPositions = new GroupingChunk("CameraPositions", cameraPositions);

            //now the bump map prototypes. These are referred to by TexMetaData[6]
            short bumpImgCount = bin.ReadInt16();

            BumpImageChunk[] bumpImages = new BumpImageChunk[bumpImgCount];
            for (int i = 0; i < bumpImgCount; i++)
            {
                bumpImages[i] = new BumpImageChunk(i, inStr);
            }
            this.BumpImages = new GroupingChunk("BumpImages", bumpImages);

            //now trailing zeroes:
            int lNextByte;

            while (-1 != (lNextByte = inStr.ReadByte()))
            {
                if (lNextByte != 0)
                {
                    throw new DeserialisationException(string.Format("Expecting SHET to be followed by a block of zeroes. Found {0}", lNextByte), inStr.Position);
                }
                TrailingZeroByteCount++;
            }
        }
Exemplo n.º 5
0
 public void CopyFrom(SteeringImageChunk xiFrom)
 {
     Array.Copy(xiFrom.Data, this.Data, Data.Length);
 }
Exemplo n.º 6
0
            public bool MatchToSteeringImage(SteeringImageChunk xiSteeringImage)
            {
                eOrientation lOriginalOrientation = Orientation;

                for (int lOrientation = (int)eOrientation.North; (int)lOrientation <= (int)eOrientation.West; lOrientation++)
                {
                  RotateTo((eOrientation)lOrientation);

                  // y needs to be flipped.
                  if (xiSteeringImage.GetPixelType(X, (FlatChunk.STEERINGDIMENSION - 1) - Y) == (byte)Direction)
                  {
                return true;
                  }
                }

                RotateTo(lOriginalOrientation);
                return false;
            }
Exemplo n.º 7
0
        ///========================================================================
        /// Method : UpdateSteeringPixel
        /// 
        /// <summary>
        /// 	Update an individual pixel in the steering maps.
        /// 
        ///   Note that we don't just blindly accept the new value supplied - 
        ///   we assume it's relative to orientation 4, and if this square's
        ///   orientation is different we rotate it first.
        /// </summary>
        /// <param name="xiTexX"></param>
        /// <param name="xiTexY"></param>
        /// <param name="xiSteeringPxX"></param>
        /// <param name="xiSteeringPxY"></param>
        /// <param name="xiNewVal"></param>
        ///========================================================================
        private void UpdateSteeringPixel(
            int xiTexX,  //the x-offset of the tex square in the grid
            int xiTexY,
            int xiSteeringPxX, //the x-offset of the steering pixel in the square
            int xiSteeringPxY,
            byte xiNewVal)
        {
            byte lSteeringImageIdx = mSubject.TexMetaData[xiTexX][xiTexY][(int)eTexMetaDataEntries.Steering];
              byte lOrientation = mSubject.TexMetaData[xiTexX][xiTexY][(int)eTexMetaDataEntries.Orientation];

              if (lSteeringImageIdx >= mSteeringImageUsageCountArray.Length)
              {
            MessageBox.Show("Cannot edit that steering square: it indexes a non-existant steering image. Please edit it numerically first");
            return;
              }

              //=======================================================================
              // Re-orient the target value based on the actual orientation of the
              // square. Note that bytes wrap round from 0 to 255 if you add or subtract
              // to give an out-of-range value.
              //=======================================================================
              if (lOrientation > 0 && lOrientation < 4)
              {
            xiNewVal -= (byte)(16 - lOrientation * 4);

            if (xiNewVal >= 16)
            {
              xiNewVal += 16;
            }
              }
              else if (lOrientation == 0 && xiNewVal > 0)
              {
            xiNewVal = (byte)(16 - xiNewVal);
              }

              //how to update the steering pix depends on how many tex squares
              //use that steering pix
              switch (mSteeringImageUsageCountArray[lSteeringImageIdx])
              {
            case 0:
              throw new Exception("Interal error: unreachable statement!");

            case 1:
              SteeringImageChunk lSteeringChunk = mMainForm.CurrentLevel.GetSteeringImageById(lSteeringImageIdx);
              lSteeringChunk.SetPixelType(xiSteeringPxX, xiSteeringPxY, xiNewVal);
              break;

            default: // i.e. > 1
              SHETChunk lShet = mMainForm.CurrentLevel.SHET;
              SteeringImageChunk lNewSteering = null;
              int lNewSteeringId = -1;

              if (lShet.UnusedSteeringImages.Count == 0)
              {
            //=================================================================
            // Create a new steering image
            //=================================================================
            lNewSteeringId = lShet.SteeringImages.mChildren.Length;
            lNewSteering = new SteeringImageChunk(lNewSteeringId);
            int lSizeIncrease = lShet.AddSteeringImage(lNewSteering);
            lShet.TrailingZeroByteCount -= lSizeIncrease;

            if (lShet.TrailingZeroByteCount < 0)
            {
              MessageBox.Show(string.Format(
                "WARNING: You have just run out of space in your level file - you will need to free up {0} bytes before you can save your changes.",
                -lShet.TrailingZeroByteCount));
            }

            //=================================================================
            // Update our usage count array to include the new steering image
            //=================================================================
            int[] lNewSteeringImageUsageCountArray = new int[lNewSteeringId + 1];
            Array.Copy(mSteeringImageUsageCountArray, lNewSteeringImageUsageCountArray, mSteeringImageUsageCountArray.Length);
            mSteeringImageUsageCountArray = lNewSteeringImageUsageCountArray;
              }
              else
              {
            //=================================================================
            // Find the first unused steering image and use that
            //=================================================================
            foreach (DictionaryEntry lEntry in lShet.UnusedSteeringImages)
            {
              lNewSteeringId = (int)lEntry.Key;
              lNewSteering = (SteeringImageChunk)lEntry.Value;
              break;
            }

            lShet.UnusedSteeringImages.Remove(lNewSteeringId);
              }

              //===================================================================
              // Update the steering image with the desired contents, and update
              // the terrain square to use it
              //===================================================================
              SteeringImageChunk lOldSteering = mMainForm.CurrentLevel.GetSteeringImageById(lSteeringImageIdx);
              lNewSteering.CopyFrom(lOldSteering);
              lNewSteering.SetPixelType(xiSteeringPxX, xiSteeringPxY, xiNewVal);
              mSubject.TexMetaData[xiTexX][xiTexY][(int)eTexMetaDataEntries.Steering]
               = (byte)lNewSteeringId;
              mSteeringImageUsageCountArray[lSteeringImageIdx]--;
              mSteeringImageUsageCountArray[lNewSteeringId]++;
              break;
              }
        }
Exemplo n.º 8
0
        private void SetRespawnPosition(
            int x,
            int y,
            RespawnSetting xiRespawnSetting)
        {
            SHETChunk lShet = mMainForm.CurrentLevel.SHET;

              // eDirection.None is used to mean 'no respawn allowed', which is coded
              // on a different metadata sheet.
              if (xiRespawnSetting.Direction == eDirection.None)
              {
            mSubject.TexMetaData[x][y][(byte)eTexMetaDataEntries.Behaviour] = FlatChunk.BEHAVIOUR_DEFAULTNORESPAWN;
            return;
              }
              else if (Array.IndexOf(sNoRespawnValues, mSubject.TexMetaData[x][y][(byte)eTexMetaDataEntries.Behaviour]) >= 0)
              {
            mSubject.TexMetaData[x][y][(byte)eTexMetaDataEntries.Behaviour] = FlatChunk.BEHAVIOUR_DEFAULT;
              }

              // Find a steering image which can be used for this direction, at one of the four orientations
              int lSteeringId = FindSteeringImageMatchingDirection(ref xiRespawnSetting);

              if (lSteeringId == int.MinValue)
              {
            xiRespawnSetting.RotateTo(eOrientation.North);

            if (lShet.UnusedSteeringImages.Count == 0)
            {
              lSteeringId = lShet.SteeringImages.mChildren.Length;
              SteeringImageChunk lNewSteeringImage = new SteeringImageChunk(
            lSteeringId,
            (byte)xiRespawnSetting.Direction);
              int lSizeIncrease = lShet.AddSteeringImage(lNewSteeringImage);
              lShet.TrailingZeroByteCount -= lSizeIncrease;

              if (lShet.TrailingZeroByteCount < 0)
              {
            MessageBox.Show(string.Format(
              "WARNING: You have just run out of space in your level file - you will need to free up {0} bytes before you can save your changes.",
              -lShet.TrailingZeroByteCount));
              }
            }
            else
            {
              foreach (DictionaryEntry lEntry in lShet.UnusedSteeringImages)
              {
            // Just get the first unused.
            lSteeringId = (int)lEntry.Key;
            SteeringImageChunk lSteeringImage = (SteeringImageChunk)lEntry.Value;
            lSteeringImage.FlushToValue((byte)xiRespawnSetting.Direction);
            break;
              }

              lShet.UnusedSteeringImages.Remove(lSteeringId);
            }
              }

              // Use 4 instead of 0 for orientation North, because orientation 0
              // reverses the directions...
              mSubject.TexMetaData[x][y][(byte)eTexMetaDataEntries.Orientation] =
               xiRespawnSetting.Orientation == eOrientation.North ? (byte)4 : (byte)xiRespawnSetting.Orientation;
              mSubject.TexMetaData[x][y][(byte)eTexMetaDataEntries.Steering] = (byte)lSteeringId;

              // Rotate back to north to set position (layer seven)
              xiRespawnSetting.RotateTo(eOrientation.North);
              byte lRespawnValue = PointToRespawnPos(new Point(xiRespawnSetting.X, xiRespawnSetting.Y));
              mSubject.TexMetaData[x][y][(byte)eTexMetaDataEntries.RespawnPos] = lRespawnValue;
        }
Exemplo n.º 9
0
 public void CopyFrom(SteeringImageChunk xiFrom)
 {
     Array.Copy(xiFrom.Data, this.Data, Data.Length);
 }
Exemplo n.º 10
0
        public void Deserialise(Stream inStr, BinaryReader bin)
        {
            //header
              HeaderString1 = StreamUtils.ReadASCIINullTermString(inStr);
              HeaderString2 = StreamUtils.ReadASCIINullTermString(inStr);
              HeaderShort1 = bin.ReadInt16();
              HeaderShort2 = bin.ReadInt16();
              HeaderByte = bin.ReadByte();
              int lSheetCount = bin.ReadInt16();

              Flats = new FlatChunk[lSheetCount];
              for (int i = 0; i < lSheetCount; i++)
              {
            Flats[i] = new FlatChunk(bin);
              }

              //key waypoints
              KeyWaypoints = new KeyWaypointsChunk(bin);

              //now the first set of images. I don't really know
              //what these do. They might be referred to by TexMetaData[7]
              short steeringImgCount = bin.ReadInt16();
              SteeringImageChunk[] steeringImages = new SteeringImageChunk[steeringImgCount];
              for (int i = 0; i < steeringImgCount; i++)
              {
            steeringImages[i] = new SteeringImageChunk(i, inStr);
              }
              this.SteeringImages = new GroupingChunk("SteeringImages", steeringImages);

              //now some camera positions:
              short cameraPositionCount = bin.ReadInt16();
              CameraPosChunk[] cameraPositions = new CameraPosChunk[cameraPositionCount];
              for (int i = 0; i < cameraPositionCount; i++)
              {
            cameraPositions[i] = new CameraPosChunk(i, bin);
              }
              this.CameraPositions = new GroupingChunk("CameraPositions", cameraPositions);

              //now the bump map prototypes. These are referred to by TexMetaData[6]
              short bumpImgCount = bin.ReadInt16();
              BumpImageChunk[] bumpImages = new BumpImageChunk[bumpImgCount];
              for (int i = 0; i < bumpImgCount; i++)
              {
            bumpImages[i] = new BumpImageChunk(i, inStr);
              }
              this.BumpImages = new GroupingChunk("BumpImages", bumpImages);

              //now trailing zeroes:
              int lNextByte;
              while (-1 != (lNextByte = inStr.ReadByte()))
              {
            if (lNextByte != 0) throw new DeserialisationException(string.Format("Expecting SHET to be followed by a block of zeroes. Found {0}", lNextByte), inStr.Position);
            TrailingZeroByteCount++;
              }
        }
Exemplo n.º 11
0
        ///========================================================================
        /// Method : AddSteeringImage
        /// 
        /// <summary>
        /// 	Add a new Steering Image, returning the size of the added image in bytes
        /// </summary>
        /// <param name="xiSteeringImage"></param>
        /// <returns></returns>
        ///========================================================================
        public int AddSteeringImage(SteeringImageChunk xiSteeringImage)
        {
            Chunk[] lNewSteeringArray = new Chunk[SteeringImages.mChildren.Length + 1];
              Array.Copy(SteeringImages.mChildren, lNewSteeringArray, SteeringImages.mChildren.Length);
              lNewSteeringArray[SteeringImages.mChildren.Length] = xiSteeringImage;
              SteeringImages.mChildren = lNewSteeringArray;

              return xiSteeringImage.Data.Length;
        }