Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs on Game.map.findRoute #262

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2763,7 +2763,14 @@ type EFFECT_COLLAPSE_TIMER = 1002;
* The options that can be accepted by `findRoute()` and friends.
*/
interface RouteOptions {
routeCallback: (roomName: string, fromRoomName: string) => any;
/**
* This callback can be used to calculate the cost of entering that room.
* You can use this to do things like prioritize your own rooms, or avoid some rooms.
* @param roomName The room being considered
* @param fromRoomName The room we're coming from
* @returns a floating point to steer the route toward a given room, or Infinity to block it entirely.
*/
routeCallback: (roomName: string, fromRoomName: string) => number;
}

interface RoomStatusPermanent {
Expand Down Expand Up @@ -2804,18 +2811,9 @@ interface GameMap {
* @param fromRoom Start room name or room object.
* @param toRoom Finish room name or room object.
* @param opts (optional) An object with the pathfinding options.
* @returns the route array or ERR_NO_PATH code
*/
findRoute(
fromRoom: string | Room,
toRoom: string | Room,
opts?: RouteOptions,
):
| Array<{
exit: ExitConstant;
room: string;
}>
| ERR_NO_PATH;
* @returns either an array of room exits / room name, or ERR_NO_PATH if the destination room cannot be reached.
*/
findRoute(fromRoom: string | Room, toRoom: string | Room, opts?: RouteOptions): { exit: ExitConstant; room: string }[] | ERR_NO_PATH;
/**
* Get the linear distance (in rooms) between two rooms. You can use this function to estimate the energy cost of
* sending resources through terminals, or using observers and nukes.
Expand Down
24 changes: 11 additions & 13 deletions src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
* The options that can be accepted by `findRoute()` and friends.
*/
interface RouteOptions {
routeCallback: (roomName: string, fromRoomName: string) => any;
/**
* This callback can be used to calculate the cost of entering that room.
* You can use this to do things like prioritize your own rooms, or avoid some rooms.
* @param roomName The room being considered
* @param fromRoomName The room we're coming from
* @returns a floating point to steer the route toward a given room, or Infinity to block it entirely.
*/
routeCallback: (roomName: string, fromRoomName: string) => number;
}

interface RoomStatusPermanent {
Expand Down Expand Up @@ -43,18 +50,9 @@ interface GameMap {
* @param fromRoom Start room name or room object.
* @param toRoom Finish room name or room object.
* @param opts (optional) An object with the pathfinding options.
* @returns the route array or ERR_NO_PATH code
*/
findRoute(
fromRoom: string | Room,
toRoom: string | Room,
opts?: RouteOptions,
):
| Array<{
exit: ExitConstant;
room: string;
}>
| ERR_NO_PATH;
* @returns either an array of room exits / room name, or ERR_NO_PATH if the destination room cannot be reached.
*/
findRoute(fromRoom: string | Room, toRoom: string | Room, opts?: RouteOptions): { exit: ExitConstant; room: string }[] | ERR_NO_PATH;
/**
* Get the linear distance (in rooms) between two rooms. You can use this function to estimate the energy cost of
* sending resources through terminals, or using observers and nukes.
Expand Down
Loading