Skip to content

Commit

Permalink
Merge branch 'sc2-next' of github.com:Ziktofel/Archipelago into sc2-next
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziktofel committed May 10, 2024
2 parents 16b9af1 + cd19868 commit 648970a
Show file tree
Hide file tree
Showing 15 changed files with 2,518 additions and 1,229 deletions.
50 changes: 31 additions & 19 deletions worlds/sc2/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
LocationInclusion, ExtraLocations, MasteryLocations, ChallengeLocations, VanillaLocations,
DisableForcedCamera, SkipCutscenes, GrantStoryTech, GrantStoryLevels, TakeOverAIAllies, RequiredTactics,
SpearOfAdunPresence, SpearOfAdunPresentInNoBuild, SpearOfAdunAutonomouslyCastAbilityPresence,
SpearOfAdunAutonomouslyCastPresentInNoBuild, MineralsPerItem, VespenePerItem, StartingSupplyPerItem,
SpearOfAdunAutonomouslyCastPresentInNoBuild,
)


Expand All @@ -46,10 +46,13 @@
from worlds._sc2common.bot.data import Race
from worlds._sc2common.bot.main import run_game
from worlds._sc2common.bot.player import Bot
from worlds.sc2.Items import lookup_id_to_name, get_full_item_list, ItemData, type_flaggroups, upgrade_numbers, upgrade_numbers_all
from worlds.sc2.Items import (
lookup_id_to_name, get_full_item_list, ItemData, upgrade_numbers, upgrade_numbers_all,
race_to_item_type, upgrade_item_types, ZergItemType,
)
from worlds.sc2.Locations import SC2WOL_LOC_ID_OFFSET, LocationType, SC2HOTS_LOC_ID_OFFSET
from worlds.sc2.MissionTables import lookup_id_to_mission, SC2Campaign, lookup_name_to_mission, \
lookup_id_to_campaign, MissionConnection, SC2Mission, campaign_mission_table, SC2Race, get_no_build_missions
lookup_id_to_campaign, MissionConnection, SC2Mission, campaign_mission_table, SC2Race
from worlds.sc2.Regions import MissionInfo

import colorama
Expand Down Expand Up @@ -212,15 +215,21 @@ def _cmd_received(self, filter_search: str = "") -> bool:
# Groups must be matched case-sensitively, so we properly capitalize the search term
# eg. "Spear of Adun" over "Spear Of Adun" or "spear of adun"
# This fails a lot of item name matches, but those should be found by partial name match
formatted_filter_search = " ".join([(part.lower() if len(part) <= 3 else part.lower().capitalize()) for part in filter_search.split()])
group_filter = ''
for group_name in item_name_groups:
if group_name in unlisted_item_name_groups:
continue
if filter_search.casefold() == group_name.casefold():
group_filter = group_name
break

def item_matches_filter(item_name: str) -> bool:
# The filter can be an exact group name or a partial item name
# Partial item name can be matched case-insensitively
if filter_search.lower() in item_name.lower():
if filter_search.casefold() in item_name.casefold():
return True
# The search term should already be formatted as a group name
if formatted_filter_search in item_name_groups and item_name in item_name_groups[formatted_filter_search]:
if group_filter and item_name in item_name_groups[group_filter]:
return True
return False

Expand Down Expand Up @@ -801,7 +810,10 @@ def calculate_items(ctx: SC2Context) -> typing.Dict[SC2Race, typing.List[int]]:
items.extend(compat_item_to_network_items(compat_item))

network_item: NetworkItem
accumulators: typing.Dict[SC2Race, typing.List[int]] = {race: [0 for _ in type_flaggroups[race]] for race in SC2Race}
accumulators: typing.Dict[SC2Race, typing.List[int]] = {
race: [0 for _ in item_type_enum_class]
for race, item_type_enum_class in race_to_item_type.items()
}

# Protoss Shield grouped item specific logic
shields_from_ground_upgrade: int = 0
Expand All @@ -814,14 +826,14 @@ def calculate_items(ctx: SC2Context) -> typing.Dict[SC2Race, typing.List[int]]:

# exists exactly once
if item_data.quantity == 1:
accumulators[item_data.race][type_flaggroups[item_data.race][item_data.type]] |= 1 << item_data.number
accumulators[item_data.race][item_data.type.flag_word] |= 1 << item_data.number

