Skip to content

Commit

Permalink
Merge pull request #143 from mdziekon/mdziekon/gh-139/flight-control-…
Browse files Browse the repository at this point in the history
…refactor-part02

 Flight Control refactor (part 02) - Various refactors
  • Loading branch information
mdziekon authored Dec 26, 2020
2 parents ae3dfbd + 41d0c2f commit 9832fed
Show file tree
Hide file tree
Showing 28 changed files with 1,052 additions and 751 deletions.
6 changes: 5 additions & 1 deletion admin/user_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@
$Data['ally_name'] = $Data['ally_request_name'];
}
$Player['Ally'] = ($Data['ally_id'] > 0 ? '<a class="help" title="'.$_Lang['SearchByAlly'].'" href="userlist.php?search_user='.$Data['ally_id'].'&search_by=aid">'.$Data['ally_name'].' ('.$Data['ally_id'].')</a>'.($Data['ally_request'] != 0 ? ' ['.$_Lang['Request'].']' : ($Data['ally_owner'] == $UID ? ' ['.$_Lang['Ally_owner'].']' : '')) : '&nbsp;-&nbsp;');
$Player['AccountActive'] = (!empty($Data['activation_code']) ? "<b class=\"orange\">{$_Lang['_no']}</b><br/>{$_Lang['ActivationCode']}: {$Data['activation_code']}" : "<b class=\"lime\">{$_Lang['_yes']}</b>");
$Player['AccountActive'] = (
!isUserAccountActivated($Data) ?
"<b class=\"orange\">{$_Lang['_no']}</b><br/>{$_Lang['ActivationCode']}: {$Data['activation_code']}" :
"<b class=\"lime\">{$_Lang['_yes']}</b>"
);
$Player['DisableIPCheck'] = (($Data['noipcheck'] == 1) ? $_Lang['_no'] : $_Lang['_yes']);
$Player['MotherPlanet'] = "{$Data['mothername']} ({$_Lang['MotherPlanet_ID']}: {$Data['id_planet']}) [<a class=\"help\" title=\"{$_Lang['GoToGalaxy']}\" href=\"../galaxy.php?mode=3&amp;galaxy={$Data['galaxy']}&amp;system={$Data['system']}&amp;planet={$Data['planet']}\">{$Data['galaxy']}:{$Data['system']}:{$Data['planet']}</a>]";

