Beispiel #1
0
    // must be called before running tree
    public STile[] GetFirstTarget(Vector3 pos)
    {
        // get section
        var x     = Mathf.FloorToInt(pos.x);
        var areaX = (x / 10) * 10;
        var gridX = x - areaX;

        var y     = Mathf.FloorToInt(pos.z);
        var areaY = (y / 10) * 10;
        var gridY = y - areaX;

        Vector2Int areaPos = new Vector2Int(areaX, areaY);

        // gerate results
        var       result = new STile[2];
        MapObject area;

        for (int i = 0; i < m_TileList.Count; ++i)
        {
            area = m_TileList[i];
            if (area.GetPosition() == areaPos)
            {
                result[1] = area.GetTile(new Vector2Int(gridX, gridY));
                var rand       = Random.Range(0, 7);
                var nextTarget = new Vector2Int(gridX + rand / 3 - 1, gridY + rand % 3 - 1);
                result[0] = area.GetTile(nextTarget);
                break;
            }
        }

        return(result);
    }
Beispiel #2
0
    // gets if tile has a water neighbour
    public bool GetNeighbourWater(STile givenTile)
    {
        // Get map
        MapObject currentMapObject = null;
        var       numOfTiles       = m_TileList.Count;

        for (int i = 0; i < numOfTiles; ++i)
        {
            if (m_TileList[i].ContainsTile(givenTile))
            {
                currentMapObject = m_TileList[i];
                break;
            }
        }

        // get neighbours
        var n = currentMapObject.GetTileNeighbours(givenTile);

        // find water
        foreach (var tile in n)
        {
            if (tile.m_TileType == ETiles.water)
            {
                return(true);
            }
        }

        return(false);
    }
Beispiel #3
0
    public void SaveTileData()
    {
        if (grid_data == null)
        {
            return;
        }
        SavedTiles   tiles = new SavedTiles();
        List <STile> saved = new List <STile>();

        for (int x = 0; x < map_width; x++)
        {
            for (int y = 0; y < map_height; y++)
            {
                Tile_Data tile = grid_data[x, y];
                if (tile == null)
                {
                    continue;
                }

                STile savedTile = new STile();
                savedTile.grid_x   = tile.X;
                savedTile.grid_y   = tile.Y;
                savedTile.world_x  = tile.worldPos.x;
                savedTile.world_y  = tile.worldPos.y;
                savedTile.tileType = tile.tileType;
                if (tile.machine_controller != null)
                {
                    if (tile.machine_controller.baseTile == tile &&
                        tile.machine_controller.machine.buildableType != BuildableType.Producer)
                    {
                        Machine machine = tile.machine_controller.machine;
                        savedTile.hasMachine       = true;
                        savedTile.machineName      = machine.name;
                        savedTile.machineCondition = machine.machineCondition;
                        Debug.Log("Saving " + savedTile.machineName);
                    }
                }
                if (tile.producer != null)
                {
                    if (tile.machine_controller.baseTile != tile)
                    {
                        continue;
                    }
                    savedTile.hasProducer     = true;
                    savedTile.producerName    = tile.producer.name;
                    savedTile.productionStage = tile.producer.productionStage;
                    savedTile.itemProduced    = tile.producer.current_Blueprint.itemProduced.itemName;
                    Debug.Log("Saving " + savedTile.producerName);
                }

                saved.Add(savedTile);
            }
        }
        tiles.areaID     = currentArea.id;
        tiles.savedTiles = saved.ToArray();
        JsonWriter.WriteTilesToJson(tiles, currentArea.id);
    }
Beispiel #4
0
    public void Serialize(string title)
    {
        tile.name = title;
        STile  original = new STile(tile);
        string content  = original.ToBase64();

        Application.ExternalEval("console.log('" + content + "')");
        Application.ExternalEval("processTile('" + content + "')");
    }
Beispiel #5
0
    public void OnSubmit()
    {
        GameObject tile = GameObject.Find("My Tile");

        tile.name = tileName.GetComponent <InputField>().text;

        // Serialize
        STile  original = new STile(tile);
        string content  = original.ToBase64();

        Publish(content);
    }
