nsteps = 0
pathset = true
destx = mouse_x
desty = mouse_y
gridx = round(x / global.gridsize) * global.gridsize
gridy = round(y / global.gridsize) * global.gridsize
gdestx = round(destx / global.gridsize) * global.gridsize
gdesty = round(desty / global.gridsize) * global.gridsize
if collision_circle(gdestx,gdesty,global.pradius,OWall,true,false)
{
pathset = false
exit
}
cx = gridx
cy = gridy
openx = ds_list_create()
openy = ds_list_create()
openf = ds_list_create()
openpx = ds_list_create()
openpy = ds_list_create()
closedx = ds_list_create()
closedy = ds_list_create()
donerouting = false
while (donerouting == false)
{
if nsteps >= maxsteps
{
show_message("Reached max steps!")
donerouting = true
break;
}
nsteps += 1
ds_list_add(closedx,cx)
ds_list_add(closedy,cy)
if cx == gdestx and cy == gdesty
{
donerouting = true
show_debug_message("Success")
break;
}
//Adjacents
putx = cx-global.gridsize
puty = cy
AddOpen(putx,puty,vercost)
putx = cx+global.gridsize
puty = cy
AddOpen(putx,puty,vercost)
putx = cx
puty = cy+global.gridsize
AddOpen(putx,puty,vercost)
putx = cx
puty = cy-global.gridsize
AddOpen(putx,puty,vercost)
//Diagonals
if allowdiag == true
{
putx = cx+global.gridsize
puty = cy+global.gridsize
AddOpen(putx,puty,diagcost)
putx = cx+global.gridsize
puty = cy-global.gridsize
AddOpen(putx,puty,diagcost)
putx = cx-global.gridsize
puty = cy-global.gridsize
AddOpen(putx,puty,diagcost)
putx = cx-global.gridsize
puty = cy+global.gridsize
AddOpen(putx,puty,diagcost)
}
lowestf = 0
lowfset = false
lowestid = 0
for(i=0;i<ds_list_size(openx);i+=1)
{
thisf = ds_list_find_value(openf,i)
thispx = ds_list_find_value(openx,i)
thispy = ds_list_find_value(openy,i)
if lowfset == false
{
if allowdiag == false
{
if (thispx == cx-global.gridsize and thispy == cy) or (thispx == cx+global.gridsize and thispy == cy) or (thispx == cx and thispy == cy+global.gridsize) or (thispx == cx and thispy == cy-global.gridsize)
{
lowfset = true
lowestf = thisf
lowestid = i
}
}
else
{
if (thispx == cx or thispx == cx-global.gridsize or thispx == cx+global.gridsize) and (thispy == cy or thispy == cy-global.gridsize or thispy == cy+global.gridsize)
{
lowfset = true
lowestf = thisf
lowestid = i
}
}
}
else
{
if thisf <= lowestf
{
if allowdiag == false
{
if (thispx == cx-global.gridsize and thispy == cy) or (thispx == cx+global.gridsize and thispy == cy) or (thispx == cx and thispy == cy+global.gridsize) or (thispx == cx and thispy == cy-global.gridsize)
{
lowfset = true
lowestf = thisf
lowestid = i
}
}
else
{
if (thispx == cx or thispx == cx-global.gridsize or thispx == cx+global.gridsize) and (thispy == cy or thispy == cy-global.gridsize or thispy == cy+global.gridsize)
{
lowfset = true
lowestf = thisf
lowestid = i
}
}
}
}
}
if lowfset == false or ds_list_size(openx) == 0
{
show_message("Routing failed")
ds_list_clear(openx)
ds_list_clear(openy)
ds_list_clear(openf)
ds_list_clear(closedx)
ds_list_clear(closedy)
ds_list_clear(openpx)
ds_list_clear(openpy)
pathset = false
break;
}
else
{
if lowfset == true
{
cx = ds_list_find_value(openx,lowestid)
cy = ds_list_find_value(openy,lowestid)
ds_list_delete(openx,lowestid)
ds_list_delete(openy,lowestid)
ds_list_delete(openf,lowestid)
}
}
}