mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
36
worlds/_sc2common/bot/power_source.py
Normal file
36
worlds/_sc2common/bot/power_source.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
|
||||
from .position import Point2
|
||||
|
||||
|
||||
@dataclass
|
||||
class PowerSource:
|
||||
position: Point2
|
||||
radius: float
|
||||
unit_tag: int
|
||||
|
||||
def __post_init__(self):
|
||||
assert self.radius > 0
|
||||
|
||||
@classmethod
|
||||
def from_proto(cls, proto):
|
||||
return PowerSource(Point2.from_proto(proto.pos), proto.radius, proto.tag)
|
||||
|
||||
def covers(self, position: Point2) -> bool:
|
||||
return self.position.distance_to(position) <= self.radius
|
||||
|
||||
def __repr__(self):
|
||||
return f"PowerSource({self.position}, {self.radius})"
|
||||
|
||||
|
||||
@dataclass
|
||||
class PsionicMatrix:
|
||||
sources: List[PowerSource]
|
||||
|
||||
@classmethod
|
||||
def from_proto(cls, proto):
|
||||
return PsionicMatrix([PowerSource.from_proto(p) for p in proto])
|
||||
|
||||
def covers(self, position: Point2) -> bool:
|
||||
return any(source.covers(position) for source in self.sources)
|
Reference in New Issue
Block a user