Beispiel #6
0
    void OnGUI()
    {
        GameObject tile = Selection.activeGameObject;

        if (!tile)
        {
            EditorGUILayout.HelpBox("Select a tile in the hierarchy view to enable Decentraland tile uploader.", MessageType.Warning);
            return;
        }

        GUILayout.Label("\n");
        GUILayout.Label("Configuration\n");

        nodeAddress = EditorGUILayout.TextField("Your Node RPC URL", nodeAddress);
        nodeAuth    = EditorGUILayout.TextField("Node RPC Auth Token", nodeAuth);

        GUILayout.Label("\n");
        GUILayout.Label("\n");
        GUILayout.Label("Editor\n");
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Tile Coordinates");
        GUILayout.Label("X");
        xOffset = EditorGUILayout.IntField(xOffset);
        GUILayout.Label("Y");
        zOffset = EditorGUILayout.IntField(zOffset);

        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Publish Selected Tile "))
        {
            // Serialize to file
            STile   original = new STile(tile);
            Vector2 index    = new Vector2(
                (tile.transform.position.x / TILE_SIZE) + xOffset,
                (tile.transform.position.z / TILE_SIZE) + zOffset
                );

            string content = original.ToBase64();

            PublishTile(index, content);
        }

        if (publishError)
        {
            EditorGUILayout.HelpBox("Error publishing tile!", MessageType.Error);
        }
        else
        {
            EditorGUILayout.HelpBox(publishing ? ("Publishing tile at (" + xOffset + "," + zOffset + ")") : (published?"Published!":""), MessageType.Info);
        }
    }
Beispiel #7
0
    IEnumerator FetchTile(Vector2 index)
    {
        Vector3 pos = indexToPosition(index);

        // Temporal Placeholder
        GameObject plane  = Instantiate(baseTile, pos, Quaternion.identity);
        GameObject loader = Instantiate(loading, pos, Quaternion.identity);

        loader.transform.position = new Vector3(pos.x, pos.y + 2, pos.z);
        string fileName = "" + index[0] + "." + index[1] + ".lnd";
        WWW    www      = new WWW("https://decentraland.org/content/" + fileName);

        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.Log("Can't fetch tile content! " + index + " " + www.error);
            names.Add(index, "Unclaimed Land");
            Destroy(loader);
        }
        else
        {
            Debug.Log("Downloaded content for tile (" + index[0] + "," + index[1] + ")");
            try
            {
                STile t = STile.FromBytes(www.bytes);
                t.ToInstance(pos);
                names.Add(index, t.GetName());
            }
            catch (EndOfStreamException e)
            {
                Debug.Log("Invalid" + index + e.ToString());
            }
            catch (SerializationException e)
            {
                Debug.Log("Invalid" + index + e.ToString());
            }
            catch (Exception e)
            {
                Debug.Log("Exception found in " + index + e.ToString());
            }
            finally
            {
                Destroy(loader);
            }
        }
    }
Beispiel #8
0
    void AddTile(STile savedTile)
    {
        tileGrid[savedTile.grid_x, savedTile.grid_y] = new Tile_Data(savedTile.grid_x, savedTile.grid_y, new Vector3Int(savedTile.grid_x, savedTile.grid_y, 0), savedTile.tileType);

        if (savedTile.hasMachine == true)
        {
            MachinePrototype machineProto = Buildable_Manager.instance.GetMachinePrototype(savedTile.machineName);
            machineProto.machineCondition = savedTile.machineCondition;
            // use this proto to spawn the machine
        }
        else if (savedTile.hasProducer == true)
        {
            ProducerPrototype producerProto = Buildable_Manager.instance.GetProducerPrototype(savedTile.producerName);
            producerProto.productionStage   = savedTile.productionStage;
            producerProto.curProductionName = savedTile.itemProduced;
        }
    }
Beispiel #9
0
        public static void DrawPreview(SpriteBatch sb, Vector2 position)
        {
            int width  = ClipBoard.GetLength(0);
            int height = ClipBoard.GetLength(1);


            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    STile tile = GetClipboard(x, y);
                    if (tile.Wall > 0)
                    {
                        Vector2   pos         = position + new Vector2(x * 16, y * 16);
                        Texture2D wallTexture = Terraria.GameContent.TextureAssets.Wall[tile.Wall].Value;
                        sb.Draw(wallTexture, pos, new Rectangle(tile.WallFrameX(), tile.WallFrameY(), 32, 32), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                    }
                }
            }

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    STile tile = GetClipboard(x, y);
                    if (tile.Active())
                    {
                        if (Terraria.GameContent.TextureAssets.Tile[tile.Type] == null || !Terraria.GameContent.TextureAssets.Tile[tile.Type].IsLoaded)
                        {
                            Main.instance.LoadTiles(tile.Type);
                        }
                        Texture2D texture = Terraria.GameContent.TextureAssets.Tile[tile.Type].Value;
                        Color     color   = Color.White;
                        color.A = 160;
                        Rectangle?value = new Rectangle(tile.FrameX, tile.FrameY, 16, 16);
                        Vector2   pos   = position + new Vector2(x * 16, y * 16);
                        sb.Draw(texture, pos, value, color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                    }
                }
            }
        }
