コード例 #1
0
function getPlotDistanceOld(SmrSector &$sector, SmrSector &$target)
{
    $plotter = new Course_Plotter();
    $plotter->set_course($sector->getSectorID(), $target->getSectorID(), $sector->getGameID());
    $plotter->plot();
    $return = $plotter->plotted_course[0];
    $plotter->Course_Plotter_Destructor();
    unset($plotter);
    return $return;
}
コード例 #2
0
function getGoodDistanceOld(SmrSector &$sector, $goodID, $transaction)
{
    // if we buy a good we're looking for the nearest sector that sells that good
    if ($transaction == 'Buy') {
        $neg_transaction = 'Sell';
    } elseif ($transaction == 'Sell') {
        $neg_transaction = 'Buy';
    }
    // initialize the queue. all sectors we have to visit are in here
    $sector_queue = array();
    // keeps the distance to the start sector
    $sector_distance = array();
    // putting start sector in queue
    array_push($sector_queue, $sector->getSectorID());
    // it has a null distance
    $sector_distance[$sector->getSectorID()] = 0;
    $good_distance = 0;
    while (sizeof($sector_queue) > 0) {
        // get current sector and
        $curr_sector_id = array_shift($sector_queue);
        // get the distance for this sector from the start sector
        $distance = $sector_distance[$curr_sector_id];
        // create a new sector object
        $curr_sector =& SmrSector::getSector($sector->getGameID(), $curr_sector_id);
        // does the current sector buy/sell the good we're looking for?
        if ($good_distance != 0) {
            if ($curr_sector->hasPort() && $curr_sector->getPort()->hasGood($goodID, $neg_transaction) && $distance < $good_distance) {
                $good_distance = $distance;
            }
        } else {
            if ($curr_sector->hasPort() && $curr_sector->getPort()->hasGood($goodID, $neg_transaction)) {
                $good_distance = $distance;
            }
        }
        // if we already found a port that buy or sell our product we don't need
        // to go further than this one.
        if ($good_distance != 0 && $good_distance <= $distance) {
            continue;
        }
        // enqueue all neighbours
        if ($curr_sector->getLinkUp() > 0 && (!isset($sector_distance[$curr_sector->getLinkUp()]) || $sector_distance[$curr_sector->getLinkUp()] > $distance + 1)) {
            array_push($sector_queue, $curr_sector->getLinkUp());
            $sector_distance[$curr_sector->getLinkUp()] = $distance + 1;
        }
        if ($curr_sector->getLinkDown() > 0 && (!isset($sector_distance[$curr_sector->getLinkDown()]) || $sector_distance[$curr_sector->getLinkDown()] > $distance + 1)) {
            array_push($sector_queue, $curr_sector->getLinkDown());
            $sector_distance[$curr_sector->getLinkDown()] = $distance + 1;
        }
        if ($curr_sector->getLinkLeft() > 0 && (!isset($sector_distance[$curr_sector->getLinkLeft()]) || $sector_distance[$curr_sector->getLinkLeft()] > $distance + 1)) {
            array_push($sector_queue, $curr_sector->getLinkLeft());
            $sector_distance[$curr_sector->getLinkLeft()] = $distance + 1;
        }
        if ($curr_sector->getLinkRight() > 0 && (!isset($sector_distance[$curr_sector->getLinkRight()]) || $sector_distance[$curr_sector->getLinkRight()] > $distance + 1)) {
            array_push($sector_queue, $curr_sector->getLinkRight());
            $sector_distance[$curr_sector->getLinkRight()] = $distance + 1;
        }
        if ($curr_sector->getWarp() > 0 && (!isset($sector_distance[$curr_sector->getWarp()]) || $sector_distance[$curr_sector->getWarp()] > $distance + 5)) {
            array_push($sector_queue, $curr_sector->getWarp());
            $sector_distance[$curr_sector->getWarp()] = $distance + 5;
        }
    }
    $container['good_distance'] = $good_distance;
    return $good_distance;
}