mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-28 18:54:18 +00:00
43397779fa
## Description: Add a rail network to handle train stations/railroad between structures. Changes: - `RailNetwork` is responsible for the train station graph. Use it to connect new `TrainStations` - A `RailRoad` connects two `TrainStation` - No loop possible in the rail network - Train stations handles its railroads - Added a layer to draw the railroads under the structures #### Clusters - To speed up computations, each `TrainStation` references its own cluster - A cluster is a list of `TrainStation` connected with each other, created by the `RailNetwork` when connecting the station - Train stations spawn trains randomly depending on its current cluster size - A `TrainStation` decides randomly of the train destination by picking one from the cluster #### Production building: - Added a factory which has no gameplay impact currently. _To be discussed._ #### Train stops: - When a train reaches a factory, it's filled with a "cargo". The loaded trains has no impact currently. _To be discussed._ - When a train reaches a city, the player earn 10k gold - When a train reaches a port, it sends a new tradeship if possible - If a destination/source is destroyed, the train & railroad are deleted too https://github.com/user-attachments/assets/42375c17-9e04-4a42-98d0-708c81ffd609 https://github.com/user-attachments/assets/fbecdb53-a516-4df8-87fb-1f9a62c4efa0 ## 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 - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: IngloriousTom --------- Co-authored-by: Scott Anderson <scottanderson@users.noreply.github.com>
80 lines
1.6 KiB
TypeScript
80 lines
1.6 KiB
TypeScript
import { RailType } from "../../../core/game/GameUpdates";
|
|
|
|
const railTypeToFunctionMap: Record<RailType, () => number[][]> = {
|
|
[RailType.TOP_RIGHT]: topRightRailroadCornerRects,
|
|
[RailType.BOTTOM_LEFT]: bottomLeftRailroadCornerRects,
|
|
[RailType.TOP_LEFT]: topLeftRailroadCornerRects,
|
|
[RailType.BOTTOM_RIGHT]: bottomRightRailroadCornerRects,
|
|
[RailType.HORIZONTAL]: horizontalRailroadRects,
|
|
[RailType.VERTICAL]: verticalRailroadRects,
|
|
};
|
|
|
|
export function getRailroadRects(type: RailType): number[][] {
|
|
const railRects = railTypeToFunctionMap[type];
|
|
if (!railRects) {
|
|
// Should never happen
|
|
throw new Error(`Unsupported RailType: ${type}`);
|
|
}
|
|
return railRects();
|
|
}
|
|
|
|
function horizontalRailroadRects(): number[][] {
|
|
// x/y/w/h
|
|
const rects = [
|
|
[-1, -1, 2, 1],
|
|
[-1, 1, 2, 1],
|
|
[-1, 0, 1, 1],
|
|
];
|
|
return rects;
|
|
}
|
|
|
|
function verticalRailroadRects(): number[][] {
|
|
// x/y/w/h
|
|
const rects = [
|
|
[-1, -2, 1, 2],
|
|
[1, -2, 1, 2],
|
|
[0, -1, 1, 1],
|
|
];
|
|
return rects;
|
|
}
|
|
|
|
function topRightRailroadCornerRects(): number[][] {
|
|
// x/y/w/h
|
|
const rects = [
|
|
[-1, -2, 1, 2],
|
|
[0, -1, 1, 2],
|
|
[1, -2, 1, 4],
|
|
];
|
|
return rects;
|
|
}
|
|
|
|
function topLeftRailroadCornerRects(): number[][] {
|
|
// x/y/w/h
|
|
const rects = [
|
|
[-1, -2, 1, 4],
|
|
[0, -1, 1, 2],
|
|
[1, -2, 1, 2],
|
|
];
|
|
return rects;
|
|
}
|
|
|
|
function bottomRightRailroadCornerRects(): number[][] {
|
|
// x/y/w/h
|
|
const rects = [
|
|
[-1, 1, 1, 2],
|
|
[0, 0, 1, 2],
|
|
[1, -1, 1, 4],
|
|
];
|
|
return rects;
|
|
}
|
|
|
|
function bottomLeftRailroadCornerRects(): number[][] {
|
|
// x/y/w/h
|
|
const rects = [
|
|
[-1, -1, 1, 4],
|
|
[0, 0, 1, 2],
|
|
[1, 1, 1, 2],
|
|
];
|
|
return rects;
|
|
}
|