Beispiel #10
0
    public void ChangeTile(STile tile, ETiles newTileState)
    {
        tile.m_TileType = newTileState;

        // update colour
        switch (newTileState)
        {
        case ETiles.water:
            tile.m_GameObject.GetComponent <Renderer>().material = m_TileMaterials[(int)ETiles.water];
            break;

        case ETiles.sand:
            tile.m_GameObject.GetComponent <Renderer>().material = m_TileMaterials[(int)ETiles.sand];
            break;

        case ETiles.grass:
            tile.m_GameObject.GetComponent <Renderer>().material = m_TileMaterials[(int)ETiles.grass];
            break;

        default:
            break;
        }
    }
Beispiel #11
0
    void SaveTileDataTest()
    {
        savedTileGrid = new STile[width, height];
        SavedTiles tiles = new SavedTiles();

        tiles.savedTiles = new STile[width * height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                savedTileGrid[x, y]        = new STile();
                savedTileGrid[x, y].grid_x = x;
                savedTileGrid[x, y].grid_y = y;



                tiles.savedTiles[x * width + y] = savedTileGrid[x, y];
            }
        }


        JsonWriter.WriteTilesToJson(tiles, AreaID.Player_Ship);
    }
Beispiel #12
0
        private static void DoUpdateHook_Pre()
        {
            if (Loading)
            {
                unsafe
                {
                    IntPtr ptr    = Buffer;
                    int    width  = *(int *)ptr;
                    int    height = *(int *)(ptr + 4);

                    STile[,] tiles = new STile[width, height];
                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            tiles[x, y] = *((STile *)(ptr + 8) + x * height + y);
                        }
                    }
                    ClipBoard = tiles;
                }
                VirtualFree(Buffer, IntPtr.Zero);
                Loading = false;
            }
            if (Main.gameMenu || Main.playerInventory)
            {
                Brushing    = false;
                BrushActive = false;
                return;
            }
            Player player   = Main.LocalPlayer;
            bool   inside   = InsideScreen();
            bool   leftDown = Mouse.GetState().LeftButton == ButtonState.Pressed && !LastLeftPressed && LastFocus && inside;
            bool   leftUp   = Mouse.GetState().LeftButton != ButtonState.Pressed && LastLeftPressed && LastFocus && inside;
            bool   rightUp  = Mouse.GetState().RightButton != ButtonState.Pressed && LastRightPressed && LastFocus && inside;

            LastLeftPressed  = Mouse.GetState().LeftButton == ButtonState.Pressed;
            LastRightPressed = Mouse.GetState().RightButton == ButtonState.Pressed;
            LastFocus        = Main.hasFocus;
            if (rightUp)
            {
                Dropping         = false;
                Brushing         = false;
                EyeDropperActive = false;
                BrushActive      = false;
            }
            if (EyeDropperActive)
            {
                player.cursorItemIconID      = ItemID.EmptyDropper;
                player.cursorItemIconEnabled = true;
            }
            if (BrushActive)
            {
                player.cursorItemIconID      = ItemID.Paintbrush;
                player.cursorItemIconEnabled = true;
            }
            if (EyeDropperActive)
            {
                if (Dropping)
                {
                    EndPos = new Vector2(Player.tileTargetX, Player.tileTargetY);
                }
                if (leftDown)
                {
                    Main.mouseLeftRelease = false;
                    player.mouseInterface = true;
                    if (!Dropping)
                    {
                        Dropping  = true;
                        EndPos    = BeginPos = new Vector2(Player.tileTargetX, Player.tileTargetY);
                        ClipBoard = null;
                    }
                    else if (Dropping)
                    {
                        Dropping = false;
                        EndPos   = new Vector2(Player.tileTargetX, Player.tileTargetY);
                        Vector2 upperLeft  = new Vector2(Math.Min(BeginPos.X, EndPos.X), Math.Min(BeginPos.Y, EndPos.Y));
                        Vector2 lowerRight = new Vector2(Math.Max(BeginPos.X, EndPos.X), Math.Max(BeginPos.Y, EndPos.Y));
                        int     minX       = (int)upperLeft.X;
                        int     maxX       = (int)lowerRight.X + 1;
                        int     minY       = (int)upperLeft.Y;
                        int     maxY       = (int)lowerRight.Y + 1;
                        ClipBoard = new STile[maxX - minX, maxY - minY];
                        for (int x = minX; x < maxX; x++)
                        {
                            for (int y = minY; y < maxY; y++)
                            {
                                if (!WorldGen.InWorld(x, y))
                                {
                                    continue;
                                }
                                Tile from = Framing.GetTileSafely(x, y);
                                ClipBoard[x - minX, y - minY] = new STile
                                {
                                    Type         = from.type,
                                    Wall         = from.wall,
                                    Liquid       = from.liquid,
                                    STileHeader  = from.sTileHeader,
                                    BTileHeader  = from.bTileHeader,
                                    BTileHeader2 = from.bTileHeader2,
                                    BTileHeader3 = from.bTileHeader3,
                                    FrameX       = from.frameX,
                                    FrameY       = from.frameY
                                };
                            }
                        }
                        Main.NewTextMultiline($"Area selected:\n" +
                                              $"    From [C/FF9933:({minX}, {minY})] to [C/FF9933:({maxX}, {maxY})]\n" +
                                              $"    Totally [C/FF9933:{ClipBoard.Length}] blocks ([C/FF9933:{ClipBoard.GetLength(0)}] X [C/FF9933:{ClipBoard.GetLength(1)}])"
                                              , false, Color.White);
                    }
                }
            }
            else if (BrushActive && ClipBoard != null)
            {
                int   bWidth  = ClipBoard.GetLength(0);
                int   bHeight = ClipBoard.GetLength(1);
                Point Point   = (Main.MouseWorld + new Vector2((bWidth + 1) % 2, (bHeight + 1) % 2) * 8).ToTileCoordinates();
                Point.X -= bWidth / 2;
                Point.Y -= bHeight / 2;
                if (leftDown)
                {
                    player.mouseInterface = true;
                    BrushBeginPos         = Point.ToVector2();
                    Brushing = true;
                }
                else if (leftUp)
                {
                    player.mouseInterface = false;
                    Brushing = false;
                }
                if (Brushing)
                {
                    for (int x = 0; x < bWidth; x++)
                    {
                        for (int y = 0; y < bHeight; y++)
                        {
                            if (WorldGen.InWorld(x + Point.X, y + Point.Y))
                            {
                                Tile target  = Framing.GetTileSafely(x + Point.X, y + Point.Y);
                                int  cycledX = ((x + Point.X - (int)BrushBeginPos.X) % bWidth + bWidth) % bWidth;
                                int  cycledY = ((y + Point.Y - (int)BrushBeginPos.Y) % bHeight + bHeight) % bHeight;

                                STile tile = GetClipboard(cycledX, cycledY);
                                target.type         = tile.Type;
                                target.wall         = tile.Wall;
                                target.liquid       = tile.Liquid;
                                target.sTileHeader  = tile.STileHeader;
                                target.bTileHeader  = tile.BTileHeader;
                                target.bTileHeader2 = tile.BTileHeader2;
                                target.bTileHeader3 = tile.BTileHeader3;
                                target.frameX       = tile.FrameX;
                                target.frameY       = tile.FrameY;
                            }
                        }
                    }

                    for (int x = 0; x < bWidth; x++)
                    {
                        for (int y = 0; y < bHeight; y++)
                        {
                            if (WorldGen.InWorld(x + Point.X, y + Point.Y))
                            {
                                WorldGen.SquareTileFrame(x + Point.X, y + Point.Y, true);
                            }
                        }
                    }
                    if (Main.netMode == 1)
                    {
                        NetMessage.SendTileSquare(-1, Point.X + bWidth / 2, Point.Y + bHeight / 2, Math.Max(bWidth, bHeight));
                    }
                }
            }
        }
