Esempio n. 1
0
        internal void MouseOverHouseObject(int houseObjectOffset)
        {
            HouseObjectDefinition houseObjectDefinition = houseObjects[houseObjectOffset];

            if (houseObjectDefinition != this.currentMouseOverObject)
            {
                this.currentMouseOverObject = houseObjectDefinition;
                this.label.Text             = houseObjectDefinition.pathName;
                this.label.Invalidate();
            }
        }
Esempio n. 2
0
    public static HouseObjectDefinition[] ParseMap(String[] objectStrings)
    {
        if (gameInstallPath == null)
        {
            throw NotLoaded();
        }

        HouseObjectDefinition[] mapObjects = new HouseObjectDefinition[1024];

        for (int objIndex = 0; objIndex < objectStrings.Length; objIndex++)
        {
            String objectString = objectStrings[objIndex];

            String extra = null;
            for (int i = 0; i < objectString.Length; i++)
            {
                Char c = objectString[i];
                if (c < '0' || c > '9')
                {
                    extra        = objectString.Substring(i);
                    objectString = objectString.Remove(i);
                    Console.WriteLine("EXTRA: '{0}'", extra);
                    break;
                }
            }
            UInt16 id = UInt16.Parse(objectString);

            HouseObjectDefinition houseObjectDefinition;
            if (!houseObjectDefinitionMap.TryGetValue(id, out houseObjectDefinition))
            {
                throw new FormatException(String.Format("Unknown object id '{0}'", id));
            }

            if (extra == null)
            {
                mapObjects[objIndex] = houseObjectDefinition;
            }
            else
            {
                mapObjects[objIndex] = new HouseObjectDefinitionWithExtra(houseObjectDefinition, extra);
            }
        }

        return(mapObjects);
    }
Esempio n. 3
0
            protected override void OnPaint(PaintEventArgs pe)
            {
                for (int boxY = 0; boxY < size; boxY++)
                {
                    Int32 houseObjectOffset = (31 - (y + boxY)) * 32;
                    Int32 controlRowOffset  = boxY * house.tileSize;
                    Int32 controlColOffset  = 0;
                    for (int boxX = 0; boxX < size; boxX++)
                    {
                        pe.Graphics.DrawRectangle(Pens.Black, new Rectangle(controlColOffset, controlRowOffset, house.tileSize, house.tileSize));
                        //pe.Graphics.DrawString(String.Format("Box {0} {1}", x, y), this.Font, Brushes.Black, new PointF(0, 0));
                        HouseObjectDefinition houseObject =
                            house.houseObjects[houseObjectOffset + (x + boxX)];
                        pe.Graphics.DrawImage(houseObject.Bitmap, controlColOffset, controlRowOffset, house.tileSize, house.tileSize);
                        //new Point(controlColOffset, controlRowOffset));

                        if (houseObject.id == 999)
                        {
                            pe.Graphics.DrawRectangle(house.goalPen,
                                                      controlColOffset + house.quarterTileSize / 2,
                                                      controlRowOffset + house.quarterTileSize / 2,
                                                      house.tileSize - house.quarterTileSize,
                                                      house.tileSize - house.quarterTileSize);
                        }

                        String extra = houseObject.Extra;
                        if (extra != null)
                        {
                            pe.Graphics.FillRectangle(SemiTransparentBrush, 0, 0, extra.Length * Font.Size, Font.GetHeight());
                            pe.Graphics.DrawString(extra, Font, Brushes.Black, new PointF(0, 0));
                        }


                        controlColOffset += house.tileSize;
                    }
                }
            }
