Skip to content

Commit

Permalink
SM: 0.4.2 percent goals fix (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
lordlou authored Sep 19, 2023
1 parent 6e02a4c commit 0012584
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion worlds/sm/variaRandomizer/rando/GraphBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def escapeTrigger(self, emptyContainer, graph, maxDiff, escapeTrigger):
# update item% objectives
accessibleItems = [il.Item for il in allItemLocs if ilCheck(il)]
majorUpgrades = [item.Type for item in accessibleItems if item.BeamBits != 0 or item.ItemBits != 0]
sm.objectives.setItemPercentFuncs(len(accessibleItems), majorUpgrades)
if split == "Scavenger":
# update escape access for scav with last scav loc
lastScavItemLoc = progItemLocs[-1]
Expand All @@ -163,6 +162,7 @@ def escapeTrigger(self, emptyContainer, graph, maxDiff, escapeTrigger):
if ilCheck(itemLoc) and (split.startswith("Full") or itemLoc.Location.isClass(split)):
availLocsByArea[itemLoc.Location.GraphArea].append(itemLoc.Location.Name)
self.log.debug("escapeTrigger. availLocsByArea="+str(availLocsByArea))
sm.objectives.setItemPercentFuncs(len(accessibleItems), majorUpgrades, container)
sm.objectives.setAreaFuncs({area:lambda sm,ap:SMBool(len(container.getLocs(lambda loc: loc.Name in availLocsByArea[area]))==0) for area in availLocsByArea})
self.log.debug("escapeTrigger. collect locs until G4 access")
# collect all item/locations up until we can pass G4 (the escape triggers)
Expand Down
12 changes: 7 additions & 5 deletions worlds/sm/variaRandomizer/utils/objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,18 @@ def updateItemPercentEscapeAccess(self, collectedLocsAccessPoints):
def setScavengerHuntFunc(self, scavClearFunc):
self.goals["finish scavenger hunt"].clearFunc = scavClearFunc

def setItemPercentFuncs(self, totalItemsCount=None, allUpgradeTypes=None):
def getPctFunc(pct, totalItemsCount):
def setItemPercentFuncs(self, totalItemsCount=None, allUpgradeTypes=None, container=None):
def getPctFunc(total_needed, container):
def f(sm, ap):
nonlocal pct, totalItemsCount
return sm.hasItemsPercent(pct, totalItemsCount)
nonlocal total_needed, container
locs_checked = len(container.getUsedLocs(lambda loc: True))
return SMBool(locs_checked >= total_needed)
return f

# AP: now based on location checks instead of local item
for pct in [25,50,75,100]:
goal = 'collect %d%% items' % pct
self.goals[goal].clearFunc = getPctFunc(pct, totalItemsCount)
self.goals[goal].clearFunc = getPctFunc(totalItemsCount * pct / 100, container)
if allUpgradeTypes is not None:
self.goals["collect all upgrades"].clearFunc = lambda sm, ap: sm.haveItems(allUpgradeTypes)

Expand Down

0 comments on commit 0012584

Please sign in to comment.