mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 11:13:27 +00:00
Fixed rail network path length limit and readded tests for it (#4406)
> **Before opening a PR:** discuss new features on [Discord](https://discord.gg/K9zernJB5z) first, and file bugs or small improvements as [issues](https://github.com/openfrontio/OpenFrontIO/issues/new/choose). You must be assigned to an `approved` issue — unsolicited PRs will be auto-closed. **Add approved & assigned issue number here:** Resolves #4396 ## Description: Makes the max rail length 1.4142 * the max station radius to be minimum amount outside of the factory effect radius. Bug: <img width="1921" height="1078" alt="image" src="https://github.com/user-attachments/assets/91b3b3fa-037a-4d9a-b06b-afe2fe2c8ea8" /> Fixed: <img width="1922" height="1079" alt="image" src="https://github.com/user-attachments/assets/3719cf73-bc41-494f-9d86-548f308f5896" /> ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory ## Please put your Discord username so you can be contacted if a bug or regression is found: tktk1234567
This commit is contained in:
@@ -71,6 +71,7 @@ describe("RailNetworkImpl", () => {
|
||||
config: () => ({
|
||||
trainStationMaxRange: () => 80,
|
||||
trainStationMinRange: () => 10,
|
||||
railroadMaxSize: () => 100,
|
||||
}),
|
||||
x: vi.fn(() => 0),
|
||||
y: vi.fn(() => 0),
|
||||
@@ -249,11 +250,7 @@ describe("RailNetworkImpl", () => {
|
||||
pathService.findTilePath.mockReturnValue(mockPath);
|
||||
|
||||
game.nearbyUnits.mockReturnValue([
|
||||
{
|
||||
unit: neighborStation.unit,
|
||||
distSquared: 400,
|
||||
euclideanDist: Math.sqrt(400),
|
||||
},
|
||||
{ unit: neighborStation.unit, distSquared: 400 },
|
||||
]);
|
||||
|
||||
const result = network.computeGhostRailPaths(UnitType.City, tile);
|
||||
@@ -272,11 +269,7 @@ describe("RailNetworkImpl", () => {
|
||||
|
||||
// distSquared = 50 <= minRange^2 (10^2 = 100)
|
||||
game.nearbyUnits.mockReturnValue([
|
||||
{
|
||||
unit: neighborStation.unit,
|
||||
distSquared: 50,
|
||||
euclideanDist: Math.sqrt(50),
|
||||
},
|
||||
{ unit: neighborStation.unit, distSquared: 50 },
|
||||
]);
|
||||
|
||||
const result = network.computeGhostRailPaths(UnitType.City, tile);
|
||||
@@ -290,8 +283,26 @@ describe("RailNetworkImpl", () => {
|
||||
|
||||
stationManager.findStation.mockReturnValue(null);
|
||||
|
||||
game.nearbyUnits.mockReturnValue([{ unit: { id: 1 }, distSquared: 400 }]);
|
||||
|
||||
const result = network.computeGhostRailPaths(UnitType.City, tile);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
test("skips paths that exceed max railroad size", () => {
|
||||
const tile = 42 as any;
|
||||
const railGridMock = { query: vi.fn(() => new Set()) };
|
||||
(network as any).railGrid = railGridMock;
|
||||
|
||||
const neighborStation = createMockStation(1);
|
||||
neighborStation.tile.mockReturnValue(100);
|
||||
stationManager.findStation.mockReturnValue(neighborStation);
|
||||
|
||||
// Path length >= railroadMaxSize (100)
|
||||
pathService.findTilePath.mockReturnValue(new Array(100));
|
||||
|
||||
game.nearbyUnits.mockReturnValue([
|
||||
{ unit: { id: 1 }, distSquared: 400, euclideanDist: Math.sqrt(400) },
|
||||
{ unit: neighborStation.unit, distSquared: 400 },
|
||||
]);
|
||||
|
||||
const result = network.computeGhostRailPaths(UnitType.City, tile);
|
||||
@@ -303,19 +314,11 @@ describe("RailNetworkImpl", () => {
|
||||
const railGridMock = { query: vi.fn(() => new Set()) };
|
||||
(network as any).railGrid = railGridMock;
|
||||
|
||||
const neighbors: Array<{
|
||||
unit: any;
|
||||
distSquared: number;
|
||||
euclideanDist: number;
|
||||
}> = [];
|
||||
const neighbors: Array<{ unit: any; distSquared: number }> = [];
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const station = createMockStation(i);
|
||||
station.tile.mockReturnValue(100 + i);
|
||||
neighbors.push({
|
||||
unit: station.unit,
|
||||
distSquared: 400 + i,
|
||||
euclideanDist: Math.sqrt(400 + i),
|
||||
});
|
||||
neighbors.push({ unit: station.unit, distSquared: 400 + i });
|
||||
}
|
||||
|
||||
stationManager.findStation.mockImplementation((unit: any) => {
|
||||
|
||||
Reference in New Issue
Block a user