public BotMap(Level l) { AirMap = new TriBool[l.CWMap.Size.x, l.CWMap.Size.z, l.CWMap.Size.y];//return x + z * Size.x + y * Size.x * Size.z; Size = l.CWMap.Size; for (int i = 0; i < l.CWMap.BlockData.Length; i++) { Vector3S pos = l.IntToPos(i); if (isAir(l.GetBlock(i))) AirMap[pos.x, pos.z, pos.y] = true; else if (Block.IsOPBlock(l.GetBlock(i))) AirMap[pos.x, pos.z, pos.y] = TriBool.Unknown; else AirMap[pos.x, pos.z, pos.y] = false; } /*for (int x = 0; x < AirMap.GetLength(0); x++) { for (int z = 0; z < AirMap.GetLength(1); z++) { for (int y = 0; y < AirMap.GetLength(2); y++) { } } }*/ }
public BotMap(Level l) { AirMap = new bool[l.Size.x, l.Size.z, l.Size.y];//return x + z * Size.x + y * Size.x * Size.z; for (int i = 0; i < l.Data.Length; i++) { Vector3S pos = l.IntToPos(i); AirMap[pos.x, pos.z, pos.y] = isAir(l.GetBlock(i)); } for (int x = 0; x < AirMap.GetLength(0); x++) { for (int z = 0; z < AirMap.GetLength(1); z++) { for (int y = 0; y < AirMap.GetLength(2); y++) { } } } }
public void Undo(long since, Level l) { ExtraData<Tuple<short, short, short>, Tuple<long, byte>> toChange = GetOriginalBlocks(since, l); List<long> asked = new List<long>(); foreach (Player p in l.Players) { if (p != player) toChange = p.history.redoRecentOthersUndo(toChange, since, l); } toChange = redoArchiveOthersUndoForAllPlayers(toChange, since, l); string path = GetFullPath(l); if (!Directory.Exists(path)) Directory.CreateDirectory(path); string tmppath = GetFullPath(l) + DateTime.Now.Ticks + futureEnding; FileStream fs = new FileStream(tmppath, FileMode.Create, FileAccess.Write); GZipStream gz = new GZipStream(fs, CompressionMode.Compress); BinaryWriter bw = new BinaryWriter(gz); foreach (Tuple<short, short, short> v in toChange.Keys) { //all changes are associated to the time in the filename byte tmp = l.GetBlock(v.Item1, v.Item2, v.Item3); if (tmp != toChange[v].Item2) { bw.Write(v.Item1);//coords bw.Write(v.Item2); bw.Write(v.Item3); bw.Write(toChange[v].Item2);//after undo l.BlockChange(new Vector3S(v.Item1, v.Item2, v.Item3), toChange[v].Item2); } } bw.Close(); gz.Close(); fs.Close(); }
private static void redo(ExtraData<Tuple<short, short, short>, Tuple<long, byte>> toChange, Level l, long UID, Player p = null) { MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); foreach (Tuple<short, short, short> v in toChange.Keys) { byte currentBlock = l.GetBlock(v.Item1, v.Item2, v.Item3); byte newBlock = toChange[v].Item2; if (currentBlock != newBlock) { if (p != null && p.Level == l) { lock (p.history.lock_recent) { p.history.recentTimes.Add(DateTime.Now.Ticks); p.history.recentChanges.Add(new Tuple<Tuple<short, short, short>, byte, byte>(v, currentBlock, newBlock)); } } else { bw.Write(DateTime.Now.Ticks); bw.Write(v.Item1); bw.Write(v.Item2); bw.Write(v.Item3); bw.Write(currentBlock); bw.Write(newBlock); } l.BlockChange(new Vector3S(v.Item1, v.Item2, v.Item3), newBlock); //TODO: Create BlockChange(short,short,short); } } bw.Close(); if (ms.Length != 0) { string path = GetFullPath((p == null) ? UID : p.UID, l); ms.Position = 0; BinaryReader br = new BinaryReader(ms); long initialTime = br.ReadInt64(); br.Close(); FileStream fs = new FileStream(path + initialTime + historyEnding, FileMode.Create, FileAccess.Write); GZipStream gz = new GZipStream(fs, CompressionMode.Compress); gz.Write(ms.ToArray(), 0, (int)ms.Length); gz.Close(); fs.Close(); } ms.Close(); }
/// <summary> /// Fills the <see cref="Cuboid"/> with <paramref name="block"/>. /// </summary> /// <param name="block">The <see cref="Block"/> to fill with.</param> /// <param name="world">The <see cref="Level"/>.</param> /// <param name="p">The player.</param> /// <remarks></remarks> public void Fill(Block block, Level world, Player p = null) { var buffer = new List<Pos>(); ushort x, z, y; ushort xmin = (ushort) Min.x, xmax = (ushort) Max.x, zmin = (ushort) Min.z, zmax = (ushort) Max.z, ymin = (ushort) Min.y, ymax = (ushort) Max.y; for (x = xmin; x <= xmax; ++x) for (z = zmin; z <= zmax; ++z) for (y = ymin; y <= ymax; ++y) if (world.GetBlock(x, z, y) != block) BufferAdd(buffer, x, z, y); //Level Blockqueue if (p != null) p.SendMessage(buffer.Count.ToString(CultureInfo.InvariantCulture) + " blocks."); buffer.ForEach( pos => world.BlockChange((ushort) (pos.pos.x), (ushort) (pos.pos.z), (ushort) (pos.pos.y), block, p)); }