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

Support for returning false by costCallback option of Room.findPath. #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xilexio
Copy link

@xilexio xilexio commented May 19, 2019

Currently roomCallback in PathFinder.search has an option to return false instead of cost matrix to efficiently avoid the room entirely. There is no easy way to do that from Creep.moveTo efficiently, since it would require replacing roomCallback in _findPath2. One could use PathFinder directly, but that results in losing much of Creep.moveTo utility such as path caching, at least without knowledge of moveTo internals such as _move.

roomCallback creates the cost matrix and passes it to costCallback to modify it. When costCallback returns something else, it is ignored. No exception or anything. I propose that at least when costCallback returns false, it should be treated as if roomCallback returned false. This isn't as efficient as coding custom roomCallback, since the cost matrix is still created, but at least it is fully compatible with existing code and will not require the player to code all functionality between Creeps.moveTo and Room.findPath if they just want to avoid certain rooms, e.g., rooms owned enemies.

@nethershaw
Copy link

I have wasted so many hours trying to get my creeps just to avoid one room. I've tried costCallback in Room.findPath. I've tried roomCallback in Pathfinder.search. I've tried just using Game.map.findRoute and given up on resolving the room contents from a distance. I've made sure of room visibility. No matter the method, creeps keep pathfinding directly into rooms I've tried to explicitly avoid.

These three lines of code would have been helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants