I've been slowly making progress with my RPG, and I'm currently working on creating roads between towns. Ultimately, I want roads built between some - but not all - towns. I've biased my A* implementation to heavily favor existing roads, otherwise the map becomes a huge mess of roads that don't utilize existing roads. Note that all map tiles are considered walkable for roadbuilding.
The problem? It hangs when I ask it to only apply some roads, rather than all of the potential roads. See the attached .love file. Here's the offending code, which comes from map.lua starting at line 319:
Code: Select all
-- Calculate paths between Locations
local paths = {}
for i = 1, #nodeDist do
local n1, n2 = nodeDist[i].n1, nodeDist[i].n2
paths[i] = ai.pathfind(map, nodeDist[i].x1, nodeDist[i].y1, nodeDist[i].x2, nodeDist[i].y2)
if paths[i] then
-- *** APPLY TUNNELS & FERRIES HERE ***
local pointsTotal = nodeByID[n1].points * nodeByID[n2].points
print("n1:"..tostring(n1).."\tn2:"..tostring(n2).."\tcost:"..tostring(paths[i].cost).."\tpoints:"..tostring(pointsTotal).."\tbuild:"..tostring(pointsTotal >= paths[i].cost))
--~ if pointsTotal >= paths[i].cost then
for j = 1, #paths[i] do
local x = paths[i][j].x
local y = paths[i][j].y
map[x][y].pathCost = map.roadCost
map[x][y].feature = map[x][y].feature + 1
end
--~ end
end
end
Help?
EDIT - I figured it out. It will also hang if I comment out map[x][y].pathCost = map.roadCost, which (eventually!) helped me figure out that previous roads were making later roads much more efficient to build - even though the end result was a TON of roads scattered across the map. That was a bad assumption on my part, lol. I've got lots of balancing to do with this, and some sections will have to go back to the drawing board.