Esempio n. 4
0
    public static void Load(String gameInstallPath)
    {
        try
        {
            if (CDLoader.gameInstallPath != null)
            {
                throw new InvalidOperationException("CDLoader.Load has already been called");
            }
            CDLoader.gameInstallPath = gameInstallPath;

            if (!Directory.Exists(gameInstallPath))
            {
                throw new InvalidOperationException(String.Format("Game Directory '{0}' does not exist", gameInstallPath));
            }

            houseObjectsPath = Path.Combine(gameInstallPath, Path.Combine("gameElements", "houseObjects"));
            if (!Directory.Exists(houseObjectsPath))
            {
                throw new InvalidOperationException(String.Format("Game Elements Directory '{0}' does not exist", houseObjectsPath));
            }

            ByteBuffer imageLoadBuffer = new ByteBuffer(4096, 2048);

            String[] objectFullPathNames = Directory.GetDirectories(houseObjectsPath);
            for (int objIndex = 0; objIndex < objectFullPathNames.Length; objIndex++)
            {
                String objectFullPathName = objectFullPathNames[objIndex];
                String objectPathName     = Path.GetFileName(objectFullPathName);

                //
                // Read Object States and Images
                //
                Dictionary <Byte, HouseObjectStateDefinition> states = new Dictionary <Byte, HouseObjectStateDefinition>();
                String[] stateFullPathNames = Directory.GetDirectories(objectFullPathName);
                for (int stateIndex = 0; stateIndex < stateFullPathNames.Length; stateIndex++)
                {
                    String stateFullPathName = stateFullPathNames[stateIndex];
                    String stateName         = Path.GetFileName(stateFullPathName);
                    Byte   stateID           = Byte.Parse(stateName);

                    states.Add(stateID, LoadState(stateID, stateFullPathName, imageLoadBuffer));
                }


                //
                // Read Object Info
                //
                String infoFile = Path.Combine(objectFullPathName, "info.txt");
                if (!File.Exists(infoFile))
                {
                    throw new InvalidOperationException(String.Format(
                                                            "Missing 'info.txt' file in path '{0}'", houseObjectsPath));
                }

                UInt16 id;
                HouseObjectDefinition houseObjectDefinition;
                using (TextReader reader = new StreamReader(new FileStream(infoFile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                {
                    String idLine = reader.ReadLine();
                    if (idLine == null)
                    {
                        throw new InvalidOperationException(
                                  "info.txt file ended before the id was found");
                    }
                    id = UInt16.Parse(idLine);
                    houseObjectDefinition = new HouseObjectDefinition(id, objectPathName, states);
                }

                houseObjectDefinitions.Add(houseObjectDefinition);
                houseObjectDefinitionMap.Add(id, houseObjectDefinition);
            }
        }
        catch (Exception)
        {
            Reset();
            throw;
        }
    }
Esempio n. 5
0
 public HouseObjectDefinitionWithExtra(HouseObjectDefinition definition, String extra)
     : base(definition.id, definition.pathName, definition.states)
 {
     this.extra = extra;
 }
Esempio n. 6
0
        public HouseViewerForm()
        {
            InitializeComponent();


            Text = "Castle Doctine Robber";
            //Width = 1024;
            //Height = 1024;
            AutoSize     = true;
            AutoSizeMode = AutoSizeMode.GrowAndShrink;
            Location     = new Point(Location.X, 10);


            label = new Label();
            Controls.Add(label);
            label.Location  = new Point(3, 3);
            label.BackColor = Color.FromArgb(0x88, 0xFF, 0xFF, 0xFF);

            Button zoomOutButton = new Button();

            zoomOutButton.Text        = "-";
            zoomOutButton.Width       = 25;
            zoomOutButton.Location    = new Point(150, 3);
            zoomOutButton.MouseClick += (s, e) =>
            {
                if (tileSize > 0)
                {
                    SetTileSize(tileSize - 1);
                }
            };
            Controls.Add(zoomOutButton);
            Button zoomInButton = new Button();

            zoomInButton.Text        = "+";
            zoomInButton.Width       = 25;
            zoomInButton.Location    = new Point(180, 3);
            zoomInButton.MouseClick += (s, e) =>
            {
                SetTileSize(tileSize + 1);
            };
            Controls.Add(zoomInButton);

            tileBoxSets[0]  = new TileBoxSet(this, 0, 0, 8);
            tileBoxSets[1]  = new TileBoxSet(this, 8, 0, 8);
            tileBoxSets[2]  = new TileBoxSet(this, 16, 0, 8);
            tileBoxSets[3]  = new TileBoxSet(this, 24, 0, 8);
            tileBoxSets[4]  = new TileBoxSet(this, 0, 8, 8);
            tileBoxSets[5]  = new TileBoxSet(this, 8, 8, 8);
            tileBoxSets[6]  = new TileBoxSet(this, 16, 8, 8);
            tileBoxSets[7]  = new TileBoxSet(this, 24, 8, 8);
            tileBoxSets[8]  = new TileBoxSet(this, 0, 16, 8);
            tileBoxSets[9]  = new TileBoxSet(this, 8, 16, 8);
            tileBoxSets[10] = new TileBoxSet(this, 16, 16, 8);
            tileBoxSets[11] = new TileBoxSet(this, 24, 16, 8);
            tileBoxSets[12] = new TileBoxSet(this, 0, 24, 8);
            tileBoxSets[13] = new TileBoxSet(this, 8, 24, 8);
            tileBoxSets[14] = new TileBoxSet(this, 16, 24, 8);
            tileBoxSets[15] = new TileBoxSet(this, 24, 24, 8);
            for (int i = 0; i < tileBoxSets.Length; i++)
            {
                TileBoxSet tileBoxSet = tileBoxSets[i];
                Controls.Add(tileBoxSet);
            }

            Rectangle screen     = Screen.FromControl(this).Bounds;
            Int32     screenSize = (screen.Width > screen.Height) ? screen.Height : screen.Width;

            SetTileSize(screenSize / 36);

            HouseObjectDefinition floor = CDLoader.HouseObjectDefinitionMap[0];

            for (int i = 0; i < houseObjects.Length; i++)
            {
                houseObjects[i] = floor;
            }

            //
            // Tests
            //

            /*
             * UInt32 index = (UInt32)houseObjects.Length - 33;
             * foreach (HouseObjectDefinition h in CDLoader.HouseObjectDefinitions)
             * {
             *  foreach(HouseObjectStateDefinition state in h.states.Values)
             *  {
             *      houseObjects[index--] = new TestHouseObject(h, state.bitmap, state.id.ToString());
             *  }
             *  houseObjects[index--] = floor;
             *  /*
             *  HouseObjectStateDefinition state0, state100;
             *  if(h.states.TryGetValue(100, out state100))
             *  {
             *      state0 = h.states[0];
             *      for (int i = 0; i < 32; i++)
             *      {
             *          for (int j = 0; j < 32; j++)
             *          {
             *              Color color1 = state0.bitmap.GetPixel(j, i);
             *              Color color2 = state100.bitmap.GetPixel(j, i);
             *              Int32 newRed = color1.R + color2.R;
             *              Int32 newGreen = color1.G + color2.G;
             *              Int32 newBlue = color1.B + color2.B;
             *              if (newRed > 255) newRed = 255;
             *              if (newGreen > 255) newGreen = 255;
             *              if (newBlue > 255) newBlue = 255;
             *              state0.bitmap.SetPixel(j, i, Color.FromArgb(0xFF,
             *                  newRed, newGreen, newBlue));
             *          }
             *      }
             *      houseObjects[index--] = new TestHouseObject(h, state0.bitmap);
             *  }
             *  //
             * }
             */
        }