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

GH-208 | Refactor galaxy rendering | Assorted refactors (#01) #210

Merged
merged 8 commits into from
May 6, 2022
12 changes: 10 additions & 2 deletions ajax/sendmissiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
include($_EnginePath . 'common.php');
include($_EnginePath . 'modules/flightControl/_includes.php');

use UniEngine\Engine\Includes\Helpers\World\Checks;
use UniEngine\Engine\Modules\FlightControl;

function CreateReturn($ReturnCode, $Update = '0')
Expand Down Expand Up @@ -62,6 +63,11 @@ function CreateReturn($ReturnCode, $Update = '0')
include($_EnginePath.'includes/functions/GetMissileRange.php');
$MissilesRange = GetMissileRange();
$FlightTime = round(((30 + (60 * $Dist)) * 2500) / $_GameConfig['game_speed']);
$isInRange = Checks\isTargetInRange([
'originPosition' => $_Planet['system'],
'targetPosition' => $System,
'range' => $MissilesRange,
]);

if($Missiles <= 0)
{
Expand All @@ -79,8 +85,10 @@ function CreateReturn($ReturnCode, $Update = '0')
{
CreateReturn('648');
}
if($Dist > $MissilesRange OR $Galaxy != $_Planet['galaxy'])
{
if (
!$isInRange ||
$Galaxy != $_Planet['galaxy']
) {
CreateReturn('647');
}
if($Missiles > $_Planet['interplanetary_missile'])
Expand Down
101 changes: 46 additions & 55 deletions includes/functions/GalaxyRowActions.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

function GalaxyRowActions($GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, $MyBuddies)
{
use UniEngine\Engine\Includes\Helpers\World\Checks;

function GalaxyRowActions($GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, $MyBuddies) {
global $_User, $_SkinPath, $CurrentMIP, $CurrentSystem, $CurrentGalaxy;
static $TPL = false;
if($TPL === false)
{

if ($TPL === false) {
$TPL = gettemplate('galaxy_row_action');
}

Expand All @@ -19,70 +20,60 @@ function GalaxyRowActions($GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System,

$HiddenOptions = $OptionsCount = 4;

$Parse = array
(
'Hide_Spy' => ' hide',
'Hide_Msg' => ' hide',
'Hide_Buddy' => ' hide',
'Hide_Rocket' => ' hide',
'Galaxy' => $Galaxy,
'System' => $System,
'Planet' => $Planet,
'SkinPath' => $_SkinPath,
'UserID' => $GalaxyRowPlayer['id'],
'Current' => $_User['current_planet'],
);
$Parse = [
'Hide_Spy' => ' hide',
'Hide_Msg' => ' hide',
'Hide_Buddy' => ' hide',
'Hide_Rocket' => ' hide',
'Galaxy' => $Galaxy,
'System' => $System,
'Planet' => $Planet,
'SkinPath' => $_SkinPath,
'UserID' => $GalaxyRowPlayer['id'],
'Current' => $_User['current_planet'],
];

if (
$_User['settings_mis'] == 1 &&
$CurrentMIP > 0 &&
$GalaxyRowPlanet['galaxy'] == $CurrentGalaxy
) {
$isInRange = Checks\isTargetInRange([
'originPosition' => $CurrentSystem,
'targetPosition' => $System,
'range' => GetMissileRange(),
]);

if($_User['settings_mis'] == 1)
{
if($CurrentMIP > 0)
{
if($GalaxyRowPlanet['galaxy'] == $CurrentGalaxy)
{
$MiRange = GetMissileRange();
$SystemLimitMin = $CurrentSystem - $MiRange;
if($SystemLimitMin < 1)
{
$SystemLimitMin = 1;
}
$SystemLimitMax = $CurrentSystem + $MiRange;
if($System <= $SystemLimitMax AND $System >= $SystemLimitMin)
{
--$HiddenOptions;
$Parse['Hide_Rocket'] = '';
}
}
if ($isInRange) {
--$HiddenOptions;
$Parse['Hide_Rocket'] = '';
}
}
if($_User['settings_esp'] == 1)
{
if ($_User['settings_esp'] == 1) {
--$HiddenOptions;
$Parse['Hide_Spy'] = '';
}
if($_User['settings_wri'] == 1 AND $GalaxyRowPlanet['id_owner'] > 0)
{
if (
$_User['settings_wri'] == 1 &&
$GalaxyRowPlanet['id_owner'] > 0
) {
--$HiddenOptions;
$Parse['Hide_Msg'] = '';
}
if($_User['settings_bud'] == 1 AND $GalaxyRowPlanet['id_owner'] > 0)
{
if(!in_array($GalaxyRowPlayer['id'], $MyBuddies))
{
--$HiddenOptions;
$Parse['Hide_Buddy'] = '';
}
if (
$_User['settings_bud'] == 1 &&
$GalaxyRowPlanet['id_owner'] > 0 &&
!in_array($GalaxyRowPlayer['id'], $MyBuddies)
) {
--$HiddenOptions;
$Parse['Hide_Buddy'] = '';
}

if($OptionsCount == $HiddenOptions)
{
$Result = renderEmptyGalaxyCell();
}
else
{
$Result = parsetemplate($TPL, $Parse);
if ($OptionsCount == $HiddenOptions) {
return renderEmptyGalaxyCell();
}

return $Result;
return parsetemplate($TPL, $Parse);
}

?>
3 changes: 2 additions & 1 deletion includes/functions/GalaxyRowDebris.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

function GalaxyRowDebris($GalaxyRow, $Galaxy, $System, $Planet, $PlanetType)
function GalaxyRowDebris($GalaxyRow, $Galaxy, $System, $Planet)
{
global $_Lang, $_SkinPath;

Expand All @@ -20,6 +20,7 @@ function GalaxyRowDebris($GalaxyRow, $Galaxy, $System, $Planet, $PlanetType)
return renderEmptyGalaxyCell();
}

$PlanetType = 2;
$BackgroundColor = null;
if($TotalDebris >= 10000000)
{
Expand Down
101 changes: 56 additions & 45 deletions includes/functions/GalaxyRowMoon.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

function GalaxyRowMoon($GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy, $System, $Planet, $PlanetType, $MyBuddies, $MyAllyPacts)
{
function GalaxyRowMoon($GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy, $System, $Planet, $MyBuddies, $MyAllyPacts) {
global $_Lang, $_User, $_SkinPath, $CanDestroy, $MoonCount;
static $TPL = false;
if($TPL === false)
Expand All @@ -13,63 +12,75 @@ function GalaxyRowMoon($GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy, $S
return renderEmptyGalaxyCell();
}

$Links = [];
$PlanetType = 3;
$menuActions = [];

$MoonCount += 1;

if($GalaxyRowUser['id'] != $_User['id'])
{
$Links[] = array('prio' => 1, 'txt' => "<a href=# onclick=&#039return sendShips(1, {$Galaxy}, {$System}, {$Planet}, {$PlanetType})&#039 >{$_Lang['type_mission'][6]}</a>");
$Links[] = array('prio' => 2, 'txt' => '', 'html' => '<td class=\"c hiFnt\">&nbsp;</td>');
$Links[] = array('prio' => 3, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&amp;system={$System}&amp;planet={$Planet}&amp;planettype={$PlanetType}&amp;target_mission=1>{$_Lang['type_mission'][1]}</a>");
if($GalaxyRowUser['id'] > 0)
{
if(($GalaxyRowUser['ally_id'] == $_User['ally_id'] AND $_User['ally_id'] > 0) OR in_array($GalaxyRowUser['id'], $MyBuddies) OR (isset($MyAllyPacts[$GalaxyRowUser['ally_id']]) && $MyAllyPacts[$GalaxyRowUser['ally_id']] >= 3))
{
$Links[] = array('prio' => 4, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=5>{$_Lang['type_mission'][5]}</a>");
if ($GalaxyRowUser['id'] != $_User['id']) {
$menuActions[1] = [
'txt' => "<a href=# onclick=&#039return sendShips(1, {$Galaxy}, {$System}, {$Planet}, {$PlanetType})&#039 >{$_Lang['type_mission'][6]}</a>",
];
$menuActions[2] = [
'txt' => '',
'html' => '<td class=\"c hiFnt\">&nbsp;</td>',
];
$menuActions[3] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&amp;system={$System}&amp;planet={$Planet}&amp;planettype={$PlanetType}&amp;target_mission=1>{$_Lang['type_mission'][1]}</a>",
];
if ($GalaxyRowUser['id'] > 0) {
if (
(
$GalaxyRowUser['ally_id'] == $_User['ally_id'] && $_User['ally_id'] > 0
) ||
in_array($GalaxyRowUser['id'], $MyBuddies) ||
(
isset($MyAllyPacts[$GalaxyRowUser['ally_id']]) && $MyAllyPacts[$GalaxyRowUser['ally_id']] >= 3
)
) {
$menuActions[4] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=5>{$_Lang['type_mission'][5]}</a>",
];
}
}
if($CanDestroy)
{
$Links[] = array('prio' => 5, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=9>{$_Lang['type_mission'][9]}</a>");
if ($CanDestroy) {
$menuActions[5] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=9>{$_Lang['type_mission'][9]}</a>",
];
}
} else {
$menuActions[6] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=4>{$_Lang['type_mission'][4]}</a>",
];
}
else
{
$Links[] = array('prio' => 6, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=4>{$_Lang['type_mission'][4]}</a>");
}
$Links[] = array('prio' => 7, 'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=3>{$_Lang['type_mission'][3]}</a>");
$menuActions[7] = [
'txt' => "<a href=fleet.php?galaxy={$Galaxy}&system={$System}&planet={$Planet}&planettype={$PlanetType}&target_mission=3>{$_Lang['type_mission'][3]}</a>",
];

foreach($Links as $Index => $Data)
{
$PriorityArray[$Index] = $Data['prio'];
}
array_multisort($PriorityArray, SORT_ASC, $Links);
ksort($menuActions);

$Parse = array
(
'Lang_Moon' => $_Lang['Moon'],
'MoonName' => $GalaxyRowPlanet['name'],
$Parse = [
'Lang_Moon' => $_Lang['Moon'],
'MoonName' => $GalaxyRowPlanet['name'],
'Galaxy' => $Galaxy,
'System' => $System,
'Planet' => $Planet,
'SkinPath' => $_SkinPath,
'Lang_Diameter' => $_Lang['diameter'],
'Diameter' => prettyNumber($GalaxyRowPlanet['diameter']),
'SkinPath' => $_SkinPath,
'Lang_Diameter' => $_Lang['diameter'],
'Diameter' => prettyNumber($GalaxyRowPlanet['diameter']),
'Diameter_Units' => $_Lang['diameter_units'],
'RowCount' => (count($Links) + 2),
'Links' => ''
);
foreach($Links as $Index => $Data)
{
if(!empty($Data['html']))
{
$Parse['Links'] .= "<tr>{$Data['html']}</tr>";
}
else
{
$Parse['Links'] .= "<tr><th".($Data['txt'] == '&nbsp;' ? ' class=tipS' : '').">{$Data['txt']}</th></tr>";
'RowCount' => (count($menuActions) + 2),
'Links' => '',
];

foreach ($menuActions as $menuAction) {
if (!empty($menuAction['html'])) {
$Parse['Links'] .= "<tr>{$menuAction['html']}</tr>";

continue;
}

$Parse['Links'] .= "<tr><th".($menuAction['txt'] == '&nbsp;' ? ' class=tipS' : '').">{$menuAction['txt']}</th></tr>";
}

return parsetemplate($TPL, $Parse);
Expand Down
Loading