Add comparison function for OverworldItem class

- Introduced CompareOverworldItems function to compare two vectors of OverworldItem objects for equality based on their properties (x, y, id).
- Included necessary header for algorithm functions to support the new comparison logic.
This commit is contained in:
scawful
2025-09-21 12:41:10 -04:00
parent 9844a12551
commit 0920fcc1fb

View File

@@ -1,6 +1,7 @@
#ifndef YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
#define YAZE_APP_ZELDA3_OVERWORLD_ITEM_H_
#include <algorithm>
#include <cstdint>
#include <iomanip>
#include <iostream>
@@ -65,6 +66,25 @@ class OverworldItem : public GameEntity {
bool deleted = false;
};
inline bool CompareOverworldItems(const std::vector<OverworldItem>& items1,
const std::vector<OverworldItem>& items2) {
if (items1.size() != items2.size()) {
return false;
}
const auto is_same_item = [](const OverworldItem& a, const OverworldItem& b) {
return a.x_ == b.x_ && a.y_ == b.y_ && a.id_ == b.id_;
};
return std::all_of(items1.begin(), items1.end(),
[&](const OverworldItem& it) {
return std::any_of(items2.begin(), items2.end(),
[&](const OverworldItem& other) {
return is_same_item(it, other);
});
});
}
const std::vector<std::string> kSecretItemNames = {
"Nothing", // 0
"Green Rupee", // 1