FR: Fix Room.deserializePath()



  • I've been beating my head against trying to get creeps to follow a serialized path that goes through a border, and have come to the conclusion that it just can't be done with the built in serializer/deserializer, and we have to write our own serializer/deserializer if we want a creep to follow a path in memory through a room border.

    I've written a custom pathfinder, using PathFinder.search, and have been happy with the paths it has given me that go through borders, and would dearly love to actually use these paths with creep.moveByPath(). But Room.serializePath() output from a PathFinder path looks something like 2310undefinedundefinedundefinedundefinedundefinedundefinedundefined.......

    Ok, so with the help of some of the great patrons of the chat, I've managed to write up a module to convert the PathFinder output to something that would be accepted by both Room.serializePath and creep.moveByPath. After ironing out the directional problem when crossing borders, I've got a function that will theoretically send a creep through a border and continue the path on the other side. At least, when you look at the pre-serialized path and the Room.serializePath output, it looks fine. The directions all look fine on the serialized path, and the locations are all good on the pre-serialized path. But comparing the paths before and after it's been serialized and deserialized, we see a BIG problem with the serializer.

    The serialized path string doesn't have any dx or dy information. Just a start location and a string of directional numbers in the format XXYYDDDDDDDDD. The deserializer is obviously just taking the start location, and incrementing/decrementing XX and YY before outputting an array of objects in the form of {x: x, y: y, dx: dx, dy: dy, direction: direction}. But when it hits a border number (0 or 49), it just keeps going. So in the deserialized path, even if you have a valid serialized string, you'll see x and y numbers outside of the bounds of 0 to 49. A creep following the deserialized path will stop at the border and complain that it's not on its path.

    I'm currently working on writing my own deserializer module that would take the serialized string and output back to an array of objects with the x and y bounded to 0 to 49. But it would REALLY be appreciated if this functionality would be built into the deserializer.



  • Actually, on reflection, this is probably a problem that should go into the Technical Issues and Bugs forum. Could this be moved over there?



  • Personally I just see this situation as a coding challenge.



  • I have also encountered this issue.

    However, it is Room.serializePath that is returning garbage. deserializePath I'm assuming is vestigial since creep.moveByPath accepts the serialized representation.

    I have confirmed that the RoomPosition array returned by PathFinder.search looks fine, but I get 2310undefinedundefinedundefinedundefinedundefinedundefinedundefined....... as output.