Esempio n. 1
0
function getGoodDistanceNew(SmrSector &$sector, $goodID, $transaction)
{
    global $var, $container;
    // check if we already did this
    if (isset($var['good_distance'])) {
        // transfer this value
        transfer('good_distance');
        // return this value
        return $var['good_distance'];
    }
    $x = Globals::getGood($goodID);
    switch ($transaction) {
        case 'Buy':
            $x['TransactionType'] = 'Sell';
            break;
        case 'Sell':
            $x['TransactionType'] = 'Buy';
    }
    $di = Plotter::findDistanceToX($x, $sector, true);
    if (is_object($di)) {
        $di = $di->getRelativeDistance();
    }
    $container['good_distance'] = $di;
    return $di;
}
Esempio n. 2
0
if ($player->getTurns() < 1) {
    create_error('You do not have enough turns to dump cargo!');
}
//lets make sure there is actually that much on the ship
if ($amount > $ship->getCargo($good_id)) {
    create_error('You can\'t dump more than you have.');
}
$sector =& $player->getSector();
if ($sector->offersFederalProtection()) {
    create_error('You can\'t dump cargo in a Federal Sector!');
}
require_once 'shop_goods.inc';
// get the distance
$x = Globals::getGood($good_id);
$x['TransactionType'] = 'Sell';
$good_distance = Plotter::findDistanceToX($x, $sector, true);
if (is_object($good_distance)) {
    $good_distance = $good_distance->getRelativeDistance();
}
$good_distance = max(1, $good_distance);
$lost_xp = round(SmrPort::getBaseExperience($amount, $good_distance));
$player->decreaseExperience($lost_xp);
$player->increaseHOF($lost_xp, array('Trade', 'Experience', 'Jettisoned'), HOF_PUBLIC);
// take turn
$player->takeTurns(1, 1);
$ship->decreaseCargo($good_id, $amount);
$player->increaseHOF($amount, array('Trade', 'Goods', 'Jettisoned'), HOF_PUBLIC);
// log action
$account->log(LOG_TYPE_TRADING, 'Dumps ' . $amount . ' of ' . $good_name . ' and looses ' . $lost_xp . ' experience', $player->getSectorID());
$container = array();
$container['url'] = 'skeleton.php';
    if (!isset($_REQUEST['xtype']) || !isset($_REQUEST['X'])) {
        create_error('You have to select what you would like to find.');
    }
    $xType = $_REQUEST['xtype'];
    $X = $_REQUEST['X'];
    $realX = Plotter::getX($xType, $X, $player->getGameID());
    if ($realX === false) {
        create_error('Invalid search.');
    }
    $account->log(LOG_TYPE_MOVEMENT, 'Player plots to nearest ' . $xType . ': ' . $X . '.', $player->getSectorID());
}
$container = create_container('skeleton.php', 'course_plot_result.php');
$sector =& $player->getSector();
if ($sector->hasX($realX, $player)) {
    create_error('Current sector has what you\'re looking for!');
}
$path =& Plotter::findDistanceToX($realX, $sector, true, $player, $player);
if ($path === false) {
    create_error('Unable to find what you\'re looking for, it either hasn\'t been added to this game or you haven\'t explored it yet.');
}
if ($path->getEndSectorID() < $sector->getSectorID()) {
    //If sector we find is a lower sector id we replot so we always use the plot from lowest to highest sector.
    $path =& Plotter::findDistanceToX($sector, $path->getEndSector(), true);
    $path->reversePath();
}
$container['Distance'] = serialize($path);
$path->removeStart();
if ($sector->isLinked($path->getNextOnPath()) && $path->getTotalSectors() > 0) {
    $player->setPlottedCourse($path);
}
forward($container);
}
// send scout msg
$sector->leavingSector($player, MOVEMENT_JUMP);
// Move the user around
// TODO: (Must be done while holding both sector locks)
$distance = $path->getRelativeDistance();
$turnsToJump = max(TURNS_JUMP_MINIMUM, round($distance * TURNS_PER_JUMP_DISTANCE));
// check for turns
if ($player->getTurns() < $turnsToJump) {
    create_error('You don\'t have enough turns for that jump!');
}
$maxMisjump = max(0, round(($distance - $turnsToJump) * MISJUMP_DISTANCE_DIFF_FACTOR / (1 + $player->getLevelID() * MISJUMP_LEVEL_FACTOR)));
$misjump = mt_rand(0, $maxMisjump);
if ($misjump > 0) {
    // we missed the sector
    $distances = Plotter::findDistanceToX('Distance', $targetSector, false, null, null, $misjump);
    while (count($distances[$misjump]) == 0) {
        $misjump--;
    }
    $misjumpSector = array_rand($distances[$misjump]);
    if ($misjumpSector == null) {
        throw new Exception('Misjump sector is null, distances: ' . var_export($distances, true));
    }
    $player->setSectorID($misjumpSector);
    unset($distances);
} else {
    // we hit it. exactly
    $player->setSectorID($targetSector->getSectorID());
}
$player->takeTurns($turnsToJump, $turnsToJump);
// log action
Esempio n. 5
0
function getPlotDistanceNew(SmrSector &$sector, SmrSector &$target)
{
    $path =& Plotter::findDistanceToX($target, $sector, true);
    return $path->getRelativeDistance();
}
foreach ($galaxies as &$galaxy) {
    if ($galaxy->contains($start)) {
        $startExists = true;
    }
    if ($galaxy->contains($target)) {
        $targetExists = true;
    }
}
unset($galaxy);
if ($startExists === false || $targetExists === false) {
    create_error('The sectors have to exist!');
}
$account->log(LOG_TYPE_MOVEMENT, 'Player plots to ' . $target . '.', $player->getSectorID());
$container = array();
$container['url'] = 'skeleton.php';
$container['body'] = 'course_plot_result.php';
require_once get_file_loc('Plotter.class.inc');
$path =& Plotter::findDistanceToX(SmrSector::getSector($player->getGameID(), max($target, $start)), SmrSector::getSector($player->getGameID(), min($target, $start)), true);
if ($path === false) {
    create_error('Unable to plot from ' . $start . ' to ' . $target . '.');
}
if ($start > $target) {
    //We always plot lowest to highest, so reverse if need be.
    $path->reversePath();
}
$container['Distance'] = serialize($path);
$path->removeStart();
if ($sector->isLinked($path->getNextOnPath()) && $path->getTotalSectors() > 0) {
    $player->setPlottedCourse($path);
}
forward($container);