1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Spacecraft\Lib\Movement\Component; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use RuntimeException; |
9
|
|
|
use Stu\Component\Map\DirectionEnum; |
10
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
11
|
|
|
use Stu\Orm\Entity\Location; |
12
|
|
|
use Stu\Orm\Entity\StarSystemMap; |
13
|
|
|
|
14
|
|
|
final class UpdateFlightDirection implements UpdateFlightDirectionInterface |
15
|
|
|
{ |
16
|
6 |
|
#[Override] |
17
|
|
|
public function updateWhenTraversing( |
18
|
|
|
Location $oldWaypoint, |
19
|
|
|
Location $waypoint, |
20
|
|
|
SpacecraftWrapperInterface $wrapper |
21
|
|
|
): DirectionEnum { |
22
|
|
|
|
23
|
6 |
|
if (!$wrapper->get()->hasComputer()) { |
24
|
1 |
|
return DirectionEnum::NON; |
25
|
|
|
} |
26
|
|
|
|
27
|
5 |
|
$startX = $oldWaypoint->getX(); |
28
|
5 |
|
$startY = $oldWaypoint->getY(); |
29
|
|
|
|
30
|
5 |
|
$destinationX = $waypoint->getX(); |
31
|
5 |
|
$destinationY = $waypoint->getY(); |
32
|
|
|
|
33
|
5 |
|
$flightDirection = null; |
34
|
|
|
|
35
|
5 |
|
if ($destinationX === $startX) { |
36
|
3 |
|
$oldy = $startY; |
37
|
3 |
|
if ($destinationY > $oldy) { |
38
|
1 |
|
$flightDirection = DirectionEnum::BOTTOM; |
39
|
2 |
|
} elseif ($destinationY < $oldy) { |
40
|
1 |
|
$flightDirection = DirectionEnum::TOP; |
41
|
|
|
} |
42
|
|
|
} |
43
|
5 |
|
if ($destinationY === $startY) { |
44
|
3 |
|
$oldx = $startX; |
45
|
3 |
|
if ($destinationX > $oldx) { |
46
|
1 |
|
$flightDirection = DirectionEnum::RIGHT; |
47
|
2 |
|
} elseif ($destinationX < $oldx) { |
48
|
1 |
|
$flightDirection = DirectionEnum::LEFT; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
5 |
|
if ($flightDirection === null) { |
53
|
1 |
|
throw new RuntimeException('this should not happen'); |
54
|
|
|
} |
55
|
|
|
|
56
|
4 |
|
$wrapper->getComputerSystemDataMandatory()->setFlightDirection($flightDirection)->update(); |
57
|
|
|
|
58
|
4 |
|
return $flightDirection; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
#[Override] |
62
|
|
|
public function updateWhenSystemExit(SpacecraftWrapperInterface $wrapper, StarSystemMap $starsystemMap): void |
63
|
|
|
{ |
64
|
|
|
$system = $starsystemMap->getSystem(); |
65
|
|
|
|
66
|
|
|
$shipX = $starsystemMap->getSx(); |
67
|
|
|
$shipY = $starsystemMap->getSy(); |
68
|
|
|
|
69
|
|
|
$rad12or34 = atan($shipY / $shipX); |
70
|
|
|
$rad14or23 = atan(($system->getMaxX() - $shipX) / $shipY); |
71
|
|
|
|
72
|
|
|
if ($rad12or34 < M_PI_4) { |
73
|
|
|
$flightDirection = $rad14or23 < M_PI_4 ? DirectionEnum::LEFT : DirectionEnum::BOTTOM; |
74
|
|
|
} elseif ($rad14or23 < M_PI_4) { |
75
|
|
|
$flightDirection = DirectionEnum::TOP; |
76
|
|
|
} else { |
77
|
|
|
$flightDirection = DirectionEnum::RIGHT; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$wrapper->getComputerSystemDataMandatory()->setFlightDirection($flightDirection)->update(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths