Esempio n. 1
0
		/// <summary>Recalculates tile system. </summary>
		public static void FixTiles(TileLayer tiles, TileCollection collection) {
			Logger.Info("Recalculating tile LAT system");

			// change all CLAT tiles to their corresponding LAT tiles
			foreach (MapTile t in tiles) {
				// If this tile comes from a CLAT (connecting lat) set,
				// then replace it's set and tilenr by corresponding LAT sets'
				t.SetNum = collection.GetSetNum(t.TileNum);

				if (collection.IsCLAT(t.SetNum)) {
					t.SetNum = collection.GetLAT(t.SetNum);
					t.TileNum = collection.GetTileNumFromSet(t.SetNum);
				}
			}

			// apply autolat
			foreach (MapTile t in tiles) {
				// If this tile is a LAT tile, we might have to connect it
				if (collection.IsLAT(t.SetNum)) {
					// Which tile to use from CLAT tileset
					byte transitionTile = 0;
					MapTile tileTopRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopRight);
					MapTile tileBottomRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomRight);
					MapTile tileBottomLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomLeft);
					MapTile tileTopLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopLeft);


					// Find out setnums of adjacent cells
					if (tileTopRight != null && collection.ConnectTiles(t.SetNum, tileTopRight.SetNum))
						transitionTile += 1;

					if (tileBottomRight != null && collection.ConnectTiles(t.SetNum, tileBottomRight.SetNum))
						transitionTile += 2;

					if (tileBottomLeft != null && collection.ConnectTiles(t.SetNum, tileBottomLeft.SetNum))
						transitionTile += 4;

					if (tileTopLeft != null && collection.ConnectTiles(t.SetNum, tileTopLeft.SetNum))
						transitionTile += 8;

					if (transitionTile > 0) {
						// Find Tileset that contains the connecting pieces
						short clatSet = collection.GetCLATSet(t.SetNum);
						// Do not change this setnum, as then we could recognize it as
						// a different tileset for later tiles around this one.
						// (T->SetNum = clatSet;)
						t.TileNum = collection.GetTileNumFromSet(clatSet, transitionTile);
						t.Drawable = collection.GetDrawable(t);
					}
				}

				// apply ramp fixup
				else if (t.SetNum == collection.RampBase) {
					var ti = t.GetTileImage();
					if (ti.RampType < 1 || 4 < ti.TerrainType) continue;

					int fixup = -1;
					MapTile tileTopRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopRight);
					MapTile tileBottomRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomRight);
					MapTile tileBottomLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomLeft);
					MapTile tileTopLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopLeft);


					switch (ti.RampType) {
						case 1:
							// northwest facing
							if (tileTopLeft != null && tileTopLeft.GetTileImage().RampType == 0)
								fixup++;
							if (tileBottomRight != null && tileBottomRight.GetTileImage().RampType == 0)
								fixup += 2;
							break;

						case 2: // northeast facing
							if (tileTopRight != null && tileTopRight.GetTileImage().RampType == 0)
								fixup++;
							if (tileBottomLeft != null && tileBottomLeft.GetTileImage().RampType == 0)
								fixup += 2;
							break;

						case 3: // southeast facing
							if (tileBottomRight != null && tileBottomRight.GetTileImage().RampType == 0)
								fixup++;
							if (tileTopLeft != null && tileTopLeft.GetTileImage().RampType == 0)
								fixup += 2;
							break;

						case 4: // southwest facing
							if (tileBottomLeft != null && tileBottomLeft.GetTileImage().RampType == 0)
								fixup++;
							if (tileTopRight != null && tileTopRight.GetTileImage().RampType == 0)
								fixup += 2;
							break;
					}

					if (fixup != -1) {
						t.TileNum = collection.GetTileNumFromSet(collection.RampSmooth, (byte)((ti.RampType - 1) * 3 + fixup));
						// update drawable too
						t.Drawable = collection.GetDrawable(t);
					}
				}

			}


		}
Esempio n. 2
0
        private void ChangeTileToClear(TileCollection coll, MapTile tile)
        {
            tile.TileNum = 0;
            tile.SubTile = 0;
            tile.Drawable = coll.GetDrawable(0);

            var t = _mapFile.Tiles.GetTileR(tile.Rx, tile.Ry);
            t.TileNum = 0;
            t.SubTile = 0;
        }