public static void LoadDS1() { Console.WriteLine("Loading DS1 references..."); foreach (string FilePath in System.IO.Directory.GetFiles(Environment.CurrentDirectory + @"\CATACOMB\")) { System.IO.Stream myStream = System.IO.File.Open(FilePath, System.IO.FileMode.Open) as System.IO.Stream; byte[] buf = new byte[myStream.Length]; myStream.Read(buf, 0, buf.Length); Game.GameInfo.DS1List.Add(new Parser(buf)); } UniqueObjects uObjects = new UniqueObjects(); foreach (Parser p in Game.GameInfo.DS1List) { //walkinfo from wall tiles WalkabilityInfo walkinfo = new WalkabilityInfo(p); Game.GameInfo.WalkInfo.Add(walkinfo); uObjects.add(p); } Console.WriteLine("...DS1 references loaded"); } /* static bool RunTest(BotConfig myBotConfig) { Console.WriteLine("Running test"); Test myTest = new Test(myBotConfig,true); bool test = myTest.DoRun(); return test; } * */ } public class UniqueObjects { public UniqueObjects() { } public void add(Parser p) { DS1.Object[] toAdd = new data.DS1.Object[p.Objects.Count]; int index = 0; foreach (data.DS1.Object obj in p.Objects) { toAdd[index] = obj; index++; } Game.GameInfo.objList.Add(toAdd); } public void Trim() { List tmpFinalList = new List(); List tmpList = new List(); for (int i = 0; i < Game.GameInfo.objList.Count; i++) { tmpList.Clear(); foreach (DS1.Object obj in Game.GameInfo.objList[i]) { if (!isDuplicated(obj, i)) { tmpList.Add(obj); } } tmpFinalList.Add(tmpList.ToArray()); } Game.GameInfo.objList = tmpFinalList; } public override string ToString() { StringBuilder sb = new StringBuilder(); int index = 0; foreach (DS1.Object[] obj1 in Game.GameInfo.objList) { sb.Append("index=" + index); foreach (DS1.Object obj2 in obj1) { sb.Append(" " + obj2.Id + "(" + obj2.X + "," + obj2.Y + ") "); } sb.Append(Environment.NewLine); index++; } return sb.ToString(); } public bool isDuplicated(DS1.Object obj, int index) { for (int i = 0; i < Game.GameInfo.objList.Count; i++) { if (i == index) continue; foreach (DS1.Object obj2 in Game.GameInfo.objList[i]) { if (obj.Id == obj2.Id && obj.X == obj2.X && obj.Y == obj2.Y) return true; } } return false; } } //int[] object id, x, y as found on ds1 } public class WalkabilityInfo { public WalkabilityInfo(bool SetAllWalkable) { this.Walkable = new bool[12, 12]; if (SetAllWalkable) { for (int x = 0; x < 12; x++) { for (int y = 0; y < 12; y++) { this[x, y] = true; } } } } public WalkabilityInfo(Parser p) { int LayerIndex = p.Layers.Count - 2; this.Walkable = new bool[p.Layers[LayerIndex].Property0.GetUpperBound(0) , p.Layers[p.Layers.Count - 2].Property0.GetUpperBound(1)]; for (int y = 0; y < Walkable.GetUpperBound(1); y++) { for (int x = 0; x < Walkable.GetUpperBound(0); x++) { if (p.Layers[LayerIndex].Property0[x, y] == 194) this[x, y] = true; else this[x, y] = false; } } } public override string ToString() { StringBuilder sb = new StringBuilder(); for (int y = 0; y < Walkable.GetUpperBound(1); y++) { for (int x = 0; x < Walkable.GetUpperBound(0); x++) { char c = this[x, y] ? '1' : '0'; sb.Append(c); } sb.Append(Environment.NewLine); } return sb.ToString(); } private bool[,] Walkable; public bool this[int x, int y] { get { return this.Walkable[x, y]; } set { this.Walkable[x, y] = value; } } }