-
Notifications
You must be signed in to change notification settings - Fork 41
Traveler API
bonzaiferroni edited this page Jan 15, 2017
·
26 revisions
This code is still being tested. If you are using it, let me know if you run into any problems.
Traveler is a general-purpose tool for moving your creeps around.
####Features:
- Efficient path-caching and CPU-use (you can see how it compares with
creep.moveTo()
here) - Ignores creeps in pathing by default which allows for fewer PathFinder calls and single-lane creep movement
- Detects hostile rooms and will path around them once discovered
- Effective long-range pathing
- Lots of options
- Download Traveler.ts or Traveler.js.
- Add a require statement to
main.js
:
var Traveler = require('Traveler.js');
- Check out suggestions in the footer for implementing the functions (e.g., adding to creep prototype).
-
travelTo
creates a new object in creep memory,_travel
, which is analogous to the object used bymoveTo()
for caching the creeps path. For this reason, it will save memory to use eithertravelTo()
ormoveTo()
with a given creep, but not both. - As with any algorithm where creeps aren't a consideration for pathing by default, you'll have best results when their path has a low chance of including immobile creeps. My creeps rarely reach the "stuck threshold" because I take extra considerations to keep the roads clear.
- My own codebase rarely harvests from rooms at more than a distance of 2. For this reason, my couriers rarely use more than 30 CPU for pathing purposes across their lifespan. I've set
REPORT_CPU_THRESHOLD
to 50, because if a creep goes above that, I'll want to know about it. If you are harvesting from further away, you might want to set this threshold to a higher value to get fewer false alarms.
Move creep to goal
.
-
creep: Creep
The creep you want to move. -
goal: { pos: RoomPosition }
Object with a propertypos: RoomPosition
. options?: Object
-
ignoreRoads?: boolean
Creeps won't prefer roads above plains (will still prefer them to swamps). Default isfalse
. -
ignoreCreeps?: boolean
Will not path around other creeps. Default istrue
. -
ignoreStuck?: boolean
Will not path around other creeps even if stuck. Default isfalse
. -
ignoreStructures?: boolean
Will not path around structures. Default isfalse
. -
preferHighway?: boolean
Creep prefer to travel along highway (empty rooms in between sectors). Default isfalse
-
allowHostile?: boolean
Hostile rooms will be included in path. Default isfalse
. -
allowSK?: boolean
SourceKeeper rooms will be included in path. (iffalse
, SK rooms will still be taken if they are they only viable path). Default isfalse
. -
range?: number
Range togoal
before it is considered reached. The default is 1. -
obstacles?: { pos: RoomPosition }[]
Array of objects with room positions that represent positions to avoid. -
roomCallback?: (roomName: string, ignoreCreeps: boolean) => CostMatrix | boolean
Callback function for overriding the defaultPathFinder
callback. If it returnsfalse
, that room will be excluded. If it returns a matrix, it will be used in place of the default matrix. If it returns undefined the default matrix will be used instead. -
routeCallback?: (roomName: string) => number
Callback function for overriding thefindRoute
callback. If it returns a number that value will be used to influence the route. If it returns undefined it will use the default value. -
returnPosition?: boolean
Return the RoomPosition that is being moved to when outcome === OK. Can be used to "look ahead". -
restrictDistance?: number
Limits the range the findRoute will search. Default is 16. -
maxOps?: number
Limits the ops (CPU) that PathFinder will use. Limit is 20000. (~20 CPU)