Reduce chance that shop_slot_shuffle produces empty slots, at the cost of cpu time.
This commit is contained in:
parent
bbf56a5a69
commit
25f234dff0
19
Shops.py
19
Shops.py
|
@ -196,20 +196,21 @@ def ShopSlotFill(world):
|
||||||
|
|
||||||
del locations_per_sphere
|
del locations_per_sphere
|
||||||
|
|
||||||
total_spheres = len(candidates_per_sphere)
|
|
||||||
|
|
||||||
for i, current_shop_slots in enumerate(shops_per_sphere):
|
for i, current_shop_slots in enumerate(shops_per_sphere):
|
||||||
if current_shop_slots:
|
if current_shop_slots:
|
||||||
candidate_sphere_ids = list(range(i, total_spheres))
|
# getting all candidates and shuffling them feels cpu expensive, there may be a better method
|
||||||
|
candidates = [(location, i) for i, candidates in enumerate(candidates_per_sphere[i:], start=i)
|
||||||
|
for location in candidates]
|
||||||
|
world.random.shuffle(candidates)
|
||||||
for location in current_shop_slots:
|
for location in current_shop_slots:
|
||||||
shop: Shop = location.parent_region.shop
|
shop: Shop = location.parent_region.shop
|
||||||
swapping_sphere_id = world.random.choices(candidate_sphere_ids,
|
for index, (c, swapping_sphere_id) in enumerate(candidates): # chosen item locations
|
||||||
cum_weights=cumu_weights[i:])[0]
|
|
||||||
swapping_sphere: list = candidates_per_sphere[swapping_sphere_id]
|
|
||||||
for c in swapping_sphere: # chosen item locations
|
|
||||||
if c.item_rule(location.item) and location.item_rule(c.item):
|
if c.item_rule(location.item) and location.item_rule(c.item):
|
||||||
swap_location_item(c, location, check_locked=False)
|
swap_location_item(c, location, check_locked=False)
|
||||||
logger.debug(f'Swapping {c} into {location}:: {location.item}')
|
logger.debug(f'Swapping {c} into {location}:: {location.item}')
|
||||||
|
# remove candidate
|
||||||
|
candidates_per_sphere[swapping_sphere_id].remove(c)
|
||||||
|
candidates.pop(index)
|
||||||
break
|
break
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -218,10 +219,6 @@ def ShopSlotFill(world):
|
||||||
location.shop_slot_disabled = True
|
location.shop_slot_disabled = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# remove candidate
|
|
||||||
swapping_sphere.remove(c)
|
|
||||||
cumu_weights[swapping_sphere_id] -= 1
|
|
||||||
|
|
||||||
item_name = location.item.name
|
item_name = location.item.name
|
||||||
if any(x in item_name for x in ['Compass', 'Map', 'Single Bomb', 'Single Arrow', 'Piece of Heart']):
|
if any(x in item_name for x in ['Compass', 'Map', 'Single Bomb', 'Single Arrow', 'Piece of Heart']):
|
||||||
price = world.random.randrange(1, 7)
|
price = world.random.randrange(1, 7)
|
||||||
|
|
Loading…
Reference in New Issue