Mongoose wrote:
I think what he's getting at is that it's sorted by the distance from the origin, but it displays the distance to the origin. If this isn't a bug, it may be a misfeature.
The result of the getNearestWarps command is simply a sorted list. Nothing is displayed, and no distances are indicated.
Tweety wrote:
so in reality getnearestwarps seems to give you the nearest warp out of a sector instead of nearest warp into a sector.
Correct. In TWX (and TW in general I believe), the term WARPS is always used to indicate warps out. I'll take that a step further and say that warps (meaning warps out) are known, and warps in are calculated or deduced. So I assert that the term WARPS is unambiguous, and always means warps out. I regret if this has caused confusion, but the command's name is consistent with other TWX command names involving warps and warps in.
getNearestWarps simply performs a breadth-first search with the specified origin, and returns the sorted results in an array. It is identical to the following code, where $origin is the origin, and $queue is the sorted resultant array:
Code:
setArray $checked SECTORS
setVar $checked[$origin] TRUE
setVar $top 1
setVar $bottom 1
setArray $queue SECTORS
setVar $queue[1] $origin
while ($bottom <= $top)
setvar $focus $queue[$bottom]
setVar $i 1
while ($i <= SECTOR.WARPCOUNT[$focus])
setVar $adjacent SECTOR.WARPS[$focus][$i]
if ($checked[$adjacent] = FALSE)
add $top 1
setVar $queue[$top] $adjacent
setVar $checked[$adjacent] TRUE
end
add $i 1
end
add $bottom 1
end
setArray $checked 0
I created getNearestWarps because I found that I used the above BFS code repeatedly. I wanted to speed it up and simplify it's usage, and thus getNearestWarps was born. There is a clear need for getNearestWarpsIn, but it hasn't made it into the TWX code yet. Until such a time, the BFS code above requires minor modification to return results based on WarpsIn, and is as efficient as it can be without being a native command. I'd be happy to post the WarpsIn version though.