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

Avoid creeps within range (SK to start) #4

Open
ozotov opened this issue Aug 8, 2020 · 4 comments
Open

Avoid creeps within range (SK to start) #4

ozotov opened this issue Aug 8, 2020 · 4 comments

Comments

@ozotov
Copy link

ozotov commented Aug 8, 2020


type: Feature Request 💡
about: Avoid creeps during long distance travels.
labels: enhancement

Summary

The main idea is to add a new feature - avoid SK while traveling through SK rooms.

Basic example

When creep travel to another room throught an SK rooms, the path that was calculated from beggining of it's travel does not include creeps in rooms, without room visibility, it also moves around the creep, just like around any other obstacle(too close for argeesive creeps);

Motivation(explanation)

Why are we doing this? What use cases does it support? What is the expected outcome?

ideas:
(mnuck)
ok, cache invalidation. we can look at a SK room's name and know it's an SK room. we could say......if the user has requested this feature, and if we don't already have it in the cache, and if we have visibility, run the hunk of code you pasted and recalc the path? (edited)

to be continued...

@ozotov
Copy link
Author

ozotov commented Aug 8, 2020

very basic example for costMatrix and radius around creep:

 room.find(FIND_CREEPS).forEach((creep) => {
            if (options.avoidSK && creep.owner.username == "Source Keeper") {
                // TOP
                matrix.set((creep.pos.x + 1), (creep.pos.y + 4), 0xff);
                matrix.set((creep.pos.x + 2), (creep.pos.y + 4), 0xff);
                matrix.set((creep.pos.x + 3), (creep.pos.y + 4), 0xff);
                matrix.set((creep.pos.x + 4), (creep.pos.y + 4), 0xff);
                matrix.set((creep.pos.x - 1), (creep.pos.y + 4), 0xff);
                matrix.set((creep.pos.x - 2), (creep.pos.y + 4), 0xff);
                matrix.set((creep.pos.x - 3), (creep.pos.y + 4), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y + 4), 0xff);
                // LEFT
                matrix.set((creep.pos.x - 4), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y - 3), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y - 2), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y - 1), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y + 1), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y + 2), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y + 3), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y + 4), 0xff);
                // RIGHT
                matrix.set((creep.pos.x + 4), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x + 4), (creep.pos.y - 3), 0xff);
                matrix.set((creep.pos.x + 4), (creep.pos.y - 2), 0xff);
                matrix.set((creep.pos.x + 4), (creep.pos.y - 1), 0xff);
                matrix.set((creep.pos.x + 4), (creep.pos.y + 1), 0xff);
                matrix.set((creep.pos.x + 4), (creep.pos.y + 2), 0xff);
                matrix.set((creep.pos.x + 4), (creep.pos.y + 3), 0xff);
                matrix.set((creep.pos.x + 4), (creep.pos.y + 4), 0xff);
                // BOTTOM
                matrix.set((creep.pos.x + 4), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x + 3), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x + 2), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x + 1), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x - 1), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x - 2), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x - 3), (creep.pos.y - 4), 0xff);
                matrix.set((creep.pos.x - 4), (creep.pos.y - 4), 0xff);
            }
            matrix.set(creep.pos.x, creep.pos.y, 0xff);
            //return matrix;
        });

@mnuck
Copy link

mnuck commented Aug 8, 2020

I can think of two moments where it makes sense to invalidate the path and recalc:

  1. When this creep enters a previously unseen SK room,
  2. When anything gets us visibility into a previously unseen SK room.

Option 1 doesn't require any extra storage. We can just run the chain of ifs whenever this creep enters an SK room.

But I like Option 2. It's better to repath early, as soon as possible. For that to work, our intrepid creep needs two new pieces of data in creep.memory._trav: A collection of SK rooms it is interested in, and the visibility status those SK rooms had when the current path was calculated. Every time that creep calls .travelTo() it should look through it's collection of SK rooms to see if any have flipped from invisible to visible. If any have, repath.

@ozotov
Copy link
Author

ozotov commented Aug 9, 2020

I like option 2 too, but it also leads to more work, or at least new questions to consider.
If it gets room visibility before enter the room, repath, should it then repath again when entering the room?
If not, there is a risk that some creeps may appear after costMatrix recalculation.
If we recalculate the costMatrix when entering the room, this is an additional performance action, although it is a single action that should not greatly affect performance.

@ozotov
Copy link
Author

ozotov commented Aug 9, 2020

zipped variant :)

            if (creep.owner.username === "Source Keeper") {
                for (let i = -4; i <= 4; i++) {
                    // TOP
                    matrix.set((creep.pos.x + i), (creep.pos.y + 4), 0xff);
                    // LEFT
                    matrix.set((creep.pos.x - 4), (creep.pos.y + i), 0xff);
                    // RIGHT
                    matrix.set((creep.pos.x + 4), (creep.pos.y + i), 0xff);
                    // BOTTOM
                    matrix.set((creep.pos.x + i), (creep.pos.y - 4), 0xff);
                }
            };

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

No branches or pull requests

2 participants