UltraMachine / rust-sc2

SC2 API for Rust
MIT License
37 stars 17 forks source link

The spam filter in command() is eating Reactor orders #46

Closed DataWraith closed 2 years ago

DataWraith commented 2 years ago

Hi.

I have built a Barracks with a Reactor and want to train two Marines. However, Unit.command() and Unit.train() will not process the second train command, unless it is queued. As far as I can tell, the second command gets filtered out by the APM spam filter, because it is identical to the previous command, and the Barracks is not technically idle (it is_unused).

The code snippet for the spam filter I am talking about looks like this:

pub fn command(&self, ability: AbilityId, target: Target, queue: bool) {
    if !(queue || self.is_idle() || self.data.allow_spam.get_locked()) {
        let last_order = &self.orders()[0];
        if ability == last_order.ability && target == last_order.target {
            return;
        }
    } else if self.is_sleeping() {
        return;
    }
        [...]

I can work around this using the queue flag, but I think a more proper solution in this case would be to change self.is_idle() to self.is_unused() in command(). self.is_unused() falls back to is_idle() when no reactor is present. However, I am not sure if that is indeed the correct way to solve this problem for good.

If you want me to, I can prepare a small pull request with the proposed change.

UltraMachine commented 2 years ago

Closing with 65d4f881a933867f5bd25bd32e4d6b8f6ad8ee47