|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Smr\Pages\Admin\UniGen; |
|
4
|
|
|
|
|
5
|
|
|
use Plotter; |
|
6
|
|
|
use Smr\Page\AccountPage; |
|
7
|
|
|
use Smr\Page\ReusableTrait; |
|
8
|
|
|
use Smr\Race; |
|
9
|
|
|
use Smr\Routes\RouteGenerator; |
|
10
|
|
|
use Smr\Template; |
|
11
|
|
|
use Smr\TradeGood; |
|
12
|
|
|
use SmrAccount; |
|
13
|
|
|
use SmrGame; |
|
14
|
|
|
use SmrLocation; |
|
15
|
|
|
|
|
16
|
|
|
class CheckMap extends AccountPage { |
|
17
|
|
|
|
|
18
|
|
|
use ReusableTrait; |
|
19
|
|
|
|
|
20
|
|
|
public string $file = 'admin/unigen/check_map.php'; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
private readonly int $gameID, |
|
24
|
|
|
private readonly int $galaxyID |
|
25
|
|
|
) {} |
|
26
|
|
|
|
|
27
|
|
|
public function build(SmrAccount $account, Template $template): void { |
|
28
|
|
|
$game = SmrGame::getGame($this->gameID); |
|
29
|
|
|
$template->assign('PageTopic', 'Check Map : ' . $game->getDisplayName()); |
|
30
|
|
|
|
|
31
|
|
|
$container = new EditGalaxy($this->gameID, $this->galaxyID); |
|
32
|
|
|
$template->assign('BackHREF', $container->href()); |
|
33
|
|
|
|
|
34
|
|
|
$galaxies = $game->getGalaxies(); |
|
35
|
|
|
|
|
36
|
|
|
// Check if any locations are missing |
|
37
|
|
|
$existingLocs = []; |
|
38
|
|
|
foreach ($galaxies as $galaxy) { |
|
39
|
|
|
foreach ($galaxy->getLocations() as $sectorLocs) { |
|
40
|
|
|
foreach (array_keys($sectorLocs) as $locID) { |
|
41
|
|
|
$existingLocs[$locID] = true; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
$missingLocs = array_diff( |
|
46
|
|
|
array_keys(SmrLocation::getAllLocations($this->gameID)), |
|
47
|
|
|
array_keys($existingLocs) |
|
48
|
|
|
); |
|
49
|
|
|
$missingLocNames = []; |
|
50
|
|
|
foreach ($missingLocs as $locID) { |
|
51
|
|
|
$missingLocNames[] = SmrLocation::getLocation($this->gameID, $locID)->getName(); |
|
52
|
|
|
} |
|
53
|
|
|
$template->assign('MissingLocNames', $missingLocNames); |
|
54
|
|
|
|
|
55
|
|
|
// Calculate the best trade routes for each galaxy |
|
56
|
|
|
$tradeGoods = [GOODS_NOTHING => true]; |
|
57
|
|
|
foreach (TradeGood::getAllIDs() as $goodID) { |
|
58
|
|
|
$tradeGoods[$goodID] = true; |
|
59
|
|
|
} |
|
60
|
|
|
$tradeRaces = []; |
|
61
|
|
|
foreach (Race::getAllIDs() as $raceID) { |
|
62
|
|
|
$tradeRaces[$raceID] = true; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$maxNumberOfPorts = 2; |
|
66
|
|
|
$routesForPort = -1; |
|
67
|
|
|
$numberOfRoutes = 1; |
|
68
|
|
|
$maxDistance = 999; |
|
69
|
|
|
|
|
70
|
|
|
$allGalaxyRoutes = []; |
|
71
|
|
|
foreach ($galaxies as $galaxy) { |
|
72
|
|
|
$galaxy->getSectors(); // Efficiently construct the sector cache |
|
73
|
|
|
$ports = $galaxy->getPorts(); |
|
74
|
|
|
$distances = Plotter::calculatePortToPortDistances($ports, $tradeRaces, $maxDistance, $galaxy->getStartSector(), $galaxy->getEndSector()); |
|
75
|
|
|
$allGalaxyRoutes[$galaxy->getDisplayName()] = RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $ports, $tradeGoods, $tradeRaces, $distances, $routesForPort, $numberOfRoutes); |
|
76
|
|
|
} |
|
77
|
|
|
$template->assign('AllGalaxyRoutes', $allGalaxyRoutes); |
|
78
|
|
|
|
|
79
|
|
|
$routeTypes = [ |
|
80
|
|
|
RouteGenerator::EXP_ROUTE => 'Experience', |
|
81
|
|
|
RouteGenerator::MONEY_ROUTE => 'Profit', |
|
82
|
|
|
]; |
|
83
|
|
|
$template->assign('RouteTypes', $routeTypes); |
|
84
|
|
|
|
|
85
|
|
|
// Largest port sell multipliers per galaxy |
|
86
|
|
|
$maxSellMultipliers = []; |
|
87
|
|
|
foreach ($galaxies as $galaxy) { |
|
88
|
|
|
$max = []; |
|
89
|
|
|
foreach ($galaxy->getPorts() as $port) { |
|
90
|
|
|
foreach ($port->getSellGoodIDs() as $goodID) { |
|
91
|
|
|
$distance = $port->getGoodDistance($goodID); |
|
92
|
|
|
// For distance ties, prefer higher good IDs |
|
93
|
|
|
if (empty($max) || $distance >= $max['Distance']) { |
|
94
|
|
|
$max = [ |
|
95
|
|
|
'Port' => $port, |
|
96
|
|
|
'GoodID' => $goodID, |
|
97
|
|
|
'Distance' => $distance, |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
if (!empty($max)) { |
|
103
|
|
|
$output = $max['Distance'] . 'x ' . TradeGood::get($max['GoodID'])->name . ' at Port #' . $max['Port']->getSectorID() . ' (' . $max['Port']->getRaceName() . ')'; |
|
104
|
|
|
$maxSellMultipliers[$galaxy->getDisplayName()] = $output; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
$template->assign('MaxSellMultipliers', $maxSellMultipliers); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|