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

Allow setting a custom Unit class #181

Open
BurnySc2 opened this issue Sep 18, 2023 · 0 comments
Open

Allow setting a custom Unit class #181

BurnySc2 opened this issue Sep 18, 2023 · 0 comments
Labels
being considered A bug that might get fixed or feature that might be implemented

Comments

@BurnySc2
Copy link
Owner

When initializing Unit objects, one would probably add attributes to it later, e.g. unit.is_scout: bool or unit.mining_at_mineral_patch: int to have some sort of persistent data.

This can only be done by extending the Unit class (either by modifying its file or inheriting) and making the Unit object persistent (either by actually making it persistent, or just updating its unit._proto data and invalidating all cache https://docs.python.org/3/library/functools.html#functools.cached_property ).
Instead of invalidating cache it can make sense to convert @cached_property back to @property for example for unit.orders for attributes that may change over multiple frames.

Alternatively the is_scout function can be a property that accesses data from the persistent bot object instead.
For example

    @property
    def is_scout(self) -> bool:
        return self.tag in self._bot_object.scouting_manager.scout_tags

A solution may be to allow bot authors to set a custom class for Unit objects to be initialized with in

unit_obj = Unit(unit, self, distance_calculation_index=index, base_build=self.base_build)

as long as they inherit from Unit class.

@BurnySc2 BurnySc2 added the being considered A bug that might get fixed or feature that might be implemented label Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
being considered A bug that might get fixed or feature that might be implemented
Projects
None yet
Development

No branches or pull requests

1 participant