Skip to content

Commit

Permalink
Fix item quantities in generation. Fix #58
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziktofel committed Sep 30, 2023
1 parent 70d168f commit ae2631b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions worlds/sc2wol/PoolFilter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Callable, Dict, List, Set
from BaseClasses import MultiWorld, ItemClassification, Item, Location
from .Items import get_full_item_list, spider_mine_sources, second_pass_placeable_items, filler_items
from .Items import get_full_item_list, spider_mine_sources, second_pass_placeable_items, filler_items, \
progressive_if_nco
from .MissionTables import no_build_regions_list, easy_regions_list, medium_regions_list, hard_regions_list,\
mission_orders, MissionInfo, alt_final_mission_locations, MissionPools
from .Options import get_option_value, MissionOrder, FinalMap, MissionProgressLocations, LocationInclusion
Expand Down Expand Up @@ -93,7 +94,10 @@ def get_item_upgrades(inventory: List[Item], parent_item: Item or str):
]


def get_item_quantity(item):
def get_item_quantity(item: Item, multiworld: MultiWorld, player: int):
if (not get_option_value(multiworld, player, "nco_items")) \
and item.name in progressive_if_nco:
return 1
return get_full_item_list()[item.name].quantity


Expand Down Expand Up @@ -138,13 +142,13 @@ def attempt_removal(item: Item) -> bool:
if not all(requirement(self) for requirement in requirements):
# If item cannot be removed, lock or revert
self.logical_inventory.add(item.name)
for _ in range(get_item_quantity(item)):
for _ in range(get_item_quantity(item, self.multiworld, self.player)):
locked_items.append(copy_item(item))
return False
return True

# Limit the maximum number of upgrades
maxUpgrad = get_option_value(self.multiworld, self.player,
maxUpgrad = get_option_value(self.multiworld, self.player,
"max_number_of_upgrades")
if maxUpgrad != -1:
unit_avail_upgrades = {}
Expand Down Expand Up @@ -197,15 +201,16 @@ def attempt_removal(item: Item) -> bool:
# Don't process general upgrades, they may have been pre-locked per-level
for item in items_to_lock:
if item in inventory:
item_quantity = inventory.count(item)
# Unit upgrades, lock all levels
for _ in range(inventory.count(item)):
for _ in range(item_quantity):
inventory.remove(item)
if item not in locked_items:
# Lock all the associated items if not already locked
for _ in range(get_item_quantity(item)):
for _ in range(item_quantity):
locked_items.append(copy_item(item))
if item in existing_items:
existing_items.remove(item)
if item in existing_items:
existing_items.remove(item)

if self.min_units_per_structure > 0 and self.has_units_per_structure():
requirements.append(lambda state: state.has_units_per_structure())
Expand Down Expand Up @@ -245,7 +250,7 @@ def attempt_removal(item: Item) -> bool:
for _ in range(inventory.count(transient_item)):
inventory.remove(transient_item)
if transient_item not in locked_items:
for _ in range(get_item_quantity(transient_item)):
for _ in range(get_item_quantity(transient_item, self.multiworld, self.player)):
locked_items.append(copy_item(transient_item))
if transient_item.classification in (ItemClassification.progression, ItemClassification.progression_skip_balancing):
self.logical_inventory.add(transient_item.name)
Expand Down

0 comments on commit ae2631b

Please sign in to comment.