short lookup_kind(const BaseitemKey &key)
{
- return lookup_kind(key.tval(), key.sval());
+ const auto sval = key.sval();
+ if (!sval.has_value()) {
+ constexpr auto any = 255;
+ return lookup_kind(key.tval(), any);
+ }
+
+ return lookup_kind(key.tval(), sval.value());
}
/*!
k_obj.tval = tval;
k_obj.sval = sval;
- if (sval == SV_ANY) {
+ constexpr auto any = 255;
+ if (sval == any) {
auto [begin, end] = std::equal_range(sorted_cache.begin(), sorted_cache.end(), &k_obj, comp_tval);
if (auto candidates_num = std::distance(begin, end);
candidates_num > 0) {
#include "system/baseitem-info-definition.h"
#include "object/tval-types.h"
-BaseitemKey::BaseitemKey(ItemKindType type_value, int subtype_value)
+BaseitemKey::BaseitemKey(const ItemKindType type_value, const std::optional<int> &subtype_value)
: type_value(type_value)
, subtype_value(subtype_value)
{
return this->type_value;
}
-int BaseitemKey::sval() const
+std::optional<int> BaseitemKey::sval() const
{
return this->subtype_value;
}
enum class ItemKindType : short;
class BaseitemKey {
public:
- BaseitemKey(ItemKindType type_value, int subtype_value);
+ BaseitemKey(const ItemKindType type_value, const std::optional<int> &subtype_value = std::nullopt);
bool operator==(const BaseitemKey &other) const;
bool operator!=(const BaseitemKey &other) const
{
}
ItemKindType tval() const;
- int sval() const;
+ std::optional<int> sval() const;
private:
ItemKindType type_value;
- int subtype_value; // @todo optionalにする.
+ std::optional<int> subtype_value;
};
enum class ItemKindType : short;