protected Tile GetTile(int index) { if (index >= Count || index < 0) { throw new ArgumentOutOfRangeException(String.Format("Index:{0}, Length:{1}", index, Count)); } int? TrueIndex; HexCoordinates trueCoords = IndexToCoords(index); TrueIndex = BaseList.CoordsToIndex(trueCoords); if (!TrueIndex.HasValue) { string errorstring = String.Format("Index:{0}, TrueIndex:null, TileHeight:{4}, trueCoords:{2}, TrueListCount:{3} Offsets:{5}", index, TrueIndex, trueCoords.ToString(), BaseList.Count, "n/a", BaseList.CoordsToOffsets(trueCoords)); throw new Exception(errorstring); //I dont know if this ever comes up. } Tile ret = BaseList.GetTile(BaseList.IndexToCoords(TrueIndex.Value)); //converting it to this then converting right back... oi. if (ret == null) //Also never comes up, but STILL... { string errorstring = String.Format("Index:{0}, TrueIndex:{1}, TileHeight:{4}, trueCoords:{2}, TrueListCount:{3}", index, TrueIndex, trueCoords.ToString(), BaseList.Count, "n/a"); throw new Exception(errorstring); } return(ret); }
override public bool ValidDirection(HexCoordinates coords, HexDirection direction) //Valid query { return(BaseList.CoordsToIndex(coords.DirectionTransform((HexDirection3D)(direction))).HasValue); }
public void SetTileHeight(int x, int z, int newHeight) { //Place the highest tile at the x,z offset at the stated height, and ensure it remains the highest tile at said location //This operation will null out all tiles between old and new if new height is less than the old height int oldHeight = TileHeight(x, z); //prior height of highest tile at XZ if (oldHeight == newHeight) { return; } //if height is not actually being changed, stop int?DesiredIndex = BaseList.OffsetsToIndex(new Vector3(x, newHeight, z)); //index new tile will be placed at in BaseList if (!DesiredIndex.HasValue) { return; } //if outside the correct range, do nothing Tile OldTile = GetTile(x, z); //Gets the highest tile at XZ HexCoordinates OldCoords = HexCoordinates.FromOffsetCoordinates(x, z, oldHeight); //coords of tile HexCoordinates OldCoordsAbove = OldCoords.Above; Tile OldTileAbove = GetTrueTile(OldCoordsAbove); //Since things could be "on top" of the old tile, it should be moved as well HexCoordinates NewCoords = HexCoordinates.FromOffsetCoordinates(x, z, newHeight); HexCoordinates NewCoordsAbove = NewCoords.Above; if (oldHeight < newHeight) { BaseList.SetTile(NewCoordsAbove, OldTileAbove); BaseList.SetTile(OldCoordsAbove, null); BaseList.SetTile(NewCoords, OldTile); BaseList.SetTile(OldCoords, null); } else { BaseList.SetTile(NewCoords, OldTile); BaseList.SetTile(NewCoordsAbove, OldTileAbove); BaseList.SetTile(OldCoordsAbove, null); while (true) { NewCoordsAbove = NewCoordsAbove.Above; if (BaseList.CoordsToIndex(NewCoordsAbove).HasValue) { BaseList.SetTile(NewCoordsAbove, null); } else { break; } } } // OldTile = GetTile(DesiredIndex); //should be the "moved" tile // OldTileAbove = GetTrueTile(NewAbove); /* * if (tile.HasActor) { PlaceTransformsOnTile(index, tile.Actor.transform); } * if (tile.Features != null && tile.Features.Count>0) { for (int i = 0; i < tile.Features.Count; i++) { tile.Features[i].Location = Coords; _TrueList.PlaceTransformsOnTile(_TrueList.CoordsToIndex(Coords).Value, tile.Features[i].transform); } } * if (abovetile.HasActor) { PlaceTransformsOnTile(_TrueList.CoordsToIndex(NewAbove).Value, abovetile.Actor.transform); } * if (abovetile.Features != null && abovetile.Features.Count > 0) { for (int i = 0; i < abovetile.Features.Count; i++) { abovetile.Features[i].Location = NewAbove; _TrueList.PlaceTransformsOnTile(_TrueList.CoordsToIndex(NewAbove).Value, abovetile.Features[i].transform); } } */ }