Ejemplo n.º 1
0
function testDistances($gameID)
{
    //Initialise cache for fairness
    $galaxies =& SmrGalaxy::getGameGalaxies($gameID);
    $galaxySectors = array();
    foreach ($galaxies as &$galaxy) {
        $galaxiesSectors[] =& $galaxy->getSectors();
    }
    unset($galaxy);
    foreach ($galaxiesSectors as &$galaxySectors) {
        foreach ($galaxySectors as &$galaxySector) {
            if ($galaxySector->hasPort()) {
                $galaxySector->getPort()->getGoods();
            }
        }
        unset($galaxySector);
    }
    unset($galaxySectors);
    //Test plotters
    $newTime = 0;
    $oldTime = 0;
    foreach ($galaxiesSectors as &$galaxySectors) {
        foreach ($galaxySectors as &$galaxySector) {
            if ($galaxySector->hasPort()) {
                $goods =& $galaxySector->getPort()->getGoods();
                foreach ($goods as &$good) {
                    $time = microtime(true);
                    $newDI = getGoodDistanceNew($galaxySector, $good['ID'], $good['TransactionType']);
                    $newTime += microtime(true) - $time;
                    $time = microtime(true);
                    $oldDI = getGoodDistanceOld($galaxySector, $good['ID'], $good['TransactionType']);
                    $oldTime += microtime(true) - $time;
                    if ($newDI != $oldDI) {
                        echo 'Difference, new: ' . $newDI . ', old:' . $oldDI . ', sector:' . $galaxySector->getSectorID() . ', good:' . $good['ID'] . EOL;
                    }
                }
                unset($good);
            }
        }
        unset($galaxySector);
    }
    unset($galaxySectors);
    echo 'New time: ' . $newTime . ', old time:' . $oldTime . EOL;
}
Ejemplo n.º 2
0
function testCourseDistances($gameID)
{
    //Initialise cache for fairness
    $galaxies =& SmrGalaxy::getGameGalaxies($gameID);
    $galaxySectors = array();
    foreach ($galaxies as &$galaxy) {
        $galaxiesSectors[] =& $galaxy->getSectors();
    }
    unset($galaxy);
    //Test plotters
    $newTime = 0;
    $oldTime = 0;
    foreach ($galaxiesSectors as &$galaxySectors) {
        foreach ($galaxySectors as &$galaxySector) {
            foreach ($galaxiesSectors as &$targetGalaxySectors) {
                foreach ($targetGalaxySectors as &$targetGalaxySector) {
                    if (!$galaxySector->equals($targetGalaxySector)) {
                        $time = microtime(true);
                        $newDI = getPlotDistanceNew($galaxySector, $targetGalaxySector);
                        $newTime += microtime(true) - $time;
                        $time = microtime(true);
                        $oldDI = getPlotDistanceOld($galaxySector, $targetGalaxySector);
                        $oldTime += microtime(true) - $time;
                        if ($newDI != $oldDI) {
                            echo 'Difference, new: ' . $newDI . ', old:' . $oldDI . ', sector1:' . $galaxySector->getSectorID() . ', sector2:' . $targetGalaxySector->getSectorID() . EOL;
                        }
                    }
                }
                unset($targetGalaxySector);
                echo 'New time: ' . $newTime . ', old time:' . $oldTime . EOL;
            }
            unset($targetGalaxySectors);
        }
        unset($galaxySector);
    }
    unset($galaxySectors);
    echo 'New time: ' . $newTime . ', old time:' . $oldTime . EOL;
}
Ejemplo n.º 3
0
header('Content-transfer-encoding: base64');
//game heading and info
echo '[GAME]' . EOL;
echo $game_id . '=' . Globals::getGameName($game_id) . EOL;
//get races
echo '[RACES]' . EOL;
$db->query('SELECT * FROM race ORDER BY race_id');
while ($db->nextRecord()) {
    $id = $db->getField('race_id');
    $name = $db->getField('race_name');
    echo 'R' . $id . '=' . $name . EOL;
}
//galaxies
echo '[GALAXIES]' . EOL;
$i = 1;
$gameGals =& SmrGalaxy::getGameGalaxies($game_id);
foreach ($gameGals as &$gameGal) {
    echo 'GAL' . $i . '=' . $gameGal->getName() . ',' . $gameGal->getWidth() . ',' . $gameGal->getHeight() . EOL;
    $i++;
}
unset($gameGal);
//icons
echo '[ICONS]' . EOL;
echo 'IWood=Wood' . EOL;
echo 'IFood=Food' . EOL;
echo 'IOre =Ore' . EOL;
echo 'IMetl=Metals' . EOL;
echo 'ISlav=Slaves' . EOL;
echo 'IText=Textiles' . EOL;
echo 'IMach=Machinery' . EOL;
echo 'ICirc=Circuits' . EOL;
Ejemplo n.º 4
0
        //new row
        if ($i != 0) {
            $leftMostSec =& $leftMostSec->getNeighbourSector('Down');
        }
        //get left most sector for this row
        $thisSec =& $leftMostSec;
        //iterate through the columns
        for ($j = 0; $j < $galaxy->getWidth(); $j++) {
            //new sector
            if ($j != 0) {
                $thisSec =& $thisSec->getNeighbourSector('Right');
            }
            $mapSectors[$i][$j] =& $thisSec;
        }
    }
    if ($account->getCssLink() != null) {
        $template->assign('ExtraCSSLink', $account->getCssLink());
    }
    $template->assign('CSSLink', URL . '/css/' . $account->getTemplate() . '.css');
    $template->assign('CSSColourLink', URL . '/css/' . $account->getTemplate() . '/' . $account->getColourScheme() . '.css');
    $template->assignByRef('ThisGalaxy', $galaxy);
    $template->assignByRef('ThisAccount', $account);
    $template->assignByRef('GameGalaxies', SmrGalaxy::getGameGalaxies($player->getGameID()));
    $template->assignByRef('ThisSector', $player->getSector());
    $template->assignByRef('MapSectors', $mapSectors);
    $template->assignByRef('ThisShip', $player->getShip());
    $template->assignByRef('ThisPlayer', $player);
    $template->display('GalaxyMap.inc');
} catch (Exception $e) {
    handleException($e);
}
Ejemplo n.º 5
0
<?php

