|
| 1 | +import enum |
| 2 | + |
| 3 | +from .teams import TEAM |
| 4 | + |
| 5 | + |
| 6 | +class MARKER_TYPE(enum.Enum): |
| 7 | + SHEEP = enum.auto() |
| 8 | + ARENA = enum.auto() |
| 9 | + |
| 10 | + |
| 11 | +class MARKER_OWNER(enum.Enum): |
| 12 | + ME = enum.auto() |
| 13 | + ARENA = enum.auto() |
| 14 | + ANOTHER_TEAM = enum.auto() |
| 15 | + |
| 16 | + |
| 17 | +class WOOL_TYPE(enum.Enum): |
| 18 | + GOLDEN_FLEECE = enum.auto() |
| 19 | + STEEL_WOOL = enum.auto() |
| 20 | + |
| 21 | + |
| 22 | +class BASE_MARKER: |
| 23 | + def __init__( |
| 24 | + self, |
| 25 | + id: int, |
| 26 | + type: MARKER_TYPE, |
| 27 | + owner: MARKER_OWNER, |
| 28 | + ) -> None: |
| 29 | + self.id = id |
| 30 | + |
| 31 | + self.type = type |
| 32 | + self.owner = owner |
| 33 | + |
| 34 | + self.owning_team: TEAM | None = None |
| 35 | + |
| 36 | + self.wool_type: WOOL_TYPE | None = None |
| 37 | + |
| 38 | + # Sizes are in meters |
| 39 | + self.size = 0.290 if self.type == MARKER_TYPE.ARENA else 0.08 |
| 40 | + |
| 41 | + def __repr__(self) -> str: |
| 42 | + return f"<Marker type={self.type} wool_type={self.wool_type} owner={self.owner} owning_team={self.owning_team} />" |
| 43 | + |
| 44 | + @property |
| 45 | + def bounding_box_color(self) -> tuple[int, int, int]: |
| 46 | + return 255, 0, 0 |
| 47 | + |
| 48 | + |
| 49 | +class ARENA_MARKER(BASE_MARKER): |
| 50 | + def __init__(self, id: int) -> None: |
| 51 | + super().__init__(id, MARKER_TYPE.ARENA, MARKER_OWNER.ARENA) |
| 52 | + |
| 53 | + def __repr__(self) -> str: |
| 54 | + return f"<Marker(ARENA)/>" |
| 55 | + |
| 56 | + |
| 57 | +class SHEEP_MARKER(BASE_MARKER): |
| 58 | + def __init__( |
| 59 | + self, id: int, owner: TEAM, my_team: TEAM | None, wool_type: WOOL_TYPE |
| 60 | + ) -> None: |
| 61 | + super().__init__( |
| 62 | + id, |
| 63 | + MARKER_TYPE.SHEEP, |
| 64 | + MARKER_OWNER.ANOTHER_TEAM if owner != my_team else MARKER_OWNER.ME, |
| 65 | + ) |
| 66 | + self.owning_team = owner |
| 67 | + |
| 68 | + self.wool_type = wool_type |
| 69 | + |
| 70 | + def __repr__(self) -> str: |
| 71 | + return f"<Marker(SHEEP) wool_type={self.wool_type} owning_team={self.owning_team} />" |
| 72 | + |
| 73 | + |
| 74 | +class MARKER(BASE_MARKER): |
| 75 | + @staticmethod |
| 76 | + def by_id(id: int, team: TEAM | None = None) -> ARENA_MARKER | SHEEP_MARKER: |
| 77 | + """ |
| 78 | + Get a marker object from an id |
| 79 | +
|
| 80 | + Marker IDs are between 0 and 99 |
| 81 | + Low marker IDs (0-39) belong to teams. X0-X9 of each range of 10 may be |
| 82 | + assigned to sheep. |
| 83 | +
|
| 84 | + For the markers which belong to sheep, low marker IDs (X0-X5) will be |
| 85 | + sheep with STEEL_WOOL. High marker IDs (X6-X9) will be sheep with |
| 86 | + GOLDEN_FLEECE. |
| 87 | +
|
| 88 | + Higher marker IDs (40+) will be part of the arena. These markers will be |
| 89 | + spaced as in 2021-2022's competition (6 markers on each side of the Arena, |
| 90 | + the first 50cm away from the wall and each subsequent marker 1m away from |
| 91 | + there) |
| 92 | +
|
| 93 | + If no team is provided, all team-owned markers will be assumed to belong to |
| 94 | + ANOTHER_TEAM |
| 95 | + """ |
| 96 | + |
| 97 | + if id >= 40: |
| 98 | + return ARENA_MARKER(id) |
| 99 | + |
| 100 | + owning_team = TEAM[f"T{id // 10}"] |
| 101 | + |
| 102 | + wool_type = WOOL_TYPE.GOLDEN_FLEECE if id % 10 > 5 else WOOL_TYPE.STEEL_WOOL |
| 103 | + |
| 104 | + return SHEEP_MARKER(id, owning_team, team, wool_type) |
0 commit comments