Fixed factory ghost radius (#4337)

> **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 #4323 

## Description:

Made stations use euclidean distance for radius for checking if other
stations are close enough, removed redundant if check and unneeded
config

<img width="1920" height="1080" alt="Screenshot from 2026-06-18
14-19-48"
src="https://github.com/user-attachments/assets/a84f29f8-0cc1-46ea-9b96-3d70d6b0b20a"
/>


## 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:
TKTK123456
2026-06-19 22:27:54 -04:00
committed by GitHub
parent 805f0968b1
commit 08af8470fa
3 changed files with 36 additions and 47 deletions
+21 -24
View File
@@ -71,7 +71,6 @@ describe("RailNetworkImpl", () => {
config: () => ({
trainStationMaxRange: () => 80,
trainStationMinRange: () => 10,
railroadMaxSize: () => 100,
}),
x: vi.fn(() => 0),
y: vi.fn(() => 0),
@@ -250,7 +249,11 @@ describe("RailNetworkImpl", () => {
pathService.findTilePath.mockReturnValue(mockPath);
game.nearbyUnits.mockReturnValue([
{ unit: neighborStation.unit, distSquared: 400 },
{
unit: neighborStation.unit,
distSquared: 400,
euclideanDist: Math.sqrt(400),
},
]);
const result = network.computeGhostRailPaths(UnitType.City, tile);
@@ -269,7 +272,11 @@ describe("RailNetworkImpl", () => {
// distSquared = 50 <= minRange^2 (10^2 = 100)
game.nearbyUnits.mockReturnValue([
{ unit: neighborStation.unit, distSquared: 50 },
{
unit: neighborStation.unit,
distSquared: 50,
euclideanDist: Math.sqrt(50),
},
]);
const result = network.computeGhostRailPaths(UnitType.City, tile);
@@ -283,26 +290,8 @@ 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: neighborStation.unit, distSquared: 400 },
{ unit: { id: 1 }, distSquared: 400, euclideanDist: Math.sqrt(400) },
]);
const result = network.computeGhostRailPaths(UnitType.City, tile);
@@ -314,11 +303,19 @@ describe("RailNetworkImpl", () => {
const railGridMock = { query: vi.fn(() => new Set()) };
(network as any).railGrid = railGridMock;
const neighbors: Array<{ unit: any; distSquared: number }> = [];
const neighbors: Array<{
unit: any;
distSquared: number;
euclideanDist: 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 });
neighbors.push({
unit: station.unit,
distSquared: 400 + i,
euclideanDist: Math.sqrt(400 + i),
});
}
stationManager.findStation.mockImplementation((unit: any) => {