procedure TwoWayDistances( sec : sector; var D : distanceArray; inward, outward : boolean ); { inward = accept TOWARD sec; outward = accept LEAVING sec } { D[j].d = distance from sec; D[j].s = one node close } var si : sectorIndex; wi : warpIndex; breadth : queue; s, daddy, sonny : sector; i : warpindex; entered : array [ sector ] of boolean; begin if inward then write('(This may take a while.) '); writeln('Computing distances...'); for s := 1 to maxSector do begin D[s].d := -1; entered[ s ] := false; end; {for} breadth.front := 0; enqueue( breadth, sec, sec ); entered[sec] := true; while breadth.front > 0 do begin serve( breadth, daddy, sonny ); if D[ sonny ].d = -1 then {haven't hit him before:} begin D[ sonny ].d := D[ daddy ].d + 1; D[ sonny ].s := daddy; if outward then with space.sectors[ sonny ] do if number > 0 then for wi := 1 to number do if not entered[ data[wi] ] then begin enqueue( breadth, sonny, data[ wi ] ); entered[ data[wi] ] := true; end; {if with for if} if inward then for s := 1 to maxSector do if not entered[ s ] then if IsWarp( s, sonny ) then begin enqueue( breadth, sonny, s ); entered[ s ] := true; end; {if for if if} end; {if} end; {while} for s := 1 to maxSector do if D[s].d = -1 then D[s].d := maxint; end; {FixDistances} function CountDist(var D : distancearray; howfar : integer ):integer; var c : integer; s : sector; begin c := 0; for s := 1 to maxSector do if D[ s ].d <= howfar then c := c + 1; countDist := c; end; {CountDist}