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 bool CombineWith(BuildEntry e) { if (m_Level == e.m_Level && m_Z == e.m_Z && m_X == (e.m_X + e.m_Width) && m_Y == e.m_Y && m_Height == e.m_Height && m_Index == e.m_Index && e.m_Count == m_Count) { e.m_Width += m_Width; return(true); } else if (m_Level == e.m_Level && m_Z == e.m_Z && m_Y == (e.m_Y + e.m_Height) && m_X == e.m_X && m_Width == e.m_Width && m_Index == e.m_Index && e.m_Count == m_Count) { e.m_Height += m_Height; return(true); } return(false); }
public int CompareTo(object obj) { BuildEntry be = (BuildEntry)obj; if (m_Y < be.m_Y) { return(-1); } else if (be.m_Y < m_Y) { return(1); } else if (m_X < be.m_X) { return(-1); } else if (be.m_X < m_X) { return(1); } return(0); }
public void ExportRunUOScript() { StringBuilder sb; using (StreamReader ip = new StreamReader("Internal/scriptbase.txt")) sb = new StringBuilder(ip.ReadToEnd()); bool firstLine = true; bool blankLine = false; StringBuilder components = new StringBuilder(); ArrayList list = Compress(); for (int i = 0; i < list.Count; ++i) { BuildEntry entry = (BuildEntry)list[i]; if (entry.m_Width == 1 && entry.m_Height == 1) { blankLine = false; if (entry.m_Count == 1) { components.AppendFormat("\r\n\t\t\tAddComponent( new AddonComponent( 0x{0:X4} ), {1}, {2}, {3} );", entry.m_Index, entry.m_X, entry.m_Y, entry.m_Z); } else { components.AppendFormat("\r\n\t\t\tAddComponent( new AddonComponent( Utility.Random( 0x{0:X4}, {4} ) ), {1}, {2}, {3} );", entry.m_Index, entry.m_X, entry.m_Y, entry.m_Z, entry.m_Count); } } else { if (!firstLine && !blankLine) { components.AppendFormat("\r\n"); } bool xLoop = (entry.m_Width != 1); bool yLoop = (entry.m_Height != 1); bool randomIndex = (entry.m_Count != 1); bool xOffset = (entry.m_X != 0); bool yOffset = (entry.m_Y != 0); if (xLoop) { components.AppendFormat("\r\n\t\t\tfor ( int x = 0; x < {0}; ++x )", entry.m_Width); } if (yLoop) { if (xLoop) { components.AppendFormat("\r\n\t\t\t\tfor ( int y = 0; y < {0}; ++y )", entry.m_Height); } else { components.AppendFormat("\r\n\t\t\tfor ( int y = 0; y < {0}; ++y )", entry.m_Height); } } string xString, yString; if (!xLoop) { xString = entry.m_X.ToString(); } else if (!xOffset) { xString = "x"; } else { xString = String.Format("{0} + x", entry.m_X); } if (!yLoop) { yString = entry.m_Y.ToString(); } else if (!yOffset) { yString = "y"; } else { yString = String.Format("{0} + y", entry.m_Y); } if (randomIndex) { if (xLoop && yLoop) { components.AppendFormat("\r\n\t\t\t\t\tAddComponent( new AddonComponent( Utility.Random( 0x{0:X4}, {4} ) ), {1}, {2}, {3} );", entry.m_Index, xString, yString, entry.m_Z, entry.m_Count); } else { components.AppendFormat("\r\n\t\t\t\tAddComponent( new AddonComponent( Utility.Random( 0x{0:X4}, {4} ) ), {1}, {2}, {3} );", entry.m_Index, xString, yString, entry.m_Z, entry.m_Count); } } else { if (xLoop && yLoop) { components.AppendFormat("\r\n\t\t\t\t\tAddComponent( new AddonComponent( 0x{0:X4} ), {1}, {2}, {3} );", entry.m_Index, xString, yString, entry.m_Z); } else { components.AppendFormat("\r\n\t\t\t\tAddComponent( new AddonComponent( 0x{0:X4} ), {1}, {2}, {3} );", entry.m_Index, xString, yString, entry.m_Z); } } components.AppendFormat("\r\n"); blankLine = true; } firstLine = false; } sb.Replace("~NAME~", Name); sb.Replace("~CLASSNAME~", Safe(Name)); sb.Replace("~COMPONENTS~", components.ToString()); using (StreamWriter op = new StreamWriter(String.Format("{0}.cs", Safe(Name)))) op.Write(sb.ToString()); }