Beispiel #13
0
    IEnumerator FetchTile(Vector2 index)
    {
        Vector3 pos = indexToPosition(index);

        // Temporal Placeholder
        GameObject plane  = Instantiate(baseTile, pos, Quaternion.identity);
        GameObject loader = Instantiate(loading, pos, Quaternion.identity);

        loader.transform.position = new Vector3(pos.x, pos.y + 2, pos.z);

        // Basic Auth
        Dictionary <string, string> headers = new Dictionary <string, string>();

        headers["Authorization"] = "Basic " + System.Convert.ToBase64String(
            System.Text.Encoding.ASCII.GetBytes("bitcoinrpc:38Dpwnjsj1zn3QETJ6GKv8YkHomA"));

        // JSON Data
        string json = "{\"method\":\"gettile\",\"params\":[" + index [0] + "," + index [1] + "],\"id\":0}";

        byte[] data = System.Text.Encoding.ASCII.GetBytes(json.ToCharArray());

        WWW www = new WWW("http://s1.decentraland.org:8301", data, headers);

        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            RPCResponse response = JsonUtility.FromJson <RPCResponse>(www.text);
            Destroy(loader);
            if (response.IsEmpty())
            {
                // TODO: do empty behavior
            }
            else if (response.IsUnmined())
            {
                names.Add(index, "Unclaimed Land");
            }
            else if (response.HasData())
            {
                // Download tile content
                string fileName = "" + index [0] + "." + index [1] + ".lnd";
                www = new WWW("http://s1.decentraland.org:9301/tile/" + fileName);
                yield return(www);

                if (string.IsNullOrEmpty(www.error))
                {
                    Debug.Log("Downloaded content for tile (" + index[0] + "," + index[1] + ")");
                    STile t = STile.FromBytes(www.bytes);
                    t.ToInstance(pos);
                    names.Add(index, t.GetName());
                }
                else
                {
                    Debug.Log("Can't fetch tile content! " + index + " " + www.error);
                }
            }
        }
        else
        {
            Debug.Log("Error on RPC call 'gettile': " + www.error);
        }
    }