# exists multiple times
elif item_data.type in ["Upgrade", "Progressive Upgrade","Progressive Upgrade 2"]:
flaggroup = type_flaggroups[item_data.race][item_data.type]
elif item_data.quantity > 1:
flaggroup = item_data.type.flag_word

# Generic upgrades apply only to Weapon / Armor upgrades
if item_data.type != "Upgrade" or ctx.generic_upgrade_items == 0:
if item_data.type not in upgrade_item_types or ctx.generic_upgrade_items == 0:
accumulators[item_data.race][flaggroup] += 1 << item_data.number
else:
if name == ItemNames.PROGRESSIVE_PROTOSS_GROUND_UPGRADE:
Expand All @@ -840,28 +852,28 @@ def calculate_items(ctx: SC2Context) -> typing.Dict[SC2Race, typing.List[int]]:
# sum
else:
if name == ItemNames.STARTING_MINERALS:
accumulators[item_data.race][type_flaggroups[item_data.race][item_data.type]] += ctx.minerals_per_item
accumulators[item_data.race][item_data.type.flag_word] += ctx.minerals_per_item
elif name == ItemNames.STARTING_VESPENE:
accumulators[item_data.race][type_flaggroups[item_data.race][item_data.type]] += ctx.vespene_per_item
accumulators[item_data.race][item_data.type.flag_word] += ctx.vespene_per_item
elif name == ItemNames.STARTING_SUPPLY:
accumulators[item_data.race][type_flaggroups[item_data.race][item_data.type]] += ctx.starting_supply_per_item
accumulators[item_data.race][item_data.type.flag_word] += ctx.starting_supply_per_item
else:
accumulators[item_data.race][type_flaggroups[item_data.race][item_data.type]] += item_data.number
accumulators[item_data.race][item_data.type.flag_word] += item_data.number

# Fix Shields from generic upgrades by unit class (Maximum of ground/air upgrades)
if shields_from_ground_upgrade > 0 or shields_from_air_upgrade > 0:
shield_upgrade_level = max(shields_from_ground_upgrade, shields_from_air_upgrade)
shield_upgrade_item = item_list[ItemNames.PROGRESSIVE_PROTOSS_SHIELDS]
for _ in range(0, shield_upgrade_level):
accumulators[shield_upgrade_item.race][type_flaggroups[shield_upgrade_item.race][shield_upgrade_item.type]] += 1 << shield_upgrade_item.number
accumulators[shield_upgrade_item.race][item_data.type.flag_word] += 1 << shield_upgrade_item.number

# Upgrades from completed missions
if ctx.generic_upgrade_missions > 0:
total_missions = sum(len(ctx.mission_req_table[campaign]) for campaign in ctx.mission_req_table)
for race in SC2Race:
if "Upgrade" not in type_flaggroups[race]:
if race == SC2Race.ANY:
continue
upgrade_flaggroup = type_flaggroups[race]["Upgrade"]
upgrade_flaggroup = race_to_item_type[race]["Upgrade"].flag_word
num_missions = ctx.generic_upgrade_missions * total_missions
amounts = [
num_missions // 100,
Expand Down Expand Up @@ -894,7 +906,7 @@ def calc_difficulty(difficulty: int):


def get_kerrigan_level(ctx: SC2Context, items: typing.Dict[SC2Race, typing.List[int]], missions_beaten: int) -> int:
item_value = items[SC2Race.ZERG][type_flaggroups[SC2Race.ZERG]["Level"]]
item_value = items[SC2Race.ZERG][ZergItemType.Level.flag_word]
mission_value = missions_beaten * ctx.kerrigan_levels_per_mission_completed
if ctx.kerrigan_levels_per_mission_completed_cap != -1:
mission_value = min(mission_value, ctx.kerrigan_levels_per_mission_completed_cap)
Expand Down
2 changes: 1 addition & 1 deletion worlds/sc2/ClientGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def build_mission_table(self, dt) -> None:
if self.ctx.mission_req_table:
self.last_checked_locations = self.ctx.checked_locations.copy()
self.first_check = False
self.first_mission = get_first_mission(self.ctx.mission_req_table)
self.first_mission = get_first_mission(self.ctx.mission_req_table).mission_name

self.mission_id_to_button = {}

Expand Down
Loading

0 comments on commit 648970a

Please sign in to comment.