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 ($amount > 1) {
    $container['msg'] = 'You have jettisoned <span class="yellow">' . $amount . '</span> units of ' . $good_name . ' and have lost <span class="exp">' . $lost_xp . '</span> experience.';
} else {
    $container['msg'] = 'You have jettisoned <span class="yellow">' . $amount . '</span> unit of ' . $good_name . ' and have lost <span class="exp">' . $lost_xp . '</span> experience.';
}
    SmrSession::updateVar('offered_price', $port->getOfferPrice($ideal_price, $relations, $portGood['TransactionType']));
}
$offered_price = $var['offered_price'];
// nothing should happen here but just to avoid / by 0
if ($ideal_price == 0 || $offered_price == 0) {
    create_error('Port calculation error...buy more goods.');
}
// can we accept the current price?
if (!empty($bargain_price) && ($portGood['TransactionType'] == 'Buy' && $bargain_price >= $ideal_price || $portGood['TransactionType'] == 'Sell' && $bargain_price <= $ideal_price)) {
    // the url we going to
    $container = create_container('skeleton.php');
    transfer('ideal_price');
    transfer('offered_price');
    // base xp is the amount you would get for a perfect trade.
    // this is the absolut max. the real xp can only be smaller.
    $base_xp = SmrPort::getBaseExperience($amount, $port->getGoodDistance($good_id));
    // if offered equals ideal we get a problem (division by zero)
    $gained_exp = round($port->calculateExperiencePercent($ideal_price, $offered_price, $bargain_price, $portGood['TransactionType']) * $base_xp);
    //will use these variables in current sector and port after successful trade
    $container['traded_xp'] = $gained_exp;
    $container['traded_amount'] = $amount;
    $container['traded_good'] = $good_name;
    $container['traded_credits'] = $bargain_price;
    if ($portGood['TransactionType'] == 'Buy') {
        $container['traded_transaction'] = 'bought';
        $ship->increaseCargo($good_id, $amount);
        $player->decreaseCredits($bargain_price);
        $player->increaseHOF($amount, array('Trade', 'Goods', 'Bought'), HOF_PUBLIC);
        $player->increaseHOF($gained_exp, array('Trade', 'Experience', 'Buying'), HOF_PUBLIC);
        $player->decreaseHOF($bargain_price, array('Trade', 'Money', 'Profit'), HOF_PUBLIC);
        $player->increaseHOF($bargain_price, array('Trade', 'Money', 'Buying'), HOF_PUBLIC);