Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mm/item option refactor #192

Merged
merged 48 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c622823
sc2: Refactored most item filtering logic to allow for locking and ex…
MatthewMarinets Apr 23, 2024
a35d1af
sc2: Removed unused old item pool creation functions
MatthewMarinets Apr 23, 2024
8c14b53
sc2: Fixing a function naming inconsistency
MatthewMarinets Apr 23, 2024
09f700f
sc2: Cleaning up some imports
MatthewMarinets Apr 23, 2024
c8a8a33
sc2: Refactored ItemType enum and updated all usages to compare again…
MatthewMarinets Apr 27, 2024
4b329f6
sc2: Fixed remaining reference to item_flaggroups, fixing unit tests
MatthewMarinets Apr 27, 2024
175b9ce
sc2: Added several generation unit tests; fixed several generation fa…
MatthewMarinets Apr 28, 2024
a869f49
sc2: Fixed some mypy type errors
MatthewMarinets Apr 28, 2024
1d1250d
sc2: Updated test to do a complete generation rather than looking at …
MatthewMarinets Apr 28, 2024
ecce323
sc2: Fully moved nova gear removal logic to filtering in init.py
MatthewMarinets Apr 28, 2024
3fc85ed
sc2: Created more item groups; filtering Nova items now uses nova equ…
MatthewMarinets Apr 28, 2024
bb58dd7
sc2: Fixed accidental all-caps on purifier item group
MatthewMarinets Apr 28, 2024
4792a7f
sc2: Added Protoss unit per building item groups
MatthewMarinets Apr 28, 2024
47741ca
sc2: Added a few more protoss / terran item groups and some sanity ch…
MatthewMarinets Apr 28, 2024
214eeb2
sc2: set orphan upgrades to only be flagged when corresponding no-bui…
MatthewMarinets Apr 30, 2024
6c7144b
sc2: Replaced bw_items, nco_items, ext_items options with vanilla_ite…
MatthewMarinets Apr 30, 2024
d0642b5
sc2: Made vanilla_items_only ignore Nova equipment; added unit tests
MatthewMarinets Apr 30, 2024
a0c6440
sc2: Added more asserts to unit tests to verify option is doing what …
MatthewMarinets Apr 30, 2024
b6fd3a4
sc2: added unexcluded_items option
MatthewMarinets Apr 30, 2024
f8b260f
sc2: Removed ItemOrigin enum
MatthewMarinets Apr 30, 2024
9eec4f0
sc2: Fixed mypy issues in init.py
MatthewMarinets Apr 30, 2024
eba4221
sc2: Fixed more mypy issues in regions.py and items.py
MatthewMarinets Apr 30, 2024
dd4a7c5
sc2: Added a usecase test for playing wol with NCO units only
MatthewMarinets Apr 30, 2024
4221b81
sc2: Fixed case-handling on /received
MatthewMarinets Apr 30, 2024
1db913c
sc2: Loosening logic on Evil Awoken when vanilla_items_only is true; …
MatthewMarinets May 2, 2024
29adee5
sc2: Removed raid liberator start-inventory under esoteric conditions…
MatthewMarinets May 2, 2024
6aba9cf
sc2: Fixed an issue where indirectly-flagged start inventory wasn't p…
MatthewMarinets May 2, 2024
7c1ef79
sc2: Zerg and Protoss units are now fully excluded when Enemy Within/…
MatthewMarinets May 2, 2024
daac893
sc2: Fixed an issue where SOA items wouldn't ever be included
MatthewMarinets May 2, 2024
67b911e
sc2: Moved faction-based item exclude out of PoolFilter.py
MatthewMarinets May 2, 2024
152d00d
sc2: Combined two like functions in init.py
MatthewMarinets May 2, 2024
fccc3b0
sc2: Loosened the asserts on a test to make it less flaky
MatthewMarinets May 2, 2024
6bc3ce9
sc2: Filter out Kerrigan items if only Kerrigan nobuilds are present …
MatthewMarinets May 2, 2024
c1035e3
sc2: Fixing a sporadic generation issue caused by accidental duplicat…
MatthewMarinets May 2, 2024
cff8f3f
sc2: Updated logic on Evil Awoken so vanilla composition is in-logic
MatthewMarinets May 2, 2024
4ea2614
sc2: Added NCO item groups; added usecase test for NCO item pool only
MatthewMarinets May 2, 2024
b95f509
sc2: Adding '0 means select all' explanation to item dict option desc…
MatthewMarinets May 2, 2024
99383d1
sc2: Fixing variable name for NCO all item groups
MatthewMarinets May 2, 2024
3eacf9c
sc2: Consolidated display names for item groups ending with numbers; …
MatthewMarinets May 2, 2024
67e7c47
sc2: Made item group substitution case-insensitive
MatthewMarinets May 2, 2024
8ea1892
sc2: Split usecase unit tests from item filtering tests
MatthewMarinets May 3, 2024
52fda6f
sc2: Added more usecase tests; fixed an issue that was spuriously put…
MatthewMarinets May 3, 2024
eff8650
sc2: Added a unit test specifying the design constraints of vanilla_i…
MatthewMarinets May 3, 2024
0828205
sc2: Set stalker upgrades to useful instead of progression; removed u…
MatthewMarinets May 6, 2024
8b3465b
sc2: Split off item groups sanity asserts into a unit test file
MatthewMarinets May 7, 2024
63542ce
sc2: PR review comments; formatting cleanups
MatthewMarinets May 7, 2024
82c2851
sc2: Reformatting stargate unit group in itemgroups
MatthewMarinets May 8, 2024
0e48aa6
sc2: re-grouped stargate units
MatthewMarinets May 10, 2024
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
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
Loading