Ejemplo n.º 1
0
		public Tile(Tile copy)
		{
			flags = copy.flags;
			tileType = copy.tileType;
			tileFrame = copy.tileFrame;
			wallType = copy.wallType;
			liquidLevel = copy.liquidLevel;
		}
Ejemplo n.º 2
0
		private void ReadWorldTiles()
		{
			Boolean theB;
			Byte theI;
			Tile theTile;
			Int32 i, j;

			if (bw != null)
				bw.ReportProgress((Int32)(((Single)progressPosition / stream.Length) * readWorldPerc)
					, "Reading Tiles");

			tiles = new Tile[MaxX, MaxY];

			for (i = 0; i < MaxX; i++)
			{
				for (j = 0; j < MaxY; j++)
				{
					theTile = new Tile();

					theB = reader.ReadBoolean();

					theTile.Active = theB;
					if (theB == true)
					{
						theI = reader.ReadByte();

						if (theI > 85)
							theTile.TileType = theI;

						theTile.TileType = theI;

						if (tileImportant[theI] == true)
						{
							theTile.Important = true;
							theTile.Frame = new PointInt16(reader.ReadInt16(), reader.ReadInt16());
						}
						else
							theTile.Important = false;
					}

					// /dev/null the Lighted Flag
					reader.ReadBoolean();

					theB = reader.ReadBoolean();

					theTile.Wall = theB;
					if (theB == true)
						theTile.WallType = reader.ReadByte();

					if (theTile.WallType == 0 && theTile.Wall == true)
						theTile.Wall = true;

					theB = reader.ReadBoolean();

					if (theB == true)
					{
						theTile.LiquidLevel = reader.ReadByte();
						theTile.Lava = reader.ReadBoolean();
					}

					tiles[i, j] = theTile;
				}
				progressPosition = stream.Position;
			}

			posChests = stream.Position;
		}
Ejemplo n.º 3
0
		// Helper function to help parse through the world loading a tile run at a time.
		// Lots of bounds checking to make sure we catch when the first errors happen.
		// Designed for 1.2.0.1
		public bool SanityCheckWorld(String world)
		{
			String error;
			int strictbool;
			int i, j;
			String byteStringOld;
			byte[] byteStreamOld;
			int byteStreamOldLength;
			String byteString;
			byte[] byteStream;
			int byteStreamPos;
			Tile curTile = new Tile();
			int RLEValue;
			byteStream = new byte[40];
			byteStreamPos = 0;
			byteStreamOld = new byte[40];
			byteStreamOldLength = 0;
			Int32 tilesRead = 0;
			stream = new FileStream(world, FileMode.Open, FileAccess.Read);
			reader = new BinaryReader(stream);

			ReadHeader();

			RLEValue = 0;
			for (i = 0; i < MaxX; i++)
			{
				for (j = 0; j < MaxY; j++)
				{
					if (RLEValue == 0)
					{
						if (tilesRead == 1773)
							tilesRead = 1773;

						byteStreamPos = 0;
						curTile.Reset();
						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)strictbool;
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed on the Activate Boolean read: 0x{1:X2}", (byte)strictbool);
						}

						curTile.Active = (strictbool == 0) ? false : true;

						if (curTile.Active)
						{
							curTile.TileType = reader.ReadByte();
							byteStream[byteStreamPos] = curTile.TileType;
							byteStreamPos++;

							if (curTile.TileType >= TileProperties.Unknown)
							{
								error = String.Format("Failed on the TileType Byte read: 0x{1:X2}", curTile.TileType);
							}

							if (Global.Instance.Info.Tiles[(int)curTile.TileType].colorName == "FindImportant")
							{
								error = String.Format("TileType {0} has unknown importance.", curTile.TileType);
							}

							if (TileProperties.tileTypeDefs[curTile.TileType].IsImportant)
							{
								curTile.Important = true;

								PointInt16 p = curTile.Frame;
								p.X = reader.ReadInt16();
								byteStream[byteStreamPos] = (byte)(p.X & 0xFF);
								byteStreamPos++;
								byteStream[byteStreamPos] = (byte)((p.X & 0xFF00) >> 8);
								byteStreamPos++;

								p.Y = reader.ReadInt16();
								byteStream[byteStreamPos] = (byte)(p.Y & 0xFF);
								byteStreamPos++;
								byteStream[byteStreamPos] = (byte)((p.Y & 0xFF00) >> 8);
								byteStreamPos++;

								curTile.Frame = p;
							}
							else
							{
								curTile.Important = false;
							}

							strictbool = reader.ReadByte();
							byteStream[byteStreamPos] = (byte)strictbool;
							byteStreamPos++;

							if (strictbool > 1)
							{
								error = String.Format("Failed on the Tile Color Boolean read: 0x{0:X2}", (byte)strictbool);
							}

							if (strictbool >= 1)
							{
								curTile.TileColor = reader.ReadByte();
								byteStream[byteStreamPos] = curTile.TileColor;
								byteStreamPos++;

								if (curTile.TileColor == 0)
								{
									error = String.Format("Failed on the Tile Color Byte read: 0x{0:X2}", curTile.TileColor);
								}
							}
						}

						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)(strictbool);
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed in the Wall Active Boolean read: 0x{0:X2}", (byte)strictbool);
						}

						if (strictbool >= 1)
						{
							curTile.WallType = reader.ReadByte();
							byteStream[byteStreamPos] = curTile.WallType;
							byteStreamPos++;

							if (curTile.WallType == 0 || curTile.WallType > Global.Instance.Info.Walls.Count)
							{
								error = String.Format("Failed in the Wall Type Byte read: 0x{0:X2}", curTile.WallType);
							}

							strictbool = reader.ReadByte();
							byteStream[byteStreamPos] = (byte)(strictbool);
							byteStreamPos++;

							if (strictbool > 1)
							{
								error = String.Format("Failed in the Wall Color Boolean read: 0x{0:X2}", (byte)strictbool);
							}

							if (strictbool >= 1)
							{
								curTile.WallColor = reader.ReadByte();
								byteStream[byteStreamPos] = curTile.WallColor;
								byteStreamPos++;

								if (curTile.WallColor == 0)
								{
									error = String.Format("Failed in the Wall Color Byte read: 0x{0:X2}", (byte)strictbool);
								}
							}
						}

						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)(strictbool);
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed in the Liquid Active Boolean read: 0x{0:X2}", (byte)strictbool);
						}

						if (strictbool >= 1)
						{
							curTile.LiquidLevel = reader.ReadByte();
							byteStream[byteStreamPos] = curTile.LiquidLevel;
							byteStreamPos++;

							strictbool = reader.ReadByte();
							byteStream[byteStreamPos] = (byte)(strictbool);
							byteStreamPos++;

							if (strictbool > 1)
							{
								error = String.Format("Failed in the IsLava Boolean read: 0x{0:X2}", (byte)strictbool);
							}

							curTile.Lava = (strictbool == 0) ? false : true;

							strictbool = reader.ReadByte();
							byteStream[byteStreamPos] = (byte)(strictbool);
							byteStreamPos++;

							if (strictbool > 1)
							{
								error = String.Format("Failed in the IsHoney Boolean read: 0x{0:X2}", (byte)strictbool);
							}

							curTile.Honey = (strictbool == 0) ? false : true;
						}

						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)(strictbool);
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed in the Red Wire Boolean read: 0x{0:X2}", (byte)strictbool);
						}

						curTile.RedWire = (strictbool == 0) ? false : true;

						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)(strictbool);
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed in the Blue Wire Boolean read: 0x{0:X2}", (byte)strictbool);
						}

						curTile.BlueWire = (strictbool == 0) ? false : true;

						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)(strictbool);
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed in the Halftile Boolean read: 0x{0:X2}", (byte)strictbool);
						}

						curTile.GreenWire = (strictbool == 0) ? false : true;

						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)(strictbool);
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed in the Halftile Boolean read: 0x{0:X2}", (byte)strictbool);
						}

						curTile.Halftile = (strictbool == 0) ? false : true;

						curTile.Slope = reader.ReadByte();

						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)(strictbool);
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed in the Actuator Boolean read: 0x{0:X2}", (byte)strictbool);
						}

						curTile.Actuator = (strictbool == 0) ? false : true;

						strictbool = reader.ReadByte();
						byteStream[byteStreamPos] = (byte)(strictbool);
						byteStreamPos++;

						if (strictbool > 1)
						{
							error = String.Format("Failed in the Inactive Boolean read: 0x{0:X2}", (byte)strictbool);
						}

						curTile.Inactive = (strictbool == 0) ? false : true;

						RLEValue = reader.ReadInt16();
						byteStream[byteStreamPos] = (byte)(RLEValue & 0xFF);
						byteStreamPos++;
						byteStream[byteStreamPos] = (byte)((RLEValue & 0xFF00) >> 8);
						byteStreamPos++;

						for (int k = byteStreamPos; k < byteStream.Length; k++)
							byteStream[k] = 0;

						for (int k = 0; k < byteStream.Length; k++)
							byteStreamOld[k] = byteStream[k];

						byteStreamOldLength = byteStreamPos;

						byteString = "";
						for (int k = 0; k < byteStreamPos; k++)
							byteString = byteString + String.Format("{0:X2} ", byteStream[k]);

						byteStringOld = byteString;
						tilesRead++;
					}
					else
					{
						RLEValue--;
						continue;
					}
				}
			}
			ReadChests();
			ReadSigns();
			ReadNPCs();
			ReadNPCNames();
			ReadFooter();
			return true;
		}
Ejemplo n.º 4
0
			public tileReader(tileReader copy)
			{
				id = nextId;
				nextId++;

				filePos = copy.filePos;

				tileLookup = new TileImportance(copy.tileLookup);
				tile = new Tile(copy.tile);
				tileOrder = new List<Byte>();

				tilesRead = copy.tilesRead;

				foreach (Byte b in copy.tileOrder)
					tileOrder.Add(b);
			}
Ejemplo n.º 5
0
			public tileReader(Int64 fPos)
			{
				id = nextId;
				nextId++;

				filePos = fPos;

				tileLookup = new TileImportance();
				tile = new Tile();
				tileOrder = new List<Byte>();

				tilesRead = 0;
			}