Beispiel #14
0
    public List <STile> GetTileNeighbours(STile tile)
    {
        // 8 directions clockwise, 0 north -> 7 north west
        var result = new List <STile>();

        bool[] dirChecks = new bool[4];         // NESW

        // grid is tileSize x tileSize
        if (tile.m_Position.y < tileSize - 1)
        {
            dirChecks[0] = true;
        }
        if (tile.m_Position.x < tileSize - 1)
        {
            dirChecks[1] = true;
        }
        if (tile.m_Position.y > 0)
        {
            dirChecks[2] = true;
        }
        if (tile.m_Position.x > 0)
        {
            dirChecks[3] = true;
        }

        if (dirChecks[0] && dirChecks[1] && dirChecks[2] && dirChecks[3])
        {
            return(new List <STile>()
            {
                m_Tiles[tile.m_Position.x, tile.m_Position.y + 1],
                m_Tiles[tile.m_Position.x + 1, tile.m_Position.y + 1],
                m_Tiles[tile.m_Position.x + 1, tile.m_Position.y],
                m_Tiles[tile.m_Position.x + 1, tile.m_Position.y - 1],
                m_Tiles[tile.m_Position.x, tile.m_Position.y - 1],
                m_Tiles[tile.m_Position.x - 1, tile.m_Position.y - 1],
                m_Tiles[tile.m_Position.x - 1, tile.m_Position.y],
                m_Tiles[tile.m_Position.x - 1, tile.m_Position.y + 1]
            });
        }

        else
        {
            // 0 1
            if (dirChecks[0])
            {
                result.Add(m_Tiles[tile.m_Position.x, tile.m_Position.y + 1]);

                if (dirChecks[1])
                {
                    result.Add(m_Tiles[tile.m_Position.x + 1, tile.m_Position.y + 1]);
                }
                else
                {
                    result.Add(m_Neighbours[2].m_Tiles[0, tile.m_Position.y + 1]);
                }
            }
            else
            {
                result.Add(m_Neighbours[0].m_Tiles[tile.m_Position.x, 0]);

                if (dirChecks[1])
                {
                    result.Add(m_Neighbours[0].m_Tiles[tile.m_Position.x + 1, 0]);
                }
                else
                {
                    result.Add(m_Neighbours[1].m_Tiles[0, 0]);
                }
            }

            // 2 3
            if (dirChecks[1])
            {
                result.Add(m_Tiles[tile.m_Position.x + 1, tile.m_Position.y]);

                if (dirChecks[2])
                {
                    result.Add(m_Tiles[tile.m_Position.x + 1, tile.m_Position.y - 1]);
                }
                else
                {
                    result.Add(m_Neighbours[4].m_Tiles[tile.m_Position.x + 1, tileSize - 1]);
                }
            }
            else
            {
                result.Add(m_Neighbours[2].m_Tiles[0, tile.m_Position.y]);

                if (dirChecks[2])
                {
                    result.Add(m_Neighbours[2].m_Tiles[0, tile.m_Position.y - 1]);
                }
                else
                {
                    result.Add(m_Neighbours[3].m_Tiles[0, tileSize - 1]);
                }
            }

            // 4 5
            if (dirChecks[2])
            {
                result.Add(m_Tiles[tile.m_Position.x, tile.m_Position.y - 1]);

                if (dirChecks[3])
                {
                    result.Add(m_Tiles[tile.m_Position.x - 1, tile.m_Position.y - 1]);
                }
                else
                {
                    result.Add(m_Neighbours[6].m_Tiles[tileSize - 1, tile.m_Position.y - 1]);
                }
            }
            else
            {
                result.Add(m_Neighbours[4].m_Tiles[tile.m_Position.x, tileSize - 1]);

                if (dirChecks[3])
                {
                    result.Add(m_Neighbours[4].m_Tiles[tile.m_Position.x - 1, tileSize - 1]);
                }
                else
                {
                    result.Add(m_Neighbours[5].m_Tiles[tileSize - 1, tileSize - 1]);
                }
            }

            // 6 7
            if (dirChecks[3])
            {
                result.Add(m_Tiles[tile.m_Position.x - 1, tile.m_Position.y]);

                if (dirChecks[0])
                {
                    result.Add(m_Tiles[tile.m_Position.x - 1, tile.m_Position.y + 1]);
                }
                else
                {
                    result.Add(m_Neighbours[0].m_Tiles[tile.m_Position.x - 1, 0]);
                }
            }
            else
            {
                result.Add(m_Neighbours[6].m_Tiles[tileSize - 1, tile.m_Position.y]);

                if (dirChecks[0])
                {
                    result.Add(m_Neighbours[6].m_Tiles[tileSize - 1, tile.m_Position.y + 1]);
                }
                else
                {
                    result.Add(m_Neighbours[7].m_Tiles[tileSize - 1, 0]);
                }
            }
        }

        return(result);
    }
