-
Notifications
You must be signed in to change notification settings - Fork 37
Improving Traveler: Important Changes
These are some important changes to Traveler, the version released on 2017-06-05.
After this discussion I decided to make all the functions on Traveler static. This means that they can be called without a reference to traveler. For example, if you want to assign travelTo
to the creep prototype, you will do this:
Creep.prototype.travelTo = function(destination: RoomPosition|{pos: RoomPosition}, options?: TravelToOptions) {
return Traveler.travelTo(this, destination, options);
};
The above prototype addition is already included in Traveler.ts/Traveler.js.
One thing traveler tries to do is avoid pathing into rooms owned by other players. The original traveler did this by having each creep check whether the room it was in was owned by another player. However, maybe some players want to allow certain rooms that are owned by allies or conquered foes or avoid certain rooms that aren't necessarily owned.
To make this easier and more consistent with the standard Memory object in screeps, you now work with the object that is supplied by the API when you access Memory.rooms[roomName]
. To add avoidance, use a statement like this:
Memory.rooms[roomName].avoid = 1;
To remove avoidance:
delete Memory.rooms[roomName].avoid;
If you liked the way creeps will register avoidance rooms automatically when they path into them, that's still in there! You just need to uncomment this line which you will find in Traveler.travelTo()
// uncomment if you would like to register hostile rooms entered
// this.updateRoomStatus(creep.room);
You can also access the function outside of the travelTo method:
Traveler.updateRoomStatus(room);
Finally, you may want to continue using the avoidance data that your creeps gathered. I've included a function Traveler.patchMemory(cleanup?: boolean)
which only needs to be called once. This will look at the object that was created at Memory.empire.hostileRooms
and patch the objects in Memory.rooms
appropriately. Here is what it does:
public static patchMemory(cleanup = false) {
if (!Memory.empire) { return; }
if (!Memory.empire.hostileRooms) { return; }
let count = 0;
for (let roomName in Memory.empire.hostileRooms) {
if (Memory.empire.hostileRooms[roomName]) {
if (!Memory.rooms[roomName]) { Memory.rooms[roomName] = {} as any; }
Memory.rooms[roomName].avoid = 1;
count++;
}
if (cleanup) {
delete Memory.empire.hostileRooms[roomName];
}
}
if (cleanup) {
delete Memory.empire.hostileRooms;
}
console.log(`TRAVELER: room avoidance data patched for ${count} rooms`);
}
Some feedback that I got from more than a few people was that it was awkward to use Traveler when your destination was just a RoomPosition. travelTo
will now accept either an object with the property {pos: RoomPosition}
or just a RoomPosition
.
Similarly, findTravelPath
will now accept either object as origin and destination.
More info here.
There was a bug where a creep might not move off the exit as it was expecting to and get thrown back into the previous room. However, from its perspective it would think that it had moved and so consume the next position in the path. This might make it stay on the exit or when it gets off, be out of sync with its path.
Stuck detection has improved and now looks for a situation like this. Please let me know if any bugs like this persist.
There were many more fixes since the first version was released. You can check out the Changelog in git README.md.