Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The great reference purge #542

Merged
merged 1 commit into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion admin/Default/1.6/universe_create_locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
$template->assign('TotalLocs', $totalLocs);

$galaxy =& SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$template->assign('Galaxy', $galaxy);

// Though we expect a location to be only in one category, it is possible to
Expand Down
5 changes: 2 additions & 3 deletions admin/Default/1.6/universe_create_planets.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
}

// Get the current number of each type of planet
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galSectors =& $galaxy->getSectors();
foreach ($galSectors as &$galSector) {
$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
foreach ($galaxy->getSectors() as $galSector) {
if($galSector->hasPlanet()) {
$numberOfPlanets[$galSector->getPlanet()->getTypeID()]++;
}
Expand Down
8 changes: 3 additions & 5 deletions admin/Default/1.6/universe_create_ports.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
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();
$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
//get totals
$total = array();
$totalPorts = array();
Expand All @@ -18,7 +17,7 @@
for ($i=1;$i<=20;$i++) {
$totalMines[$i] = 0;
}
foreach ($galSectors as &$galSector) {
foreach ($galaxy->getSectors() as $galSector) {
if($galSector->hasPort()) {
$totalPorts[$galSector->getPort()->getLevel()]++;
$total['Ports']++;
Expand Down Expand Up @@ -52,8 +51,7 @@
$PHP_OUTPUT.= '</td><td class="center">';
$PHP_OUTPUT.= '<table class="standard"><tr><th colspan="2">Port Race % Distribution</th></tr>';

$races =& Globals::getRaces();
foreach ($races as &$race) {
foreach (Globals::getRaces() as $race) {
$PHP_OUTPUT.= '<tr><td class="right">' . $race['Race Name'] . '</td><td><input type="number" size="5" name="race' . $race['Race ID'] . '" value="0" onFocus="startRaceCalc();" onBlur="stopRaceCalc();"></td></tr>';
}
$PHP_OUTPUT.= '<tr><td class="right">Total</td><td><input type="number" size="5" name="racedist" value="0"></td></tr>';
Expand Down
130 changes: 53 additions & 77 deletions admin/Default/1.6/universe_create_save_processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
$var['game_id']=$newID;

//insert race relations
$races =& Globals::getRaces();
foreach ($races as &$race) {
foreach ($races as &$race2) {
foreach (Globals::getRaces() as $race) {
foreach (Globals::getRaces() as $race2) {
if ($race['Race ID'] == $race2['Race ID']) $amount = MAX_GLOBAL_RELATIONS;
elseif ($race['Race ID'] == 1 || $race2['Race ID'] == 1) $amount = 0; //0 relats with neutral
else $amount = MIN_GLOBAL_RELATIONS;
Expand All @@ -65,7 +64,7 @@
}
else if ($submit=='Create Galaxies') {
for ($i=1;$i<=$var['num_gals'];$i++) {
$galaxy =& SmrGalaxy::createGalaxy($var['game_id'],$i);
$galaxy = SmrGalaxy::createGalaxy($var['game_id'],$i);
$galaxy->setName($_POST['gal' . $i]);
$galaxy->setWidth($_POST['width' . $i]);
$galaxy->setHeight($_POST['height' . $i]);
Expand All @@ -81,7 +80,7 @@
$var['message'] = '<span class="green">Success</span> : Succesfully created galaxies.';
}
else if ($submit=='Redo Connections') {
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
if(!$galaxy->generateSectors($_REQUEST['connect']))
$var['message'] = '<span class="red">Error</span> : Regenerating connections failed.';
else
Expand All @@ -95,13 +94,13 @@
$var['gal_on'] = (int)$_REQUEST['jumpgal'];
}
elseif ($submit == 'Toggle Link') {
$sector =& SmrSector::getSector($var['game_id'],$var['sector_id']);
$sector = SmrSector::getSector($var['game_id'],$var['sector_id']);
$sector->toggleLink($var['dir']);
SmrSector::saveSectors();
}
elseif ($submit == 'Modify Sector') {
if(!empty($_POST['sector_edit'])) {
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
if($galaxy->contains($_POST['sector_edit'])) {
$var['sector_id'] = $_POST['sector_edit'];
$var['body'] = '1.6/universe_create_sector_details.php';
Expand All @@ -111,19 +110,18 @@
}
}
elseif ($submit == 'Create Locations') {
$locations =& SmrLocation::getAllLocations();
$galSectors =& SmrSector::getGalaxySectors($var['game_id'],$var['gal_on']);
foreach ($galSectors as &$sector) {
$galSectors = SmrSector::getGalaxySectors($var['game_id'],$var['gal_on']);
foreach ($galSectors as $sector) {
$sector->removeAllLocations();
}
foreach ($locations as &$location) {
foreach (SmrLocation::getAllLocations() as $location) {
if (isset($_POST['loc' . $location->getTypeID()])) {
for ($i=0;$i<$_POST['loc' . $location->getTypeID()];$i++) {
$sector =& $galSectors[array_rand($galSectors)]; //get random sector from start of gal to end of gal
$sector = $galSectors[array_rand($galSectors)]; //get random sector from start of gal to end of gal
//4 per sector max locs and no locations inside fed

while (!checkSectorAllowedForLoc($sector,$location)) {
$sector =& $galSectors[array_rand($galSectors)]; //get valid sector
$sector = $galSectors[array_rand($galSectors)]; //get valid sector
}

addLocationToSector($location,$sector);
Expand All @@ -134,17 +132,17 @@
}
elseif ($submit == 'Create Warps') {
//get all warp info from all gals, some need to be removed, some need to be added
$galaxies =& SmrGalaxy::getGameGalaxies($var['game_id']);
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galSectors =& $galaxy->getSectors();
$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galSectors = $galaxy->getSectors();
//get totals
foreach ($galSectors as &$galSector) {
foreach ($galSectors as $galSector) {
if($galSector->hasWarp()) {
$galSector->removeWarp();
}
} unset($galSector);
}
//iterate over all the galaxies
foreach ($galaxies as &$eachGalaxy) {
$galaxies = SmrGalaxy::getGameGalaxies($var['game_id']);
foreach ($galaxies as $eachGalaxy) {
//do we have a warp to this gal?
if (isset($_POST['warp' . $eachGalaxy->getGalaxyID()])) {
// Sanity check the number
Expand All @@ -154,30 +152,29 @@
}
//iterate for each warp to this gal
for ($i=1; $i<=$numWarps; $i++) {
$galSector =& $galSectors[array_rand($galSectors)];
$galSector = $galSectors[array_rand($galSectors)];
//only 1 warp per sector
while ($galSector->hasWarp() || $galSector->offersFederalProtection()) {
$galSector =& $galSectors[array_rand($galSectors)];
$galSector = $galSectors[array_rand($galSectors)];
}
//get other side
$otherSectors =& $eachGalaxy->getSectors();
$otherSector =& $otherSectors[array_rand($otherSectors)];
$otherSectors = $eachGalaxy->getSectors();
$otherSector = $otherSectors[array_rand($otherSectors)];
//make sure it does not go to itself
while ($otherSector->hasWarp() || $otherSector->offersFederalProtection() || $otherSector->equals($galSector)) {
$otherSector =& $otherSectors[array_rand($otherSectors)];
$otherSector = $otherSectors[array_rand($otherSectors)];
}
$galSector->setWarp($otherSector);
}
}
} unset($eachGalaxy);
}
SmrSector::saveSectors();
$var['message'] = '<span class="green">Success</span> : Succesfully added warps.';
}
elseif ($submit == 'Create Planets') {
$galaxies =& SmrGalaxy::getGameGalaxies($var['game_id']);
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galSectors =& $galaxy->getSectors();
foreach ($galSectors as &$galSector) {
$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galSectors = $galaxy->getSectors();
foreach ($galSectors as $galSector) {
if($galSector->hasPlanet()) {
$galSector->removePlanet();
}
Expand All @@ -193,8 +190,8 @@
foreach ($allowedTypeIDs as $planetTypeID) {
$numberOfPlanets = $_POST['type' . $planetTypeID];
for ($i=1;$i<=$numberOfPlanets;$i++) {
$galSector =& $galSectors[array_rand($galSectors)];
while ($galSector->hasPlanet()) $galSector =& $galSectors[array_rand($galSectors)]; //1 per sector
$galSector = $galSectors[array_rand($galSectors)];
while ($galSector->hasPlanet()) $galSector = $galSectors[array_rand($galSectors)]; //1 per sector
$galSector->createPlanet($planetTypeID);
}
}
Expand All @@ -205,21 +202,20 @@
for ($i=1;$i<=9;$i++) {
$totalPorts+=$_REQUEST['port' . $i];
}
$races =& Globals::getRaces();
$totalRaceDist=0;
$assignedPorts=0;
$numRacePorts = array();
foreach ($races as &$race) {
foreach (Globals::getRaces() as $race) {
$totalRaceDist+=$_REQUEST['race' . $race['Race ID']];
$numRacePorts[$race['Race ID']] = ceil($_REQUEST['race' . $race['Race ID']] / 100 * $totalPorts);
$assignedPorts+=$numRacePorts[$race['Race ID']];
if($numRacePorts[$race['Race ID']]==0)
unset($numRacePorts[$race['Race ID']]);
}
if ($totalRaceDist == 100) {
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galSectors =& $galaxy->getSectors();
foreach ($galSectors as &$galSector) {
$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galSectors = $galaxy->getSectors();
foreach ($galSectors as $galSector) {
if($galSector->hasPort()) {
$galSector->removePort();
}
Expand All @@ -235,16 +231,16 @@
//iterate once for each port of this level
for ($j=0;$j<$_REQUEST['port' . $i];$j++) {
//get a sector for this port
$galSector =& $galSectors[array_rand($galSectors)];
$galSector = $galSectors[array_rand($galSectors)];
//check if this sector is valid, if not then get a new one
while ($galSector->hasPort() || $galSector->offersFederalProtection()) $galSector =& $galSectors[array_rand($galSectors)];
while ($galSector->hasPort() || $galSector->offersFederalProtection()) $galSector = $galSectors[array_rand($galSectors)];

$raceID = array_rand($numRacePorts);
$numRacePorts[$raceID]--;
if($numRacePorts[$raceID]==0)
unset($numRacePorts[$raceID]);

$port =& $galSector->createPort();
$port = $galSector->createPort();
$port->setRaceID($raceID);
$port->upgradeToLevel($i);
$port->setCreditsToDefault();
Expand Down Expand Up @@ -273,7 +269,7 @@
}
}
elseif ($submit == 'Edit Sector') {
$sector =& SmrSector::getSector($var['game_id'],$var['sector_id']);
$sector = SmrSector::getSector($var['game_id'],$var['sector_id']);

//update connections
if (isset($_POST['up']))
Expand Down Expand Up @@ -316,10 +312,10 @@
//update port
if ($_POST['port_level'] > 0) {
if(!$sector->hasPort()) {
$port =& $sector->createPort();
$port = $sector->createPort();
}
else {
$port =& $sector->getPort();
$port = $sector->getPort();
}
if ($port->getLevel()!=$_POST['port_level']) {
$port->upgradeToLevel($_POST['port_level']);
Expand All @@ -334,18 +330,18 @@
$locationsToKeep = array();
for($x=0;$x<UNI_GEN_LOCATION_SLOTS;$x++) {
if ($_POST['loc_type'.$x] != 0) {
$locationToAdd =& SmrLocation::getLocation($_POST['loc_type'.$x]);
$locationToAdd = SmrLocation::getLocation($_POST['loc_type'.$x]);
if($sector->hasLocation($locationToAdd->getTypeID()))
$locationsToKeep[] =& $locationToAdd;
$locationsToKeep[] = $locationToAdd;
else
$locationsToAdd[] =& $locationToAdd;
$locationsToAdd[] = $locationToAdd;
}
}
$sector->removeAllLocations();
foreach($locationsToKeep as &$locationToAdd) {
foreach($locationsToKeep as $locationToAdd) {
$sector->addLocation($locationToAdd);
}
foreach($locationsToAdd as &$locationToAdd) {
foreach($locationsToAdd as $locationToAdd) {
addLocationToSector($locationToAdd,$sector);
}
if ($_POST['warp'] > 0) {
Expand All @@ -369,7 +365,7 @@
forward($container);


function checkSectorAllowedForLoc(SmrSector &$sector,SmrLocation &$location) {
function checkSectorAllowedForLoc(SmrSector $sector, SmrLocation $location) {
if (!$location->isHQ()) {
return (sizeof($sector->getLocations()) < 4 && !$sector->offersFederalProtection() );
}
Expand All @@ -380,60 +376,40 @@ function checkSectorAllowedForLoc(SmrSector &$sector,SmrLocation &$location) {
}
}

function addLocationToSector(SmrLocation &$location,SmrSector &$sector) {
$fedBeacon =& SmrLocation::getLocation(LOCATION_TYPE_FEDERAL_BEACON);
// if ($loc_id > 1 && $loc_id < 10) {
// //get max loc #s for each type
// $max = array(0,0,0,0,0,0,0,0,0,0);
// foreach ($LOCATIONS as $id => $array) {
// //skip fed beacon and "Random Bank Location" and such
// if ($id >= 100) $type = floor($id / 100);
// else continue;
// //determine a range of this type of location (ie banks are 501-504)
// if ($id > $max[$type]) $max[$type] = $id;
// }
//
// //we need to insert random banks,ship shops, etc
// $min = $loc_id * 100 + 1; //smallest ID
// $max_s = $max[$loc_id]; //largest ID
// $loc_id = mt_rand($min, $max_s); //get rand id
// while (in_array($loc_id,$SPECIAL) || in_array($loc_id, $updateLoc[$sector])) $loc_id = mt_rand($min, $max_s); //check if this is an allowed id
// }

function addLocationToSector(SmrLocation $location, SmrSector $sector) {
if($sector->hasLocation($location->getTypeID()))
return false;

$sector->addLocation($location); //insert the location
if ($location->isHQ()) {
//only playable races have extra locations to add
//Racial/Fed
$linkedLocations =& $location->getLinkedLocations();
foreach($linkedLocations as &$linkedLocation) {
foreach ($location->getLinkedLocations() as $linkedLocation) {
$sector->addLocation($linkedLocation);
if($linkedLocation->isFed())
$fedBeacon =& $linkedLocation;
} unset($linkedLocation);
$fedBeacon = $linkedLocation;
}

//add Beacons to all surrounding areas (up to 2 sectors out)
if (!$sector->offersFederalProtection())
$sector->addLocation($fedBeacon); //add beacon to this sector
$visitedSectors = array();
$links = array('Up','Right','Down','Left');
$fedSectors = array(&$sector);
$fedSectors = array($sector);
$tempFedSectors = array();
for($i=0;$i<DEFAULT_FED_RADIUS;$i++) {
foreach($fedSectors as &$fedSector) {
foreach($fedSectors as $fedSector) {
foreach($links as $link) {
if ($fedSector->hasLink($link) && !isset($visitedSectors[$fedSector->getLink($link)])) {
$linkSector =& $sector->getLinkSector($link);
$linkSector = $sector->getLinkSector($link);
if (!$linkSector->offersFederalProtection())
$linkSector->addLocation($fedBeacon); //add beacon to this sector
$tempFedSectors[] =& $linkSector;
$tempFedSectors[] = $linkSector;
$visitedSectors[$fedSector->getLink($link)] = true;
}
}
}
$fedSectors =& $tempFedSectors;
$fedSectors = $tempFedSectors;
$tempFedSectors = array();
}
}
Expand Down
6 changes: 3 additions & 3 deletions admin/Default/1.6/universe_create_sector_details.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$sector =& SmrSector::getSector($var['game_id'],$var['sector_id']);
$sector = SmrSector::getSector($var['game_id'],$var['sector_id']);
$container = $var;
$container['url'] = '1.6/universe_create_save_processing.php';
$container['body'] = '1.6/universe_create_sectors.php';
Expand Down Expand Up @@ -52,7 +52,7 @@
$PHP_OUTPUT.= '</select>';
//goods determined randomly to sway admin abuse
$PHP_OUTPUT.= '<br /><br />';
$sectorLocations =& $sector->getLocations();
$sectorLocations = $sector->getLocations();
for ($i=0;$i<UNI_GEN_LOCATION_SLOTS;$i++) {
$PHP_OUTPUT.= 'Location ' . ($i + 1) . ': <select name="loc_type' . $i . '">';
$PHP_OUTPUT.= '<option value="0">No Location</option>';
Expand All @@ -73,7 +73,7 @@
if ($sector->hasLinkDown()) $PHP_OUTPUT.= ' checked';
$PHP_OUTPUT.= '></td><td width="5%" class="center">Warp:<br /><input type="number" size="5" name="warp" value="';
if ($sector->hasWarp()) {
$warpSector=& $sector->getWarpSector();
$warpSector = $sector->getWarpSector();
$PHP_OUTPUT.= $warpSector->getSectorID();
$warpGal = $warpSector->getGalaxyName();
}
Expand Down
Loading