Beispiel #15
0
 public bool ContainsTile(STile tile)
 {
     return((m_Tiles[tile.m_Position.x, tile.m_Position.y].Equals(tile)) ? true : false);
 }
Beispiel #16
0
    public STile GetNewTarget(STile current, STile old)     // TODO update to use STile
    {
        STile result = old;

        // rand direction
        int rand = Random.Range(1, 100);

        MapObject currentMapObject = null;
        var       numOfTiles       = m_TileList.Count;

        for (int i = 0; i < numOfTiles; ++i)
        {
            if (m_TileList[i].ContainsTile(current))
            {
                currentMapObject = m_TileList[i];
                break;
            }
        }


        var n = currentMapObject.GetTileNeighbours(current);
        int p = 0;                  // the position / forward direction

        for (int i = 0; i < 8; ++i) // only ever 8 neighbours
        {
            if (n[i].Equals(old))
            {
                p = 4 + i;
            }
        }
        if (rand > 75 && rand <= 100)         // forward
        {
            result = currentMapObject.GetTile(current.m_Position + current.m_Position - old.m_Position);
        }

        else if (rand > 57 && rand <= 75)         // forward right
        {
            result = n[(p + 1) % 8];
        }

        else if (rand > 24 && rand <= 39)         // right
        {
            result = n[(p + 2) % 8];
        }

        else if (rand > 5 && rand <= 9)         // back right
        {
            result = n[(p + 3) % 8];
        }

        // back is old and is done asap

        else if (rand > 1 && rand <= 5)         // back left
        {
            result = n[(p + 5) % 8];
        }

        else if (rand > 9 && rand <= 24)         // left
        {
            result = n[(p + 6) % 8];
        }

        else if (rand > 39 && rand <= 57)         // forward left
        {
            result = n[(p + 7) % 8];
        }

        else
        {
            // something went wrong
            Debug.Log("Get new target didnt get return dirrection");
            return(current);
        }

        // if its not water its fine
        if (result.m_TileType != ETiles.water)
        {
            return(result);
        }

        // if its water find a non water tile
        List <STile> nonWaterTiles = new List <STile>();

        for (int i = 0; i < n.Count; ++i)
        {
            if (n[i].m_TileType != ETiles.water)
            {
                nonWaterTiles.Add(n[i]);
            }
        }

        if (nonWaterTiles.Count > 0)
        {
            rand = Random.Range(0, nonWaterTiles.Count);
            return(nonWaterTiles[rand]);
        }
        else
        {
            return(old);
        }
    }