require_once get_file_loc('SmrGalaxy.class.inc');
if (isset($var['gal_on'])) {
    $gal_on = $var['gal_on'];
} else {
    $PHP_OUTPUT .= 'Gal_on not found!!';
}
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'], $var['gal_on']);
$galSectors =& $galaxy->getSectors();
//get totals
$total = array();
$totalPorts = array();
$totalMines = array();
$total['Ports'] = 0;
$total['Mines'] = 0;
for ($i = 1; $i <= 9; $i++) {
    $totalPorts[$i] = 0;
}
for ($i = 1; $i <= 20; $i++) {
    $totalMines[$i] = 0;
}
foreach ($galSectors as &$galSector) {
    if ($galSector->hasPort()) {
        $totalPorts[$galSector->getPort()->getLevel()]++;
        $total['Ports']++;
    }
    if ($galSector->hasMine()) {
        $totalMines[$galSector->getMine()->getLevel()]++;
        $total['Mines']++;
    }
Ejemplo n.º 6
0
    $player->setTurns($player->getTurns() * ($speed / $ship->getSpeed()));
    doUNO($player, $ship);
} elseif ($var['func'] == 'Weapon') {
    $weapon_id = $_REQUEST['weapon_id'];
    $amount = $_REQUEST['amount'];
    for ($i = 1; $i <= $amount; $i++) {
        $ship->addWeapon($weapon_id);
    }
} elseif ($var['func'] == 'Uno') {
    doUNO($player, $ship);
} elseif ($var['func'] == 'Warp') {
    $sector_to = trim($_REQUEST['sector_to']);
    if (!is_numeric($sector_to)) {
        create_error('Sector ID has to be a number.');
    }
    if (!SmrGalaxy::getGalaxyContaining($player->getGameID(), $sector_to)) {
        create_error('Sector ID is not in any galaxy.');
    }
    $player->setSectorID($sector_to);
    $player->setLandedOnPlanet(false);
} elseif ($var['func'] == 'Turns') {
    $player->setTurns((int) $_REQUEST['turns']);
} elseif ($var['func'] == 'Exp') {
    $exp = min(500000, (int) $_REQUEST['exp']);
    $player->setExperience($exp);
} elseif ($var['func'] == 'Align') {
    $align = max(-500, min(500, (int) $_REQUEST['align']));
    $player->setAlignment($align);
} elseif ($var['func'] == 'Kills') {
    $kills = (int) $_REQUEST['kills'];
    $db->query('UPDATE account_has_stats SET kills = ' . $db->escapeNumber($kills) . ' WHERE account_id = ' . $db->escapeNumber($player->getAccountID()));
Ejemplo n.º 7
0
        $locSells .= 'UG=,';
    }
    if ($location->isFed()) {
        $locSells .= 'Fed=,';
    }
    if ($locSells != '') {
        $file .= substr($locSells, 0, -1);
    }
    $file .= EOL;
}
unset($location);
$file .= '[Game]
Name=' . inify(Globals::getGameName($gameID)) . '
[Galaxies]
';
$galaxies =& SmrGalaxy::getGameGalaxies($gameID);
foreach ($galaxies as &$galaxy) {
    $file .= $galaxy->getGalaxyID() . '=' . $galaxy->getWidth() . ',' . $galaxy->getHeight() . ',' . $galaxy->getGalaxyType() . ',' . inify($galaxy->getName()) . EOL;
}
unset($galaxy);
foreach ($galaxies as &$galaxy) {
    $sectors =& $galaxy->getSectors();
    foreach ($sectors as &$sector) {
        $file .= '[Sector=' . $sector->getSectorID() . ']' . EOL;
        if (!$sector->isVisited($player) && $adminCreate === false) {
            continue;
        }
        foreach ($sector->getLinks() as $linkName => $link) {
            $file .= $linkName . '=' . $link . EOL;
        }
        if ($sector->hasWarp()) {
Ejemplo n.º 8
0
    //start section
    require_once get_file_loc('SmrPort.class.inc');
    // add port infos
    $db->query('SELECT sector_id FROM port WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND sector_id <= ' . $db->escapeNumber($high) . ' AND sector_id >= ' . $db->escapeNumber($low) . ' ORDER BY sector_id');
    while ($db->nextRecord()) {
        SmrPort::getPort($player->getGameID(), $db->getField('sector_id'))->addCachePort($player->getAccountID());
    }
    $container = create_container('skeleton.php', 'bar_main.php');
    $container['script'] = 'bar_opening.php';
    $container['message'] = '<div align="center">Galaxy Info has been added.  Enjoy!</div><br />';
    forward($container);
} else {
    //find what gal they want
    $container = array();
    $container['url'] = 'skeleton.php';
    $container['body'] = 'bar_main.php';
    $container['script'] = 'bar_galmap_buy.php';
    $container['process'] = true;
    $PHP_OUTPUT .= '<div align="center">What galaxy do you want info on?<br />';
    $PHP_OUTPUT .= create_echo_form($container);
    $PHP_OUTPUT .= '<select type="select" name="gal_id">';
    $PHP_OUTPUT .= '<option value="0">[Select a galaxy]</option>';
    $gameGalaxies =& SmrGalaxy::getGameGalaxies($player->getGameID());
    foreach ($gameGalaxies as &$galaxy) {
        $PHP_OUTPUT .= '<option value="' . $galaxy->getGalaxyID() . '">' . $galaxy->getName() . '</option>';
    }
    unset($galaxy);
    $PHP_OUTPUT .= '</select><br />';
    $PHP_OUTPUT .= create_submit('Buy the map');
    $PHP_OUTPUT .= '</form></div>';
}
Ejemplo n.º 9
0
if (!is_numeric($target)) {
    create_error('Please enter only numbers!');
}
if ($player->getSectorID() == $target) {
    create_error('Hmmmm...if ' . $player->getSectorID() . '=' . $target . ' then that means...YOU\'RE ALREADY THERE! *cough*you\'re real smart*cough*');
}
if ($sector->hasForces()) {
    $sectorForces =& $sector->getForces();
    foreach ($sectorForces as &$forces) {
        if ($forces->hasMines() && !$player->forceNAPAlliance($forces->getOwner())) {
            create_error('You cant jump when there are unfriendly forces in the sector!');
        }
    }
    unset($forces);
}
if (!SmrGalaxy::getGalaxyContaining($player->getGameID(), $target)) {
    create_error('The target sector doesn\'t exist!');
}
// create sector object for target sector
$targetSector =& SmrSector::getSector($player->getGameID(), $target);
require_once get_file_loc('Plotter.class.inc');
$path =& Plotter::findDistanceToX($targetSector, $player->getSector(), true);
if ($path === false) {
    create_error('Unable to plot from ' . $start . ' to ' . $target . '.');
}
// 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));
Ejemplo n.º 10
0
<?php

require_once get_file_loc('SmrGalaxy.class.inc');
if (!isset($var['game_id'])) {
    SmrSession::updateVar('game_id', $_REQUEST['game_id']);
}
if (!isset($var['gal_on'])) {
    SmrSession::updateVar('gal_on', 1);
}
//generate sector array
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'], $var['gal_on']);
$galaxies =& SmrGalaxy::getGameGalaxies($var['game_id']);
$topLeft =& SmrSector::getSector($var['game_id'], $galaxy->getStartSector());
$mapSectors = array();
$leftMostSec =& $topLeft;
for ($i = 0; $i < $galaxy->getHeight(); $i++) {
    $mapSectors[$i] = array();
    //new row
    if ($i != 0) {
        $leftMostSec =& $leftMostSec->getNeighbourSector('Down');
    }
    //get left most sector for this row
    $thisSec =& $leftMostSec;
    //iterate through the columns
    for ($j = 0; $j < $galaxy->getWidth(); $j++) {
        //new sector
        if ($j != 0) {
            $thisSec =& $thisSec->getNeighbourSector('Right');
        }
        $mapSectors[$i][$j] =& $thisSec;
    }
Ejemplo n.º 11
0
function &findRoutes(&$player)
{
    debug('Finding Routes');
    $galaxies =& SmrGalaxy::getGameGalaxies($player->getGameID());
    $tradeGoods = array(GOOD_NOTHING => false);
    $goods =& Globals::getGoods();
    foreach ($goods as $goodID => &$good) {
        if ($player->meetsAlignmentRestriction($good['AlignRestriction'])) {
            $tradeGoods[$goodID] = true;
        } else {
            $tradeGoods[$goodID] = false;
        }
    }
    unset($good);
    $tradeRaces = array();
    $races =& Globals::getRaces();
    foreach ($races as $raceID => &$race) {
        $tradeRaces[$raceID] = false;
    }
    unset($race);
    $tradeRaces[$player->getRaceID()] = true;
    $galaxy =& $player->getSector()->getGalaxy();
    $maxNumberOfPorts = 2;
    $routesForPort = -1;
    $numberOfRoutes = 1000;
    $maxDistance = 15;
    $startSectorID = $galaxy->getStartSector();
    $endSectorID = $galaxy->getEndSector();
    $db = new SmrMySqlDatabase();
    $db->query('SELECT routes FROM route_cache WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' AND max_ports=' . $db->escapeNumber($maxNumberOfPorts) . ' AND goods_allowed=' . $db->escapeObject($tradeGoods) . ' AND races_allowed=' . $db->escapeObject($tradeRaces) . ' AND start_sector_id=' . $db->escapeNumber($startSectorID) . ' AND end_sector_id=' . $db->escapeNumber($endSectorID) . ' AND routes_for_port=' . $db->escapeNumber($routesForPort) . ' AND max_distance=' . $db->escapeNumber($maxDistance));
    if ($db->nextRecord()) {
        $routes = unserialize(gzuncompress($db->getField('routes')));
        debug('Using Cached Routes: #' . count($routes));
        return $routes;
    } else {
        debug('Generating Routes');
        $allSectors = array();
        foreach ($galaxies as &$galaxy) {
            $allSectors += $galaxy->getSectors();
            //Merge arrays
        }
        unset($galaxy);
        $distances =& Plotter::calculatePortToPortDistances($allSectors, $maxDistance, $startSectorID, $endSectorID);
        if ($maxNumberOfPorts == 1) {
            $allRoutes = RouteGenerator::generateOneWayRoutes($allSectors, $distances, $tradeGoods, $tradeRaces, $routesForPort);
        } else {
            $allRoutes = RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $allSectors, $tradeGoods, $tradeRaces, $distances, $routesForPort, $numberOfRoutes);
        }
        unset($distances);
        $allRoutes =& $allRoutes[RouteGenerator::EXP_ROUTE];
        $routesMerged = array();
        foreach ($allRoutes as $multi => &$routesByMulti) {
            $routesMerged += $routesByMulti;
            //Merge arrays
        }
        unset($routesByMulti);
        unset($allSectors);
        SmrPort::clearCache();
        SmrSector::clearCache();
        $db->query('INSERT INTO route_cache ' . '(game_id, max_ports, goods_allowed, races_allowed, start_sector_id, end_sector_id, routes_for_port, max_distance, routes)' . ' VALUES (' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($maxNumberOfPorts) . ', ' . $db->escapeObject($tradeGoods) . ', ' . $db->escapeObject($tradeRaces) . ', ' . $db->escapeNumber($startSectorID) . ', ' . $db->escapeNumber($endSectorID) . ', ' . $db->escapeNumber($routesForPort) . ', ' . $db->escapeNumber($maxDistance) . ', ' . $db->escapeObject($routesMerged, true) . ')');
        debug('Found Routes: #' . count($routesMerged));
        return $routesMerged;
    }
}