Skip to content

Commit

Permalink
GH-139 Move max flight's speed getter into an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed May 27, 2022
1 parent acce507 commit 0a7f0b0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
19 changes: 6 additions & 13 deletions fleet1.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,6 @@
}
}

$slowestShipSpeed = min(
array_map_withkeys($shipsDetails, function ($shipDetails) {
return $shipDetails['speed'];
})
);

// Speed modifier
if (MORALE_ENABLED) {
if ($_User['morale_level'] <= MORALE_PENALTY_FLEETSLOWDOWN) {
$slowestShipSpeed *= MORALE_PENALTY_FLEETSLOWDOWN_VALUE;
}
}

$_Lang['P_HideACSJoining'] = $Hide;
$GetACSData = intval($_POST['getacsdata']);
$SetPosNotEmpty = false;
Expand Down Expand Up @@ -202,9 +189,15 @@
$_Lang['SetTargetMission'] = 2;
}

$slowestShipSpeed = FlightControl\Utils\Helpers\getSlowestShipSpeed([
'shipsDetails' => $shipsDetails,
'user' => &$_User,
]);

// Show info boxes
$_Lang['P_SFBInfobox'] = FlightControl\Components\SmartFleetBlockadeInfoBox\render()['componentHTML'];


$_Lang['P_ShipsDetailsJSON'] = json_encode($shipsDetails, JSON_FORCE_OBJECT);
$_Lang['speedallsmin'] = $slowestShipSpeed;
$_Lang['MaxSpeedPretty'] = prettyNumber($slowestShipSpeed);
Expand Down
1 change: 1 addition & 0 deletions modules/flightControl/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
include($includePath . './utils/helpers/getFleetUnionJoinData.helper.php');
include($includePath . './utils/helpers/getFlightParams.helper.php');
include($includePath . './utils/helpers/getQuantumGateStateDetails.helper.php');
include($includePath . './utils/helpers/getSlowestShipSpeed.helper.php');
include($includePath . './utils/helpers/getTargetInfo.helper.php');
include($includePath . './utils/helpers/getUserExpeditionSlotsCount.helper.php');
include($includePath . './utils/helpers/getUserFleetSlotsCount.helper.php');
Expand Down
30 changes: 30 additions & 0 deletions modules/flightControl/utils/helpers/getSlowestShipSpeed.helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace UniEngine\Engine\Modules\FlightControl\Utils\Helpers;

/**
* @param array $params
* @param Array<{ speed: number }> $params['shipsDetails']
* @param ref $params['user']
*/
function getSlowestShipSpeed($params) {
$shipsDetails = $params['shipsDetails'];
$user = &$params['user'];

$slowestShipSpeed = min(
array_map_withkeys($shipsDetails, function ($shipDetails) {
return $shipDetails['speed'];
})
);

if (
MORALE_ENABLED &&
$user['morale_level'] <= MORALE_PENALTY_FLEETSLOWDOWN
) {
$slowestShipSpeed *= MORALE_PENALTY_FLEETSLOWDOWN_VALUE;
}

return $slowestShipSpeed;
}

?>

0 comments on commit 0a7f0b0

Please sign in to comment.