Reply To: We need a "Suggestions" thread

Home Forums Wayward We need a "Suggestions" thread Reply To: We need a "Suggestions" thread

#4752
Quantum Leap
Member

Well.. Originally, I thought that Wayward’s code is too big to do Fallout-like customizations, and I started prototyping things on my own. It grew bigger and bigger until I realized that it comes close to the original codes in size (ouch). I will send you private link to its full source via email. Meanwhile, here is my ugly chunk of pathfinding code, which could be easily modified to work within Wayward:

GAME.GUI.SCREEN.GetPossiblePathXY = function( world, x1, y1, x2, y2, movement ) { // world map coordinates
    var tiles = GAME.MAP.mTileMap[world];

    var minx = x2 < x1 ? x2 : x1, maxx = x2 > x1 ? x2 : x1;
    var miny = y2 < y1 ? y2 : y1, maxy = y2 > y1 ? y2 : y1;
    var gridx = (maxx - minx) + 10, gridy = (maxy - miny) + 10;

    var grid = new PF.Grid(gridx, gridy);

    for ( var i = (minx - 5), lenx = ( maxx + 5 ); i < lenx; i++ ) {
        for ( var j = (miny - 5), leny = ( maxy + 5 ); j < leny; j++ ) {
            if ( GAME.UNITS.Get(world, i, j) != false ) {
                grid.setWalkableAt( i - (minx - 5), j - (miny - 5), false);
                continue;
            }
            if ( movement.inArray( tiles[i][j].move ) == false ) {
                grid.setWalkableAt( i - (minx - 5), j - (miny - 5), false);
                continue;
            }
        }
    }
        
    var finder = new PF.AStarFinder({allowDiagonal: false});

    var path = finder.findPath( x1 - (minx - 5),  y1 - (miny - 5), x2 - (minx - 5), y2 - (miny - 5), grid );

    if ( path.length > 0 ) {
        for ( var i = 0; i < path.length; i++ ) {
            path[i] = [ path[i][0] + (minx - 5), path[i][1] + (miny - 5) ];
        }
    }
    
    return path; // world coordinates, includes start/stop points
};

Again, as everything else in my protoWard, it was hacked in mere minutes just to get results fast. Don’t kick me too hard..

PS: Yep, I noticed a lot of changes in Wayward, thank you!