Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SC2: Fix unused_items refill to respect item dependencies. #3116

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

Ziktofel
Copy link
Collaborator

@Ziktofel Ziktofel commented Apr 8, 2024

What is this fixing or adding?

See bug: Ziktofel#187
After main culling process done, some items might be brought back. However, the item dependencies were ignored. This fixes that by filtering unused_items by using dependency rules

How was this tested?

Tested with YAML that produced the issue, the problem is gone now

If this makes graphical changes, please attach screenshots.

No

@github-actions github-actions bot added the waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. label Apr 8, 2024
@Ziktofel Ziktofel added the is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. label Apr 8, 2024
Copy link
Contributor

@MatthewMarinets MatthewMarinets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change makes sense, though the style looks a bit error prone. Tidying this up would be nice, but would require a significant refactor in how we treat item parents / dependencies. This bugfix looks good for now.

To explain what's going on (for future reviewers and to test my knowledge):

  • Currently, if there are too many items for the number of locations, items are culled
  • Some items depend on other items to have any effect; these items are also culled along with their parent items
  • The generator keeps track of some unused items that can be added back after further culling (line 395) -- when an upgrade item gets culled directly, it gets added to the unused items list
  • This list of unused items wasn't properly culled if parent items were removed from the item pool

I see two ways that things could have been failing:

  1. An upgrade item could be culled (say baneling splash area), which would add it to the unused items list. Then the parent item gets culled, which also culls all the child items from the item pool, but doesn't properly remove baneling splash from the unused items list. Baneling splash could then be added back to the item pool when items are pulled back from the unused list
  2. We have some upgrades with multiple parents -- e.g. Zealot leg speed can affect Zealots, Centurions, and Sentinels. Because it's not a direct child, zealot leg speed is not culled when any of its parents are culled. This multi-parent culling happens below (around line 405 onwards) -- but by that point the unused items list was already populated, and it didn't get culled.

This change should fix both possible paths to a bug.

For a future refactor, it would be nice if we could package up the items lists with a structure of some sort and helper functions that could handle these complicated parent-child item dependencies.

@Ziktofel
Copy link
Collaborator Author

Ziktofel commented Apr 8, 2024

Yeah, the item dependencies could use some refactoring but that's out of scope of this PR

Copy link
Contributor

@Bicoloursnake Bicoloursnake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding typing to variables is always appreciated. It makes sense for unused_items to have the same filters as inventory. That should fix the problems we're seeing. Disclaimer: did not test, but extra filters on unused_items look to correctly mirror filters on inventory.

Copy link
Contributor

@Magnemania Magnemania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably more elegant ways to do this, but it works and is readable.

@Ziktofel Ziktofel added waiting-on: core-review Issue/PR has been peer-reviewed and is ready to be merged or needs input from a core maintainer. and removed waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Apr 8, 2024
@Ziktofel
Copy link
Collaborator Author

Ziktofel commented Apr 8, 2024

Yeah, it's a bugfix, I've straightly fixed that so it can't break anything else

@Ziktofel Ziktofel added waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. and removed waiting-on: core-review Issue/PR has been peer-reviewed and is ready to be merged or needs input from a core maintainer. labels Apr 8, 2024
@Ziktofel
Copy link
Collaborator Author

Ziktofel commented Apr 8, 2024

Changed back due to @Salzkorn's tests

Copy link
Contributor

@Bicoloursnake Bicoloursnake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Salz for catching that. I forgot that the parent name is an item name string, not an item itself. This looks good now.

@Ziktofel
Copy link
Collaborator Author

Ziktofel commented Apr 8, 2024

Yeah, I've added a type check to validate that

@Ziktofel Ziktofel added waiting-on: core-review Issue/PR has been peer-reviewed and is ready to be merged or needs input from a core maintainer. and removed waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Apr 8, 2024
Copy link
Contributor

@MatthewMarinets MatthewMarinets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks good at a glance. Not sure if the type check was checked with mypy / a static analyzer, but I'd recommend doing so if it hasn't been done already.

@Ziktofel
Copy link
Collaborator Author

Ziktofel commented Apr 9, 2024

In Intellij it highlights the code if it fails type check

@Berserker66 Berserker66 merged commit 8d28c34 into ArchipelagoMW:main Apr 11, 2024
15 checks passed
EmilyV99 pushed a commit to EmilyV99/Archipelago that referenced this pull request Apr 15, 2024
EmilyV99 pushed a commit to EmilyV99/Archipelago that referenced this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. waiting-on: core-review Issue/PR has been peer-reviewed and is ready to be merged or needs input from a core maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants