Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I start mapping legal moves and pathfind in a turn-based game?

Asked by 5 years ago

Hello. I am working on a turn-based strategy game which is based on a grid of many blocks. Here is a code snippet of my terrain generation (keep in mind that some variables here are called earlier):

local terrain = {}
function planTerrain() -- put terrain into array
for x = 1,size.X do
    terrain[x] = {}
    for y = 1, size.Y do
        local noise = 10*math.noise(x/5,y/5,seed)
        local currentblock
        --if noise >= 1 then
        --currentblock = "Mountain"   -- turn into building?
        if  noise >= -1 then
        currentblock = "Grass"
        else
        currentblock = "Water"
        end
        if currentblock then
        local blocktags = {
            block = currentblock;
            biome = GetBiome(x,y);
            size = B_I[currentblock].Size;
            canwalkon = B_I[currentblock].CanWalkOn;
            currentunit = nil;
            coords = Vector2.new(x,y);
            building = nil
            }
        table.insert(terrain[x],y,blocktags)

        end

        end
    end

    updateclients()
    return terrain
end


planTerrain() --excecute planning

On the clientside, the 2d array gets visualized, and the player can invoke the server from there. I even made a remote function which the player can invoke to move a unit. My only problem, however, is deciding which moves are legal. Water, mountains, etc. should all block unit paths. Not to mention, each unit has its own movement points (aka the max blocks it can walk every turn). I wanted to use PathfindingService but I have no idea how to display SurfaceGuis on moves that are valid.

I just don't know where to even start.

Answer this question