Expand Down
3 changes: 1 addition & 2 deletions admin/userlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,7 @@
$Bloc['UserMoreInfo'] .= "<br/><span class=\"fl\"><b class=\"red\">{$_Lang['UserIsBanned']}:</b> <b class=\"{$BanColor}\">".date('d.m.Y, H:i:s', $Data['ban_endtime'])."</b></span><span class=\"fr\">({$BanTime})</span>";
}
// MoreInfo - Activation Link
if(!empty($Data['activation_code']))
{
if (!isUserAccountActivated($Data)) {
$Bloc['UserMoreInfo'] .= "<br/><span class=\"fl\"><b class=\"orange\">{$_Lang['UserNotActivated']}</b></span><span class=\"fr\">[{$_Lang['UserActivationLink']}: <a href=\"".(GAMEURL)."activate.php?code={$Data['activation_code']}\" target=\"_blank\">".(GAMEURL)."activate.php?code=<b class=\"orange\">{$Data['activation_code']}</b></a>]</span>";
}
// MoreInfo - is On Deletion
Expand Down
136 changes: 62 additions & 74 deletions ajax/galaxyfleet.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

include($_EnginePath.'common.php');

include($_EnginePath . 'modules/flightControl/_includes.php');

use UniEngine\Engine\Modules\FlightControl;

function CreateReturn($ReturnCode)
{
global $Update, $ShipCount, $Galaxy, $System, $Planet, $Type, $ActualFleets, $Spy_Probes, $Recyclers, $Colonizers;
Expand Down Expand Up @@ -42,10 +46,11 @@ function CreateReturn($ReturnCode)
{
CreateReturn('601');
}
if(!empty($_User['activation_code']))
{

if (!isUserAccountActivated($_User)) {
CreateReturn('661');
}

$Galaxy = (isset($_POST['galaxy']) ? intval($_POST['galaxy']) : 0);
$System = (isset($_POST['system']) ? intval($_POST['system']) : 0);
$Planet = (isset($_POST['planet']) ? intval($_POST['planet']) : 0);
Expand Down Expand Up @@ -78,8 +83,12 @@ function CreateReturn($ReturnCode)
Morale_ReCalculate($_User, $Time);
}

if(($_User[$_Vars_GameElements[108]] + 1 + (($_User['admiral_time'] > 0) ? 2 : 0)) <= $ActualFleets)
{
$fleetSlotsCount = FlightControl\Utils\Helpers\getUserFleetSlotsCount([
'user' => $_User,
'timestamp' => $Time,
]);

if ($ActualFleets >= $fleetSlotsCount) {
$Update = '1';
CreateReturn('609');
}
Expand Down Expand Up @@ -430,32 +439,14 @@ function CreateReturn($ReturnCode)
$ShipCount = $CurrentPlanet[$_Vars_GameElements[$ShipID]];
}

// Create SpeedsArray
$SpeedsAvailable = array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
$availableSpeeds = FlightControl\Utils\Helpers\getAvailableSpeeds([
'user' => &$_User,
'timestamp' => $Time,
]);

if($_User['admiral_time'] > $Time)
{
$SpeedsAvailable[] = 12;
$SpeedsAvailable[] = 11;
$SpeedsAvailable[] = 0.5;
$SpeedsAvailable[] = 0.25;
}
if(MORALE_ENABLED)
{
$MaxAvailableSpeed = max($SpeedsAvailable);
if($_User['morale_level'] >= MORALE_BONUS_FLEETSPEEDUP1)
{
$SpeedsAvailable[] = $MaxAvailableSpeed + (MORALE_BONUS_FLEETSPEEDUP1_VALUE / 10);
}
if($_User['morale_level'] >= MORALE_BONUS_FLEETSPEEDUP2)
{
$SpeedsAvailable[] = $MaxAvailableSpeed + (MORALE_BONUS_FLEETSPEEDUP2_VALUE / 10);
}
}
arsort($SpeedsAvailable);
reset($SpeedsAvailable);
reset($availableSpeeds);

$GenFleetSpeed = current($SpeedsAvailable);
$GenFleetSpeed = current($availableSpeeds);
$SpeedFactor = getUniFleetsSpeedFactor();
$MaxFleetSpeed = getShipsCurrentSpeed($ShipID, $_User);

Expand Down Expand Up @@ -494,66 +485,63 @@ function CreateReturn($ReturnCode)
$fleet['start_time'] = $duration + $Time;
$fleet['end_time'] = (2 * $duration) + $Time;

if($CurrentPlanet['deuterium'] >= $consumption)
if ($CurrentPlanet['deuterium'] < $consumption) {
CreateReturn('607');
}

$FleetStorage = $_Vars_Prices[$ShipID]['capacity'] * $ShipCount;
if($Mission == 6)
{
$FleetStorage = $_Vars_Prices[$ShipID]['capacity'] * $ShipCount;
if($Mission == 6)
// Try to SlowDown fleet only if it's Espionage Mission
while($FleetStorage < $consumption)
{
// Try to SlowDown fleet only if it's Espionage Mission
while($FleetStorage < $consumption)
$GenFleetSpeed = next($availableSpeeds);
if($GenFleetSpeed !== false)
{
$GenFleetSpeed = next($SpeedsAvailable);
if($GenFleetSpeed !== false)
{
$duration = getFlightDuration([
'speedFactor' => $GenFleetSpeed,
'distance' => $distance,
'maxShipsSpeed' => $MaxFleetSpeed
]);
$consumption = getFlightTotalConsumption(
[
'ships' => [
$ShipID => $ShipCount
],
'distance' => $distance,
'duration' => $duration,
$duration = getFlightDuration([
'speedFactor' => $GenFleetSpeed,
'distance' => $distance,
'maxShipsSpeed' => $MaxFleetSpeed
]);
$consumption = getFlightTotalConsumption(
[
'ships' => [
$ShipID => $ShipCount
],
$_User
);
'distance' => $distance,
'duration' => $duration,
],
$_User
);

$fleet['start_time'] = $duration + $Time;
$fleet['end_time'] = (2 * $duration) + $Time;
}
else
{
break;
}
$fleet['start_time'] = $duration + $Time;
$fleet['end_time'] = (2 * $duration) + $Time;
}
}

if($FleetStorage >= $consumption)
{
switch($Mission)
else
{
case 6: //Spy
$TargetOwner = $TargetUser;
break;
case 8: //Recycling
$TargetOwner = 0;
break;
case 7: //Colonization
$TargetOwner = 0;
break;
break;
}
}
else
}

if($FleetStorage >= $consumption)
{
switch($Mission)
{
CreateReturn('608');
case 6: //Spy
$TargetOwner = $TargetUser;
break;
case 8: //Recycling
$TargetOwner = 0;
break;
case 7: //Colonization
$TargetOwner = 0;
break;
}
}
else
{
CreateReturn('607');
CreateReturn('608');
}

if(!isset($TargetID) || $TargetID <= 0)
Expand Down
19 changes: 13 additions & 6 deletions ajax/sendmissiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
$_SetAccessLogPath = '../';
$_EnginePath = '../';

include($_EnginePath.'common.php');
include($_EnginePath . 'common.php');
include($_EnginePath . 'modules/flightControl/_includes.php');

use UniEngine\Engine\Modules\FlightControl;

function CreateReturn($ReturnCode, $Update = '0')
{
Expand All @@ -23,18 +26,22 @@ function CreateReturn($ReturnCode, $Update = '0')
{
CreateReturn('601');
}
if(!empty($_User['activation_code']))
{

if (!isUserAccountActivated($_User)) {
CreateReturn('661');
}

$Now = time();

$FlyingFleets = doquery("SELECT COUNT(`fleet_id`) as `Number` FROM {{table}} WHERE `fleet_owner` = '{$_User['id']}';", 'fleets', true);
$FlyingFleets = $FlyingFleets['Number'];
$MaxFleets = 1 + $_User[$_Vars_GameElements[108]] + (($_User['admiral_time'] > $Now) ? 2 : 0);
if($FlyingFleets >= $MaxFleets)
{

$MaxFleets = FlightControl\Utils\Helpers\getUserFleetSlotsCount([
'user' => $_User,
'timestamp' => $Now,
]);

if ($FlyingFleets >= $MaxFleets) {
CreateReturn('609');
}

Expand Down
Loading

0 comments on commit 9832fed

Please sign in to comment.