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

Update RoomPosition find functions to use Find enum #358

Merged
merged 2 commits into from
Aug 25, 2022

Conversation

JCGrant
Copy link
Contributor

@JCGrant JCGrant commented Aug 4, 2021

This PR updates the find methods to operate similarly to the look methods.

I tried to update this code at screeps-starter-rust:

for source in room.find(find::SOURCES_ACTIVE).iter() {
    let id = source.id();
    creep_targets.insert(name, CreepTarget::Harvest(id));
    break;
}

to use find_closest_by_path but the types kept getting in the way.

You can now write something like this:

let room_position: RoomPosition = creep.pos().into();
let source = room_position.find_closest_by_path(find::SOURCES_ACTIVE);
match source {
    Some(source) => {
        let id = source.id();
        creep_targets.insert(name, CreepTarget::Harvest(id));
    }
    None => {}
}

However, there is a slight quirk which I don't quite understand.

I would ideally like to write something like the following:

creep.pos().find_closest_by_path(SOURCES);

Without needing the intermediate into() call.

Especially because there is another call to creep.pos() above in the same code, which just works.

creep.pos().is_near_to(source.pos())

Do you have an idea why this might be the case?

@shanemadden shanemadden merged commit 40ad4b9 into rustyscreeps:bindgen Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants