still a little problem :S (sorry 😃)
heres your function
function find_adjacent($sector_id, $depth)
{
$adjacents = array();
for($x=1;$x<=$depth;$x++)
{
//west
$west = $sector_id - $x;
if (!in_array($west,$adjacents)) { $adjacents[] = $west; }
//east
$east = $sector_id + $x;
if (!in_array($east,$adjacents)) { $adjacents[] = $east; }
for($y=1;$y<=$depth;$y++)
{
//northwest
$northwest = (($sector_id - $x) - ($y * 50));
if (!in_array($northwest,$adjacents)) { $adjacents[] = $northwest; }
//north
$north = $sector_id - ($y * 50);
if (!in_array($north,$adjacents)) { $adjacents[] = $north; }
//northeast
$northeast = (($sector_id + $x) - ($y * 50));
if (!in_array($northeast,$adjacents)) { $adjacents[] = $northeast; }
//southeast
$southeast = (($sector_id + $x) + ($y * 50));
if (!in_array($southeast,$adjacents)) { $adjacents[] = $southeast; }
//south
$south = $sector_id + ($y * 50);
if (!in_array($south,$adjacents)) { $adjacents[] = $south; }
//southwest
$southwest = (($sector_id - $x) + ($y * 50));
if (!in_array($southwest,$adjacents)) { $adjacents[] = $southwest; }
}
}
sort($adjacents); //just makes the array easier to read on vardumps...
return $adjacents;
}
and heres the makeadjacent array function
function makeadjacentarray(&$array, $sector, $depth) {
// Add current sector to the list
$array[$sector] = true;
echo " MAKE ADJACENT ARRAY FUNCTION<BR>sector given: $sector<BR>";
echo "depth: $depth<BR>";
if ($depth > 0) {
// Go through adjacent sectors
$neighbours = find_adjacent($sector, $depth - 1);
foreach ($neighbours as $neighbour) {
//echo "neighbour: $neighbour<BR>";
//echo "checking array: " . $array[$neighbour] . " [DONE]<BR>";
if($array[$neighbour] == true)
{
//echo "already found adjacent for $neighbour<BR>";
}
else
{
echo "<BR>MAKE ADJACENT ARRAY FUNCTION<BR>calling make-adjacent for: $neighbour, depth is: $depth<BR><BR>";
makeadjacentarray($array, $neighbour, $depth - 1);
//echo "new depth: $depth<BR>";
}
}
}
return array_keys($array);
}
unfortunatly when i run this:
$test_array = Array();
$result = makeadjacentarray($test_array,$ship->ship_sectorid,2);
to find a depth of 2 from the current ships location, it comes out with just 1 set of adjacents instead of 2
if i ask it to do 3 it works but misses one square, and the attatched image is what happens if i ask it to do 4:
EDIT: theres also a line at the other end of the map that you cant see, sectors 50-400 (vertical line at the other side of the map) are filled blue