speed up local item fill, by sorting by world once instead of up to twice per player
This commit is contained in:
parent
113efa8f02
commit
37cf2e1ac4
28
Fill.py
28
Fill.py
|
@ -142,22 +142,30 @@ def distribute_items_restrictive(world, gftower_trash=False, fill_locations=None
|
||||||
|
|
||||||
if any(localprioitempool.values() or
|
if any(localprioitempool.values() or
|
||||||
localrestitempool.values()): # we need to make sure some fills are limited to certain worlds
|
localrestitempool.values()): # we need to make sure some fills are limited to certain worlds
|
||||||
|
local_locations = {player: [] for player in world.player_ids}
|
||||||
|
for location in fill_locations:
|
||||||
|
local_locations[location.player].append(location)
|
||||||
|
for locations in local_locations.values():
|
||||||
|
world.random.shuffle(locations)
|
||||||
|
|
||||||
for player, items in localprioitempool.items(): # items already shuffled
|
for player, items in localprioitempool.items(): # items already shuffled
|
||||||
local_locations = [location for location in fill_locations if location.player == player]
|
player_local_locations = local_locations[player]
|
||||||
if not local_locations:
|
|
||||||
continue
|
|
||||||
world.random.shuffle(local_locations)
|
|
||||||
for item_to_place in items:
|
for item_to_place in items:
|
||||||
spot_to_fill = local_locations.pop()
|
if not player_local_locations:
|
||||||
|
logging.warning(f"Ran out of local locations for player {player}, "
|
||||||
|
f"cannot place {item_to_place}.")
|
||||||
|
break
|
||||||
|
spot_to_fill = player_local_locations.pop()
|
||||||
world.push_item(spot_to_fill, item_to_place, False)
|
world.push_item(spot_to_fill, item_to_place, False)
|
||||||
fill_locations.remove(spot_to_fill)
|
fill_locations.remove(spot_to_fill)
|
||||||
for player, items in localrestitempool.items(): # items already shuffled
|
for player, items in localrestitempool.items(): # items already shuffled
|
||||||
local_locations = [location for location in fill_locations if location.player == player]
|
player_local_locations = local_locations[player]
|
||||||
if not local_locations:
|
|
||||||
continue
|
|
||||||
world.random.shuffle(local_locations)
|
|
||||||
for item_to_place in items:
|
for item_to_place in items:
|
||||||
spot_to_fill = local_locations.pop()
|
if not player_local_locations:
|
||||||
|
logging.warning(f"Ran out of local locations for player {player}, "
|
||||||
|
f"cannot place {item_to_place}.")
|
||||||
|
break
|
||||||
|
spot_to_fill = player_local_locations.pop()
|
||||||
world.push_item(spot_to_fill, item_to_place, False)
|
world.push_item(spot_to_fill, item_to_place, False)
|
||||||
fill_locations.remove(spot_to_fill)
|
fill_locations.remove(spot_to_fill)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue