Exemple #1
0
 public Tile(int index, TileItem[] items, int itemcount, TileLocation global, TileLocation local, int[] ord)
 {
     this._index = index;
     this._itemCount = itemcount;
     this._globalLocation = global;
     this._items = items;
     this._memoryLocation = local;
     this._order = ord;
 }
Exemple #2
0
        public static Tile GetTile(TileLocation location)
        {
            try
            {
                TileLocation local;
                int num, minFloor, maxFloor;
                Tile PlayerTile;

                local = Tile.globalToLocal(location);
                num = Tile.ToTileNumber(local);
                PlayerTile = GetPlayerTile();

                minFloor = 0;
                maxFloor = 0;

                for (int i = 0; i <= 7; i++)
                {
                    if (PlayerTile.Index >= Addresses.Map.MaxTiles * i && PlayerTile.Index <= Addresses.Map.MaxTiles * (i + 1))
                    {
                        minFloor = (int)Addresses.Map.MaxTiles * i;
                        maxFloor = (int)Addresses.Map.MaxTiles * (i + 1) - 1;
                        break;
                    }
                }

                if (num > maxFloor)
                {
                    num = num - maxFloor + minFloor - 1;
                }

                if (num < minFloor)
                {
                    num = maxFloor - minFloor + num + 1;
                }

                return GetTile(num);
            }
            catch (InvalidOperationException ex)
            {
                Helpers.Debug.Report(ex);
            }
            return null;
        }
Exemple #3
0
        public static TileLocation globalToLocal(TileLocation loc)
        {
            try
            {
                TileLocation result = new TileLocation();
                TileLocation playerLoc;
                int zz, PlayerZPlane;

                playerLoc = PlayerLocation();

                if (playerLoc.z <= GROUND_LAYER)
                {
                    PlayerZPlane = (MAPSIZE_Z - 1) - playerLoc.z;
                }
                else
                {
                    PlayerZPlane = UNDERGROUND_LAYER;
                }

                zz = playerLoc.z - loc.z;

                result.x = loc.x - (playerLoc.x - 8) - zz;
                result.y = loc.y - (playerLoc.y - 6) - zz;
                result.z = PlayerZPlane + zz;

                return result;
            }
            catch (InvalidOperationException ex)
            {
                Helpers.Debug.Report(ex);
            }
            return new TileLocation();
        }
Exemple #4
0
 public static TileLocation PlayerLocation()
 {
     try
     {
         TileLocation loc = new TileLocation();
         loc.x = (int)Player.X;
         loc.y = (int)Player.Y;
         loc.z = (int)Player.Z;
         return loc;
     }
     catch (InvalidOperationException ex)
     {
         Helpers.Debug.Report(ex);
     }
     return new TileLocation();
 }
Exemple #5
0
        public static TileLocation tileToLocal(int index)
        {
            try
            {
                TileLocation result = new TileLocation();

                result.z = Convert.ToInt32(index / (14 * 18));
                result.y = Convert.ToInt32(index - result.z * 14 * 18) / 18;
                result.x = Convert.ToInt32(index - result.z * 14 * 18) - result.y * 18;
                return result;
            }
            catch (InvalidOperationException ex)
            {
                Helpers.Debug.Report(ex);
            }
            return new TileLocation();
        }
Exemple #6
0
        public static TileLocation tileToGlobal(Tile tile, Tile PlayerTile)
        {
            try
            {
                TileLocation result = new TileLocation();
                TileLocation loc = new TileLocation();
                TileLocation playerMemLoc, playerGloLoc;

                loc = tile.MemoryLocation;
                playerMemLoc = PlayerTile.MemoryLocation;

                int diffX = 0;
                int diffY = 0;
                int maxX = 0;
                int maxY = 0;

                diffX = 8 - playerMemLoc.x;
                diffY = 6 - playerMemLoc.y;
                loc.x = loc.x + diffX;
                loc.y = loc.y + diffY;

                maxY = (int)Addresses.Map.MaxY + 1;
                maxX = (int)Addresses.Map.MaxX;

                if (loc.x > maxX)
                {
                    loc.x = loc.x - (int)Addresses.Map.MaxX;
                    //loc.y = loc.y + 1;
                }
                else if (loc.x < 0)
                {
                    loc.x = loc.x + (int)Addresses.Map.MaxX;
                    //loc.y = loc.y - 1;
                }
                else if (loc.y > maxY)
                {
                    loc.y = loc.y - (int)Addresses.Map.MaxY;
                }
                else if (loc.y < 0)
                {
                    loc.y = loc.y + (int)Addresses.Map.MaxY;
                }

                playerGloLoc = PlayerTile.GlobalLocation;

                result.x = playerGloLoc.x + (loc.x - 8);
                result.y = playerGloLoc.y + (loc.y - 6);
                result.z = playerGloLoc.z + (loc.z - playerMemLoc.z);

                return result;
            }
            catch (InvalidOperationException ex)
            {
                Helpers.Debug.Report(ex);
            }
            return new TileLocation();
        }
Exemple #7
0
 public static int ToTileNumber(TileLocation local)
 {
     try
     {
         return local.x + local.y * 18 + local.z * 14 * 18;
     }
     catch (InvalidOperationException ex)
     {
         Helpers.Debug.Report(ex);
     }
     return 0;
 }