Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions sc2/game_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from sc2.data import Attribute, Race
from sc2.ids.ability_id import AbilityId
from sc2.ids.upgrade_id import UpgradeId
from sc2.ids.unit_typeid import UnitTypeId
from sc2.unit_command import UnitCommand

Expand Down Expand Up @@ -279,6 +280,14 @@ def morph_cost(self) -> Cost | None:
)


# Workaround for Blizzard protobuf returning wrong ability IDs (ARMORYRESEARCHSWARM_...)
UPGRADE_RESEARCH_OVERRIDES: dict[UpgradeId, AbilityId] = {
UpgradeId.TERRANVEHICLEANDSHIPARMORSLEVEL1: AbilityId.ARMORYRESEARCH_TERRANVEHICLEANDSHIPPLATINGLEVEL1,
UpgradeId.TERRANVEHICLEANDSHIPARMORSLEVEL2: AbilityId.ARMORYRESEARCH_TERRANVEHICLEANDSHIPPLATINGLEVEL2,
UpgradeId.TERRANVEHICLEANDSHIPARMORSLEVEL3: AbilityId.ARMORYRESEARCH_TERRANVEHICLEANDSHIPPLATINGLEVEL3,
}


class UpgradeData:
def __init__(self, game_data: GameData, proto) -> None:
"""
Expand All @@ -295,8 +304,16 @@ def __repr__(self) -> str:
def name(self) -> str:
return self._proto.name

@property
def id(self) -> UpgradeId:
return UpgradeId(self._proto.upgrade_id)

@property
def research_ability(self) -> AbilityData | None:
# Check if the upgrade has a known protobuf ability ID bug
if self.id in UPGRADE_RESEARCH_OVERRIDES:
ability_id = UPGRADE_RESEARCH_OVERRIDES[self.id].value
return self._game_data.abilities.get(ability_id)
if self._proto.ability_id == 0:
return None
if self._proto.ability_id not in self._game_data.abilities:
Expand Down
Loading