diff --git a/fleet2.php b/fleet2.php index 14420289..0aa7a232 100644 --- a/fleet2.php +++ b/fleet2.php @@ -236,22 +236,18 @@ $PreSelectedMission = intval($_POST['target_mission']); $SpeedFactor = getUniFleetsSpeedFactor(); -$AllFleetSpeed = getFleetShipsSpeeds($Fleet['array'], $_User); $GenFleetSpeed = $_POST['speed']; -$MaxFleetSpeed = min($AllFleetSpeed); -if(MORALE_ENABLED) -{ - if($_User['morale_level'] <= MORALE_PENALTY_FLEETSLOWDOWN) - { - $MaxFleetSpeed *= MORALE_PENALTY_FLEETSLOWDOWN_VALUE; - } -} + +$slowestShipSpeed = FlightControl\Utils\Helpers\getSlowestShipSpeed([ + 'shipsDetails' => getFleetShipsSpeeds($Fleet['array'], $_User), + 'user' => &$_User, +]); $distance = getFlightDistanceBetween($_Planet, $Target); $duration = getFlightDuration([ 'speedFactor' => $GenFleetSpeed, 'distance' => $distance, - 'maxShipsSpeed' => $MaxFleetSpeed + 'maxShipsSpeed' => $slowestShipSpeed ]); $consumption = getFlightTotalConsumption( diff --git a/fleet3.php b/fleet3.php index 3db3f18b..ef00ac19 100644 --- a/fleet3.php +++ b/fleet3.php @@ -472,17 +472,13 @@ function messageRed($Text, $Title) } // --- Calculate Speed and Distance -$AllFleetSpeed = getFleetShipsSpeeds($Fleet['array'], $_User); $GenFleetSpeed = $Fleet['Speed']; $SpeedFactor = getUniFleetsSpeedFactor(); -$MaxFleetSpeed = min($AllFleetSpeed); -if(MORALE_ENABLED) -{ - if($_User['morale_level'] <= MORALE_PENALTY_FLEETSLOWDOWN) - { - $MaxFleetSpeed *= MORALE_PENALTY_FLEETSLOWDOWN_VALUE; - } -} + +$slowestShipSpeed = FlightControl\Utils\Helpers\getSlowestShipSpeed([ + 'shipsDetails' => getFleetShipsSpeeds($Fleet['array'], $_User), + 'user' => &$_User, +]); $Distance = getFlightDistanceBetween($_Planet, $Target); @@ -521,7 +517,7 @@ function messageRed($Text, $Title) 'fleet' => $Fleet, 'fleetSpeed' => $GenFleetSpeed, 'distance' => $Distance, - 'maxFleetSpeed' => $MaxFleetSpeed, + 'maxFleetSpeed' => $slowestShipSpeed, 'isUsingQuantumGate' => $isUsingQuantumGate, 'quantumGateUseType' => $quantumGateUseType, ]); @@ -795,7 +791,7 @@ function messageRed($Text, $Title) $_Lang['FleetMission'] = $_Lang['type_mission'][$Fleet['Mission']]; $_Lang['FleetDistance'] = prettyNumber($Distance); -$_Lang['FleetSpeed'] = prettyNumber($MaxFleetSpeed); +$_Lang['FleetSpeed'] = prettyNumber($slowestShipSpeed); $_Lang['FleetFuel'] = prettyNumber($Consumption); $_Lang['StartGalaxy'] = $_Planet['galaxy']; $_Lang['StartSystem'] = $_Planet['system']; diff --git a/includes/helpers/fleets/functions.php b/includes/helpers/fleets/functions.php index d45eb64f..5b160013 100644 --- a/includes/helpers/fleets/functions.php +++ b/includes/helpers/fleets/functions.php @@ -105,14 +105,12 @@ function getShipsCurrentConsumption($shipID, $user) { return $usedEngine['data']['consumption']; } -function getFleetShipsSpeeds($fleetShips, $user) { - $speedsPerShip = []; - - foreach ($fleetShips as $shipID => $_shipsCount) { - $speedsPerShip[$shipID] = getShipsCurrentSpeed($shipID, $user); - } - - return $speedsPerShip; +function getFleetShipsSpeeds($fleetShips, &$user) { + return array_map_withkeys($fleetShips, function ($shipCount, $shipId) use (&$user) { + return [ + 'speed' => getShipsCurrentSpeed($shipId, $user), + ]; + }); } // Arguments: