From 20afd8a1dfa07274a069fe381af0bef2afd44d38 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:37:00 +0100 Subject: [PATCH 01/10] Actually take item from pool when plandoing from_pool --- Fill.py | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/Fill.py b/Fill.py index c9660ab708ca..e53b21f5aeff 100644 --- a/Fill.py +++ b/Fill.py @@ -918,15 +918,31 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: world.random.shuffle(items) count = 0 err: typing.List[str] = [] - successful_pairs: typing.List[typing.Tuple[Item, Location]] = [] + successful_pairs: typing.List[typing.Tuple[int, Item, Location]] = [] # int -> index in multiworld.itempool + claimed_indices: typing.Set[int] = set() for item_name in items: - item = world.worlds[player].create_item(item_name) + index = None + + if from_pool: + try: + index, item = next( + (i, item) for i, item in enumerate(world.itempool) + if item.name == item_name and i not in claimed_indices) + except StopIteration: + warn( + f"Could not remove {item_name} from pool for {world.player_name[player]} as it's already missing from it.", + placement['force']) + item = world.worlds[player].create_item(item_name) + else: + item = world.worlds[player].create_item(item_name) + for location in reversed(candidates): if (location.address is None) == (item.code is None): # either both None or both not None if not location.item: if location.item_rule(item): if location.can_fill(world.state, item, False): - successful_pairs.append((item, location)) + successful_pairs.append((index, item, location)) + claimed_indices.add(index) candidates.remove(location) count = count + 1 break @@ -945,18 +961,17 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: failed( f"Plando block failed to place {m - count} of {m} item(s) for {world.player_name[player]}, error(s): {' '.join(err)}", placement['force']) - for (item, location) in successful_pairs: + + # Sort indices in reverse so we can remove them one by one + successful_pairs.sort(key=lambda index_and_placement: index_and_placement[0], reverse=True) + + for (index, item, location) in successful_pairs: world.push_item(location, item, collect=False) location.event = True # flag location to be checked during fill location.locked = True logging.debug(f"Plando placed {item} at {location}") - if from_pool: - try: - world.itempool.remove(item) - except ValueError: - warn( - f"Could not remove {item} from pool for {world.player_name[player]} as it's already missing from it.", - placement['force']) + if index is not None: + world.itempool.pop(index) except Exception as e: raise Exception( From 73771bccb784adae70e69502e3ca6a8719fd597b Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:57:13 +0100 Subject: [PATCH 02/10] Remove the awkward index thing --- Fill.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Fill.py b/Fill.py index e53b21f5aeff..09076c902953 100644 --- a/Fill.py +++ b/Fill.py @@ -918,16 +918,12 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: world.random.shuffle(items) count = 0 err: typing.List[str] = [] - successful_pairs: typing.List[typing.Tuple[int, Item, Location]] = [] # int -> index in multiworld.itempool - claimed_indices: typing.Set[int] = set() + successful_pairs: typing.List[typing.Tuple[Item, Location]] = [] for item_name in items: - index = None - if from_pool: try: - index, item = next( - (i, item) for i, item in enumerate(world.itempool) - if item.name == item_name and i not in claimed_indices) + index, item = next((i, item) for i, item in enumerate(world.itempool) if item.name == item_name) + world.itempool.pop(index) except StopIteration: warn( f"Could not remove {item_name} from pool for {world.player_name[player]} as it's already missing from it.", @@ -941,8 +937,7 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: if not location.item: if location.item_rule(item): if location.can_fill(world.state, item, False): - successful_pairs.append((index, item, location)) - claimed_indices.add(index) + successful_pairs.append((item, location)) candidates.remove(location) count = count + 1 break @@ -954,6 +949,9 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: err.append(f"Cannot place {item_name} into already filled location {location}.") else: err.append(f"Mismatch between {item_name} and {location}, only one is an event.") + else: # Execute if break statement wasn't hit: Placement was unsuccessful + if from_pool: + world.itempool.append(item) if count == maxcount: break if count < placement['count']['min']: @@ -963,15 +961,12 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: placement['force']) # Sort indices in reverse so we can remove them one by one - successful_pairs.sort(key=lambda index_and_placement: index_and_placement[0], reverse=True) - for (index, item, location) in successful_pairs: + for (item, location) in successful_pairs: world.push_item(location, item, collect=False) location.event = True # flag location to be checked during fill location.locked = True logging.debug(f"Plando placed {item} at {location}") - if index is not None: - world.itempool.pop(index) except Exception as e: raise Exception( From 44adafcb1a2034565d95b5be5af13e97e6d4308b Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:59:03 +0100 Subject: [PATCH 03/10] oops left a comment in --- Fill.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Fill.py b/Fill.py index 09076c902953..546639bed16d 100644 --- a/Fill.py +++ b/Fill.py @@ -949,7 +949,7 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: err.append(f"Cannot place {item_name} into already filled location {location}.") else: err.append(f"Mismatch between {item_name} and {location}, only one is an event.") - else: # Execute if break statement wasn't hit: Placement was unsuccessful + else: # Execute if break statement wasn't hit: Placement was unsuccessful, put item back if from_pool if from_pool: world.itempool.append(item) if count == maxcount: @@ -960,8 +960,6 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: f"Plando block failed to place {m - count} of {m} item(s) for {world.player_name[player]}, error(s): {' '.join(err)}", placement['force']) - # Sort indices in reverse so we can remove them one by one - for (item, location) in successful_pairs: world.push_item(location, item, collect=False) location.event = True # flag location to be checked during fill From 6cb5cfa72c6728af77551f15fcc9066797941e19 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:59:30 +0100 Subject: [PATCH 04/10] there wasn't a line break here before --- Fill.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Fill.py b/Fill.py index 546639bed16d..71f6b006f83c 100644 --- a/Fill.py +++ b/Fill.py @@ -959,7 +959,6 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: failed( f"Plando block failed to place {m - count} of {m} item(s) for {world.player_name[player]}, error(s): {' '.join(err)}", placement['force']) - for (item, location) in successful_pairs: world.push_item(location, item, collect=False) location.event = True # flag location to be checked during fill From 5d67b4fbc8b3e801e098be5a0cf4dea49199d607 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sun, 5 Nov 2023 01:15:51 +0100 Subject: [PATCH 05/10] Only remove if actually found, check against player number --- Fill.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Fill.py b/Fill.py index 71f6b006f83c..8496ab6fd314 100644 --- a/Fill.py +++ b/Fill.py @@ -920,10 +920,11 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: err: typing.List[str] = [] successful_pairs: typing.List[typing.Tuple[Item, Location]] = [] for item_name in items: + index_to_delete = None if from_pool: try: - index, item = next((i, item) for i, item in enumerate(world.itempool) if item.name == item_name) - world.itempool.pop(index) + index_to_delete, item = next((i, item) for i, item in enumerate(world.itempool) + if item.name == item_name and item.player == player) except StopIteration: warn( f"Could not remove {item_name} from pool for {world.player_name[player]} as it's already missing from it.", @@ -940,6 +941,8 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: successful_pairs.append((item, location)) candidates.remove(location) count = count + 1 + if index_to_delete: + world.itempool.pop(index_to_delete) break else: err.append(f"Can't place item at {location} due to fill condition not met.") @@ -949,9 +952,7 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: err.append(f"Cannot place {item_name} into already filled location {location}.") else: err.append(f"Mismatch between {item_name} and {location}, only one is an event.") - else: # Execute if break statement wasn't hit: Placement was unsuccessful, put item back if from_pool - if from_pool: - world.itempool.append(item) + if count == maxcount: break if count < placement['count']['min']: From 28eb5eb7a2818155451e0db4d3570aa59c679f7d Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sun, 5 Nov 2023 01:16:26 +0100 Subject: [PATCH 06/10] oops --- Fill.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fill.py b/Fill.py index 8496ab6fd314..a805763cc077 100644 --- a/Fill.py +++ b/Fill.py @@ -941,7 +941,7 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: successful_pairs.append((item, location)) candidates.remove(location) count = count + 1 - if index_to_delete: + if index_to_delete is not None: world.itempool.pop(index_to_delete) break else: From 98d7f412c2f72d8c884ecb0d6c4d51f330bb0f5c Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sun, 5 Nov 2023 01:35:43 +0100 Subject: [PATCH 07/10] Go back to index based system so we can just remove at the end --- Fill.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Fill.py b/Fill.py index a805763cc077..4ff065c871a9 100644 --- a/Fill.py +++ b/Fill.py @@ -918,13 +918,16 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: world.random.shuffle(items) count = 0 err: typing.List[str] = [] - successful_pairs: typing.List[typing.Tuple[Item, Location]] = [] + successful_pairs: typing.List[typing.Tuple[int, Item, Location]] = [] + claimed_indices: typing.Set[typing.Optional[int]] = set() for item_name in items: - index_to_delete = None + index_to_delete: typing.Optional[int] = None if from_pool: try: - index_to_delete, item = next((i, item) for i, item in enumerate(world.itempool) - if item.name == item_name and item.player == player) + index_to_delete, item = next( + (i, item) for i, item in enumerate(world.itempool) + if item.name == item_name and item.player == player and i not in claimed_indices + ) except StopIteration: warn( f"Could not remove {item_name} from pool for {world.player_name[player]} as it's already missing from it.", @@ -938,11 +941,10 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: if not location.item: if location.item_rule(item): if location.can_fill(world.state, item, False): - successful_pairs.append((item, location)) + successful_pairs.append((index_to_delete, item, location)) + claimed_indices.add(index_to_delete) candidates.remove(location) count = count + 1 - if index_to_delete is not None: - world.itempool.pop(index_to_delete) break else: err.append(f"Can't place item at {location} due to fill condition not met.") @@ -960,11 +962,17 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: failed( f"Plando block failed to place {m - count} of {m} item(s) for {world.player_name[player]}, error(s): {' '.join(err)}", placement['force']) - for (item, location) in successful_pairs: + + # Sort indices in reverse so we can remove them one by one + successful_pairs = sorted(successful_pairs, key=lambda successful_pair: successful_pair[0], reverse=True) + + for (index, item, location) in successful_pairs: world.push_item(location, item, collect=False) location.event = True # flag location to be checked during fill location.locked = True logging.debug(f"Plando placed {item} at {location}") + if index is not None: # If this item is from_pool and was found in the pool, remove it. + world.itempool.pop(index) except Exception as e: raise Exception( From 7abb3162ab2658fac99026cb66b043d8d0744023 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sun, 5 Nov 2023 01:37:28 +0100 Subject: [PATCH 08/10] Comment --- Fill.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Fill.py b/Fill.py index 4ff065c871a9..f7a4569f99d5 100644 --- a/Fill.py +++ b/Fill.py @@ -924,6 +924,7 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: index_to_delete: typing.Optional[int] = None if from_pool: try: + # If from_pool, try to find an existing item with this name & player in the itempool and use it index_to_delete, item = next( (i, item) for i, item in enumerate(world.itempool) if item.name == item_name and item.player == player and i not in claimed_indices From b57e93a958b1b5074a812e6df975f2833b8b3917 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Tue, 12 Mar 2024 01:38:42 +0100 Subject: [PATCH 09/10] Fix error on None --- Fill.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fill.py b/Fill.py index bcc5df97d153..40b4d1053bf9 100644 --- a/Fill.py +++ b/Fill.py @@ -968,7 +968,7 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: placement['force']) # Sort indices in reverse so we can remove them one by one - successful_pairs = sorted(successful_pairs, key=lambda successful_pair: successful_pair[0], reverse=True) + successful_pairs = sorted(successful_pairs, key=lambda successful_pair: successful_pair[0] or 0, reverse=True) for (index, item, location) in successful_pairs: multiworld.push_item(location, item, collect=False) From fbbb8ad002cb2a38216e1f86ea2a0c3f0fc0ca8b Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sun, 28 Jul 2024 23:17:06 +0200 Subject: [PATCH 10/10] Update Fill.py Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> --- Fill.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fill.py b/Fill.py index 40b4d1053bf9..2c51724afefb 100644 --- a/Fill.py +++ b/Fill.py @@ -930,7 +930,7 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None: # If from_pool, try to find an existing item with this name & player in the itempool and use it index_to_delete, item = next( (i, item) for i, item in enumerate(multiworld.itempool) - if item.name == item_name and item.player == player and i not in claimed_indices + if item.player == player and item.name == item_name and i not in claimed_indices ) except StopIteration: warn(