Skip to content

Commit

Permalink
sc2: used variable item names in PoolFilter.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewMarinets committed Oct 12, 2023
1 parent ebda200 commit 5dca8a6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 49 deletions.
55 changes: 33 additions & 22 deletions worlds/sc2/ItemNames.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""
A complete collection of Starcraft 2 item names as strings.
Users of this data may make some assumptions about the structure of a name:
* The upgrade for a unit will end with the unit's name in parentheses
* Weapon / armor upgrades may may be grouped by a common prefix specified within this file
"""

# Terran Units
Expand Down Expand Up @@ -37,18 +40,23 @@
Sensor_Tower = "Sensor Tower"

# Terran Weapon / Armor Upgrades
Progressive_Terran_Infantry_Weapon = "Progressive Terran Infantry Weapon"
Progressive_Terran_Infantry_Armor = "Progressive Terran Infantry Armor"
Progressive_Terran_Vehicle_Weapon = "Progressive Terran Vehicle Weapon"
Progressive_Terran_Vehicle_Armor = "Progressive Terran Vehicle Armor"
Progressive_Terran_Ship_Weapon = "Progressive Terran Ship Weapon"
Progressive_Terran_Ship_Armor = "Progressive Terran Ship Armor"
Progressive_Terran_Weapon_Upgrade = "Progressive Terran Weapon Upgrade"
Progressive_Terran_Armor_Upgrade = "Progressive Terran Armor Upgrade"
Progressive_Terran_Infantry_Upgrade = "Progressive Terran Infantry Upgrade"
Progressive_Terran_Vehicle_Upgrade = "Progressive Terran Vehicle Upgrade"
Progressive_Terran_Ship_Upgrade = "Progressive Terran Ship Upgrade"
Progressive_Terran_Weapon_Armor_Upgrade = "Progressive Terran Weapon/Armor Upgrade"
terran_upgrade_prefix = "Progressive Terran"
terran_infantry_upgrade_prefix = f"{terran_upgrade_prefix} Infantry"
terran_vehicle_upgrade_prefix = f"{terran_upgrade_prefix} Vehicle"
terran_ship_upgrade_prefix = f"{terran_upgrade_prefix} Ship"

Progressive_Terran_Infantry_Weapon = f"{terran_infantry_upgrade_prefix} Weapon"
Progressive_Terran_Infantry_Armor = f"{terran_infantry_upgrade_prefix} Armor"
Progressive_Terran_Vehicle_Weapon = f"{terran_vehicle_upgrade_prefix} Weapon"
Progressive_Terran_Vehicle_Armor = f"{terran_vehicle_upgrade_prefix} Armor"
Progressive_Terran_Ship_Weapon = f"{terran_ship_upgrade_prefix} Weapon"
Progressive_Terran_Ship_Armor = f"{terran_ship_upgrade_prefix} Armor"
Progressive_Terran_Weapon_Upgrade = f"{terran_upgrade_prefix} Weapon Upgrade"
Progressive_Terran_Armor_Upgrade = f"{terran_upgrade_prefix} Armor Upgrade"
Progressive_Terran_Infantry_Upgrade = f"{terran_infantry_upgrade_prefix} Upgrade"
Progressive_Terran_Vehicle_Upgrade = f"{terran_vehicle_upgrade_prefix} Upgrade"
Progressive_Terran_Ship_Upgrade = f"{terran_ship_upgrade_prefix} Upgrade"
Progressive_Terran_Weapon_Armor_Upgrade = f"{terran_upgrade_prefix} Weapon/Armor Upgrade"

# Mercenaries
War_Pigs = "War Pigs"
Expand Down Expand Up @@ -238,16 +246,19 @@
Spine_Crawler = "Spine Crawler"

# Zerg Weapon / Armor Upgrades
Progressive_Zerg_Melee_Attack = "Progressive Zerg Melee Attack"
Progressive_Zerg_Missile_Attack = "Progressive Zerg Missile Attack"
Progressive_Zerg_Ground_Carapace = "Progressive Zerg Ground Carapace"
Progressive_Zerg_Flyer_Attack = "Progressive Zerg Flyer Attack"
Progressive_Zerg_Flyer_Carapace = "Progressive Zerg Flyer Carapace"
Progressive_Zerg_Weapon_Upgrade = "Progressive Zerg Weapon Upgrade"
Progressive_Zerg_Armor_Upgrade = "Progressive Zerg Armor Upgrade"
Progressive_Zerg_Ground_Upgrade = "Progressive Zerg Ground Upgrade"
Progressive_Zerg_Flyer_Upgrade = "Progressive Zerg Flyer Upgrade"
Progressive_Zerg_Weapon_Armor_Upgrade = "Progressive Zerg Weapon/Armor Upgrade"
zerg_upgrade_prefix = "Progressive Zerg"
zerg_flyer_upgrade_prefix = f"{zerg_upgrade_prefix} Flyer"

Progressive_Zerg_Melee_Attack = f"{zerg_upgrade_prefix} Melee Attack"
Progressive_Zerg_Missile_Attack = f"{zerg_upgrade_prefix} Missile Attack"
Progressive_Zerg_Ground_Carapace = f"{zerg_upgrade_prefix} Ground Carapace"
Progressive_Zerg_Flyer_Attack = f"{zerg_flyer_upgrade_prefix} Attack"
Progressive_Zerg_Flyer_Carapace = f"{zerg_flyer_upgrade_prefix} Carapace"
Progressive_Zerg_Weapon_Upgrade = f"{zerg_upgrade_prefix} Weapon Upgrade"
Progressive_Zerg_Armor_Upgrade = f"{zerg_upgrade_prefix} Armor Upgrade"
Progressive_Zerg_Ground_Upgrade = f"{zerg_upgrade_prefix} Ground Upgrade"
Progressive_Zerg_Flyer_Upgrade = f"{zerg_flyer_upgrade_prefix} Upgrade"
Progressive_Zerg_Weapon_Armor_Upgrade = f"{zerg_upgrade_prefix} Weapon/Armor Upgrade"

# Zerg Unit Upgrades
Zergling_Hardened_Carapace = "Hardened Carapace (Zergling)"
Expand Down
60 changes: 33 additions & 27 deletions worlds/sc2/PoolFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@
from .Options import get_option_value, MissionOrder, \
get_enabled_campaigns, get_disabled_campaigns, RequiredTactics, kerrigan_unit_available
from .LogicMixin import SC2Logic
from . import ItemNames

# Items with associated upgrades
UPGRADABLE_ITEMS = [
# WoL
"Marine", "Medic", "Firebat", "Marauder", "Reaper", "Ghost", "Spectre",
"Hellion", "Vulture", "Goliath", "Diamondback", "Siege Tank", "Thor", "Predator", "Widow Mine", "Cyclone",
"Medivac", "Wraith", "Viking", "Banshee", "Battlecruiser", "Raven", "Science Vessel", "Liberator", "Valkyrie",
"Bunker", "Missile Turret",
# HotS
"Zergling", "Roach", "Hydralisk", "Baneling", "Mutalisk", "Swarm Host", "Ultralisk"
]

BARRACKS_UNITS = {"Marine", "Medic", "Firebat", "Marauder", "Reaper", "Ghost", "Spectre"}
FACTORY_UNITS = {"Hellion", "Vulture", "Goliath", "Diamondback", "Siege Tank", "Thor", "Predator", "Widow Mine", "Cyclone"}
STARPORT_UNITS = {"Medivac", "Wraith", "Viking", "Banshee", "Battlecruiser", "Hercules", "Science Vessel", "Raven", "Liberator", "Valkyrie"}
UPGRADABLE_ITEMS = {item.parent_item for item in get_full_item_list().values()}

BARRACKS_UNITS = {
ItemNames.Marine, ItemNames.Medic, ItemNames.Firebat, ItemNames.Marauder,
ItemNames.Reaper, ItemNames.Ghost, ItemNames.Spectre,
}
FACTORY_UNITS = {
ItemNames.Hellion, ItemNames.Vulture, ItemNames.Goliath, ItemNames.Diamondback,
ItemNames.Siege_Tank, ItemNames.Thor, ItemNames.Predator, ItemNames.Widow_Mine,
ItemNames.Cyclone,
}
STARPORT_UNITS = {
ItemNames.Medivac, ItemNames.Wraith, ItemNames.Viking, ItemNames.Banshee,
ItemNames.Battlecruiser, ItemNames.Hercules, ItemNames.Science_Vessel, ItemNames.Raven,
ItemNames.Liberator, ItemNames.Valkyrie,
}


def filter_missions(multiworld: MultiWorld, player: int) -> Dict[MissionPools, List[SC2Mission]]:
Expand Down Expand Up @@ -327,25 +331,27 @@ def attempt_removal(item: Item) -> bool:
inventory = [item for item in inventory if not item.name.endswith("(Spider Mine)")]
if not BARRACKS_UNITS & self.logical_inventory:
inventory = [item for item in inventory if
not (item.name.startswith("Progressive Infantry") or item.name == "Orbital Strike")]
not (item.name.startswith(ItemNames.terran_infantry_upgrade_prefix) or item.name == ItemNames.Orbital_Strike)]
if not FACTORY_UNITS & self.logical_inventory:
inventory = [item for item in inventory if not item.name.startswith("Progressive Vehicle")]
inventory = [item for item in inventory if not item.name.startswith(ItemNames.terran_vehicle_upgrade_prefix)]
if not STARPORT_UNITS & self.logical_inventory:
inventory = [item for item in inventory if not item.name.startswith("Progressive Ship")]
inventory = [item for item in inventory if not item.name.startswith(ItemNames.terran_ship_upgrade_prefix)]
# HotS
# Baneling without sources => remove Baneling and upgrades
if "Baneling" in self.logical_inventory and\
"Zergling" not in self.logical_inventory and\
"Spawn Banelings (Kerrigan Tier 4)" not in self.logical_inventory:
inventory = [item for item in inventory if "Baneling" not in item.name]
if (ItemNames.Baneling in self.logical_inventory
and ItemNames.Zergling not in self.logical_inventory
and ItemNames.Kerrigan_Spawn_Banelings not in self.logical_inventory
):
inventory = [item for item in inventory if ItemNames.Baneling not in item.name]
# Spawn Banelings without Zergling => remove Baneling unit, keep upgrades
if "Baneling" in self.logical_inventory and\
"Zergling" not in self.logical_inventory and\
"Spawn Banelings (Kerrigan Tier 4)" in self.logical_inventory:
inventory = [item for item in inventory if item.name != "Baneling"]
if "Mutalisk" not in self.logical_inventory:
inventory = [item for item in inventory if not item.name.startswith("Progressive Zerg Flyer")]
locked_items = [item for item in locked_items if not item.name.startswith("Progressive Zerg Flyer")]
if (ItemNames.Baneling in self.logical_inventory
and ItemNames.Zergling not in self.logical_inventory
and ItemNames.Kerrigan_Spawn_Banelings in self.logical_inventory
):
inventory = [item for item in inventory if item.name != ItemNames.Baneling]
if ItemNames.Mutalisk not in self.logical_inventory:
inventory = [item for item in inventory if not item.name.startswith(ItemNames.zerg_flyer_upgrade_prefix)]
locked_items = [item for item in locked_items if not item.name.startswith(ItemNames.zerg_flyer_upgrade_prefix)]

# Cull finished, adding locked items back into inventory
inventory += locked_items
Expand Down

0 comments on commit 5dca8a6

Please sign in to comment.