Fix item crash
This commit is contained in:
@@ -22,8 +22,7 @@ void inventoryInit(
|
|||||||
inventory->storage = storage;
|
inventory->storage = storage;
|
||||||
inventory->storageSize = storageSize;
|
inventory->storageSize = storageSize;
|
||||||
|
|
||||||
// Zero item ids.
|
memoryZero(storage, sizeof(inventorystack_t) * storageSize);
|
||||||
memoryZero(inventory->storage, sizeof(inventorystack_t) * storageSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t inventoryItemExists(const inventory_t *inventory, const itemid_t item) {
|
bool_t inventoryItemExists(const inventory_t *inventory, const itemid_t item) {
|
||||||
|
|||||||
+9
-14
@@ -30,23 +30,18 @@ with open(args.csv, newline="", encoding="utf-8") as f:
|
|||||||
item_types.append(item_type)
|
item_types.append(item_type)
|
||||||
rows[item_id] = row
|
rows[item_id] = row
|
||||||
|
|
||||||
# Assign enum values: types and IDs share a single counter so values never collide
|
# Assign enum values: types and IDs each start from 1 with NULL = 0.
|
||||||
count = 0
|
|
||||||
type_values = {}
|
type_values = {}
|
||||||
id_values = {}
|
type_count = 1
|
||||||
|
|
||||||
count += 1 # 0 = NULL
|
|
||||||
for t in item_types:
|
for t in item_types:
|
||||||
type_values[t] = count
|
type_values[t] = type_count
|
||||||
count += 1
|
type_count += 1
|
||||||
# ITEM_TYPE_COUNT = count; item IDs continue from here
|
|
||||||
type_count = count
|
|
||||||
|
|
||||||
count += 1 # type_count = ITEM_ID_NULL
|
id_values = {}
|
||||||
|
id_count = 1
|
||||||
for i in item_ids:
|
for i in item_ids:
|
||||||
id_values[i] = count
|
id_values[i] = id_count
|
||||||
count += 1
|
id_count += 1
|
||||||
id_count = count
|
|
||||||
|
|
||||||
# Count items per type
|
# Count items per type
|
||||||
type_item_counts = { t: 0 for t in item_types }
|
type_item_counts = { t: 0 for t in item_types }
|
||||||
@@ -68,7 +63,7 @@ out += [
|
|||||||
"} itemtype_t;",
|
"} itemtype_t;",
|
||||||
"",
|
"",
|
||||||
"typedef enum {",
|
"typedef enum {",
|
||||||
f" ITEM_ID_NULL = {type_count},",
|
" ITEM_ID_NULL = 0,",
|
||||||
]
|
]
|
||||||
for i in item_ids:
|
for i in item_ids:
|
||||||
out.append(f" {id_enum(i)} = {id_values[i]},")
|
out.append(f" {id_enum(i)} = {id_values[i]},")
|
||||||
|
|||||||
Reference in New Issue
Block a user