Skip to content

Incorrectly set dirt/rock tiles #12

@blayzenw

Description

@blayzenw

The way that the tiles are set makes rock tiles that a player can dig. The problem is with the updateAPIMap function in WGenerator.java. It does not set the 4 tiles around the vertice to dirt/grass when processing the type of tile.

The fix for this requires doing three passes when setting the surface tiles:
The first sets everything rock.
The second places 4 dirt tiles around each vertex (set all 9 vertices to dirt to tell wurm to not allow digging on any tile on the dirt border)
The third places bushes and trees so they don't get painted over by the dirt

This is the fixed code

    private void updateAPIMap() {
        MapData map = getAPI().getMapData();
        Random treeRand = new Random(System.currentTimeMillis());

        for (int i = 0; i < heightMap.getMapSize(); i++) {
            for (int j = 0; j < heightMap.getMapSize(); j++) {
                map.setSurfaceHeight(i, j, tileMap.getSurfaceHeight(i, j));
                map.setRockHeight(i, j, tileMap.getRockHeight(i, j));

                if (tileMap.hasOres())
                    map.setCaveTile(i, j, tileMap.getOreType(i, j), tileMap.getOreCount(i, j));

                map.setSurfaceTile(i, j, Tile.TILE_ROCK);
            }
        }
        for (int i = 0; i < heightMap.getMapSize(); i++) {
            for (int j = 0; j < heightMap.getMapSize(); j++) {
                if(tileMap.getType(i, j) != Tile.TILE_ROCK && !tileMap.getType(i, j).isTree() && !tileMap.getType(i, j).isBush()){
                    for(int x = i - 1; x < i + 1; x++)
                        for(int y = j - 1; y < j + 1; y++)
                            if(x > 0 && y > 0 && x < heightMap.getMapSize() && y <heightMap.getMapSize())
                                map.setSurfaceTile(x, y, tileMap.getType(i, j));
                }   
            }
        }
        for (int i = 0; i < heightMap.getMapSize(); i++) {
            for (int j = 0; j < heightMap.getMapSize(); j++) {
                if (tileMap.getType(i, j).isTree())
                    map.setTree(i, j, tileMap.getType(i, j).getTreeType((byte) 0), 
                            FoliageAge.values()[treeRand.nextInt(FoliageAge.values().length)], GrowthTreeStage.MEDIUM);
                else if (tileMap.getType(i, j).isBush())
                    map.setBush(i, j, tileMap.getType(i, j).getBushType((byte) 0), 
                            FoliageAge.values()[treeRand.nextInt(FoliageAge.values().length)], GrowthTreeStage.MEDIUM);
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions