Skip to content

Commit

Permalink
Merge pull request #409 from hemberger/warp-creation
Browse files Browse the repository at this point in the history
Improve warp creator in Universe Generator
  • Loading branch information
hemberger authored Mar 31, 2018
2 parents f82c2ef + 7d9559b commit 55ebc63
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 31 deletions.
15 changes: 12 additions & 3 deletions admin/Default/1.6/universe_create_save_processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,25 @@
foreach ($galaxies as &$eachGalaxy) {
//do we have a warp to this gal?
if (isset($_POST['warp' . $eachGalaxy->getGalaxyID()])) {
// Sanity check the number
$numWarps = $_POST['warp' . $eachGalaxy->getGalaxyID()];
if ($numWarps > 10) {
create_error('Specify no more than 10 warps between two galaxies!');
}
//iterate for each warp to this gal
for ($i=1;$i<=$_POST['warp' . $eachGalaxy->getGalaxyID()];$i++) {
for ($i=1; $i<=$numWarps; $i++) {
$galSector =& $galSectors[array_rand($galSectors)];
//only 1 warp per sector
while($galSector->hasWarp()) $galSector =& $galSectors[array_rand($galSectors)];
while ($galSector->hasWarp() || $galSector->offersFederalProtection()) {
$galSector =& $galSectors[array_rand($galSectors)];
}
//get other side
$otherSectors =& $eachGalaxy->getSectors();
$otherSector =& $otherSectors[array_rand($otherSectors)];
//make sure it does not go to itself
while($otherSector->hasWarp() || $otherSector->equals($galSector)) $otherSector =& $otherSectors[array_rand($otherSectors)];
while ($otherSector->hasWarp() || $otherSector->offersFederalProtection() || $otherSector->equals($galSector)) {
$otherSector =& $otherSectors[array_rand($otherSectors)];
}
$galSector->setWarp($otherSector);
}
}
Expand Down
72 changes: 44 additions & 28 deletions admin/Default/1.6/universe_create_warps.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,61 @@
<?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!!';
if (isset($var['message'])) {
$template->assign('Message', $var['message']);
SmrSession::updateVar('message', null); // Only show message once
}

$galaxies =& SmrGalaxy::getGameGalaxies($var['game_id']);
$galaxy =& SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']);
$galSectors =& $galaxy->getSectors();

$template->assign('PageTopic', 'Warps for Galaxy : '.$galaxy->getName().' ('.$galaxy->getGalaxyID().')');


// Initialize warps array
$warps = array();
foreach ($galaxies as $gal1) {
$warps[$gal1->getGalaxyID()] = array();
foreach ($galaxies as $gal2) {
$warps[$gal1->getGalaxyID()][$gal2->getGalaxyID()] = 0;
}
}

//get totals
foreach ($galSectors as &$galSector) {
if($galSector->hasWarp()) {
$otherGalaxyID = $galSector->getWarpSector()->getGalaxyID();
if($otherGalaxyID==$galaxy->getGalaxyID())
$warps[$otherGalaxyID]+=0.5;
else
$warps[$otherGalaxyID]++;
$db->query('SELECT * FROM warp WHERE game_id='.$db->escapeNumber($var['game_id']));
while ($db->nextRecord()) {
$warp1 = SmrSector::getSector($db->getInt('game_id'), $db->getInt('sector_id_1'));
$warp2 = SmrSector::getSector($db->getInt('game_id'), $db->getInt('sector_id_2'));
if ($warp1->getGalaxyID() == $warp2->getGalaxyID()) {
$warps[$warp1->getGalaxyID()][$warp2->getGalaxyID()]++;
} else {
$warps[$warp1->getGalaxyID()][$warp2->getGalaxyID()]++;
$warps[$warp2->getGalaxyID()][$warp1->getGalaxyID()]++;
}
}

//universe_create_warps.php
// Get links to other pages
$container = create_container('skeleton.php', '1.6/universe_create_warps.php');
$container['game_id'] = $var['game_id'];
$galLinks = array();
foreach ($galaxies as $gal) {
$container['gal_on'] = $gal->getGalaxyID();
$galLinks[$gal->getGalaxyID()] = SmrSession::getNewHREF($container);
}
$template->assign('GalLinks', $galLinks);

$container = $var;
$container['url'] = '1.6/universe_create_save_processing.php';
$container['body'] = '1.6/universe_create_sectors.php';
$PHP_OUTPUT.= create_echo_form($container);
$PHP_OUTPUT.= 'Working on Galaxy : ' . $galaxy->getName() . ' (' . $galaxy->getGalaxyID() . ')<br />';
$PHP_OUTPUT.= '<table class="standard">';
foreach ($galaxies as &$eachGalaxy) {
$PHP_OUTPUT.= '<tr><td class="right">' . $eachGalaxy->getName() . '</td><td>';
$PHP_OUTPUT.= '<input type="number" value="';
if (isset($warps[$eachGalaxy->getGalaxyID()])) $PHP_OUTPUT.= $warps[$eachGalaxy->getGalaxyID()];
else $PHP_OUTPUT.= '0';
$PHP_OUTPUT.= '" size="5" name="warp' . $eachGalaxy->getGalaxyID() . '"></td></tr>';
}
$PHP_OUTPUT.= '<tr><td colspan="2" class="center"><input type="submit" name="submit" value="Create Warps">';
$container['body'] = '1.6/universe_create_warps.php';
$template->assign('SubmitHREF', SmrSession::getNewHREF($container));

$container = $var;
$container['body'] = '1.6/universe_create_sectors.php';
$PHP_OUTPUT.= '<br /><br /><a href="'.SmrSession::getNewHREF($container).'" class="submitStyle">Cancel</a>';
$PHP_OUTPUT.= '</td></tr></table></form>';
$template->assign('CancelHREF', SmrSession::getNewHREF($container));

$PHP_OUTPUT.= '<span class="small">Note: When you press "Create Warps" this will rearrange all current warps.<br />';
$PHP_OUTPUT.= 'To add new warps without rearranging everything use the edit sector feature.';
$PHP_OUTPUT.= 'Keep in mind this removes both sides of the warp, so 2 gals are changed for each warp.</span>';
$template->assign('Galaxy', $galaxy);
$template->assign('Galaxies', $galaxies);
$template->assign('Warps', $warps);

?>
?>
81 changes: 81 additions & 0 deletions templates/Default/admin/Default/1.6/universe_create_warps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
if (isset($Message)) {
echo $Message; ?><br /><br /><?php
} ?>

<table>
<tr>
<td class="shrink" style="white-space:nowrap">
<form method="POST" action="<?php echo $SubmitHREF; ?>">
<table class="standard">
<tr>
<th>Galaxy</th>
<th>Number of Warps</th>
</tr><?php
foreach ($Galaxies as $eachGalaxy) { ?>
<tr>
<td class="right"><?php echo $eachGalaxy->getName(); ?></td>
<td><input class="center" type="number" value="<?php echo $Warps[$Galaxy->getGalaxyID()][$eachGalaxy->getGalaxyID()]; ?>" name="warp<?php echo $eachGalaxy->getGalaxyID(); ?>"></td>
</tr><?php
} ?>
<tr>
<td colspan="2" class="center">
<input type="submit" name="submit" value="Create Warps">
<br /><br />
<a href="<?php echo $CancelHREF; ?>" class="submitStyle">&lt;&lt;&nbsp;Back to Map</a>
</td>
</tr>
</table>
</form>
</td>

<td style="vertical-align:top">
<div style="margin-left:10px">
Warps will be placed randomly in the galaxies, with these exceptions:
<ul>
<li>Only one warp per sector</li>
<li>No warps in sectors with Federal Beacons</li>
</ul>
<span class="bold">Note:</span> When you press "Create Warps" this will rearrange all current warps.
To add new warps without rearranging everything use the edit sector feature.
Keep in mind this removes both sides of the warp, so 2 galaxies are changed for each warp.
</div>
</td>
</tr>
</table>
<br />

<style type="text/css">
p.vert {
writing-mode: tb-rl;
padding: 1px;
margin: 1px;
}
</style>

<h2>Warp Summary</h2>
<p>Click on a galaxy name to edit warps for that galaxy.</p>
<table class="standard">
<tr>
<td></td><?php
foreach ($Galaxies as $gal) { ?>
<th>
<p class="vert">
<a href="<?php echo $GalLinks[$gal->getGalaxyID()]; ?>"><?php echo $gal->getName(); ?></a>
</p>
</th><?php
} ?>
<th><p class="vert">Total</p></th>
</tr><?php
foreach ($Galaxies as $galRow) { ?>
<tr>
<th><a href="<?php echo $GalLinks[$galRow->getGalaxyID()]; ?>"><?php echo $galRow->getName(); ?></a></th><?php
foreach ($Galaxies as $galCol) {
$count = $Warps[$galRow->getGalaxyID()][$galCol->getGalaxyID()];
$display = $count == 0 ? '' : $count; ?>
<td class="center"><?php echo $display; ?></td><?php
} ?>
<th><?php echo array_sum($Warps[$galRow->getGalaxyID()]); ?></th>
</tr><?php
} ?>
</table>

0 comments on commit 55ebc63

Please sign in to comment.