fix $item with names that are also specials

This commit is contained in:
Martin Michelsen
2023-06-19 15:32:27 -07:00
parent e8fcf2884a
commit 6468af6eb7
2 changed files with 38 additions and 27 deletions
+13 -2
View File
@@ -1409,7 +1409,7 @@ const unordered_map<uint32_t, ItemNameInfo> name_info_for_primary_identifier({
{0x031903, "Team Points 10000"},
});
ItemData::ItemData(const string& orig_description) {
ItemData::ItemData(const string& orig_description, bool skip_special) {
this->data1d.clear(0);
this->id = 0xFFFFFFFF;
this->data2d = 0;
@@ -1444,6 +1444,7 @@ ItemData::ItemData(const string& orig_description) {
}
uint8_t weapon_special = 0;
if (!skip_special) {
for (const auto& it : name_for_weapon_special) {
if (!it.second) {
continue;
@@ -1456,6 +1457,7 @@ ItemData::ItemData(const string& orig_description) {
break;
}
}
}
static map<string, uint32_t> primary_identifier_for_name;
if (primary_identifier_for_name.empty()) {
@@ -1865,13 +1867,23 @@ ItemData item_for_string(const string& desc) {
try {
return ItemData(desc);
} catch (const exception&) {
}
try {
return ItemData(desc, true);
} catch (const exception&) {
}
string data = parse_data_string(desc);
if (data.size() < 2) {
throw runtime_error("item code too short");
}
if (data[0] > 4) {
throw runtime_error("invalid item class");
}
if (data.size() > 16) {
throw runtime_error("item code too long");
}
ItemData ret;
if (data.size() <= 12) {
memcpy(ret.data1.data(), data.data(), data.size());
@@ -1880,5 +1892,4 @@ ItemData item_for_string(const string& desc) {
memcpy(ret.data2.data(), data.data() + 12, data.size() - 12);
}
return ret;
}
}
+1 -1
View File
@@ -96,7 +96,7 @@ struct ItemData { // 0x14 bytes
} __attribute__((packed));
ItemData();
explicit ItemData(const std::string& orig_description);
explicit ItemData(const std::string& orig_description, bool skip_special = false);
ItemData(const ItemData& other);
ItemData& operator=(const ItemData& other);