public void AddComponent(int x, int y, int z, int level, int index, int baseIndex, int count, int hue) { if (x >= 0 && x < m_Width && y >= 0 && y < m_Height && level >= 0 && level < Levels) { ArrayList list = m_Components[x][y][level]; HouseComponent nc = new HouseComponent(index, z, baseIndex, count); nc.Hue = hue; for (int i = 0; i < list.Count; ++i) { HouseComponent hc = (HouseComponent)list[i]; if (hc.Z == z && hc.Height == 0 && nc.Height == 0) { list[i] = nc; list.Sort(); return; } else if (hc.Z == z && hc.Height != 0 && nc.Height != 0) { list[i] = nc; list.Sort(); return; } } list.Add(nc); list.Sort(); } }
public ArrayList Compress() { ArrayList list = new ArrayList(); for (int i = 0; i < HouseDesign.Levels; ++i) { for (int x = 0; x < m_Width; ++x) { for (int y = 0; y < m_Height; ++y) { ArrayList comps = m_Components[x][y][i]; for (int j = 0; j < comps.Count; ++j) { HouseComponent hc = (HouseComponent)comps[j]; list.Add(new BuildEntry(x, y, hc.Z, hc.BaseIndex, hc.Count, i)); } } } } bool combined, thisCombined; do { combined = false; for (int i = 0; i < list.Count; ++i) { BuildEntry be = (BuildEntry)list[i]; thisCombined = false; for (int j = 0; !thisCombined && j < list.Count; ++j) { BuildEntry te = (BuildEntry)list[j]; if (i != j && be.CombineWith(te)) { list.RemoveAt(i); --i; combined = thisCombined = true; } } } } while (combined); return(list); }
public HouseDesign(DesignData fileHeader) { m_FileHeader = fileHeader; m_Name = fileHeader.Name; m_Category = fileHeader.Category; m_SubSection = fileHeader.Subsection; m_Width = fileHeader.Width; m_Height = fileHeader.Height; m_UserWidth = fileHeader.UserWidth; m_UserHeight = fileHeader.UserHeight; m_Components = null; Clear(); if (fileHeader == null) { return; } if (!m_FileHeader.IsLoaded) { m_FileHeader.Load(); } for (int i = 0; i < fileHeader.Items.Count; ++i) { DesignItem item = fileHeader.Items[i]; HouseComponent hc = new HouseComponent(item.ItemID, item.Z); hc.Hue = item.Hue; m_Components[item.X][item.Y][GetZLevel(item.Z)].Add(hc); } Sort(); // unload design items to conserve memory m_FileHeader.Unload(); }
public int CompareTo(object obj) { HouseComponent hc = (HouseComponent)obj; if (m_Z < hc.m_Z) { return(-1); } else if (hc.m_Z < m_Z) { return(1); } else if (m_Height < hc.m_Height) { return(-1); } else if (hc.m_Height < m_Height) { return(1); } return(0); }
public Bitmap GetPreviewImage(int level) { int xMin = int.MaxValue, yMin = int.MaxValue; int xMax = int.MinValue, yMax = int.MinValue; for (int i = 0; i <= level; ++i) { for (int x = 0, vx = 0; x < m_Width; ++x, vx += 22) { int px = vx, py = vx; for (int y = 0; y < m_Height; ++y, px -= 22, py += 22) { ArrayList components = m_Components[x][y][i]; for (int j = 0; j < components.Count; ++j) { HouseComponent hc = (HouseComponent)components[j]; Bitmap img = hc.Image; int dx = px - (img.Width / 2); int dy = py - (hc.Z * 4) - img.Height; if (dx < xMin) { xMin = dx; } if (dy < yMin) { yMin = dy; } dx += img.Width; dy += img.Height; if (dx > xMax) { xMax = dx; } if (dy > yMax) { yMax = dy; } } } } } if (xMin == int.MaxValue || yMin == int.MaxValue || xMax == int.MinValue || yMax == int.MinValue) { return(new Bitmap(0, 0)); } Bitmap bmp = new Bitmap(xMax - xMin, yMax - yMin); Graphics g = Graphics.FromImage(bmp); int xOffset = -xMin; int yOffset = -yMin; for (int i = 0; i <= level; ++i) { for (int x = 0, vx = 0; x < m_Width; ++x, vx += 22) { int px = vx + xOffset, py = vx + yOffset; for (int y = 0; y < m_Height; ++y, px -= 22, py += 22) { ArrayList components = m_Components[x][y][i]; for (int j = 0; j < components.Count; ++j) { HouseComponent hc = (HouseComponent)components[j]; g.DrawImage(hc.Image, px - (hc.Image.Width / 2), py - (hc.Z * 4) - hc.Image.Height); } } } } g.Dispose(); return(bmp); }
public void AddComponent(int x, int y, int z, int level, int index, HouseComponent hc) { AddComponent(x, y, z, level, index, index, 1, hc.Hue); }
public void AddComponent(int x, int y, int level, int index, HouseComponent hc) { AddComponent(x, y, LevelZ[level], level, index, hc); }