fix invalid tool class on v3/v4

This commit is contained in:
Martin Michelsen
2023-11-21 11:25:25 -08:00
parent 1d8ae0b4d9
commit 267c2ca00b
3 changed files with 20 additions and 10 deletions
+19 -8
View File
@@ -632,8 +632,26 @@ void ItemCreator::generate_common_tool_variances(uint32_t area_norm, ItemData& i
if (this->is_v3() && (tool_class == 0x1A)) {
tool_class = 0x73;
}
this->log.info("Generating tool with class %02hhX", tool_class);
// Note: This block was originally a separate function called
// generate_common_tool_type
{
// It appears that when Sega deleted Hit Material in v3, they never deleted
// it from the ItemPT entries, so sometimes ItemCreator tries to generate
// it. The original implementation just generates no item when that happens,
// so we do the same here.
try {
auto data = this->item_parameter_table->find_tool_by_id(tool_class);
item.data1[0] = 0x03;
item.data1[1] = data.first;
item.data1[2] = data.second;
} catch (const out_of_range&) {
this->log.info("Tool class is missing; skipping item generation");
return;
}
}
this->generate_common_tool_type(tool_class, item);
if (item.data1[1] == 0x02) { // Tech disk
item.data1[4] = this->get_rand_from_weighted_tables_2d_vertical(this->pt->technique_index_prob_table(), area_norm);
item.data1[2] = this->generate_tech_disk_level(item.data1[4], area_norm);
@@ -652,13 +670,6 @@ uint8_t ItemCreator::generate_tech_disk_level(uint32_t tech_num, uint32_t area_n
return range.min;
}
void ItemCreator::generate_common_tool_type(uint8_t id, ItemData& item) const {
auto data = this->item_parameter_table->find_tool_by_id(id);
item.data1[0] = 0x03;
item.data1[1] = data.first;
item.data1[2] = data.second;
}
void ItemCreator::generate_common_mag_variances(ItemData& item) const {
if (item.data1[0] == 0x02) {
item.data1[1] = 0x00;