Skip to content

Commit

Permalink
GH-139 Simplify max speed calculation for other steps of fleet sending
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed May 27, 2022
1 parent 0a7f0b0 commit edf811e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
16 changes: 6 additions & 10 deletions fleet2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 7 additions & 11 deletions fleet3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -521,7 +517,7 @@ function messageRed($Text, $Title)
'fleet' => $Fleet,
'fleetSpeed' => $GenFleetSpeed,
'distance' => $Distance,
'maxFleetSpeed' => $MaxFleetSpeed,
'maxFleetSpeed' => $slowestShipSpeed,
'isUsingQuantumGate' => $isUsingQuantumGate,
'quantumGateUseType' => $quantumGateUseType,
]);
Expand Down Expand Up @@ -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'];
Expand Down
14 changes: 6 additions & 8 deletions includes/helpers/fleets/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit edf811e

Please sign in to comment.