function CreateOnePlanetRecord($gal, $System, $pos, $id_owner, $planet_name = '', $homeplanet = false)
{
    global $lang;
    // We must check if planet exists.
    $PlanetExist = mysql_fetch_array(doquery("SELECT\t`id` FROM {{table}} WHERE `galaxy` = '" . $gal . "' AND `system` = '" . $System . "' AND `planet` = '" . $pos . "';", 'planets'));
    // Well, does planet exist.
    if (!$PlanetExist) {
        $planet = PlanetSizeRandomiser($pos, $homeplanet);
        $planet['metal'] = BUILD_METAL;
        $planet['crystal'] = BUILD_CRISTAL;
        $planet['deuterium'] = BUILD_DEUTERIUM;
        $planet['metal_perhour'] = $game_config['metal_basic_income'];
        $planet['crystal_perhour'] = $game_config['crystal_basic_income'];
        $planet['deuterium_perhour'] = $game_config['deuterium_basic_income'];
        $planet['metal_max'] = BASE_STORAGE_SIZE;
        $planet['crystal_max'] = BASE_STORAGE_SIZE;
        $planet['deuterium_max'] = BASE_STORAGE_SIZE;
        $planet['galaxy'] = $gal;
        $planet['system'] = $System;
        $planet['planet'] = $pos;
        $planet['id_owner'] = $id_owner;
        if ($pos == 1 || $pos == 2 || $pos == 3) {
            $planet['img'] = 'trocken';
            $planet['no.'] = rand_in_array(array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10'));
            $planet['temp_min'] = mt_rand(0, 100);
            $planet['temp_max'] = $planet['temp_min'] + 40;
        } elseif ($pos == 4 || $pos == 5 || $pos == 6) {
            $planet['img'] = 'dschjungel';
            $planet['no.'] = rand_in_array(array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10'));
            $planet['temp_min'] = mt_rand(-25, 75);
            $planet['temp_max'] = $planet['temp_min'] + 40;
        } elseif ($pos == 7 || $pos == 8 || $pos == 9) {
            $planet['img'] = 'normaltemp';
            $planet['no.'] = rand_in_array(array('01', '02', '03', '04', '05', '06', '07'));
            $planet['temp_min'] = mt_rand(-50, 50);
            $planet['temp_max'] = $planet['temp_min'] + 40;
        } elseif ($pos == 10 || $pos == 11 || $pos == 12) {
            $planet['img'] = 'wasser';
            $planet['no.'] = rand_in_array(array('01', '02', '03', '04', '05', '06', '07', '08', '09'));
            $planet['temp_min'] = mt_rand(-75, 25);
            $planet['temp_max'] = $planet['temp_min'] + 40;
        } elseif ($pos == 13 || $pos == 14 || $pos == 15) {
            $planet['img'] = 'eis';
            $planet['no.'] = rand_in_array(array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10'));
            $planet['temp_min'] = mt_rand(-100, 10);
            $planet['temp_max'] = $planet['temp_min'] + 40;
        } else {
            $planet['img'] = rand_in_array(array('dschjungel', 'gas', 'normaltemp', 'trocken', 'wasser', 'wuesten', 'eis'));
            $planet['no.'] = rand_in_array(array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '00'));
            $planet['temp_min'] = mt_rand(-120, 10);
            $planet['temp_max'] = $planet['temp_min'] + 40;
        }
        $planet['image'] = $planet['img'] . "planet" . $planet['no.'];
        if (strlen($planet_name) > 0) {
            $planet['name'] = $planet_name;
        } else {
            $planet['name'] = $lang['sys_colo_defaultname'];
        }
        doquery("INSERT INTO {{table}} (`name`,`id_owner`,`galaxy`,`system`,`planet`,`last_update`,`planet_type`,`image`,`diameter`,`field_max`,`temp_min`,`temp_max`,`metal`,`metal_perhour`,`metal_max`,`crystal`,`crystal_perhour`,`crystal_max`,`deuterium`,`deuterium_perhour`,`deuterium_max`)\r\n\t\tVALUES ('" . $planet['name'] . "','" . $planet['id_owner'] . "','" . $planet['galaxy'] . "','" . $planet['system'] . "','" . $planet['planet'] . "','" . time() . "','1','" . $planet['image'] . "','" . $planet['diameter'] . "','" . $planet['field_max'] . "','" . $planet['temp_min'] . "','" . $planet['temp_max'] . "','" . $planet['metal'] . "','" . $planet['metal_perhour'] . "','" . $planet['metal_max'] . "','" . $planet['crystal'] . "','" . $planet['crystal_perhour'] . "','" . $planet['crystal_max'] . "','" . $planet['deuterium'] . "','" . $planet['deuterium_perhour'] . "','" . $planet['deuterium_max'] . "') ;", 'planets');
        return true;
    } else {
        return false;
    }
}
/**
 * MissionCaseExpedition.php
 *
 * @version 1.0
 * @copyright 2008 By Chlorel for XNova
 */
function MissionCaseExpedition($FleetRow)
{
    global $lang, $resource, $pricelist;
    /*
    Outcomes:
    
    Find nothing.
    Find an Alien Virus, though nothing comes of this.
    Find some small "Pets", though nothing comes of this.
    Find Dark Matter.
    Have problems with the fleet, be fixed and come back.
    Find resources, but only as much as your fleet has cargo space for.
    Find a merchant from an alien world to trade with.
    Gain ships.
    Find an alien/pirate fleet and be attacked. A combat report is made.
    Find Solar Wind or a wormhole. Your fleet returns sooner.
    An unexpected back coupling in the energy spools of the engines hastened the expeditions return. The fleet returns home earlier than expected.
    Get lost. It will take your fleet longer to return.
    Get lost, your whole fleet will never return.
    */
    //Relative potential outcomes, these do not have to total anything, simple increase the value, if a value = 0, it wont ever happen, if nothing is twice as bit as virus its twice as likely to happen.
    $outcomes = array('nothing' => 3, 'find_dm' => 1, 'problems' => 1, 'resources' => 0, 'merchant' => 0, 'ships' => 0, 'aliens' => 0, 'wormhole' => 1, 'get_lost' => 1);
    $outcomes_total = array_sum($outcomes);
    $result = false;
    foreach ($outcomes as $event => $likelyhood) {
        $chance = $likelyhood / $outcomes_total * 100;
        if ($chance > mt_rand(0, 100)) {
            $result = $event;
            break;
        } else {
            $outcomes_total -= $likelyhood;
        }
    }
    //Theoretically if it got to the last event there should have been a 1 in 1 chance of getting it, but there is always a chance of rounding errors so to play it safe, if there was no event selected choose the default, nothing:
    if (!$result) {
        $result = 'nothing';
    }
    //OK, now we have to deal with whatever we gave him.
    switch ($result) {
        case 'find_dm':
            //Find Dark Matter.
            $amount = floor(pow(mt_rand(1000, 1000 * pow(MAX_DARKMATTER, 0.25)) / 1000, 4));
            $message = sprintf(rand_in_array($lang['fleet_15_dark']), $lang['Matter'], pretty_number($amount), $lang['Matter']);
            PM($FleetRow['owner_userid'], 0, $message, $lang['fleet_15_tit'], $lang['fleet_control'], 2);
            doquery("UPDATE {{table}} SET `matter` = `matter` + '" . $amount . "' WHERE `id` = '" . $FleetRow['owner_userid'] . "' LIMIT 1 ;", 'users', false);
            break;
        case 'problems':
            //Have problems with the fleet, be fixed and come back (delayed)
            //Add time to the fleet return time, and send a message.
            $delay = mt_rand(MIN_DELAY, MAX_DELAY);
            PM($FleetRow['owner_userid'], 0, rand_in_array($lang['fleet_15_problems']), $lang['fleet_15_tit'], $lang['fleet_control'], 2);
            doquery("UPDATE {{table}} SET `arrival` = `arrival` + '" . $delay . "' WHERE `partner_fleet` = '" . $FleetRow['fleet_id'] . "' LIMIT 1 ;", 'fleets', false);
            break;
        case 'resources':
            //Find resources, but only as much as your fleet has cargo space for.
            break;
        case 'merchant':
            //Find a merchant from an alien world to trade with.
            break;
        case 'ships':
            //Gain ships.
            break;
        case 'aliens':
            //Find an alien/pirate fleet and be attacked. A combat report is made.
            break;
        case 'wormhole':
            //Find Solar Wind or a wormhole. Your fleet returns sooner.
            //An unexpected back coupling in the energy spools of the engines hastened the expeditions return. The fleet returns home earlier than expected.
            //Add time to the fleet return time, and send a message.
            $gained = mt_rand(MIN_DELAY, MAX_DELAY);
            if ($FleetRow['arrival'] - $gained < time() + 2) {
                $gained = $FleetRow['arrival'] - time() - 2;
            }
            PM($FleetRow['owner_userid'], 0, rand_in_array($lang['fleet_15_wormhole']), $lang['fleet_15_tit'], $lang['fleet_control'], 2);
            doquery("UPDATE {{table}} SET `arrival` = `arrival` - '" . $gained . "' WHERE `partner_fleet` = '" . $FleetRow['fleet_id'] . "' LIMIT 1 ;", 'fleets', false);
            break;
        case 'get_lost':
            //Get lost, your whole fleet will never return.
            //This one is fairly simple, we just delete the return fleet and send a message
            DeletePartnerFleet($FleetRow['fleet_id']);
            PM($FleetRow['owner_userid'], 0, rand_in_array($lang['fleet_15_lost']), $lang['fleet_15_tit'], $lang['fleet_control'], 2);
            break;
        default:
            //Find nothing.
            //Find an Alien Virus, though nothing comes of this.
            //Find some small "Pets", though nothing comes of this.
            //Just send back a message, anyone one of the found nothing messages will do.
            PM($FleetRow['owner_userid'], 0, rand_in_array($lang['fleet_15_nothing']), $lang['fleet_15_tit'], $lang['fleet_control'], 2);
            break;
    }
}